X-Git-Url: https://git.armaanb.net/?p=opendoas.git;a=blobdiff_plain;f=configure;h=34538bc56a5fe6ea3921c088edd0dfeef6af60ce;hp=f8d351b46a405d854a75e917f498e2032e9f4168;hb=HEAD;hpb=049eedbf316fcc831a485f1fc53aa33035ba12da diff --git a/configure b/configure index f8d351b..34538bc 100755 --- a/configure +++ b/configure @@ -1,12 +1,12 @@ -#!/bin/sh +#!/usr/bin/env sh die() { - printf "$1\n" >&2 - exit 1 + printf "$1\n" >&2 + exit 1 } usage() { - cat <$CONFIG_H ! if [ -z "$BUILD" ]; then - BUILD="$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')" + BUILD="$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')" fi if [ -z "$HOST" ]; then - [ -z "$TARGET" ] && TARGET=$BUILD - HOST=$TARGET + [ -z "$TARGET" ] && TARGET=$BUILD + HOST=$TARGET fi if [ -z "$TARGET" ]; then - [ -z "$HOST" ] && HOST=$BUILD - TARGET=$HOST + [ -z "$HOST" ] && HOST=$BUILD + TARGET=$HOST fi if [ -z "$OS" ]; then - # Derive OS from cpu-manufacturer-os-kernel - CPU=${TARGET%%-*} - REST=${TARGET#*-} - MANU=${REST%%-*} - REST=${REST#*-} - OS=${REST%%-*} - REST=${REST#*-} - KERNEL=${REST%%-*} + # Derive OS from cpu-manufacturer-os-kernel + CPU=${TARGET%%-*} + REST=${TARGET#*-} + MANU=${REST%%-*} + REST=${REST#*-} + OS=${REST%%-*} + REST=${REST#*-} + KERNEL=${REST%%-*} fi OS_CFLAGS="-D__${OS}__" case "$OS" in - linux) - 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} - ;; + linux) + 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 'LDLIBS += -lutil\n' >>$CONFIG_MK + : ${BINGRP:=wheel} + ;; + freebsd) + printf 'LDLIBS += -lutil\n' >>$CONFIG_MK + : ${BINGRP:=wheel} + ;; + darwin) + : ${BINGRP:=wheel} + ;; esac : ${PREFIX:=/usr/local} @@ -127,108 +130,88 @@ esac : ${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} +PREFIX ?= ${PREFIX} +EPREFIX ?= ${EPREFIX} +BINDIR ?= ${BINDIR} +SHAREDIR ?= ${SHAREDIR} +MANDIR ?= ${MANDIR} +SYSCONFDIR?= ${SYSCONFDIR} +BINMODE ?= ${BINMODE} +BINOWN ?= ${BINOWN} +BINGRP ?= ${BINGRP} EOF [ -n "$OS_CFLAGS" ] && \ - printf 'CFLAGS += %s\n' "$OS_CFLAGS" >>$CONFIG_MK + printf 'OS_CFLAGS += %s\n' "$OS_CFLAGS" >>$CONFIG_MK [ -n "$DEBUG" ] && \ - printf 'CFLAGS += -O0 -g\n' >>$CONFIG_MK + printf 'CFLAGS += -O0 -g\n' >>$CONFIG_MK [ -n "$BUILD_STATIC" ] && \ - printf 'CFLAGS += -static\n' >>$CONFIG_MK + printf 'CFLAGS += -static\n' >>$CONFIG_MK -# Add CPPFLAGS/CFLAGS/LDFLAGS to CC for testing features -XCC="${CC:=cc} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS" +# Add CPPFLAGS/CFLAGS/LDFLAGS/LDLIBS to CC for testing features +XCC="${CC:=cc} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS $LDLIBS" # Make sure to disable --as-needed for CC tests. case "$OS" in - darwin) ;; - *) XCC="$XCC -Wl,--no-as-needed" ;; + darwin) ;; + *) XCC="$XCC -Wl,--no-as-needed" ;; esac check_func() { - func="$1"; src="$2"; shift 2 - 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' >&2 - printf '#define HAVE_%s\n' "$upperfunc" >>$CONFIG_H - return 0 - else - printf '/* #define HAVE_%s */\n' "$upperfunc" >>$CONFIG_H - printf 'no.\n' >&2 - return 1 - fi + func="$1"; src="$2"; shift 2 + 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' >&2 + printf '#define HAVE_%s\n' "$upperfunc" >>$CONFIG_H + return 0 + else + 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=' + src=' #include int main(void) { - return 0; + 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 + +printf 'SRCS += shadow.c\n' >>$CONFIG_MK +printf 'LDLIBS += -lcrypt\n' >>$CONFIG_MK +return 0 } +definsults() { + printf 'SRCS += insults.c\n' >>$CONFIG_MK + [ -z "$WITHOUT_INSULTS" ] && { + printf '#define DOAS_INSULTS\n' >>$CONFIG_H + } + return 0 +} + + 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 + [ -z "$WITHOUT_TIMESTAMP" ] && { + printf '#define USE_TIMESTAMP\n' >>$CONFIG_H + printf 'SRCS += timestamp.c\n' >>$CONFIG_MK + printf 'timestamp\n' + return 0 + } + return 1 } # @@ -237,11 +220,11 @@ persistmethod() { src=' #include int main(void) { - explicit_bzero(NULL, 0); - return 0; + explicit_bzero(NULL, 0); + return 0; }' check_func "explicit_bzero" "$src" || { - printf 'SRCS += libopenbsd/explicit_bzero.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/explicit_bzero.c\n' >>$CONFIG_MK } # @@ -250,13 +233,13 @@ check_func "explicit_bzero" "$src" || { src=' #include int main(void) { - const char s1[] = "foo"; - char s2[10]; - strlcat(s2, s1, sizeof(s2)); - return 0; + const char s1[] = "foo"; + char s2[10]; + strlcat(s2, s1, sizeof(s2)); + return 0; }' check_func "strlcat" "$src" || { - printf 'SRCS += libopenbsd/strlcat.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/strlcat.c\n' >>$CONFIG_MK } # @@ -265,13 +248,13 @@ check_func "strlcat" "$src" || { src=' #include int main(void) { - const char s1[] = "foo"; - char s2[10]; - strlcpy(s2, s1, sizeof(s2)); - return 0; + const char s1[] = "foo"; + char s2[10]; + strlcpy(s2, s1, sizeof(s2)); + return 0; }' check_func "strlcpy" "$src" || { - printf 'SRCS += libopenbsd/strlcpy.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/strlcpy.c\n' >>$CONFIG_MK } # @@ -280,24 +263,25 @@ check_func "strlcpy" "$src" || { src=' #include int main(void) { - errc(0, 0, ""); - return 0; + errc(0, 0, ""); + return 0; }' check_func "errc" "$src" || { - printf 'SRCS += libopenbsd/errc.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/errc.c\n' >>$CONFIG_MK } # # Check for verrc(). # src=' +#include #include int main(void) { - verrc(0, 0, ""); - return 0; + verrc(0, 0, "x", NULL); + return 0; }' check_func "verrc" "$src" || { - printf 'SRCS += libopenbsd/verrc.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/verrc.c\n' >>$CONFIG_MK } # @@ -306,11 +290,11 @@ check_func "verrc" "$src" || { src=' #include int main(void) { - setprogname(""); - return 0; + setprogname(""); + return 0; }' check_func "setprogname" "$src" || { - printf 'SRCS += libopenbsd/progname.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/progname.c\n' >>$CONFIG_MK } # @@ -319,12 +303,12 @@ check_func "setprogname" "$src" || { src=' #include int main(void) { - char buf[12]; - readpassphrase("", buf, sizeof(buf), 0); - return 0; + char buf[12]; + readpassphrase("", buf, sizeof(buf), 0); + return 0; }' check_func "readpassphrase" "$src" || { - printf 'SRCS += libopenbsd/readpassphrase.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/readpassphrase.c\n' >>$CONFIG_MK } # @@ -333,12 +317,12 @@ check_func "readpassphrase" "$src" || { src=' #include int main(void) { - const char *errstr; - strtonum("", 1, 64, &errstr); - return 0; + const char *errstr; + strtonum("", 1, 64, &errstr); + return 0; }' check_func "strtonum" "$src" || { - printf 'SRCS += libopenbsd/strtonum.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/strtonum.c\n' >>$CONFIG_MK } # @@ -347,11 +331,11 @@ check_func "strtonum" "$src" || { src=' #include int main(void) { - reallocarray(NULL, 0, 0); - return 0; + reallocarray(NULL, 0, 0); + return 0; }' check_func "reallocarray" "$src" || { - printf 'SRCS += libopenbsd/reallocarray.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/reallocarray.c\n' >>$CONFIG_MK } # @@ -360,12 +344,12 @@ check_func "reallocarray" "$src" || { src=' #include int main(void) { - const char *p = { "", NULL }; - execvpe("", p, p); - return 0; + const char *p = { "", NULL }; + execvpe("", p, p); + return 0; }' check_func "execvpe" "$src" || { - printf 'SRCS += libopenbsd/execvpe.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/execvpe.c\n' >>$CONFIG_MK } # @@ -374,12 +358,50 @@ check_func "execvpe" "$src" || { src=' #include int main(void) { - setresuid(0, 0, 0); - return 0; + setresuid(0, 0, 0); + return 0; }' -check_func "setresuid" "$src" || { - printf 'SRCS += libopenbsd/bsd-setres_id.c\n' >>$CONFIG_MK -} +check_func "setresuid" "$src" +have_setresuid=$? + +# +# Check for setresgid(). +# +src=' +#include +int main(void) { + setresgid(0, 0, 0); + return 0; +}' +check_func "setresgid" "$src" +have_setresgid=$? + +if [ $have_setresuid -eq 1 -o $have_setresgid -eq 1 ]; then + printf 'SRCS += libopenbsd/bsd-setres_id.c\n' >>$CONFIG_MK +fi + +# +# Check for setreuid(). +# +src=' +#include +int main(void) { + setreuid(0, 0); + return 0; +}' +check_func "setreuid" "$src" + + +# +# Check for setregid(). +# +src=' +#include +int main(void) { + setregid(0, 0); + return 0; +}' +check_func "setregid" "$src" # # Check for closefrom(). @@ -387,11 +409,11 @@ check_func "setresuid" "$src" || { src=' #include int main(void) { - closefrom(0); - return 0; + closefrom(0); + return 0; }' check_func "closefrom" "$src" || { - printf 'SRCS += libopenbsd/closefrom.c\n' >>$CONFIG_MK + printf 'SRCS += libopenbsd/closefrom.c\n' >>$CONFIG_MK } # @@ -400,8 +422,8 @@ check_func "closefrom" "$src" || { src=' #include int main(void) { - (void)sysconf(0); - return 0; + (void)sysconf(0); + return 0; }' check_func "sysconf" "$src" @@ -411,8 +433,8 @@ check_func "sysconf" "$src" src=' #include int main(void) { - (void)dirfd(0); - return 0; + (void)dirfd(0); + return 0; }' check_func "dirfd" "$src" @@ -422,7 +444,7 @@ check_func "dirfd" "$src" src=' #include int main(void) { - return 0; + return 0; }' check_func "fcntl_h" "$src" @@ -435,7 +457,7 @@ src=' #error no F_CLOSEM #endif int main(void) { - return 0; + return 0; }' check_func "F_CLOSEM" "$src" @@ -445,7 +467,7 @@ check_func "F_CLOSEM" "$src" src=' #include int main(void) { - return 0; + return 0; }' check_func "dirent_h" "$src" @@ -455,7 +477,7 @@ check_func "dirent_h" "$src" src=' #include int main(void) { - return 0; + return 0; }' check_func "sys_ndir_h" "$src" @@ -465,7 +487,7 @@ check_func "sys_ndir_h" "$src" src=' #include int main(void) { - return 0; + return 0; }' check_func "sys_dir_h" "$src" @@ -475,7 +497,7 @@ check_func "sys_dir_h" "$src" src=' #include int main(void) { - return 0; + return 0; }' check_func "ndir_h" "$src" @@ -486,7 +508,7 @@ src=' #include #include int main(void) { - return 0; + return 0; }' check_func "login_cap_h" "$src" @@ -499,22 +521,18 @@ int main(void){return 0;} __attribute__((__unused__)) static void foo(void){return;} ' check_func "__attribute__" "$src" || { - printf 'CFLAGS += -DNO_ATTRIBUTE_ON_RETURN_TYPE=1\n' >>$CONFIG_MK + printf 'OS_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 + +insults=$(definsults) persist=$(persistmethod) if [ $? -eq 0 ]; then - printf 'Using persist method\t\t\t%s.\n' "$persist" >&2 + printf 'Using persist method\t\t\t%s.\n' "$persist" >&2 else - printf 'Using persist method\t\t\tnone.\n' >&2 + printf 'Using persist method\t\t\tnone.\n' >&2 fi printf '#define DOAS_CONF "%s/doas.conf"\n' "${SYSCONFDIR}" >>$CONFIG_H