diff options
author | Charles Longeau <github@chl.be> | 2011-09-26 19:03:20 +0200 |
---|---|---|
committer | Charles Longeau <github@chl.be> | 2011-09-26 19:13:35 +0200 |
commit | 2b96d4480d8073fca5c93d38041a7ad3ddfa31fb (patch) | |
tree | d998163012d2170ff33acbf90f3efba161be8165 /openbsd-compat | |
parent | fix strnvis() compat code (needed for {Free,DragonFly}BSD) (diff) | |
download | OpenSMTPD-2b96d4480d8073fca5c93d38041a7ad3ddfa31fb.tar.xz OpenSMTPD-2b96d4480d8073fca5c93d38041a7ad3ddfa31fb.zip |
add setres{g,u}id compat code (needed by NetBSD)
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/Makefile.am | 1 | ||||
-rw-r--r-- | openbsd-compat/setresguid.c | 60 |
2 files changed, 61 insertions, 0 deletions
diff --git a/openbsd-compat/Makefile.am b/openbsd-compat/Makefile.am index 5ebf57cf..30a49ca6 100644 --- a/openbsd-compat/Makefile.am +++ b/openbsd-compat/Makefile.am @@ -17,6 +17,7 @@ libopenbsd_compat_a_SOURCES = \ imsg.c \ imsg-buffer.c \ mktemp.c \ + setresguid.c \ setproctitle.c \ strlcat.c \ strlcpy.c \ diff --git a/openbsd-compat/setresguid.c b/openbsd-compat/setresguid.c new file mode 100644 index 00000000..ea162110 --- /dev/null +++ b/openbsd-compat/setresguid.c @@ -0,0 +1,60 @@ +/* Subset of uidswap.c from portable OpenSSH */ + +/* $OpenBSD: uidswap.c,v 1.35 2006/08/03 03:34:42 deraadt Exp $ */ +/* + * Author: Tatu Ylonen <ylo@cs.hut.fi> + * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland + * All rights reserved + * Code for uid-swapping. + * + * As far as I am concerned, the code I have written for this software + * can be used freely for any purpose. Any derived versions of this + * software must be clearly marked as such, and if the derived work is + * incompatible with the protocol description in the RFC file, it must be + * called by a name other than "ssh" or "Secure Shell". + */ + +#include "includes.h" + + +#ifndef HAVE_SETRESGID +int setresgid(uid_t rgid, uid_t egid, uid_t sgid) +{ + +#if defined(HAVE_SETRESGID) && !defined(BROKEN_SETRESGID) + if (setresgid(rgid, egid, sgid) < 0) + fatal("setresgid %u: %.100s", (u_int)rgid, strerror(errno)); +#elif defined(HAVE_SETREGID) && !defined(BROKEN_SETREGID) + if (setregid(rgid, egid) < 0) + fatal("setregid %u: %.100s", (u_int)rgid, strerror(errno)); +#else + if (setegid(egid) < 0) + fatal("setegid %u: %.100s", (u_int)egid, strerror(errno)); + if (setgid(rgid) < 0) + fatal("setgid %u: %.100s", (u_int)rgid, strerror(errno)); +#endif +} +#endif /* HAVE_SETRESGID */ + + + +#ifndef HAVE_SETRESUID +int setresuid(uid_t ruid, uid_t euid, uid_t suid) +{ + +#if defined(HAVE_SETRESUID) && !defined(BROKEN_SETRESUID) + if (setresuid(ruid, euid, suid) < 0) + fatal("setresuid %u: %.100s", (u_int)ruid, strerror(errno)); +#elif defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID) + if (setreuid(ruid, euid) < 0) + fatal("setreuid %u: %.100s", (u_int)ruid, strerror(errno)); +#else +# ifndef SETEUID_BREAKS_SETUID + if (seteuid(euid) < 0) + fatal("seteuid %u: %.100s", (u_int)euid, strerror(errno)); +# endif + if (setuid(ruid) < 0) + fatal("setuid %u: %.100s", (u_int)ruid, strerror(errno)); +#endif +} +#endif /* HAVE_SETRESUID */ |