mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-15 04:40:05 +01:00
Allow special "-" (standard input) keyfile hangdling even for TCRYPT devices.
Fail if there are more keyfiles specified for non-TCRYPT device. Fixes issue#269.
This commit is contained in:
@@ -28,6 +28,7 @@ static const char *opt_hash = NULL;
|
||||
static int opt_verify_passphrase = 0;
|
||||
|
||||
static const char *opt_key_file = NULL;
|
||||
static const char *opt_keyfile_stdin = NULL;
|
||||
static int opt_keyfiles_count = 0;
|
||||
static const char *opt_keyfiles[MAX_KEYFILES];
|
||||
|
||||
@@ -236,11 +237,14 @@ static int tcrypt_load(struct crypt_device *cd, struct crypt_params_tcrypt *para
|
||||
{
|
||||
int r, tries = opt_tries, eperm = 0;
|
||||
|
||||
if (opt_keyfile_stdin)
|
||||
tries = 1;
|
||||
|
||||
do {
|
||||
/* TCRYPT header is encrypted, get passphrase now */
|
||||
r = tools_get_key(_("Enter passphrase: "),
|
||||
CONST_CAST(char**)¶ms->passphrase,
|
||||
¶ms->passphrase_size, 0, 0, NULL, opt_timeout,
|
||||
¶ms->passphrase_size, 0, 0, opt_keyfile_stdin, opt_timeout,
|
||||
_verify_passphrase(0), 0, cd);
|
||||
if (r < 0)
|
||||
continue;
|
||||
@@ -1529,7 +1533,7 @@ int main(int argc, const char **argv)
|
||||
poptContext popt_context;
|
||||
struct action_type *action;
|
||||
const char *aname;
|
||||
int r;
|
||||
int r, total_keyfiles = 0;
|
||||
|
||||
crypt_set_log_callback(NULL, tool_log, NULL);
|
||||
|
||||
@@ -1543,11 +1547,15 @@ int main(int argc, const char **argv)
|
||||
|
||||
while((r = poptGetNextOpt(popt_context)) > 0) {
|
||||
unsigned long long ull_value;
|
||||
char *endp;
|
||||
char *endp, *kf;
|
||||
|
||||
if (r == 5) {
|
||||
if (opt_keyfiles_count < MAX_KEYFILES)
|
||||
opt_keyfiles[opt_keyfiles_count++] = poptGetOptArg(popt_context);
|
||||
kf = poptGetOptArg(popt_context);
|
||||
if (tools_is_stdin(kf))
|
||||
opt_keyfile_stdin = kf;
|
||||
else if (opt_keyfiles_count < MAX_KEYFILES)
|
||||
opt_keyfiles[opt_keyfiles_count++] = kf;
|
||||
total_keyfiles++;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1699,6 +1707,10 @@ int main(int argc, const char **argv)
|
||||
_("Negative number for option not permitted."),
|
||||
poptGetInvocationName(popt_context));
|
||||
|
||||
if (total_keyfiles > 1 && strcmp(opt_type, "tcrypt"))
|
||||
usage(popt_context, EXIT_FAILURE, _("Only one --key-file argument is allowed."),
|
||||
poptGetInvocationName(popt_context));
|
||||
|
||||
if (opt_random && opt_urandom)
|
||||
usage(popt_context, EXIT_FAILURE, _("Only one of --use-[u]random options is allowed."),
|
||||
poptGetInvocationName(popt_context));
|
||||
|
||||
Reference in New Issue
Block a user