tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: genfs_can_chtimes() (more duplicate code)



YAMAMOTO Takashi wrote:

What's different with the ufs version? that it doesn't rely on VA_UTIMES_NULL?

"rely on"?  i don't understand what you mean.
i guess you misunderstood VA_UTIMES_NULL?

from utimes(2):

     If times is NULL, the access and modification times are set to the cur-
     rent time.  The caller must be the owner of the file, have permission to
     write the file, or be the super-user.

     If times is non-NULL, it is assumed to point to an array of two timeval
     structures.  The access time is set to the value of the first element,
        <snip>
     all three times at once.  The caller must be the owner of the file or be
     the super-user.

VA_UTIMES_NULL means that "times is NULL" in the above text.

For some reason I thought VA_UTIMES_NULL means that we don't need to set
the time because it wasn't specified. Don't ask me why. :)

no objection from me, as far as you don't break the check. :-)

How's this?

       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, or... */
                if (kauth_cred_geteuid(cred) == owner_uid)
                        return (0);

                /* set the times to the current time, and... */
                if ((vaflags & VA_UTIMES_NULL) == 0)
                        return (EPERM);
                                        
                /* have write access. */
                error = VOP_ACCESS(vp, VWRITE, cred));
                if (error)
                        return (error);

                return (0);
       }

Thanks,

-e.


Home | Main Index | Thread Index | Old Index