From owner-svn-src-head@FreeBSD.ORG Sun Jun 7 19:59:02 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BB9206CC; Sun, 7 Jun 2015 19:59:02 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9CC3513C4; Sun, 7 Jun 2015 19:59:02 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t57Jx2RI066011; Sun, 7 Jun 2015 19:59:02 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t57Jx1ut066003; Sun, 7 Jun 2015 19:59:01 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201506071959.t57Jx1ut066003@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Sun, 7 Jun 2015 19:59:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284133 - head/usr.sbin/pw X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jun 2015 19:59:02 -0000 Author: bapt Date: Sun Jun 7 19:59:01 2015 New Revision: 284133 URL: https://svnweb.freebsd.org/changeset/base/284133 Log: Fix duplicate checking Modified: head/usr.sbin/pw/pw.c head/usr.sbin/pw/pw_group.c head/usr.sbin/pw/pw_user.c head/usr.sbin/pw/pwupd.h Modified: head/usr.sbin/pw/pw.c ============================================================================== --- head/usr.sbin/pw/pw.c Sun Jun 7 19:48:21 2015 (r284132) +++ head/usr.sbin/pw/pw.c Sun Jun 7 19:59:01 2015 (r284133) @@ -269,6 +269,10 @@ main(int argc, char *argv[]) if (errstr != NULL) errx(EX_USAGE, "Bad id '%s': %s", optarg, errstr); + break; + case 'o': + conf.checkduplicate = true; + break; default: addarg(&arglist, ch, optarg); break; Modified: head/usr.sbin/pw/pw_group.c ============================================================================== --- head/usr.sbin/pw/pw_group.c Sun Jun 7 19:48:21 2015 (r284132) +++ head/usr.sbin/pw/pw_group.c Sun Jun 7 19:59:01 2015 (r284133) @@ -45,7 +45,7 @@ static struct passwd *lookup_pwent(const static void delete_members(char ***members, int *grmembers, int *i, struct carg *arg, struct group *grp); static int print_group(struct group * grp); -static gid_t gr_gidpolicy(struct userconf * cnf, struct cargs * args); +static gid_t gr_gidpolicy(struct userconf * cnf, long id); int pw_group(int mode, char *name, long id, struct cargs * args) @@ -73,7 +73,7 @@ pw_group(int mode, char *name, long id, * next gid to stdout */ if (mode == M_NEXT) { - gid_t next = gr_gidpolicy(cnf, args); + gid_t next = gr_gidpolicy(cnf, id); if (getarg(args, 'q')) return next; printf("%u\n", next); @@ -145,7 +145,7 @@ pw_group(int mode, char *name, long id, grp = &fakegroup; grp->gr_name = pw_checkname(name, 0); grp->gr_passwd = "*"; - grp->gr_gid = gr_gidpolicy(cnf, args); + grp->gr_gid = gr_gidpolicy(cnf, id); grp->gr_mem = members; } @@ -336,19 +336,18 @@ delete_members(char ***members, int *grm static gid_t -gr_gidpolicy(struct userconf * cnf, struct cargs * args) +gr_gidpolicy(struct userconf * cnf, long id) { struct group *grp; gid_t gid = (gid_t) - 1; - struct carg *a_gid = getarg(args, 'g'); /* * Check the given gid, if any */ - if (a_gid != NULL) { - gid = (gid_t) atol(a_gid->val); + if (id > 0) { + gid = (gid_t) id; - if ((grp = GETGRGID(gid)) != NULL && getarg(args, 'o') == NULL) + if ((grp = GETGRGID(gid)) != NULL && conf.checkduplicate) errx(EX_DATAERR, "gid `%u' has already been allocated", grp->gr_gid); } else { struct bitmap bm; Modified: head/usr.sbin/pw/pw_user.c ============================================================================== --- head/usr.sbin/pw/pw_user.c Sun Jun 7 19:48:21 2015 (r284132) +++ head/usr.sbin/pw/pw_user.c Sun Jun 7 19:59:01 2015 (r284133) @@ -54,7 +54,7 @@ static char locked_str[] = "*LOCKED*"; static int delete_user(struct userconf *cnf, struct passwd *pwd, char *name, int delete, int mode); static int print_user(struct passwd * pwd); -static uid_t pw_uidpolicy(struct userconf * cnf, struct cargs * args); +static uid_t pw_uidpolicy(struct userconf * cnf, long id); static uid_t pw_gidpolicy(struct cargs * args, char *nam, gid_t prefer); static time_t pw_pwdpolicy(struct userconf * cnf, struct cargs * args); static time_t pw_exppolicy(struct userconf * cnf, struct cargs * args); @@ -160,7 +160,7 @@ pw_user(int mode, char *name, long id, s */ if (mode == M_NEXT) { - uid_t next = pw_uidpolicy(cnf, args); + uid_t next = pw_uidpolicy(cnf, id); if (getarg(args, 'q')) return next; printf("%u:", next); @@ -389,8 +389,8 @@ pw_user(int mode, char *name, long id, s edited = 1; } - if ((arg = getarg(args, 'u')) != NULL && isdigit((unsigned char)*arg->val)) { - pwd->pw_uid = (uid_t) atol(arg->val); + if (id > 0 && isdigit((unsigned char)*arg->val)) { + pwd->pw_uid = (uid_t)id; edited = 1; if (pwd->pw_uid != 0 && strcmp(pwd->pw_name, "root") == 0) errx(EX_DATAERR, "can't change uid of `root' account"); @@ -502,7 +502,7 @@ pw_user(int mode, char *name, long id, s pwd = &fakeuser; pwd->pw_name = name; pwd->pw_class = cnf->default_class ? cnf->default_class : ""; - pwd->pw_uid = pw_uidpolicy(cnf, args); + pwd->pw_uid = pw_uidpolicy(cnf, id); pwd->pw_gid = pw_gidpolicy(args, pwd->pw_name, (gid_t) pwd->pw_uid); pwd->pw_change = pw_pwdpolicy(cnf, args); pwd->pw_expire = pw_exppolicy(cnf, args); @@ -741,19 +741,18 @@ pw_user(int mode, char *name, long id, s static uid_t -pw_uidpolicy(struct userconf * cnf, struct cargs * args) +pw_uidpolicy(struct userconf * cnf, long id) { struct passwd *pwd; uid_t uid = (uid_t) - 1; - struct carg *a_uid = getarg(args, 'u'); /* * Check the given uid, if any */ - if (a_uid != NULL) { - uid = (uid_t) atol(a_uid->val); + if (id > 0) { + uid = (uid_t) id; - if ((pwd = GETPWUID(uid)) != NULL && getarg(args, 'o') == NULL) + if ((pwd = GETPWUID(uid)) != NULL && conf.checkduplicate) errx(EX_DATAERR, "uid `%u' has already been allocated", pwd->pw_uid); } else { struct bitmap bm; Modified: head/usr.sbin/pw/pwupd.h ============================================================================== --- head/usr.sbin/pw/pwupd.h Sun Jun 7 19:48:21 2015 (r284132) +++ head/usr.sbin/pw/pwupd.h Sun Jun 7 19:59:01 2015 (r284133) @@ -87,6 +87,7 @@ struct pwconf { bool dryrun; bool pretty; bool v7; + bool checkduplicate; struct userconf *userconf; };