]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libcrypt: allow to build systemd without libcrypt/libxcrypt
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 25 Oct 2025 05:59:54 +0000 (14:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Jan 2026 03:55:57 +0000 (12:55 +0900)
libcrypt is only used by firstboot, homed, and sysusers, which can be
disabled by meson option.
Let's not require the library unconditionally.

meson.build
meson_options.txt
src/shared/libcrypt-util.c
src/shared/libcrypt-util.h
src/test/meson.build

index cf23ed51efee5a4091f8aa8cd40d257dfe832c5b..4f98dbd9da50b3c34b8e182006d80c63382964f8 100644 (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'],
index 4ce3c7faca0b3f5391af458735e35507679ca69e..5061869483b786b563ed1d87c73ee1c34d1b4285 100644 (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' },
index 6910c5f5276a0068fb58edbdd8e6477e97bfaea4..e8b0b72e35394c5051ab428d0d14a403bd236035 100644 (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
index e80cfcaf4e21f26aec8cb3d16047e36e7fe75f51..626668c710faa7914be3327ebe0468d17253772c 100644 (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);
index a21f85c2ecb27da6dc09afe39f73339f49b821b9..7b77f3bd587e87ed0948f4d0a41549281e217b24 100644 (file)
@@ -346,6 +346,7 @@ executables += [
         test_template + {
                 'sources' : files('test-libcrypt-util.c'),
                 'dependencies' : libcrypt,
+                'conditions' : ['HAVE_LIBCRYPT'],
                 'timeout' : 120,
         },
         test_template + {