|
|
| version 1.1.1.2, 2012/05/29 12:26:49 | version 1.1.1.3, 2013/07/22 10:46:13 |
|---|---|
| Line 1 | Line 1 |
| /* | /* |
| * Copyright (c) 2004-2008, 2010-2011 Todd C. Miller <Todd.Miller@courtesan.com> | * Copyright (c) 2004-2008, 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com> |
| * | * |
| * Permission to use, copy, modify, and distribute this software for any | * Permission to use, copy, modify, and distribute this software for any |
| * purpose with or without fee is hereby granted, provided that the above | * purpose with or without fee is hereby granted, provided that the above |
| Line 17 | Line 17 |
| #include <config.h> | #include <config.h> |
| #include <sys/types.h> | #include <sys/types.h> |
| #include <sys/param.h> | |
| #include <sys/stat.h> | #include <sys/stat.h> |
| #include <sys/time.h> | #include <sys/time.h> |
| #include <sys/wait.h> | #include <sys/wait.h> |
| Line 63 switch_user(uid_t euid, gid_t egid, int ngroups, GETGR | Line 62 switch_user(uid_t euid, gid_t egid, int ngroups, GETGR |
| /* When restoring root, change euid first; otherwise change it last. */ | /* When restoring root, change euid first; otherwise change it last. */ |
| if (euid == ROOT_UID) { | if (euid == ROOT_UID) { |
| if (seteuid(ROOT_UID) != 0) | if (seteuid(ROOT_UID) != 0) |
| error(1, "seteuid(ROOT_UID)"); | fatal("seteuid(ROOT_UID)"); |
| } | } |
| if (setegid(egid) != 0) | if (setegid(egid) != 0) |
| error(1, "setegid(%d)", (int)egid); | fatal("setegid(%d)", (int)egid); |
| if (ngroups != -1) { | if (ngroups != -1) { |
| if (sudo_setgroups(ngroups, groups) != 0) | if (sudo_setgroups(ngroups, groups) != 0) |
| error(1, "setgroups"); | fatal("setgroups"); |
| } | } |
| if (euid != ROOT_UID) { | if (euid != ROOT_UID) { |
| if (seteuid(euid) != 0) | if (seteuid(euid) != 0) |
| error(1, "seteuid(%d)", (int)euid); | fatal("seteuid(%d)", (int)euid); |
| } | } |
| errno = serrno; | errno = serrno; |
| Line 188 sudo_edit(struct command_details *command_details) | Line 187 sudo_edit(struct command_details *command_details) |
| easprintf(&tf[j].tfile, "%.*s/%s.XXXXXXXX", tmplen, tmpdir, cp); | easprintf(&tf[j].tfile, "%.*s/%s.XXXXXXXX", tmplen, tmpdir, cp); |
| } | } |
| if (seteuid(user_details.uid) != 0) | if (seteuid(user_details.uid) != 0) |
| error(1, "seteuid(%d)", (int)user_details.uid); | fatal("seteuid(%d)", (int)user_details.uid); |
| tfd = mkstemps(tf[j].tfile, suff ? strlen(suff) : 0); | tfd = mkstemps(tf[j].tfile, suff ? strlen(suff) : 0); |
| if (seteuid(ROOT_UID) != 0) | if (seteuid(ROOT_UID) != 0) |
| error(1, "seteuid(ROOT_UID)"); | fatal("seteuid(ROOT_UID)"); |
| if (tfd == -1) { | if (tfd == -1) { |
| warning("mkstemps"); | warning("mkstemps"); |
| goto cleanup; | goto cleanup; |
| Line 258 sudo_edit(struct command_details *command_details) | Line 257 sudo_edit(struct command_details *command_details) |
| for (i = 0; i < nfiles; i++) { | for (i = 0; i < nfiles; i++) { |
| rc = -1; | rc = -1; |
| if (seteuid(user_details.uid) != 0) | if (seteuid(user_details.uid) != 0) |
| error(1, "seteuid(%d)", (int)user_details.uid); | fatal("seteuid(%d)", (int)user_details.uid); |
| if ((tfd = open(tf[i].tfile, O_RDONLY, 0644)) != -1) { | if ((tfd = open(tf[i].tfile, O_RDONLY, 0644)) != -1) { |
| rc = fstat(tfd, &sb); | rc = fstat(tfd, &sb); |
| } | } |
| if (seteuid(ROOT_UID) != 0) | if (seteuid(ROOT_UID) != 0) |
| error(1, "seteuid(ROOT_UID)"); | fatal("seteuid(ROOT_UID)"); |
| if (rc || !S_ISREG(sb.st_mode)) { | if (rc || !S_ISREG(sb.st_mode)) { |
| if (rc) | if (rc) |
| warning("%s", tf[i].tfile); | warning("%s", tf[i].tfile); |