Open System Services Programmer's Guide
printf("The following supplementary groups are available:\n");
for(i = 0; i < ngroups; i++) {
gid = grouplist[i];
printf("\t");
printgroup(gid);
printf("\n");
}
return;
}
struct stat statbuf;
int main(int argc, char **argv)
{
uid_t uid;
gid_t gid, egid;
char *login;
char termid[L_ctermid];
int fd;
/* Get new effective group ID from command line.
Default value set to real group ID value.
*/
if(argc > 1)
egid = atoi(argv[1]);
else
egid = getgid();
/* Print out information about the user */
login = getlogin();
if (login == NULL)
printf("Login name is not known\n");
else
printf("Login name is '%s'\n",login);
ctermid(termid);
printf("Terminal pathname is '%s'\n", termid);
uid = getuid();
printf("Real UID is");
printuser(uid);
uid = geteuid();
printf(" and effective UID is");
printuser(uid);
gid = getgid();
printf("\nReal group ID is");
printgroup(gid);
gid = getegid();
printf(" and effective group ID is ");
printgroup(gid);
printf("\n");
printsupgroups();
/* Create a new file with effective group ID of this process.
Then set the effective group ID of this process to one of
the supplemental group values. Use chown to set the group ID
of the file to the new effective group ID. The real group ID
value is left unchanged.
*/
if((fd = open("junkfile", O_RDWR|O_CREAT, 0666)) < 0) {
fprintf(stderr, "Can't create file 'junkfile'\n");
exit(1);
}
close(fd);
if(stat("junkfile", &statbuf) < 0) {
fprintf(stderr, "Can't get status of file 'junkfile'\n");
exit(1);
}
printf("junkfile created with uid = %d, gid = %d\n",
258 Managing OSS Security