1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

Reworked passing of envars to Pinentry.

This commit is contained in:
Werner Koch 2009-07-07 10:02:41 +00:00
parent 58e6e28bb1
commit f6f5430e50
31 changed files with 1169 additions and 352 deletions

View file

@ -1,3 +1,15 @@
2009-07-07 Werner Koch <wk@g10code.com>
* gpgsm.h: Include session-env.h.
(opt): Add field SESSION_ENV. Remove obsolete fields.
* server.c (option_handler): Rewrite setting of option fields.
Replace strdup by xtrystrdup.
* gpgsm.c (set_opt_session_env): New.
(main): Use it for oDisplay, oTTYname, oTTYtype and oXauthority.
* call-agent.c (start_agent): Adjust start_new_gpg_agent for
changed args.
* misc.c (setup_pinentry_env): Use new session_env stuff.
2009-07-02 Werner Koch <wk@g10code.com>
* certreqgen-ui.c (gpgsm_gencertreq_tty): Allow using a key from a

View file

@ -85,9 +85,8 @@ start_agent (ctrl_t ctrl)
GPG_ERR_SOURCE_DEFAULT,
opt.homedir,
opt.agent_program,
opt.display, opt.ttyname, opt.ttytype,
opt.lc_ctype, opt.lc_messages,
opt.xauthority, opt.pinentry_user_data,
opt.session_env,
opt.verbose, DBG_ASSUAN,
gpgsm_status2, ctrl);

View file

@ -196,7 +196,7 @@ static ARGPARSE_OPTS opts[] = {
ARGPARSE_c (aListSecretKeys, "list-secret-keys", N_("list secret keys")),
ARGPARSE_c (aListChain, "list-chain", N_("list certificate chain")),
ARGPARSE_c (aFingerprint, "fingerprint", N_("list keys and fingerprints")),
ARGPARSE_c (aKeygen, "gen-key", "@"),
ARGPARSE_c (aKeygen, "gen-key", N_("generate a new key pair")),
ARGPARSE_c (aDeleteKey, "delete-keys",
N_("remove keys from the public keyring")),
ARGPARSE_c (aSendKeys, "send-keys", N_("export keys to a key server")),
@ -614,6 +614,18 @@ wrong_args (const char *text)
}
static void
set_opt_session_env (const char *name, const char *value)
{
gpg_error_t err;
err = session_env_setenv (opt.session_env, name, value);
if (err)
log_fatal ("error setting session environment: %s\n",
gpg_strerror (err));
}
/* Setup the debugging. With a DEBUG_LEVEL of NULL only the active
debug flags are propagated to the subsystems. With DEBUG_LEVEL
set, a specific set of debug flags is set; and individual debugging
@ -890,6 +902,11 @@ main ( int argc, char **argv)
create_dotlock (NULL); /* register locking cleanup */
opt.session_env = session_env_new ();
if (!opt.session_env)
log_fatal ("error allocating session environment block: %s\n",
strerror (errno));
/* Note: If you change this default cipher algorithm , please
remember to update the Gpgconflist entry as well. */
opt.def_cipher_algoid = "3DES"; /*des-EDE3-CBC*/
@ -943,7 +960,7 @@ main ( int argc, char **argv)
memset (&ctrl, 0, sizeof ctrl);
gpgsm_init_default_ctrl (&ctrl);
ctrl.no_server = 1;
ctrl.status_fd = -1; /* not status output */
ctrl.status_fd = -1; /* No status output. */
ctrl.autodetect_encoding = 1;
/* Set the default option file */
@ -1208,12 +1225,23 @@ main ( int argc, char **argv)
case oNoOptions: break; /* no-options */
case oHomedir: opt.homedir = pargs.r.ret_str; break;
case oAgentProgram: opt.agent_program = pargs.r.ret_str; break;
case oDisplay: opt.display = xstrdup (pargs.r.ret_str); break;
case oTTYname: opt.ttyname = xstrdup (pargs.r.ret_str); break;
case oTTYtype: opt.ttytype = xstrdup (pargs.r.ret_str); break;
case oDisplay:
set_opt_session_env ("DISPLAY", pargs.r.ret_str);
break;
case oTTYname:
set_opt_session_env ("GPG_TTY", pargs.r.ret_str);
break;
case oTTYtype:
set_opt_session_env ("TERM", pargs.r.ret_str);
break;
case oXauthority:
set_opt_session_env ("XAUTHORITY", pargs.r.ret_str);
break;
case oLCctype: opt.lc_ctype = xstrdup (pargs.r.ret_str); break;
case oLCmessages: opt.lc_messages = xstrdup (pargs.r.ret_str); break;
case oXauthority: opt.xauthority = xstrdup (pargs.r.ret_str); break;
case oDirmngrProgram: opt.dirmngr_program = pargs.r.ret_str; break;
case oDisableDirmngr: opt.disable_dirmngr = 1; break;
case oPreferSystemDirmngr: opt.prefer_system_dirmngr = 1; break;
@ -1357,7 +1385,7 @@ main ( int argc, char **argv)
if (log_get_errorcount(0))
gpgsm_exit(2);
/* Now that we have the optiosn parsed we need to update the default
/* Now that we have the options parsed we need to update the default
control structure. */
gpgsm_init_default_ctrl (&ctrl);

