tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
genfs_can_chtimes() (more duplicate code)
Hi,
We have similar code to check if we can change the timestamps on files
in the following file-systems: ptyfs, smbfs, tmpfs, udf, ext2, ufs,
msdosfs. The code looks like this:
1113 if (!issuperuser) {
1114 if (euid != uid)
1115 return EPERM;
1116 if ((setattrflags & VA_UTIMES_NULL) == 0) {
1117 error = VOP_ACCESS(vp, VWRITE, cred);
1118 if (error)
1119 return error;
1120 }
1121 }
...only much uglier, in file-systems that are not udf. :)
I would like to introduce the following, in genfs_vnops.c:
int
genfs_can_chtimes(vnode_t *vp, u_int vaflags, uid_t owner_uid,
kauth_cred_t cred)
{
int error;
/* Must be root, or... */
error = kauth_authorize_generic(cred,
KAUTH_GENERIC_ISSUSER, NULL);
if (!error)
return (0);
/* must be owner, and... */
if (kauth_cred_geteuid(cred) != owner_uid)
return (EPERM);
/* have write access if changing times. */
if ((vaflags & VA_UTIMES_NULL) == 0) {
error = VOP_ACCESS(vp, VWRITE, cred);
if (error)
return (error);
}
return (0);
}
To be used as a replacement. Usage:
error = genfs_can_chtimes(vp, va_flags, uid, cred);
if (error)
return (error);
Are there any objections to such a change?
Thanks,
-e.
Home |
Main Index |
Thread Index |
Old Index