xref: /minix3/minix/fs/mfs/protect.c (revision ccaeedb267288a9eea9fd8cd1c553aa98bdef60d)
1433d6423SLionel Sambuc #include "fs.h"
2433d6423SLionel Sambuc #include "inode.h"
3433d6423SLionel Sambuc #include "super.h"
4433d6423SLionel Sambuc 
5433d6423SLionel Sambuc 
6433d6423SLionel Sambuc /*===========================================================================*
7433d6423SLionel Sambuc  *				fs_chmod				     *
8433d6423SLionel Sambuc  *===========================================================================*/
fs_chmod(ino_t ino_nr,mode_t * mode)9*ccaeedb2SDavid van Moolenbroek int fs_chmod(ino_t ino_nr, mode_t *mode)
10433d6423SLionel Sambuc {
11433d6423SLionel Sambuc /* Perform the chmod(name, mode) system call. */
12433d6423SLionel Sambuc   register struct inode *rip;
13433d6423SLionel Sambuc 
14433d6423SLionel Sambuc   /* Temporarily open the file. */
15*ccaeedb2SDavid van Moolenbroek   if( (rip = get_inode(fs_dev, ino_nr)) == NULL)
16433d6423SLionel Sambuc 	  return(EINVAL);
17433d6423SLionel Sambuc 
18433d6423SLionel Sambuc   if(rip->i_sp->s_rd_only) {
19433d6423SLionel Sambuc   	put_inode(rip);
20433d6423SLionel Sambuc 	return EROFS;
21433d6423SLionel Sambuc   }
22433d6423SLionel Sambuc 
23433d6423SLionel Sambuc   /* Now make the change. Clear setgid bit if file is not in caller's grp */
24*ccaeedb2SDavid van Moolenbroek   rip->i_mode = (rip->i_mode & ~ALL_MODES) | (*mode & ALL_MODES);
25433d6423SLionel Sambuc   rip->i_update |= CTIME;
26433d6423SLionel Sambuc   IN_MARKDIRTY(rip);
27433d6423SLionel Sambuc 
28433d6423SLionel Sambuc   /* Return full new mode to caller. */
29*ccaeedb2SDavid van Moolenbroek   *mode = rip->i_mode;
30433d6423SLionel Sambuc 
31433d6423SLionel Sambuc   put_inode(rip);
32433d6423SLionel Sambuc   return(OK);
33433d6423SLionel Sambuc }
34433d6423SLionel Sambuc 
35433d6423SLionel Sambuc 
36433d6423SLionel Sambuc /*===========================================================================*
37433d6423SLionel Sambuc  *				fs_chown				     *
38433d6423SLionel Sambuc  *===========================================================================*/
fs_chown(ino_t ino_nr,uid_t uid,gid_t gid,mode_t * mode)39*ccaeedb2SDavid van Moolenbroek int fs_chown(ino_t ino_nr, uid_t uid, gid_t gid, mode_t *mode)
40433d6423SLionel Sambuc {
41433d6423SLionel Sambuc   register struct inode *rip;
42433d6423SLionel Sambuc 
43433d6423SLionel Sambuc   /* Temporarily open the file. */
44*ccaeedb2SDavid van Moolenbroek   if( (rip = get_inode(fs_dev, ino_nr)) == NULL)
45433d6423SLionel Sambuc 	  return(EINVAL);
46433d6423SLionel Sambuc 
47*ccaeedb2SDavid van Moolenbroek   rip->i_uid = uid;
48*ccaeedb2SDavid van Moolenbroek   rip->i_gid = gid;
49433d6423SLionel Sambuc   rip->i_mode &= ~(I_SET_UID_BIT | I_SET_GID_BIT);
50433d6423SLionel Sambuc   rip->i_update |= CTIME;
51433d6423SLionel Sambuc   IN_MARKDIRTY(rip);
52433d6423SLionel Sambuc 
53433d6423SLionel Sambuc   /* Update caller on current mode, as it may have changed. */
54*ccaeedb2SDavid van Moolenbroek   *mode = rip->i_mode;
55433d6423SLionel Sambuc   put_inode(rip);
56433d6423SLionel Sambuc 
57433d6423SLionel Sambuc   return(OK);
58433d6423SLionel Sambuc }
59