summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2012-11-05 17:04:37 +1100
committerDarren Tucker <dtucker@zip.com.au>2012-11-05 17:04:37 +1100
commitf96ff18a9240e38e5d3c671f5f8f341099874aaf (patch)
treeedca765088179b1faec91fb305ce8a2487663cc9
parenta6e3f01d1e230b8acfdd6b4cf3096459d2a325e0 (diff)
- (dtucker) [uidswap.c openbsd-compat/Makefile.in
openbsd-compat/bsd-setres_id.c openbsd-compat/bsd-setres_id.h openbsd-compat/openbsd-compat.h] Move the fallback code for setting uids and gids from uidswap.c to the compat library, which allows it to work with the new setresuid calls in auth2-pubkey. with tim@, ok djm@
-rw-r--r--ChangeLog7
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/bsd-setres_id.c99
-rw-r--r--openbsd-compat/bsd-setres_id.h24
-rw-r--r--openbsd-compat/openbsd-compat.h3
-rw-r--r--uidswap.c34
6 files changed, 134 insertions, 37 deletions
diff --git a/ChangeLog b/ChangeLog
index 85c92eb7f..8cc7c8e7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
120121105
2 - (dtucker) [uidswap.c openbsd-compat/Makefile.in
3 openbsd-compat/bsd-setres_id.c openbsd-compat/bsd-setres_id.h
4 openbsd-compat/openbsd-compat.h] Move the fallback code for setting uids
5 and gids from uidswap.c to the compat library, which allows it to work with
6 the new setresuid calls in auth2-pubkey. with tim@, ok djm@
7
120121104 820121104
2 - (djm) OpenBSD CVS Sync 9 - (djm) OpenBSD CVS Sync
3 - jmc@cvs.openbsd.org 2012/10/31 08:04:50 10 - jmc@cvs.openbsd.org 2012/10/31 08:04:50
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index 196a81d13..992b9743b 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.48 2011/11/04 00:25:25 dtucker Exp $ 1# $Id: Makefile.in,v 1.49 2012/11/05 06:04:37 dtucker Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -18,7 +18,7 @@ LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o timingsafe_bcmp.o vis.o 19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o timingsafe_bcmp.o vis.o
20 20
21COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o 21COMPAT=bsd-arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-setres_id.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o
22 22
23PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o 23PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o
24 24
diff --git a/openbsd-compat/bsd-setres_id.c b/openbsd-compat/bsd-setres_id.c
new file mode 100644
index 000000000..020b214b8
--- /dev/null
+++ b/openbsd-compat/bsd-setres_id.c
@@ -0,0 +1,99 @@
1/* $Id: bsd-setres_id.c,v 1.1 2012/11/05 06:04:37 dtucker Exp $ */
2
3/*
4 * Copyright (c) 2012 Darren Tucker (dtucker at zip com au).
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include "includes.h"
20
21#include <sys/types.h>
22
23#include <stdarg.h>
24#include <unistd.h>
25
26#include "log.h"
27
28#if !defined(HAVE_SETRESGID) || defined(BROKEN_SETRESGID)
29int
30setresgid(gid_t rgid, gid_t egid, gid_t sgid)
31{
32 int ret = 0, saved_errno;
33
34 if (rgid != sgid) {
35 errno = ENOSYS;
36 return -1;
37 }
38#if defined(HAVE_SETREGID) && !defined(BROKEN_SETREGID)
39 if (setregid(rgid, egid) < 0) {
40 saved_errno = errno;
41 error("setregid %u: %.100s", rgid, strerror(errno));
42 errno = saved_errno;
43 ret = -1;
44 }
45#else
46 if (setegid(egid) < 0) {
47 saved_errno = errno;
48 error("setegid %u: %.100s", (u_int)egid, strerror(errno));
49 errno = saved_errno;
50 ret = -1;
51 }
52 if (setgid(rgid) < 0) {
53 saved_errno = errno;
54 error("setgid %u: %.100s", rgid, strerror(errno));
55 errno = saved_errno;
56 ret = -1;
57 }
58#endif
59 return ret;
60}
61#endif
62
63#if !defined(HAVE_SETRESUID) || defined(BROKEN_SETRESUID)
64int
65setresuid(uid_t ruid, uid_t euid, uid_t suid)
66{
67 int ret = 0, saved_errno;
68
69 if (ruid != suid) {
70 errno = ENOSYS;
71 return -1;
72 }
73#if defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID)
74 if (setreuid(ruid, euid) < 0) {
75 saved_errno = errno;
76 error("setreuid %u: %.100s", ruid, strerror(errno));
77 errno = saved_errno;
78 ret = -1;
79 }
80#else
81
82# ifndef SETEUID_BREAKS_SETUID
83 if (seteuid(euid) < 0) {
84 saved_errno = errno;
85 error("seteuid %u: %.100s", euid, strerror(errno));
86 errno = saved_errno;
87 ret = -1;
88 }
89# endif
90 if (setuid(ruid) < 0) {
91 saved_errno = errno;
92 error("setuid %u: %.100s", ruid, strerror(errno));
93 errno = saved_errno;
94 ret = -1;
95 }
96#endif
97 return ret;
98}
99#endif
diff --git a/openbsd-compat/bsd-setres_id.h b/openbsd-compat/bsd-setres_id.h
new file mode 100644
index 000000000..6c269e0b9
--- /dev/null
+++ b/openbsd-compat/bsd-setres_id.h
@@ -0,0 +1,24 @@
1/* $Id: bsd-setres_id.h,v 1.1 2012/11/05 06:04:37 dtucker Exp $ */
2
3/*
4 * Copyright (c) 2012 Darren Tucker (dtucker at zip com au).
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#ifndef HAVE_SETRESGID
20int setresgid(gid_t, gid_t, gid_t);
21#endif
22#ifndef HAVE_SETRESUID
23int setresuid(uid_t, uid_t, uid_t);
24#endif
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 807acf626..664cb0445 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.52 2011/09/23 01:16:11 djm Exp $ */ 1/* $Id: openbsd-compat.h,v 1.53 2012/11/05 06:04:38 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved.
@@ -149,6 +149,7 @@ int writev(int, struct iovec *, int);
149 149
150/* Home grown routines */ 150/* Home grown routines */
151#include "bsd-misc.h" 151#include "bsd-misc.h"
152#include "bsd-setres_id.h"
152#include "bsd-statvfs.h" 153#include "bsd-statvfs.h"
153#include "bsd-waitpid.h" 154#include "bsd-waitpid.h"
154#include "bsd-poll.h" 155#include "bsd-poll.h"
diff --git a/uidswap.c b/uidswap.c
index 837648396..cdd7309e3 100644
--- a/uidswap.c
+++ b/uidswap.c
@@ -138,20 +138,8 @@ permanently_drop_suid(uid_t uid)
138 uid_t old_uid = getuid(); 138 uid_t old_uid = getuid();
139 139
140 debug("permanently_drop_suid: %u", (u_int)uid); 140 debug("permanently_drop_suid: %u", (u_int)uid);
141#if defined(HAVE_SETRESUID) && !defined(BROKEN_SETRESUID)
142 if (setresuid(uid, uid, uid) < 0) 141 if (setresuid(uid, uid, uid) < 0)
143 fatal("setresuid %u: %.100s", (u_int)uid, strerror(errno)); 142 fatal("setresuid %u: %.100s", (u_int)uid, strerror(errno));
144#elif defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID)
145 if (setreuid(uid, uid) < 0)
146 fatal("setreuid %u: %.100s", (u_int)uid, strerror(errno));
147#else
148# ifndef SETEUID_BREAKS_SETUID
149 if (seteuid(uid) < 0)
150 fatal("seteuid %u: %.100s", (u_int)uid, strerror(errno));
151# endif
152 if (setuid(uid) < 0)
153 fatal("setuid %u: %.100s", (u_int)uid, strerror(errno));
154#endif
155 143
156#ifndef HAVE_CYGWIN 144#ifndef HAVE_CYGWIN
157 /* Try restoration of UID if changed (test clearing of saved uid) */ 145 /* Try restoration of UID if changed (test clearing of saved uid) */
@@ -220,18 +208,8 @@ permanently_set_uid(struct passwd *pw)
220 debug("permanently_set_uid: %u/%u", (u_int)pw->pw_uid, 208 debug("permanently_set_uid: %u/%u", (u_int)pw->pw_uid,
221 (u_int)pw->pw_gid); 209 (u_int)pw->pw_gid);
222 210
223#if defined(HAVE_SETRESGID) && !defined(BROKEN_SETRESGID)
224 if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) < 0) 211 if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) < 0)
225 fatal("setresgid %u: %.100s", (u_int)pw->pw_gid, strerror(errno)); 212 fatal("setresgid %u: %.100s", (u_int)pw->pw_gid, strerror(errno));
226#elif defined(HAVE_SETREGID) && !defined(BROKEN_SETREGID)
227 if (setregid(pw->pw_gid, pw->pw_gid) < 0)
228 fatal("setregid %u: %.100s", (u_int)pw->pw_gid, strerror(errno));
229#else
230 if (setegid(pw->pw_gid) < 0)
231 fatal("setegid %u: %.100s", (u_int)pw->pw_gid, strerror(errno));
232 if (setgid(pw->pw_gid) < 0)
233 fatal("setgid %u: %.100s", (u_int)pw->pw_gid, strerror(errno));
234#endif
235 213
236#ifdef __APPLE__ 214#ifdef __APPLE__
237 /* 215 /*
@@ -243,20 +221,8 @@ permanently_set_uid(struct passwd *pw)
243 pw->pw_name, (u_int)pw->pw_gid, strerror(errno)); 221 pw->pw_name, (u_int)pw->pw_gid, strerror(errno));
244#endif 222#endif
245 223
246#if defined(HAVE_SETRESUID) && !defined(BROKEN_SETRESUID)
247 if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) < 0) 224 if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) < 0)
248 fatal("setresuid %u: %.100s", (u_int)pw->pw_uid, strerror(errno)); 225 fatal("setresuid %u: %.100s", (u_int)pw->pw_uid, strerror(errno));
249#elif defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID)
250 if (setreuid(pw->pw_uid, pw->pw_uid) < 0)
251 fatal("setreuid %u: %.100s", (u_int)pw->pw_uid, strerror(errno));
252#else
253# ifndef SETEUID_BREAKS_SETUID
254 if (seteuid(pw->pw_uid) < 0)
255 fatal("seteuid %u: %.100s", (u_int)pw->pw_uid, strerror(errno));
256# endif
257 if (setuid(pw->pw_uid) < 0)
258 fatal("setuid %u: %.100s", (u_int)pw->pw_uid, strerror(errno));
259#endif
260 226
261#ifndef HAVE_CYGWIN 227#ifndef HAVE_CYGWIN
262 /* Try restoration of GID if changed (test clearing of saved gid) */ 228 /* Try restoration of GID if changed (test clearing of saved gid) */