1
0
mirror of https://github.com/systemd/systemd.git synced 2025-05-29 01:05:59 +03:00
systemd/src/shared/idn-util.c
Lennart Poettering cd7c207795 tree-wide: add dlopen ELF notes to all dlopen() deps of ours
Use 'recommended' priority for the default compression library, to
indicate that it should be prioritized over the other ones, as it
will be used to compress journals/core files.
Also use 'recommended' for kmod, as systems will likely fail to boot
if it's missing from the initrd.
Use 'suggested' for everything else.

There is one dlopen'ed TPM library that has the name generated
at runtime (depending on the driver), so that cannot be added, as it
needs to be known at build time.
Also when we support multiple ABI versions list them all, as for the
same reason we cannot know which one will be used at build time.

$ dlopen-notes.py build/libsystemd.so.0.39.0 build/src/shared/libsystemd-shared-256.so
libarchive.so.13 suggested
libbpf.so.0 suggested
libbpf.so.1 suggested
libcryptsetup.so.12 suggested
libdw.so.1 suggested
libelf.so.1 suggested
libfido2.so.1 suggested
libgcrypt.so.20 suggested
libidn2.so.0 suggested
libip4tc.so.2 suggested
libkmod.so.2 recommended
liblz4.so.1 suggested
liblzma.so.5 suggested
libp11-kit.so.0 suggested
libpcre2-8.so.0 suggested
libpwquality.so.1 suggested
libqrencode.so.3 suggested
libqrencode.so.4 suggested
libtss2-esys.so.0 suggested
libtss2-mu.so.0 suggested
libtss2-rc.so.0 suggested
libzstd.so.1 recommended

Co-authored-by: Luca Boccassi <bluca@debian.org>
2024-05-08 11:07:36 +01:00

83 lines
2.5 KiB
C

/* SPDX-License-Identifier: LGPL-2.1-or-later */
#if HAVE_LIBIDN2
# include <idn2.h>
#elif HAVE_LIBIDN
# include <idna.h>
# include <stringprep.h>
#endif
#include "alloc-util.h"
#include "dlfcn-util.h"
#include "idn-util.h"
#if HAVE_LIBIDN || HAVE_LIBIDN2
static void* idn_dl = NULL;
#endif
#if HAVE_LIBIDN2
DLSYM_FUNCTION(idn2_lookup_u8);
const char *(*sym_idn2_strerror)(int rc) _const_ = NULL;
DLSYM_FUNCTION(idn2_to_unicode_8z8z);
int dlopen_idn(void) {
ELF_NOTE_DLOPEN("idn",
"Support for internationalized domain names",
ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libidn2.so.0");
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));
}
#endif
#if HAVE_LIBIDN
DLSYM_FUNCTION(idna_to_ascii_4i);
DLSYM_FUNCTION(idna_to_unicode_44i);
DLSYM_FUNCTION(stringprep_ucs4_to_utf8);
DLSYM_FUNCTION(stringprep_utf8_to_ucs4);
int dlopen_idn(void) {
_cleanup_(dlclosep) void *dl = NULL;
int r;
ELF_NOTE_DLOPEN("idn",
"Support for internationalized domain names",
ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
"libidn.so.12", "libidn.so.11");
if (idn_dl)
return 0; /* Already loaded */
dl = dlopen("libidn.so.12", RTLD_LAZY);
if (!dl) {
/* libidn broke ABI in 1.34, but not in a way we care about (a new field got added to an
* open-coded struct we do not use), hence support both versions. */
dl = dlopen("libidn.so.11", RTLD_LAZY);
if (!dl)
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"libidn support is not installed: %s", dlerror());
log_debug("Loaded 'libidn.so.11' via dlopen()");
} else
log_debug("Loaded 'libidn.so.12' via dlopen()");
r = dlsym_many_or_warn(
dl,
LOG_DEBUG,
DLSYM_ARG(idna_to_ascii_4i),
DLSYM_ARG(idna_to_unicode_44i),
DLSYM_ARG(stringprep_ucs4_to_utf8),
DLSYM_ARG(stringprep_utf8_to_ucs4));
if (r < 0)
return r;
idn_dl = TAKE_PTR(dl);
return 1;
}
#endif