Add more password agent information

Add an (optional) "Id" key in the password agent .ask files. The Id is
supposed to be a simple string in "<subsystem>:<target>" form which
is used to provide more information on what the requested passphrase
is to be used for (which e.g. allows an agent to only react to cryptsetup
requests).

(v2: rebased, fixed indentation, escape name, use strappenda)
This commit is contained in:
David Härdeman
2014-04-24 09:23:54 +02:00
committed by Lennart Poettering
parent 0d522a7a05
commit 9fa1de965a
4 changed files with 34 additions and 9 deletions
+12 -2
View File
@@ -257,6 +257,8 @@ static int get_password(const char *name, usec_t until, bool accept_cached, char
int r;
char **p;
_cleanup_free_ char *text = NULL;
_cleanup_free_ char *escaped_name = NULL;
char *id;
assert(name);
assert(passwords);
@@ -264,7 +266,13 @@ static int get_password(const char *name, usec_t until, bool accept_cached, char
if (asprintf(&text, "Please enter passphrase for disk %s!", name) < 0)
return log_oom();
r = ask_password_auto(text, "drive-harddisk", until, accept_cached, passwords);
escaped_name = cescape(name);
if (!escaped_name)
return log_oom();
id = strappenda("cryptsetup:", escaped_name);
r = ask_password_auto(text, "drive-harddisk", id, until, accept_cached, passwords);
if (r < 0) {
log_error("Failed to query password: %s", strerror(-r));
return r;
@@ -278,7 +286,9 @@ static int get_password(const char *name, usec_t until, bool accept_cached, char
if (asprintf(&text, "Please enter passphrase for disk %s! (verification)", name) < 0)
return log_oom();
r = ask_password_auto(text, "drive-harddisk", until, false, &passwords2);
id = strappenda("cryptsetup-verification:", escaped_name);
r = ask_password_auto(text, "drive-harddisk", id, until, false, &passwords2);
if (r < 0) {
log_error("Failed to query verification password: %s", strerror(-r));
return r;