[svn] GnuPG - r4956 - in trunk: agent g10
svn author wk
cvs at cvs.gnupg.org
Tue Mar 17 18:59:37 CET 2009
Author: wk
Date: 2009-03-17 18:59:36 +0100 (Tue, 17 Mar 2009)
New Revision: 4956
Modified:
trunk/agent/ChangeLog
trunk/agent/command.c
trunk/g10/ChangeLog
trunk/g10/call-agent.c
Log:
Enhanced last patch.
Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog 2009-03-17 12:13:32 UTC (rev 4955)
+++ trunk/agent/ChangeLog 2009-03-17 17:59:36 UTC (rev 4956)
@@ -1,6 +1,9 @@
2009-03-17 Werner Koch <wk at g10code.com>
* command.c (cmd_get_passphrase): Break repeat loop on error.
+ Show error message.
+ (cmd_getinfo): Add subcommand "cmd_has_option".
+ (command_has_option): New.
2009-03-17 Daiki Ueno <ueno at unixuser.org>
Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog 2009-03-17 12:13:32 UTC (rev 4955)
+++ trunk/g10/ChangeLog 2009-03-17 17:59:36 UTC (rev 4956)
@@ -1,3 +1,8 @@
+2009-03-17 Werner Koch <wk at g10code.com>
+
+ * call-agent.c (my_percent_plus_escape): Remove.
+ (agent_get_passphrase): Rewrite using percent_plus_escape.
+
2009-03-17 Daiki Ueno <ueno at unixuser.org>
* passphrase.c (passphrase_get): Add extra arg REPEAT and adjust
Modified: trunk/agent/command.c
===================================================================
--- trunk/agent/command.c 2009-03-17 12:13:32 UTC (rev 4955)
+++ trunk/agent/command.c 2009-03-17 17:59:36 UTC (rev 4956)
@@ -105,8 +105,12 @@
} eventcounter;
+
+/* Local prototypes. */
+static int command_has_option (const char *cmd, const char *cmdopt);
+
/* Release the memory buffer MB but first wipe out the used memory. */
static void
@@ -1046,6 +1050,7 @@
char *p;
void *cache_marker;
int opt_data, opt_check, opt_no_ask, opt_repeat = 0;
+ char *repeat_errtext = NULL;
opt_data = has_option (line, "--data");
opt_check = has_option (line, "--check");
@@ -1125,7 +1130,10 @@
plus_to_blank (desc);
next_try:
- rc = agent_get_passphrase (ctrl, &response, desc, prompt, errtext);
+ rc = agent_get_passphrase (ctrl, &response, desc, prompt,
+ repeat_errtext? repeat_errtext:errtext);
+ xfree (repeat_errtext);
+ repeat_errtext = NULL;
if (!rc)
{
int i;
@@ -1147,6 +1155,13 @@
{
xfree (response2);
xfree (response);
+ repeat_errtext = try_percent_escape
+ (_("does not match - try again"), NULL);
+ if (!repeat_errtext)
+ {
+ rc = gpg_error_from_syserror ();
+ break;
+ }
goto next_try;
}
xfree (response2);
@@ -1599,6 +1614,9 @@
socket_name - Return the name of the socket.
ssh_socket_name - Return the name of the ssh socket.
scd_running - Return OK if the SCdaemon is already running.
+
+ cmd_has_option CMD OPT
+ - Returns OK if the command CMD implements the option OPT.
*/
static int
cmd_getinfo (assuan_context_t ctx, char *line)
@@ -1639,6 +1657,38 @@
{
rc = agent_scd_check_running ()? 0 : gpg_error (GPG_ERR_GENERAL);
}
+ else if (!strncmp (line, "cmd_has_option", 14)
+ && (line[14] == ' ' || line[14] == '\t' || !line[14]))
+ {
+ char *cmd, *cmdopt;
+ line += 14;
+ while (*line == ' ' || *line == '\t')
+ line++;
+ if (!*line)
+ rc = gpg_error (GPG_ERR_MISSING_VALUE);
+ else
+ {
+ cmd = line;
+ while (*line && (*line != ' ' && *line != '\t'))
+ line++;
+ if (!*line)
+ rc = gpg_error (GPG_ERR_MISSING_VALUE);
+ else
+ {
+ *line++ = 0;
+ while (*line == ' ' || *line == '\t')
+ line++;
+ if (!*line)
+ rc = gpg_error (GPG_ERR_MISSING_VALUE);
+ else
+ {
+ cmdopt = line;
+ if (!command_has_option (cmd, cmdopt))
+ rc = gpg_error (GPG_ERR_GENERAL);
+ }
+ }
+ }
+ }
else
rc = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT");
return rc;
@@ -1765,6 +1815,20 @@
}
+/* Return true if the commznd CMD implements the option OPT. */
+static int
+command_has_option (const char *cmd, const char *cmdopt)
+{
+ if (!strcmp (cmd, "GET_PASSPHRASE"))
+ {
+ if (!strcmp (cmdopt, "repeat"))
+ return 1;
+ }
+
+ return 0;
+}
+
+
/* Tell the assuan library about our commands */
static int
register_commands (assuan_context_t ctx)
Modified: trunk/g10/call-agent.c
===================================================================
--- trunk/g10/call-agent.c 2009-03-17 12:13:32 UTC (rev 4955)
+++ trunk/g10/call-agent.c 2009-03-17 17:59:36 UTC (rev 4956)
@@ -144,30 +144,7 @@
return buffer;
}
-/* Copy the text ATEXT into the buffer P and do plus '+' and percent
- escaping. Note that the provided buffer needs to be 3 times the
- size of ATEXT plus 1. Returns a pointer to the leading Nul in P. */
-static char *
-my_percent_plus_escape (char *p, const char *atext)
-{
- const unsigned char *s;
- for (s=atext; *s; s++)
- {
- if (*s < ' ' || *s == '+' || *s == '%')
- {
- snprintf (p, 4, "%%%02X", *s);
- p += 3;
- }
- else if (*s == ' ')
- *p++ = '+';
- else
- *p++ = *s;
- }
- *p = 0;
- return p;
-}
-
/* Take a 20 byte hexencoded string and put it into the the provided
20 byte buffer FPR in binary format. */
static int
@@ -878,8 +855,11 @@
char **r_passphrase)
{
int rc;
- char *line, *p;
- char cmd[] = "GET_PASSPHRASE --data --repeat=%d -- ";
+ char line[ASSUAN_LINELENGTH];
+ char *arg1 = NULL;
+ char *arg2 = NULL;
+ char *arg3 = NULL;
+ char *arg4 = NULL;
membuf_t data;
*r_passphrase = NULL;
@@ -888,42 +868,38 @@
if (rc)
return rc;
- /* We allocate 3 times the needed space for the texts so that
- there is enough space for escaping. */
- line = xtrymalloc ( strlen (cmd) + sizeof(repeat) + 1
- + (cache_id? 3*strlen (cache_id): 1) + 1
- + (err_msg? 3*strlen (err_msg): 1) + 1
- + (prompt? 3*strlen (prompt): 1) + 1
- + (desc_msg? 3*strlen (desc_msg): 1) + 1
- + 1);
- if (!line)
- return gpg_error_from_syserror ();
+ /* Check that the gpg-agent understands the repeat option. */
+ if (assuan_transact (agent_ctx,
+ "GETINFO cmd_has_option GET_PASSPHRASE repeat",
+ NULL, NULL, NULL, NULL, NULL, NULL))
+ return gpg_error (GPG_ERR_NOT_SUPPORTED);
- p = line + sprintf (line, cmd, repeat);
if (cache_id && *cache_id)
- p = my_percent_plus_escape (p, cache_id);
- else
- *p++ = 'X';
- *p++ = ' ';
-
+ if (!(arg1 = percent_plus_escape (cache_id)))
+ goto no_mem;
if (err_msg && *err_msg)
- p = my_percent_plus_escape (p, err_msg);
- else
- *p++ = 'X';
- *p++ = ' ';
-
+ if (!(arg2 = percent_plus_escape (err_msg)))
+ goto no_mem;
if (prompt && *prompt)
- p = my_percent_plus_escape (p, prompt);
- else
- *p++ = 'X';
- *p++ = ' ';
-
+ if (!(arg3 = percent_plus_escape (prompt)))
+ goto no_mem;
if (desc_msg && *desc_msg)
- p = my_percent_plus_escape (p, desc_msg);
- else
- *p++ = 'X';
- *p = 0;
+ if (!(arg4 = percent_plus_escape (desc_msg)))
+ goto no_mem;
+ snprintf (line, DIM(line)-1,
+ "GET_PASSPHRASE --data --repeat=%d -- %s %s %s %s",
+ repeat,
+ arg1? arg1:"X",
+ arg2? arg2:"X",
+ arg3? arg3:"X",
+ arg4? arg4:"X");
+ line[DIM(line)-1] = 0;
+ xfree (arg1);
+ xfree (arg2);
+ xfree (arg3);
+ xfree (arg4);
+
init_membuf_secure (&data, 64);
rc = assuan_transact (agent_ctx, line,
membuf_data_cb, &data,
@@ -938,8 +914,14 @@
if (!*r_passphrase)
rc = gpg_error_from_syserror ();
}
- xfree (line);
return rc;
+ no_mem:
+ rc = gpg_error_from_syserror ();
+ xfree (arg1);
+ xfree (arg2);
+ xfree (arg3);
+ xfree (arg4);
+ return rc;
}
More information about the Gnupg-commits
mailing list