From f5f4eae173cfa61b3665e327d828f203fa6d72f3 Mon Sep 17 00:00:00 2001 From: Sam James Date: Fri, 24 Dec 2021 22:02:20 +0800 Subject: [PATCH 2/2] autofs-5.1.8 - fix bashism in configure configure scripts need to work with a POSIX-compliant shell, so let's not use a bashism here. ``` checking for res_query in -lresolv... yes checking for libhesiod... no ./configure: 4880: test: 0: unexpected operator checking how to run the C preprocessor... gcc -E ``` Tested-by: Yixun Lan Signed-off-by: Sam James autofs-5.1.8 - fix missing include in hash.h Fixes a build failure with the musl libc: ``` ../include/hash.h:74:8: error: unknown type name '__always_inline' 74 | static __always_inline uint32_t hash_64(uint64_t val, unsigned int bits) | ^~~~~~~~~~~~~~~ ``` We need to include stddef.h from linux-headers to ensure _always_inline is always defined. Bug: https://bugs.gentoo.org/828918 Tested-by: Yixun Lan Signed-off-by: Sam James autofs-5.1.8 - define fallback dummy NSS config path On musl, _PATH_NSSWITCH_CONF won't be defined (it doesn't support NSS), so let's give it a dummy path when it's not defined by glibc. Fixes build failures like: ``` ../include/nsswitch.h:27:23: error: '_PATH_NSSWITCH_CONF' undeclared (first use in this function) 27 | #define NSSWITCH_FILE _PATH_NSSWITCH_CONF | ^~~~~~~~~~~~~~~~~~~ ``` Tested-by: Yixun Lan Signed-off-by: Sam James autofs-5.1.8 - avoid internal stat.h definitions Tested-by: Yixun Lan Signed-off-by: Sam James autofs-5.1.8 - add missing include to hash.h for _WORDSIZE Fixes build failure on musl like: ``` ../include/hash.h:22:2: error: #error Wordsize not 32 or 64 22 | #error Wordsize not 32 or 64 | ^~~~~ ``` Tested-by: Yixun Lan Signed-off-by: Sam James autofs-5.1.8 - add missing include to log.h for pid_t Fixes build failures on musl like: ``` ../include/log.h:49:8: error: unknown type name 'pid_t' 49 | extern pid_t log_pidinfo(struct autofs_point *ap, pid_t pid, char *label); | ^~~~~ ../include/log.h:49:51: error: unknown type name 'pid_t'; did you mean 'gid_t'? 49 | extern pid_t log_pidinfo(struct autofs_point *ap, pid_t pid, char *label); | ^~~~~ | gid_t ``` Tested-by: Yixun Lan Signed-off-by: Sam James autofs-5.1.8 - define _SWORD_TYPE for musl Copy the definition from glibc. Fixes build failures like: ``` automount.c:280:35: error: '__SWORD_TYPE' undeclared (first use in this function) 280 | if (fs.f_type != (__SWORD_TYPE) AUTOFS_SUPER_MAGIC) { | ^~~~~~~~~~~~ automount.c:280:35: note: each undeclared identifier is reported only once for each function it appears in automount.c:280:48: error: expected ')' before numeric constant 280 | if (fs.f_type != (__SWORD_TYPE) AUTOFS_SUPER_MAGIC) { | ~ ^ | ) ``` Tested-by: Yixun Lan Signed-off-by: Sam James autofs-5.1.8 - add autofs_strerror_r() helper for musl If using musl libc the XSI-compliant variant strerror_r() which returns an integer instead of a pointer so add a helper function to handle this case. Signed-off-by: Fabian Groffen Signed-off-by: Ian Kent autofs-5.1.8 - handle innetgr() not present in musl The function innetgr(3) may not be present in musl libc, add a check for this. Originally contributed by Fabian, modified by me. Signed-off-by: Fabian Groffen Signed-off-by: Ian Kent --- configure | 9 +++++---- configure.in | 8 ++++---- daemon/automount.c | 10 ++++++++++ daemon/lookup.c | 6 +++--- include/automount.h | 5 +++++ include/config.h.in | 3 +++ include/hash.h | 6 ++++++ include/log.h | 2 ++ include/nsswitch.h | 4 ++++ lib/log.c | 10 ++++++++++ modules/lookup_multi.c | 4 ++-- modules/parse_amd.c | 7 +++++++ 12 files changed, 61 insertions(+), 13 deletions(-) diff --git a/configure b/configure index 394a8d5..33446b0 100755 --- a/configure +++ b/configure @@ -4227,12 +4227,13 @@ fi -for ac_func in pipe2 +for ac_func in pipe2 innetgr do : - ac_fn_c_check_func "$LINENO" "pipe2" "ac_cv_func_pipe2" -if test "x$ac_cv_func_pipe2" = xyes; then : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF -#define HAVE_PIPE2 1 +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi diff --git a/configure.in b/configure.in index 750ffb4..68cbd44 100644 --- a/configure.in +++ b/configure.in @@ -169,7 +169,7 @@ AF_CHECK_SSS_LIB(SSS_AUTOFS, libsss_autofs.so) AC_SUBST(HAVE_SSS_AUTOFS) AC_SUBST(sssldir) -AC_CHECK_FUNCS(pipe2) +AC_CHECK_FUNCS(pipe2 innetgr) # # Newer mounts have the -s (sloppy) option to ignore unknown options, @@ -262,7 +262,7 @@ if test -z "$HAVE_HESIOD" -o "$HAVE_HESIOD" != "0" then HAVE_HESIOD=0 AF_CHECK_LIBHESIOD() - if test "$HAVE_HESIOD" == "1"; then + if test "$HAVE_HESIOD" = "1"; then AC_DEFINE(WITH_HESIOD,1, [Define if using Hesiod as a source of automount maps]) fi @@ -337,11 +337,11 @@ AC_ARG_WITH(sasl, SASL_FLAGS="-I${withval}/include" fi ) -if test -z "$HAVE_SASL" -o "$HAVE_SASL" != "0" -a "$HAVE_LIBXML" == "1" +if test -z "$HAVE_SASL" -o "$HAVE_SASL" != "0" -a "$HAVE_LIBXML" = "1" then HAVE_SASL=0 AC_CHECK_LIB(sasl2, sasl_client_start, HAVE_SASL=1 LIBSASL="$LIBSASL -lsasl2", , -lsasl2 $LIBS) - if test "$HAVE_SASL" == "1"; then + if test "$HAVE_SASL" = "1"; then AC_DEFINE(WITH_SASL,1, [Define if using SASL authentication with the LDAP module]) fi diff --git a/daemon/automount.c b/daemon/automount.c index cc28689..5dffce0 100644 --- a/daemon/automount.c +++ b/daemon/automount.c @@ -48,6 +48,16 @@ #endif #endif +#ifndef __SWORD_TYPE +#if __WORDSIZE == 32 +# define __SWORD_TYPE int +#elif __WORDSIZE == 64 +# define __SWORD_TYPE long int +#else +#error +#endif +#endif + const char *program; /* Initialized with argv[0] */ const char *version = VERSION_STRING; /* Program version */ const char *libdir = AUTOFS_LIB_DIR; /* Location of library modules */ diff --git a/daemon/lookup.c b/daemon/lookup.c index 0b281f8..4a286d6 100644 --- a/daemon/lookup.c +++ b/daemon/lookup.c @@ -397,7 +397,7 @@ static int read_file_source_instance(struct autofs_point *ap, struct map_source return NSS_STATUS_NOTFOUND; } - if (st.st_mode & __S_IEXEC) + if (st.st_mode & S_IEXEC) type = src_prog; else type = src_file; @@ -930,7 +930,7 @@ static int lookup_name_file_source_instance(struct autofs_point *ap, struct map_ return NSS_STATUS_NOTFOUND; } - if (st.st_mode & __S_IEXEC) + if (st.st_mode & S_IEXEC) type = src_prog; else type = src_file; @@ -1077,7 +1077,7 @@ static struct map_source *lookup_get_map_source(struct master_mapent *entry) if (!S_ISREG(st.st_mode)) return NULL; - if (st.st_mode & __S_IEXEC) + if (st.st_mode & S_IEXEC) type = "program"; else type = "file"; diff --git a/include/automount.h b/include/automount.h index 947ed16..d2d05d8 100644 --- a/include/automount.h +++ b/include/automount.h @@ -43,6 +43,11 @@ #define ENABLE_CORES 1 +#ifndef __GLIBC__ +# define strerror_r(N,B,S) autofs_strerror_r(N,B,S) +char *autofs_strerror_r(int errnum, char *buf, size_t buflen); /* GNU */ +#endif + /* We MUST have the paths to mount(8) and umount(8) */ #ifndef HAVE_MOUNT #error Failed to locate mount(8)! diff --git a/include/config.h.in b/include/config.h.in index 4e36b39..4f8daa8 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -30,6 +30,9 @@ /* Define to 1 if you have the `getservbyname' function. */ #undef HAVE_GETSERVBYNAME +/* Define to 1 if you have the `innetgr' function. */ +#undef HAVE_INNETGR + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H diff --git a/include/hash.h b/include/hash.h index 2447f29..0f1d7b5 100644 --- a/include/hash.h +++ b/include/hash.h @@ -3,6 +3,12 @@ /* Fast hashing routine for ints, longs and pointers. (C) 2002 Nadia Yvette Chambers, IBM */ +#ifdef __GLIBC__ +#include +#else +#include +#endif +#include #include #include diff --git a/include/log.h b/include/log.h index 69eed96..a7b09f9 100644 --- a/include/log.h +++ b/include/log.h @@ -17,6 +17,8 @@ #ifndef LOG_H #define LOG_H +#include + /* Define logging functions */ #define LOGOPT_NONE 0x0000 diff --git a/include/nsswitch.h b/include/nsswitch.h index d3e4027..8376113 100644 --- a/include/nsswitch.h +++ b/include/nsswitch.h @@ -24,6 +24,10 @@ #include #include "list.h" +#ifndef _PATH_NSSWITCH_CONF +#define _PATH_NSSWITCH_CONF "/dev/null" +#endif + #define NSSWITCH_FILE _PATH_NSSWITCH_CONF enum nsswitch_status { diff --git a/lib/log.c b/lib/log.c index 0cb47d7..aa4a180 100644 --- a/lib/log.c +++ b/lib/log.c @@ -364,3 +364,13 @@ pid_t log_pidinfo(struct autofs_point *ap, pid_t pid, char *label) { return ppid; } + +#ifndef __GLIBC__ +# undef strerror_r +char *autofs_strerror_r(int errnum, char *buf, size_t buflen) { + int s = strerror_r(errnum, buf, buflen); + if (s) + return NULL; + return buf; +} +#endif diff --git a/modules/lookup_multi.c b/modules/lookup_multi.c index fadd2ea..cf109de 100644 --- a/modules/lookup_multi.c +++ b/modules/lookup_multi.c @@ -247,7 +247,7 @@ static struct lookup_mod *nss_open_lookup(const char *format, int argc, const ch continue; } - if (st.st_mode & __S_IEXEC) + if (st.st_mode & S_IEXEC) type = src_prog; else type = src_file; @@ -452,7 +452,7 @@ int lookup_reinit(const char *my_mapfmt, continue; } - if (st.st_mode & __S_IEXEC) + if (st.st_mode & S_IEXEC) type = src_prog; else type = src_file; diff --git a/modules/parse_amd.c b/modules/parse_amd.c index 163174c..5090060 100644 --- a/modules/parse_amd.c +++ b/modules/parse_amd.c @@ -425,6 +425,7 @@ static int sel_in_network(struct autofs_point *ap, return ret; } +#ifdef HAVE_INNETGR static int sel_netgrp(struct autofs_point *ap, struct selector *s, struct substvar *sv) { @@ -489,6 +490,7 @@ out: return ret; } +#endif static int eval_selector(struct autofs_point *ap, struct amd_entry *this, struct substvar *sv) @@ -628,7 +630,12 @@ static int eval_selector(struct autofs_point *ap, switch (s->sel->selector) { case SEL_NETGRP: case SEL_NETGRPD: +#ifndef HAVE_INNETGR + error(logopt, MODPREFIX + "netgroups not available, function innetgr(3) not available"); +#else ret = sel_netgrp(ap, s, sv); +#endif break; default: -- 2.36.1