Subject: [PATCH] gnu: cyrus-sasl: Fix time.h check

From: aragaer <[email-masked]>
Date: Wed, 30 Apr 2025 17:35:43 +0300

The code conditionally includes <time.h> in some places but configure script
never checks for time.h, so it is never included. This works most of the time
but fails when doing cross compilation.

The patch was submitted to cyrus-sasl repository shortly after the 2.1.28
release (https://github.com/cyrusimap/cyrus-sasl/commit/266f0acf7f5e029afbb3e263437039e50cd6c262).

The package itself is a dependency for over 2000 other packages, but the
change only affects the build process. It should not break anything, only fix
an existing build failure.

Change-Id: I46e3801d50758f79df0447dd3bd483b427277e12
---
 gnu/local.mk                                  |  1 +
 gnu/packages/cyrus-sasl.scm                   | 47 +++++++++------
 .../patches/cyrus-sasl-fix-time-h.patch       | 57 +++++++++++++++++++
 3 files changed, 88 insertions(+), 17 deletions(-)
 create mode 100644 gnu/packages/patches/cyrus-sasl-fix-time-h.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 3efe47fe17..b59315368b 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1163,6 +1163,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/curlftpfs-fix-no_verify_hostname.patch	\
   %D%/packages/patches/cursynth-wave-rand.patch			\
   %D%/packages/patches/cvs-CVE-2017-12836.patch		\
+  %D%/packages/patches/cyrus-sasl-fix-time-h.patch		\
   %D%/packages/patches/d-feet-drop-unused-meson-argument.patch	\
   %D%/packages/patches/dante-non-darwin.patch			\
   %D%/packages/patches/date-ignore-zonenow.patch	\
diff --git a/gnu/packages/cyrus-sasl.scm b/gnu/packages/cyrus-sasl.scm
index ef408f2dd7..e7a011c9e7 100644
--- a/gnu/packages/cyrus-sasl.scm
+++ b/gnu/packages/cyrus-sasl.scm
@@ -28,6 +28,8 @@ (define-module (gnu packages cyrus-sasl)
   #:use-module (gnu packages kerberos)
   #:use-module (gnu packages tls)
   #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix build utils)
+  #:use-module (guix build mix-build-system)
   #:use-module (guix gexp)
   #:use-module (guix packages)
   #:use-module (guix download)
@@ -37,27 +39,38 @@ (define-public cyrus-sasl
   (package
     (name "cyrus-sasl")
     (version "2.1.28")
-    (source (origin
-              (method url-fetch)
-              (uri (string-append "https://github.com/cyrusimap/cyrus-sasl"
-                                  "/releases/download/cyrus-sasl-" version
-                                  "/cyrus-sasl-" version ".tar.gz"))
-              (sha256
-               (base32
-                "135kbgyfpa1mwqp5dm223yr6ddzi4vjm7cr414d7rmhys2mwdkvw"))))
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append "https://github.com/cyrusimap/cyrus-sasl"
+                           "/releases/download/cyrus-sasl-"
+                           version
+                           "/cyrus-sasl-"
+                           version
+                           ".tar.gz"))
+       (sha256
+        (base32 "135kbgyfpa1mwqp5dm223yr6ddzi4vjm7cr414d7rmhys2mwdkvw"))
+       (patches (search-patches "cyrus-sasl-fix-time-h.patch"))))
     (build-system gnu-build-system)
     (inputs (list gdbm libxcrypt mit-krb5 openssl))
