16 change_uid(Process *proc) {
17 uid_t run_uid, run_euid;
18 gid_t run_gid, run_egid;
23 if (getuid() != 0 || geteuid() != 0) {
25 "you must be root to use the -u option\n");
28 if ((pent = getpwnam(options.user)) == NULL) {
29 fprintf(stderr, "cannot find user `%s'\n", options.user);
32 run_uid = pent->pw_uid;
33 run_gid = pent->pw_gid;
35 if (initgroups(options.user, run_gid) < 0) {
36 perror("ltrace: initgroups");
43 if (options.user || !geteuid()) {
48 if (!stat(proc->filename, &statbuf)) {
49 if (statbuf.st_mode & S_ISUID) {
50 run_euid = statbuf.st_uid;
52 if (statbuf.st_mode & S_ISGID) {
53 run_egid = statbuf.st_gid;
56 if (setregid(run_gid, run_egid) < 0) {
57 perror("ltrace: setregid");
60 if (setreuid(run_uid, run_euid) < 0) {
61 perror("ltrace: setreuid");
68 execute_program(Process *sp, char **argv) {
71 debug(1, "Executing `%s'...", sp->filename);
75 perror("ltrace: fork");
77 } else if (!pid) { /* child */
80 execvp(sp->filename, argv);
81 fprintf(stderr, "Can't execute `%s': %s\n", sp->filename,
86 debug(1, "PID=%d", pid);