]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
Move USE_SYSTEM_GLOB into a glob.h compat shim.
authorDarren Tucker <dtucker@dtucker.net>
Sun, 8 Feb 2026 00:30:21 +0000 (11:30 +1100)
committerDarren Tucker <dtucker@dtucker.net>
Sun, 8 Feb 2026 17:05:27 +0000 (04:05 +1100)
This moves the logic for selecting whether or not we can use the system
glob into configure, and if either don't have glob or can't use it, we
create the shim.  Removes several diffs vs upstream.

auth2-pubkey.c
configure.ac
defines.h
readconf.c
scp.c
servconf.c
sftp-client.h
sftp-glob.c
sftp-usergroup.c
sftp.c

index 5d5d79196a092916b842b07d04639cf9e018d1b9..be378f266c873d7142b619984782c2e4cc7697d6 100644 (file)
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <paths.h>
 #include <pwd.h>
+#include <glob.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <time.h>
 #include <unistd.h>
 #include <limits.h>
-#ifdef USE_SYSTEM_GLOB
-# include <glob.h>
-#else
-# include "openbsd-compat/glob.h"
-#endif
 
 #include "xmalloc.h"
 #include "ssh.h"
index 60d45716bdef8e8b852a35c81ccd1a3153e29407..a8823d68b5a0e494b05b8d6d8e6c72039565d133 100644 (file)
@@ -464,7 +464,6 @@ AC_CHECK_HEADERS([ \
        floatingpoint.h \
        fnmatch.h \
        getopt.h \
-       glob.h \
        ia.h \
        iaf.h \
        inttypes.h \
@@ -553,7 +552,6 @@ AC_CHECK_HEADERS([ \
        *)      ;;
        esac >"$header"
 ])
-AC_SUBST([COMPATINCLUDES])
 
 AC_CHECK_DECLS([le32toh, le64toh, htole64], [], [], [
 #ifdef HAVE_SYS_TYPES_H
@@ -805,7 +803,7 @@ int main(void) { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16))
        AC_DEFINE([SETEUID_BREAKS_SETUID])
        AC_DEFINE([BROKEN_SETREUID])
        AC_DEFINE([BROKEN_SETREGID])
-       AC_DEFINE([BROKEN_GLOB], [1], [OS X glob does not do what we expect])
+       broken_glob=yes  # OS X glob does not do what we expect
        AC_DEFINE_UNQUOTED([BIND_8_COMPAT], [1],
                [Define if your resolver libs need this for getrrsetbyname])
        AC_DEFINE([SSH_TUN_FREEBSD], [1], [Open tunnel devices the FreeBSD way])
@@ -1123,7 +1121,7 @@ mips-sony-bsd|mips-sony-newsos4)
            [Use tunnel device compatibility to OpenBSD])
        AC_CHECK_HEADER([net/if_tap.h], ,
            AC_DEFINE([SSH_TUN_NO_L2], [1], [No layer 2 tunnel support]))
-       AC_DEFINE([BROKEN_GLOB], [1], [FreeBSD glob does not do what we need])
+       broken_glob=yes # FreeBSD glob does not do what we need
        TEST_MALLOC_OPTIONS="AJRX"
        # Preauth crypto occasionally uses file descriptors for crypto offload
        # and will crash if they cannot be opened.
@@ -1678,6 +1676,15 @@ else
            [Define to rpl_calloc if the replacement function should be used.])
 fi
 
+dnl Figure out if we have a system glob, and if so if we can use it.
+AC_CHECK_FUNCS([glob],
+       [ AC_CHECK_HEADERS([glob.h],
+         [use_system_glob=yes],
+         [use_system_glob=no])
+       ],
+       use_system_glob=no
+)
+
 # Check for ALTDIRFUNC glob() extension
 AC_MSG_CHECKING([for GLOB_ALTDIRFUNC support])
 AC_EGREP_CPP([FOUNDIT],
@@ -1695,6 +1702,7 @@ AC_EGREP_CPP([FOUNDIT],
        ],
        [
                AC_MSG_RESULT([no])
+               use_system_glob=no
        ]
 )
 
@@ -1709,7 +1717,9 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <glob.h> ]],
                AC_MSG_RESULT([yes])
        ], [
                AC_MSG_RESULT([no])
-])
+               use_system_glob=no
+       ]
+)
 
 # Check for g.gl_statv glob() extension
 AC_MSG_CHECKING([for gl_statv and GLOB_KEEPSTAT extensions for glob])
@@ -1727,10 +1737,28 @@ g.gl_statv = NULL;
                AC_MSG_RESULT([yes])
        ], [
                AC_MSG_RESULT([no])
+               use_system_glob=no
+       ]
+)
 
