]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: crypt.h must always exist
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Jul 2025 04:13:29 +0000 (13:13 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Jul 2025 13:13:20 +0000 (22:13 +0900)
We require at least crypt_r() exists, and it is provided since glibc-2.0
(and dropped in glibc-2.39) or by libxcrypt, and the function is
provided in crypt.h regardless it is provided by glibc or libxcrypt.
Hence, we cannot fallback to unistd.h.

This makes the condition about crypt.h more strict, and stop compilation
earlier when crypt.h does not exist.

README
meson.build
src/shared/libcrypt-util.c
src/test/test-libcrypt-util.c

diff --git a/README b/README
index 0062563d5c126b940d002e2284791a4bd8973dbb..5fff47827f75a059aeb8aaa624caca8d0654c005 100644 (file)
--- a/README
+++ b/README
@@ -212,6 +212,7 @@ REQUIREMENTS:
         newer though. TL;DR: turn audit off, still.
 
         glibc >= 2.31
+        libxcrypt or glibc (<= 2.38 built with --enable-crypt)
         libcap
         libmount >= 2.30 (from util-linux)
                 (util-linux *must* be built without --enable-libmount-support-mtab)
index c5c08928f88d40692ac2eca6d4b7523082743349..9f94162c60cb4cbfa20986585e22111a5a48837d 100644 (file)
@@ -685,15 +685,22 @@ conf.set('GPERF_LEN_TYPE', gperf_len_type,
 
 #####################################################################
 
-if not cc.has_header('sys/capability.h')
-        error('POSIX caps headers not found')
-endif
-foreach header : ['crypt.h',
-                  'sys/sdt.h',
-                  'threads.h',
-                  'valgrind/memcheck.h',
-                  'valgrind/valgrind.h',
-                 ]
+foreach header : [
+        'crypt.h',
+        'sys/capability.h',
+]
+
+        if not cc.has_header(header)
+                error('Header file @0@ not found.'.format(header))
+        endif
+endforeach
+
+foreach header : [
+        'sys/sdt.h',
+        'threads.h',
+        'valgrind/memcheck.h',
+        'valgrind/valgrind.h',
+]
 
         conf.set10('HAVE_' + header.underscorify().to_upper(),
                    cc.has_header(header))
@@ -989,11 +996,6 @@ threads = dependency('threads')
 librt = cc.find_library('rt')
 libm = cc.find_library('m')
 libdl = cc.find_library('dl')
-libcrypt = dependency('libcrypt', 'libxcrypt', required : false)
-if not libcrypt.found()
-        # fallback to use find_library() if libcrypt is provided by glibc, e.g. for LibreELEC.
-        libcrypt = cc.find_library('crypt')
-endif
 libcap = dependency('libcap')
 
 # On some architectures, libatomic is required. But on some installations,
@@ -1007,15 +1009,21 @@ else
         libatomic = []
 endif
 
-crypt_header = conf.get('HAVE_CRYPT_H') == 1 ? '''#include <crypt.h>''' : '''#include <unistd.h>'''
-foreach ident : [
-        ['crypt_ra',               crypt_header],
-        ['crypt_preferred_method', crypt_header],
-        ['crypt_gensalt_ra',       crypt_header]]
+libcrypt = dependency('libcrypt', 'libxcrypt', required : false)
+if not libcrypt.found()
+        # fallback to use find_library() if libcrypt is provided by glibc, e.g. for LibreELEC.
+        libcrypt = cc.find_library('crypt')
+endif
 
-        have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE',
+foreach func : [
+        'crypt_ra',               # since libxcrypt-4.0.0
+        'crypt_gensalt_ra',       # since libxcrypt-4.0.0
+        'crypt_preferred_method', # since libxcrypt-4.4.0
+]
+
+        have = cc.has_function(func, prefix : '''#include <crypt.h>''', args : '-D_GNU_SOURCE',
                                dependencies : libcrypt)
-        conf.set10('HAVE_' + ident[0].to_upper(), have)
+        conf.set10('HAVE_' + func.to_upper(), have)
 endforeach
 
 bpf_framework = get_option('bpf-framework')
index aa41cd4458e31421ac38e693bb55c05d56764553..42c6feaabe7e42896bee18886a2c84d0cea6ab3f 100644 (file)
@@ -1,20 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#if HAVE_CRYPT_H
-/* libxcrypt is a replacement for glibc's libcrypt, and libcrypt might be
- * removed from glibc at some point. As part of the removal, defines for
- * crypt(3) are dropped from unistd.h, and we must include crypt.h instead.
- *
- * Newer versions of glibc (v2.0+) already ship crypt.h with a definition
- * of crypt(3) as well, so we simply include it if it is present.  MariaDB,
- * MySQL, PostgreSQL, Perl and some other wide-spread packages do it the
- * same way since ages without any problems.
- */
-#  include <crypt.h>
-#else
-#  include <unistd.h>
-#endif
-
+#include <crypt.h>
 #include <stdlib.h>
 
 #include "alloc-util.h"
index f544a0003eaea3eb7bc1b696001ca3e92d6a2255..92eda2e1a7cc1d14f4305194d1ab63d45ebc4fa0 100644 (file)
@@ -1,10 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#if HAVE_CRYPT_H
-#  include <crypt.h>
-#else
-#  include <unistd.h>
-#endif
+#include <crypt.h>
 
 #include "libcrypt-util.h"
 #include "strv.h"