Source-Changes-HG archive

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

[src/netbsd-1-4]: src/usr.sbin/chown Pull up revision 1.21 (requested by darr...



details:   https://anonhg.NetBSD.org/src/rev/39646174983c
branches:  netbsd-1-4
changeset: 470594:39646174983c
user:      he <he%NetBSD.org@localhost>
date:      Thu May 11 10:28:20 2000 +0000

description:
Pull up revision 1.21 (requested by darrenr):
  Deal with user names with `.' in them.  Fixes PR#10043.

diffstat:

 usr.sbin/chown/chown.c |  36 +++++++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 13 deletions(-)

diffs (81 lines):

diff -r 3a6c7a280847 -r 39646174983c usr.sbin/chown/chown.c
--- a/usr.sbin/chown/chown.c    Thu May 11 10:16:36 2000 +0000
+++ b/usr.sbin/chown/chown.c    Thu May 11 10:28:20 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: chown.c,v 1.19 1999/03/14 19:36:05 kleink Exp $        */
+/*     $NetBSD: chown.c,v 1.19.2.1 2000/05/11 10:28:20 he Exp $        */
 
 /*
  * Copyright (c) 1988, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)chown.c    8.8 (Berkeley) 4/4/94";
 #else
-__RCSID("$NetBSD: chown.c,v 1.19 1999/03/14 19:36:05 kleink Exp $");
+__RCSID("$NetBSD: chown.c,v 1.19.2.1 2000/05/11 10:28:20 he Exp $");
 #endif
 #endif /* not lint */
 
@@ -64,7 +64,7 @@
 #include <unistd.h>
 
 static void    a_gid __P((const char *));
-static void    a_uid __P((const char *));
+static int     a_uid __P((const char *));
 static id_t    id __P((const char *, const char *));
        int     main __P((int, char **));
 static void    usage __P((void));
@@ -149,17 +149,19 @@
        uid = (uid_t)-1;
        gid = (gid_t)-1;
        if (ischown) {
-#ifdef SUPPORT_DOT
-               if ((cp = strchr(*argv, '.')) != NULL) {
-                       *cp++ = '\0';
-                       a_gid(cp);
-               } else
-#endif
                if ((cp = strchr(*argv, ':')) != NULL) {
                        *cp++ = '\0';
                        a_gid(cp);
                } 
-               a_uid(*argv);
+#ifdef SUPPORT_DOT
+               else if ((cp = strrchr(*argv, '.')) != NULL) {
+                       if (a_uid(*argv) == -1) {
+                               *cp++ = '\0';
+                               a_gid(cp);
+                       }
+               }
+#endif
+               (void) a_uid(*argv);
        } else 
                a_gid(*argv);
 
@@ -218,15 +220,23 @@
        gid = ((gr = getgrnam(s)) == NULL) ? id(s, "group") : gr->gr_gid;
 }
 
-static void
+static int
 a_uid(s)
        const char *s;
 {
        struct passwd *pw;
 
        if (*s == '\0')                 /* Argument was "[:.]gid". */
-               return;
-       uid = ((pw = getpwnam(s)) == NULL) ? id(s, "user") : pw->pw_uid;
+               return 0;
+       pw = getpwnam(s);
+       if (pw != NULL) {
+               uid = pw->pw_uid;
+               return 0;
+       }
+       if (isalpha(*s))
+               return -1;
+       uid = id(s, "user");
+       return 0;
 }
 
 static id_t



Home | Main Index | Thread Index | Old Index