Reputation: 118
I have written this function:
void setugid(uid_t uid, gid_t gid) {
uid_t euid = geteuid();
gid_t egid = getegid();
if (setgid(gid) < 0 || setuid(uid) < 0)
assert(0);
}
Assert was executed. In the core dump i found this values of variables:
uid = 8
gid = 12
euid = 0
egid = 0
8 and 12 are correct ids. I have seen such problem when setuid
is followed by setgid
. But not in my case. What can the problem be?
I have found the problem. The user with id 8 has reached its limit of executed processes.
Upvotes: 0
Views: 1237
Reputation: 118
I have found the problem. The user with id 8 has reached its limit of executed processes.
Upvotes: 0
Reputation: 1363
You should really modify your program to show the errors returned by the system calls.
If the EUID of your process is really 0, that program can only fail if it has no permissions to change UID or GID (CAP_SETUOD and CAP_SETGID capabilities), or if the UID you are about to change has reached its process limit and thus can not have one more process.
I suggest changing your function to print the euid of your process before calling setuid()
or setgid()
, and print the errno
if any of those calls fail.
Upvotes: 2