/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#include "alloc-util.h"
#include "dlfcn-util.h"
+#include "log.h"
#include "pcre2-dlopen.h"
#if HAVE_PCRE2
PCRE2_SIZE* (*sym_pcre2_get_ovector_pointer)(pcre2_match_data *);
int dlopen_pcre2(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (pcre2_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libpcre2-8.so.0", RTLD_LAZY);
- if (!dl)
- return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "PCRE2 support is not installed: %s", dlerror());
-
/* So here's something weird: PCRE2 actually renames the symbols exported by the library via C
* macros, so that the exported symbols carry a suffix "_8" but when used from C the suffix is
* gone. In the argument list below we ignore this mangling. Surprisingly (at least to me), we
* string actually contains the "_8" suffix already due to that and we don't have to append it
* manually anymore. C is weird. 🤯 */
- r = dlsym_many_or_warn(
- dl,
- LOG_ERR,
+ return dlopen_many_sym_or_warn(
+ &pcre2_dl, "libpcre2-8.so.0", LOG_ERR,
DLSYM_ARG(pcre2_match_data_create),
DLSYM_ARG(pcre2_match_data_free),
DLSYM_ARG(pcre2_code_free),
DLSYM_ARG(pcre2_compile),
DLSYM_ARG(pcre2_get_error_message),
DLSYM_ARG(pcre2_match),
- DLSYM_ARG(pcre2_get_ovector_pointer),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- pcre2_dl = TAKE_PTR(dl);
-
- return 1;
+ DLSYM_ARG(pcre2_get_ovector_pointer));
}
#else
/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#include "alloc-util.h"
#include "dlfcn-util.h"
#include "bpf-dlopen.h"
+#include "log.h"
#if HAVE_LIBBPF
static void *bpf_dl = NULL;
const char* (*sym_bpf_program__name)(const struct bpf_program *);
int dlopen_bpf(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (bpf_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libbpf.so.0", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libbpf is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ return dlopen_many_sym_or_warn(
+ &bpf_dl, "libbpf.so.0", LOG_DEBUG,
DLSYM_ARG(bpf_link__destroy),
DLSYM_ARG(bpf_link__fd),
DLSYM_ARG(bpf_map__fd),
DLSYM_ARG(bpf_probe_prog_type),
DLSYM_ARG(bpf_program__attach_cgroup),
DLSYM_ARG(bpf_program__name),
- DLSYM_ARG(libbpf_get_error),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- bpf_dl = TAKE_PTR(dl);
- return 1;
+ DLSYM_ARG(libbpf_get_error));
}
#else
int (*sym_crypt_volume_key_get)(struct crypt_device *cd, int keyslot, char *volume_key, size_t *volume_key_size, const char *passphrase, size_t passphrase_size);
int dlopen_cryptsetup(void) {
- _cleanup_(dlclosep) void *dl = NULL;
int r;
- if (cryptsetup_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libcryptsetup.so.12", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libcryptsetup support is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ r = dlopen_many_sym_or_warn(
+ &cryptsetup_dl, "libcryptsetup.so.12", LOG_DEBUG,
DLSYM_ARG(crypt_activate_by_passphrase),
#if HAVE_CRYPT_ACTIVATE_BY_SIGNED_KEY
DLSYM_ARG(crypt_activate_by_signed_key),
DLSYM_ARG(crypt_token_max),
#endif
DLSYM_ARG(crypt_token_status),
- DLSYM_ARG(crypt_volume_key_get),
- NULL);
- if (r < 0)
+ DLSYM_ARG(crypt_volume_key_get));
+ if (r <= 0)
return r;
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- cryptsetup_dl = TAKE_PTR(dl);
-
/* Redirect the default logging calls of libcryptsetup to our own logging infra. (Note that
* libcryptsetup also maintains per-"struct crypt_device" log functions, which we'll also set
* whenever allocating a "struct crypt_device" context. Why set both? To be defensive: maybe some
int (*sym_idn2_to_unicode_8z8z)(const char * input, char ** output, int flags) = NULL;
int dlopen_idn(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (idn_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libidn2.so.0", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libidn2 support is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ return dlopen_many_sym_or_warn(
+ &idn_dl, "libidn2.so.0", LOG_DEBUG,
DLSYM_ARG(idn2_lookup_u8),
DLSYM_ARG(idn2_strerror),
- DLSYM_ARG(idn2_to_unicode_8z8z),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- idn_dl = TAKE_PTR(dl);
-
- return 1;
+ DLSYM_ARG(idn2_to_unicode_8z8z));
}
#endif
const char* (*sym_fido_strerr)(int) = NULL;
int dlopen_libfido2(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (libfido2_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libfido2.so.1", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libfido2 support is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ return dlopen_many_sym_or_warn(
+ &libfido2_dl, "libfido2.so.1", LOG_DEBUG,
DLSYM_ARG(fido_assert_allow_cred),
DLSYM_ARG(fido_assert_free),
DLSYM_ARG(fido_assert_hmac_secret_len),
DLSYM_ARG(fido_dev_make_cred),
DLSYM_ARG(fido_dev_new),
DLSYM_ARG(fido_dev_open),
- DLSYM_ARG(fido_strerr),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- libfido2_dl = TAKE_PTR(dl);
- return 1;
+ DLSYM_ARG(fido_strerr));
}
static int verify_features(
const char* (*sym_pwquality_strerror)(char *buf, size_t len, int errcode, void *auxerror);
int dlopen_pwquality(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (pwquality_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libpwquality.so.1", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libpwquality support is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ return dlopen_many_sym_or_warn(
+ &pwquality_dl, "libpwquality.so.1", LOG_DEBUG,
DLSYM_ARG(pwquality_check),
DLSYM_ARG(pwquality_default_settings),
DLSYM_ARG(pwquality_free_settings),
DLSYM_ARG(pwquality_get_str_value),
DLSYM_ARG(pwquality_read_config),
DLSYM_ARG(pwquality_set_int_value),
- DLSYM_ARG(pwquality_strerror),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- pwquality_dl = TAKE_PTR(dl);
- return 1;
+ DLSYM_ARG(pwquality_strerror));
}
void pwq_maybe_disable_dictionary(pwquality_settings_t *pwq) {
#if HAVE_QRENCODE
#include <qrencode.h>
-#include "alloc-util.h"
#include "dlfcn-util.h"
#include "locale-util.h"
+#include "log.h"
#include "terminal-util.h"
#define ANSI_WHITE_ON_BLACK "\033[40;37;1m"
static void (*sym_QRcode_free)(QRcode *qrcode) = NULL;
int dlopen_qrencode(void) {
- _cleanup_(dlclosep) void *dl = NULL;
- int r;
-
- if (qrcode_dl)
- return 0; /* Already loaded */
-
- dl = dlopen("libqrencode.so.4", RTLD_LAZY);
- if (!dl)
- return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
- "libqrcode support is not installed: %s", dlerror());
-
- r = dlsym_many_or_warn(
- dl,
- LOG_DEBUG,
+ return dlopen_many_sym_or_warn(
+ &qrcode_dl, "libqrencode.so.4", LOG_DEBUG,
DLSYM_ARG(QRcode_encodeString),
- DLSYM_ARG(QRcode_free),
- NULL);
- if (r < 0)
- return r;
-
- /* Note that we never release the reference here, because there's no real reason to, after all this
- * was traditionally a regular shared library dependency which lives forever too. */
- qrcode_dl = TAKE_PTR(dl);
- return 1;
+ DLSYM_ARG(QRcode_free));
}
static void print_border(FILE *output, unsigned width) {