aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2004-08-31 15:22:52 +0000
committerWerner Koch <[email protected]>2004-08-31 15:22:52 +0000
commitca650aefbc07eed448f2998e66bf1e1dff878831 (patch)
tree1d576effa9a82e101600ed58ad9677f989c7891c
parentpost release preparations (diff)
downloadgnupg-ca650aefbc07eed448f2998e66bf1e1dff878831.tar.gz
gnupg-ca650aefbc07eed448f2998e66bf1e1dff878831.zip
(maybe_create_keyring): Try to create the home directory
before acquiring a lock for the keyring.
-rw-r--r--THANKS1
-rw-r--r--TODO3
-rw-r--r--g10/ChangeLog5
-rw-r--r--g10/keydb.c57
4 files changed, 41 insertions, 25 deletions
diff --git a/THANKS b/THANKS
index d824b9454..462cfdddd 100644
--- a/THANKS
+++ b/THANKS
@@ -17,6 +17,7 @@ Bodo Moeller [email protected]
Brendan O'Dea [email protected]
Brenno de Winter [email protected]
Brian Gladman [email protected]
+Brian Greenberg [email protected]
Brian M. Carlson [email protected]
Brian Moore [email protected]
Brian Warner [email protected]
diff --git a/TODO b/TODO
index 2d6ceafd2..6bb36b092 100644
--- a/TODO
+++ b/TODO
@@ -96,6 +96,9 @@
* See po/ca.po for remarks on the used strings.
+ * Write a test to check the correct behaviour of creating new
+ keyrings, copying the opion files and creating the home directory.
+
Things we won't do
------------------
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 10885f227..729479d8b 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,8 @@
+2004-08-31 Werner Koch <[email protected]>
+
+ * keydb.c (maybe_create_keyring): Try to create the home directory
+ before acquiring a lock for the keyring.
+
2004-08-20 David Shaw <[email protected]>
* hkp.c (dehtmlize): Understand the quote character
diff --git a/g10/keydb.c b/g10/keydb.c
index 96c37b4d9..5aa57613c 100644
--- a/g10/keydb.c
+++ b/g10/keydb.c
@@ -76,7 +76,7 @@ static void unlock_all (KEYDB_HANDLE hd);
static int
maybe_create_keyring (char *filename, int force)
{
- DOTLOCK lockhd;
+ DOTLOCK lockhd = NULL;
IOBUF iobuf;
int rc;
mode_t oldmask;
@@ -91,6 +91,32 @@ maybe_create_keyring (char *filename, int force)
if (!force)
return G10ERR_OPEN_FILE;
+ /* First of all we try to create the home directory. Note, that we
+ don't do any locking here because any sane application of gpg
+ would create the home directory by itself and not rely on gpg's
+ tricky auto-creation which is anyway only done for some home
+ directory name patterns. */
+ last_slash_in_filename = strrchr (filename, DIRSEP_C);
+ *last_slash_in_filename = 0;
+ if (access(filename, F_OK))
+ {
+ static int tried;
+
+ if (!tried)
+ {
+ tried = 1;
+ try_make_homedir (filename);
+ }
+ if (access (filename, F_OK))
+ {
+ rc = G10ERR_OPEN_FILE;
+ *last_slash_in_filename = DIRSEP_C;
+ goto leave;
+ }
+ }
+ *last_slash_in_filename = DIRSEP_C;
+
+
/* To avoid races with other instances of gpg trying to create or
update the keyring (it is removed during an update for a short
time), we do the next stuff in a locked state. */
@@ -126,28 +152,6 @@ maybe_create_keyring (char *filename, int force)
}
/* The file does not yet exist, create it now. */
-
- last_slash_in_filename = strrchr (filename, DIRSEP_C);
- *last_slash_in_filename = 0;
- if (access(filename, F_OK))
- { /* On the first time we try to create the default
- homedir and check again. */
- static int tried;
-
- if (!tried)
- {
- tried = 1;
- try_make_homedir (filename);
- }
- if (access (filename, F_OK))
- {
- rc = G10ERR_OPEN_FILE;
- *last_slash_in_filename = DIRSEP_C;
- goto leave;
- }
- }
- *last_slash_in_filename = DIRSEP_C;
-
oldmask = umask (077);
iobuf = iobuf_create (filename);
umask (oldmask);
@@ -168,8 +172,11 @@ maybe_create_keyring (char *filename, int force)
rc = 0;
leave:
- release_dotlock (lockhd);
- destroy_dotlock (lockhd);
+ if (lockhd)
+ {
+ release_dotlock (lockhd);
+ destroy_dotlock (lockhd);
+ }
return rc;
}