Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xinstall If unprivileged, don't even look up user or...



details:   https://anonhg.NetBSD.org/src/rev/96d700d8d638
branches:  trunk
changeset: 495380:96d700d8d638
user:      cgd <cgd%NetBSD.org@localhost>
date:      Thu Jul 27 03:57:50 2000 +0000

description:
If unprivileged, don't even look up user or group name.  (always set uid and
gid to -1.)  Don't bother checking 'unpriv' when it's redundant with the
uid/gid == -1 check.  (Doing the uid/gid handling consistently also fixes
the directory-creation code, which didn't check unpriv and did chmod/chown
anyway.)  One minor spaces/tabs cleanup at one of the uid/gid checks.

diffstat:

 usr.bin/xinstall/xinstall.c |  46 ++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 21 deletions(-)

diffs (95 lines):

diff -r 50f2ca8f147b -r 96d700d8d638 usr.bin/xinstall/xinstall.c
--- a/usr.bin/xinstall/xinstall.c       Thu Jul 27 03:48:08 2000 +0000
+++ b/usr.bin/xinstall/xinstall.c       Thu Jul 27 03:57:50 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xinstall.c,v 1.40 2000/07/27 03:45:02 cgd Exp $        */
+/*     $NetBSD: xinstall.c,v 1.41 2000/07/27 03:57:50 cgd Exp $        */
 
 /*
  * Copyright (c) 1987, 1993
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)xinstall.c 8.1 (Berkeley) 7/21/93";
 #else
-__RCSID("$NetBSD: xinstall.c,v 1.40 2000/07/27 03:45:02 cgd Exp $");
+__RCSID("$NetBSD: xinstall.c,v 1.41 2000/07/27 03:57:50 cgd Exp $");
 #endif
 #endif /* not lint */
 
@@ -223,12 +223,18 @@
                usage();
 
        /* get group and owner id's */
-       if (group && !(gp = getgrnam(group)) && !isdigit((unsigned char)*group))
-               errx(1, "unknown group %s", group);
-       gid = (group) ? ((gp) ? gp->gr_gid : atoi(group)) : -1;
-       if (owner && !(pp = getpwnam(owner)) && !isdigit((unsigned char)*owner))
-               errx(1, "unknown user %s", owner);
-       uid = (owner) ? ((pp) ? pp->pw_uid : atoi(owner)) : -1;
+       if (unpriv)
+               uid = gid = -1;
+       else {
+               if (group && !(gp = getgrnam(group)) &&
+                   !isdigit((unsigned char)*group))
+                       errx(1, "unknown group %s", group);
+               gid = (group) ? ((gp) ? gp->gr_gid : atoi(group)) : -1;
+               if (owner && !(pp = getpwnam(owner)) &&
+                   !isdigit((unsigned char)*owner))
+                       errx(1, "unknown user %s", owner);
+               uid = (owner) ? ((pp) ? pp->pw_uid : atoi(owner)) : -1;
+       }
 
        if (dodir) {
                for (; *argv != NULL; ++argv)
@@ -251,7 +257,7 @@
                if (stat(*argv, &from_sb))
                        err(1, "%s", *argv);
                if (!S_ISREG(to_sb.st_mode))
-                       errx(1, "%s: %s", to_name, strerror(EFTYPE));
+                       errx(1, "%s: not a regular file", to_name);
                if (!dolink && to_sb.st_dev == from_sb.st_dev &&
                    to_sb.st_ino == from_sb.st_ino)
                        errx(1, "%s and %s are the same file", *argv, to_name);
@@ -359,7 +365,7 @@
                if (stat(from_name, &from_sb))
                        err(1, "%s", from_name);
                if (!S_ISREG(from_sb.st_mode))
-                       errx(1, "%s: %s", from_name, strerror(EFTYPE));
+                       errx(1, "%s: not a regular file", to_name);
                /* Build the target path. */
                if (flags & DIRECTORY) {
                        (void)snprintf(pathbuf, sizeof(pathbuf), "%s/%s",
@@ -442,16 +448,14 @@
                  err(1, "stripping %s", to_name);
        }
 
-       if (!unpriv) {
-               /*
-                * Set owner, group, mode for target; do the chown first,
-                * chown may lose the setuid bits.
-                */
-               if ((gid != -1 || uid != -1) && fchown(to_fd, uid, gid)) {
-                       serrno = errno;
-                       (void)unlink(to_name);
-                       errx(1, "%s: chown/chgrp: %s", to_name, strerror(serrno));
-               }
+       /*
+        * Set owner, group, mode for target; do the chown first,
+        * chown may lose the setuid bits.
+        */
+       if ((gid != -1 || uid != -1) && fchown(to_fd, uid, gid)) {
+               serrno = errno;
+               (void)unlink(to_name);
+               errx(1, "%s: chown/chgrp: %s", to_name, strerror(serrno));
        }
        if (fchmod(to_fd, mode)) {
                serrno = errno;
@@ -660,7 +664,7 @@
        if (((gid != -1 || uid != -1) && chown(path, uid, gid)) ||
             chmod(path, mode)) {
                 warn("%s", path);
-        }
+       }
 }
 
 /*



Home | Main Index | Thread Index | Old Index