static int get_password(const char *vol, const char *src, usec_t until, bool accept_cached, char ***ret) {
_cleanup_free_ char *description = NULL, *name_buffer = NULL, *mount_point = NULL, *maj_min = NULL, *text = NULL, *escaped_name = NULL;
- _cleanup_strv_free_ char **passwords = NULL, **passwords2 = NULL;
+ _cleanup_strv_free_erase_ char **passwords = NULL;
const char *name = NULL;
char **p, *id;
int r = 0;
id = strjoina("cryptsetup:", escaped_name);
- r = ask_password_auto(text, "drive-harddisk", id, "cryptsetup", until, ASK_PASSWORD_PUSH_CACHE|(accept_cached ? ASK_PASSWORD_ACCEPT_CACHED : 0), &passwords);
+ r = ask_password_auto(text, "drive-harddisk", id, "cryptsetup", until,
+ ASK_PASSWORD_PUSH_CACHE | (accept_cached*ASK_PASSWORD_ACCEPT_CACHED),
+ &passwords);
if (r < 0)
return log_error_errno(r, "Failed to query password: %m");
if (arg_verify) {
+ _cleanup_strv_free_erase_ char **passwords2 = NULL;
+
assert(strv_length(passwords) == 1);
- if (asprintf(&text, "Please enter passphrase for disk %s! (verification)", name) < 0) {
- r = log_oom();
- goto finish;
- }
+ if (asprintf(&text, "Please enter passphrase for disk %s! (verification)", name) < 0)
+ return log_oom();
id = strjoina("cryptsetup-verification:", escaped_name);
r = ask_password_auto(text, "drive-harddisk", id, "cryptsetup", until, ASK_PASSWORD_PUSH_CACHE, &passwords2);
- if (r < 0) {
- log_error_errno(r, "Failed to query verification password: %m");
- goto finish;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to query verification password: %m");
assert(strv_length(passwords2) == 1);
if (!streq(passwords[0], passwords2[0])) {
log_warning("Passwords did not match, retrying.");
- r = -EAGAIN;
- goto finish;
+ return -EAGAIN;
}
}
/* Pad password if necessary */
c = new(char, arg_key_size);
- if (!c) {
- r = -ENOMEM;
- goto finish;
- }
+ if (!c)
+ return log_oom();
strncpy(c, *p, arg_key_size);
free(*p);
*ret = passwords;
passwords = NULL;
- r = 0;
-
-finish:
- strv_erase(passwords);
- strv_erase(passwords2);
-
- return r;
+ return 0;
}
static int attach_tcrypt(
}
for (tries = 0; arg_tries == 0 || tries < arg_tries; tries++) {
- _cleanup_strv_free_ char **passwords = NULL;
+ _cleanup_strv_free_erase_ char **passwords = NULL;
if (!key_file) {
k = get_password(argv[2], argv[3], until, tries == 0 && !arg_verify, &passwords);
arg_header ? argv[3] : NULL,
passwords,
flags);
- strv_erase(passwords);
if (k >= 0)
break;
else if (k == -EAGAIN) {
msg2 = strjoina(draw_special_char(DRAW_TRIANGULAR_BULLET), " Please enter new root password again: ");
for (;;) {
- _cleanup_free_ char *a = NULL, *b = NULL;
+ _cleanup_string_free_erase_ char *a = NULL, *b = NULL;
r = ask_password_tty(msg1, NULL, 0, 0, NULL, &a);
if (r < 0)
}
r = ask_password_tty(msg2, NULL, 0, 0, NULL, &b);
- if (r < 0) {
- string_erase(a);
+ if (r < 0)
return log_error_errno(r, "Failed to query root password: %m");
- }
if (!streq(a, b)) {
log_error("Entered passwords did not match, please try again.");
- string_erase(a);
- string_erase(b);
continue;
}
- string_erase(b);
arg_root_password = a;
a = NULL;
break;
}
if (arg_plymouth) {
- _cleanup_strv_free_ char **passwords = NULL;
+ _cleanup_strv_free_erase_ char **passwords = NULL;
r = ask_password_plymouth(message, not_after, accept_cached ? ASK_PASSWORD_ACCEPT_CACHED : 0, filename, &passwords);
if (r >= 0) {
}
}
- strv_erase(passwords);
-
} else {
- _cleanup_free_ char *password = NULL;
+ _cleanup_string_free_erase_ char *password = NULL;
int tty_fd = -1;
if (arg_console) {
strcpy(packet + 1, password);
}
}
-
- string_erase(password);
}
if (IN_SET(r, -ETIME, -ENOENT)) {