简体   繁体   中英

setegid() in a suid-root binary in C

Good evening, I am trying to write a suid-root binary in C and I have stumbled across the following problem: I execute it as a non-privileged user user1 and I am able to use setuid/seteuid to change to any user id I want. The problem is that I can't do that with effective group ids. Part of code:

if ( setegid(VariableID) == -1 ) {
    perror("setegid failed");
    exit(1);
}

and this returns:

setegid failed: Operation not permitted

Please note that I can successfully change group IDs between root(0) and the user that executes the binary but I can't change to other groups. Shouldn't this be possible since the binary is suid-root like the UID/EUID?

The answer (thanks Ingo Leonhardt) is that you need to change the group id before the user id. It kind of makes sense now.. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM