diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | readpass.c | 4 | ||||
-rw-r--r-- | sshconnect.c | 4 | ||||
-rw-r--r-- | sshconnect2.c | 4 | ||||
-rw-r--r-- | uidswap.c | 37 | ||||
-rw-r--r-- | uidswap.h | 3 |
6 files changed, 48 insertions, 9 deletions
@@ -42,6 +42,9 @@ | |||
42 | [readpass.c sshconnect.c sshconnect.h sshconnect2.c uidswap.c] | 42 | [readpass.c sshconnect.c sshconnect.h sshconnect2.c uidswap.c] |
43 | replace remaining setuid() calls with permanently_set_uid() and | 43 | replace remaining setuid() calls with permanently_set_uid() and |
44 | check seteuid() return values; report Marcus Meissner; ok dtucker djm | 44 | check seteuid() return values; report Marcus Meissner; ok dtucker djm |
45 | - markus@cvs.openbsd.org 2006/06/08 14:45:49 | ||
46 | [readpass.c sshconnect.c sshconnect2.c uidswap.c uidswap.h] | ||
47 | do not set the gid, noted by solar; ok djm | ||
45 | 48 | ||
46 | 20060521 | 49 | 20060521 |
47 | - (dtucker) [auth.c monitor.c] Now that we don't log from both the monitor | 50 | - (dtucker) [auth.c monitor.c] Now that we don't log from both the monitor |
@@ -4675,4 +4678,4 @@ | |||
4675 | - (djm) Trim deprecated options from INSTALL. Mention UsePAM | 4678 | - (djm) Trim deprecated options from INSTALL. Mention UsePAM |
4676 | - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu | 4679 | - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu |
4677 | 4680 | ||
4678 | $Id: ChangeLog,v 1.4341 2006/06/13 03:05:15 djm Exp $ | 4681 | $Id: ChangeLog,v 1.4342 2006/06/13 03:10:00 djm Exp $ |
diff --git a/readpass.c b/readpass.c index 60e4a902f..34d70b07a 100644 --- a/readpass.c +++ b/readpass.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: readpass.c,v 1.38 2006/06/06 10:20:20 markus Exp $ */ | 1 | /* $OpenBSD: readpass.c,v 1.39 2006/06/08 14:45:49 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2001 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -61,7 +61,7 @@ ssh_askpass(char *askpass, const char *msg) | |||
61 | return NULL; | 61 | return NULL; |
62 | } | 62 | } |
63 | if (pid == 0) { | 63 | if (pid == 0) { |
64 | permanently_set_uid(getpwuid(getuid())); | 64 | permanently_drop_suid(getuid()); |
65 | close(p[0]); | 65 | close(p[0]); |
66 | if (dup2(p[1], STDOUT_FILENO) < 0) | 66 | if (dup2(p[1], STDOUT_FILENO) < 0) |
67 | fatal("ssh_askpass: dup2: %s", strerror(errno)); | 67 | fatal("ssh_askpass: dup2: %s", strerror(errno)); |
diff --git a/sshconnect.c b/sshconnect.c index 41ad82f9f..c76572662 100644 --- a/sshconnect.c +++ b/sshconnect.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshconnect.c,v 1.183 2006/06/06 10:20:20 markus Exp $ */ | 1 | /* $OpenBSD: sshconnect.c,v 1.184 2006/06/08 14:45:49 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -97,7 +97,7 @@ ssh_proxy_connect(const char *host, u_short port, const char *proxy_command) | |||
97 | char *argv[10]; | 97 | char *argv[10]; |
98 | 98 | ||
99 | /* Child. Permanently give up superuser privileges. */ | 99 | /* Child. Permanently give up superuser privileges. */ |
100 | permanently_set_uid(getpwuid(original_real_uid)); | 100 | permanently_drop_suid(original_real_uid); |
101 | 101 | ||
102 | /* Redirect stdin and stdout. */ | 102 | /* Redirect stdin and stdout. */ |
103 | close(pin[1]); | 103 | close(pin[1]); |
diff --git a/sshconnect2.c b/sshconnect2.c index c97738c7b..4f96dcfc4 100644 --- a/sshconnect2.c +++ b/sshconnect2.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshconnect2.c,v 1.154 2006/06/06 10:20:20 markus Exp $ */ | 1 | /* $OpenBSD: sshconnect2.c,v 1.155 2006/06/08 14:45:49 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -1253,7 +1253,7 @@ ssh_keysign(Key *key, u_char **sigp, u_int *lenp, | |||
1253 | return -1; | 1253 | return -1; |
1254 | } | 1254 | } |
1255 | if (pid == 0) { | 1255 | if (pid == 0) { |
1256 | permanently_set_uid(getpwuid(getuid())); | 1256 | permanently_drop_suid(getuid()); |
1257 | close(from[0]); | 1257 | close(from[0]); |
1258 | if (dup2(from[1], STDOUT_FILENO) < 0) | 1258 | if (dup2(from[1], STDOUT_FILENO) < 0) |
1259 | fatal("ssh_keysign: dup2: %s", strerror(errno)); | 1259 | fatal("ssh_keysign: dup2: %s", strerror(errno)); |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: uidswap.c,v 1.28 2006/06/06 10:20:20 markus Exp $ */ | 1 | /* $OpenBSD: uidswap.c,v 1.29 2006/06/08 14:45:49 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -123,6 +123,41 @@ temporarily_use_uid(struct passwd *pw) | |||
123 | strerror(errno)); | 123 | strerror(errno)); |
124 | } | 124 | } |
125 | 125 | ||
126 | void | ||
127 | permanently_drop_suid(uid_t uid) | ||
128 | { | ||
129 | uid_t old_uid = getuid(); | ||
130 | |||
131 | debug("permanently_drop_suid: %u", (u_int)uid); | ||
132 | #if defined(HAVE_SETRESUID) && !defined(BROKEN_SETRESUID) | ||
133 | if (setresuid(uid, uid, uid) < 0) | ||
134 | fatal("setresuid %u: %.100s", (u_int)uid, strerror(errno)); | ||
135 | #elif defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID) | ||
136 | if (setreuid(uid, uid) < 0) | ||
137 | fatal("setreuid %u: %.100s", (u_int)uid, strerror(errno)); | ||
138 | #else | ||
139 | # ifndef SETEUID_BREAKS_SETUID | ||
140 | if (seteuid(uid) < 0) | ||
141 | fatal("seteuid %u: %.100s", (u_int)uid, strerror(errno)); | ||
142 | # endif | ||
143 | if (setuid(uid) < 0) | ||
144 | fatal("setuid %u: %.100s", (u_int)uid, strerror(errno)); | ||
145 | #endif | ||
146 | |||
147 | #ifndef HAVE_CYGWIN | ||
148 | /* Try restoration of UID if changed (test clearing of saved uid) */ | ||
149 | if (old_uid != uid && | ||
150 | (setuid(old_uid) != -1 || seteuid(old_uid) != -1)) | ||
151 | fatal("%s: was able to restore old [e]uid", __func__); | ||
152 | #endif | ||
153 | |||
154 | /* Verify UID drop was successful */ | ||
155 | if (getuid() != uid || geteuid() != uid) { | ||
156 | fatal("%s: euid incorrect uid:%u euid:%u (should be %u)", | ||
157 | __func__, (u_int)getuid(), (u_int)geteuid(), (u_int)uid); | ||
158 | } | ||
159 | } | ||
160 | |||
126 | /* | 161 | /* |
127 | * Restores to the original (privileged) uid. | 162 | * Restores to the original (privileged) uid. |
128 | */ | 163 | */ |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: uidswap.h,v 1.10 2006/03/25 22:22:43 djm Exp $ */ | 1 | /* $OpenBSD: uidswap.h,v 1.11 2006/06/08 14:45:49 markus Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
@@ -18,5 +18,6 @@ | |||
18 | void temporarily_use_uid(struct passwd *); | 18 | void temporarily_use_uid(struct passwd *); |
19 | void restore_uid(void); | 19 | void restore_uid(void); |
20 | void permanently_set_uid(struct passwd *); | 20 | void permanently_set_uid(struct passwd *); |
21 | void permanently_drop_suid(uid_t); | ||
21 | 22 | ||
22 | #endif /* UIDSWAP_H */ | 23 | #endif /* UIDSWAP_H */ |