}
#endif
+static void libcryptsetup_log(int level __attribute__((__unused__)), const char *msg, void *data)
+{
+ struct libmnt_context *cxt = (struct libmnt_context *)data;
+
+ DBG(VERITY, ul_debugobj(cxt, "cryptsetup: %s", msg));
+}
+
/* Taken from https://gitlab.com/cryptsetup/cryptsetup/blob/master/lib/utils_crypt.c#L225 */
static size_t crypt_hex_to_bytes(const char *hex, char **result)
{
#ifdef CRYPTSETUP_VIA_DLOPEN
/* To avoid linking libmount to libcryptsetup, and keep the default dependencies list down, use dlopen */
void *dl = NULL;
+ void (*sym_crypt_set_debug_level)(int) = NULL;
+ void (*sym_crypt_set_log_callback)(struct crypt_device *, void (*log)(int, const char *, void *), void *) = NULL;
int (*sym_crypt_init_data_device)(struct crypt_device **, const char *, const char *) = NULL;
int (*sym_crypt_load)(struct crypt_device *, const char *, void *) = NULL;
int (*sym_crypt_get_volume_key_size)(struct crypt_device *) = NULL;
int (*sym_crypt_get_verity_info)(struct crypt_device *, struct crypt_params_verity *) = NULL;
int (*sym_crypt_volume_key_get)(struct crypt_device *, int, char *, size_t *, const char *, size_t) = NULL;
#else
+ void (*sym_crypt_set_debug_level)(int) = &crypt_set_debug_level;
+ void (*sym_crypt_set_log_callback)(struct crypt_device *, void (*log)(int, const char *, void *), void *) = &crypt_set_log_callback;
int (*sym_crypt_init_data_device)(struct crypt_device **, const char *, const char *) = &crypt_init_data_device;
int (*sym_crypt_load)(struct crypt_device *, const char *, void *) = &crypt_load;
int (*sym_crypt_get_volume_key_size)(struct crypt_device *) = &crypt_get_volume_key_size;
/* clear errors first, then load all the libcryptsetup symbols */
dlerror();
+ if (rc == 0)
+ *(void **)(&sym_crypt_set_debug_level) = get_symbol(cxt, dl, "crypt_set_debug_level", &rc);
+ if (rc == 0)
+ *(void **)(&sym_crypt_set_log_callback) = get_symbol(cxt, dl, "crypt_set_log_callback", &rc);
if (rc == 0)
*(void **)(&sym_crypt_init_data_device) = get_symbol(cxt, dl, "crypt_init_data_device", &rc);
if (rc == 0)
if (rc)
goto done;
+ if (mnt_context_is_verbose(cxt))
+ (*sym_crypt_set_debug_level)(CRYPT_DEBUG_ALL);
+ (*sym_crypt_set_log_callback)(NULL, libcryptsetup_log, cxt);
+
rc = (*sym_crypt_init_data_device)(&crypt_dev, hash_device, backing_file);
if (rc)
goto done;
#ifdef RTLD_DEEPBIND
dl_flags |= RTLD_DEEPBIND;
#endif
+ void (*sym_crypt_set_debug_level)(int) = NULL;
+ void (*sym_crypt_set_log_callback)(struct crypt_device *, void (*log)(int, const char *, void *), void *) = NULL;
int (*sym_crypt_init_by_name)(struct crypt_device **, const char *) = NULL;
int (*sym_crypt_deactivate_by_name)(struct crypt_device *, const char *, uint32_t) = NULL;
void (*sym_crypt_free)(struct crypt_device *) = NULL;
#else
+ void (*sym_crypt_set_debug_level)(int) = &crypt_set_debug_level;
+ void (*sym_crypt_set_log_callback)(struct crypt_device *, void (*log)(int, const char *, void *), void *) = &crypt_set_log_callback;
int (*sym_crypt_init_by_name)(struct crypt_device **, const char *) = &crypt_init_by_name;
int (*sym_crypt_deactivate_by_name)(struct crypt_device *, const char *, uint32_t) = &crypt_deactivate_by_name;
void (*sym_crypt_free)(struct crypt_device *) = &crypt_free;
/* clear errors first */
dlerror();
+ if (!rc)
+ *(void **)(&sym_crypt_set_debug_level) = get_symbol(cxt, dl, "crypt_set_debug_level", &rc);
+ if (!rc)
+ *(void **)(&sym_crypt_set_log_callback) = get_symbol(cxt, dl, "crypt_set_log_callback", &rc);
if (!rc)
*(void **)(&sym_crypt_init_by_name) = get_symbol(cxt, dl, "crypt_init_by_name", &rc);
if (!rc)
*(void **)(&sym_crypt_free) = get_symbol(cxt, dl, "crypt_free", &rc);
#endif
if (!rc) {
+ if (mnt_context_is_verbose(cxt))
+ (*sym_crypt_set_debug_level)(CRYPT_DEBUG_ALL);
+ (*sym_crypt_set_log_callback)(NULL, libcryptsetup_log, cxt);
rc = (*sym_crypt_init_by_name)(&crypt_dev, src);
if (!rc) {
rc = (*sym_crypt_deactivate_by_name)(crypt_dev, src, flags);