Skip to content

Commit

Permalink
UTILS: swap order of seteuid()/setegid()
Browse files Browse the repository at this point in the history
Otherwise it fails with:
```
6906  16:40:32.455571 setresuid(-1, 996, -1) = 0
6906  16:40:32.455590 setresgid(-1, 993, -1) = -1 EPERM (Operation not permitted)
```

Reviewed-by: Alejandro López <[email protected]>
Reviewed-by: Iker Pedrosa <[email protected]>
  • Loading branch information
alexey-tikhonov committed Aug 9, 2023
1 parent 91d32fe commit fcfffb5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/util/usertools.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,29 +860,30 @@ void sss_set_sssd_user_eid(void)

if (geteuid() == 0) {
sss_sssd_user_uid_and_gid(&uid, &gid);
if (seteuid(uid) != EOK) {
DEBUG(SSSDBG_MINOR_FAILURE,
"Failed to set euid to %"SPRIuid": %s\n",
uid, sss_strerror(errno));
}

if (setegid(gid) != EOK) {
DEBUG(SSSDBG_MINOR_FAILURE,
DEBUG(SSSDBG_IMPORTANT_INFO,
"Failed to set egid to %"SPRIgid": %s\n",
gid, sss_strerror(errno));
}
if (seteuid(uid) != EOK) {
DEBUG(SSSDBG_IMPORTANT_INFO,
"Failed to set euid to %"SPRIuid": %s\n",
uid, sss_strerror(errno));
}
}
}

void sss_restore_sssd_user_eid(void)
{
if (getuid() == 0) {
if (seteuid(getuid()) != EOK) {
DEBUG(SSSDBG_MINOR_FAILURE,
DEBUG(SSSDBG_IMPORTANT_INFO,
"Failed to restore euid: %s\n",
sss_strerror(errno));
}
if (setegid(getgid()) != EOK) {
DEBUG(SSSDBG_MINOR_FAILURE,
DEBUG(SSSDBG_IMPORTANT_INFO,
"Failed to restore egid: %s\n",
sss_strerror(errno));
}
Expand Down

0 comments on commit fcfffb5

Please sign in to comment.