-])
+AC_CHECK_DECLS([GLOB_NOMATCH], , [use_system_glob=no], [#include <glob.h>])
 
-AC_CHECK_DECLS([GLOB_NOMATCH], , , [#include <glob.h>])
+if test "x$broken_glob" = "xyes"; then
+       AC_DEFINE([BROKEN_GLOB], [1], [Do not use system glob])
+       use_system_glob=no
+fi
+
+dnl If we don't have a system glob, or we do but we're not using it, then
+dnl create a glob.h shim so we don't have to sprinkle ifdefs everywhere.
+AC_MSG_CHECKING([if we can use the system glob])
+if test "x$use_system_glob" = "xyes" ; then
+       AC_MSG_RESULT([yes])
+else
+       AC_MSG_RESULT([no])
+       COMPATINCLUDES="openbsd-compat/include"
+       mkdir -p "$COMPATINCLUDES"
+       echo '# include "openbsd-compat/glob.h"' >$COMPATINCLUDES/glob.h
+fi
 
 AC_CHECK_DECL([VIS_ALL], ,
     AC_DEFINE(BROKEN_STRNVIS, 1, [missing VIS_ALL]), [#include <vis.h>])
@@ -2089,7 +2117,6 @@ AC_CHECK_FUNCS([ \
        getrandom \
        getsid \
        getttyent \
-       glob \
        group_from_gid \
        inet_aton \
        inet_ntoa \
@@ -5830,6 +5857,7 @@ LDFLAGS_NOPIE=`echo "$LDFLAGS" | sed 's/^-pie //;s/ -pie//g'`
 CFLAGS_NOPIE=`echo "$CFLAGS" | sed 's/^-fPIE //;s/ -fPIE//g'`
 AC_SUBST([LDFLAGS_NOPIE])
 AC_SUBST([CFLAGS_NOPIE])
+AC_SUBST([COMPATINCLUDES])
 
 AC_EXEEXT
 AC_CONFIG_FILES([Makefile buildpkg.sh opensshd.init openssh.xml \
index 8901da47a5fe217335d5b325979f91701453f4e2..1988b730c8a8e43e0a049d6941944ab56ea5befc 100644 (file)
--- a/defines.h
+++ b/defines.h
@@ -979,13 +979,6 @@ struct winsize {
 # endif /* gcc version */
 #endif /* __predict_true */
 
-#if defined(HAVE_GLOB_H) && defined(GLOB_HAS_ALTDIRFUNC) && \
-    defined(GLOB_HAS_GL_MATCHC) && defined(GLOB_HAS_GL_STATV) && \
-    defined(HAVE_DECL_GLOB_NOMATCH) &&  HAVE_DECL_GLOB_NOMATCH != 0 && \
-    !defined(BROKEN_GLOB)
-# define USE_SYSTEM_GLOB
-#endif
-
 /*
  * sntrup761 uses variable length arrays and c99-style declarations after code,
  * so only enable if the compiler supports them.
index 48529540a175b1b51f7cb50cdc7de4575369bd77..580026431d96db83319ec2ecc0d5e1f2518c2e67 100644 (file)
@@ -28,6 +28,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <glob.h>
 #include <ifaddrs.h>
 #include <limits.h>
 #include <netdb.h>
 #include <string.h>
 #include <stdarg.h>
 #include <unistd.h>
-#ifdef USE_SYSTEM_GLOB
-# include <glob.h>
-#else
-# include "openbsd-compat/glob.h"
-#endif
 #include <util.h>
 #if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H) && !defined(BROKEN_STRNVIS)
 # include <vis.h>
diff --git a/scp.c b/scp.c
index 86418d85e2fc022a6785c7ffcc0e49d61303f6e0..f27c8fe3fedc4f1d1112c2ecc8c40cdf4d814093 100644 (file)
--- a/scp.c
+++ b/scp.c
 #ifdef HAVE_FNMATCH_H
 #include <fnmatch.h>
 #endif
-#ifdef USE_SYSTEM_GLOB
-# include <glob.h>
-#else
-# include "openbsd-compat/glob.h"
-#endif
+#include <glob.h>
 #include <libgen.h>
 #include <limits.h>
 #include <util.h>
index 75f3f5dbd43cc64d01d63b1f4a9c926fe0a3885a..be9cc827b8d2bdb89087aa7b6f2dcdf7a16954bb 100644 (file)
@@ -26,6 +26,7 @@
 #endif
 
 #include <ctype.h>
+#include <glob.h>
 #include <netdb.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <errno.h>
 #include <util.h>
-#ifdef USE_SYSTEM_GLOB
-# include <glob.h>
-#else
-# include "openbsd-compat/glob.h"
-#endif
 
 #include "openbsd-compat/sys-queue.h"
 #include "xmalloc.h"
index 873ad3849f5bb52883b2ea8b933a543c3734d28d..7b2a94af81769377c93fd983341e605ed1c70be5 100644 (file)
 #ifndef _SFTP_CLIENT_H
 #define _SFTP_CLIENT_H
 
-#ifdef USE_SYSTEM_GLOB
-# include <glob.h>
-#else
-# include "openbsd-compat/glob.h"
-#endif
-
 typedef struct SFTP_DIRENT SFTP_DIRENT;
 
 struct SFTP_DIRENT {
index e054e75e80af4696d09666ef29cc7f7140bf2ec2..a8d3e07fc6907f56fd21f160ea9679e0a30fa7a7 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/stat.h>
 
 #include <dirent.h>
+#include <glob.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
index 93396ffc63dbf0a58bcd59446b4d078004adbd96..3cfcefea580e07f5ba0817daefa0d581b3c535ef 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/types.h>
 #include <openbsd-compat/sys-tree.h>
 
+#include <glob.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
diff --git a/sftp.c b/sftp.c
index b5adc09de881efe726b5c8793cfe0be8163033b1..1e509f897a813ac66ae12350bdaaf5726fbc1f75 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -28,7 +28,7 @@
 
 #include <ctype.h>
 #include <errno.h>
-
+#include <glob.h>
 #include <paths.h>
 #include <libgen.h>
 #ifdef HAVE_LOCALE_H