View file

@ -1,5 +1,5 @@
/* gpgsm.h - Global definitions for GpgSM
* Copyright (C) 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
* Copyright (C) 2001, 2003, 2004, 2007, 2009 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -32,6 +32,8 @@
#include "../common/status.h"
#include "../common/estream.h"
#include "../common/audit.h"
#include "../common/session-env.h"
#define MAX_DIGEST_LEN 64
@ -61,13 +63,10 @@ struct
const char *homedir; /* Configuration directory name */
const char *config_filename; /* Name of the used config file. */
const char *agent_program;
char *display;
char *ttyname;
char *ttytype;
session_env_t session_env;
char *lc_ctype;
char *lc_messages;
char *xauthority;
char *pinentry_user_data;
const char *dirmngr_program;
int prefer_system_dirmngr; /* Prefer using a system wide drimngr. */

View file

@ -1,5 +1,5 @@
/* misc.c - Miscellaneous fucntions
* Copyright (C) 2004 Free Software Foundation, Inc.
* Copyright (C) 2004, 2009 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@ -40,16 +40,16 @@ setup_pinentry_env (void)
{
#ifndef HAVE_W32_SYSTEM
char *lc;
if (opt.display)
setenv ("DISPLAY", opt.display, 1);
const char *name, *value;
int iterator;
/* Try to make sure that GPG_TTY has been set. This is needed if we
call for example the protect-tools with redirected stdin and thus
it won't be able to ge a default by itself. Try to do it here
but print a warning. */
if (opt.ttyname)
setenv ("GPG_TTY", opt.ttyname, 1);
value = session_env_getenv (opt.session_env, "GPG_TTY");
if (value)
setenv ("GPG_TTY", value, 1);
else if (!(lc=getenv ("GPG_TTY")) || !*lc)
{
log_error (_("GPG_TTY has not been set - "
@ -60,9 +60,6 @@ setup_pinentry_env (void)
setenv ("GPG_TTY", lc, 1);
}
if (opt.ttytype)
setenv ("TERM", opt.ttytype, 1);
if (opt.lc_ctype)
setenv ("LC_CTYPE", opt.lc_ctype, 1);
#if defined(HAVE_SETLOCALE) && defined(LC_CTYPE)
@ -77,11 +74,15 @@ setup_pinentry_env (void)
setenv ("LC_MESSAGES", lc, 1);
#endif
if (opt.xauthority)
setenv ("XAUTHORITY", opt.xauthority, 1);
if (opt.pinentry_user_data)
setenv ("PINENTRY_USER_DATA", opt.pinentry_user_data, 1);
iterator = 0;
while ((name = session_env_list_stdenvnames (&iterator, NULL)))
{
if (!strcmp (name, "GPG_TTY"))
continue; /* Already set. */
value = session_env_getenv (opt.session_env, name);
if (value)
setenv (name, value, 1);
}
#endif /*!HAVE_W32_SYSTEM*/
}

View file

@ -183,69 +183,59 @@ static int
option_handler (assuan_context_t ctx, const char *key, const char *value)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
gpg_error_t err = 0;
if (!strcmp (key, "include-certs"))
if (!strcmp (key, "putenv"))
{
int i = *value? atoi (value) : -1;
if (ctrl->include_certs < -2)
return gpg_error (GPG_ERR_ASS_PARAMETER);
ctrl->include_certs = i;
/* Change the session's environment to be used for the
Pinentry. Valid values are:
<NAME> Delete envvar NAME
<KEY>= Set envvar NAME to the empty string
<KEY>=<VALUE> Set envvar NAME to VALUE
*/
err = session_env_putenv (opt.session_env, value);
}
else if (!strcmp (key, "display"))
{
if (opt.display)
free (opt.display);
opt.display = strdup (value);
if (!opt.display)
return out_of_core ();
err = session_env_setenv (opt.session_env, "DISPLAY", value);
}
else if (!strcmp (key, "ttyname"))
{
if (opt.ttyname)
free (opt.ttyname);
opt.ttyname = strdup (value);
if (!opt.ttyname)
return out_of_core ();
err = session_env_setenv (opt.session_env, "GPG_TTY", value);
}
else if (!strcmp (key, "ttytype"))
{
if (opt.ttytype)
free (opt.ttytype);
opt.ttytype = strdup (value);
if (!opt.ttytype)
return out_of_core ();
err = session_env_setenv (opt.session_env, "TERM", value);
}
else if (!strcmp (key, "lc-ctype"))
{
if (opt.lc_ctype)
free (opt.lc_ctype);
opt.lc_ctype = strdup (value);
xfree (opt.lc_ctype);
opt.lc_ctype = xtrystrdup (value);
if (!opt.lc_ctype)
return out_of_core ();
err = gpg_error_from_syserror ();
}
else if (!strcmp (key, "lc-messages"))
{
if (opt.lc_messages)
free (opt.lc_messages);
opt.lc_messages = strdup (value);
xfree (opt.lc_messages);
opt.lc_messages = xtrystrdup (value);
if (!opt.lc_messages)
return out_of_core ();
err = gpg_error_from_syserror ();
}
else if (!strcmp (key, "xauthority"))
{
if (opt.xauthority)
free (opt.xauthority);
opt.xauthority = strdup (value);
if (!opt.xauthority)
return out_of_core ();
err = session_env_setenv (opt.session_env, "XAUTHORITY", value);
}
else if (!strcmp (key, "pinentry-user-data"))
{
if (opt.pinentry_user_data)
free (opt.pinentry_user_data);
opt.pinentry_user_data = strdup (value);
if (!opt.pinentry_user_data)
return out_of_core ();
err = session_env_setenv (opt.session_env, "PINENTRY_USER_DATA", value);
}
else if (!strcmp (key, "include-certs"))
{
int i = *value? atoi (value) : -1;
if (ctrl->include_certs < -2)
err = gpg_error (GPG_ERR_ASS_PARAMETER);
else
ctrl->include_certs = i;
}
else if (!strcmp (key, "list-mode"))
{
@ -266,7 +256,7 @@ option_handler (assuan_context_t ctx, const char *key, const char *value)
ctrl->server_local->list_external = 1;
}
else
return gpg_error (GPG_ERR_ASS_PARAMETER);
err = gpg_error (GPG_ERR_ASS_PARAMETER);
}
else if (!strcmp (key, "list-to-output"))
{
@ -284,7 +274,7 @@ option_handler (assuan_context_t ctx, const char *key, const char *value)
if ( i >= 0 && i <= 1 )
ctrl->validation_model = i;
else
return gpg_error (GPG_ERR_ASS_PARAMETER);
err = gpg_error (GPG_ERR_ASS_PARAMETER);
}
else if (!strcmp (key, "with-key-data"))
{
@ -296,7 +286,9 @@ option_handler (assuan_context_t ctx, const char *key, const char *value)
ctrl->server_local->enable_audit_log = i;
}
else if (!strcmp (key, "allow-pinentry-notify"))
ctrl->server_local->allow_pinentry_notify = 1;
{
ctrl->server_local->allow_pinentry_notify = 1;
}
else if (!strcmp (key, "with-ephemeral-keys"))
{
int i = *value? atoi (value) : 0;
@ -307,9 +299,9 @@ option_handler (assuan_context_t ctx, const char *key, const char *value)
ctrl->server_local->no_encrypt_to = 1;
}
else
return gpg_error (GPG_ERR_UNKNOWN_OPTION);
err = gpg_error (GPG_ERR_UNKNOWN_OPTION);
return 0;
return err;
}