aboutsummaryrefslogtreecommitdiffstats
path: root/agent/command.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2002-01-19 20:59:19 +0000
committerWerner Koch <[email protected]>2002-01-19 20:59:19 +0000
commiteac306fc907a0c7c081b2508d72843fffa56b29f (patch)
tree3549b77f290a1c68a4dae21dc3dd631716e28414 /agent/command.c
parent* sysutils.c: New. This is the misc.c file from gnupg 1.0.6 with (diff)
downloadgnupg-eac306fc907a0c7c081b2508d72843fffa56b29f.tar.gz
gnupg-eac306fc907a0c7c081b2508d72843fffa56b29f.zip
* gpg-agent.c (main): Disable core dumps.
* cache.c: New. * command.c (cmd_get_passphrase): Use the cache. (cmd_clear_passphrase): Ditto. * gpg-agent.c: Removed unused cruft and implement the socket based server. (my_strusage): Take bug report address from configure.ac. * command.c (start_command_handler): Add an argument to start as regular server. (start_command_handler): Enable Assuan logging.
Diffstat (limited to 'agent/command.c')
-rw-r--r--agent/command.c93
1 files changed, 78 insertions, 15 deletions
diff --git a/agent/command.c b/agent/command.c
index bde3835ab..dae6c34e6 100644
--- a/agent/command.c
+++ b/agent/command.c
@@ -281,20 +281,74 @@ static int
cmd_get_passphrase (ASSUAN_CONTEXT ctx, char *line)
{
int rc;
+ const char *pw;
char *response;
- char *desc, *prompt, *errtext;
-
- /* FIXME: Parse that stuff */
- desc = "We need a passphrase";
- prompt = NULL;
- errtext = NULL;
+ char *cacheid = NULL, *desc = NULL, *prompt = NULL, *errtext = NULL;
+ char *p;
- rc = agent_get_passphrase (&response, desc, prompt, errtext);
- if (!rc)
+ /* parse the stuff */
+ for (p=line; *p == ' '; p++)
+ ;
+ cacheid = p;
+ p = strchr (cacheid, ' ');
+ if (p)
+ {
+ *p++ = 0;
+ while (*p == ' ')
+ p++;
+ errtext = p;
+ p = strchr (errtext, ' ');
+ if (p)
+ {
+ *p++ = 0;
+ while (*p == ' ')
+ p++;
+ prompt = p;
+ p = strchr (prompt, ' ');
+ if (p)
+ {
+ *p++ = 0;
+ while (*p == ' ')
+ p++;
+ desc = p;
+ p = strchr (desc, ' ');
+ if (p)
+ *p = 0; /* ignore garbage */
+ }
+ }
+ }
+ if (!cacheid || !*cacheid || strlen (cacheid) > 50)
+ return set_error (Parameter_Error, "invalid length of cacheID");
+ if (!desc)
+ return set_error (Parameter_Error, "no description given");
+
+ if (!strcmp (cacheid, "X"))
+ cacheid = NULL;
+ if (!strcmp (errtext, "X"))
+ errtext = NULL;
+ if (!strcmp (prompt, "X"))
+ prompt = NULL;
+ if (!strcmp (desc, "X"))
+ desc = NULL;
+
+ /* Note: we store the hexified versions in the cache. */
+ pw = cacheid ? agent_get_cache (cacheid) : NULL;
+ if (pw)
{
assuan_begin_confidential (ctx);
- rc = assuan_set_okay_line (ctx, response);
- xfree (response);
+ rc = assuan_set_okay_line (ctx, pw);
+ }
+ else
+ {
+ rc = agent_get_passphrase (&response, desc, prompt, errtext);
+ if (!rc)
+ {
+ if (cacheid)
+ agent_put_cache (cacheid, response, 0);
+ assuan_begin_confidential (ctx);
+ rc = assuan_set_okay_line (ctx, response);
+ xfree (response);
+ }
}
return map_to_assuan_status (rc);
@@ -310,12 +364,21 @@ cmd_get_passphrase (ASSUAN_CONTEXT ctx, char *line)
static int
cmd_clear_passphrase (ASSUAN_CONTEXT ctx, char *line)
{
- int rc;
-
- /* fixme: no caching yet. so return with OK */
- rc = 0;
+ char *cacheid = NULL;
+ char *p;
- return map_to_assuan_status (rc);
+ /* parse the stuff */
+ for (p=line; *p == ' '; p++)
+ ;
+ cacheid = p;
+ p = strchr (cacheid, ' ');
+ if (p)
+ *p = 0; /* ignore garbage */
+ if (!cacheid || !*cacheid || strlen (cacheid) > 50)
+ return set_error (Parameter_Error, "invalid length of cacheID");
+
+ agent_put_cache (cacheid, NULL, 0);
+ return 0;
}