I have a project thant i want to use root to execute a program as a normal user.
first i have a normal user fgo whoes uid and gid is 501.
id fgo
[root@cpera test]# id fgo
uid=501(fgo) gid=501(fgo) groups=501(fgo)
here's the sample code
#define _GNU_SOURCE
#include <sched.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/capability.h>
#include <sys/resource.h>
#include <unistd.h>
#include<stdlib.h>
#include <stdio.h>
#include <string.h>
int main( int argc,char *argv[]){
while(setgid(501)!=0) sleep(1);
while(setuid(501)!=0) sleep(1);
printf("start to exec\n");
execvp("/bin/sh",NULL);
}
compile and execute
gcc a.c && ./a.out
the output is:
[root@cpera test]# ./a.out
start to exec
[fgo@cpera test]$ id
uid=501(fgo) gid=501(fgo) groups=501(fgo),0(root)
i googled it and find that the groups from id is called supplementary group inherited from the parent process.GID, current, primary, supplementary, effective and real group IDs?
how can i make root not in the groups of the sub process?