From e8644a414a9953a4f7a3b966519dee6fcf66eff0 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Tue, 8 Sep 2020 20:02:31 +0200 Subject: meson: test if we have libcrypt_ra We always seem to have either libcrypt_r and not the other two, or all three. So the fallback for libcrypt_ra needs to be based on libcrypt_r. --- meson.build | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'meson.build') diff --git a/meson.build b/meson.build index ab0d7da1e9..203aa63c1a 100644 --- a/meson.build +++ b/meson.build @@ -881,6 +881,16 @@ libm = cc.find_library('m') libdl = cc.find_library('dl') libcrypt = cc.find_library('crypt') +crypt_header = conf.get('HAVE_CRYPT_H') == 1 ? \ + '''#include ''' : '''#include ''' +foreach ident : [ + ['crypt_ra', crypt_header]] + + have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE', + dependencies : libcrypt) + conf.set10('HAVE_' + ident[0].to_upper(), have) +endforeach + libcap = dependency('libcap', required : false) if not libcap.found() # Compat with Ubuntu 14.04 which ships libcap w/o .pc file -- cgit v1.2.3 From 2b49f0ca83279cdf1199df33ee794d0e026a08d2 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Thu, 10 Sep 2020 18:21:41 +0200 Subject: Check for crypt_gensalt_ra() instead of relying on libxcrypt presence Since the loop to check various xcrypt functions is already in place, adding one more is cheap. And it is nicer to check for the function directly. People like to backport things, so we might get lucky even without having libxcrypt. --- meson.build | 3 ++- src/shared/libcrypt-util.c | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'meson.build') diff --git a/meson.build b/meson.build index 203aa63c1a..f75c9b2cfb 100644 --- a/meson.build +++ b/meson.build @@ -884,7 +884,8 @@ libcrypt = cc.find_library('crypt') crypt_header = conf.get('HAVE_CRYPT_H') == 1 ? \ '''#include ''' : '''#include ''' foreach ident : [ - ['crypt_ra', crypt_header]] + ['crypt_ra', crypt_header], + ['crypt_gensalt_ra', crypt_header]] have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE', dependencies : libcrypt) diff --git a/src/shared/libcrypt-util.c b/src/shared/libcrypt-util.c index ca40c02c4e..de0cfced6d 100644 --- a/src/shared/libcrypt-util.c +++ b/src/shared/libcrypt-util.c @@ -31,12 +31,12 @@ int make_salt(char **ret) { -#ifdef XCRYPT_VERSION_MAJOR +#if HAVE_CRYPT_GENSALT_RA const char *e; char *salt; - /* If we have libxcrypt we default to the "preferred method" (i.e. usually yescrypt), and generate it - * with crypt_gensalt_ra(). */ + /* If we have crypt_gensalt_ra() we default to the "preferred method" (i.e. usually yescrypt). + * crypt_gensalt_ra() is usually provided by libxcrypt. */ e = secure_getenv("SYSTEMD_CRYPT_PREFIX"); if (!e) @@ -51,8 +51,7 @@ int make_salt(char **ret) { *ret = salt; return 0; #else - /* If libxcrypt is not used, we use SHA512 and generate the salt on our own since crypt_gensalt_ra() - * is not available. */ + /* If crypt_gensalt_ra() is not available, we use SHA512 and generate the salt on our own. */ static const char table[] = "abcdefghijklmnopqrstuvwxyz" -- cgit v1.2.3