X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=configure;h=632c74afff96c96218522059ef611accc8a6eca0;hb=b82ffa68a6436ce3f4c4b480bc9c12ac284b0d99;hp=e6a842a126ac2bced46e71b12dcc5070b7a4e1be;hpb=154b849c750be60d4c76cdcac56314b28c8a2790;p=opendoas.git diff --git a/configure b/configure index e6a842a..632c74a 100755 --- a/configure +++ b/configure @@ -25,12 +25,23 @@ usage: configure [options] --enable-static prepare for static build --without-pam disable pam support + --without-shadow disable shadow support + + --with-timestamp enable timestamp support + + --uid-max=NUM set UID_MAX (default 65535) + --gid-max=NUM set GID_MAX (default 65535) --help, -h display this help and exit EOF exit 0 } +# defaults +WITHOUT_TIMESTAMP=yes +UID_MAX=65535 +GID_MAX=65535 + for x; do opt=${x%%=*} var=${x#*=} @@ -47,29 +58,28 @@ for x; do --target) TARGET=$var ;; --enable-debug) DEBUG=yes ;; --enable-static) BUILD_STATIC=yes ;; - --with-pam) WITHOUT_PAM= ;; + --with-pam) WITHOUT_PAM=; WITHOUT_SHADOW=yes ;; + --with-shadow) WITHOUT_SHADOW=; WITHOUT_PAM=yes ;; --without-pam) WITHOUT_PAM=yes ;; + --without-shadow) WITHOUT_SHADOW=yes ;; + --with-timestamp) WITHOUT_TIMESTAMP= ;; + --without-timestamp) WITHOUT_TIMESTAMP=yes ;; + --uid-max) UID_MAX=$var ;; + --gid-max) UID_MAX=$var ;; --help|-h) usage ;; *) die "Error: unknown option $opt" ;; esac done CONFIG_MK=config.mk -rm -f "$CONFIG_MK" +CONFIG_H=config.h +rm -f "$CONFIG_MK" "$CONFIG_H" -# : ${VERSION:="$(git describe --dirty --tags --long --always)"} -: ${VERSION:="0.3.2"} +cat <$CONFIG_H +#ifndef CONFIG_H +#define CONFIG_H -cat <>$CONFIG_MK -PREFIX ?= ${PREFIX:="/usr"} -EPREFIX ?= ${EPREFIX:="${PREFIX}"} -BINDIR ?= ${BINDIR:="${PREFIX}/bin"} -SHAREDIR ?= ${SHAREDIR:="${PREFIX}/share"} -MANDIR ?= ${MANDIR:="${SHAREDIR}/man"} -SYSCONFDIR?= ${SYSCONFDIR:="/etc"} -PAMDIR ?= ${PAMDIR:="${SYSCONFDIR}/pam.d"} -CFLAGS += -DVERSION="\"${VERSION}\"" -EOF +! if [ -z "$BUILD" ]; then BUILD="$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')" @@ -98,13 +108,43 @@ OS_CFLAGS="-D__${OS}__" case "$OS" in linux) - OS_CFLAGS="$OS_CFLAGS -D_DEFAULT_SOURCE -D_GNU_SOURCE -DUID_MAX=60000 -DGID_MAX=60000" - printf 'CURDIR := .\n' >>$CONFIG_MK - [ -z "$WITHOUT_PAM" ] && \ - printf 'PAM_DOAS = pam.d__doas__linux\n' >>$CONFIG_MK + printf 'Setting UID_MAX\t\t\t\t%d.\n' "$UID_MAX" >&2 + printf '#define UID_MAX %s\n' "$UID_MAX" >>$CONFIG_H + printf 'Setting GID_MAX\t\t\t\t%d.\n' "$GID_MAX" >&2 + printf '#define GID_MAX %s\n' "$GID_MAX" >>$CONFIG_H + OS_CFLAGS="$OS_CFLAGS -D_DEFAULT_SOURCE -D_GNU_SOURCE" + ;; + netbsd) + OS_CFLAGS="$OS_CFLAGS -D_OPENBSD_SOURCE" + printf 'LDFLAGS += -lutil\n' >>$CONFIG_MK + : ${BINGRP:=wheel} ;; esac +: ${PREFIX:=/usr/local} +: ${EPREFIX:=${PREFIX}} +: ${BINDIR:=${PREFIX}/bin} +: ${SHAREDIR:=${PREFIX}/share} +: ${MANDIR:=${SHAREDIR}/man} +: ${SYSCONFDIR:=/etc} +: ${PAMDIR:=${SYSCONFDIR}/pam.d} +: ${BINMODE:=4755} +: ${BINOWN:=root} +: ${BINGRP:=root} + +cat <>$CONFIG_MK +PREFIX ?= ${PREFIX} +EPREFIX ?= ${EPREFIX} +BINDIR ?= ${BINDIR} +SHAREDIR ?= ${SHAREDIR} +MANDIR ?= ${MANDIR} +SYSCONFDIR?= ${SYSCONFDIR} +PAMDIR ?= ${PAMDIR} +BINMODE ?= ${BINMODE} +BINOWN ?= ${BINOWN} +BINGRP ?= ${BINGRP} +EOF + [ -n "$OS_CFLAGS" ] && \ printf 'CFLAGS += %s\n' "$OS_CFLAGS" >>$CONFIG_MK @@ -115,28 +155,81 @@ esac printf 'CFLAGS += -static\n' >>$CONFIG_MK # Add CPPFLAGS/CFLAGS/LDFLAGS to CC for testing features -XCC="${CC:=clang} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS" +XCC="${CC:=cc} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS" # Make sure to disable --as-needed for CC tests. XCC="$XCC -Wl,--no-as-needed" check_func() { func="$1"; src="$2"; shift 2 - printf 'Checking for %-14s\t\t' "$func ..." + printf 'Checking for %-14s\t\t' "$func ..." >&2 printf '%s\n' "$src" >"_$func.c" $XCC "_$func.c" -o "_$func" 2>/dev/null ret=$? rm -f "_$func.c" "_$func" + upperfunc="$(printf '%s\n' "$func" | tr '[[:lower:]]' '[[:upper:]]')" if [ $ret -eq 0 ]; then - printf 'yes.\n' - upperfunc="$(printf '%s\n' "$func" | tr '[[:lower:]]' '[[:upper:]]')" - printf 'CFLAGS += -DHAVE_%s\n' "$upperfunc" >>$CONFIG_MK + printf 'yes.\n' >&2 + printf '#define HAVE_%s\n' "$upperfunc" >>$CONFIG_H return 0 else - printf 'no.\n' + printf '/* #define HAVE_%s */\n' "$upperfunc" >>$CONFIG_H + printf 'no.\n' >&2 return 1 fi } +authmethod() { + # + # Check for pam_appl.h. + # + src=' +#include +int main(void) { + return 0; +}' + [ -z "$WITHOUT_PAM" ] && check_func "pam_appl_h" "$src" && { + printf 'SRCS += pam.c\n' >>$CONFIG_MK + printf 'LDFLAGS += -lpam\n' >>$CONFIG_MK + printf '#define USE_PAM\n' >>$CONFIG_H + printf 'pam\n' + + pam_file="pam.d__doas__${OS}" + [ -e "$pam_file" ] && printf 'PAM_DOAS = %s\n' "$pam_file" >>$CONFIG_MK + return 0 + } + + # + # Check for shadow.h. + # + src=' +#include +int main(void) { + return 0; +}' + [ -z "$WITHOUT_SHADOW" ] && check_func "shadow_h" "$src" && { + printf 'SRCS += shadow.c\n' >>$CONFIG_MK + printf 'LDFLAGS += -lcrypt\n' >>$CONFIG_MK + printf '#define USE_SHADOW\n' >>$CONFIG_H + printf 'shadow\n' + return 0 + } + + return 1 +} + +persistmethod() { + [ -z "$WITHOUT_TIMESTAMP" ] && { + printf '#define USE_TIMESTAMP\n' >>$CONFIG_H + printf 'SRCS += timestamp.c\n' >>$CONFIG_MK + printf 'timestamp\n' + return 0 + } + return 1 +} + +# +# Check for explicit_bzero(). +# src=' #include int main(void) { @@ -144,10 +237,9 @@ int main(void) { return 0; }' check_func "explicit_bzero" "$src" || { - printf 'OPENBSD += explicit_bzero.o\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/explicit_bzero.c\n' >>$CONFIG_MK } - # # Check for strlcat(). # @@ -160,7 +252,7 @@ int main(void) { return 0; }' check_func "strlcat" "$src" || { - printf 'OPENBSD += strlcat.o\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/strlcat.c\n' >>$CONFIG_MK } # @@ -175,7 +267,7 @@ int main(void) { return 0; }' check_func "strlcpy" "$src" || { - printf 'OPENBSD += strlcpy.o\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/strlcpy.c\n' >>$CONFIG_MK } # @@ -188,7 +280,7 @@ int main(void) { return 0; }' check_func "errc" "$src" || { - printf 'OPENBSD += errc.o\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/errc.c\n' >>$CONFIG_MK } # @@ -201,7 +293,7 @@ int main(void) { return 0; }' check_func "verrc" "$src" || { - printf 'OPENBSD += verrc.o\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/verrc.c\n' >>$CONFIG_MK } # @@ -214,7 +306,7 @@ int main(void) { return 0; }' check_func "setprogname" "$src" || { - printf 'OPENBSD += progname.o\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/progname.c\n' >>$CONFIG_MK } # @@ -228,7 +320,7 @@ int main(void) { return 0; }' check_func "readpassphrase" "$src" || { - printf 'OPENBSD += readpassphrase.o\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/readpassphrase.c\n' >>$CONFIG_MK } # @@ -242,7 +334,7 @@ int main(void) { return 0; }' check_func "strtonum" "$src" || { - printf 'OPENBSD += strtonum.o\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/strtonum.c\n' >>$CONFIG_MK } # @@ -255,87 +347,142 @@ int main(void) { return 0; }' check_func "reallocarray" "$src" || { - printf 'OPENBSD += reallocarray.o\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/reallocarray.c\n' >>$CONFIG_MK } # -# Check for bsd_auth.h. +# Check for execvpe(). # src=' -#include +#include int main(void) { + const char *p = { "", NULL }; + execvpe("", p, p); return 0; }' -check_func "bsd_auth_h" "$src" && \ - have_bsd_auth_h=1 +check_func "execvpe" "$src" || die "system has no execvpe(3): not supported" # -# Check for pam_appl.h. +# Check for setresuid(). # src=' -#include +#include int main(void) { + setresuid(0, 0, 0); return 0; }' -check_func "pam_appl_h" "$src" && { - [ -z "$WITHOUT_PAM" -a -z "$have_bsd_auth_h" ] && { - printf 'SRCS += pam.c\n' >>$CONFIG_MK - printf 'LDFLAGS += -lpam\n' >>$CONFIG_MK - } +check_func "setresuid" "$src" || { + printf 'SRCS += libopenbsd/bsd-setres_id.c\n' >>$CONFIG_MK } # -# Check for shadow.h. +# Check for closefrom(). # src=' -#include +#include int main(void) { + closefrom(0); return 0; }' -check_func "shadow_h" "$src" && { - [ -n "$WITHOUT_PAM" -a -z "$have_bsd_auth_h" ] && \ - printf 'LDFLAGS += -lcrypt\n' >>$CONFIG_MK +check_func "closefrom" "$src" || { + printf 'SRCS += libopenbsd/closefrom.c\n' >>$CONFIG_MK } # -# Check for execvpe(). +# Check for sysconf(). # src=' #include int main(void) { - const char *p = { "", NULL }; - execvpe("", p, p); + (void)sysconf(0); return 0; }' -check_func "execvpe" "$src" || { - printf 'OPENBSD += execvpe.o\n' >>$CONFIG_MK -} +check_func "sysconf" "$src" # -# Check for setresuid(). +# Check for dirfd(). # src=' -#include +#include int main(void) { - setresuid(0, 0, 0); + (void)dirfd(0); return 0; }' -check_func "setresuid" "$src" || { - printf 'OPENBSD += setresuid.o\n' >>$CONFIG_MK -} +check_func "dirfd" "$src" # -# Check for pledge(). +# Check for fcntl.h. # src=' -#include +#include int main(void) { - pledge("", NULL); return 0; }' -check_func "pledge" "$src" || { - printf 'OPENBSD += pledge-noop.o\n' >>$CONFIG_MK -} +check_func "fcntl_h" "$src" + +# +# Check for F_CLOSEM. +# +src=' +#include +#ifndef F_CLOSEM +#error no F_CLOSEM +#endif +int main(void) { + return 0; +}' +check_func "F_CLOSEM" "$src" + +# +# Check for dirent.h. +# +src=' +#include +int main(void) { + return 0; +}' +check_func "dirent_h" "$src" + +# +# Check for sys/ndir.h. +# +src=' +#include +int main(void) { + return 0; +}' +check_func "sys_ndir_h" "$src" + +# +# Check for sys/dir.h. +# +src=' +#include +int main(void) { + return 0; +}' +check_func "sys_dir_h" "$src" + +# +# Check for ndir.h. +# +src=' +#include +int main(void) { + return 0; +}' +check_func "ndir_h" "$src" + +# +# Check for login_cap.h. +# +src=' +#include +#include +int main(void) { + return 0; +}' +check_func "login_cap_h" "$src" # # @@ -348,3 +495,22 @@ __attribute__((__unused__)) static void foo(void){return;} check_func "__attribute__" "$src" || { printf 'CFLAGS += -DNO_ATTRIBUTE_ON_RETURN_TYPE=1\n' >>$CONFIG_MK } + +auth=$(authmethod) +if [ $? -eq 0 ]; then + printf 'Using auth method\t\t\t%s.\n' "$auth" >&2 +else + printf 'Error auth method\t\t\n' >&2 + exit 1 +fi + +persist=$(persistmethod) +if [ $? -eq 0 ]; then + printf 'Using persist method\t\t\t%s.\n' "$persist" >&2 +else + printf 'Using persist method\t\t\tnone.\n' >&2 +fi + +printf '#define DOAS_CONF "%s/doas.conf"\n' "${SYSCONFDIR}" >>$CONFIG_H + +printf '\n#endif /* CONFIG_H */\n' >>$CONFIG_H