summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2023-04-19 11:05:42 +0200
committerWerner Koch <wk@gnupg.org>2023-04-19 11:05:42 +0200
commit80d4ae12156530d643e7d685c286df32f71b7285 (patch)
tree51497a318c6867a77cc0079c8a2b74b433bd3d0d
parentgpg: Make sure that we are not accidently working with the PIV app. (diff)
downloadgnupg2-80d4ae12156530d643e7d685c286df32f71b7285.tar.xz
gnupg2-80d4ae12156530d643e7d685c286df32f71b7285.zip
Use keyboxd on a fresh install also on Windows.
* common/homedir.c (gnupg_maybe_make_homedir): Factor some code out to ... (create_common_conf): new. (standard_homedir): Call it also from here. -- Fixes-commit: d9e7488b17fdc617eec735e2c0485b69285ba511
-rw-r--r--common/homedir.c72
1 files changed, 40 insertions, 32 deletions
diff --git a/common/homedir.c b/common/homedir.c
index 66e79e35c..286685feb 100644
--- a/common/homedir.c
+++ b/common/homedir.c
@@ -154,6 +154,42 @@ w32_shgetfolderpath (HWND a, int b, HANDLE c, DWORD d)
}
#endif /*HAVE_W32_SYSTEM*/
+/* Given the directory name DNAME try to create a common.conf and
+ * enable the keyboxd. This should only be called for the standard
+ * home directory and only if that directory has just been created. */
+static void
+create_common_conf (const char *dname)
+{
+#ifdef BUILD_WITH_KEYBOXD
+ estream_t fp;
+ char *fcommon;
+
+ fcommon = make_filename (dname, "common.conf", NULL);
+ fp = es_fopen (fcommon, "wx,mode=-rw-r");
+ if (!fp)
+ {
+ log_info (_("error creating '%s': %s\n"), fcommon,
+ gpg_strerror (gpg_error_from_syserror ()));
+ }
+ else
+ {
+ if (es_fputs ("use-keyboxd\n", fp) == EOF)
+ {
+ log_info (_("error writing to '%s': %s\n"), fcommon,
+ gpg_strerror (es_ferror (fp)
+ ? gpg_error_from_syserror ()
+ : gpg_error (GPG_ERR_EOF)));
+ es_fclose (fp);
+ }
+ else if (es_fclose (fp))
+ {
+ log_info (_("error closing '%s': %s\n"), fcommon,
+ gpg_strerror (gpg_error_from_syserror ()));
+ }
+ }
+#endif /* BUILD_WITH_KEYBOXD */
+}
+
/* Check whether DIR is the default homedir. */
static int
@@ -259,7 +295,9 @@ standard_homedir (void)
/* Try to create the directory if it does not yet exists. */
if (gnupg_access (dir, F_OK))
- gnupg_mkdir (dir, "-rwx");
+ if (!gnupg_mkdir (dir, "-rwx"))
+ create_common_conf (dir);
+
}
else
dir = GNUPG_DEFAULT_HOMEDIR;
@@ -791,39 +829,9 @@ gnupg_maybe_make_homedir (const char *fname, int quiet)
fname, strerror(errno) );
else
{
- estream_t fp;
- char *fcommon;
-
if (!quiet )
log_info ( _("directory '%s' created\n"), fname );
-
-#ifdef BUILD_WITH_KEYBOXD
- /* A new default homedir has been created. Now create a
- * common.conf. */
- fcommon = make_filename (fname, "common.conf", NULL);
- fp = es_fopen (fcommon, "wx,mode=-rw-r");
- if (!fp)
- {
- log_info (_("error creating '%s': %s\n"), fcommon,
- gpg_strerror (gpg_error_from_syserror ()));
- }
- else
- {
- if (es_fputs ("use-keyboxd\n", fp) == EOF)
- {
- log_info (_("error writing to '%s': %s\n"), fcommon,
- gpg_strerror (es_ferror (fp)
- ? gpg_error_from_syserror ()
- : gpg_error (GPG_ERR_EOF)));
- es_fclose (fp);
- }
- else if (es_fclose (fp))
- {
- log_info (_("error closing '%s': %s\n"), fcommon,
- gpg_strerror (gpg_error_from_syserror ()));
- }
- }
-#endif /* BUILD_WITH_KEYBOXD */
+ create_common_conf (fname);
}
}
}