diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index 6d4493c0bb..2a8e676eda 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -39,11 +39,7 @@ int dlopen_libintl(int log_level) { #else static void *libintl_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "intl", - "Support for message translation via gettext", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libintl.so.8"); + LIBINTL_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); return dlopen_many_sym_or_warn( &libintl_dl, diff --git a/src/basic/locale-util.h b/src/basic/locale-util.h index fb22953f16..c2cbf3580a 100644 --- a/src/basic/locale-util.h +++ b/src/basic/locale-util.h @@ -4,6 +4,8 @@ #include /* IWYU pragma: export */ #include /* IWYU pragma: export */ +#include "sd-dlopen.h" /* IWYU pragma: export */ + #include "basic-forward.h" #include "dlfcn-util.h" @@ -14,6 +16,22 @@ extern DLSYM_PROTOTYPE(dgettext) __attribute__((format_arg(2))); int dlopen_libintl(int log_level); +#ifdef __GLIBC__ +#define DLOPEN_LIBINTL(log_level, priority) dlopen_libintl(log_level) +#else +#define LIBINTL_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("intl", \ + "Support for message translation via gettext", \ + priority, \ + "libintl.so.8") + +#define DLOPEN_LIBINTL(log_level, priority) \ + ({ \ + LIBINTL_NOTE(priority); \ + dlopen_libintl(log_level); \ + }) +#endif + typedef enum LocaleVariable { /* We don't list LC_ALL here on purpose. People should be * using LANG instead. */ diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c index 3e6f75d52a..84fca4da0e 100644 --- a/src/shared/acl-util.c +++ b/src/shared/acl-util.c @@ -49,11 +49,7 @@ int dlopen_libacl(int log_level) { #if HAVE_ACL static void *libacl_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "acl", - "Support for file Access Control Lists (ACLs)", - SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, - "libacl.so.1"); + LIBACL_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED); return dlopen_many_sym_or_warn( &libacl_dl, diff --git a/src/shared/acl-util.h b/src/shared/acl-util.h index 5e2aeb94a9..981f43a8cc 100644 --- a/src/shared/acl-util.h +++ b/src/shared/acl-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" #if HAVE_ACL @@ -60,6 +62,17 @@ static inline int acl_set_perm(acl_permset_t ps, acl_perm_t p, bool b) { return (b ? sym_acl_add_perm : sym_acl_delete_perm)(ps, p); } +#define LIBACL_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("acl", \ + "Support for file Access Control Lists (ACLs)", \ + priority, \ + "libacl.so.1") + +#define DLOPEN_LIBACL(log_level, priority) \ + ({ \ + LIBACL_NOTE(priority); \ + dlopen_libacl(log_level); \ + }) #else typedef void* acl_t; @@ -90,6 +103,8 @@ static inline int devnode_acl(int fd, const Set *uids) { static inline int fd_add_uid_acl_permission(int fd, uid_t uid, unsigned mask) { return -EOPNOTSUPP; } + +#define DLOPEN_LIBACL(log_level, priority) dlopen_libacl(log_level) #endif int dlopen_libacl(int log_level); diff --git a/src/shared/blkid-util.c b/src/shared/blkid-util.c index 022a43ffa9..233d45c4f0 100644 --- a/src/shared/blkid-util.c +++ b/src/shared/blkid-util.c @@ -99,11 +99,7 @@ int dlopen_libblkid(int log_level) { #if HAVE_BLKID static void *libblkid_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "blkid", - "Support for block device identification", - SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, - "libblkid.so.1"); + LIBBLKID_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED); return dlopen_many_sym_or_warn( &libblkid_dl, diff --git a/src/shared/blkid-util.h b/src/shared/blkid-util.h index 718a0f15a9..c211bbf3ab 100644 --- a/src/shared/blkid-util.h +++ b/src/shared/blkid-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" #if HAVE_BLKID @@ -63,6 +65,20 @@ enum { int blkid_probe_lookup_value_id128(blkid_probe b, const char *field, sd_id128_t *ret); int blkid_probe_lookup_value_u64(blkid_probe b, const char *field, uint64_t *ret); + +#define LIBBLKID_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("blkid", \ + "Support for block device identification", \ + priority, \ + "libblkid.so.1") + +#define DLOPEN_LIBBLKID(log_level, priority) \ + ({ \ + LIBBLKID_NOTE(priority); \ + dlopen_libblkid(log_level); \ + }) +#else +#define DLOPEN_LIBBLKID(log_level, priority) dlopen_libblkid(log_level) #endif int dlopen_libblkid(int log_level); diff --git a/src/shared/bpf-util.c b/src/shared/bpf-util.c index ea703ce589..92fc05f8fc 100644 --- a/src/shared/bpf-util.c +++ b/src/shared/bpf-util.c @@ -87,11 +87,7 @@ int dlopen_bpf(int log_level) { if (cached < 0) return cached; /* Already tried, and failed. */ - SD_ELF_NOTE_DLOPEN( - "bpf", - "Support firewalling and sandboxing with BPF", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libbpf.so.1", "libbpf.so.0"); + BPF_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); DISABLE_WARNING_DEPRECATED_DECLARATIONS; diff --git a/src/shared/bpf-util.h b/src/shared/bpf-util.h index 622e4c2e28..faf7349b8a 100644 --- a/src/shared/bpf-util.h +++ b/src/shared/bpf-util.h @@ -3,6 +3,8 @@ #include +#include "sd-dlopen.h" + #if HAVE_LIBBPF #include /* IWYU pragma: export */ @@ -88,6 +90,19 @@ static inline int compat_bpf_map_create( * we understand. */ int bpf_get_error_translated(const void *ptr); +#define BPF_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("bpf", \ + "Support firewalling and sandboxing with BPF", \ + priority, \ + "libbpf.so.1", "libbpf.so.0") + +#define DLOPEN_BPF(log_level, priority) \ + ({ \ + BPF_NOTE(priority); \ + dlopen_bpf(log_level); \ + }) +#else +#define DLOPEN_BPF(log_level, priority) dlopen_bpf(log_level) #endif int dlopen_bpf(int log_level); diff --git a/src/shared/crypto-util.c b/src/shared/crypto-util.c index bca43aebc9..5359078f6c 100644 --- a/src/shared/crypto-util.c +++ b/src/shared/crypto-util.c @@ -336,11 +336,7 @@ int dlopen_libcrypto(int log_level) { #if HAVE_OPENSSL static void *libcrypto_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "libcrypto", - "Support for cryptographic operations", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libcrypto.so.3"); + LIBCRYPTO_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); return dlopen_many_sym_or_warn( &libcrypto_dl, diff --git a/src/shared/crypto-util.h b/src/shared/crypto-util.h index 7e975c0240..f3494bc683 100644 --- a/src/shared/crypto-util.h +++ b/src/shared/crypto-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" #include "iovec-util.h" #include "sha256.h" @@ -31,6 +33,18 @@ int dlopen_libcrypto(int log_level); #define X509_FINGERPRINT_SIZE SHA256_DIGEST_SIZE #if HAVE_OPENSSL +#define LIBCRYPTO_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("libcrypto", \ + "Support for cryptographic operations", \ + priority, \ + "libcrypto.so.3") + +#define DLOPEN_LIBCRYPTO(log_level, priority) \ + ({ \ + LIBCRYPTO_NOTE(priority); \ + dlopen_libcrypto(log_level); \ + }) + # include /* IWYU pragma: export */ # include /* IWYU pragma: export */ # include /* IWYU pragma: export */ @@ -402,4 +416,6 @@ int openssl_extract_public_key(EVP_PKEY *private_key, EVP_PKEY **ret); OpenSSLAskPasswordUI* openssl_ask_password_ui_free(OpenSSLAskPasswordUI *ui); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(OpenSSLAskPasswordUI*, openssl_ask_password_ui_free, NULL); +#else +#define DLOPEN_LIBCRYPTO(log_level, priority) dlopen_libcrypto(log_level) #endif diff --git a/src/shared/cryptsetup-util.c b/src/shared/cryptsetup-util.c index d80824578f..35a59721f8 100644 --- a/src/shared/cryptsetup-util.c +++ b/src/shared/cryptsetup-util.c @@ -281,11 +281,7 @@ int dlopen_cryptsetup(int log_level) { * still available though, and given we want to support 2.2.0 for a while longer, we'll use the old * symbol if the new one is not available. */ - SD_ELF_NOTE_DLOPEN( - "cryptsetup", - "Support for disk encryption, integrity, and authentication", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libcryptsetup.so.12"); + CRYPTSETUP_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); r = dlopen_many_sym_or_warn( &cryptsetup_dl, "libcryptsetup.so.12", log_level, diff --git a/src/shared/cryptsetup-util.h b/src/shared/cryptsetup-util.h index 23d52d111a..1b3ab8b960 100644 --- a/src/shared/cryptsetup-util.h +++ b/src/shared/cryptsetup-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "dlfcn-util.h" #include "shared-forward.h" @@ -89,6 +91,20 @@ int cryptsetup_add_token_json(struct crypt_device *cd, sd_json_variant *v); int cryptsetup_get_volume_key_prefix(struct crypt_device *cd, const char *volume_name, char **ret); int cryptsetup_get_volume_key_id(struct crypt_device *cd, const char *volume_name, const void *volume_key, size_t volume_key_size, char **ret); + +#define CRYPTSETUP_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("cryptsetup", \ + "Support for disk encryption, integrity, and authentication", \ + priority, \ + "libcryptsetup.so.12") + +#define DLOPEN_CRYPTSETUP(log_level, priority) \ + ({ \ + CRYPTSETUP_NOTE(priority); \ + dlopen_cryptsetup(log_level); \ + }) +#else +#define DLOPEN_CRYPTSETUP(log_level, priority) dlopen_cryptsetup(log_level) #endif int dlopen_cryptsetup(int log_level); diff --git a/src/shared/curl-util.c b/src/shared/curl-util.c index aabc321729..961a97ad2f 100644 --- a/src/shared/curl-util.c +++ b/src/shared/curl-util.c @@ -604,11 +604,7 @@ int dlopen_curl(int log_level) { #if HAVE_LIBCURL static void *curl_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "curl", - "Support for downloading and uploading files over HTTP", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libcurl.so.4"); + CURL_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); return dlopen_many_sym_or_warn( &curl_dl, diff --git a/src/shared/curl-util.h b/src/shared/curl-util.h index c35de1cb7b..33bf3684c9 100644 --- a/src/shared/curl-util.h +++ b/src/shared/curl-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" #if HAVE_LIBCURL @@ -71,6 +73,19 @@ int curl_append_to_header(struct curl_slist **list, char **headers); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(CURL*, sym_curl_easy_cleanup, curl_easy_cleanupp, NULL); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct curl_slist*, sym_curl_slist_free_all, curl_slist_free_allp, NULL); +#define CURL_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("curl", \ + "Support for downloading and uploading files over HTTP", \ + priority, \ + "libcurl.so.4") + +#define DLOPEN_CURL(log_level, priority) \ + ({ \ + CURL_NOTE(priority); \ + dlopen_curl(log_level); \ + }) +#else +#define DLOPEN_CURL(log_level, priority) dlopen_curl(log_level) #endif int dlopen_curl(int log_level); diff --git a/src/shared/fdisk-util.c b/src/shared/fdisk-util.c index 5c55135842..8efafbc96e 100644 --- a/src/shared/fdisk-util.c +++ b/src/shared/fdisk-util.c @@ -83,11 +83,7 @@ int dlopen_fdisk(int log_level) { #if HAVE_LIBFDISK static void *fdisk_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "fdisk", - "Support for reading and writing partition tables", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libfdisk.so.1"); + FDISK_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); return dlopen_many_sym_or_warn( &fdisk_dl, diff --git a/src/shared/fdisk-util.h b/src/shared/fdisk-util.h index 66620c9c1c..367c6cd051 100644 --- a/src/shared/fdisk-util.h +++ b/src/shared/fdisk-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" #if HAVE_LIBFDISK @@ -84,6 +86,19 @@ int fdisk_partition_get_type_as_id128(struct fdisk_partition *p, sd_id128_t *ret int fdisk_partition_get_attrs_as_uint64(struct fdisk_partition *pa, uint64_t *ret); int fdisk_partition_set_attrs_as_uint64(struct fdisk_partition *pa, uint64_t flags); +#define FDISK_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("fdisk", \ + "Support for reading and writing partition tables", \ + priority, \ + "libfdisk.so.1") + +#define DLOPEN_FDISK(log_level, priority) \ + ({ \ + FDISK_NOTE(priority); \ + dlopen_fdisk(log_level); \ + }) +#else +#define DLOPEN_FDISK(log_level, priority) dlopen_fdisk(log_level) #endif int dlopen_fdisk(int log_level); diff --git a/src/shared/idn-util.c b/src/shared/idn-util.c index 01512b95dd..01c808b57f 100644 --- a/src/shared/idn-util.c +++ b/src/shared/idn-util.c @@ -17,11 +17,7 @@ DLSYM_PROTOTYPE(idn2_to_unicode_8z8z) = NULL; int dlopen_idn(int log_level) { #if HAVE_LIBIDN2 - SD_ELF_NOTE_DLOPEN( - "idn", - "Support for internationalized domain names", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libidn2.so.0"); + IDN_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); return dlopen_many_sym_or_warn( &idn_dl, "libidn2.so.0", log_level, diff --git a/src/shared/idn-util.h b/src/shared/idn-util.h index 918f8c0a57..9bed27140f 100644 --- a/src/shared/idn-util.h +++ b/src/shared/idn-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" #if HAVE_LIBIDN2 @@ -11,6 +13,20 @@ extern DLSYM_PROTOTYPE(idn2_lookup_u8); extern const char *(*sym_idn2_strerror)(int rc) _const_; extern DLSYM_PROTOTYPE(idn2_to_unicode_8z8z); + +#define IDN_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("idn", \ + "Support for internationalized domain names", \ + priority, \ + "libidn2.so.0") + +#define DLOPEN_IDN(log_level, priority) \ + ({ \ + IDN_NOTE(priority); \ + dlopen_idn(log_level); \ + }) +#else +#define DLOPEN_IDN(log_level, priority) dlopen_idn(log_level) #endif int dlopen_idn(int log_level); diff --git a/src/shared/libarchive-util.c b/src/shared/libarchive-util.c index c037f4a770..5879cf6272 100644 --- a/src/shared/libarchive-util.c +++ b/src/shared/libarchive-util.c @@ -80,11 +80,7 @@ int dlopen_libarchive(int log_level) { static void *libarchive_dl = NULL; int r; - SD_ELF_NOTE_DLOPEN( - "archive", - "Support for decompressing archive files", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libarchive.so.13"); + LIBARCHIVE_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); r = dlopen_many_sym_or_warn( &libarchive_dl, diff --git a/src/shared/libarchive-util.h b/src/shared/libarchive-util.h index 9f47ea67ea..afaf371200 100644 --- a/src/shared/libarchive-util.h +++ b/src/shared/libarchive-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" #if HAVE_LIBARCHIVE @@ -79,9 +81,20 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct archive_entry*, sym_archive_entry DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct archive*, sym_archive_write_free, archive_write_freep, NULL); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct archive*, sym_archive_read_free, archive_read_freep, NULL); +#define LIBARCHIVE_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("archive", \ + "Support for decompressing archive files", \ + priority, \ + "libarchive.so.13") + +#define DLOPEN_LIBARCHIVE(log_level, priority) \ + ({ \ + LIBARCHIVE_NOTE(priority); \ + dlopen_libarchive(log_level); \ + }) + #else - - +#define DLOPEN_LIBARCHIVE(log_level, priority) dlopen_libarchive(log_level) #endif int dlopen_libarchive(int log_level); diff --git a/src/shared/libmount-util.c b/src/shared/libmount-util.c index 065fcc2cb2..fd83da136f 100644 --- a/src/shared/libmount-util.c +++ b/src/shared/libmount-util.c @@ -120,11 +120,7 @@ int dlopen_libmount(int log_level) { #if HAVE_LIBMOUNT static void *libmount_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "mount", - "Support for mount enumeration", - SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, - "libmount.so.1"); + LIBMOUNT_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED); return dlopen_many_sym_or_warn( &libmount_dl, diff --git a/src/shared/libmount-util.h b/src/shared/libmount-util.h index 7eb7b230b2..44e58ec932 100644 --- a/src/shared/libmount-util.h +++ b/src/shared/libmount-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" #if HAVE_LIBMOUNT @@ -73,6 +75,17 @@ int libmount_is_leaf( struct libmnt_table *table, struct libmnt_fs *fs); +#define LIBMOUNT_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("mount", \ + "Support for mount enumeration", \ + priority, \ + "libmount.so.1") + +#define DLOPEN_LIBMOUNT(log_level, priority) \ + ({ \ + LIBMOUNT_NOTE(priority); \ + dlopen_libmount(log_level); \ + }) #else struct libmnt_monitor; @@ -83,6 +96,7 @@ static inline void* sym_mnt_unref_monitor(struct libmnt_monitor *p) { return NULL; } +#define DLOPEN_LIBMOUNT(log_level, priority) dlopen_libmount(log_level) #endif int dlopen_libmount(int log_level); diff --git a/src/shared/microhttpd-util.c b/src/shared/microhttpd-util.c index ade36a8c74..9820a1e400 100644 --- a/src/shared/microhttpd-util.c +++ b/src/shared/microhttpd-util.c @@ -36,11 +36,7 @@ int dlopen_microhttpd(int log_level) { #if HAVE_MICROHTTPD static void *microhttpd_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "microhttpd", - "Support for embedded HTTP server via libmicrohttpd", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libmicrohttpd.so.12"); + MICROHTTPD_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); return dlopen_many_sym_or_warn( µhttpd_dl, diff --git a/src/shared/microhttpd-util.h b/src/shared/microhttpd-util.h index 488ba7ea6e..39b2b9267b 100644 --- a/src/shared/microhttpd-util.h +++ b/src/shared/microhttpd-util.h @@ -1,11 +1,24 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" int dlopen_microhttpd(int log_level); #if HAVE_MICROHTTPD +#define MICROHTTPD_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("microhttpd", \ + "Support for embedded HTTP server via libmicrohttpd", \ + priority, \ + "libmicrohttpd.so.12") + +#define DLOPEN_MICROHTTPD(log_level, priority) \ + ({ \ + MICROHTTPD_NOTE(priority); \ + dlopen_microhttpd(log_level); \ + }) #include @@ -134,4 +147,6 @@ int setup_gnutls_logger(char **categories); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct MHD_Daemon*, sym_MHD_stop_daemon, MHD_stop_daemonp, NULL); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct MHD_Response*, sym_MHD_destroy_response, MHD_destroy_responsep, NULL); +#else +#define DLOPEN_MICROHTTPD(log_level, priority) dlopen_microhttpd(log_level) #endif diff --git a/src/shared/module-util.c b/src/shared/module-util.c index 2fb5cd3329..e060c69d9d 100644 --- a/src/shared/module-util.c +++ b/src/shared/module-util.c @@ -173,11 +173,7 @@ int dlopen_libkmod(int log_level) { #if HAVE_KMOD static void *libkmod_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "kmod", - "Support for loading kernel modules", - SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, - "libkmod.so.2"); + LIBKMOD_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED); return dlopen_many_sym_or_warn( &libkmod_dl, diff --git a/src/shared/module-util.h b/src/shared/module-util.h index 629979722c..730e14c31b 100644 --- a/src/shared/module-util.h +++ b/src/shared/module-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" #if HAVE_KMOD @@ -35,6 +37,17 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct kmod_list*, sym_kmod_module_unref int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose); int module_setup_context(struct kmod_ctx **ret); +#define LIBKMOD_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("kmod", \ + "Support for loading kernel modules", \ + priority, \ + "libkmod.so.2") + +#define DLOPEN_LIBKMOD(log_level, priority) \ + ({ \ + LIBKMOD_NOTE(priority); \ + dlopen_libkmod(log_level); \ + }) #else struct kmod_ctx; @@ -48,6 +61,7 @@ static inline int module_load_and_warn(struct kmod_ctx *ctx, const char *module, return -EOPNOTSUPP; } +#define DLOPEN_LIBKMOD(log_level, priority) dlopen_libkmod(log_level) #endif int dlopen_libkmod(int log_level); diff --git a/src/shared/pam-util.c b/src/shared/pam-util.c index fb57dd9757..0fe4207a0b 100644 --- a/src/shared/pam-util.c +++ b/src/shared/pam-util.c @@ -383,11 +383,7 @@ int dlopen_libpam(int log_level) { #if HAVE_PAM static void *libpam_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "pam", - "Support for LinuxPAM", - SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, - "libpam.so.0"); + LIBPAM_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED); return dlopen_many_sym_or_warn( &libpam_dl, diff --git a/src/shared/pam-util.h b/src/shared/pam-util.h index ca3ed0c7c8..408c371e8d 100644 --- a/src/shared/pam-util.h +++ b/src/shared/pam-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" #if HAVE_PAM @@ -104,6 +106,19 @@ int pam_prompt_graceful(pam_handle_t *pamh, int style, char **ret_response, cons * and hands it to sym_pam_putenv(), then erases the buffer before freeing in case it carried a secret. */ int pam_putenv_assign(pam_handle_t *pamh, const char *name, const char *value); +#define LIBPAM_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("pam", \ + "Support for LinuxPAM", \ + priority, \ + "libpam.so.0") + +#define DLOPEN_LIBPAM(log_level, priority) \ + ({ \ + LIBPAM_NOTE(priority); \ + dlopen_libpam(log_level); \ + }) +#else +#define DLOPEN_LIBPAM(log_level, priority) dlopen_libpam(log_level) #endif int dlopen_libpam(int log_level); diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c index d06dc4f82c..0ba0d6cd91 100644 --- a/src/shared/seccomp-util.c +++ b/src/shared/seccomp-util.c @@ -2604,11 +2604,7 @@ int dlopen_libseccomp(int log_level) { #if HAVE_SECCOMP static void *libseccomp_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "seccomp", - "Support for Seccomp Sandboxes", - SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, - "libseccomp.so.2"); + LIBSECCOMP_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED); return dlopen_many_sym_or_warn( &libseccomp_dl, diff --git a/src/shared/seccomp-util.h b/src/shared/seccomp-util.h index 7037ef52d1..89dcaf5ca7 100644 --- a/src/shared/seccomp-util.h +++ b/src/shared/seccomp-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "errno-util.h" #include "shared-forward.h" @@ -155,6 +157,17 @@ int parse_syscall_and_errno(const char *in, char **name, int *error); int seccomp_suppress_sync(void); +#define LIBSECCOMP_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("seccomp", \ + "Support for Seccomp Sandboxes", \ + priority, \ + "libseccomp.so.2") + +#define DLOPEN_LIBSECCOMP(log_level, priority) \ + ({ \ + LIBSECCOMP_NOTE(priority); \ + dlopen_libseccomp(log_level); \ + }) #else static inline bool is_seccomp_available(void) { @@ -162,6 +175,7 @@ static inline bool is_seccomp_available(void) { } +#define DLOPEN_LIBSECCOMP(log_level, priority) dlopen_libseccomp(log_level) #endif int dlopen_libseccomp(int log_level); diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c index 81ec4a9ba6..eb1f28a814 100644 --- a/src/shared/selinux-util.c +++ b/src/shared/selinux-util.c @@ -94,11 +94,7 @@ int dlopen_libselinux(int log_level) { #if HAVE_SELINUX static void *libselinux_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "selinux", - "Support for SELinux", - SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED, - "libselinux.so.1"); + LIBSELINUX_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED); return dlopen_many_sym_or_warn( &libselinux_dl, diff --git a/src/shared/selinux-util.h b/src/shared/selinux-util.h index f73503bc4b..98cfb6bbe4 100644 --- a/src/shared/selinux-util.h +++ b/src/shared/selinux-util.h @@ -3,6 +3,8 @@ #include +#include "sd-dlopen.h" + #include "shared-forward.h" #if HAVE_SELINUX @@ -50,12 +52,25 @@ extern DLSYM_PROTOTYPE(string_to_security_class); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(char*, sym_freecon, freeconp, NULL); +#define LIBSELINUX_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("selinux", \ + "Support for SELinux", \ + priority, \ + "libselinux.so.1") + +#define DLOPEN_LIBSELINUX(log_level, priority) \ + ({ \ + LIBSELINUX_NOTE(priority); \ + dlopen_libselinux(log_level); \ + }) #else static inline void freeconp(char **p) { assert(*p == NULL); } + +#define DLOPEN_LIBSELINUX(log_level, priority) dlopen_libselinux(log_level) #endif int dlopen_libselinux(int log_level); diff --git a/src/shared/ssl-util.c b/src/shared/ssl-util.c index 7b9314be96..ce51c8cc59 100644 --- a/src/shared/ssl-util.c +++ b/src/shared/ssl-util.c @@ -36,11 +36,7 @@ int dlopen_libssl(int log_level) { #if HAVE_OPENSSL static void *libssl_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "libssl", - "Support for TLS", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libssl.so.3"); + LIBSSL_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); return dlopen_many_sym_or_warn( &libssl_dl, diff --git a/src/shared/ssl-util.h b/src/shared/ssl-util.h index 7deb028cfe..80c56fcbe1 100644 --- a/src/shared/ssl-util.h +++ b/src/shared/ssl-util.h @@ -1,11 +1,24 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "shared-forward.h" int dlopen_libssl(int log_level); #if HAVE_OPENSSL +#define LIBSSL_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("libssl", \ + "Support for TLS", \ + priority, \ + "libssl.so.3") + +#define DLOPEN_LIBSSL(log_level, priority) \ + ({ \ + LIBSSL_NOTE(priority); \ + dlopen_libssl(log_level); \ + }) # include /* IWYU pragma: export */ @@ -43,4 +56,6 @@ extern DLSYM_PROTOTYPE(TLS_client_method); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(SSL*, sym_SSL_free, SSL_freep, NULL); +#else +#define DLOPEN_LIBSSL(log_level, priority) dlopen_libssl(log_level) #endif diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 3f29730c7f..2e2c5d03b5 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -124,11 +124,7 @@ static int dlopen_tpm2_esys(int log_level) { static void *libtss2_esys_dl = NULL; int r; - SD_ELF_NOTE_DLOPEN( - "tpm", - "Support for TPM", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libtss2-esys.so.0"); + TPM2_ESYS_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); r = dlopen_many_sym_or_warn( &libtss2_esys_dl, "libtss2-esys.so.0", log_level, @@ -190,11 +186,7 @@ static int dlopen_tpm2_esys(int log_level) { static int dlopen_tpm2_rc(int log_level) { static void *libtss2_rc_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "tpm", - "Support for TPM", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libtss2-rc.so.0"); + TPM2_RC_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); return dlopen_many_sym_or_warn( &libtss2_rc_dl, "libtss2-rc.so.0", log_level, @@ -204,11 +196,7 @@ static int dlopen_tpm2_rc(int log_level) { static int dlopen_tpm2_mu(int log_level) { static void *libtss2_mu_dl = NULL; - SD_ELF_NOTE_DLOPEN( - "tpm", - "Support for TPM", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libtss2-mu.so.0"); + TPM2_MU_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); return dlopen_many_sym_or_warn( &libtss2_mu_dl, "libtss2-mu.so.0", log_level, @@ -239,11 +227,7 @@ static int dlopen_tpm2_tcti_device(int log_level) { /* The "device" TCTI is the most relevant one, let's also load it explicitly on dlopen_tpm2(), even * if we don't resolve any symbols here. */ - SD_ELF_NOTE_DLOPEN( - "tpm", - "Support for TPM", - SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libtss2-tcti-device.so.0"); + TPM2_TCTI_DEVICE_NOTE(SD_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED); return dlopen_verbose( &libtss2_tcti_device_dl, diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h index bc26a16947..4d62702ce1 100644 --- a/src/shared/tpm2-util.h +++ b/src/shared/tpm2-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "sd-dlopen.h" + #include "bitfield.h" #include "iovec-util.h" #include "shared-forward.h" @@ -43,6 +45,28 @@ static inline bool TPM2_PCR_MASK_VALID(uint32_t pcr_mask) { int dlopen_tpm2(int log_level); #if HAVE_TPM2 +#define TPM2_ESYS_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("tpm", "Support for TPM", priority, "libtss2-esys.so.0") +#define TPM2_RC_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("tpm", "Support for TPM", priority, "libtss2-rc.so.0") +#define TPM2_MU_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("tpm", "Support for TPM", priority, "libtss2-mu.so.0") +#define TPM2_TCTI_DEVICE_NOTE(priority) \ + SD_ELF_NOTE_DLOPEN("tpm", "Support for TPM", priority, "libtss2-tcti-device.so.0") + +#define TPM2_NOTE(priority) \ + ({ \ + TPM2_ESYS_NOTE(priority); \ + TPM2_RC_NOTE(priority); \ + TPM2_MU_NOTE(priority); \ + TPM2_TCTI_DEVICE_NOTE(priority); \ + }) + +#define DLOPEN_TPM2(log_level, priority) \ + ({ \ + TPM2_NOTE(priority); \ + dlopen_tpm2(log_level); \ + }) #include /* IWYU pragma: export */ #include /* IWYU pragma: export */ @@ -413,6 +437,7 @@ static inline int tpm2_pcrlock_search_file(const char *path, FILE **ret_file, ch return -ENOENT; } +#define DLOPEN_TPM2(log_level, priority) dlopen_tpm2(log_level) #endif /* HAVE_TPM2 */ int tpm2_list_devices(bool legend, bool quiet);