mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Properly apply versioned symbols in library and fix problems uncovered
by doing that:-) git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@124 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
2009-09-30 Milan Broz <mbroz@redhat.com>
|
||||||
|
* Fix exported symbols and versions in libcryptsetup.
|
||||||
|
* Do not use internal lib functions in cryptsetup.
|
||||||
|
* Add crypt_log to library.
|
||||||
|
* Fix crypt_remove_device (remove, luksClose) implementation.
|
||||||
|
|
||||||
2009-09-28 Milan Broz <mbroz@redhat.com>
|
2009-09-28 Milan Broz <mbroz@redhat.com>
|
||||||
* Add luksHeaderBackup and luksHeaderRestore commands.
|
* Add luksHeaderBackup and luksHeaderRestore commands.
|
||||||
* Fail passphrase read if piped input no longer exists.
|
* Fail passphrase read if piped input no longer exists.
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ libcryptsetup_la_DEPENDENCIES = libcryptsetup.sym
|
|||||||
|
|
||||||
libcryptsetup_la_LDFLAGS = \
|
libcryptsetup_la_LDFLAGS = \
|
||||||
$(_STATIC_LIBRARY) \
|
$(_STATIC_LIBRARY) \
|
||||||
--version-script=libcryptsetup.sym \
|
-Wl,--version-script=libcryptsetup.sym \
|
||||||
-version-info 1:0:0
|
-version-info 1:0:0
|
||||||
|
|
||||||
libcryptsetup_la_CFLAGS = -Wall
|
libcryptsetup_la_CFLAGS = -Wall
|
||||||
|
|||||||
@@ -109,7 +109,6 @@ void get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
|
|||||||
|
|
||||||
int parse_into_name_and_mode(const char *nameAndMode, char *name, char *mode);
|
int parse_into_name_and_mode(const char *nameAndMode, char *name, char *mode);
|
||||||
|
|
||||||
void set_default_log(void (*log)(int class, char *msg));
|
|
||||||
void logger(struct crypt_device *cd, int class, const char *file, int line, const char *format, ...);
|
void logger(struct crypt_device *cd, int class, const char *file, int line, const char *format, ...);
|
||||||
#define log_dbg(x...) logger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
#define log_dbg(x...) logger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
||||||
#define log_std(c, x...) logger(c, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
#define log_std(c, x...) logger(c, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ int crypt_init_by_name(struct crypt_device **cd, const char *name);
|
|||||||
/**
|
/**
|
||||||
* Set log function.
|
* Set log function.
|
||||||
*
|
*
|
||||||
* @cd - crypt device handle
|
* @cd - crypt device handle (can be NULL to set default log function)
|
||||||
* @usrptr - provided identification in callback
|
* @usrptr - provided identification in callback
|
||||||
* @class - log type below (debug messages can uses other levels)
|
* @class - log type below (debug messages can uses other levels)
|
||||||
* @msg - log message
|
* @msg - log message
|
||||||
@@ -47,6 +47,15 @@ void crypt_set_log_callback(struct crypt_device *cd,
|
|||||||
void (*log)(int class, const char *msg, void *usrptr),
|
void (*log)(int class, const char *msg, void *usrptr),
|
||||||
void *usrptr);
|
void *usrptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log message through log function.
|
||||||
|
*
|
||||||
|
* @cd - crypt device handle
|
||||||
|
* @class - log type
|
||||||
|
* @msg - log message
|
||||||
|
*/
|
||||||
|
void crypt_log(struct crypt_device *cd, int class, const char *msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set confirmation callback (yes/no)
|
* Set confirmation callback (yes/no)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ CRYPTSETUP_1.0 {
|
|||||||
crypt_get_error;
|
crypt_get_error;
|
||||||
crypt_get_dir;
|
crypt_get_dir;
|
||||||
crypt_set_debug_level;
|
crypt_set_debug_level;
|
||||||
|
crypt_log;
|
||||||
|
|
||||||
crypt_header_backup;
|
crypt_header_backup;
|
||||||
crypt_header_restore;
|
crypt_header_restore;
|
||||||
|
|||||||
39
lib/setup.c
39
lib/setup.c
@@ -39,7 +39,7 @@ struct crypt_device {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Log helper */
|
/* Log helper */
|
||||||
static void (*_default_log)(int class, char *msg) = NULL;
|
static void (*_default_log)(int class, const char *msg, void *usrptr) = NULL;
|
||||||
static int _debug_level = 0;
|
static int _debug_level = 0;
|
||||||
|
|
||||||
void crypt_set_debug_level(int level)
|
void crypt_set_debug_level(int level)
|
||||||
@@ -47,9 +47,12 @@ void crypt_set_debug_level(int level)
|
|||||||
_debug_level = level;
|
_debug_level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_default_log(void (*log)(int class, char *msg))
|
void crypt_log(struct crypt_device *cd, int class, const char *msg)
|
||||||
{
|
{
|
||||||
_default_log = log;
|
if (cd && cd->log)
|
||||||
|
cd->log(class, msg, cd->log_usrptr);
|
||||||
|
else if (_default_log)
|
||||||
|
_default_log(class, msg, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logger(struct crypt_device *cd, int class, const char *file,
|
void logger(struct crypt_device *cd, int class, const char *file,
|
||||||
@@ -62,10 +65,7 @@ void logger(struct crypt_device *cd, int class, const char *file,
|
|||||||
|
|
||||||
if (vasprintf(&target, format, argp) > 0) {
|
if (vasprintf(&target, format, argp) > 0) {
|
||||||
if (class >= 0) {
|
if (class >= 0) {
|
||||||
if (cd && cd->log)
|
crypt_log(cd, class, target);
|
||||||
cd->log(class, target, cd->log_usrptr);
|
|
||||||
else if (_default_log)
|
|
||||||
_default_log(class, target);
|
|
||||||
#ifdef CRYPT_DEBUG
|
#ifdef CRYPT_DEBUG
|
||||||
} else if (_debug_level)
|
} else if (_debug_level)
|
||||||
printf("# %s:%d %s\n", file ?: "?", line, target);
|
printf("# %s:%d %s\n", file ?: "?", line, target);
|
||||||
@@ -552,8 +552,12 @@ void crypt_set_log_callback(struct crypt_device *cd,
|
|||||||
void (*log)(int class, const char *msg, void *usrptr),
|
void (*log)(int class, const char *msg, void *usrptr),
|
||||||
void *usrptr)
|
void *usrptr)
|
||||||
{
|
{
|
||||||
cd->log = log;
|
if (!cd)
|
||||||
cd->log_usrptr = usrptr;
|
_default_log = log;
|
||||||
|
else {
|
||||||
|
cd->log = log;
|
||||||
|
cd->log_usrptr = usrptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void crypt_set_confirm_callback(struct crypt_device *cd,
|
void crypt_set_confirm_callback(struct crypt_device *cd,
|
||||||
@@ -703,7 +707,18 @@ int crypt_query_device(struct crypt_options *options)
|
|||||||
/* OPTIONS: name, icb */
|
/* OPTIONS: name, icb */
|
||||||
int crypt_remove_device(struct crypt_options *options)
|
int crypt_remove_device(struct crypt_options *options)
|
||||||
{
|
{
|
||||||
return crypt_deactivate(NULL, options->name);
|
struct crypt_device *cd = NULL;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = crypt_init_by_name(&cd, options->name);
|
||||||
|
if (r)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = crypt_deactivate(cd, options->name);
|
||||||
|
|
||||||
|
crypt_free(cd);
|
||||||
|
return r;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* OPTIONS: device, cipher, hash, align_payload, key_size (master key), key_slot
|
/* OPTIONS: device, cipher, hash, align_payload, key_size (master key), key_slot
|
||||||
@@ -981,12 +996,12 @@ int crypt_init_by_name(struct crypt_device **cd, const char *name)
|
|||||||
ci = crypt_status(NULL, name);
|
ci = crypt_status(NULL, name);
|
||||||
if (ci < ACTIVE) {
|
if (ci < ACTIVE) {
|
||||||
log_err(NULL, _("Device %s is not active.\n"), name);
|
log_err(NULL, _("Device %s is not active.\n"), name);
|
||||||
return -EINVAL;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = dm_query_device(name, &device, NULL, NULL, NULL,
|
r = dm_query_device(name, &device, NULL, NULL, NULL,
|
||||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||||
if (!r)
|
if (r >= 0)
|
||||||
r = crypt_init(cd, device);
|
r = crypt_init(cd, device);
|
||||||
|
|
||||||
free(device);
|
free(device);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -70,7 +71,7 @@ static struct action_type {
|
|||||||
const char *desc;
|
const char *desc;
|
||||||
} action_types[] = {
|
} action_types[] = {
|
||||||
{ "create", action_create, 0, 2, 1, 1, 1, N_("<name> <device>"),N_("create device") },
|
{ "create", action_create, 0, 2, 1, 1, 1, N_("<name> <device>"),N_("create device") },
|
||||||
{ "remove", action_remove, 0, 1, 1, 0, 1, N_("<name>"), N_("remove device") },
|
{ "remove", action_remove, 0, 1, 1, 1, 1, N_("<name>"), N_("remove device") },
|
||||||
{ "resize", action_resize, 0, 1, 1, 1, 1, N_("<name>"), N_("resize active device") },
|
{ "resize", action_resize, 0, 1, 1, 1, 1, N_("<name>"), N_("resize active device") },
|
||||||
{ "status", action_status, 0, 1, 1, 0, 1, N_("<name>"), N_("show device status") },
|
{ "status", action_status, 0, 1, 1, 0, 1, N_("<name>"), N_("show device status") },
|
||||||
{ "luksFormat", action_luksFormat, 0, 1, 1, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
|
{ "luksFormat", action_luksFormat, 0, 1, 1, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
|
||||||
@@ -80,7 +81,7 @@ static struct action_type {
|
|||||||
{ "luksKillSlot", action_luksKillSlot, 0, 2, 1, 1, 1, N_("<device> <key slot>"), N_("wipes key with number <key slot> from LUKS device") },
|
{ "luksKillSlot", action_luksKillSlot, 0, 2, 1, 1, 1, N_("<device> <key slot>"), N_("wipes key with number <key slot> from LUKS device") },
|
||||||
{ "luksUUID", action_luksUUID, 0, 1, 0, 0, 1, N_("<device>"), N_("print UUID of LUKS device") },
|
{ "luksUUID", action_luksUUID, 0, 1, 0, 0, 1, N_("<device>"), N_("print UUID of LUKS device") },
|
||||||
{ "isLuks", action_isLuks, 0, 1, 0, 0, 0, N_("<device>"), N_("tests <device> for LUKS partition header") },
|
{ "isLuks", action_isLuks, 0, 1, 0, 0, 0, N_("<device>"), N_("tests <device> for LUKS partition header") },
|
||||||
{ "luksClose", action_remove, 0, 1, 1, 0, 1, N_("<name>"), N_("remove LUKS mapping") },
|
{ "luksClose", action_remove, 0, 1, 1, 1, 1, N_("<name>"), N_("remove LUKS mapping") },
|
||||||
{ "luksDump", action_luksDump, 0, 1, 0, 0, 1, N_("<device>"), N_("dump LUKS partition information") },
|
{ "luksDump", action_luksDump, 0, 1, 0, 0, 1, N_("<device>"), N_("dump LUKS partition information") },
|
||||||
{ "luksSuspend",action_luksSuspend, 0, 1, 1, 1, 1, N_("<device>"), N_("Suspend LUKS device and wipe key (all IOs are frozen).") },
|
{ "luksSuspend",action_luksSuspend, 0, 1, 1, 1, 1, N_("<device>"), N_("Suspend LUKS device and wipe key (all IOs are frozen).") },
|
||||||
{ "luksResume", action_luksResume, 0, 1, 1, 1, 1, N_("<device>"), N_("Resume suspended LUKS device.") },
|
{ "luksResume", action_luksResume, 0, 1, 1, 1, 1, N_("<device>"), N_("Resume suspended LUKS device.") },
|
||||||
@@ -91,6 +92,30 @@ static struct action_type {
|
|||||||
{ NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL }
|
{ NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void clogger(struct crypt_device *cd, int class, const char *file,
|
||||||
|
int line, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list argp;
|
||||||
|
char *target = NULL;
|
||||||
|
|
||||||
|
va_start(argp, format);
|
||||||
|
|
||||||
|
if (vasprintf(&target, format, argp) > 0) {
|
||||||
|
if (class >= 0) {
|
||||||
|
crypt_log(cd, class, target);
|
||||||
|
#ifdef CRYPT_DEBUG
|
||||||
|
} else if (opt_debug)
|
||||||
|
printf("# %s:%d %s\n", file ?: "?", line, target);
|
||||||
|
#else
|
||||||
|
} else if (opt_debug)
|
||||||
|
printf("# %s\n", target);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(argp);
|
||||||
|
free(target);
|
||||||
|
}
|
||||||
|
|
||||||
/* Interface Callbacks */
|
/* Interface Callbacks */
|
||||||
static int yesDialog(char *msg)
|
static int yesDialog(char *msg)
|
||||||
{
|
{
|
||||||
@@ -319,7 +344,9 @@ static int _action_luksFormat_useMK()
|
|||||||
.data_alignment = opt_align_payload,
|
.data_alignment = opt_align_payload,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (parse_into_name_and_mode(opt_cipher ?: DEFAULT_LUKS_CIPHER, cipher, cipher_mode)) {
|
if (sscanf(opt_cipher ?: DEFAULT_LUKS_CIPHER,
|
||||||
|
"%" MAX_CIPHER_LEN_STR "[^-]-%" MAX_CIPHER_LEN_STR "s",
|
||||||
|
cipher, cipher_mode) != 2) {
|
||||||
log_err("No known cipher specification pattern detected.\n");
|
log_err("No known cipher specification pattern detected.\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -643,11 +670,6 @@ static int run_action(struct action_type *action)
|
|||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (dm_init(NULL, action->required_dm_backend) < 1) {
|
|
||||||
log_err("Cannot communicate with device-mapper. Is dm_mod kernel module loaded?\n");
|
|
||||||
return -ENOSYS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action->required_memlock)
|
if (action->required_memlock)
|
||||||
crypt_memory_lock(NULL, 1);
|
crypt_memory_lock(NULL, 1);
|
||||||
|
|
||||||
@@ -656,9 +678,6 @@ static int run_action(struct action_type *action)
|
|||||||
if (action->required_memlock)
|
if (action->required_memlock)
|
||||||
crypt_memory_lock(NULL, 0);
|
crypt_memory_lock(NULL, 0);
|
||||||
|
|
||||||
if (action->required_dm_backend)
|
|
||||||
dm_exit();
|
|
||||||
|
|
||||||
if (r < 0 && (opt_verbose || action->show_status))
|
if (r < 0 && (opt_verbose || action->show_status))
|
||||||
show_status(-r);
|
show_status(-r);
|
||||||
|
|
||||||
@@ -706,7 +725,7 @@ int main(int argc, char **argv)
|
|||||||
int r;
|
int r;
|
||||||
const char *null_action_argv[] = {NULL};
|
const char *null_action_argv[] = {NULL};
|
||||||
|
|
||||||
set_default_log(cmdLineLog);
|
crypt_set_log_callback(NULL, _log, NULL);
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
|
|||||||
@@ -34,18 +34,10 @@
|
|||||||
#define DEFAULT_LUKS_KEY_SIZE 128
|
#define DEFAULT_LUKS_KEY_SIZE 128
|
||||||
|
|
||||||
#define MAX_CIPHER_LEN 32
|
#define MAX_CIPHER_LEN 32
|
||||||
|
#define MAX_CIPHER_LEN_STR "32"
|
||||||
|
|
||||||
/* Helper funcions provided by internal libcryptsetup objects */
|
#define log_dbg(x...) clogger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
||||||
void set_default_log(void (*log)(int class, char *msg));
|
#define log_std(x...) clogger(NULL, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
||||||
void logger(struct crypt_device *cd, int class, const char *file, int line, const char *format, ...);
|
#define log_err(x...) clogger(NULL, CRYPT_LOG_ERROR, __FILE__, __LINE__, x)
|
||||||
#define log_dbg(x...) logger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
|
||||||
#define log_std(x...) logger(NULL, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
|
||||||
#define log_err(x...) logger(NULL, CRYPT_LOG_ERROR, __FILE__, __LINE__, x)
|
|
||||||
|
|
||||||
extern int memlock_inc(struct crypt_device *ctx);
|
|
||||||
extern int memlock_dec(struct crypt_device *ctx);
|
|
||||||
extern int dm_init(struct crypt_device *context, int check_kernel);
|
|
||||||
extern void dm_exit(void);
|
|
||||||
extern int parse_into_name_and_mode(const char *nameAndMode, char *name, char *mode);
|
|
||||||
|
|
||||||
#endif /* CRYPTSETUP_H */
|
#endif /* CRYPTSETUP_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user