Skip to content

Commit 07db76e

Browse files
committed
Med: daemons: Fix user/group checking in based.
This fixes a bug introduced by bcc7c90. The group members returned by getgrnam will only include those users that are listed in /etc/group for that group. It won't include any users for which a group is their primary. In other words, if this is what's in /etc/passwd: hacluster:x:189:189:cluster user:/var/lib/pacemaker:/sbin/nologin And this is what's in /etc/group: haclient:x:189: Then getgrnam will not list hacluster as a member of the haclient group and is_daemon_group_member will return false. We need to re-introduce the primary group check to fix this.
1 parent 18ff34b commit 07db76e

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

daemons/based/based_remote.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,36 @@ remote_auth_timeout_cb(gpointer data)
9595
static bool
9696
is_daemon_group_member(const char *user)
9797
{
98-
const struct group *group = getgrnam(CRM_DAEMON_GROUP);
98+
int rc = pcmk_rc_ok;
99+
gid_t gid = 0;
100+
const struct group *group = NULL;
99101

102+
/* group->gr_mem only contains those users that are listed in /etc/group.
103+
* It won't list the user if the group is their primary (that is, it's in
104+
* the GID field in /etc/passwd (or passwd->pw_gid as returned by getpwent).
105+
* So, we first need to perform a primary group check.
106+
*/
107+
rc = pcmk__lookup_user(user, NULL, &gid);
108+
if (rc != pcmk_rc_ok) {
109+
pcmk__notice("Rejecting remote client: could not find user '%s': %s",
110+
user, pcmk_rc_str(rc));
111+
return false;
112+
}
113+
114+
group = getgrnam(CRM_DAEMON_GROUP);
100115
if (group == NULL) {
101116
pcmk__err("Rejecting remote client: " CRM_DAEMON_GROUP " is not a "
102117
"valid group");
103118
return false;
104119
}
105120

121+
if (group->gr_gid == gid) {
122+
return true;
123+
}
124+
125+
/* If that didn't work, check if CRM_DAEMON_GROUP is a secondary group for
126+
* the user.
127+
*/
106128
for (const char *const *member = (const char *const *) group->gr_mem;
107129
*member != NULL; member++) {
108130

0 commit comments

Comments
 (0)