libcrypt-util: Clean up dlopen_libcrypt()
This commit is contained in:
+16
-28
@@ -15,11 +15,16 @@
|
||||
#include "strv.h"
|
||||
|
||||
#if HAVE_LIBCRYPT
|
||||
#ifdef __GLIBC__
|
||||
static void *libcrypt_dl = NULL;
|
||||
|
||||
static DLSYM_PROTOTYPE(crypt_gensalt_ra) = NULL;
|
||||
static DLSYM_PROTOTYPE(crypt_preferred_method) = NULL;
|
||||
static DLSYM_PROTOTYPE(crypt_ra) = NULL;
|
||||
#else
|
||||
static DLSYM_PROTOTYPE(crypt_gensalt_ra) = missing_crypt_gensalt_ra;
|
||||
static DLSYM_PROTOTYPE(crypt_preferred_method) = missing_crypt_preferred_method;
|
||||
static DLSYM_PROTOTYPE(crypt_ra) = missing_crypt_ra;
|
||||
#endif
|
||||
|
||||
int make_salt(char **ret) {
|
||||
const char *e;
|
||||
@@ -128,10 +133,10 @@ int dlopen_libcrypt(int log_level) {
|
||||
#if HAVE_LIBCRYPT
|
||||
#ifdef __GLIBC__
|
||||
static int cached = 0;
|
||||
int r;
|
||||
int r = -ENOENT;
|
||||
|
||||
if (libcrypt_dl)
|
||||
return 0; /* Already loaded */
|
||||
return 1; /* Already loaded */
|
||||
|
||||
if (cached < 0)
|
||||
return cached; /* Already tried, and failed. */
|
||||
@@ -145,36 +150,19 @@ int dlopen_libcrypt(int log_level) {
|
||||
SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
|
||||
"libcrypt.so.2", "libcrypt.so.1", "libcrypt.so.1.1");
|
||||
|
||||
_cleanup_(dlclosep) void *dl = NULL;
|
||||
const char *dle = NULL;
|
||||
FOREACH_STRING(soname, "libcrypt.so.2", "libcrypt.so.1", "libcrypt.so.1.1") {
|
||||
r = dlopen_safe(soname, &dl, &dle);
|
||||
if (r >= 0) {
|
||||
log_debug("Loaded '%s' via dlopen().", soname);
|
||||
r = dlopen_many_sym_or_warn(
|
||||
&libcrypt_dl, soname, LOG_DEBUG,
|
||||
DLSYM_ARG(crypt_gensalt_ra),
|
||||
DLSYM_ARG(crypt_preferred_method),
|
||||
DLSYM_ARG(crypt_ra));
|
||||
if (r >= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (r < 0) {
|
||||
log_full_errno(log_level, r, "Failed to load libcrypt: %s", dle ?: STRERROR(r));
|
||||
return (cached = -EOPNOTSUPP); /* turn into recognizable error */
|
||||
}
|
||||
|
||||
r = dlsym_many_or_warn(
|
||||
dl, log_level,
|
||||
DLSYM_ARG(crypt_gensalt_ra),
|
||||
DLSYM_ARG(crypt_preferred_method),
|
||||
DLSYM_ARG(crypt_ra));
|
||||
if (r < 0)
|
||||
return (cached = r);
|
||||
|
||||
libcrypt_dl = TAKE_PTR(dl);
|
||||
#else
|
||||
libcrypt_dl = NULL;
|
||||
sym_crypt_gensalt_ra = missing_crypt_gensalt_ra;
|
||||
sym_crypt_preferred_method = missing_crypt_preferred_method;
|
||||
sym_crypt_ra = missing_crypt_ra;
|
||||
return cached = log_full_errno(log_level, r, "Failed to load libcrypt: %m");
|
||||
#endif
|
||||
return 0;
|
||||
return 1;
|
||||
#else
|
||||
return log_full_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"libcrypt support is not compiled in.");
|
||||
|
||||
Reference in New Issue
Block a user