summaryrefslogtreecommitdiffstats
path: root/agent
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2016-06-07 10:59:46 +0200
committerWerner Koch <wk@gnupg.org>2016-06-07 10:59:46 +0200
commit22a7ef01aa2c0eb77bcc40174d09104acc35cab1 (patch)
tree3782b20549fcc48d2598128676227d9a16f785b6 /agent
parentpo: Update Japanese translation. (diff)
downloadgnupg2-22a7ef01aa2c0eb77bcc40174d09104acc35cab1.tar.xz
gnupg2-22a7ef01aa2c0eb77bcc40174d09104acc35cab1.zip
Replace use of opt.homedir by accessor functions.
* common/homedir.c (the_gnupg_homedir): New var. (gnupg_set_homedir): New. (gnupg_homedir): New. * g10/options.h (struct opt): Remove 'homedir' and replace all users by the new accessor functions. * g13/g13-common.h (struct opt): Ditto. * scd/scdaemon.h (struct opt): Ditto. * sm/gpgsm.h (struct opt): Ditto. * dirmngr/dirmngr.h (struct opt): Ditto. * agent/preset-passphrase.c (opt_homedir): Ditto. * agent/protect-tool.c (opt_homedir): Ditto. -- This will make detection of a non-default homedir easier. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'agent')
-rw-r--r--agent/agent.h1
-rw-r--r--agent/command-ssh.c4
-rw-r--r--agent/command.c3
-rw-r--r--agent/findkey.c12
-rw-r--r--agent/gpg-agent.c26
-rw-r--r--agent/preset-passphrase.c7
-rw-r--r--agent/protect-tool.c8
-rw-r--r--agent/trustlist.c24
8 files changed, 50 insertions, 35 deletions
diff --git a/agent/agent.h b/agent/agent.h
index 0dcb20107..42a580cd2 100644
--- a/agent/agent.h
+++ b/agent/agent.h
@@ -62,7 +62,6 @@ struct
int quiet; /* Be as quiet as possible */
int dry_run; /* Don't change any persistent data */
int batch; /* Batch mode */
- const char *homedir; /* Configuration directory name */
/* True if we handle sigusr2. */
int sigusr2_enabled;
diff --git a/agent/command-ssh.c b/agent/command-ssh.c
index 0e1d9fc9f..e3cd4b9b8 100644
--- a/agent/command-ssh.c
+++ b/agent/command-ssh.c
@@ -897,7 +897,7 @@ open_control_file (ssh_control_file_t *r_cf, int append)
/* Note: As soon as we start to use non blocking functions here
(i.e. where Pth might switch threads) we need to employ a
mutex. */
- cf->fname = make_filename_try (opt.homedir, SSH_CONTROL_FILE_NAME, NULL);
+ cf->fname = make_filename_try (gnupg_homedir (), SSH_CONTROL_FILE_NAME, NULL);
if (!cf->fname)
{
err = gpg_error_from_syserror ();
@@ -2734,7 +2734,7 @@ ssh_handler_request_identities (ctrl_t ctrl,
{
char *dname;
- dname = make_filename (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, NULL);
+ dname = make_filename (gnupg_homedir (), GNUPG_PRIVATE_KEYS_DIR, NULL);
if (!dname)
{
err = gpg_err_code_from_syserror ();
diff --git a/agent/command.c b/agent/command.c
index d55e7da5c..1898d6cf7 100644
--- a/agent/command.c
+++ b/agent/command.c
@@ -1258,7 +1258,8 @@ cmd_keyinfo (assuan_context_t ctx, char *line)
char *dirname;
struct dirent *dir_entry;
- dirname = make_filename_try (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, NULL);
+ dirname = make_filename_try (gnupg_homedir (),
+ GNUPG_PRIVATE_KEYS_DIR, NULL);
if (!dirname)
{
err = gpg_error_from_syserror ();
diff --git a/agent/findkey.c b/agent/findkey.c
index a78709cc2..d3780b930 100644
--- a/agent/findkey.c
+++ b/agent/findkey.c
@@ -135,7 +135,8 @@ agent_write_private_key (const unsigned char *grip,
bin2hex (grip, 20, hexgrip);
strcpy (hexgrip+40, ".key");
- fname = make_filename (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL);
+ fname = make_filename (gnupg_homedir (), GNUPG_PRIVATE_KEYS_DIR,
+ hexgrip, NULL);
/* FIXME: Write to a temp file first so that write failures during
key updates won't lead to a key loss. */
@@ -652,7 +653,8 @@ read_key_file (const unsigned char *grip, gcry_sexp_t *result)
bin2hex (grip, 20, hexgrip);
strcpy (hexgrip+40, ".key");
- fname = make_filename (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL);
+ fname = make_filename (gnupg_homedir (), GNUPG_PRIVATE_KEYS_DIR,
+ hexgrip, NULL);
fp = es_fopen (fname, "rb");
if (!fp)
{
@@ -767,7 +769,8 @@ remove_key_file (const unsigned char *grip)
bin2hex (grip, 20, hexgrip);
strcpy (hexgrip+40, ".key");
- fname = make_filename (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL);
+ fname = make_filename (gnupg_homedir (), GNUPG_PRIVATE_KEYS_DIR,
+ hexgrip, NULL);
if (gnupg_remove (fname))
err = gpg_error_from_syserror ();
xfree (fname);
@@ -1289,7 +1292,8 @@ agent_key_available (const unsigned char *grip)
bin2hex (grip, 20, hexgrip);
strcpy (hexgrip+40, ".key");
- fname = make_filename (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL);
+ fname = make_filename (gnupg_homedir (), GNUPG_PRIVATE_KEYS_DIR,
+ hexgrip, NULL);
result = !access (fname, R_OK)? 0 : -1;
xfree (fname);
return result;
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index a9505307f..183229653 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -804,8 +804,6 @@ main (int argc, char **argv )
if (shell && strlen (shell) >= 3 && !strcmp (shell+strlen (shell)-3, "csh") )
csh_style = 1;
- opt.homedir = default_homedir ();
-
/* Record some of the original environment strings. */
{
const char *s;
@@ -861,7 +859,7 @@ main (int argc, char **argv )
else if (pargs.r_opt == oNoOptions)
default_config = 0; /* --no-options */
else if (pargs.r_opt == oHomedir)
- opt.homedir = pargs.r.ret_str;
+ gnupg_set_homedir (pargs.r.ret_str);
else if (pargs.r_opt == oDebugQuickRandom)
{
gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
@@ -878,8 +876,8 @@ main (int argc, char **argv )
*/
if (default_config)
- configname = make_filename (opt.homedir, GPG_AGENT_NAME EXTSEP_S "conf",
- NULL );
+ configname = make_filename (gnupg_homedir (),
+ GPG_AGENT_NAME EXTSEP_S "conf", NULL);
argc = orig_argc;
argv = orig_argv;
@@ -944,7 +942,7 @@ main (int argc, char **argv )
case oNoGreeting: /* Dummy option. */ break;
case oNoVerbose: opt.verbose = 0; break;
case oNoOptions: break; /* no-options */
- case oHomedir: opt.homedir = pargs.r.ret_str; break;
+ case oHomedir: gnupg_set_homedir (pargs.r.ret_str); break;
case oNoDetach: nodetach = 1; break;
case oLogFile: logfile = pargs.r.ret_str; break;
case oCsh: csh_style = 1; break;
@@ -1030,7 +1028,7 @@ main (int argc, char **argv )
finalize_rereadable_options ();
/* Turn the homedir into an absolute one. */
- opt.homedir = make_absfilename (opt.homedir, NULL);
+ gnupg_set_homedir (make_absfilename (gnupg_homedir (), NULL));
/* Print a warning if an argument looks like an option. */
if (!opt.quiet && !(pargs.flags & ARGPARSE_FLAG_STOP_SEEN))
@@ -1104,8 +1102,8 @@ main (int argc, char **argv )
char *filename_esc;
/* List options and default values in the GPG Conf format. */
- filename = make_filename (opt.homedir, GPG_AGENT_NAME EXTSEP_S "conf",
- NULL );
+ filename = make_filename (gnupg_homedir (),
+ GPG_AGENT_NAME EXTSEP_S "conf", NULL);
filename_esc = percent_escape (filename, NULL);
es_printf ("%s-%s.conf:%lu:\"%s\n",
@@ -1764,7 +1762,7 @@ create_socket_name (char *standard_name, int with_homedir)
char *name;
if (with_homedir)
- name = make_filename (opt.homedir, standard_name, NULL);
+ name = make_filename (gnupg_homedir (), standard_name, NULL);
else
name = make_filename (standard_name, NULL);
if (strchr (name, PATHSEP_C))
@@ -1932,7 +1930,7 @@ create_directories (void)
const char *defhome = standard_homedir ();
char *home;
- home = make_filename (opt.homedir, NULL);
+ home = make_filename (gnupg_homedir (), NULL);
if ( stat (home, &statbuf) )
{
if (errno == ENOENT)
@@ -2731,7 +2729,7 @@ check_own_socket (void)
if (check_own_socket_running || shutdown_pending)
return; /* Still running or already shutting down. */
- sockname = make_filename (opt.homedir, GPG_AGENT_SOCK_NAME, NULL);
+ sockname = make_filename_try (gnupg_homedir (), GPG_AGENT_SOCK_NAME, NULL);
if (!sockname)
return; /* Out of memory. */
@@ -2757,7 +2755,9 @@ check_for_running_agent (int silent)
char *sockname;
assuan_context_t ctx = NULL;
- sockname = make_filename (opt.homedir, GPG_AGENT_SOCK_NAME, NULL);
+ sockname = make_filename_try (gnupg_homedir (), GPG_AGENT_SOCK_NAME, NULL);
+ if (!sockname)
+ return gpg_error_from_syserror ();
err = assuan_new (&ctx);
if (!err)
diff --git a/agent/preset-passphrase.c b/agent/preset-passphrase.c
index 1ebf1812a..29fdfe850 100644
--- a/agent/preset-passphrase.c
+++ b/agent/preset-passphrase.c
@@ -66,7 +66,6 @@ enum cmd_and_opt_values
aTest };
-static const char *opt_homedir;
static const char *opt_passphrase;
static ARGPARSE_OPTS opts[] = {
@@ -219,8 +218,6 @@ main (int argc, char **argv)
i18n_init ();
init_common_subsystems (&argc, &argv);
- opt_homedir = default_homedir ();
-
pargs.argc = &argc;
pargs.argv = &argv;
pargs.flags= 1; /* (do not remove the args) */
@@ -229,7 +226,7 @@ main (int argc, char **argv)
switch (pargs.r_opt)
{
case oVerbose: opt.verbose++; break;
- case oHomedir: opt_homedir = pargs.r.ret_str; break;
+ case oHomedir: gnupg_set_homedir (pargs.r.ret_str); break;
case oPreset: cmd = oPreset; break;
case oForget: cmd = oForget; break;
@@ -248,7 +245,7 @@ main (int argc, char **argv)
/* Tell simple-pwquery about the the standard socket name. */
{
- char *tmp = make_filename (opt_homedir, GPG_AGENT_SOCK_NAME, NULL);
+ char *tmp = make_filename (gnupg_homedir (), GPG_AGENT_SOCK_NAME, NULL);
simple_pw_set_socket (tmp);
xfree (tmp);
}
diff --git a/agent/protect-tool.c b/agent/protect-tool.c
index ad036ee1e..fdb791373 100644
--- a/agent/protect-tool.c
+++ b/agent/protect-tool.c
@@ -86,7 +86,6 @@ struct rsa_secret_key_s
};
-static const char *opt_homedir;
static int opt_armor;
static int opt_canonical;
static int opt_store;
@@ -577,9 +576,6 @@ main (int argc, char **argv )
gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
- opt_homedir = default_homedir ();
-
-
pargs.argc = &argc;
pargs.argv = &argv;
pargs.flags= 1; /* (do not remove the args) */
@@ -590,7 +586,7 @@ main (int argc, char **argv )
case oVerbose: opt.verbose++; break;
case oArmor: opt_armor=1; break;
case oCanonical: opt_canonical=1; break;
- case oHomedir: opt_homedir = pargs.r.ret_str; break;
+ case oHomedir: gnupg_set_homedir (pargs.r.ret_str); break;
case oAgentProgram: opt_agent_program = pargs.r.ret_str; break;
@@ -634,7 +630,7 @@ main (int argc, char **argv )
/* Set the information which can't be taken from envvars. */
gnupg_prepare_get_passphrase (GPG_ERR_SOURCE_DEFAULT,
opt.verbose,
- opt_homedir,
+ gnupg_homedir (),
opt_agent_program,
NULL, NULL, NULL);
diff --git a/agent/trustlist.c b/agent/trustlist.c
index af5f64570..b8df3fdde 100644
--- a/agent/trustlist.c
+++ b/agent/trustlist.c
@@ -344,7 +344,14 @@ read_trustfiles (void)
return gpg_error_from_syserror ();
tableidx = 0;
- fname = make_filename (opt.homedir, "trustlist.txt", NULL);
+ fname = make_filename_try (gnupg_homedir (), "trustlist.txt", NULL);
+ if (!fname)
+ {
+ err = gpg_error_from_syserror ();
+ xfree (table);
+ return err;
+ }
+
if ( access (fname, F_OK) )
{
if ( errno == ENOENT )
@@ -608,7 +615,10 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
trustlist with only admin priviliges to modify it. Of course
this is not a secure way of denying access, but it avoids the
usual clicking on an Okay button most users are used to. */
- fname = make_filename (opt.homedir, "trustlist.txt", NULL);
+ fname = make_filename_try (gnupg_homedir (), "trustlist.txt", NULL);
+ if (!fname)
+ return gpg_error_from_syserror ();
+
if ( access (fname, W_OK) && errno != ENOENT)
{
xfree (fname);
@@ -733,7 +743,15 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
return is_disabled? gpg_error (GPG_ERR_NOT_TRUSTED) : 0;
}
- fname = make_filename (opt.homedir, "trustlist.txt", NULL);
+ fname = make_filename_try (gnupg_homedir (), "trustlist.txt", NULL);
+ if (!fname)
+ {
+ err = gpg_error_from_syserror ();
+ unlock_trusttable ();
+ xfree (fprformatted);
+ xfree (nameformatted);
+ return err;
+ }
if ( access (fname, F_OK) && errno == ENOENT)
{
fp = es_fopen (fname, "wx,mode=-rw-r");