From nobody Thu May 09 13:16:52 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 4VZsx12TN1z5JfnL; Thu, 09 May 2024 13:16:53 +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 4VZsx106LYz584G; Thu, 9 May 2024 13:16:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715260613; 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=8hcTek0FEOa2Y4ZiTHCsC6ssmvkZW8TYUJHCwI2SQxQ=; b=vexMNe0T0HF+81MalcPINt7vZF9+cdl434Uy/bThsjWpESvm2pVaJltJNyPNWeXBhWrU+j RKuvTc6K6H4EqE1UR8k4kY4EZbJRbcu81fB/JNDpU2TuhBwVqKMszQFeHpwrHrt3sjqpxr pLTGHupzdSTHV4wnsnAlD3qp1iUvWQZu+yqb6lBOCk+wxJgzgS1OygGjTCjd2g5DxB0rfb K3bVqxl0NwbtvTcpxCyhKagamGRTscO/4pDB69/lU5sq0DVRuI+vFvUFylq9pSgTE1btWb r3hE0bbawdnZ4iOQf1v3ysDjavVxPBwFh+GBeE8VBF5fH3SkEhL7r4NL+wVuTA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715260613; a=rsa-sha256; cv=none; b=aK53HdPT/1P8Y4yPjP9xRBVKDuy5i42GpPL7Avvt+N4WRaZ8SJ2nrm8Sn/uWF/YPxtTGSK +Kg5Pp2Ynlo8Mdz2n6x2Wvla814tl0jm66bYCKXtHq8+juKbBst1CC5IW/rQOokw016E42 w8QP1t5moV3RlDYYVQCdt0W95Z9n/TbwJB8SEMEL6TgIqNfc1zt99lG0rrGDi5Mv47Nfzg YFYGDxx7FWRrvjruurSo0772F8qBUZ0ZQGKPEVOfMjx/OmLaIfWTJnk3ysJHmbmVBhAKxT xk+/eWJzFIfnlxgWMjfCWihbo1EY5bRQSdLluR4GgDRKF9hR8lXIgAzAOtAneQ== 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=1715260613; 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=8hcTek0FEOa2Y4ZiTHCsC6ssmvkZW8TYUJHCwI2SQxQ=; b=ZEtQcd1EXaUw6K2mE8yuAR7zOMAOPuqW8ec/9u6wxmdfNMzHC/OHHkk0fy08zI2HKeyZvy 1qwXhcTbC5ABXw+gv5wwZhvoy8nQ1Fdj0iXjQmtFmYH+U3A7fVN4rPI4NYJLbFrmkU/nzN pbDLLz3zRC1BY4H0xvYDN39I1u3qg96UaWAvaAXdT1rY/CBr7taar7YGSQcPLMRGEfiFta 05Cj7mwL2uBi+eSlkKDo5GJc2GT57IYyu5f2bL1csBnKX6NJjEyX3XzQLnKMuC3eGQIj1Q yyMl/gt9nnWn0C2Hh9AcPVrMEMfyCdWboSu1kGLA0Pj/Ktxa6w9bUYgAEAHuRw== 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 4VZsx06qdGz18rl; Thu, 9 May 2024 13:16:52 +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 449DGq76032184; Thu, 9 May 2024 13:16:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 449DGq8G032181; Thu, 9 May 2024 13:16:52 GMT (envelope-from git) Date: Thu, 9 May 2024 13:16:52 GMT Message-Id: <202405091316.449DGq8G032181@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: 3532d9c66ece - stable/13 - pw: Ensure group membership is not duplicated 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: 3532d9c66ecefd356ec670f014e4647537b59ef1 Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=3532d9c66ecefd356ec670f014e4647537b59ef1 commit 3532d9c66ecefd356ec670f014e4647537b59ef1 Author: Naman Sood AuthorDate: 2023-07-19 12:44:21 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-05-09 11:04:30 +0000 pw: Ensure group membership is not duplicated Fix the following problem: 1. A nonexistent user, someuser, is added to somegroup in /etc/group. 2. someuser is then created with membership in somegroup. The entry for somegroup in /etc/group will then contain somegroup:*:12345:someuser,someuser With this fix, the entry will be somegroup:*:12345:someuser PR: 238995 Reviewed by: bapt, jrm Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41076 (cherry picked from commit 17839f45d86e79065a65ad3e2522dd69b29a652c) --- usr.sbin/pw/pw.h | 2 ++ usr.sbin/pw/pw_group.c | 2 +- usr.sbin/pw/pw_user.c | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/usr.sbin/pw/pw.h b/usr.sbin/pw/pw.h index 54a49f3d691a..5de333ce5e71 100644 --- a/usr.sbin/pw/pw.h +++ b/usr.sbin/pw/pw.h @@ -112,3 +112,5 @@ extern const char *Which[]; uintmax_t strtounum(const char * __restrict, uintmax_t, uintmax_t, const char ** __restrict); + +bool grp_has_member(struct group *grp, const char *name); diff --git a/usr.sbin/pw/pw_group.c b/usr.sbin/pw/pw_group.c index 91300afe3c23..32dec769fb1a 100644 --- a/usr.sbin/pw/pw_group.c +++ b/usr.sbin/pw/pw_group.c @@ -413,7 +413,7 @@ pw_group_del(int argc, char **argv, char *arg1) return (EXIT_SUCCESS); } -static bool +bool grp_has_member(struct group *grp, const char *name) { int j; diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index 78cdfc98c447..ac04dc2fa89b 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -1454,6 +1454,9 @@ pw_user_add(int argc, char **argv, char *arg1) if (cmdcnf->groups != NULL) { for (i = 0; i < cmdcnf->groups->sl_cur; i++) { grp = GETGRNAM(cmdcnf->groups->sl_str[i]); + /* gr_add doesn't check if new member is already in group */ + if (grp_has_member(grp, pwd->pw_name)) + continue; grp = gr_add(grp, pwd->pw_name); /* * grp can only be NULL in 2 cases: