return BIT_SET(supported, c);
}
-#if HAVE_XZ
int dlopen_lzma(void) {
+#if HAVE_XZ
ELF_NOTE_DLOPEN("lzma",
"Support lzma compression in journal and coredump files",
COMPRESSION_PRIORITY_XZ,
DLSYM_ARG(lzma_stream_buffer_encode),
DLSYM_ARG(lzma_lzma_preset),
DLSYM_ARG(lzma_stream_decoder));
-}
+#else
+ return -EOPNOTSUPP;
#endif
+}
int compress_blob_xz(const void *src, uint64_t src_size,
void *dst, size_t dst_alloc_size, size_t *dst_size, int level) {
#endif
}
-#if HAVE_LZ4
int dlopen_lz4(void) {
+#if HAVE_LZ4
ELF_NOTE_DLOPEN("lz4",
"Support lz4 compression in journal and coredump files",
COMPRESSION_PRIORITY_LZ4,
DLSYM_ARG(LZ4_decompress_safe),
DLSYM_ARG(LZ4_decompress_safe_partial),
DLSYM_ARG(LZ4_versionNumber));
-}
+#else
+ return -EOPNOTSUPP;
#endif
+}
int compress_blob_lz4(const void *src, uint64_t src_size,
void *dst, size_t dst_alloc_size, size_t *dst_size, int level) {
#endif
}
-#if HAVE_ZSTD
int dlopen_zstd(void) {
+#if HAVE_ZSTD
ELF_NOTE_DLOPEN("zstd",
"Support zstd compression in journal and coredump files",
COMPRESSION_PRIORITY_ZSTD,
DLSYM_ARG(ZSTD_isError),
DLSYM_ARG(ZSTD_createDCtx),
DLSYM_ARG(ZSTD_createCCtx));
-}
+#else
+ return -EOPNOTSUPP;
#endif
+}
int compress_blob_zstd(
const void *src, uint64_t src_size,
int decompress_stream_lz4(int fdf, int fdt, uint64_t max_size);
int decompress_stream_zstd(int fdf, int fdt, uint64_t max_size);
-#if HAVE_LZ4
int dlopen_lz4(void);
-#endif
-
-#if HAVE_ZSTD
int dlopen_zstd(void);
-#endif
-
-#if HAVE_XZ
int dlopen_lzma(void);
-#endif
static inline int compress_blob(
Compression compression,
/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#if HAVE_GCRYPT
-
#include <sys/syslog.h>
#include "gcrypt-util.h"
+#if HAVE_GCRYPT
+
static void *gcrypt_dl = NULL;
static DLSYM_PROTOTYPE(gcry_control) = NULL;
DLSYM_PROTOTYPE(gcry_prime_check) = NULL;
DLSYM_PROTOTYPE(gcry_randomize) = NULL;
DLSYM_PROTOTYPE(gcry_strerror) = NULL;
+#endif
-static int dlopen_gcrypt(void) {
+int dlopen_gcrypt(void) {
+#if HAVE_GCRYPT
ELF_NOTE_DLOPEN("gcrypt",
"Support for journald forward-sealing",
ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
DLSYM_ARG(gcry_prime_check),
DLSYM_ARG(gcry_randomize),
DLSYM_ARG(gcry_strerror));
+#else
+ return -EOPNOTSUPP;
+#endif
}
int initialize_libgcrypt(bool secmem) {
+#if HAVE_GCRYPT
int r;
r = dlopen_gcrypt();
sym_gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
return 0;
-}
+#else
+ return -EOPNOTSUPP;
#endif
+}
#include "forward.h"
+int dlopen_gcrypt(void);
+
+int initialize_libgcrypt(bool secmem);
+
#if HAVE_GCRYPT
#include <gcrypt.h> /* IWYU pragma: export */
extern DLSYM_PROTOTYPE(gcry_randomize);
extern DLSYM_PROTOTYPE(gcry_strerror);
-int initialize_libgcrypt(bool secmem);
-
/* Copied from gcry_md_putc from gcrypt.h due to the need to call the sym_ variant */
#define sym_gcry_md_putc(h,c) \
do { \
static DLSYM_PROTOTYPE(gelf_getphdr) = NULL;
static DLSYM_PROTOTYPE(gelf_getnote) = NULL;
+#endif
+
int dlopen_dw(void) {
+#if HAVE_ELFUTILS
int r;
ELF_NOTE_DLOPEN("dw",
return r;
return 1;
+#else
+ return -EOPNOTSUPP;
+#endif
}
int dlopen_elf(void) {
+#if HAVE_ELFUTILS
int r;
ELF_NOTE_DLOPEN("elf",
return r;
return 1;
+#else
+ return -EOPNOTSUPP;
+#endif
}
+#if HAVE_ELFUTILS
+
typedef struct StackContext {
MemStream m;
Dwfl *dwfl;
#include "forward.h"
-#if HAVE_ELFUTILS
int dlopen_dw(void);
int dlopen_elf(void);
-#endif
/* Parse an ELF object in a forked process, so that errors while iterating over
* untrusted and potentially malicious data do not propagate to the main caller's process.
log_debug("libfido2: %s", strempty(s));
}
+#endif
+
int dlopen_libfido2(void) {
+#if HAVE_LIBFIDO2
int r;
ELF_NOTE_DLOPEN("fido2",
sym_fido_set_log_handler(fido_log_propagate_handler);
return 0;
+#else
+ return -EOPNOTSUPP;
+#endif
}
+#if HAVE_LIBFIDO2
+
static int verify_features(
fido_dev_t *d,
const char *path,
_FIDO2ENROLL_TYPE_INVALID = -EINVAL,
} Fido2EnrollFlags;
+int dlopen_libfido2(void);
+
#if HAVE_LIBFIDO2
#include <fido.h>
extern DLSYM_PROTOTYPE(fido_set_log_handler);
extern DLSYM_PROTOTYPE(fido_strerr);
-int dlopen_libfido2(void);
-
static inline void fido_cbor_info_free_wrapper(fido_cbor_info_t **p) {
if (*p)
sym_fido_cbor_info_free(p);
#include "errno-util.h"
#include "log.h"
#include "memory-util.h"
-#include "password-quality-util.h"
+#include "password-quality-util-passwdqc.h"
#include "strv.h"
#if HAVE_PASSWDQC
DLSYM_PROTOTYPE(passwdqc_check) = NULL;
DLSYM_PROTOTYPE(passwdqc_random) = NULL;
-int dlopen_passwdqc(void) {
- ELF_NOTE_DLOPEN("passwdqc",
- "Support for password quality checks",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
- "libpasswdqc.so.1");
-
- return dlopen_many_sym_or_warn(
- &passwdqc_dl, "libpasswdqc.so.1", LOG_DEBUG,
- DLSYM_ARG(passwdqc_params_reset),
- DLSYM_ARG(passwdqc_params_load),
- DLSYM_ARG(passwdqc_params_parse),
- DLSYM_ARG(passwdqc_params_free),
- DLSYM_ARG(passwdqc_check),
- DLSYM_ARG(passwdqc_random));
-}
-
static int pwqc_allocate_context(passwdqc_params_t **ret) {
_cleanup_(sym_passwdqc_params_freep) passwdqc_params_t *params = NULL;
}
#endif
+
+int dlopen_passwdqc(void) {
+#if HAVE_PASSWDQC
+ ELF_NOTE_DLOPEN("passwdqc",
+ "Support for password quality checks",
+ ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ "libpasswdqc.so.1");
+
+ return dlopen_many_sym_or_warn(
+ &passwdqc_dl, "libpasswdqc.so.1", LOG_DEBUG,
+ DLSYM_ARG(passwdqc_params_reset),
+ DLSYM_ARG(passwdqc_params_load),
+ DLSYM_ARG(passwdqc_params_parse),
+ DLSYM_ARG(passwdqc_params_free),
+ DLSYM_ARG(passwdqc_check),
+ DLSYM_ARG(passwdqc_random));
+#else
+ return -EOPNOTSUPP;
+#endif
+}
extern DLSYM_PROTOTYPE(passwdqc_check);
extern DLSYM_PROTOTYPE(passwdqc_random);
-int dlopen_passwdqc(void);
-
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(passwdqc_params_t*, sym_passwdqc_params_free, NULL);
int suggest_passwords(void);
int check_password_quality(const char *password, const char *old, const char *username, char **ret_error);
#endif
+
+int dlopen_passwdqc(void);
#include "errno-util.h"
#include "log.h"
#include "password-quality-util.h"
+#include "password-quality-util-pwquality.h"
#include "string-util.h"
#include "strv.h"
DLSYM_PROTOTYPE(pwquality_set_int_value) = NULL;
DLSYM_PROTOTYPE(pwquality_strerror) = NULL;
-int dlopen_pwquality(void) {
- ELF_NOTE_DLOPEN("pwquality",
- "Support for password quality checks",
- ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
- "libpwquality.so.1");
-
- 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_generate),
- DLSYM_ARG(pwquality_get_str_value),
- DLSYM_ARG(pwquality_read_config),
- DLSYM_ARG(pwquality_set_int_value),
- DLSYM_ARG(pwquality_strerror));
-}
-
static void pwq_maybe_disable_dictionary(pwquality_settings_t *pwq) {
char buf[PWQ_MAX_ERROR_MESSAGE_LEN];
const char *path;
}
#endif
+
+int dlopen_pwquality(void) {
+#if HAVE_PWQUALITY
+ ELF_NOTE_DLOPEN("pwquality",
+ "Support for password quality checks",
+ ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
+ "libpwquality.so.1");
+
+ 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_generate),
+ DLSYM_ARG(pwquality_get_str_value),
+ DLSYM_ARG(pwquality_read_config),
+ DLSYM_ARG(pwquality_set_int_value),
+ DLSYM_ARG(pwquality_strerror));
+#else
+ return -EOPNOTSUPP;
+#endif
+}
extern DLSYM_PROTOTYPE(pwquality_set_int_value);
extern DLSYM_PROTOTYPE(pwquality_strerror);
-int dlopen_pwquality(void);
-
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(pwquality_settings_t*, sym_pwquality_free_settings, NULL);
int suggest_passwords(void);
int check_password_quality(const char *password, const char *old, const char *username, char **ret_error);
#endif
+
+int dlopen_pwquality(void);
#if HAVE_QRENCODE
#include <qrencode.h>
+#endif
#include <stdio.h>
#include "ansi-color.h"
#define UNICODE_LOWER_HALF_BLOCK UTF8("▄")
#define UNICODE_UPPER_HALF_BLOCK UTF8("▀")
+#if HAVE_QRENCODE
static void *qrcode_dl = NULL;
static DLSYM_PROTOTYPE(QRcode_encodeString) = NULL;
static DLSYM_PROTOTYPE(QRcode_free) = NULL;
+#endif
int dlopen_qrencode(void) {
+#if HAVE_QRENCODE
int r;
ELF_NOTE_DLOPEN("qrencode",
}
return r;
+#else
+ return -EOPNOTSUPP;
+#endif
}
+#if HAVE_QRENCODE
+
static void print_border(FILE *output, unsigned width, unsigned row, unsigned column) {
assert(output);
assert(width);
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(QRcode*, sym_QRcode_free, NULL);
+#endif
+
int print_qrcode_full(
FILE *out,
const char *header,
unsigned tty_height,
bool check_tty) {
+#if HAVE_QRENCODE
int r;
/* If this is not a UTF-8 system or ANSI colors aren't supported/disabled don't print any QR
fputc('\n', out);
return 0;
-}
+#else
+ return -EOPNOTSUPP;
#endif
+}
#include "forward.h"
-#if HAVE_QRENCODE
-int dlopen_qrencode(void);
-
int print_qrcode_full(
FILE *out,
const char *header,
unsigned tty_width,
unsigned tty_height,
bool check_tty);
-#else
-static inline int print_qrcode_full(
- FILE *out,
- const char *header,
- const char *string,
- unsigned row,
- unsigned column,
- unsigned tty_width,
- unsigned tty_height,
- bool check_tty) {
- return -EOPNOTSUPP;
-}
-#endif
+
+int dlopen_qrencode(void);
static inline int print_qrcode(FILE *out, const char *header, const char *string) {
return print_qrcode_full(out, header, string, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, true);
DLSYM_ARG(Tss2_MU_UINT32_Marshal));
}
+#endif
+
int dlopen_tpm2(void) {
+#if HAVE_TPM2
int r;
r = dlopen_tpm2_esys();
return r;
return 0;
+#else
+ return -EOPNOTSUPP;
+#endif
}
+#if HAVE_TPM2
+
void Esys_Freep(void *p) {
assert(p);
#define TPM2_N_HASH_ALGORITHMS 4U
+int dlopen_tpm2(void);
+
#if HAVE_TPM2
#include <tss2/tss2_esys.h> /* IWYU pragma: export */
#include <tss2/tss2_mu.h> /* IWYU pragma: export */
#include <tss2/tss2_rc.h> /* IWYU pragma: export */
-int dlopen_tpm2(void);
-
typedef struct Tpm2Context {
unsigned n_ref;
#include "tests.h"
#include "tpm2-util.h"
+#define ASSERT_DLOPEN(func, cond) \
+ cond ? ASSERT_OK(func()) : ASSERT_ERROR(func(), EOPNOTSUPP)
+
static int run(int argc, char **argv) {
test_setup_logging(LOG_DEBUG);
* where .so versions change and distributions update, but systemd doesn't have the new so names
* around yet. */
-#if HAVE_LIBIDN2 || HAVE_LIBIDN
- assert_se(dlopen_idn() >= 0);
-#endif
-
-#if HAVE_LIBCRYPTSETUP
- assert_se(dlopen_cryptsetup() >= 0);
-#endif
-
-#if HAVE_PASSWDQC
- assert_se(dlopen_passwdqc() >= 0);
-#endif
-
-#if HAVE_PWQUALITY
- assert_se(dlopen_pwquality() >= 0);
-#endif
-
-#if HAVE_QRENCODE
- assert_se(dlopen_qrencode() >= 0);
-#endif
-
-#if HAVE_TPM2
- assert_se(dlopen_tpm2() >= 0);
-#endif
-
-#if HAVE_LIBFIDO2
- assert_se(dlopen_libfido2() >= 0);
-#endif
-
-#if HAVE_LIBBPF
- assert_se(dlopen_bpf() >= 0);
-#endif
-
-#if HAVE_ELFUTILS
- assert_se(dlopen_dw() >= 0);
- assert_se(dlopen_elf() >= 0);
-#endif
-
-#if HAVE_PCRE2
- assert_se(dlopen_pcre2() >= 0);
-#endif
-
-#if HAVE_P11KIT
- assert_se(dlopen_p11kit() >= 0);
-#endif
-
-#if HAVE_LIBARCHIVE
- assert_se(dlopen_libarchive() >= 0);
-#endif
-
-#if HAVE_LZ4
- assert_se(dlopen_lz4() >= 0);
-#endif
-
-#if HAVE_ZSTD
- assert_se(dlopen_zstd() >= 0);
-#endif
-
-#if HAVE_XZ
- assert_se(dlopen_lzma() >= 0);
-#endif
-
-#if HAVE_GCRYPT
- assert_se(initialize_libgcrypt(/* secmem= */ false) >= 0);
-#endif
-
-#if HAVE_KMOD
- assert_se(dlopen_libkmod() >= 0);
-#endif
-
-#if HAVE_APPARMOR
- assert_se(dlopen_libapparmor() >= 0);
-#endif
+ ASSERT_DLOPEN(dlopen_idn, HAVE_LIBIDN2 || HAVE_LIBIDN);
+ ASSERT_DLOPEN(dlopen_cryptsetup, HAVE_LIBCRYPTSETUP);
+ ASSERT_DLOPEN(dlopen_passwdqc, HAVE_PASSWDQC);
+ ASSERT_DLOPEN(dlopen_pwquality, HAVE_PWQUALITY);
+ ASSERT_DLOPEN(dlopen_qrencode, HAVE_QRENCODE);
+ ASSERT_DLOPEN(dlopen_tpm2, HAVE_TPM2);
+ ASSERT_DLOPEN(dlopen_libfido2, HAVE_LIBFIDO2);
+ ASSERT_DLOPEN(dlopen_bpf, HAVE_LIBBPF);
+ ASSERT_DLOPEN(dlopen_dw, HAVE_ELFUTILS);
+ ASSERT_DLOPEN(dlopen_elf, HAVE_ELFUTILS);
+ ASSERT_DLOPEN(dlopen_pcre2, HAVE_PCRE2);
+ ASSERT_DLOPEN(dlopen_p11kit, HAVE_P11KIT);
+ ASSERT_DLOPEN(dlopen_libarchive, HAVE_LIBARCHIVE);
+ ASSERT_DLOPEN(dlopen_lz4, HAVE_LZ4);
+ ASSERT_DLOPEN(dlopen_zstd, HAVE_ZSTD);
+ ASSERT_DLOPEN(dlopen_lzma, HAVE_XZ);
+ ASSERT_DLOPEN(dlopen_gcrypt, HAVE_GCRYPT);
+ ASSERT_DLOPEN(dlopen_libkmod, HAVE_KMOD);
+ ASSERT_DLOPEN(dlopen_libapparmor, HAVE_APPARMOR);
return 0;
}