diff options
author | bapt <bapt@FreeBSD.org> | 2015-07-14 12:21:47 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-07-14 12:21:47 +0000 |
commit | c18dc3d1d64644fb485bf5fdf66a7c3dbcda41a2 (patch) | |
tree | 647233c4c343ab358d65264d2e77e3a1a44b6bbd /usr.sbin | |
parent | fd9aec951b3f9ab80dca6190e8839b7c98ce9571 (diff) | |
download | FreeBSD-src-c18dc3d1d64644fb485bf5fdf66a7c3dbcda41a2.zip FreeBSD-src-c18dc3d1d64644fb485bf5fdf66a7c3dbcda41a2.tar.gz |
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 <janm@transactionware.com>
Approved by: re (marius)
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pw/pw.c | 3 | ||||
-rw-r--r-- | usr.sbin/pw/pw_user.c | 18 |
2 files changed, 7 insertions, 14 deletions
diff --git a/usr.sbin/pw/pw.c b/usr.sbin/pw/pw.c index 30fb55b..f4704a4 100644 --- a/usr.sbin/pw/pw.c +++ b/usr.sbin/pw/pw.c @@ -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); diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index c3b2751..5b46013 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -748,7 +748,7 @@ pw_uidpolicy(struct userconf * cnf, long id) /* * 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 *nam, gid_t prefer) 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 *nam, gid_t prefer) * 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; |