Remove building with NOCRYPTO option
[minix.git] / minix / lib / libpuffs / protect.c
blobef34808484b29177ec6cadf0ae4088f6068943b4
1 /* Created (MFS based):
2 * June 2011 (Evgeniy Ivanov)
3 */
5 #include "fs.h"
7 #include "puffs.h"
8 #include "puffs_priv.h"
11 /*===========================================================================*
12 * fs_chmod *
13 *===========================================================================*/
14 int fs_chmod(ino_t ino_nr, mode_t *mode)
16 /* Perform the chmod(name, mode) system call. */
17 struct puffs_node *pn;
18 struct vattr va;
19 PUFFS_MAKECRED(pcr, &global_kcred);
21 if (global_pu->pu_ops.puffs_node_setattr == NULL)
22 return(EINVAL);
24 if ((pn = puffs_pn_nodewalk(global_pu, find_inode_cb, &ino_nr)) == NULL)
25 return(EINVAL);
27 puffs_vattr_null(&va);
28 /* Clear setgid bit if file is not in caller's grp */
29 va.va_mode = (pn->pn_va.va_mode & ~ALL_MODES) | (*mode & ALL_MODES);
30 (void)clock_time(&va.va_ctime);
32 if (global_pu->pu_ops.puffs_node_setattr(global_pu, pn, &va, pcr) != 0)
33 return(EINVAL);
35 /* Return full new mode to caller. */
36 *mode = pn->pn_va.va_mode;
38 return(OK);
42 /*===========================================================================*
43 * fs_chown *
44 *===========================================================================*/
45 int fs_chown(ino_t ino_nr, uid_t uid, gid_t gid, mode_t *mode)
47 struct puffs_node *pn;
48 struct vattr va;
49 PUFFS_MAKECRED(pcr, &global_kcred);
51 if ((pn = puffs_pn_nodewalk(global_pu, find_inode_cb, &ino_nr)) == NULL)
52 return(EINVAL);
54 puffs_vattr_null(&va);
55 va.va_uid = uid;
56 va.va_gid = gid;
57 va.va_mode = pn->pn_va.va_mode & ~(I_SET_UID_BIT | I_SET_GID_BIT);
58 (void)clock_time(&va.va_ctime);
60 if (global_pu->pu_ops.puffs_node_setattr(global_pu, pn, &va, pcr) != 0)
61 return(EINVAL);
63 /* Update caller on current mode, as it may have changed. */
64 *mode = pn->pn_va.va_mode;
66 return(OK);