(maybe_create_keyring): Try to create the home directory

before acquiring a lock for the keyring.
This commit is contained in:
Werner Koch 2004-08-31 15:22:52 +00:00
parent 145cd2cfb2
commit ca650aefbc
4 changed files with 41 additions and 25 deletions

1
THANKS
View File

@ -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

3
TODO
View File

@ -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
------------------

View File

@ -1,3 +1,8 @@
2004-08-31 Werner Koch <wk@g10code.de>
* keydb.c (maybe_create_keyring): Try to create the home directory
before acquiring a lock for the keyring.
2004-08-20 David Shaw <dshaw@jabberwocky.com>
* hkp.c (dehtmlize): Understand the quote character

View File

@ -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;
}