diff options
author | 2019-11-10 08:17:42 +0100 | |
---|---|---|
committer | 2019-11-10 08:17:42 +0100 | |
commit | 8b000a04ab9644245beebd54419b03d3c98599b0 (patch) | |
tree | 15aec22f8cf2dbf56f3885d63234810c5349609a /openbsd-compat | |
parent | Merge pull request #987 from OpenSMTPD/clang_scan (diff) | |
download | OpenSMTPD-8b000a04ab9644245beebd54419b03d3c98599b0.tar.xz OpenSMTPD-8b000a04ab9644245beebd54419b03d3c98599b0.zip |
convert most of openbsd-compat to conditional build rather than
conditionally ifdef out bits
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/Makefile.am | 130 | ||||
-rw-r--r-- | openbsd-compat/empty.c | 0 | ||||
-rw-r--r-- | openbsd-compat/fgetln.c | 3 | ||||
-rw-r--r-- | openbsd-compat/freezero.c | 3 | ||||
-rw-r--r-- | openbsd-compat/pw_dup.c | 3 | ||||
-rw-r--r-- | openbsd-compat/reallocarray.c | 3 | ||||
-rw-r--r-- | openbsd-compat/setresgid.c | 41 | ||||
-rw-r--r-- | openbsd-compat/setresuid.c (renamed from openbsd-compat/setresguid.c) | 24 | ||||
-rw-r--r-- | openbsd-compat/strlcat.c | 3 | ||||
-rw-r--r-- | openbsd-compat/strlcpy.c | 3 | ||||
-rw-r--r-- | openbsd-compat/strmode.c | 2 |
11 files changed, 133 insertions, 82 deletions
diff --git a/openbsd-compat/Makefile.am b/openbsd-compat/Makefile.am index 6fb72d29..bbf02096 100644 --- a/openbsd-compat/Makefile.am +++ b/openbsd-compat/Makefile.am @@ -1,6 +1,8 @@ noinst_LIBRARIES = libopenbsd-compat.a -libopenbsd_compat_a_SOURCES = arc4random.c +libopenbsd_compat_a_SOURCES = empty.c + +libopenbsd_compat_a_SOURCES += arc4random.c libopenbsd_compat_a_SOURCES += SSL_CTX_use_certificate_chain_mem.c libopenbsd_compat_a_SOURCES += base64.c libopenbsd_compat_a_SOURCES += bsd-getpeereid.c @@ -8,90 +10,138 @@ libopenbsd_compat_a_SOURCES += bsd-misc.c libopenbsd_compat_a_SOURCES += bsd-waitpid.c libopenbsd_compat_a_SOURCES += entropy.c libopenbsd_compat_a_SOURCES += event_asr_run.c -libopenbsd_compat_a_SOURCES += fgetln.c -libopenbsd_compat_a_SOURCES += freezero.c libopenbsd_compat_a_SOURCES += getopt.c -libopenbsd_compat_a_SOURCES += imsg.c -libopenbsd_compat_a_SOURCES += imsg-buffer.c -#libopenbsd_compat_a_SOURCES += libressl.c -libopenbsd_compat_a_SOURCES += pidfile.c -libopenbsd_compat_a_SOURCES += pw_dup.c -libopenbsd_compat_a_SOURCES += reallocarray.c -libopenbsd_compat_a_SOURCES += recallocarray.c libopenbsd_compat_a_SOURCES += setproctitle.c -libopenbsd_compat_a_SOURCES += setresguid.c -libopenbsd_compat_a_SOURCES += strlcat.c -libopenbsd_compat_a_SOURCES += strlcpy.c -libopenbsd_compat_a_SOURCES += strmode.c -libopenbsd_compat_a_SOURCES += strtonum.c -libopenbsd_compat_a_SOURCES += strsep.c libopenbsd_compat_a_SOURCES += vis.c libopenbsd_compat_a_SOURCES += xmalloc.c -if !SUPPORT_BASENAME -libopenbsd_compat_a_SOURCES += basename.c -endif +#if NEED_SSL_CTX_USE_CERTIFICATE_CHAIN_MEM +#libopenbsd_compat_a_SOURCES += SSL_CTX_use_certificate_chain_mem.c +#endif -if !SUPPORT_CRYPT_CHECKPASS -libopenbsd_compat_a_SOURCES += crypt_checkpass.c +if NEED_BASENAME +libopenbsd_compat_a_SOURCES += basename.c endif -if !SUPPORT_CLOCK_GETTIME +if NEED_CLOCK_GETTIME libopenbsd_compat_a_SOURCES += clock_gettime.c endif -if !SUPPORT_CLOSEFROM +if NEED_CLOSEFROM libopenbsd_compat_a_SOURCES += bsd-closefrom.c endif -if !SUPPORT_DAEMON -libopenbsd_compat_a_SOURCES += daemon.c +if NEED_CRYPT_CHECKPASS +libopenbsd_compat_a_SOURCES += crypt_checkpass.c endif -if !SUPPORT_DIRNAME -libopenbsd_compat_a_SOURCES += dirname.c +if NEED_DAEMON +libopenbsd_compat_a_SOURCES += daemon.c endif -if !SUPPORT_ERR_H -libopenbsd_compat_a_SOURCES += bsd-err.c +if NEED_DIRNAME +libopenbsd_compat_a_SOURCES += dirname.c endif -if !SUPPORT_ERRC +if NEED_ERRC libopenbsd_compat_a_SOURCES += errc.c endif -if !SUPPORT_EXPLICIT_BZERO +if NEED_EXPLICIT_BZERO libopenbsd_compat_a_SOURCES += explicit_bzero.c endif -if !SUPPORT_FMT_SCALED -libopenbsd_compat_a_SOURCES += fmt_scaled.c +if NEED_FGETLN +libopenbsd_compat_a_SOURCES += fgetln.c endif -if !SUPPORT_FLOCK +if NEED_FLOCK libopenbsd_compat_a_SOURCES += flock.c endif -if !SUPPORT_FPARSELN +if NEED_FMT_SCALED +libopenbsd_compat_a_SOURCES += fmt_scaled.c +endif + +if NEED_FPARSELN libopenbsd_compat_a_SOURCES += fparseln.c endif -if !SUPPORT_GETLINE -libopenbsd_compat_a_SOURCES += getline.c +if NEED_FREEZERO +libopenbsd_compat_a_SOURCES += freezero.c +endif + +if NEED_GETLINE +libopenbsd_compat_a_SOURCES += getline.c +endif + +if NEED_IMSG +libopenbsd_compat_a_SOURCES += imsg.c +libopenbsd_compat_a_SOURCES += imsg-buffer.c endif -if !SUPPORT_INET_NET_PTON +if NEED_INET_NET_PTON libopenbsd_compat_a_SOURCES += inet_net_pton.c endif -if !SUPPORT_STRNDUP +if NEED_PIDFILE +libopenbsd_compat_a_SOURCES += pidfile.c +endif + +if NEED_PW_DUP +libopenbsd_compat_a_SOURCES += pw_dup.c +endif + +if NEED_REALLOCARRAY +libopenbsd_compat_a_SOURCES += reallocarray.c +endif + +if NEED_RECALLOCARRAY +libopenbsd_compat_a_SOURCES += recallocarray.c +endif + +if NEED_SETRESGID +libopenbsd_compat_a_SOURCES += setresgid.c +endif + +if NEED_SETRESUID +libopenbsd_compat_a_SOURCES += setresuid.c +endif + +if NEED_STRLCAT +libopenbsd_compat_a_SOURCES += strlcat.c +endif + +if NEED_STRLCPY +libopenbsd_compat_a_SOURCES += strlcpy.c +endif + +if NEED_STRMODE +libopenbsd_compat_a_SOURCES += strmode.c +endif + +if NEED_STRSEP +libopenbsd_compat_a_SOURCES += strsep.c +endif + +if NEED_STRTONUM +libopenbsd_compat_a_SOURCES += strtonum.c +endif + +if NEED_STRNDUP libopenbsd_compat_a_SOURCES += strndup.c endif -if !SUPPORT_STRNLEN +if NEED_STRNLEN libopenbsd_compat_a_SOURCES += strnlen.c endif + +if !SUPPORT_ERR_H +libopenbsd_compat_a_SOURCES += bsd-err.c +endif + + EXTRA_DIST = base64.h EXTRA_DIST += bsd-misc.h EXTRA_DIST += bsd-waitpid.h diff --git a/openbsd-compat/empty.c b/openbsd-compat/empty.c new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/openbsd-compat/empty.c diff --git a/openbsd-compat/fgetln.c b/openbsd-compat/fgetln.c index 78099515..6c3290d0 100644 --- a/openbsd-compat/fgetln.c +++ b/openbsd-compat/fgetln.c @@ -18,7 +18,6 @@ * portable fgetln() version, NOT reentrant */ -#ifndef HAVE_FGETLN #include <stdio.h> #include <stdlib.h> #include <errno.h> @@ -57,4 +56,4 @@ fgetln(FILE *fp, size_t *len) } return (*len = r) ? buf : NULL; } -#endif + diff --git a/openbsd-compat/freezero.c b/openbsd-compat/freezero.c index 7183f796..9b64e2b0 100644 --- a/openbsd-compat/freezero.c +++ b/openbsd-compat/freezero.c @@ -21,7 +21,6 @@ #include "includes.h" -#ifndef HAVE_FREEZERO #include <stdlib.h> void @@ -32,5 +31,3 @@ freezero(void *ptr, size_t sz) explicit_bzero(ptr, sz); free(ptr); } - -#endif /* HAVE_FREEZERO */ diff --git a/openbsd-compat/pw_dup.c b/openbsd-compat/pw_dup.c index e16680c4..a01bad07 100644 --- a/openbsd-compat/pw_dup.c +++ b/openbsd-compat/pw_dup.c @@ -31,8 +31,6 @@ #include <stdio.h> #include <string.h> -#ifndef HAVE_PW_DUP - #define PW_SIZE(name, size) \ do { \ if (pw->name) { \ @@ -93,4 +91,3 @@ pw_dup(const struct passwd *pw) return (newpw); } -#endif diff --git a/openbsd-compat/reallocarray.c b/openbsd-compat/reallocarray.c index ddd7f3a2..9beec719 100644 --- a/openbsd-compat/reallocarray.c +++ b/openbsd-compat/reallocarray.c @@ -18,7 +18,7 @@ /* OPENBSD ORIGINAL: lib/libc/stdlib/reallocarray.c */ #include "includes.h" -#ifndef HAVE_REALLOCARRAY + #include <sys/types.h> #include <errno.h> #include <stdint.h> @@ -40,4 +40,3 @@ reallocarray(void *optr, size_t nmemb, size_t size) } return realloc(optr, size * nmemb); } -#endif diff --git a/openbsd-compat/setresgid.c b/openbsd-compat/setresgid.c new file mode 100644 index 00000000..e798cdad --- /dev/null +++ b/openbsd-compat/setresgid.c @@ -0,0 +1,41 @@ +/* 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" + +#include <stdarg.h> +#include <string.h> +#include <unistd.h> + +#include "log.h" + +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 + return (0); +} diff --git a/openbsd-compat/setresguid.c b/openbsd-compat/setresuid.c index 78e7f196..36df39e9 100644 --- a/openbsd-compat/setresguid.c +++ b/openbsd-compat/setresuid.c @@ -22,29 +22,6 @@ #include "log.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 - return (0); -} -#endif /* HAVE_SETRESGID */ - - - -#ifndef HAVE_SETRESUID int setresuid(uid_t ruid, uid_t euid, uid_t suid) { @@ -64,4 +41,3 @@ int setresuid(uid_t ruid, uid_t euid, uid_t suid) #endif return (0); } -#endif /* HAVE_SETRESUID */ diff --git a/openbsd-compat/strlcat.c b/openbsd-compat/strlcat.c index bcc1b61a..979eb876 100644 --- a/openbsd-compat/strlcat.c +++ b/openbsd-compat/strlcat.c @@ -19,7 +19,6 @@ /* OPENBSD ORIGINAL: lib/libc/string/strlcat.c */ #include "includes.h" -#ifndef HAVE_STRLCAT #include <sys/types.h> #include <string.h> @@ -58,5 +57,3 @@ strlcat(char *dst, const char *src, size_t siz) return(dlen + (s - src)); /* count does not include NUL */ } - -#endif /* !HAVE_STRLCAT */ diff --git a/openbsd-compat/strlcpy.c b/openbsd-compat/strlcpy.c index b4b1b601..2562ebbf 100644 --- a/openbsd-compat/strlcpy.c +++ b/openbsd-compat/strlcpy.c @@ -19,7 +19,6 @@ /* OPENBSD ORIGINAL: lib/libc/string/strlcpy.c */ #include "includes.h" -#ifndef HAVE_STRLCPY #include <sys/types.h> #include <string.h> @@ -54,5 +53,3 @@ strlcpy(char *dst, const char *src, size_t siz) return(s - src - 1); /* count does not include NUL */ } - -#endif /* !HAVE_STRLCPY */ diff --git a/openbsd-compat/strmode.c b/openbsd-compat/strmode.c index 4a816142..2fc2bb0e 100644 --- a/openbsd-compat/strmode.c +++ b/openbsd-compat/strmode.c @@ -31,7 +31,6 @@ /* OPENBSD ORIGINAL: lib/libc/string/strmode.c */ #include "includes.h" -#ifndef HAVE_STRMODE #include <sys/types.h> #include <sys/stat.h> @@ -145,4 +144,3 @@ strmode(int mode, char *p) *p++ = ' '; /* will be a '+' if ACL's implemented */ *p = '\0'; } -#endif |