diff options
author | Werner Koch <wk@gnupg.org> | 2010-10-14 10:32:55 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2010-10-14 10:32:55 +0200 |
commit | fd19a84c805099c4f672a3d0968c87d305c647a9 (patch) | |
tree | e90ffb4e55c30b71518eff3ca26aab594056c755 /tools | |
parent | More agent support for gpg. (diff) | |
download | gnupg2-fd19a84c805099c4f672a3d0968c87d305c647a9.tar.xz gnupg2-fd19a84c805099c4f672a3d0968c87d305c647a9.zip |
Some tweaks to the agent startup.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/ChangeLog | 8 | ||||
-rw-r--r-- | tools/gpg-connect-agent.c | 127 | ||||
-rw-r--r-- | tools/gpgconf-comp.c | 30 | ||||
-rw-r--r-- | tools/gpgconf.c | 3 |
4 files changed, 21 insertions, 147 deletions
diff --git a/tools/ChangeLog b/tools/ChangeLog index f841ac13a..de148ba56 100644 --- a/tools/ChangeLog +++ b/tools/ChangeLog @@ -1,3 +1,11 @@ +2010-10-14 Werner Koch <wk@g10code.com> + + * gpg-connect-agent.c (start_agent): Rewrite using the + start_new_gpg_agent function. + + * gpgconf-comp.c (gpg_agent_runtime_change): Use gpg-connect-agent + on all platforms. + 2010-10-06 Werner Koch <wk@g10code.com> * watchgnupg.c (print_version): Add option --time-only. diff --git a/tools/gpg-connect-agent.c b/tools/gpg-connect-agent.c index 8210df598..652f288c5 100644 --- a/tools/gpg-connect-agent.c +++ b/tools/gpg-connect-agent.c @@ -2156,131 +2156,28 @@ read_and_print_response (assuan_context_t ctx, int withhash, int *r_goterr) static assuan_context_t start_agent (void) { - int rc = 0; - char *infostr, *p; + gpg_error_t err; assuan_context_t ctx; session_env_t session_env; - infostr = getenv ("GPG_AGENT_INFO"); - if (!infostr || !*infostr) - { - char *sockname; - - rc = assuan_new (&ctx); - if (rc) - { - log_error ("assuan_new failed: %s\n", gpg_strerror (rc)); - exit (1); - } - - /* Check whether we can connect at the standard socket. */ - sockname = make_filename (opt.homedir, "S.gpg-agent", NULL); - rc = assuan_socket_connect (ctx, sockname, 0, 0); - -#ifdef HAVE_W32_SYSTEM - /* If we failed to connect under Windows, we fire up the agent. */ - if (gpg_err_code (rc) == GPG_ERR_ASS_CONNECT_FAILED) - { - const char *agent_program; - const char *argv[3]; - int save_rc = rc; - - if (opt.verbose) - log_info (_("no running gpg-agent - starting one\n")); - agent_program = gnupg_module_name (GNUPG_MODULE_NAME_AGENT); - - argv[0] = "--daemon"; - argv[1] = "--use-standard-socket"; - argv[2] = NULL; - - rc = gnupg_spawn_process_detached (agent_program, argv, NULL); - if (rc) - log_debug ("failed to start agent `%s': %s\n", - agent_program, gpg_strerror (rc)); - else - { - /* Give the agent some time to prepare itself. */ - gnupg_sleep (3); - /* Now try again to connect the agent. */ - rc = assuan_new (&ctx); - if (rc) - { - log_error ("assuan_new failed: %s\n", gpg_strerror (rc)); - exit (1); - } - - rc = assuan_socket_connect (ctx, sockname, 0, 0); - } - if (rc) - rc = save_rc; - } -#endif /*HAVE_W32_SYSTEM*/ - xfree (sockname); - } - else - { - int prot; - int pid; - - infostr = xstrdup (infostr); - if ( !(p = strchr (infostr, PATHSEP_C)) || p == infostr) - { - log_error (_("malformed GPG_AGENT_INFO environment variable\n")); - xfree (infostr); - exit (1); - } - *p++ = 0; - pid = atoi (p); - while (*p && *p != PATHSEP_C) - p++; - prot = *p? atoi (p+1) : 0; - if (prot != 1) - { - log_error (_("gpg-agent protocol version %d is not supported\n"), - prot); - xfree (infostr); - exit (1); - } - - rc = assuan_new (&ctx); - if (rc) - { - log_error ("assuan_new failed: %s\n", gpg_strerror (rc)); - exit (1); - } - - rc = assuan_socket_connect (ctx, infostr, pid, 0); - xfree (infostr); - } - - if (rc) - { - log_error ("can't connect to the agent: %s\n", gpg_strerror (rc)); - exit (1); - } - - if (opt.verbose) - log_info ("connection to agent established\n"); - - rc = assuan_transact (ctx, "RESET", NULL, NULL, NULL, NULL, NULL, NULL); - if (rc) - { - log_error (_("error sending %s command: %s\n"), "RESET", - gpg_strerror (rc)); - exit (1); - } - session_env = session_env_new (); if (!session_env) log_fatal ("error allocating session environment block: %s\n", strerror (errno)); - rc = send_pinentry_environment (ctx, GPG_ERR_SOURCE_DEFAULT, - NULL, NULL, session_env); + err = start_new_gpg_agent (&ctx, + GPG_ERR_SOURCE_DEFAULT, + opt.homedir, + NULL, + NULL, NULL, + session_env, + !opt.quiet, 0, + NULL, NULL); + session_env_release (session_env); - if (rc) + if (err) { - log_error (_("error sending standard options: %s\n"), gpg_strerror (rc)); + log_error (_("error sending standard options: %s\n"), gpg_strerror (err)); exit (1); } diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c index 1718a08a5..d0372469d 100644 --- a/tools/gpgconf-comp.c +++ b/tools/gpgconf-comp.c @@ -1032,35 +1032,6 @@ struct error_line_s static void gpg_agent_runtime_change (void) { -#ifndef HAVE_W32_SYSTEM - char *agent = getenv ("GPG_AGENT_INFO"); - char *pid_str; - unsigned long pid_long; - char *tail; - pid_t pid; - - if (!agent) - return; - - pid_str = strchr (agent, ':'); - if (!pid_str) - return; - - pid_str++; - errno = 0; - pid_long = strtoul (pid_str, &tail, 0); - if (errno || (*tail != ':' && *tail != '\0')) - return; - - pid = (pid_t) pid_long; - - /* Check for overflow. */ - if (pid_long != (unsigned long) pid) - return; - - /* Ignore any errors here. */ - kill (pid, SIGHUP); -#else gpg_error_t err; const char *pgmname; const char *argv[2]; @@ -1077,7 +1048,6 @@ gpg_agent_runtime_change (void) gc_error (0, 0, "error running `%s%s': %s", pgmname, " reloadagent", gpg_strerror (err)); gnupg_release_process (pid); -#endif /*!HAVE_W32_SYSTEM*/ } diff --git a/tools/gpgconf.c b/tools/gpgconf.c index 222bc48f8..d6c333792 100644 --- a/tools/gpgconf.c +++ b/tools/gpgconf.c @@ -50,7 +50,6 @@ enum cmd_and_opt_values aCheckConfig, aListDirs, aReload - }; @@ -72,7 +71,7 @@ static ARGPARSE_OPTS opts[] = N_("list global configuration file") }, { aCheckConfig, "check-config", 256, N_("check global configuration file") }, - { aReload, "reload", 256, "@" }, + { aReload, "reload", 256, N_("reload all or a given component")}, { 301, NULL, 0, N_("@\nOptions:\n ") }, |