Skip to content

Commit

Permalink
UTILS: switch_creds(): cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-tikhonov committed Nov 19, 2024
1 parent 20b566a commit af9bdd6
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/util/become_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,37 +106,30 @@ errno_t switch_creds(TALLOC_CTX *mem_ctx,
return EOK;
}

if (saved_creds) {
/* save current user credentials */
if (saved_creds) { /* save current user credentials */
size = getgroups(0, NULL);
if (size == -1) {
ret = errno;
DEBUG(SSSDBG_CRIT_FAILURE, "Getgroups failed! (%d, %s)\n",
DEBUG(SSSDBG_CRIT_FAILURE, "getgroups() failed! (%d, %s)\n",
ret, strerror(ret));
goto done;
return ret;
}

ssc = talloc_size(mem_ctx,
(sizeof(struct sss_creds) + size * sizeof(gid_t)));
if (!ssc) {
DEBUG(SSSDBG_CRIT_FAILURE, "Allocation failed!\n");
ret = ENOMEM;
goto done;
return ENOMEM;
}
ssc->num_gids = size;

ssc->num_gids = size;
size = getgroups(ssc->num_gids, ssc->gids);
if (size == -1) {
ret = errno;
DEBUG(SSSDBG_CRIT_FAILURE, "Getgroups failed! (%d, %s)\n",
ret, strerror(ret));
/* free ssc immediately otherwise the code will try to restore
* wrong creds */
talloc_zfree(ssc);
goto done;
if (size != ssc->num_gids) {
DEBUG(SSSDBG_CRIT_FAILURE, "2nd getgroups() returned different list!");
talloc_free(ssc);
return EINVAL;
}

/* we care only about effective ids */
ssc->uid = myuid;
ssc->gid = mygid;
}
Expand Down

0 comments on commit af9bdd6

Please sign in to comment.