From nobody Thu May 09 13:16:25 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 4VZswT4pcVz5JfYp; Thu, 09 May 2024 13:16:25 +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 4VZswT4KCHz57fQ; Thu, 9 May 2024 13:16:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715260585; 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=2sozntcgV3+66hPsAE0UNkz/lKrODmFLY5WlHRolKyU=; b=VFVvqkiBpcNwvFMz0tObwAACJGm9an/JTJMIUwi7jluSlnC8jMTCDzM+QtD3y9q1FmNoQf BFUZSz2Gu/Z0AJ7xZ0kKSl8GM3Ca2cJynY1uEI0/3kLiCyIjXlLxpQn0Z6oARLDUi2drOK NmxB6lNB9JYGrFUioWlfggySCVamqh1kB+dh+eapd4hjvOKpksjaOGBwZq88rbKxScJKoP JBq3bAcMS26DDdWT2CjKJqVnDg4L6Ko4GzDoHBHA+BGYYO+qd8HnyyvdR+1ITbrcHILDwR h/f/wLUhM355Hm4Rx41S4d96YZ3tHji9WRaIzGzniC2qY4Epu57efGO/J9htlw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715260585; a=rsa-sha256; cv=none; b=VWzp1B/SzwIsujgXh6bvO+pFlpWwpPfN0dMrCBzGcaNL95fkyAUBEoRyR9h2/Gdp/05Gkn UJ7vvK2ZybvlryKC3kUHNDEXAewOmKErLLX9iK8I205VXZRnSaZfo+L52ICuVdVIn/kYbF Qb+Mtgd+yDjPyH3Z4JQD21CwsrUAQ1HYeQWcmb64+I0rQzn2FKrSk0j2hAiNyD6FwKWgtp VRdGGmI19jGFF+4TIGSK43hzE2XpjPCkthi7TWc+figvksTSOx1zg+xVGq6WBJTqKdHRRP ZOpP4RsPH29bfY2KJSMENHKqHk93QUZhTODfs61ZmKDGrT3XYPngqoNJ/P5INg== 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=1715260585; 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=2sozntcgV3+66hPsAE0UNkz/lKrODmFLY5WlHRolKyU=; b=VOVOGb+889OQ5Ym8X/OENp4uv3MZ9Dec+s53SppirKyLRRLZM5olKnVU5ZGhD+F6iAYsed YTcBYK7xbHi5QwvE3lpAl0AGG+UKlmTwYG5DIYISvV1T9K7Zt/n6lhsaCjZ8Srjx9K+mdO wEE/6oDyVmQAw45vmalqVvD8bTTD9iAEokl8yteoIGJ1WkWd5YmOl48Hu5rsrUOpAALKJB L6VB3lrlxLyWaqRlRh1RxxzwQ3e1qAuqg9Mgy/JKNgYLQE0sgIL2aXPXG+TiC4xgN2eyzO E+mok5HRwqdmD/bRLM8Wj6PfJv4WUgKqGnZ9aZNgtjNCzKrXHPxgJewHwqS6WQ== 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 4VZswT3sR0z19B2; Thu, 9 May 2024 13:16:25 +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 449DGPig031889; Thu, 9 May 2024 13:16:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 449DGPdX031886; Thu, 9 May 2024 13:16:25 GMT (envelope-from git) Date: Thu, 9 May 2024 13:16:25 GMT Message-Id: <202405091316.449DGPdX031886@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: 2f59ee828754 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 2f59ee8287548225e7c71db987574fe043ed1be4 Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=2f59ee8287548225e7c71db987574fe043ed1be4 commit 2f59ee8287548225e7c71db987574fe043ed1be4 Author: Dag-Erling Smørgrav AuthorDate: 2024-05-06 16:18:39 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-05-09 10:59:02 +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 6875d931a1d2..89354b249935 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -146,7 +146,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); } @@ -708,9 +708,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); @@ -772,9 +776,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); @@ -855,9 +863,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); @@ -1003,9 +1015,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)); } @@ -1022,9 +1038,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)); } @@ -1291,9 +1311,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"); @@ -1604,9 +1628,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"); @@ -1787,7 +1815,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), @@ -1808,7 +1836,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 3b495482eb05..b4efa42bada7 100755 --- a/usr.sbin/pw/tests/pw_useradd_test.sh +++ b/usr.sbin/pw/tests/pw_useradd_test.sh @@ -313,6 +313,22 @@ user_add_R_intermed_body() { test -d ${HOME}/a/b/c/foo || atf_fail "user directory not created" } +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 @@ -511,6 +527,7 @@ atf_init_test_cases() { atf_add_test_case user_add_R atf_add_test_case user_add_R_no_symlink atf_add_test_case user_add_R_intermed + 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