#include #include #include #include #include #include int main(int ac, char *av[]) { pid_t childPid; const char *userName = "gismobile"; if((childPid = fork()) == 0) { /* * If a user name is specified, try to set our uid to match that * user name. This is to allow e.g. a banner page to show the * name of the printing user rather than the user who started * the print server. */ if(userName) { uid_t myUid; if((myUid = geteuid()) == (uid_t)0) { struct passwd *pPasswd; if((pPasswd = getpwnam(userName))) { printf("child: Setting uid=%d\n", (int)pPasswd->pw_uid); setuid((uid_t)pPasswd->pw_uid); } else { printf("child: getpwnam() failed\n"); } } } /* return BadAlloc? */ if (execv("/usr/bin/id", NULL) == -1) { fprintf(stderr, "child: unable to exec '%s'\n", "/usr/bin/id"); } } else { int status; (void) waitpid(childPid, &status, 0); } return EXIT_SUCCESS; }