diff --git a/agent/ChangeLog b/agent/ChangeLog index c718380de..c19193b23 100644 --- a/agent/ChangeLog +++ b/agent/ChangeLog @@ -1,3 +1,12 @@ +2002-09-25 Werner Koch + + * 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 * gpg-agent.c (create_private_keys_directory) diff --git a/agent/agent.h b/agent/agent.h index 51ab19800..24267b06a 100644 --- a/agent/agent.h +++ b/agent/agent.h @@ -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); diff --git a/agent/cache.c b/agent/cache.c index 4b18ad30f..8f5bf9d3d 100644 --- a/agent/cache.c +++ b/agent/cache.c @@ -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 diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index c99fc4afc..3c823e5f6 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -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; diff --git a/agent/query.c b/agent/query.c index c461a55ce..ee18a1483 100644 --- a/agent/query.c +++ b/agent/query.c @@ -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 )