From: Yu Watanabe Date: Wed, 23 Jul 2025 04:13:29 +0000 (+0900) Subject: meson: crypt.h must always exist X-Git-Tag: v258-rc1~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa32f4cd755f9163036e370f9074fa68f2f2799e;p=thirdparty%2Fsystemd.git meson: crypt.h must always exist 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. --- diff --git a/README b/README index 0062563d5c1..5fff47827f7 100644 --- 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) diff --git a/meson.build b/meson.build index c5c08928f88..9f94162c60c 100644 --- a/meson.build +++ b/meson.build @@ -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 ''' : '''#include ''' -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 ''', 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') diff --git a/src/shared/libcrypt-util.c b/src/shared/libcrypt-util.c index aa41cd4458e..42c6feaabe7 100644 --- a/src/shared/libcrypt-util.c +++ b/src/shared/libcrypt-util.c @@ -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 -#else -# include -#endif - +#include #include #include "alloc-util.h" diff --git a/src/test/test-libcrypt-util.c b/src/test/test-libcrypt-util.c index f544a0003ea..92eda2e1a7c 100644 --- a/src/test/test-libcrypt-util.c +++ b/src/test/test-libcrypt-util.c @@ -1,10 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#if HAVE_CRYPT_H -# include -#else -# include -#endif +#include #include "libcrypt-util.h" #include "strv.h"