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.
This commit is contained in:
Yu Watanabe
2026-01-02 12:55:57 +09:00
parent 5863641bb7
commit 8de783a288
5 changed files with 24 additions and 12 deletions
+7 -11
View File
@@ -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'],
+2
View File
@@ -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' },
+5 -1
View File
@@ -1,6 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <crypt.h>
#if HAVE_LIBCRYPT
# include <crypt.h>
#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
+9
View File
@@ -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);
+1
View File
@@ -346,6 +346,7 @@ executables += [
test_template + {
'sources' : files('test-libcrypt-util.c'),
'dependencies' : libcrypt,
'conditions' : ['HAVE_LIBCRYPT'],
'timeout' : 120,
},
test_template + {