From nobody Thu May 09 13:16:53 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VZsx230pKz5Jfts; Thu, 09 May 2024 13:16:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VZsx21LvDz586W; Thu, 9 May 2024 13:16:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715260614; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=le0eLlIBsnhzCIkkTitdrdw99Dh5A+MixipMFrlnYlU=; b=oDEuZ/basrpfwj91qIahoAsPXaL2CIsLd48KmoddK4ilSRx3D1Qpbflg3BzcDEWYffyn3d BT16KwV7AZdRmYFVxqWPhTwqLGR5I+Cgu2CF4NuikuNc1SERUOCIVNfbo8vA3yRmVNbDBB eIhg/zdp6CvcLQij2R9I3eN/HCfXBmQdVxbJ7/r9YeFEctp4v3Ka8VAsX+ifWEvy5fkd+k 5gqPQ3OH+nzLXiO8qfqEJyGYiL8cpHpDYTgdKRLLG60fh45mdo/34C5hPyxGdJDKXFy4LG m44kMf1Vvi5Bl/vcNcciqwYgNsAxY4i4d7TxUkv+8nD/m25xcqMs5XYDsqVuzA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715260614; a=rsa-sha256; cv=none; b=B65wHextgqcqhTVUq1XD0vwvT6J9LM41kDrA6jrSElUHK9IVtJfpOqz0X7mvCFNX3tScxr bbHrAN9jqstEA1FfnaBHYYBeOQoWMWrOj7+VTdl0cnqPCqJpSAm1CR3fJbvNi5C8edfUX9 EN5Cf/ALyJLXrklq58Z4rrvNLbA48JmSBRhx7cwVWiXIfE+xanbAVBWL+HD9MB9vIvD11m Ot/KeGD45VbcwKGXMZbIucqlHVHcBt0HnHuhsjcMc0+LWqARaxwLcA/F30LIWdvaYaCbBG rDPGVZ9MffSlfJVEyYqk8agY5jWC54ViPmpBmqkHOdj/8jhpV+DP3HP9q7d3Fw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715260614; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=le0eLlIBsnhzCIkkTitdrdw99Dh5A+MixipMFrlnYlU=; b=mJmeFL19EBAX/ARxblkKeE3KcKzCk9FIFLJuQJHmt9+Uozxh5wa4oTim4fVODTCbht4sNo e5KbLcOg+K4/HnNYBjg44qB3Q6UVNL7HuxhLJO8+1xX0RP64gRRaV2V/Okj3lSi19WhfWe 6QYLU+9UF535wx6woukVbEViq7+3xCEeuFt7puAb1SEiz8zD8kiUn11rGo8quIWAQN/+pI u049p8bhqZCxiQhZCpCWjGOOc8llPhowOzWjZhaqOObJN04jaOXntx1V/1nRD7iGFDFRLk 04JOZfqU9rRlrUuv6caQTy7rgr+U8oMT0vrNkZarnDxWdXcVGKZaklUU2asgXA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VZsx20hVTz18fy; Thu, 9 May 2024 13:16:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 449DGrmi032226; Thu, 9 May 2024 13:16:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 449DGr23032223; Thu, 9 May 2024 13:16:53 GMT (envelope-from git) Date: Thu, 9 May 2024 13:16:53 GMT Message-Id: <202405091316.449DGr23032223@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: e3bd4b9288cc - stable/13 - pw: Rename some enums. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e3bd4b9288cc05ac4b9e6bf7574d4d2f10ae02a2 Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=e3bd4b9288cc05ac4b9e6bf7574d4d2f10ae02a2 commit e3bd4b9288cc05ac4b9e6bf7574d4d2f10ae02a2 Author: Dag-Erling Smørgrav AuthorDate: 2024-05-06 16:18:39 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-05-09 11:05:35 +0000 pw: Rename some enums. Rename `M_PRINT` and `M_UPDATE` to `M_SHOW` and `M_MODIFY` to match the names of the commands they represent. No functional change intended. MFC after: 3 days Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D45096 (cherry picked from commit a9ea647c29cf510a164947251de0d34f53f2bca0) pw: Don't silently ignore unparsed command line arguments. MFC after: 3 days Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D45097 (cherry picked from commit c86119328e6b2cfeb4f9319f6b154524d88caaf4) pw: Test home directory ownership and mode. MFC after: 3 days Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D45099 (cherry picked from commit e12b7446bddcb91b869abef6048910cc15185a33) --- usr.sbin/pw/pw.c | 13 ++++++++-- usr.sbin/pw/pw.h | 22 +++++++++-------- usr.sbin/pw/pw_group.c | 35 ++++++++++++++++++++------ usr.sbin/pw/pw_user.c | 48 ++++++++++++++++++++++++++++-------- usr.sbin/pw/tests/pw_useradd_test.sh | 17 +++++++++++++ 5 files changed, 106 insertions(+), 29 deletions(-) diff --git a/usr.sbin/pw/pw.c b/usr.sbin/pw/pw.c index 063553dd084f..fc17f6dba022 100644 --- a/usr.sbin/pw/pw.c +++ b/usr.sbin/pw/pw.c @@ -101,13 +101,16 @@ static int (*cmdfunc[W_NUM][M_NUM])(int argc, char **argv, char *_name) = { struct pwconf conf; +static int mode = -1; +static int which = -1; + static int getindex(const char *words[], const char *word); static void cmdhelp(int mode, int which); int main(int argc, char *argv[]) { - int mode = -1, which = -1, tmp; + int tmp; struct stat st; char arg, *arg1; bool relocated, nis; @@ -375,5 +378,11 @@ cmdhelp(int mode, int which) fprintf(stderr, "%s", help[which][mode]); } - exit(EXIT_FAILURE); + exit(EX_USAGE); +} + +void +usage(void) +{ + cmdhelp(mode, which); } diff --git a/usr.sbin/pw/pw.h b/usr.sbin/pw/pw.h index 5de333ce5e71..c3725693f91d 100644 --- a/usr.sbin/pw/pw.h +++ b/usr.sbin/pw/pw.h @@ -36,14 +36,14 @@ enum _mode { - M_ADD, - M_DELETE, - M_UPDATE, - M_PRINT, + M_ADD, + M_DELETE, + M_MODIFY, + M_SHOW, M_NEXT, M_LOCK, M_UNLOCK, - M_NUM + M_NUM }; enum _passmode @@ -56,13 +56,13 @@ enum _passmode enum _which { - W_USER, - W_GROUP, - W_NUM + W_USER, + W_GROUP, + W_NUM }; -#define _DEF_DIRMODE (S_IRWXU | S_IRWXG | S_IRWXO) -#define _PW_CONF "pw.conf" +#define _DEF_DIRMODE (S_IRWXU | S_IRWXG | S_IRWXO) +#define _PW_CONF "pw.conf" #define _UC_MAXLINE 1024 #define _UC_MAXSHELLS 32 @@ -114,3 +114,5 @@ uintmax_t strtounum(const char * __restrict, uintmax_t, uintmax_t, const char ** __restrict); bool grp_has_member(struct group *grp, const char *name); + +void usage(void); diff --git a/usr.sbin/pw/pw_group.c b/usr.sbin/pw/pw_group.c index 32dec769fb1a..1941c03aa2c5 100644 --- a/usr.sbin/pw/pw_group.c +++ b/usr.sbin/pw/pw_group.c @@ -273,9 +273,13 @@ pw_group_next(int argc, char **argv, char *arg1 __unused) quiet = true; break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); if (quiet) freopen(_PATH_DEVNULL, "w", stderr); @@ -332,9 +336,13 @@ pw_group_show(int argc, char **argv, char *arg1) all = true; break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); if (quiet) freopen(_PATH_DEVNULL, "w", stderr); @@ -391,9 +399,13 @@ pw_group_del(int argc, char **argv, char *arg1) nis = true; break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); if (quiet) freopen(_PATH_DEVNULL, "w", stderr); @@ -551,9 +563,13 @@ pw_group_add(int argc, char **argv, char *arg1) nis = true; break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); if (quiet) freopen(_PATH_DEVNULL, "w", stderr); @@ -645,9 +661,14 @@ pw_group_mod(int argc, char **argv, char *arg1) nis = true; break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); + if (quiet) freopen(_PATH_DEVNULL, "w", stderr); cnf = get_userconfig(cfg); @@ -697,11 +718,11 @@ pw_group_mod(int argc, char **argv, char *arg1) if ((grp = GETGRNAM(name)) == NULL) errx(EX_SOFTWARE, "group disappeared during update"); - pw_log(cnf, M_UPDATE, W_GROUP, "%s(%ju)", grp->gr_name, + pw_log(cnf, M_MODIFY, W_GROUP, "%s(%ju)", grp->gr_name, (uintmax_t)grp->gr_gid); if (nis && nis_update() == 0) - pw_log(cnf, M_UPDATE, W_GROUP, "NIS maps updated"); + pw_log(cnf, M_MODIFY, W_GROUP, "NIS maps updated"); return (EXIT_SUCCESS); } diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index ac04dc2fa89b..ebe80977fa0e 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -163,7 +163,7 @@ create_and_populate_homedir(struct userconf *cnf, struct passwd *pwd, copymkdir(conf.rootfd, pwd->pw_dir, skelfd, homemode, pwd->pw_uid, pwd->pw_gid, 0); - pw_log(cnf, update ? M_UPDATE : M_ADD, W_USER, "%s(%ju) home %s made", + pw_log(cnf, update ? M_MODIFY : M_ADD, W_USER, "%s(%ju) home %s made", pwd->pw_name, (uintmax_t)pwd->pw_uid, pwd->pw_dir); } @@ -756,9 +756,13 @@ pw_user_next(int argc, char **argv, char *name __unused) quiet = true; break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); if (quiet) freopen(_PATH_DEVNULL, "w", stderr); @@ -820,9 +824,13 @@ pw_user_show(int argc, char **argv, char *arg1) v7 = true; break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); if (quiet) freopen(_PATH_DEVNULL, "w", stderr); @@ -903,9 +911,13 @@ pw_user_del(int argc, char **argv, char *arg1) nis = true; break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); if (quiet) freopen(_PATH_DEVNULL, "w", stderr); @@ -1055,9 +1067,13 @@ pw_user_lock(int argc, char **argv, char *arg1) /* compatibility */ break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); return (pw_userlock(arg1, M_LOCK)); } @@ -1074,9 +1090,13 @@ pw_user_unlock(int argc, char **argv, char *arg1) /* compatibility */ break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); return (pw_userlock(arg1, M_UNLOCK)); } @@ -1343,9 +1363,13 @@ pw_user_add(int argc, char **argv, char *arg1) nis = true; break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); if (geteuid() != 0 && ! dryrun) errx(EX_NOPERM, "you must be root"); @@ -1656,9 +1680,13 @@ pw_user_mod(int argc, char **argv, char *arg1) nis = true; break; default: - exit(EX_USAGE); + usage(); } } + argc -= optind; + argv += optind; + if (argc > 0) + usage(); if (geteuid() != 0 && ! dryrun) errx(EX_NOPERM, "you must be root"); @@ -1839,7 +1867,7 @@ pw_user_mod(int argc, char **argv, char *arg1) if (pwd == NULL) errx(EX_NOUSER, "user '%s' disappeared during update", name); grp = GETGRGID(pwd->pw_gid); - pw_log(cnf, M_UPDATE, W_USER, "%s(%ju):%s(%ju):%s:%s:%s", + pw_log(cnf, M_MODIFY, W_USER, "%s(%ju):%s(%ju):%s:%s:%s", pwd->pw_name, (uintmax_t)pwd->pw_uid, grp ? grp->gr_name : "unknown", (uintmax_t)(grp ? grp->gr_gid : (uid_t)-1), @@ -1860,7 +1888,7 @@ pw_user_mod(int argc, char **argv, char *arg1) } if (nis && nis_update() == 0) - pw_log(cnf, M_UPDATE, W_USER, "NIS maps updated"); + pw_log(cnf, M_MODIFY, W_USER, "NIS maps updated"); return (EXIT_SUCCESS); } diff --git a/usr.sbin/pw/tests/pw_useradd_test.sh b/usr.sbin/pw/tests/pw_useradd_test.sh index b191d51104f7..93a192c59409 100755 --- a/usr.sbin/pw/tests/pw_useradd_test.sh +++ b/usr.sbin/pw/tests/pw_useradd_test.sh @@ -305,6 +305,22 @@ user_add_R_symlink_body() { atf_check -s exit:0 -o inline:"usr/home\n" readlink ${HOME}/home } +atf_test_case user_add_dir +user_add_dir_body() { + populate_root_etc_skel + + atf_check -s exit:0 ${RPW} useradd foo -M 0705 -m + atf_check grep -q '^foo:' $HOME/etc/master.passwd + atf_check test -d ${HOME}/home/foo + atf_check -o save:ugid \ + awk -F: '$1 == "foo" { print $3, $4 }' \ + $HOME/etc/master.passwd + atf_check -o file:ugid \ + stat -f '%u %g' ${HOME}/home/foo + atf_check -o inline:"40705\n" \ + stat -f '%p' ${HOME}/home/foo +} + atf_test_case user_add_skel user_add_skel_body() { populate_root_etc_skel @@ -479,6 +495,7 @@ atf_init_test_cases() { atf_add_test_case user_add_password_from_h atf_add_test_case user_add_R atf_add_test_case user_add_R_symlink + atf_add_test_case user_add_dir atf_add_test_case user_add_skel atf_add_test_case user_add_uid0 atf_add_test_case user_add_uid_too_large