diff --git a/THANKS b/THANKS index d824b9454..462cfdddd 100644 --- a/THANKS +++ b/THANKS @@ -17,6 +17,7 @@ Bodo Moeller Bodo_Moeller@public.uni-hamburg.de Brendan O'Dea bod@debian.org Brenno de Winter brenno@dewinter.com Brian Gladman brg@gladman.plus.com +Brian Greenberg grnbrg@cc.umanitoba.ca Brian M. Carlson karlsson@hal-pc.org Brian Moore bem@cmc.net Brian Warner warner@lothar.com 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 + + * keydb.c (maybe_create_keyring): Try to create the home directory + before acquiring a lock for the keyring. + 2004-08-20 David Shaw * 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; }