summaryrefslogtreecommitdiff
path: root/uidswap.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2016-01-08 14:24:56 +1100
committerDamien Miller <djm@mindrot.org>2016-01-08 14:29:12 +1100
commit4626cbaf78767fc8e9c86dd04785386c59ae0839 (patch)
tree449a777d8781a7f88724cbec9a4717f5b3fe4ec6 /uidswap.c
parent422d1b3ee977ff4c724b597fb2e437d38fc8de9d (diff)
Support Illumos/Solaris fine-grained privileges
Includes a pre-auth privsep sandbox and several pledge() emulations. bz#2511, patch by Alex Wilson. ok dtucker@
Diffstat (limited to 'uidswap.c')
-rw-r--r--uidswap.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/uidswap.c b/uidswap.c
index 0702e1d9e..8bf6b244e 100644
--- a/uidswap.c
+++ b/uidswap.c
@@ -134,7 +134,7 @@ temporarily_use_uid(struct passwd *pw)
134void 134void
135permanently_drop_suid(uid_t uid) 135permanently_drop_suid(uid_t uid)
136{ 136{
137#ifndef HAVE_CYGWIN 137#ifndef NO_UID_RESTORATION_TEST
138 uid_t old_uid = getuid(); 138 uid_t old_uid = getuid();
139#endif 139#endif
140 140
@@ -142,8 +142,14 @@ permanently_drop_suid(uid_t uid)
142 if (setresuid(uid, uid, uid) < 0) 142 if (setresuid(uid, uid, uid) < 0)
143 fatal("setresuid %u: %.100s", (u_int)uid, strerror(errno)); 143 fatal("setresuid %u: %.100s", (u_int)uid, strerror(errno));
144 144
145#ifndef HAVE_CYGWIN 145#ifndef NO_UID_RESTORATION_TEST
146 /* Try restoration of UID if changed (test clearing of saved uid) */ 146 /*
147 * Try restoration of UID if changed (test clearing of saved uid).
148 *
149 * Note that we don't do this on Cygwin, or on Solaris-based platforms
150 * where fine-grained privileges are available (the user might be
151 * deliberately allowed the right to setuid back to root).
152 */
147 if (old_uid != uid && 153 if (old_uid != uid &&
148 (setuid(old_uid) != -1 || seteuid(old_uid) != -1)) 154 (setuid(old_uid) != -1 || seteuid(old_uid) != -1))
149 fatal("%s: was able to restore old [e]uid", __func__); 155 fatal("%s: was able to restore old [e]uid", __func__);
@@ -199,7 +205,7 @@ restore_uid(void)
199void 205void
200permanently_set_uid(struct passwd *pw) 206permanently_set_uid(struct passwd *pw)
201{ 207{
202#ifndef HAVE_CYGWIN 208#ifndef NO_UID_RESTORATION_TEST
203 uid_t old_uid = getuid(); 209 uid_t old_uid = getuid();
204 gid_t old_gid = getgid(); 210 gid_t old_gid = getgid();
205#endif 211#endif
@@ -227,7 +233,7 @@ permanently_set_uid(struct passwd *pw)
227 if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) < 0) 233 if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) < 0)
228 fatal("setresuid %u: %.100s", (u_int)pw->pw_uid, strerror(errno)); 234 fatal("setresuid %u: %.100s", (u_int)pw->pw_uid, strerror(errno));
229 235
230#ifndef HAVE_CYGWIN 236#ifndef NO_UID_RESTORATION_TEST
231 /* Try restoration of GID if changed (test clearing of saved gid) */ 237 /* Try restoration of GID if changed (test clearing of saved gid) */
232 if (old_gid != pw->pw_gid && pw->pw_uid != 0 && 238 if (old_gid != pw->pw_gid && pw->pw_uid != 0 &&
233 (setgid(old_gid) != -1 || setegid(old_gid) != -1)) 239 (setgid(old_gid) != -1 || setegid(old_gid) != -1))
@@ -241,7 +247,7 @@ permanently_set_uid(struct passwd *pw)
241 (u_int)pw->pw_gid); 247 (u_int)pw->pw_gid);
242 } 248 }
243 249
244#ifndef HAVE_CYGWIN 250#ifndef NO_UID_RESTORATION_TEST
245 /* Try restoration of UID if changed (test clearing of saved uid) */ 251 /* Try restoration of UID if changed (test clearing of saved uid) */
246 if (old_uid != pw->pw_uid && 252 if (old_uid != pw->pw_uid &&
247 (setuid(old_uid) != -1 || seteuid(old_uid) != -1)) 253 (setuid(old_uid) != -1 || seteuid(old_uid) != -1))