Annotation of embedaddon/sudo/m4/sudo.m4, revision 1.1.1.1

1.1       misho       1: dnl Local m4 macros for autoconf (used by sudo)
                      2: dnl
                      3: dnl Copyright (c) 1994-1996, 1998-2005, 2007-2014
                      4: dnl    Todd C. Miller <Todd.Miller@courtesan.com>
                      5: dnl
                      6: dnl XXX - should cache values in all cases!!!
                      7: dnl
                      8: dnl checks for programs
                      9: 
                     10: dnl
                     11: dnl check for sendmail in well-known locations
                     12: dnl
                     13: AC_DEFUN([SUDO_PROG_SENDMAIL], [AC_MSG_CHECKING([for sendmail])
                     14: found=no
                     15: for p in "/usr/sbin/sendmail" "/usr/lib/sendmail" "/usr/etc/sendmail" "/usr/ucblib/sendmail" "/usr/local/lib/sendmail" "/usr/local/bin/sendmail"; do
                     16:     if test -f "$p"; then
                     17:        found=yes
                     18:        AC_MSG_RESULT([$p])
                     19:        SUDO_DEFINE_UNQUOTED(_PATH_SUDO_SENDMAIL, "$p")
                     20:        break
                     21:     fi
                     22: done
                     23: if test X"$found" != X"yes"; then
                     24:     AC_MSG_RESULT([not found])
                     25: fi
                     26: ])dnl
                     27: 
                     28: dnl
                     29: dnl check for vi in well-known locations
                     30: dnl
                     31: AC_DEFUN([SUDO_PROG_VI], [AC_MSG_CHECKING([for vi])
                     32: found=no
                     33: for editor in "/usr/bin/vi" "/bin/vi" "/usr/ucb/vi" "/usr/bsd/vi" "/usr/local/bin/vi"; do
                     34:     if test -f "$editor"; then
                     35:        found=yes
                     36:        AC_MSG_RESULT([$editor])
                     37:        SUDO_DEFINE_UNQUOTED(_PATH_VI, "$editor")
                     38:        break
                     39:     fi
                     40: done
                     41: if test X"$found" != X"yes"; then
                     42:     AC_MSG_RESULT([not found])
                     43: fi
                     44: ])dnl
                     45: 
                     46: dnl
                     47: dnl check for mv in well-known locations
                     48: dnl
                     49: AC_DEFUN([SUDO_PROG_MV], [AC_MSG_CHECKING([for mv])
                     50: found=no
                     51: for p in "/usr/bin/mv" "/bin/mv" "/usr/ucb/mv" "/usr/sbin/mv"; do
                     52:     if test -f "$p"; then
                     53:        found=yes
                     54:        AC_MSG_RESULT([$p])
                     55:        SUDO_DEFINE_UNQUOTED(_PATH_MV, "$p")
                     56:        break
                     57:     fi
                     58: done
                     59: if test X"$found" != X"yes"; then
                     60:     AC_MSG_RESULT([not found])
                     61: fi
                     62: ])dnl
                     63: 
                     64: dnl
                     65: dnl check for bourne shell in well-known locations
                     66: dnl
                     67: AC_DEFUN([SUDO_PROG_BSHELL], [AC_MSG_CHECKING([for bourne shell])
                     68: found=no
                     69: for p in "/bin/sh" "/usr/bin/sh" "/sbin/sh" "/usr/sbin/sh" "/bin/ksh" "/usr/bin/ksh" "/bin/bash" "/usr/bin/bash"; do
                     70:     if test -f "$p"; then
                     71:        found=yes
                     72:        AC_MSG_RESULT([$p])
                     73:        SUDO_DEFINE_UNQUOTED(_PATH_BSHELL, "$p")
                     74:        break
                     75:     fi
                     76: done
                     77: if test X"$found" != X"yes"; then
                     78:     AC_MSG_RESULT([not found])
                     79: fi
                     80: ])dnl
                     81: 
                     82: dnl
                     83: dnl check for utmp file
                     84: dnl
                     85: AC_DEFUN([SUDO_PATH_UTMP], [AC_MSG_CHECKING([for utmp file path])
                     86: found=no
                     87: for p in "/var/run/utmp" "/var/adm/utmp" "/etc/utmp"; do
                     88:     if test -r "$p"; then
                     89:        found=yes
                     90:        AC_MSG_RESULT([$p])
                     91:        SUDO_DEFINE_UNQUOTED(_PATH_UTMP, "$p")
                     92:        break
                     93:     fi
                     94: done
                     95: if test X"$found" != X"yes"; then
                     96:     AC_MSG_RESULT([not found])
                     97: fi
                     98: ])dnl
                     99: 
                    100: dnl
                    101: dnl Where the log file goes, use /var/log if it exists, else /{var,usr}/adm
                    102: dnl
                    103: AC_DEFUN([SUDO_LOGFILE], [AC_MSG_CHECKING(for log file location)
                    104: if test -n "$with_logpath"; then
                    105:     AC_MSG_RESULT($with_logpath)
                    106:     SUDO_DEFINE_UNQUOTED(_PATH_SUDO_LOGFILE, "$with_logpath")
                    107: elif test -d "/var/log"; then
                    108:     AC_MSG_RESULT(/var/log/sudo.log)
                    109:     SUDO_DEFINE(_PATH_SUDO_LOGFILE, "/var/log/sudo.log")
                    110: elif test -d "/var/adm"; then
                    111:     AC_MSG_RESULT(/var/adm/sudo.log)
                    112:     SUDO_DEFINE(_PATH_SUDO_LOGFILE, "/var/adm/sudo.log")
                    113: elif test -d "/usr/adm"; then
                    114:     AC_MSG_RESULT(/usr/adm/sudo.log)
                    115:     SUDO_DEFINE(_PATH_SUDO_LOGFILE, "/usr/adm/sudo.log")
                    116: else
                    117:     AC_MSG_RESULT(unknown, you will have to set _PATH_SUDO_LOGFILE by hand)
                    118: fi
                    119: ])dnl
                    120: 
                    121: dnl
                    122: dnl Parent directory for time stamp dir.
                    123: dnl
                    124: AC_DEFUN([SUDO_RUNDIR], [AC_MSG_CHECKING(for sudo run dir location)
                    125: rundir="$with_rundir"
                    126: if test -z "$rundir"; then
                    127:     for d in /var/run /var/db /var/lib /var/adm /usr/adm; do
                    128:        if test -d "$d"; then
                    129:            rundir="$d/sudo"
                    130:            break
                    131:        fi
                    132:     done
                    133: fi
                    134: AC_MSG_RESULT([$rundir])
                    135: SUDO_DEFINE_UNQUOTED(_PATH_SUDO_TIMEDIR, "$rundir/ts")
                    136: ])dnl
                    137: 
                    138: dnl
                    139: dnl Parent directory for the lecture status dir.
                    140: dnl
                    141: AC_DEFUN([SUDO_VARDIR], [AC_MSG_CHECKING(for sudo var dir location)
                    142: vardir="$with_vardir"
                    143: if test -z "$vardir"; then
                    144:     for d in /var/db /var/lib /var/adm /usr/adm; do
                    145:        if test -d "$d"; then
                    146:            vardir="$d/sudo"
                    147:            break
                    148:        fi
                    149:     done
                    150: fi
                    151: AC_MSG_RESULT([$vardir])
                    152: SUDO_DEFINE_UNQUOTED(_PATH_SUDO_LECTURE_DIR, "$vardir/lectured")
                    153: ])dnl
                    154: 
                    155: dnl
                    156: dnl Where the I/O log files go, use /var/log/sudo-io if
                    157: dnl /var/log exists, else /{var,usr}/adm/sudo-io
                    158: dnl
                    159: AC_DEFUN([SUDO_IO_LOGDIR], [
                    160:     AC_MSG_CHECKING(for I/O log dir location)
                    161:     if test "${with_iologdir-yes}" != "yes"; then
                    162:        iolog_dir="$with_iologdir"
                    163:     elif test -d "/var/log"; then
                    164:        iolog_dir="/var/log/sudo-io"
                    165:     elif test -d "/var/adm"; then
                    166:        iolog_dir="/var/adm/sudo-io"
                    167:     else
                    168:        iolog_dir="/usr/adm/sudo-io"
                    169:     fi
                    170:     if test "${with_iologdir}" != "no"; then
                    171:        SUDO_DEFINE_UNQUOTED(_PATH_SUDO_IO_LOGDIR, "$iolog_dir")
                    172:     fi
                    173:     AC_MSG_RESULT($iolog_dir)
                    174: ])dnl
                    175: 
                    176: dnl
                    177: dnl check for working fnmatch(3)
                    178: dnl
                    179: AC_DEFUN([SUDO_FUNC_FNMATCH],
                    180: [AC_MSG_CHECKING([for working fnmatch with FNM_CASEFOLD])
                    181: AC_CACHE_VAL(sudo_cv_func_fnmatch,
                    182: [rm -f conftestdata; > conftestdata
                    183: AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <fnmatch.h>
                    184: main() { exit(fnmatch("/*/bin/echo *", "/usr/bin/echo just a test", FNM_CASEFOLD)); }]])], [sudo_cv_func_fnmatch=yes], [sudo_cv_func_fnmatch=no],
                    185:   [sudo_cv_func_fnmatch=no])
                    186: rm -f core core.* *.core])
                    187: AC_MSG_RESULT($sudo_cv_func_fnmatch)
                    188: AS_IF([test $sudo_cv_func_fnmatch = yes], [$1], [$2])])
                    189: 
                    190: dnl
                    191: dnl Attempt to check for working PIE support.
                    192: dnl This is a bit of a hack but on Solaris 10 with GNU ld and GNU as
                    193: dnl we can end up with strange values from malloc().
                    194: dnl A better check would be to verify that ASLR works with PIE.
                    195: dnl
                    196: AC_DEFUN([SUDO_WORKING_PIE],
                    197: [AC_MSG_CHECKING([for working PIE support])
                    198: AC_CACHE_VAL(sudo_cv_working_pie,
                    199: [rm -f conftestdata; > conftestdata
                    200: AC_RUN_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT
                    201: main() { char *p = malloc(1024); if (p == NULL) return 1; memset(p, 0, 1024); return 0; }])], [sudo_cv_working_pie=yes], [sudo_cv_working_pie=no],
                    202:   [sudo_cv_working_pie=no])
                    203: rm -f core core.* *.core])
                    204: AC_MSG_RESULT($sudo_cv_working_pie)
                    205: AS_IF([test $sudo_cv_working_pie = yes], [$1], [$2])])
                    206: 
                    207: dnl
                    208: dnl check for isblank(3)
                    209: dnl
                    210: AC_DEFUN([SUDO_FUNC_ISBLANK],
                    211:   [AC_CACHE_CHECK([for isblank], [sudo_cv_func_isblank],
                    212:     [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <ctype.h>]], [[return (isblank('a'));]])],
                    213:     [sudo_cv_func_isblank=yes], [sudo_cv_func_isblank=no])])
                    214: ] [
                    215:   if test "$sudo_cv_func_isblank" = "yes"; then
                    216:     AC_DEFINE(HAVE_ISBLANK, 1, [Define if you have isblank(3).])
                    217:   else
                    218:     AC_LIBOBJ(isblank)
                    219:   fi
                    220: ])
                    221: 
                    222: AC_DEFUN([SUDO_CHECK_LIB], [
                    223:     _sudo_check_lib_extras=`echo "$5"|sed -e 's/[      ]*//g' -e 's/-l/_/g'`
                    224:     AC_MSG_CHECKING([for $2 in -l$1${5+ }$5])
                    225:     AC_CACHE_VAL([sudo_cv_lib_$1''_$2$_sudo_check_lib_extras], [
                    226:        SUDO_CHECK_LIB_OLIBS="$LIBS"
                    227:        LIBS="$LIBS -l$1${5+ }$5"
                    228:        AC_LINK_IFELSE(
                    229:            [AC_LANG_CALL([], [$2])],
                    230:            [eval sudo_cv_lib_$1''_$2$_sudo_check_lib_extras=yes],
                    231:            [eval sudo_cv_lib_$1''_$2$_sudo_check_lib_extras=no]
                    232:        )
                    233:        LIBS="$SUDO_CHECK_LIB_OLIBS"
                    234:     ])
                    235:     if eval test \$sudo_cv_lib_$1''_$2$_sudo_check_lib_extras = "yes"; then
                    236:        AC_MSG_RESULT([yes])
                    237:        $3
                    238:     else
                    239:        AC_MSG_RESULT([no])
                    240:        $4
                    241:     fi
                    242: ])
                    243: 
                    244: dnl
                    245: dnl check unsetenv() return value
                    246: dnl
                    247: AC_DEFUN([SUDO_FUNC_UNSETENV_VOID],
                    248:   [AC_CACHE_CHECK([whether unsetenv returns void], [sudo_cv_func_unsetenv_void],
                    249:     [AC_RUN_IFELSE([AC_LANG_PROGRAM(
                    250:       [AC_INCLUDES_DEFAULT
                    251:         int unsetenv();
                    252:       ], [
                    253:         [return unsetenv("FOO") != 0;]
                    254:       ])
                    255:     ],
                    256:     [sudo_cv_func_unsetenv_void=no],
                    257:     [sudo_cv_func_unsetenv_void=yes],
                    258:     [sudo_cv_func_unsetenv_void=no])])
                    259:     if test $sudo_cv_func_unsetenv_void = yes; then
                    260:       AC_DEFINE(UNSETENV_VOID, 1,
                    261:         [Define to 1 if the `unsetenv' function returns void instead of `int'.])
                    262:     fi
                    263:   ])
                    264: 
                    265: dnl
                    266: dnl check putenv() argument for const
                    267: dnl
                    268: AC_DEFUN([SUDO_FUNC_PUTENV_CONST],
                    269: [AC_CACHE_CHECK([whether putenv takes a const argument],
                    270: sudo_cv_func_putenv_const,
                    271: [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
                    272: int putenv(const char *string) {return 0;}], [])],
                    273:     [sudo_cv_func_putenv_const=yes],
                    274:     [sudo_cv_func_putenv_const=no])
                    275:   ])
                    276:   if test $sudo_cv_func_putenv_const = yes; then
                    277:     AC_DEFINE(PUTENV_CONST, const, [Define to const if the `putenv' takes a const argument.])
                    278:   else
                    279:     AC_DEFINE(PUTENV_CONST, [])
                    280:   fi
                    281: ])
                    282: 
                    283: dnl
                    284: dnl check for sa_len field in struct sockaddr
                    285: dnl
                    286: AC_DEFUN([SUDO_SOCK_SA_LEN], [
                    287:     AC_CHECK_MEMBER([struct sockaddr.sa_len], 
                    288:        [AC_DEFINE(HAVE_STRUCT_SOCKADDR_SA_LEN, 1, [Define if your struct sockaddr has an sa_len field.])],
                    289:        [], [
                    290: #        include <sys/types.h>
                    291: #        include <sys/socket.h>] 
                    292:     )]
                    293: )
                    294: 
                    295: dnl
                    296: dnl check for sin_len field in struct sockaddr_in
                    297: dnl
                    298: AC_DEFUN([SUDO_SOCK_SIN_LEN], [
                    299:     AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
                    300:        [AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN, 1, [Define if your struct sockaddr_in has a sin_len field.])],
                    301:        [], [
                    302: #        include <sys/types.h>
                    303: #        include <sys/socket.h>]
                    304:     )]
                    305: )
                    306: 
                    307: dnl
                    308: dnl check for max length of uid_t in string representation.
                    309: dnl we can't really trust UID_MAX or MAXUID since they may exist
                    310: dnl only for backwards compatibility.
                    311: dnl
                    312: AC_DEFUN([SUDO_UID_T_LEN],
                    313: [AC_REQUIRE([AC_TYPE_UID_T])
                    314: AC_MSG_CHECKING(max length of uid_t)
                    315: AC_CACHE_VAL(sudo_cv_uid_t_len,
                    316: [rm -f conftestdata
                    317: AC_RUN_IFELSE([AC_LANG_SOURCE([[
                    318: #include <stdio.h>
                    319: #include <pwd.h>
                    320: #include <limits.h>
                    321: #include <sys/types.h>
                    322: #include <sys/param.h>
                    323: main() {
                    324:   FILE *f;
                    325:   char b[1024];
                    326:   uid_t u = (uid_t) -1;
                    327: 
                    328:   if ((f = fopen("conftestdata", "w")) == NULL)
                    329:     exit(1);
                    330: 
                    331:   (void) sprintf(b, "%lu", (unsigned long) u);
                    332:   (void) fprintf(f, "%d\n", strlen(b));
                    333:   (void) fclose(f);
                    334:   exit(0);
                    335: }]])], [sudo_cv_uid_t_len=`cat conftestdata`], [sudo_cv_uid_t_len=10], [sudo_cv_uid_t_len=10])
                    336: ])
                    337: rm -f conftestdata
                    338: AC_MSG_RESULT($sudo_cv_uid_t_len)
                    339: AC_DEFINE_UNQUOTED(MAX_UID_T_LEN, $sudo_cv_uid_t_len, [Define to the max length of a uid_t in string context (excluding the NUL).])
                    340: ])
                    341: 
                    342: dnl
                    343: dnl Append a libpath to an LDFLAGS style variable if not already present.
                    344: dnl Also appends to the _R version unless rpath is disabled.
                    345: dnl
                    346: AC_DEFUN([SUDO_APPEND_LIBPATH], [
                    347:     case "${$1}" in
                    348:        *"-L$2"|*"-L$2 ")
                    349:            ;;
                    350:        *)
                    351:            $1="${$1} -L$2"
                    352:            if test X"$enable_rpath" = X"yes"; then
                    353:                $1_R="${$1_R} -R$2"
                    354:            fi
                    355:            ;;
                    356:     esac
                    357: ])
                    358: 
                    359: dnl
                    360: dnl Append a directory to CPPFLAGS if not already present.
                    361: dnl
                    362: AC_DEFUN([SUDO_APPEND_CPPFLAGS], [
                    363:     case "${CPPFLAGS}" in
                    364:        *"$1"|*"$1 ")
                    365:            ;;
                    366:        *)
                    367:            if test X"${CPPFLAGS}" = X""; then
                    368:                CPPFLAGS="$1"
                    369:            else
                    370:                CPPFLAGS="${CPPFLAGS} $1"
                    371:            fi
                    372:            ;;
                    373:     esac
                    374: ])
                    375: 
                    376: dnl
                    377: dnl Determine the mail spool location
                    378: dnl NOTE: must be run *after* check for paths.h
                    379: dnl
                    380: AC_DEFUN([SUDO_MAILDIR], [
                    381: maildir=no
                    382: if test X"$ac_cv_header_paths_h" = X"yes"; then
                    383: AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
                    384: #include <paths.h>],
                    385: [char *p = _PATH_MAILDIR;])], [maildir=yes], [])
                    386: fi
                    387: if test $maildir = no; then
                    388:     # Solaris has maillock.h which defines MAILDIR
                    389:     AC_CHECK_HEADERS(maillock.h, [
                    390:        SUDO_DEFINE(_PATH_MAILDIR, MAILDIR)
                    391:        maildir=yes
                    392:     ])
                    393:     if test $maildir = no; then
                    394:        for d in /var/mail /var/spool/mail /usr/spool/mail; do
                    395:            if test -d "$d"; then
                    396:                maildir=yes
                    397:                SUDO_DEFINE_UNQUOTED(_PATH_MAILDIR, "$d")
                    398:                break
                    399:            fi
                    400:        done
                    401:        if test $maildir = no; then
                    402:            # unable to find mail dir, hope for the best
                    403:            SUDO_DEFINE_UNQUOTED(_PATH_MAILDIR, "/var/mail")
                    404:        fi
                    405:     fi
                    406: fi
                    407: ])
                    408: 
                    409: dnl
                    410: dnl private versions of AC_DEFINE and AC_DEFINE_UNQUOTED that don't support
                    411: dnl tracing that we use to define paths for pathnames.h so autoheader doesn't
                    412: dnl put them in config.h.in.  An awful hack.
                    413: dnl
                    414: m4_define([SUDO_DEFINE],
                    415: [cat >>confdefs.h <<\EOF
                    416: [@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
                    417: EOF
                    418: ])
                    419: 
                    420: m4_define([SUDO_DEFINE_UNQUOTED],
                    421: [cat >>confdefs.h <<EOF
                    422: [@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
                    423: EOF
                    424: ])

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>