Ok, so I'm trying to wrap my head around what the s flag does in linux.
I've got the following code:
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdio.h>
int main(int argc, char **argv, char **envp)
{
gid_t gid;
uid_t uid;
gid = getegid();
uid = geteuid();
printf("gid %d\n",gid);
printf("uid %d\n",uid);
setresgid(gid, gid, gid);
setresuid(uid, uid, uid);
system("id");
}
and the s flag is set for user.
-rwsr-xr-x 1 root root 7358 2017-08-24 17:45 a.out
so to my understanding, since the s flag is set, the effective gid, and uid should be the user.
However when I run this file as another user I get the following.
nebula@nebula:/tmp$ ./a.out
gid 1000
uid 1000
uid=1000(nebula) gid=1000(nebula) groups=1000(nebula),4(adm),20(dialout),24(cdrom),46(plugdev),108(lpadmin),109(sambashare),110(admin)
I believe that this shows that the effective uid and gid were not set the way I would have thought.
Any help?? Thanks!
geteuid()
does not return correct root value, trysetreuid(-1, 0)
. (Or use getresuid() to access the save uid instead of the effective one.) – eckes Aug 25 '17 at 2:15