Author: bapt
Date: Tue Jul 14 12:21:47 2015
New Revision: 285536
URL: https://svnweb.freebsd.org/changeset/base/285536

Log:
  MFC: r285414, r285440, r285441, r285443
  
  - allow to create users with uid 0
  - fix check duplicates logic
  - fix gid policy to be in sync with uid if possible
  
  Reported by:  Jan Mikkelsen <j...@transactionware.com>
  Approved by:  re (marius)

Modified:
  stable/10/usr.sbin/pw/pw.c
  stable/10/usr.sbin/pw/pw_user.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/pw/pw.c
==============================================================================
--- stable/10/usr.sbin/pw/pw.c  Tue Jul 14 12:16:14 2015        (r285535)
+++ stable/10/usr.sbin/pw/pw.c  Tue Jul 14 12:21:47 2015        (r285536)
@@ -137,6 +137,7 @@ main(int argc, char *argv[])
        relocated = nis = false;
        memset(&conf, 0, sizeof(conf));
        strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath));
+       conf.checkduplicate = true;
 
        LIST_INIT(&arglist);
 
@@ -281,7 +282,7 @@ main(int argc, char *argv[])
                                    errstr);
                        break;
                case 'o':
-                       conf.checkduplicate = true;
+                       conf.checkduplicate = false;
                        break;
                default:
                        addarg(&arglist, ch, optarg);

Modified: stable/10/usr.sbin/pw/pw_user.c
==============================================================================
--- stable/10/usr.sbin/pw/pw_user.c     Tue Jul 14 12:16:14 2015        
(r285535)
+++ stable/10/usr.sbin/pw/pw_user.c     Tue Jul 14 12:21:47 2015        
(r285536)
@@ -748,7 +748,7 @@ pw_uidpolicy(struct userconf * cnf, long
        /*
         * Check the given uid, if any
         */
-       if (id > 0) {
+       if (id >= 0) {
                uid = (uid_t) id;
 
                if ((pwd = GETPWUID(uid)) != NULL && conf.checkduplicate)
@@ -824,7 +824,7 @@ pw_gidpolicy(struct cargs * args, char *
                gid = grp->gr_gid;  /* Already created? Use it anyway... */
        } else {
                struct cargs    grpargs;
-               char            tmp[32];
+               gid_t           grid = -1;
 
                LIST_INIT(&grpargs);
 
@@ -837,26 +837,18 @@ pw_gidpolicy(struct cargs * args, char *
                 * user's name dups an existing group, then the group add
                 * function will happily handle that case for us and exit.
                 */
-               if (GETGRGID(prefer) == NULL) {
-                       snprintf(tmp, sizeof(tmp), "%u", prefer);
-                       addarg(&grpargs, 'g', tmp);
-               }
+               if (GETGRGID(prefer) == NULL)
+                       grid = prefer;
                if (conf.dryrun) {
                        addarg(&grpargs, 'q', NULL);
                        gid = pw_group(M_NEXT, nam, -1, &grpargs);
                }
                else
                {
-                       pw_group(M_ADD, nam, -1, &grpargs);
+                       pw_group(M_ADD, nam, grid, &grpargs);
                        if ((grp = GETGRNAM(nam)) != NULL)
                                gid = grp->gr_gid;
                }
-               a_gid = LIST_FIRST(&grpargs);
-               while (a_gid != NULL) {
-                       struct carg    *t = LIST_NEXT(a_gid, list);
-                       LIST_REMOVE(a_gid, list);
-                       a_gid = t;
-               }
        }
        ENDGRENT();
        return gid;
_______________________________________________
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"

Reply via email to