From: Yu Watanabe Date: Sat, 25 Oct 2025 05:59:54 +0000 (+0900) Subject: libcrypt: allow to build systemd without libcrypt/libxcrypt X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8de783a288912a13b65ca269f01f3bc912d1aedb;p=thirdparty%2Fsystemd.git libcrypt: allow to build systemd without libcrypt/libxcrypt libcrypt is only used by firstboot, homed, and sysusers, which can be disabled by meson option. Let's not require the library unconditionally. --- diff --git a/meson.build b/meson.build index cf23ed51efe..4f98dbd9da5 100644 --- a/meson.build +++ b/meson.build @@ -685,15 +685,6 @@ conf.set('GPERF_LEN_TYPE', gperf_len_type, ##################################################################### -foreach header : [ - 'crypt.h', -] - - if not cc.has_header(header) - error(f'Header file @header@ not found') - endif -endforeach - foreach header : [ 'gshadow.h', 'nss.h', @@ -1048,11 +1039,14 @@ endif if get_option('libc') == 'musl' libcrypt = [] + have = get_option('libcrypt').allowed() else libcrypt = dependency('libcrypt', 'libxcrypt', - required : true, + required : get_option('libcrypt'), version : '>=4.4.0') + have = libcrypt.found() endif +conf.set10('HAVE_LIBCRYPT', have) bpf_framework = get_option('bpf-framework') bpf_compiler = get_option('bpf-compiler') @@ -1585,10 +1579,11 @@ conf.set10('ENABLE_SYSUPDATED', have2) conf.set10('ENABLE_STORAGETM', get_option('storagetm')) have = get_option('homed').require( + conf.get('HAVE_LIBCRYPT') == 1 and conf.get('HAVE_OPENSSL') == 1 and conf.get('HAVE_LIBFDISK') == 1 and conf.get('HAVE_LIBCRYPTSETUP') == 1, - error_message : 'openssl, fdisk and libcryptsetup required').allowed() + error_message : 'libcrypt, openssl, fdisk, and libcryptsetup required').allowed() conf.set10('ENABLE_HOMED', have) have = have and conf.get('HAVE_PAM') == 1 @@ -3115,6 +3110,7 @@ foreach tuple : [ ['gnutls'], ['libarchive'], ['libbpf'], + ['libcrypt'], ['libcryptsetup'], ['libcryptsetup-plugins'], ['libcurl'], diff --git a/meson_options.txt b/meson_options.txt index 4ce3c7faca0..5061869483b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -426,6 +426,8 @@ option('pwquality', type : 'feature', deprecated : { 'true' : 'enabled', 'false' description : 'libpwquality support') option('microhttpd', type : 'feature', deprecated : { 'true' : 'enabled', 'false' : 'disabled' }, description : 'libµhttpd support') +option('libcrypt', type : 'feature', + description : 'libcrypt/libxcrypt support') option('libcryptsetup', type : 'feature', deprecated : { 'true' : 'enabled', 'false' : 'disabled' }, description : 'libcryptsetup support') option('libcryptsetup-plugins', type : 'feature', deprecated : { 'true' : 'enabled', 'false' : 'disabled' }, diff --git a/src/shared/libcrypt-util.c b/src/shared/libcrypt-util.c index 6910c5f5276..e8b0b72e353 100644 --- a/src/shared/libcrypt-util.c +++ b/src/shared/libcrypt-util.c @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#if HAVE_LIBCRYPT +# include +#endif #include "alloc-util.h" #include "errno-util.h" @@ -9,6 +11,7 @@ #include "string-util.h" #include "strv.h" +#if HAVE_LIBCRYPT int make_salt(char **ret) { const char *e; char *salt; @@ -85,6 +88,7 @@ int test_password_many(char **hashed_password, const char *password) { return false; } +#endif bool looks_like_hashed_password(const char *s) { /* Returns false if the specified string is certainly not a hashed UNIX password. crypt(5) lists diff --git a/src/shared/libcrypt-util.h b/src/shared/libcrypt-util.h index e80cfcaf4e2..626668c710f 100644 --- a/src/shared/libcrypt-util.h +++ b/src/shared/libcrypt-util.h @@ -3,8 +3,17 @@ #include "shared-forward.h" +#if HAVE_LIBCRYPT int make_salt(char **ret); int hash_password(const char *password, char **ret); int test_password_one(const char *hashed_password, const char *password); int test_password_many(char **hashed_password, const char *password); + +#else + +static inline int hash_password(const char *password, char **ret) { + return -EOPNOTSUPP; +} +#endif + bool looks_like_hashed_password(const char *s); diff --git a/src/test/meson.build b/src/test/meson.build index a21f85c2ecb..7b77f3bd587 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -346,6 +346,7 @@ executables += [ test_template + { 'sources' : files('test-libcrypt-util.c'), 'dependencies' : libcrypt, + 'conditions' : ['HAVE_LIBCRYPT'], 'timeout' : 120, }, test_template + {