From owner-svn-src-all@freebsd.org Tue Feb 18 11:26:58 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EFDF525CD64; Tue, 18 Feb 2020 11:26:57 +0000 (UTC) (envelope-from cy@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48MJTs4nsbz49Nk; Tue, 18 Feb 2020 11:26:57 +0000 (UTC) (envelope-from cy@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 769E91F399; Tue, 18 Feb 2020 11:26:56 +0000 (UTC) (envelope-from cy@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 01IBQu7s016283; Tue, 18 Feb 2020 11:26:56 GMT (envelope-from cy@FreeBSD.org) Received: (from cy@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 01IBQuea016282; Tue, 18 Feb 2020 11:26:56 GMT (envelope-from cy@FreeBSD.org) Message-Id: <202002181126.01IBQuea016282@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cy set sender to cy@FreeBSD.org using -f From: Cy Schubert Date: Tue, 18 Feb 2020 11:26:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r358066 - head/lib/libpam/modules/pam_login_access X-SVN-Group: head X-SVN-Commit-Author: cy X-SVN-Commit-Paths: head/lib/libpam/modules/pam_login_access X-SVN-Commit-Revision: 358066 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Feb 2020 11:26:58 -0000 Author: cy Date: Tue Feb 18 11:26:56 2020 New Revision: 358066 URL: https://svnweb.freebsd.org/changeset/base/358066 Log: When pam_login_access(5) fails to match a username it attempts to match the primary group a user belongs to. This commit extends the match to secondary groups a user belongs to as well, just as the Linux pam_access(5) does. Approved by: des (implicit, blanket) Modified: head/lib/libpam/modules/pam_login_access/login_access.c Modified: head/lib/libpam/modules/pam_login_access/login_access.c ============================================================================== --- head/lib/libpam/modules/pam_login_access/login_access.c Tue Feb 18 11:26:52 2020 (r358065) +++ head/lib/libpam/modules/pam_login_access/login_access.c Tue Feb 18 11:26:56 2020 (r358066) @@ -17,10 +17,12 @@ static char sccsid[] = "%Z% %M% %I% %E% %U%"; __FBSDID("$FreeBSD$"); #include +#include #include #include #include #include +#include #include #include #include @@ -174,6 +176,9 @@ static int user_match(const char *tok, const char *string) { struct group *group; + struct passwd *passwd; + gid_t *grouplist; + int ngroups = NGROUPS; int i; /* @@ -186,10 +191,37 @@ user_match(const char *tok, const char *string) return (netgroup_match(tok + 1, (char *) 0, string)); } else if (string_match(tok, string)) { /* ALL or exact match */ return (YES); - } else if ((group = getgrnam(tok)) != NULL) {/* try group membership */ - for (i = 0; group->gr_mem[i]; i++) - if (strcasecmp(string, group->gr_mem[i]) == 0) + } else { + if ((passwd = getpwnam(string)) == NULL) + return (NO); + errno = 0; + if ((group = getgrnam(tok)) == NULL) {/* try group membership */ + if (errno != 0) { + syslog(LOG_ERR, "getgrnam() failed for %s: %s", string, strerror(errno)); + } else { + syslog(LOG_NOTICE, "group not found: %s", string); + } + return (NO); + } + errno = 0; + if ((grouplist = calloc(ngroups, sizeof(gid_t))) == NULL) { + if (errno == ENOMEM) { + syslog(LOG_ERR, "cannot allocate memory for grouplist: %s", string); + } + return (NO); + } + if (getgrouplist(string, passwd->pw_gid, grouplist, &ngroups) != 0) { + syslog(LOG_ERR, "getgrouplist() failed for %s", string); + free(grouplist); + return (NO); + } + for (i = 0; i < ngroups; i++) { + if (grouplist[i] == group->gr_gid) { + free(grouplist); return (YES); + } + } + free(grouplist); } return (NO); }