mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 20:00:08 +01:00
Remove global variables from tools utilities.
This commit is contained in:
committed by
Milan Broz
parent
9da23371d5
commit
6dbfe52c35
103
src/cryptsetup.c
103
src/cryptsetup.c
@@ -40,6 +40,8 @@ static int action_argc;
|
|||||||
static const char *null_action_argv[] = {NULL, NULL};
|
static const char *null_action_argv[] = {NULL, NULL};
|
||||||
static int total_keyfiles = 0;
|
static int total_keyfiles = 0;
|
||||||
|
|
||||||
|
static struct tools_log_params log_parms;
|
||||||
|
|
||||||
void tools_cleanup(void)
|
void tools_cleanup(void)
|
||||||
{
|
{
|
||||||
tools_args_free(tool_core_args, ARRAY_SIZE(tool_core_args));
|
tools_args_free(tool_core_args, ARRAY_SIZE(tool_core_args));
|
||||||
@@ -252,12 +254,12 @@ static int action_open_plain(void)
|
|||||||
/* Skip blkid scan when activating plain device with offset */
|
/* Skip blkid scan when activating plain device with offset */
|
||||||
if (!ARG_UINT64(OPT_OFFSET_ID)) {
|
if (!ARG_UINT64(OPT_OFFSET_ID)) {
|
||||||
/* Print all present signatures in read-only mode */
|
/* Print all present signatures in read-only mode */
|
||||||
r = tools_detect_signatures(action_argv[0], 0, &signatures);
|
r = tools_detect_signatures(action_argv[0], 0, &signatures, ARG_SET(OPT_BATCH_MODE_ID));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signatures) {
|
if (signatures && !ARG_SET(OPT_BATCH_MODE_ID)) {
|
||||||
r = asprintf(&msg, _("Detected device signature(s) on %s. Proceeding further may damage existing data."), action_argv[0]);
|
r = asprintf(&msg, _("Detected device signature(s) on %s. Proceeding further may damage existing data."), action_argv[0]);
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
r = -ENOMEM;
|
r = -ENOMEM;
|
||||||
@@ -544,7 +546,7 @@ static int tcryptDump_with_volume_key(struct crypt_device *cd)
|
|||||||
unsigned i;
|
unsigned i;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!yesDialog(
|
if (!ARG_SET(OPT_BATCH_MODE_ID) && !yesDialog(
|
||||||
_("Header dump with volume key is sensitive information\n"
|
_("Header dump with volume key is sensitive information\n"
|
||||||
"which allows access to encrypted partition without passphrase.\n"
|
"which allows access to encrypted partition without passphrase.\n"
|
||||||
"This dump should be always stored encrypted on safe place."),
|
"This dump should be always stored encrypted on safe place."),
|
||||||
@@ -1132,15 +1134,15 @@ static int _do_luks2_reencrypt_recovery(struct crypt_device *cd)
|
|||||||
case CRYPT_REENCRYPT_NONE:
|
case CRYPT_REENCRYPT_NONE:
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case CRYPT_REENCRYPT_CLEAN:
|
case CRYPT_REENCRYPT_CLEAN:
|
||||||
r = noDialog(_("Seems device does not require reencryption recovery.\n"
|
if (ARG_SET(OPT_BATCH_MODE_ID) ||
|
||||||
"Do you want to proceed anyway?"), NULL);
|
!noDialog(_("Seems device does not require reencryption recovery.\n"
|
||||||
if (!r)
|
"Do you want to proceed anyway?"), NULL))
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
case CRYPT_REENCRYPT_CRASH:
|
case CRYPT_REENCRYPT_CRASH:
|
||||||
r = yesDialog(_("Really proceed with LUKS2 reencryption recovery?"),
|
if (!ARG_SET(OPT_BATCH_MODE_ID) &&
|
||||||
_("Operation aborted.\n"));
|
!yesDialog(_("Really proceed with LUKS2 reencryption recovery?"),
|
||||||
if (!r)
|
_("Operation aborted.\n")))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -1178,21 +1180,23 @@ static int action_luksRepair(void)
|
|||||||
action_argv[0])))
|
action_argv[0])))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
crypt_set_log_callback(cd, quiet_log, NULL);
|
crypt_set_log_callback(cd, quiet_log, &log_parms);
|
||||||
r = crypt_load(cd, luksType(device_type), NULL);
|
r = crypt_load(cd, luksType(device_type), NULL);
|
||||||
crypt_set_log_callback(cd, tool_log, NULL);
|
crypt_set_log_callback(cd, tool_log, &log_parms);
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
log_verbose(_("No known problems detected for LUKS header."));
|
log_verbose(_("No known problems detected for LUKS header."));
|
||||||
goto skip_repair;
|
goto skip_repair;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = tools_detect_signatures(action_argv[0], 1, NULL);
|
r = tools_detect_signatures(action_argv[0], 1, NULL, ARG_SET(OPT_BATCH_MODE_ID));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
r = yesDialog(_("Really try to repair LUKS device header?"),
|
if (!ARG_SET(OPT_BATCH_MODE_ID) &&
|
||||||
_("Operation aborted.\n")) ? 0 : -EINVAL;
|
!yesDialog(_("Really try to repair LUKS device header?"),
|
||||||
if (r == 0)
|
_("Operation aborted.\n")))
|
||||||
|
r = -EINVAL;
|
||||||
|
else
|
||||||
r = crypt_repair(cd, luksType(device_type), NULL);
|
r = crypt_repair(cd, luksType(device_type), NULL);
|
||||||
skip_repair:
|
skip_repair:
|
||||||
if (!r && crypt_get_type(cd) && !strcmp(crypt_get_type(cd), CRYPT_LUKS2))
|
if (!r && crypt_get_type(cd) && !strcmp(crypt_get_type(cd), CRYPT_LUKS2))
|
||||||
@@ -1207,6 +1211,10 @@ static int _wipe_data_device(struct crypt_device *cd)
|
|||||||
char tmp_name[64], tmp_path[128], tmp_uuid[40];
|
char tmp_name[64], tmp_path[128], tmp_uuid[40];
|
||||||
uuid_t tmp_uuid_bin;
|
uuid_t tmp_uuid_bin;
|
||||||
int r;
|
int r;
|
||||||
|
struct tools_progress_params prog_parms = {
|
||||||
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
||||||
|
};
|
||||||
|
|
||||||
if (!ARG_SET(OPT_BATCH_MODE_ID))
|
if (!ARG_SET(OPT_BATCH_MODE_ID))
|
||||||
log_std(_("Wiping device to initialize integrity checksum.\n"
|
log_std(_("Wiping device to initialize integrity checksum.\n"
|
||||||
@@ -1229,7 +1237,7 @@ static int _wipe_data_device(struct crypt_device *cd)
|
|||||||
/* Wipe the device */
|
/* Wipe the device */
|
||||||
set_int_handler(0);
|
set_int_handler(0);
|
||||||
r = crypt_wipe(cd, tmp_path, CRYPT_WIPE_ZERO, 0, 0, DEFAULT_WIPE_BLOCK,
|
r = crypt_wipe(cd, tmp_path, CRYPT_WIPE_ZERO, 0, 0, DEFAULT_WIPE_BLOCK,
|
||||||
0, &tools_wipe_progress, NULL);
|
0, &tools_wipe_progress, &prog_parms);
|
||||||
if (crypt_deactivate(cd, tmp_name))
|
if (crypt_deactivate(cd, tmp_name))
|
||||||
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
|
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
|
||||||
set_int_block(0);
|
set_int_block(0);
|
||||||
@@ -1357,11 +1365,11 @@ static int _luksFormat(struct crypt_device **r_cd, char **r_password, size_t *r_
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Print all present signatures in read-only mode */
|
/* Print all present signatures in read-only mode */
|
||||||
r = tools_detect_signatures(header_device, 0, &signatures);
|
r = tools_detect_signatures(header_device, 0, &signatures, ARG_SET(OPT_BATCH_MODE_ID));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!created) {
|
if (!created && !ARG_SET(OPT_BATCH_MODE_ID)) {
|
||||||
r = asprintf(&msg, _("This will overwrite data on %s irrevocably."), header_device);
|
r = asprintf(&msg, _("This will overwrite data on %s irrevocably."), header_device);
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
r = -ENOMEM;
|
r = -ENOMEM;
|
||||||
@@ -1567,7 +1575,7 @@ static int verify_keyslot(struct crypt_device *cd, int key_slot, crypt_keyslot_i
|
|||||||
int i, max, r;
|
int i, max, r;
|
||||||
|
|
||||||
if (ki == CRYPT_SLOT_ACTIVE_LAST && !ARG_SET(OPT_BATCH_MODE_ID) && !key_file &&
|
if (ki == CRYPT_SLOT_ACTIVE_LAST && !ARG_SET(OPT_BATCH_MODE_ID) && !key_file &&
|
||||||
msg_last && !yesDialog(msg_last, msg_fail))
|
msg_last && !ARG_SET(OPT_BATCH_MODE_ID) && !yesDialog(msg_last, msg_fail))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
r = tools_get_key(msg_pass, &password, &passwordLen,
|
r = tools_get_key(msg_pass, &password, &passwordLen,
|
||||||
@@ -1699,6 +1707,7 @@ static int action_luksRemoveKey(void)
|
|||||||
log_verbose(_("Keyslot %d is selected for deletion."), ARG_INT32(OPT_KEY_SLOT_ID));
|
log_verbose(_("Keyslot %d is selected for deletion."), ARG_INT32(OPT_KEY_SLOT_ID));
|
||||||
|
|
||||||
if (crypt_keyslot_status(cd, ARG_INT32(OPT_KEY_SLOT_ID)) == CRYPT_SLOT_ACTIVE_LAST &&
|
if (crypt_keyslot_status(cd, ARG_INT32(OPT_KEY_SLOT_ID)) == CRYPT_SLOT_ACTIVE_LAST &&
|
||||||
|
!ARG_SET(OPT_BATCH_MODE_ID) &&
|
||||||
!yesDialog(_("This is the last keyslot. "
|
!yesDialog(_("This is the last keyslot. "
|
||||||
"Device will become unusable after purging this key."),
|
"Device will become unusable after purging this key."),
|
||||||
_("Operation aborted, the keyslot was NOT wiped.\n"))) {
|
_("Operation aborted, the keyslot was NOT wiped.\n"))) {
|
||||||
@@ -2011,7 +2020,7 @@ static int action_isLuks(void)
|
|||||||
if ((r = crypt_init(&cd, uuid_or_device_header(NULL))))
|
if ((r = crypt_init(&cd, uuid_or_device_header(NULL))))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
crypt_set_log_callback(cd, quiet_log, NULL);
|
crypt_set_log_callback(cd, quiet_log, &log_parms);
|
||||||
r = crypt_load(cd, luksType(device_type), NULL);
|
r = crypt_load(cd, luksType(device_type), NULL);
|
||||||
out:
|
out:
|
||||||
crypt_free(cd);
|
crypt_free(cd);
|
||||||
@@ -2027,6 +2036,7 @@ static int action_luksUUID(void)
|
|||||||
if ((r = crypt_init(&cd, uuid_or_device_header(NULL))))
|
if ((r = crypt_init(&cd, uuid_or_device_header(NULL))))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
if (!ARG_SET(OPT_BATCH_MODE_ID))
|
||||||
crypt_set_confirm_callback(cd, yesDialog, _("Operation aborted.\n"));
|
crypt_set_confirm_callback(cd, yesDialog, _("Operation aborted.\n"));
|
||||||
|
|
||||||
if ((r = crypt_load(cd, luksType(device_type), NULL)))
|
if ((r = crypt_load(cd, luksType(device_type), NULL)))
|
||||||
@@ -2052,7 +2062,7 @@ static int luksDump_with_volume_key(struct crypt_device *cd)
|
|||||||
unsigned i;
|
unsigned i;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!yesDialog(
|
if (!ARG_SET(OPT_BATCH_MODE_ID) && !yesDialog(
|
||||||
_("The header dump with volume key is sensitive information\n"
|
_("The header dump with volume key is sensitive information\n"
|
||||||
"that allows access to encrypted partition without a passphrase.\n"
|
"that allows access to encrypted partition without a passphrase.\n"
|
||||||
"This dump should be stored encrypted in a safe place."),
|
"This dump should be stored encrypted in a safe place."),
|
||||||
@@ -2122,7 +2132,7 @@ static int luksDump_with_unbound_key(struct crypt_device *cd)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!yesDialog(
|
if (!ARG_SET(OPT_BATCH_MODE_ID) && !yesDialog(
|
||||||
_("The header dump with unbound key is sensitive information.\n"
|
_("The header dump with unbound key is sensitive information.\n"
|
||||||
"This dump should be stored encrypted in a safe place."),
|
"This dump should be stored encrypted in a safe place."),
|
||||||
NULL))
|
NULL))
|
||||||
@@ -2284,6 +2294,7 @@ static int action_luksRestore(void)
|
|||||||
if ((r = crypt_init(&cd, uuid_or_device_header(NULL))))
|
if ((r = crypt_init(&cd, uuid_or_device_header(NULL))))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
if (!ARG_SET(OPT_BATCH_MODE_ID))
|
||||||
crypt_set_confirm_callback(cd, yesDialog, NULL);
|
crypt_set_confirm_callback(cd, yesDialog, NULL);
|
||||||
r = crypt_header_restore(cd, NULL, ARG_STR(OPT_HEADER_BACKUP_FILE_ID));
|
r = crypt_header_restore(cd, NULL, ARG_STR(OPT_HEADER_BACKUP_FILE_ID));
|
||||||
out:
|
out:
|
||||||
@@ -2390,7 +2401,7 @@ static int action_luksErase(void)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!yesDialog(msg, _("Operation aborted, keyslots were NOT wiped.\n"))) {
|
if (!ARG_SET(OPT_BATCH_MODE_ID) && !yesDialog(msg, _("Operation aborted, keyslots were NOT wiped.\n"))) {
|
||||||
r = -EPERM;
|
r = -EPERM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -2448,16 +2459,16 @@ static int action_luksConvert(void)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r = 0;
|
||||||
|
if (!ARG_SET(OPT_BATCH_MODE_ID)) {
|
||||||
if (asprintf(&msg, _("This operation will convert %s to %s format.\n"),
|
if (asprintf(&msg, _("This operation will convert %s to %s format.\n"),
|
||||||
uuid_or_device_header(NULL), to_type) == -1) {
|
uuid_or_device_header(NULL), to_type) == -1)
|
||||||
crypt_free(cd);
|
r = -ENOMEM;
|
||||||
return -ENOMEM;
|
else if (!yesDialog(msg, _("Operation aborted, device was NOT converted.\n")))
|
||||||
|
r = -EPERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yesDialog(msg, _("Operation aborted, device was NOT converted.\n")))
|
r = r ?: crypt_convert(cd, to_type, NULL);
|
||||||
r = crypt_convert(cd, to_type, NULL);
|
|
||||||
else
|
|
||||||
r = -EPERM;
|
|
||||||
|
|
||||||
free(msg);
|
free(msg);
|
||||||
crypt_free(cd);
|
crypt_free(cd);
|
||||||
@@ -2591,7 +2602,7 @@ static int _token_import(struct crypt_device *cd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r = tools_read_json_file(cd, ARG_STR(OPT_JSON_FILE_ID), &json, &json_length);
|
r = tools_read_json_file(cd, ARG_STR(OPT_JSON_FILE_ID), &json, &json_length, ARG_SET(OPT_BATCH_MODE_ID));
|
||||||
if (r)
|
if (r)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@@ -2720,6 +2731,8 @@ static int _get_device_active_name(struct crypt_device *cd, const char *data_dev
|
|||||||
else
|
else
|
||||||
log_err(_("Failed to auto-detect device %s holders."), data_device);
|
log_err(_("Failed to auto-detect device %s holders."), data_device);
|
||||||
|
|
||||||
|
r = -EINVAL;
|
||||||
|
if (!ARG_SET(OPT_BATCH_MODE_ID)) {
|
||||||
r = asprintf(&msg, _("Unable to decide if device %s is activated or not.\n"
|
r = asprintf(&msg, _("Unable to decide if device %s is activated or not.\n"
|
||||||
"Are you sure you want to proceed with reencryption in offline mode?\n"
|
"Are you sure you want to proceed with reencryption in offline mode?\n"
|
||||||
"It may lead to data corruption if the device is actually activated.\n"
|
"It may lead to data corruption if the device is actually activated.\n"
|
||||||
@@ -2729,6 +2742,7 @@ static int _get_device_active_name(struct crypt_device *cd, const char *data_dev
|
|||||||
r = noDialog(msg, _("Operation aborted.\n")) ? 0 : -EINVAL;
|
r = noDialog(msg, _("Operation aborted.\n")) ? 0 : -EINVAL;
|
||||||
free(msg);
|
free(msg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -2847,7 +2861,7 @@ static int action_encrypt_luks2(struct crypt_device **cd)
|
|||||||
r = crypt_load(*cd, CRYPT_LUKS, NULL);
|
r = crypt_load(*cd, CRYPT_LUKS, NULL);
|
||||||
crypt_free(*cd);
|
crypt_free(*cd);
|
||||||
*cd = NULL;
|
*cd = NULL;
|
||||||
if (!r) {
|
if (!r && !ARG_SET(OPT_BATCH_MODE_ID)) {
|
||||||
r = asprintf(&msg, _("Detected LUKS device on %s. Do you want to encrypt that LUKS device again?"), action_argv[0]);
|
r = asprintf(&msg, _("Detected LUKS device on %s. Do you want to encrypt that LUKS device again?"), action_argv[0]);
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@@ -3319,6 +3333,10 @@ static int action_reencrypt(void)
|
|||||||
struct crypt_device *cd = NULL;
|
struct crypt_device *cd = NULL;
|
||||||
struct crypt_params_integrity ip = { 0 };
|
struct crypt_params_integrity ip = { 0 };
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
struct tools_progress_params prog_parms = {
|
||||||
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
||||||
|
};
|
||||||
|
|
||||||
if (action_argc < 1 && (!ARG_SET(OPT_ACTIVE_NAME_ID) || ARG_SET(OPT_ENCRYPT_ID))) {
|
if (action_argc < 1 && (!ARG_SET(OPT_ACTIVE_NAME_ID) || ARG_SET(OPT_ENCRYPT_ID))) {
|
||||||
log_err(_("Command requires device as argument."));
|
log_err(_("Command requires device as argument."));
|
||||||
@@ -3388,7 +3406,7 @@ static int action_reencrypt(void)
|
|||||||
|
|
||||||
if (r >= 0 && !ARG_SET(OPT_INIT_ONLY_ID)) {
|
if (r >= 0 && !ARG_SET(OPT_INIT_ONLY_ID)) {
|
||||||
set_int_handler(0);
|
set_int_handler(0);
|
||||||
r = crypt_reencrypt(cd, tools_reencrypt_progress, NULL);
|
r = crypt_reencrypt(cd, tools_reencrypt_progress, &prog_parms);
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
crypt_free(cd);
|
crypt_free(cd);
|
||||||
@@ -3559,6 +3577,14 @@ static void basic_options_cb(poptContext popt_context,
|
|||||||
|
|
||||||
/* special cases additional handling */
|
/* special cases additional handling */
|
||||||
switch (key->val) {
|
switch (key->val) {
|
||||||
|
case OPT_DEBUG_JSON_ID:
|
||||||
|
/* fall through */
|
||||||
|
case OPT_DEBUG_ID:
|
||||||
|
log_parms.debug = true;
|
||||||
|
/* fall through */
|
||||||
|
case OPT_VERBOSE_ID:
|
||||||
|
log_parms.verbose = true;
|
||||||
|
break;
|
||||||
case OPT_DEVICE_SIZE_ID:
|
case OPT_DEVICE_SIZE_ID:
|
||||||
if (ARG_UINT64(OPT_DEVICE_SIZE_ID) == 0)
|
if (ARG_UINT64(OPT_DEVICE_SIZE_ID) == 0)
|
||||||
usage(popt_context, EXIT_FAILURE, poptStrerror(POPT_ERROR_BADNUMBER),
|
usage(popt_context, EXIT_FAILURE, poptStrerror(POPT_ERROR_BADNUMBER),
|
||||||
@@ -3652,7 +3678,7 @@ int main(int argc, const char **argv)
|
|||||||
const char *aname;
|
const char *aname;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
crypt_set_log_callback(NULL, tool_log, NULL);
|
crypt_set_log_callback(NULL, tool_log, &log_parms);
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
@@ -3895,8 +3921,6 @@ int main(int argc, const char **argv)
|
|||||||
poptGetInvocationName(popt_context));
|
poptGetInvocationName(popt_context));
|
||||||
|
|
||||||
if (ARG_SET(OPT_DEBUG_ID) || ARG_SET(OPT_DEBUG_JSON_ID)) {
|
if (ARG_SET(OPT_DEBUG_ID) || ARG_SET(OPT_DEBUG_JSON_ID)) {
|
||||||
ARG_SET_TRUE(OPT_DEBUG_ID);
|
|
||||||
ARG_SET_TRUE(OPT_VERBOSE_ID);
|
|
||||||
crypt_set_debug_level(ARG_SET(OPT_DEBUG_JSON_ID)? CRYPT_DEBUG_JSON : CRYPT_DEBUG_ALL);
|
crypt_set_debug_level(ARG_SET(OPT_DEBUG_JSON_ID)? CRYPT_DEBUG_JSON : CRYPT_DEBUG_ALL);
|
||||||
dbg_version_and_cmd(argc, argv);
|
dbg_version_and_cmd(argc, argv);
|
||||||
}
|
}
|
||||||
@@ -3925,13 +3949,6 @@ int main(int argc, const char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Remove global variables from future cli library */
|
|
||||||
opt_verbose = ARG_SET(OPT_VERBOSE_ID) ? 1 : 0;
|
|
||||||
opt_debug = ARG_SET(OPT_DEBUG_ID) ? 1 : 0;
|
|
||||||
opt_debug_json = ARG_SET(OPT_DEBUG_JSON_ID) ? 1 : 0;
|
|
||||||
opt_batch_mode = ARG_SET(OPT_BATCH_MODE_ID) ? 1 : 0;
|
|
||||||
opt_progress_frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID);
|
|
||||||
|
|
||||||
if (ARG_SET(OPT_DISABLE_KEYRING_ID))
|
if (ARG_SET(OPT_DISABLE_KEYRING_ID))
|
||||||
(void) crypt_volume_key_keyring(NULL, 0);
|
(void) crypt_volume_key_keyring(NULL, 0);
|
||||||
|
|
||||||
|
|||||||
@@ -64,12 +64,6 @@
|
|||||||
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int opt_debug;
|
|
||||||
extern int opt_debug_json;
|
|
||||||
extern int opt_verbose;
|
|
||||||
extern int opt_batch_mode;
|
|
||||||
extern int opt_progress_frequency;
|
|
||||||
|
|
||||||
/* Common tools */
|
/* Common tools */
|
||||||
void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)));
|
void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)));
|
||||||
void quiet_log(int level, const char *msg, void *usrptr);
|
void quiet_log(int level, const char *msg, void *usrptr);
|
||||||
@@ -104,13 +98,21 @@ int tools_is_stdin(const char *key_file);
|
|||||||
int tools_string_to_size(struct crypt_device *cd, const char *s, uint64_t *size);
|
int tools_string_to_size(struct crypt_device *cd, const char *s, uint64_t *size);
|
||||||
int tools_is_cipher_null(const char *cipher);
|
int tools_is_cipher_null(const char *cipher);
|
||||||
|
|
||||||
|
struct tools_progress_params {
|
||||||
|
uint32_t frequency;
|
||||||
|
struct timeval start_time;
|
||||||
|
struct timeval end_time;
|
||||||
|
uint64_t start_offset;
|
||||||
|
bool batch_mode;
|
||||||
|
};
|
||||||
|
|
||||||
int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr);
|
int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr);
|
||||||
int tools_reencrypt_progress(uint64_t size, uint64_t offset, void *usrptr);
|
int tools_reencrypt_progress(uint64_t size, uint64_t offset, void *usrptr);
|
||||||
|
|
||||||
int tools_read_json_file(struct crypt_device *cd, const char *file, char **json, size_t *json_size);
|
int tools_read_json_file(struct crypt_device *cd, const char *file, char **json, size_t *json_size, bool batch_mode);
|
||||||
int tools_write_json_file(struct crypt_device *cd, const char *file, const char *json);
|
int tools_write_json_file(struct crypt_device *cd, const char *file, const char *json);
|
||||||
|
|
||||||
int tools_detect_signatures(const char *device, int ignore_luks, size_t *count);
|
int tools_detect_signatures(const char *device, int ignore_luks, size_t *count, bool batch_mode);
|
||||||
int tools_wipe_all_signatures(const char *path);
|
int tools_wipe_all_signatures(const char *path);
|
||||||
|
|
||||||
int tools_lookup_crypt_device(struct crypt_device *cd, const char *type,
|
int tools_lookup_crypt_device(struct crypt_device *cd, const char *type,
|
||||||
@@ -133,4 +135,9 @@ void tools_cleanup(void);
|
|||||||
#define log_verbose(x...) crypt_logf(NULL, CRYPT_LOG_VERBOSE, x)
|
#define log_verbose(x...) crypt_logf(NULL, CRYPT_LOG_VERBOSE, x)
|
||||||
#define log_err(x...) crypt_logf(NULL, CRYPT_LOG_ERROR, x)
|
#define log_err(x...) crypt_logf(NULL, CRYPT_LOG_ERROR, x)
|
||||||
|
|
||||||
|
struct tools_log_params {
|
||||||
|
bool verbose;
|
||||||
|
bool debug;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* CRYPTSETUP_H */
|
#endif /* CRYPTSETUP_H */
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ static const char **action_argv;
|
|||||||
|
|
||||||
static const char *set_pbkdf = NULL;
|
static const char *set_pbkdf = NULL;
|
||||||
|
|
||||||
|
static struct tools_log_params log_parms;
|
||||||
|
|
||||||
#define MAX_SLOT 32
|
#define MAX_SLOT 32
|
||||||
#define MAX_TOKEN 32
|
#define MAX_TOKEN 32
|
||||||
struct reenc_ctx {
|
struct reenc_ctx {
|
||||||
@@ -909,6 +911,10 @@ static int copy_data_forward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
size_t block_size, void *buf, uint64_t *bytes)
|
size_t block_size, void *buf, uint64_t *bytes)
|
||||||
{
|
{
|
||||||
ssize_t s1, s2;
|
ssize_t s1, s2;
|
||||||
|
struct tools_progress_params prog_parms = {
|
||||||
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
||||||
|
};
|
||||||
|
|
||||||
log_dbg("Reencrypting in forward direction.");
|
log_dbg("Reencrypting in forward direction.");
|
||||||
|
|
||||||
@@ -920,7 +926,7 @@ static int copy_data_forward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
|
|
||||||
rc->resume_bytes = *bytes = rc->device_offset;
|
rc->resume_bytes = *bytes = rc->device_offset;
|
||||||
|
|
||||||
tools_reencrypt_progress(rc->device_size, *bytes, NULL);
|
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
||||||
|
|
||||||
if (write_log(rc) < 0)
|
if (write_log(rc) < 0)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
@@ -956,7 +962,7 @@ static int copy_data_forward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
|
|
||||||
*bytes += (uint64_t)s2;
|
*bytes += (uint64_t)s2;
|
||||||
|
|
||||||
tools_reencrypt_progress(rc->device_size, *bytes, NULL);
|
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
||||||
}
|
}
|
||||||
|
|
||||||
return quit ? -EAGAIN : 0;
|
return quit ? -EAGAIN : 0;
|
||||||
@@ -967,6 +973,10 @@ static int copy_data_backward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
{
|
{
|
||||||
ssize_t s1, s2, working_block;
|
ssize_t s1, s2, working_block;
|
||||||
off64_t working_offset;
|
off64_t working_offset;
|
||||||
|
struct tools_progress_params prog_parms = {
|
||||||
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
||||||
|
};
|
||||||
|
|
||||||
log_dbg("Reencrypting in backward direction.");
|
log_dbg("Reencrypting in backward direction.");
|
||||||
|
|
||||||
@@ -979,7 +989,7 @@ static int copy_data_backward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
*bytes = rc->resume_bytes;
|
*bytes = rc->resume_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
tools_reencrypt_progress(rc->device_size, *bytes, NULL);
|
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
||||||
|
|
||||||
if (write_log(rc) < 0)
|
if (write_log(rc) < 0)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
@@ -1027,7 +1037,7 @@ static int copy_data_backward(struct reenc_ctx *rc, int fd_old, int fd_new,
|
|||||||
|
|
||||||
*bytes += (uint64_t)s2;
|
*bytes += (uint64_t)s2;
|
||||||
|
|
||||||
tools_reencrypt_progress(rc->device_size, *bytes, NULL);
|
tools_reencrypt_progress(rc->device_size, *bytes, &prog_parms);
|
||||||
}
|
}
|
||||||
|
|
||||||
return quit ? -EAGAIN : 0;
|
return quit ? -EAGAIN : 0;
|
||||||
@@ -1593,6 +1603,12 @@ static void basic_options_cb(poptContext popt_context,
|
|||||||
|
|
||||||
/* special cases additional handling */
|
/* special cases additional handling */
|
||||||
switch (key->val) {
|
switch (key->val) {
|
||||||
|
case OPT_DEBUG_ID:
|
||||||
|
log_parms.debug = true;
|
||||||
|
/* fall through */
|
||||||
|
case OPT_VERBOSE_ID:
|
||||||
|
log_parms.verbose = true;
|
||||||
|
break;
|
||||||
case OPT_BLOCK_SIZE_ID:
|
case OPT_BLOCK_SIZE_ID:
|
||||||
if (ARG_UINT32(OPT_BLOCK_SIZE_ID) < 1 || ARG_UINT32(OPT_BLOCK_SIZE_ID) > 64)
|
if (ARG_UINT32(OPT_BLOCK_SIZE_ID) < 1 || ARG_UINT32(OPT_BLOCK_SIZE_ID) > 64)
|
||||||
usage(popt_context, EXIT_FAILURE,
|
usage(popt_context, EXIT_FAILURE,
|
||||||
@@ -1643,7 +1659,7 @@ int main(int argc, const char **argv)
|
|||||||
poptContext popt_context;
|
poptContext popt_context;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
crypt_set_log_callback(NULL, tool_log, NULL);
|
crypt_set_log_callback(NULL, tool_log, &log_parms);
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
@@ -1720,16 +1736,10 @@ int main(int argc, const char **argv)
|
|||||||
poptGetInvocationName(popt_context));
|
poptGetInvocationName(popt_context));
|
||||||
|
|
||||||
if (ARG_SET(OPT_DEBUG_ID)) {
|
if (ARG_SET(OPT_DEBUG_ID)) {
|
||||||
ARG_SET_TRUE(OPT_VERBOSE_ID);
|
|
||||||
crypt_set_debug_level(CRYPT_DEBUG_ALL);
|
crypt_set_debug_level(CRYPT_DEBUG_ALL);
|
||||||
dbg_version_and_cmd(argc, argv);
|
dbg_version_and_cmd(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
opt_verbose = ARG_SET(OPT_VERBOSE_ID) ? 1 : 0;
|
|
||||||
opt_debug = ARG_SET(OPT_DEBUG_ID) ? 1 : 0;
|
|
||||||
opt_batch_mode = ARG_SET(OPT_BATCH_MODE_ID) ? 1 : 0;
|
|
||||||
opt_progress_frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID);
|
|
||||||
|
|
||||||
r = run_reencrypt(action_argv[0]);
|
r = run_reencrypt(action_argv[0]);
|
||||||
tools_cleanup();
|
tools_cleanup();
|
||||||
poptFreeContext(popt_context);
|
poptFreeContext(popt_context);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
static const char **action_argv;
|
static const char **action_argv;
|
||||||
static int action_argc;
|
static int action_argc;
|
||||||
|
static struct tools_log_params log_parms;
|
||||||
|
|
||||||
void tools_cleanup(void)
|
void tools_cleanup(void)
|
||||||
{
|
{
|
||||||
@@ -83,6 +84,10 @@ static int _wipe_data_device(struct crypt_device *cd, const char *integrity_key)
|
|||||||
char tmp_name[64], tmp_path[128], tmp_uuid[40];
|
char tmp_name[64], tmp_path[128], tmp_uuid[40];
|
||||||
uuid_t tmp_uuid_bin;
|
uuid_t tmp_uuid_bin;
|
||||||
int r;
|
int r;
|
||||||
|
struct tools_progress_params prog_parms = {
|
||||||
|
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
|
||||||
|
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID)
|
||||||
|
};
|
||||||
|
|
||||||
if (!ARG_SET(OPT_BATCH_MODE_ID))
|
if (!ARG_SET(OPT_BATCH_MODE_ID))
|
||||||
log_std(_("Wiping device to initialize integrity checksum.\n"
|
log_std(_("Wiping device to initialize integrity checksum.\n"
|
||||||
@@ -105,7 +110,7 @@ static int _wipe_data_device(struct crypt_device *cd, const char *integrity_key)
|
|||||||
/* Wipe the device */
|
/* Wipe the device */
|
||||||
set_int_handler(0);
|
set_int_handler(0);
|
||||||
r = crypt_wipe(cd, tmp_path, CRYPT_WIPE_ZERO, 0, 0, DEFAULT_WIPE_BLOCK,
|
r = crypt_wipe(cd, tmp_path, CRYPT_WIPE_ZERO, 0, 0, DEFAULT_WIPE_BLOCK,
|
||||||
0, &tools_wipe_progress, NULL);
|
0, &tools_wipe_progress, &prog_parms);
|
||||||
if (crypt_deactivate(cd, tmp_name))
|
if (crypt_deactivate(cd, tmp_name))
|
||||||
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
|
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
|
||||||
set_int_block(0);
|
set_int_block(0);
|
||||||
@@ -164,6 +169,7 @@ static int action_format(int arg)
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
if (!ARG_SET(OPT_BATCH_MODE_ID)) {
|
||||||
r = asprintf(&msg, _("This will overwrite data on %s irrevocably."), action_argv[0]);
|
r = asprintf(&msg, _("This will overwrite data on %s irrevocably."), action_argv[0]);
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
r = -ENOMEM;
|
r = -ENOMEM;
|
||||||
@@ -174,8 +180,9 @@ static int action_format(int arg)
|
|||||||
free(msg);
|
free(msg);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
r = tools_detect_signatures(action_argv[0], 0, &signatures);
|
r = tools_detect_signatures(action_argv[0], 0, &signatures, ARG_SET(OPT_BATCH_MODE_ID));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
@@ -499,6 +506,12 @@ static void basic_options_cb(poptContext popt_context,
|
|||||||
|
|
||||||
/* special cases additional handling */
|
/* special cases additional handling */
|
||||||
switch (key->val) {
|
switch (key->val) {
|
||||||
|
case OPT_DEBUG_ID:
|
||||||
|
log_parms.debug = true;
|
||||||
|
/* fall through */
|
||||||
|
case OPT_VERBOSE_ID:
|
||||||
|
log_parms.verbose = true;
|
||||||
|
break;
|
||||||
case OPT_INTEGRITY_KEY_SIZE_ID:
|
case OPT_INTEGRITY_KEY_SIZE_ID:
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case OPT_JOURNAL_INTEGRITY_KEY_SIZE_ID:
|
case OPT_JOURNAL_INTEGRITY_KEY_SIZE_ID:
|
||||||
@@ -539,7 +552,7 @@ int main(int argc, const char **argv)
|
|||||||
const char *aname;
|
const char *aname;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
crypt_set_log_callback(NULL, tool_log, NULL);
|
crypt_set_log_callback(NULL, tool_log, &log_parms);
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
@@ -641,16 +654,10 @@ int main(int argc, const char **argv)
|
|||||||
poptGetInvocationName(popt_context));
|
poptGetInvocationName(popt_context));
|
||||||
|
|
||||||
if (ARG_SET(OPT_DEBUG_ID)) {
|
if (ARG_SET(OPT_DEBUG_ID)) {
|
||||||
ARG_SET_TRUE(OPT_VERBOSE_ID);
|
|
||||||
crypt_set_debug_level(CRYPT_DEBUG_ALL);
|
crypt_set_debug_level(CRYPT_DEBUG_ALL);
|
||||||
dbg_version_and_cmd(argc, argv);
|
dbg_version_and_cmd(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
opt_verbose = ARG_SET(OPT_VERBOSE_ID) ? 1 : 0;
|
|
||||||
opt_debug = ARG_SET(OPT_DEBUG_ID) ? 1 : 0;
|
|
||||||
opt_batch_mode = ARG_SET(OPT_BATCH_MODE_ID) ? 1 : 0;
|
|
||||||
opt_progress_frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID);
|
|
||||||
|
|
||||||
r = run_action(action);
|
r = run_action(action);
|
||||||
tools_cleanup();
|
tools_cleanup();
|
||||||
poptFreeContext(popt_context);
|
poptFreeContext(popt_context);
|
||||||
|
|||||||
@@ -189,23 +189,23 @@ int tools_lookup_crypt_device(struct crypt_device *cd, const char *type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void report_partition(const char *value, const char *device)
|
static void report_partition(const char *value, const char *device, bool batch_mode)
|
||||||
{
|
{
|
||||||
if (opt_batch_mode)
|
if (batch_mode)
|
||||||
log_dbg("Device %s already contains a '%s' partition signature.", device, value);
|
log_dbg("Device %s already contains a '%s' partition signature.", device, value);
|
||||||
else
|
else
|
||||||
log_std(_("WARNING: Device %s already contains a '%s' partition signature.\n"), device, value);
|
log_std(_("WARNING: Device %s already contains a '%s' partition signature.\n"), device, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void report_superblock(const char *value, const char *device)
|
static void report_superblock(const char *value, const char *device, bool batch_mode)
|
||||||
{
|
{
|
||||||
if (opt_batch_mode)
|
if (batch_mode)
|
||||||
log_dbg("Device %s already contains a '%s' superblock signature.", device, value);
|
log_dbg("Device %s already contains a '%s' superblock signature.", device, value);
|
||||||
else
|
else
|
||||||
log_std(_("WARNING: Device %s already contains a '%s' superblock signature.\n"), device, value);
|
log_std(_("WARNING: Device %s already contains a '%s' superblock signature.\n"), device, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tools_detect_signatures(const char *device, int ignore_luks, size_t *count)
|
int tools_detect_signatures(const char *device, int ignore_luks, size_t *count, bool batch_mode)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
size_t tmp_count;
|
size_t tmp_count;
|
||||||
@@ -236,9 +236,9 @@ int tools_detect_signatures(const char *device, int ignore_luks, size_t *count)
|
|||||||
|
|
||||||
while ((pr = blk_probe(h)) < PRB_EMPTY) {
|
while ((pr = blk_probe(h)) < PRB_EMPTY) {
|
||||||
if (blk_is_partition(h))
|
if (blk_is_partition(h))
|
||||||
report_partition(blk_get_partition_type(h), device);
|
report_partition(blk_get_partition_type(h), device, batch_mode);
|
||||||
else if (blk_is_superblock(h))
|
else if (blk_is_superblock(h))
|
||||||
report_superblock(blk_get_superblock_type(h), device);
|
report_superblock(blk_get_superblock_type(h), device, batch_mode);
|
||||||
else {
|
else {
|
||||||
log_dbg("Internal tools_detect_signatures() error.");
|
log_dbg("Internal tools_detect_signatures() error.");
|
||||||
r = -EINVAL;
|
r = -EINVAL;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
* In future, read max allowed JSON size from config section.
|
* In future, read max allowed JSON size from config section.
|
||||||
*/
|
*/
|
||||||
#define LUKS2_MAX_MDA_SIZE 0x400000
|
#define LUKS2_MAX_MDA_SIZE 0x400000
|
||||||
int tools_read_json_file(struct crypt_device *cd, const char *file, char **json, size_t *json_size)
|
int tools_read_json_file(struct crypt_device *cd, const char *file, char **json, size_t *json_size, bool batch_mode)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
int fd, block, r;
|
int fd, block, r;
|
||||||
@@ -56,7 +56,7 @@ int tools_read_json_file(struct crypt_device *cd, const char *file, char **json,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isatty(fd) && !opt_batch_mode)
|
if (isatty(fd) && !batch_mode)
|
||||||
log_std(_("Provide valid LUKS2 token JSON:\n"));
|
log_std(_("Provide valid LUKS2 token JSON:\n"));
|
||||||
|
|
||||||
/* we expect JSON (string) */
|
/* we expect JSON (string) */
|
||||||
|
|||||||
@@ -25,12 +25,6 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
int opt_verbose = 0;
|
|
||||||
int opt_debug = 0;
|
|
||||||
int opt_debug_json = 0;
|
|
||||||
int opt_batch_mode = 0;
|
|
||||||
int opt_progress_frequency = 0;
|
|
||||||
|
|
||||||
/* interrupt handling */
|
/* interrupt handling */
|
||||||
volatile int quit = 0;
|
volatile int quit = 0;
|
||||||
static int signals_blocked = 0;
|
static int signals_blocked = 0;
|
||||||
@@ -77,15 +71,17 @@ void check_signal(int *r)
|
|||||||
*r = -EINTR;
|
*r = -EINTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)))
|
void tool_log(int level, const char *msg, void *usrptr)
|
||||||
{
|
{
|
||||||
|
struct tools_log_params *params = (struct tools_log_params *)usrptr;
|
||||||
|
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
|
||||||
case CRYPT_LOG_NORMAL:
|
case CRYPT_LOG_NORMAL:
|
||||||
fprintf(stdout, "%s", msg);
|
fprintf(stdout, "%s", msg);
|
||||||
break;
|
break;
|
||||||
case CRYPT_LOG_VERBOSE:
|
case CRYPT_LOG_VERBOSE:
|
||||||
if (opt_verbose)
|
if (params && params->verbose)
|
||||||
fprintf(stdout, "%s", msg);
|
fprintf(stdout, "%s", msg);
|
||||||
break;
|
break;
|
||||||
case CRYPT_LOG_ERROR:
|
case CRYPT_LOG_ERROR:
|
||||||
@@ -93,7 +89,7 @@ void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)))
|
|||||||
break;
|
break;
|
||||||
case CRYPT_LOG_DEBUG_JSON:
|
case CRYPT_LOG_DEBUG_JSON:
|
||||||
case CRYPT_LOG_DEBUG:
|
case CRYPT_LOG_DEBUG:
|
||||||
if (opt_debug)
|
if (params && params->debug)
|
||||||
fprintf(stdout, "# %s", msg);
|
fprintf(stdout, "# %s", msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -101,7 +97,9 @@ void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)))
|
|||||||
|
|
||||||
void quiet_log(int level, const char *msg, void *usrptr)
|
void quiet_log(int level, const char *msg, void *usrptr)
|
||||||
{
|
{
|
||||||
if (!opt_verbose && (level == CRYPT_LOG_ERROR || level == CRYPT_LOG_NORMAL))
|
struct tools_log_params *params = (struct tools_log_params *)usrptr;
|
||||||
|
|
||||||
|
if ((!params || !params->verbose) && (level == CRYPT_LOG_ERROR || level == CRYPT_LOG_NORMAL))
|
||||||
return;
|
return;
|
||||||
tool_log(level, msg, usrptr);
|
tool_log(level, msg, usrptr);
|
||||||
}
|
}
|
||||||
@@ -117,7 +115,7 @@ static int _dialog(const char *msg, void *usrptr, int default_answer)
|
|||||||
if (block)
|
if (block)
|
||||||
set_int_block(0);
|
set_int_block(0);
|
||||||
|
|
||||||
if (isatty(STDIN_FILENO) && !opt_batch_mode) {
|
if (isatty(STDIN_FILENO)) {
|
||||||
log_std("\nWARNING!\n========\n");
|
log_std("\nWARNING!\n========\n");
|
||||||
log_std("%s\n\nAre you sure? (Type 'yes' in capital letters): ", msg);
|
log_std("%s\n\nAre you sure? (Type 'yes' in capital letters): ", msg);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@@ -156,11 +154,8 @@ void show_status(int errcode)
|
|||||||
{
|
{
|
||||||
char *crypt_error;
|
char *crypt_error;
|
||||||
|
|
||||||
if(!opt_verbose)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!errcode) {
|
if (!errcode) {
|
||||||
log_std(_("Command successful.\n"));
|
log_verbose(_("Command successful."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +175,7 @@ void show_status(int errcode)
|
|||||||
else
|
else
|
||||||
crypt_error = _("unknown error");
|
crypt_error = _("unknown error");
|
||||||
|
|
||||||
log_std(_("Command failed with code %i (%s).\n"), -errcode, crypt_error);
|
log_verbose(_("Command failed with code %i (%s)."), -errcode, crypt_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *uuid_or_device(const char *spec)
|
const char *uuid_or_device(const char *spec)
|
||||||
@@ -352,14 +347,11 @@ static double time_diff(struct timeval *start, struct timeval *end)
|
|||||||
|
|
||||||
static void tools_clear_line(void)
|
static void tools_clear_line(void)
|
||||||
{
|
{
|
||||||
if (opt_progress_frequency)
|
|
||||||
return;
|
|
||||||
/* vt100 code clear line */
|
/* vt100 code clear line */
|
||||||
log_std("\33[2K\r");
|
log_std("\33[2K\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tools_time_progress(uint64_t device_size, uint64_t bytes, uint64_t *start_bytes,
|
static void tools_time_progress(uint64_t device_size, uint64_t bytes, struct tools_progress_params *parms)
|
||||||
struct timeval *start_time, struct timeval *end_time)
|
|
||||||
{
|
{
|
||||||
struct timeval now_time;
|
struct timeval now_time;
|
||||||
unsigned long long mbytes, eta;
|
unsigned long long mbytes, eta;
|
||||||
@@ -367,36 +359,33 @@ static void tools_time_progress(uint64_t device_size, uint64_t bytes, uint64_t *
|
|||||||
int final = (bytes == device_size);
|
int final = (bytes == device_size);
|
||||||
const char *eol, *ustr = "";
|
const char *eol, *ustr = "";
|
||||||
|
|
||||||
if (opt_batch_mode)
|
|
||||||
return;
|
|
||||||
|
|
||||||
gettimeofday(&now_time, NULL);
|
gettimeofday(&now_time, NULL);
|
||||||
if (start_time->tv_sec == 0 && start_time->tv_usec == 0) {
|
if (parms->start_time.tv_sec == 0 && parms->start_time.tv_usec == 0) {
|
||||||
*start_time = now_time;
|
parms->start_time = now_time;
|
||||||
*end_time = now_time;
|
parms->end_time = now_time;
|
||||||
*start_bytes = bytes;
|
parms->start_offset = bytes;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt_progress_frequency) {
|
if (parms->frequency) {
|
||||||
frequency = (double)opt_progress_frequency;
|
frequency = (double)parms->frequency;
|
||||||
eol = "\n";
|
eol = "\n";
|
||||||
} else {
|
} else {
|
||||||
frequency = 0.5;
|
frequency = 0.5;
|
||||||
eol = "";
|
eol = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!final && time_diff(end_time, &now_time) < frequency)
|
if (!final && time_diff(&parms->end_time, &now_time) < frequency)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
*end_time = now_time;
|
parms->end_time = now_time;
|
||||||
|
|
||||||
tdiff = time_diff(start_time, end_time);
|
tdiff = time_diff(&parms->start_time, &parms->end_time);
|
||||||
if (!tdiff)
|
if (!tdiff)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mbytes = bytes / 1024 / 1024;
|
mbytes = bytes / 1024 / 1024;
|
||||||
uib = (double)(bytes - *start_bytes) / tdiff;
|
uib = (double)(bytes - parms->start_offset) / tdiff;
|
||||||
|
|
||||||
/* FIXME: calculate this from last minute only. */
|
/* FIXME: calculate this from last minute only. */
|
||||||
eta = (unsigned long long)(device_size / uib - tdiff);
|
eta = (unsigned long long)(device_size / uib - tdiff);
|
||||||
@@ -412,6 +401,7 @@ static void tools_time_progress(uint64_t device_size, uint64_t bytes, uint64_t *
|
|||||||
ustr = "Ki";
|
ustr = "Ki";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!parms->frequency)
|
||||||
tools_clear_line();
|
tools_clear_line();
|
||||||
if (final)
|
if (final)
|
||||||
log_std("Finished, time %02llu:%02llu.%03llu, "
|
log_std("Finished, time %02llu:%02llu.%03llu, "
|
||||||
@@ -430,14 +420,15 @@ static void tools_time_progress(uint64_t device_size, uint64_t bytes, uint64_t *
|
|||||||
|
|
||||||
int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr)
|
int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr)
|
||||||
{
|
{
|
||||||
static struct timeval start_time = {}, end_time = {};
|
|
||||||
static uint64_t start_offset = 0;
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
struct tools_progress_params *parms = (struct tools_progress_params *)usrptr;
|
||||||
|
|
||||||
tools_time_progress(size, offset, &start_offset, &start_time, &end_time);
|
if (parms && !parms->batch_mode)
|
||||||
|
tools_time_progress(size, offset, parms);
|
||||||
|
|
||||||
check_signal(&r);
|
check_signal(&r);
|
||||||
if (r) {
|
if (r) {
|
||||||
|
if (!parms || !parms->frequency)
|
||||||
tools_clear_line();
|
tools_clear_line();
|
||||||
log_err(_("\nWipe interrupted."));
|
log_err(_("\nWipe interrupted."));
|
||||||
}
|
}
|
||||||
@@ -466,14 +457,15 @@ int tools_is_stdin(const char *key_file)
|
|||||||
|
|
||||||
int tools_reencrypt_progress(uint64_t size, uint64_t offset, void *usrptr)
|
int tools_reencrypt_progress(uint64_t size, uint64_t offset, void *usrptr)
|
||||||
{
|
{
|
||||||
static struct timeval start_time = {}, end_time = {};
|
|
||||||
static uint64_t start_offset = 0;
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
struct tools_progress_params *parms = (struct tools_progress_params *)usrptr;
|
||||||
|
|
||||||
tools_time_progress(size, offset, &start_offset, &start_time, &end_time);
|
if (parms && !parms->batch_mode)
|
||||||
|
tools_time_progress(size, offset, parms);
|
||||||
|
|
||||||
check_signal(&r);
|
check_signal(&r);
|
||||||
if (r) {
|
if (r) {
|
||||||
|
if (!parms || !parms->frequency)
|
||||||
tools_clear_line();
|
tools_clear_line();
|
||||||
log_err(_("\nReencryption interrupted."));
|
log_err(_("\nReencryption interrupted."));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
static const char **action_argv;
|
static const char **action_argv;
|
||||||
static int action_argc;
|
static int action_argc;
|
||||||
|
static struct tools_log_params log_parms;
|
||||||
|
|
||||||
void tools_cleanup(void)
|
void tools_cleanup(void)
|
||||||
{
|
{
|
||||||
@@ -462,6 +463,14 @@ static void basic_options_cb(poptContext popt_context,
|
|||||||
void *data __attribute__((unused)))
|
void *data __attribute__((unused)))
|
||||||
{
|
{
|
||||||
tools_parse_arg_value(popt_context, tool_core_args[key->val].type, tool_core_args + key->val, arg, key->val, NULL);
|
tools_parse_arg_value(popt_context, tool_core_args[key->val].type, tool_core_args + key->val, arg, key->val, NULL);
|
||||||
|
|
||||||
|
switch (key->val) {
|
||||||
|
case OPT_DEBUG_ID:
|
||||||
|
log_parms.debug = true;
|
||||||
|
/* fall through */
|
||||||
|
case OPT_VERBOSE_ID:
|
||||||
|
log_parms.verbose = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
@@ -492,7 +501,7 @@ int main(int argc, const char **argv)
|
|||||||
const char *aname;
|
const char *aname;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
crypt_set_log_callback(NULL, tool_log, NULL);
|
crypt_set_log_callback(NULL, tool_log, &log_parms);
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
@@ -568,14 +577,10 @@ int main(int argc, const char **argv)
|
|||||||
poptGetInvocationName(popt_context));
|
poptGetInvocationName(popt_context));
|
||||||
|
|
||||||
if (ARG_SET(OPT_DEBUG_ID)) {
|
if (ARG_SET(OPT_DEBUG_ID)) {
|
||||||
ARG_SET_TRUE(OPT_VERBOSE_ID);
|
|
||||||
crypt_set_debug_level(CRYPT_DEBUG_ALL);
|
crypt_set_debug_level(CRYPT_DEBUG_ALL);
|
||||||
dbg_version_and_cmd(argc, argv);
|
dbg_version_and_cmd(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
opt_verbose = ARG_SET(OPT_VERBOSE_ID) ? 1 : 0;
|
|
||||||
opt_debug = ARG_SET(OPT_DEBUG_ID) ? 1 : 0;
|
|
||||||
|
|
||||||
r = run_action(action);
|
r = run_action(action);
|
||||||
tools_cleanup();
|
tools_cleanup();
|
||||||
poptFreeContext(popt_context);
|
poptFreeContext(popt_context);
|
||||||
|
|||||||
Reference in New Issue
Block a user