Extend test-dlopen-so to also cover cases when built without support

Let's make things more consistent and have all dlopen_xxx() functions
return EOPNOTSUPP on failure and verify this behavior in test-dlopen-so.
This commit is contained in:
Daan De Meyer
2025-09-17 19:40:17 +01:00
committed by Luca Boccassi
parent 9736f634c8
commit ff33c8f87d
17 changed files with 147 additions and 154 deletions
+12
View File
@@ -89,7 +89,10 @@ static DLSYM_PROTOTYPE(elf_version) = NULL;
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",
@@ -138,9 +141,13 @@ int dlopen_dw(void) {
return r;
return 1;
#else
return -EOPNOTSUPP;
#endif
}
int dlopen_elf(void) {
#if HAVE_ELFUTILS
int r;
ELF_NOTE_DLOPEN("elf",
@@ -165,8 +172,13 @@ int dlopen_elf(void) {
return r;
return 1;
#else
return -EOPNOTSUPP;
#endif
}
#if HAVE_ELFUTILS
typedef struct StackContext {
MemStream m;
Dwfl *dwfl;
-2
View File
@@ -3,10 +3,8 @@
#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.
+8
View File
@@ -71,7 +71,10 @@ static void fido_log_propagate_handler(const char *s) {
log_debug("libfido2: %s", strempty(s));
}
#endif
int dlopen_libfido2(void) {
#if HAVE_LIBFIDO2
int r;
ELF_NOTE_DLOPEN("fido2",
@@ -136,8 +139,13 @@ int dlopen_libfido2(void) {
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,
+2 -2
View File
@@ -16,6 +16,8 @@ typedef enum Fido2EnrollFlags {
_FIDO2ENROLL_TYPE_INVALID = -EINVAL,
} Fido2EnrollFlags;
int dlopen_libfido2(void);
#if HAVE_LIBFIDO2
#include <fido.h>
@@ -70,8 +72,6 @@ extern DLSYM_PROTOTYPE(fido_init);
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);
+21 -17
View File
@@ -4,7 +4,7 @@
#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
@@ -18,22 +18,6 @@ DLSYM_PROTOTYPE(passwdqc_params_free) = NULL;
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;
@@ -144,3 +128,23 @@ int check_password_quality(
}
#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
}
+2 -2
View File
@@ -15,11 +15,11 @@ extern DLSYM_PROTOTYPE(passwdqc_params_free);
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);
+23 -18
View File
@@ -8,6 +8,7 @@
#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"
@@ -24,24 +25,6 @@ DLSYM_PROTOTYPE(pwquality_read_config) = NULL;
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;
@@ -163,3 +146,25 @@ int check_password_quality(const char *password, const char *old, const char *us
}
#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
}
+2 -2
View File
@@ -17,11 +17,11 @@ extern DLSYM_PROTOTYPE(pwquality_read_config);
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);
+15 -1
View File
@@ -4,6 +4,7 @@
#if HAVE_QRENCODE
#include <qrencode.h>
#endif
#include <stdio.h>
#include "ansi-color.h"
@@ -18,12 +19,15 @@
#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",
@@ -41,8 +45,13 @@ int dlopen_qrencode(void) {
}
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);
@@ -176,6 +185,8 @@ static void write_qrcode(FILE *output, QRcode *qr, unsigned row, unsigned column
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(QRcode*, sym_QRcode_free, NULL);
#endif
int print_qrcode_full(
FILE *out,
const char *header,
@@ -186,6 +197,7 @@ int print_qrcode_full(
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
@@ -235,5 +247,7 @@ int print_qrcode_full(
fputc('\n', out);
return 0;
}
#else
return -EOPNOTSUPP;
#endif
}
+2 -16
View File
@@ -3,9 +3,6 @@
#include "forward.h"
#if HAVE_QRENCODE
int dlopen_qrencode(void);
int print_qrcode_full(
FILE *out,
const char *header,
@@ -15,19 +12,8 @@ int print_qrcode_full(
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);
+8
View File
@@ -217,7 +217,10 @@ static int dlopen_tpm2_mu(void) {
DLSYM_ARG(Tss2_MU_UINT32_Marshal));
}
#endif
int dlopen_tpm2(void) {
#if HAVE_TPM2
int r;
r = dlopen_tpm2_esys();
@@ -233,8 +236,13 @@ int dlopen_tpm2(void) {
return r;
return 0;
#else
return -EOPNOTSUPP;
#endif
}
#if HAVE_TPM2
void Esys_Freep(void *p) {
assert(p);
+2 -2
View File
@@ -39,14 +39,14 @@ static inline bool TPM2_PCR_MASK_VALID(uint32_t pcr_mask) {
#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;