+    (native-inputs `(("autoconf" ,autoconf)
+                     ("automake" ,automake)
+                     ("libtool" ,libtool)))
     (arguments
      (list
-      #:configure-flags #~(list (string-append "--with-plugindir="
-                                               (assoc-ref %outputs "out")
-                                               "/lib/sasl2")
-                                ;; When cross-compiling the build system is
-                                ;; unable to determine whether SPNEGO is
-                                ;; supported; Kerberos does, so enable it.
-                                #$@(if (%current-target-system)
-                                       '("ac_cv_gssapi_supports_spnego=yes")
-                                       '()))
+      #:phases '(modify-phases %standard-phases
+                  (add-before 'configure 'autoreconf
+                    (lambda* (#:key system #:allow-other-keys)
+                      (invoke "autoreconf" "-vfi"))))
+      #:configure-flags
+      #~(list (string-append "--with-plugindir="
+                             (assoc-ref %outputs "out") "/lib/sasl2")
+              ;; When cross-compiling the build system is
+              ;; unable to determine whether SPNEGO is
+              ;; supported; Kerberos does, so enable it.
+              #$@(if (%current-target-system)
+                     '("ac_cv_gssapi_supports_spnego=yes")
+                     '()))
 
       ;; The 'plugins' directory has shared source files, such as
       ;; 'plugin_common.c'.  When building the shared libraries there, libtool
diff --git a/gnu/packages/patches/cyrus-sasl-fix-time-h.patch b/gnu/packages/patches/cyrus-sasl-fix-time-h.patch
new file mode 100644
index 0000000000..922c4cb322
--- /dev/null
+++ b/gnu/packages/patches/cyrus-sasl-fix-time-h.patch
@@ -0,0 +1,57 @@
+From 266f0acf7f5e029afbb3e263437039e50cd6c262 Mon Sep 17 00:00:00 2001
+From: Sam James <[email-masked]>
+Date: Wed, 23 Feb 2022 00:45:15 +0000
+Subject: [PATCH] Fix <time.h> check
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+We're conditionally including based on HAVE_TIME_H in a bunch of places,
+but we're not actually checking for time.h, so that's never going to be defined.
+
+While at it, add in a missing include in the cram plugin.
+
+This fixes a bunch of implicit declaration warnings:
+```
+ * cyrus-sasl-2.1.28/lib/saslutil.c:280:3: warning: implicit declaration of function ‘time’ [-Wimplicit-function-declaration]
+ * cyrus-sasl-2.1.28/lib/saslutil.c:364:41: warning: implicit declaration of function ‘clock’ [-Wimplicit-function-declaration]
+ * cyrus-sasl-2.1.28/plugins/cram.c:132:7: warning: implicit declaration of function ‘time’ [-Wimplicit-function-declaration]
+ * cyrus-sasl-2.1.28/lib/saslutil.c:280:3: warning: implicit declaration of function ‘time’ [-Wimplicit-function-declaration]
+ * cyrus-sasl-2.1.28/lib/saslutil.c:364:41: warning: implicit declaration of function ‘clock’ [-Wimplicit-function-declaration]
+ * cyrus-sasl-2.1.28/plugins/cram.c:132:7: warning: implicit declaration of function ‘time’ [-Wimplicit-function-declaration]
+```
+
+Signed-off-by: Sam James <[email-masked]>
+---
+ configure.ac   | 2 +-
+ plugins/cram.c | 4 ++++
+ 2 files changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/configure.ac b/configure.ac
+index e1bf53b6..ad781830 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -1290,7 +1290,7 @@ AC_CHECK_HEADERS_ONCE([sys/time.h])
+ 
+ AC_HEADER_DIRENT
+ AC_HEADER_SYS_WAIT
+-AC_CHECK_HEADERS(crypt.h des.h dlfcn.h fcntl.h limits.h malloc.h paths.h strings.h sys/file.h sys/time.h syslog.h unistd.h inttypes.h sys/uio.h sys/param.h sysexits.h stdarg.h varargs.h krb5.h)
++AC_CHECK_HEADERS(crypt.h des.h dlfcn.h fcntl.h limits.h malloc.h paths.h strings.h sys/file.h sys/time.h syslog.h time.h unistd.h inttypes.h sys/uio.h sys/param.h sysexits.h stdarg.h varargs.h krb5.h)
+ 
+ IPv6_CHECK_SS_FAMILY()
+ IPv6_CHECK_SA_LEN()
+diff --git a/plugins/cram.c b/plugins/cram.c
+index d02e9baa..695aaa91 100644
+--- a/plugins/cram.c
++++ b/plugins/cram.c
+@@ -53,6 +53,10 @@
+ #endif
+ #include <fcntl.h>
+ 
++#ifdef HAVE_TIME_H
++#include <time.h>
++#endif
++
+ #include <sasl.h>
+ #include <saslplug.h>
+ #include <saslutil.h>
-- 
2.49.0