From nobody Wed Jul 19 13:39:46 2023 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 4R5cPd2Qwqz4nyDf; Wed, 19 Jul 2023 13:39:47 +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 4R5cPb4HTpz4JRP; Wed, 19 Jul 2023 13:39:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689773987; 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=C0b/2DIZ9YAXKTkbLM4m29MjtAbvBbtJC90HXo6zxpg=; b=H7xXJr7KWklcLSCNbuo7T052+QhC1BsPgMLbOnyDCTNevtLaNEQ23FeHiW5VGFu56lWFp3 aSfUalNDamulOLO/M4V2Ql5yDVJ8IWIom5k4FnzBrNdv8a3O2PeOHIfhv/xWJaRQIHopvh 5xl6mkPnXAU2i2HukO6I34UhPmQ8NBGdUrM3qgrIbr60sAZ1uH55uXJe+0j2wtKPUf4Y7v f9z9Ht/KMgZFOQHHO7jGH3OXpdLX3Urc+MmMJ92Z4fyqlCdfr+d0OhEJKlWDonFzI7E/4I xg8btYYTk/P4VpyEscPTZqtlNgjEibUZXw8FWHldHSHOHq/2kXUZLV69/kM8dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689773987; 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=C0b/2DIZ9YAXKTkbLM4m29MjtAbvBbtJC90HXo6zxpg=; b=Urjwft38GEBa42wtuhM9lqckGuSf+30jlkCbKy+/Zzh60SW0neqbxa4xp6viOXDfGx6Hs6 +OTwRlcM0Dv6LbdauuDxftmV3jXpo2vMjVbjDv+vE2/w61BECSWpq1IMz97qpjgJ3cuE4w WFbpkPrPMP3g3lA0D08tYLwIXtodRBaIpWvLADiJKgFJhpEOgrt7saOfEUvdW1i8CZQEmi UeZr1A0FvboJEaB7TtNvYd9pNyfmmTTEeJXPB33e8rwVbSekXqF9AwoiRP6wkuKErKxHEW RTSmpoL8FgGoDH6tAwOBF5P9ttIaR1mBxynKnFk1xrKKKTtfM7qta9CUdQhQgw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1689773987; a=rsa-sha256; cv=none; b=WtwKNKcYkXMg1+W3WM08iIdkX06YCXdYXzDf9biAYiSXV1BCE+SFcdxsVW1jQuMYepaaKc 6WRMESDwdGIkgSx/el/zlTgWeFqQYhRNYMTim5GJx3gYcaYBAPt7TkUG2yqw43y0CkDpoZ 3ftU11r7ntyj4qJRbvy/d+56Ri/XKakuSHiVrebCR0S5zArZAoCbsaBE1cy/bU647QB7AX Mwy96TpYhJu7UQXoHFLREvVCtkyNipNguKLYofuIXbOjK/jGgzbhhWQ+5Gzo9DzUwfrk0k kHdPXJlNXHz+w+0CmpI3DewHGLyfaNg0ejL09tLv1pTlqePvL3NV3M6tNit7Lg== 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 4R5cPb07ljzq87; Wed, 19 Jul 2023 13:39:47 +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 36JDdk2b034074; Wed, 19 Jul 2023 13:39:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36JDdkUX034073; Wed, 19 Jul 2023 13:39:46 GMT (envelope-from git) Date: Wed, 19 Jul 2023 13:39:46 GMT Message-Id: <202307191339.36JDdkUX034073@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Joseph Mingrone Subject: git: 17839f45d86e - main - 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 17839f45d86e79065a65ad3e2522dd69b29a652c Auto-Submitted: auto-generated The branch main has been updated by jrm: URL: https://cgit.FreeBSD.org/src/commit/?id=17839f45d86e79065a65ad3e2522dd69b29a652c commit 17839f45d86e79065a65ad3e2522dd69b29a652c Author: Naman Sood AuthorDate: 2023-07-19 12:44:21 +0000 Commit: Joseph Mingrone CommitDate: 2023-07-19 13:36:09 +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 --- 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 fb1ba9a44f84..6eb5a25e56ec 100644 --- a/usr.sbin/pw/pw.h +++ b/usr.sbin/pw/pw.h @@ -114,3 +114,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 277763041f0a..48f999d3e1d3 100644 --- a/usr.sbin/pw/pw_group.c +++ b/usr.sbin/pw/pw_group.c @@ -418,7 +418,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 bea248c802ed..9029069c6a9f 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -1408,6 +1408,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: