aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Brinkmann <[email protected]>2008-02-09 00:49:36 +0000
committerMarcus Brinkmann <[email protected]>2008-02-09 00:49:36 +0000
commit36ffb72bb9c372c4ce12af7fc435a356ff8d65c9 (patch)
treef8a89880e2d1b5740b259e4f1ad9498f9583dc25
parentAdd card vendor 004. (diff)
downloadgnupg-36ffb72bb9c372c4ce12af7fc435a356ff8d65c9.tar.gz
gnupg-36ffb72bb9c372c4ce12af7fc435a356ff8d65c9.zip
2008-02-09 Marcus Brinkmann <[email protected]>
* gpg.c (main): New variable default_configname. Use it if save_configname is NULL (can happen if default configfile does not exist). Move default configname determination to ... (get_default_configname): ... this new function.
-rw-r--r--g10/ChangeLog7
-rw-r--r--g10/gpg.c110
2 files changed, 73 insertions, 44 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index d7823bf00..dbd7533c2 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,10 @@
+2008-02-09 Marcus Brinkmann <[email protected]>
+
+ * gpg.c (main): New variable default_configname. Use it if
+ save_configname is NULL (can happen if default configfile does
+ not exist). Move default configname determination to ...
+ (get_default_configname): ... this new function.
+
2008-01-26 Werner Koch <[email protected]>
* card-util.c (get_manufacturer): Add vendor 004 and support for
diff --git a/g10/gpg.c b/g10/gpg.c
index 1d5197a0e..d91f46609 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -1,6 +1,6 @@
/* gpg.c - The GnuPG utility (main for gpg)
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
- * 2007 Free Software Foundation, Inc.
+ * 2007, 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -1760,6 +1760,65 @@ encode_s2k_iterations(int iterations)
return result;
}
+
+char *
+get_default_configname (void)
+{
+ char *configname = NULL;
+ char *name = xstrdup ("gpg" EXTSEP_S "conf-" SAFE_VERSION);
+ char *ver = &name[strlen ("gpg" EXTSEP_S "conf-")];
+
+ do
+ {
+ if (configname)
+ {
+ char *tok;
+
+ xfree (configname);
+ configname = NULL;
+
+ if ((tok = strrchr (ver, SAFE_VERSION_DASH)))
+ *tok='\0';
+ else if ((tok = strrchr (ver, SAFE_VERSION_DOT)))
+ *tok='\0';
+ else
+ break;
+ }
+
+ configname = make_filename (opt.homedir, name, NULL);
+ }
+ while (access (configname, R_OK));
+
+ xfree(name);
+
+ if (! configname)
+ configname = make_filename (opt.homedir, "gpg" EXTSEP_S "conf", NULL);
+ if (! access (configname, R_OK))
+ {
+ /* Print a warning when both config files are present. */
+ char *p = make_filename (opt.homedir, "options", NULL);
+ if (! access (p, R_OK))
+ log_info (_("NOTE: old default options file `%s' ignored\n"), p);
+ xfree (p);
+ }
+ else
+ {
+ /* Use the old default only if it exists. */
+ char *p = make_filename (opt.homedir, "options", NULL);
+ if (!access (p, R_OK))
+ {
+ xfree (configname);
+ configname = p;
+ }
+ else
+ xfree (p);
+ }
+
+ return configname;
+}
+
+
+
int
main (int argc, char **argv )
{
@@ -1778,6 +1837,7 @@ main (int argc, char **argv )
FILE *configfp = NULL;
char *configname = NULL;
char *save_configname = NULL;
+ char *default_configname = NULL;
unsigned configlineno;
int parse_debug = 0;
int default_config = 1;
@@ -1959,49 +2019,10 @@ main (int argc, char **argv )
set_native_charset (NULL); /* Try to auto set the character set */
/* Try for a version specific config file first */
- if( default_config )
- {
- char *name=xstrdup("gpg" EXTSEP_S "conf-" SAFE_VERSION);
- char *ver=&name[strlen("gpg" EXTSEP_S "conf-")];
+ default_configname = get_default_configname ();
+ if (default_config)
+ configname = xstrdup (default_configname);
- do
- {
- if(configname)
- {
- char *tok;
-
- xfree(configname);
- configname=NULL;
-
- if((tok=strrchr(ver,SAFE_VERSION_DASH)))
- *tok='\0';
- else if((tok=strrchr(ver,SAFE_VERSION_DOT)))
- *tok='\0';
- else
- break;
- }
-
- configname = make_filename(opt.homedir,name,NULL);
- }
- while(access(configname,R_OK));
-
- xfree(name);
-
- if(!configname)
- configname=make_filename(opt.homedir, "gpg" EXTSEP_S "conf", NULL );
- if (!access (configname, R_OK))
- { /* Print a warning when both config files are present. */
- char *p = make_filename(opt.homedir, "options", NULL );
- if (!access (p, R_OK))
- log_info (_("NOTE: old default options file `%s' ignored\n"), p);
- xfree (p);
- }
- else
- { /* Keep on using the old default one. */
- xfree (configname);
- configname = make_filename(opt.homedir, "options", NULL );
- }
- }
argc = orig_argc;
argv = orig_argv;
pargs.argc = &argc;
@@ -2880,10 +2901,11 @@ main (int argc, char **argv )
directly after the option parsing. */
if (cmd == aGPGConfList)
{
- gpgconf_list (save_configname);
+ gpgconf_list (save_configname ? save_configname : default_configname);
g10_exit (0);
}
xfree (save_configname);
+ xfree (default_configname);
if( nogreeting )
greeting = 0;