* gpg-agent.c (handle_signal): Flush cache on SIGHUP.

* cache.c (agent_flush_cache): New.
* gpg-agent.c, agent.h: Add --keep-display and --keep-tty.
* query.c (start_pinentry): Implement them.  The option passing
needs more thoughts.
This commit is contained in:
Werner Koch 2002-09-26 07:10:56 +00:00
parent 48d55024e2
commit 2d432afff6
5 changed files with 54 additions and 6 deletions

View File

@ -1,3 +1,12 @@
2002-09-25 Werner Koch <wk@gnupg.org>
* gpg-agent.c (handle_signal): Flush cache on SIGHUP.
* cache.c (agent_flush_cache): New.
* gpg-agent.c, agent.h: Add --keep-display and --keep-tty.
* query.c (start_pinentry): Implement them. The option passing
needs more thoughts.
2002-09-09 Werner Koch <wk@gnupg.org>
* gpg-agent.c (create_private_keys_directory)

View File

@ -48,7 +48,8 @@ struct {
int running_detached; /* we are running detached from the tty. */
int ignore_cache_for_signing;
int keep_tty; /* don't switch the TTY (for pinentry) on request */
int keep_display; /* don't switch the DISPLAY (for pinentry) on request */
} opt;
@ -126,6 +127,7 @@ int agent_get_confirmation (const char *desc, const char *ok,
const char *cancel);
/*-- cache.c --*/
void agent_flush_cache (void);
int agent_put_cache (const char *key, const char *data, int ttl);
const char *agent_get_cache (const char *key, void **cache_id);
void agent_unlock_cache_entry (void **cache_id);

View File

@ -150,6 +150,35 @@ housekeeping (void)
}
void
agent_flush_cache (void)
{
ITEM r;
if (DBG_CACHE)
log_debug ("agent_flush_cache\n");
for (r=thecache; r; r = r->next)
{
if (!r->lockcount && r->pw)
{
if (DBG_CACHE)
log_debug (" flushing `%s'\n", r->key);
release_data (r->pw);
r->pw = NULL;
r->accessed = 0;
}
else if (r->lockcount && r->pw)
{
if (DBG_CACHE)
log_debug (" marked `%s' for flushing\n", r->key);
r->accessed = 0;
r->ttl = 0;
}
}
}
/* Store DATA of length DATALEN in the cache under KEY and mark it
with a maximum lifetime of TTL seconds. If there is already data

View File

@ -80,6 +80,8 @@ enum cmd_and_opt_values
oDisablePth,
oIgnoreCacheForSigning,
oKeepTTY,
oKeepDISPLAY,
aTest };
@ -116,7 +118,9 @@ static ARGPARSE_OPTS opts[] = {
"|N|expire cached PINs after N seconds"},
{ oIgnoreCacheForSigning, "ignore-cache-for-signing", 0,
"do not use the PIN cache when signing"},
{ oKeepTTY, "keep-tty", 0, N_("ignore requests to change the TTY")},
{ oKeepDISPLAY, "keep-display",
0, N_("ignore requests to change the X display")},
{0}
};
@ -413,6 +417,8 @@ main (int argc, char **argv )
case oDefCacheTTL: opt.def_cache_ttl = pargs.r.ret_ulong; break;
case oIgnoreCacheForSigning: opt.ignore_cache_for_signing = 1; break;
case oKeepTTY: opt.keep_tty = 1; break;
case oKeepDISPLAY: opt.keep_display = 1; break;
default : pargs.err = configfp? 1:2; break;
}
@ -780,7 +786,9 @@ handle_signal (int signo)
switch (signo)
{
case SIGHUP:
log_info ("SIGHUP received - re-reading configuration\n");
log_info ("SIGHUP received - "
"re-reading configuration and flushing cache\n");
agent_flush_cache ();
reread_configuration ();
break;

View File

@ -113,7 +113,7 @@ start_pinentry (void)
/* FIXME: We must do this thread specific */
argv[0] = pgmname;
if (opt.display)
if (opt.display && !opt.keep_display)
{
argv[1] = "--display";
argv[2] = opt.display;
@ -150,7 +150,7 @@ start_pinentry (void)
NULL, NULL, NULL, NULL, NULL, NULL);
if (rc)
return unlock_pinentry (map_assuan_err (rc));
if (opt.ttyname)
if (opt.ttyname && !opt.keep_tty)
{
char *optstr;
if (asprintf (&optstr, "OPTION ttyname=%s", opt.ttyname) < 0 )
@ -161,7 +161,7 @@ start_pinentry (void)
if (rc)
return unlock_pinentry (map_assuan_err (rc));
}
if (opt.ttytype)
if (opt.ttytype && !opt.keep_tty)
{
char *optstr;
if (asprintf (&optstr, "OPTION ttytype=%s", opt.ttytype) < 0 )