For libc syscall wrappers (pidfd_open, fsopen, openat2, etc.) we previously gated the calls behind build-time HAVE_* checks. Replace these with shim functions in src/libc/ that fall back to the raw syscall at runtime when the loaded glibc lacks the symbol. The infrastructure lives in src/libc/libc-shim.h: DEFINE_SYSCALL_SHIM falls back to a direct syscall, DEFINE_LIBC_SHIM returns ENOSYS (for posix_spawn-family helpers that have no corresponding syscall), and DEFINE_LIBC_ERRNO_SHIM sets errno=ENOSYS and returns -1 (for read/write-style helpers). The weak reference to the libc symbol is bound via __asm__(\"name\") rename so the bare libc identifier never appears as a C token — this avoids both #undef boilerplate against override-header redirects and the resulting -Wredundant-decls warning. Drop the corresponding cc.has_function() loop from meson.build. For optional libraries (libcryptsetup, libdw, libarchive), drop the per-symbol HAVE_* checks. Always declare the prototypes, suppressing the redundant-decl warnings via DISABLE_WARNING_REDUNDANT_DECLS and NOLINT, and resolve the symbols after the main dlopen via a new DLSYM_OPTIONAL() helper that only assigns on success. libcryptsetup's crypt_set_keyring_to_link / crypt_token_set_external_path and libarchive's *_is_set wrappers use fallback functions as their pointer initializers (returning -ENOSYS and 0 respectively), so call sites can invoke the symbol unconditionally and just check for -ENOSYS where the \"not supported\" distinction matters. The same shim treatment applies to pidfd_spawn / posix_spawnattr_setcgroup_np (src/libc/spawn.c) and epoll_pwait2 (src/libc/epoll.c), with corresponding override headers in src/include/override/spawn.h and src/include/override/sys/epoll.h. posix_spawn_wrapper() in process-util.c and epoll_wait_usec() in sd-event.c now detect ENOSYS in the return value instead of checking the function pointer, falling back to plain posix_spawn() and epoll_wait() respectively. coredump-config and coredump-submit get a dlopen_dw_has_dwfl_set_sysroot() helper. The kexec arch gate now uses defined(__NR_kexec_file_load) directly; pidfd.h uses __has_include_next() to decide whether to pull in glibc's header. This lets binaries built against newer glibc / libcryptsetup / libdw / libarchive headers still load and run on older targets where these symbols are absent.
98 lines
4.4 KiB
C
98 lines
4.4 KiB
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
#pragma once
|
|
|
|
#include "dlfcn-util.h"
|
|
#include "shared-forward.h"
|
|
|
|
#if HAVE_LIBCRYPTSETUP
|
|
#include <libcryptsetup.h> /* IWYU pragma: export */
|
|
|
|
/* Available since libcryptsetup 2.7. Always redeclare so DLSYM_PROTOTYPE's typeof() resolves on older
|
|
* headers; suppress the warning when newer libcryptsetup already declares them. */
|
|
DISABLE_WARNING_REDUNDANT_DECLS;
|
|
/* NOLINTBEGIN(readability-redundant-declaration) */
|
|
extern int crypt_set_keyring_to_link(struct crypt_device *cd,
|
|
const char *key_description,
|
|
const char *old_key_description,
|
|
const char *key_type_desc,
|
|
const char *keyring_to_link_vk);
|
|
extern int crypt_token_set_external_path(const char *path);
|
|
/* NOLINTEND(readability-redundant-declaration) */
|
|
REENABLE_WARNING;
|
|
|
|
extern DLSYM_PROTOTYPE(crypt_activate_by_passphrase);
|
|
extern DLSYM_PROTOTYPE(crypt_activate_by_signed_key);
|
|
extern DLSYM_PROTOTYPE(crypt_activate_by_token_pin);
|
|
extern DLSYM_PROTOTYPE(crypt_activate_by_volume_key);
|
|
extern DLSYM_PROTOTYPE(crypt_deactivate);
|
|
extern DLSYM_PROTOTYPE(crypt_deactivate_by_name);
|
|
extern DLSYM_PROTOTYPE(crypt_format);
|
|
extern DLSYM_PROTOTYPE(crypt_free);
|
|
extern DLSYM_PROTOTYPE(crypt_get_cipher);
|
|
extern DLSYM_PROTOTYPE(crypt_get_cipher_mode);
|
|
extern DLSYM_PROTOTYPE(crypt_get_data_offset);
|
|
extern DLSYM_PROTOTYPE(crypt_get_device_name);
|
|
extern DLSYM_PROTOTYPE(crypt_get_dir);
|
|
extern DLSYM_PROTOTYPE(crypt_get_type);
|
|
extern DLSYM_PROTOTYPE(crypt_get_uuid);
|
|
extern DLSYM_PROTOTYPE(crypt_get_verity_info);
|
|
extern DLSYM_PROTOTYPE(crypt_get_volume_key_size);
|
|
extern DLSYM_PROTOTYPE(crypt_header_restore);
|
|
extern DLSYM_PROTOTYPE(crypt_init);
|
|
extern DLSYM_PROTOTYPE(crypt_init_by_name);
|
|
extern DLSYM_PROTOTYPE(crypt_init_data_device);
|
|
extern DLSYM_PROTOTYPE(crypt_keyslot_add_by_volume_key);
|
|
extern DLSYM_PROTOTYPE(crypt_keyslot_destroy);
|
|
extern DLSYM_PROTOTYPE(crypt_keyslot_max);
|
|
extern DLSYM_PROTOTYPE(crypt_keyslot_status);
|
|
extern DLSYM_PROTOTYPE(crypt_load);
|
|
extern DLSYM_PROTOTYPE(crypt_metadata_locking);
|
|
extern DLSYM_PROTOTYPE(crypt_persistent_flags_get);
|
|
extern DLSYM_PROTOTYPE(crypt_persistent_flags_set);
|
|
extern DLSYM_PROTOTYPE(crypt_reencrypt_init_by_passphrase);
|
|
extern DLSYM_PROTOTYPE(crypt_reencrypt_run);
|
|
extern DLSYM_PROTOTYPE(crypt_resize);
|
|
extern DLSYM_PROTOTYPE(crypt_resume_by_volume_key);
|
|
extern DLSYM_PROTOTYPE(crypt_set_data_device);
|
|
extern DLSYM_PROTOTYPE(crypt_set_data_offset);
|
|
extern DLSYM_PROTOTYPE(crypt_set_debug_level);
|
|
extern DLSYM_PROTOTYPE(crypt_set_keyring_to_link);
|
|
extern DLSYM_PROTOTYPE(crypt_set_log_callback);
|
|
extern DLSYM_PROTOTYPE(crypt_set_metadata_size);
|
|
extern DLSYM_PROTOTYPE(crypt_set_pbkdf_type);
|
|
extern DLSYM_PROTOTYPE(crypt_status);
|
|
extern DLSYM_PROTOTYPE(crypt_suspend);
|
|
extern DLSYM_PROTOTYPE(crypt_token_external_path);
|
|
extern DLSYM_PROTOTYPE(crypt_token_json_get);
|
|
extern DLSYM_PROTOTYPE(crypt_token_json_set);
|
|
extern DLSYM_PROTOTYPE(crypt_token_max);
|
|
extern DLSYM_PROTOTYPE(crypt_token_set_external_path);
|
|
extern DLSYM_PROTOTYPE(crypt_token_status);
|
|
extern DLSYM_PROTOTYPE(crypt_volume_key_get);
|
|
extern DLSYM_PROTOTYPE(crypt_volume_key_keyring);
|
|
extern DLSYM_PROTOTYPE(crypt_wipe);
|
|
extern DLSYM_PROTOTYPE(crypt_get_integrity_info);
|
|
|
|
/* Be careful, these work with dlopen_cryptsetup(), that is, they call sym_crypt_free() instead of
|
|
* crypt_free() and hence depend on dlopen_cryptsetup() having been called. */
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(struct crypt_device *, sym_crypt_free, crypt_freep, NULL);
|
|
#define crypt_free_and_replace(a, b) \
|
|
free_and_replace_full(a, b, sym_crypt_free)
|
|
|
|
void cryptsetup_enable_logging(struct crypt_device *cd);
|
|
|
|
int cryptsetup_set_minimal_pbkdf(struct crypt_device *cd);
|
|
|
|
int cryptsetup_get_token_as_json(struct crypt_device *cd, int idx, const char *verify_type, sd_json_variant **ret);
|
|
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);
|
|
#endif
|
|
|
|
int dlopen_cryptsetup(int log_level);
|
|
|
|
int cryptsetup_get_keyslot_from_token(sd_json_variant *v);
|
|
|
|
const char* mangle_none(const char *s);
|