|
Lines 57-69
temporarily_use_uid(struct passwd *pw)
Link Here
|
| 57 |
(u_int)pw->pw_uid, (u_int)pw->pw_gid, |
57 |
(u_int)pw->pw_uid, (u_int)pw->pw_gid, |
| 58 |
(u_int)saved_euid, (u_int)saved_egid); |
58 |
(u_int)saved_euid, (u_int)saved_egid); |
| 59 |
#ifndef HAVE_CYGWIN |
59 |
#ifndef HAVE_CYGWIN |
| 60 |
if (saved_euid != 0) { |
60 |
if (saved_euid != ROOTUID) { |
| 61 |
privileged = 0; |
61 |
privileged = 0; |
| 62 |
return; |
62 |
return; |
| 63 |
} |
63 |
} |
| 64 |
#endif |
64 |
#endif |
| 65 |
#else |
65 |
#else |
| 66 |
if (geteuid() != 0) { |
66 |
if (geteuid() != ROOTUID) { |
| 67 |
privileged = 0; |
67 |
privileged = 0; |
| 68 |
return; |
68 |
return; |
| 69 |
} |
69 |
} |
|
Lines 87-95
temporarily_use_uid(struct passwd *pw)
Link Here
|
| 87 |
|
87 |
|
| 88 |
/* set and save the user's groups */ |
88 |
/* set and save the user's groups */ |
| 89 |
if (user_groupslen == -1) { |
89 |
if (user_groupslen == -1) { |
|
|
90 |
#ifndef HAVE_INTERIX |
| 90 |
if (initgroups(pw->pw_name, pw->pw_gid) < 0) |
91 |
if (initgroups(pw->pw_name, pw->pw_gid) < 0) |
| 91 |
fatal("initgroups: %s: %.100s", pw->pw_name, |
92 |
fatal("initgroups: %s: %.100s", pw->pw_name, |
| 92 |
strerror(errno)); |
93 |
strerror(errno)); |
|
|
94 |
#endif |
| 93 |
|
95 |
|
| 94 |
user_groupslen = getgroups(0, NULL); |
96 |
user_groupslen = getgroups(0, NULL); |
| 95 |
if (user_groupslen < 0) |
97 |
if (user_groupslen < 0) |
|
Lines 104-112
temporarily_use_uid(struct passwd *pw)
Link Here
|
| 104 |
xfree(user_groups); |
106 |
xfree(user_groups); |
| 105 |
} |
107 |
} |
| 106 |
} |
108 |
} |
|
|
109 |
#ifndef HAVE_INTERIX |
| 107 |
/* Set the effective uid to the given (unprivileged) uid. */ |
110 |
/* Set the effective uid to the given (unprivileged) uid. */ |
| 108 |
if (setgroups(user_groupslen, user_groups) < 0) |
111 |
if (setgroups(user_groupslen, user_groups) < 0) |
| 109 |
fatal("setgroups: %.100s", strerror(errno)); |
112 |
fatal("setgroups: %.100s", strerror(errno)); |
|
|
113 |
#endif |
| 110 |
#ifndef SAVED_IDS_WORK_WITH_SETEUID |
114 |
#ifndef SAVED_IDS_WORK_WITH_SETEUID |
| 111 |
/* Propagate the privileged gid to all of our gids. */ |
115 |
/* Propagate the privileged gid to all of our gids. */ |
| 112 |
if (setgid(getegid()) < 0) |
116 |
if (setgid(getegid()) < 0) |
|
Lines 154-161
restore_uid(void)
Link Here
|
| 154 |
setgid(getgid()); |
158 |
setgid(getgid()); |
| 155 |
#endif /* SAVED_IDS_WORK_WITH_SETEUID */ |
159 |
#endif /* SAVED_IDS_WORK_WITH_SETEUID */ |
| 156 |
|
160 |
|
|
|
161 |
#ifndef HAVE_INTERIX |
| 157 |
if (setgroups(saved_egroupslen, saved_egroups) < 0) |
162 |
if (setgroups(saved_egroupslen, saved_egroups) < 0) |
| 158 |
fatal("setgroups: %.100s", strerror(errno)); |
163 |
fatal("setgroups: %.100s", strerror(errno)); |
|
|
164 |
#endif |
| 159 |
temporarily_use_uid_effective = 0; |
165 |
temporarily_use_uid_effective = 0; |
| 160 |
} |
166 |
} |
| 161 |
|
167 |
|
|
Lines 174-179
permanently_set_uid(struct passwd *pw)
Link Here
|
| 174 |
debug("permanently_set_uid: %u/%u", (u_int)pw->pw_uid, |
180 |
debug("permanently_set_uid: %u/%u", (u_int)pw->pw_uid, |
| 175 |
(u_int)pw->pw_gid); |
181 |
(u_int)pw->pw_gid); |
| 176 |
|
182 |
|
|
|
183 |
#if defined(HAVE_INTERIX) |
| 184 |
if (setuser(pw->pw_name, NULL, SU_COMPLETE)) |
| 185 |
fatal("setuser %u: %.100s", (u_int)pw->pw_gid, strerror(errno)); |
| 186 |
#else |
| 177 |
#if defined(HAVE_SETRESGID) && !defined(BROKEN_SETRESGID) |
187 |
#if defined(HAVE_SETRESGID) && !defined(BROKEN_SETRESGID) |
| 178 |
if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) < 0) |
188 |
if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) < 0) |
| 179 |
fatal("setresgid %u: %.100s", (u_int)pw->pw_gid, strerror(errno)); |
189 |
fatal("setresgid %u: %.100s", (u_int)pw->pw_gid, strerror(errno)); |
|
Lines 222-227
permanently_set_uid(struct passwd *pw)
Link Here
|
| 222 |
(setuid(old_uid) != -1 || seteuid(old_uid) != -1)) |
232 |
(setuid(old_uid) != -1 || seteuid(old_uid) != -1)) |
| 223 |
fatal("%s: was able to restore old [e]uid", __func__); |
233 |
fatal("%s: was able to restore old [e]uid", __func__); |
| 224 |
#endif |
234 |
#endif |
|
|
235 |
#endif /* HAVE_INTERIX */ |
| 225 |
|
236 |
|
| 226 |
/* Verify UID drop was successful */ |
237 |
/* Verify UID drop was successful */ |
| 227 |
if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid) { |
238 |
if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid) { |