new naming convention
[unix-history] / usr / src / sys / kern / vfs_syscalls.c
index a208763..205d5c2 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)vfs_syscalls.c      7.2 (Berkeley) %G%
+ *     @(#)vfs_syscalls.c      7.6 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -41,8 +41,9 @@ chdir()
 chroot()
 {
 
 chroot()
 {
 
-       if (suser())
-               chdirec(&u.u_rdir);
+       if (u.u_error = suser(u.u_cred, &u.u_acflag))
+               return;
+       chdirec(&u.u_rdir);
 }
 
 /*
 }
 
 /*
@@ -208,7 +209,7 @@ mknod()
        } *uap = (struct a *)u.u_ap;
        register struct nameidata *ndp = &u.u_nd;
 
        } *uap = (struct a *)u.u_ap;
        register struct nameidata *ndp = &u.u_nd;
 
-       if (!suser())
+       if (u.u_error = suser(u.u_cred, &u.u_acflag))
                return;
        ndp->ni_nameiop = CREATE;
        ndp->ni_segflg = UIO_USERSPACE;
                return;
        ndp->ni_nameiop = CREATE;
        ndp->ni_segflg = UIO_USERSPACE;
@@ -260,7 +261,13 @@ link()
        ip = namei(ndp);        /* well, this routine is doomed anyhow */
        if (ip == NULL)
                return;
        ip = namei(ndp);        /* well, this routine is doomed anyhow */
        if (ip == NULL)
                return;
-       if ((ip->i_mode&IFMT) == IFDIR && !suser()) {
+       if ((ip->i_mode&IFMT) == IFDIR &&
+           (u.u_error = suser(u.u_cred, &u.u_acflag))) {
+               iput(ip);
+               return;
+       }
+       if (ip->i_nlink == LINK_MAX - 1) {
+               u.u_error = EMLINK;
                iput(ip);
                return;
        }
                iput(ip);
                return;
        }
@@ -357,7 +364,8 @@ unlink()
        if (ip == NULL)
                return;
        dp = ndp->ni_pdir;
        if (ip == NULL)
                return;
        dp = ndp->ni_pdir;
-       if ((ip->i_mode&IFMT) == IFDIR && !suser())
+       if ((ip->i_mode&IFMT) == IFDIR &&
+           (u.u_error = suser(u.u_cred, &u.u_acflag)))
                goto out;
        /*
         * Don't unlink a mounted file.
                goto out;
        /*
         * Don't unlink a mounted file.
@@ -557,7 +565,8 @@ fchmod()
        if (fp == NULL)
                return;
        ip = (struct inode *)fp->f_data;
        if (fp == NULL)
                return;
        ip = (struct inode *)fp->f_data;
-       if (u.u_uid != ip->i_uid && !suser())
+       if (u.u_uid != ip->i_uid &&
+           (u.u_error = suser(u.u_cred, &u.u_acflag)))
                return;
        ILOCK(ip);
        u.u_error = chmod1(ip, uap->fmode);
                return;
        ILOCK(ip);
        u.u_error = chmod1(ip, uap->fmode);
@@ -600,8 +609,13 @@ chown()
                int     uid;
                int     gid;
        } *uap = (struct a *)u.u_ap;
                int     uid;
                int     gid;
        } *uap = (struct a *)u.u_ap;
+       register struct nameidata *ndp = &u.u_nd;
 
 
-       if ((ip = owner(uap->fname, NOFOLLOW)) == NULL)
+       ndp->ni_nameiop = LOOKUP | NOFOLLOW;
+       ndp->ni_segflg = UIO_USERSPACE;
+       ndp->ni_dirp = uap->fname;
+       ip = namei(ndp);
+       if (ip == NULL)
                return;
        u.u_error = chown1(ip, uap->uid, uap->gid);
        iput(ip);
                return;
        u.u_error = chown1(ip, uap->uid, uap->gid);
        iput(ip);
@@ -647,9 +661,14 @@ chown1(ip, uid, gid)
                uid = ip->i_uid;
        if (gid == -1)
                gid = ip->i_gid;
                uid = ip->i_uid;
        if (gid == -1)
                gid = ip->i_gid;
-       if (uid != ip->i_uid && !suser())
-               return (u.u_error);
-       if (gid != ip->i_gid && !groupmember((gid_t)gid) && !suser())
+       /*
+        * If we don't own the file, are trying to change the owner
+        * of the file, or are not a member of the target group,
+        * the caller must be superuser or the call fails.
+        */
+       if ((u.u_uid != ip->i_uid || uid != ip->i_uid ||
+           !groupmember((gid_t)gid)) &&
+           (u.u_error = suser(u.u_cred, &u.u_acflag)))
                return (u.u_error);
 #ifdef QUOTA
        if (ip->i_uid == uid)           /* this just speeds things a little */
                return (u.u_error);
 #ifdef QUOTA
        if (ip->i_uid == uid)           /* this just speeds things a little */
@@ -1113,7 +1132,8 @@ maknode(mode, ndp)
        ip->i_nlink = 1;
        ip->i_uid = u.u_uid;
        ip->i_gid = pdir->i_gid;
        ip->i_nlink = 1;
        ip->i_uid = u.u_uid;
        ip->i_gid = pdir->i_gid;
-       if (ip->i_mode & ISGID && !groupmember(ip->i_gid))
+       if (ip->i_mode & ISGID && !groupmember(ip->i_gid) &&
+           (u.u_error = suser(u.u_cred, &u.u_acflag)))
                ip->i_mode &= ~ISGID;
 #ifdef QUOTA
        ip->i_dquot = inoquota(ip);
                ip->i_mode &= ~ISGID;
 #ifdef QUOTA
        ip->i_dquot = inoquota(ip);