summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat')
-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
4 files changed, 127 insertions, 3 deletions
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"