xref: /minix3/minix/fs/ext2/protect.c (revision 970d95ecd592b97088f82dd45b0c93a10fc1d1c4)
1433d6423SLionel Sambuc /* Created (MFS based):
2433d6423SLionel Sambuc  *   February 2010 (Evgeniy Ivanov)
3433d6423SLionel Sambuc  */
4433d6423SLionel Sambuc 
5433d6423SLionel Sambuc #include "fs.h"
6433d6423SLionel Sambuc #include "inode.h"
7433d6423SLionel Sambuc #include "super.h"
8433d6423SLionel Sambuc 
9433d6423SLionel Sambuc 
10433d6423SLionel Sambuc /*===========================================================================*
11433d6423SLionel Sambuc  *				fs_chmod				     *
12433d6423SLionel Sambuc  *===========================================================================*/
fs_chmod(ino_t ino_nr,mode_t * mode)13*970d95ecSDavid van Moolenbroek int fs_chmod(ino_t ino_nr, mode_t *mode)
14433d6423SLionel Sambuc {
15433d6423SLionel Sambuc /* Perform the chmod(name, mode) system call. */
16433d6423SLionel Sambuc   register struct inode *rip;
17433d6423SLionel Sambuc 
18433d6423SLionel Sambuc   /* Temporarily open the file. */
19*970d95ecSDavid van Moolenbroek   if( (rip = get_inode(fs_dev, ino_nr)) == NULL)
20433d6423SLionel Sambuc 	  return(EINVAL);
21433d6423SLionel Sambuc 
22433d6423SLionel Sambuc   /* Now make the change. Clear setgid bit if file is not in caller's grp */
23*970d95ecSDavid van Moolenbroek   rip->i_mode = (rip->i_mode & ~ALL_MODES) | (*mode & ALL_MODES);
24433d6423SLionel Sambuc   rip->i_update |= CTIME;
25433d6423SLionel Sambuc   rip->i_dirt = IN_DIRTY;
26433d6423SLionel Sambuc 
27433d6423SLionel Sambuc   /* Return full new mode to caller. */
28*970d95ecSDavid van Moolenbroek   *mode = rip->i_mode;
29433d6423SLionel Sambuc 
30433d6423SLionel Sambuc   put_inode(rip);
31433d6423SLionel Sambuc   return(OK);
32433d6423SLionel Sambuc }
33433d6423SLionel Sambuc 
34433d6423SLionel Sambuc 
35433d6423SLionel Sambuc /*===========================================================================*
36433d6423SLionel Sambuc  *				fs_chown				     *
37433d6423SLionel Sambuc  *===========================================================================*/
fs_chown(ino_t ino_nr,uid_t uid,gid_t gid,mode_t * mode)38*970d95ecSDavid van Moolenbroek int fs_chown(ino_t ino_nr, uid_t uid, gid_t gid, mode_t *mode)
39433d6423SLionel Sambuc {
40433d6423SLionel Sambuc   register struct inode *rip;
41433d6423SLionel Sambuc 
42433d6423SLionel Sambuc   /* Temporarily open the file. */
43*970d95ecSDavid van Moolenbroek   if( (rip = get_inode(fs_dev, ino_nr)) == NULL)
44433d6423SLionel Sambuc 	  return(EINVAL);
45433d6423SLionel Sambuc 
46*970d95ecSDavid van Moolenbroek   rip->i_uid = uid;
47*970d95ecSDavid van Moolenbroek   rip->i_gid = gid;
48433d6423SLionel Sambuc   rip->i_mode &= ~(I_SET_UID_BIT | I_SET_GID_BIT);
49433d6423SLionel Sambuc   rip->i_update |= CTIME;
50433d6423SLionel Sambuc   rip->i_dirt = IN_DIRTY;
51433d6423SLionel Sambuc 
52433d6423SLionel Sambuc   /* Update caller on current mode, as it may have changed. */
53*970d95ecSDavid van Moolenbroek   *mode = rip->i_mode;
54433d6423SLionel Sambuc   put_inode(rip);
55433d6423SLionel Sambuc 
56433d6423SLionel Sambuc   return(OK);
57433d6423SLionel Sambuc }
58