mirror of git://git.gnupg.org/gnupg.git
(maybe_create_keyring): Try to create the home directory
before acquiring a lock for the keyring.
This commit is contained in:
parent
145cd2cfb2
commit
ca650aefbc
1
THANKS
1
THANKS
|
@ -17,6 +17,7 @@ Bodo Moeller Bodo_Moeller@public.uni-hamburg.de
|
||||||
Brendan O'Dea bod@debian.org
|
Brendan O'Dea bod@debian.org
|
||||||
Brenno de Winter brenno@dewinter.com
|
Brenno de Winter brenno@dewinter.com
|
||||||
Brian Gladman brg@gladman.plus.com
|
Brian Gladman brg@gladman.plus.com
|
||||||
|
Brian Greenberg grnbrg@cc.umanitoba.ca
|
||||||
Brian M. Carlson karlsson@hal-pc.org
|
Brian M. Carlson karlsson@hal-pc.org
|
||||||
Brian Moore bem@cmc.net
|
Brian Moore bem@cmc.net
|
||||||
Brian Warner warner@lothar.com
|
Brian Warner warner@lothar.com
|
||||||
|
|
3
TODO
3
TODO
|
@ -96,6 +96,9 @@
|
||||||
|
|
||||||
* See po/ca.po for remarks on the used strings.
|
* 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
|
Things we won't do
|
||||||
------------------
|
------------------
|
||||||
|
|
|
@ -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>
|
2004-08-20 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
* hkp.c (dehtmlize): Understand the quote character
|
* hkp.c (dehtmlize): Understand the quote character
|
||||||
|
|
57
g10/keydb.c
57
g10/keydb.c
|
@ -76,7 +76,7 @@ static void unlock_all (KEYDB_HANDLE hd);
|
||||||
static int
|
static int
|
||||||
maybe_create_keyring (char *filename, int force)
|
maybe_create_keyring (char *filename, int force)
|
||||||
{
|
{
|
||||||
DOTLOCK lockhd;
|
DOTLOCK lockhd = NULL;
|
||||||
IOBUF iobuf;
|
IOBUF iobuf;
|
||||||
int rc;
|
int rc;
|
||||||
mode_t oldmask;
|
mode_t oldmask;
|
||||||
|
@ -91,6 +91,32 @@ maybe_create_keyring (char *filename, int force)
|
||||||
if (!force)
|
if (!force)
|
||||||
return G10ERR_OPEN_FILE;
|
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
|
/* To avoid races with other instances of gpg trying to create or
|
||||||
update the keyring (it is removed during an update for a short
|
update the keyring (it is removed during an update for a short
|
||||||
time), we do the next stuff in a locked state. */
|
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. */
|
/* 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);
|
oldmask = umask (077);
|
||||||
iobuf = iobuf_create (filename);
|
iobuf = iobuf_create (filename);
|
||||||
umask (oldmask);
|
umask (oldmask);
|
||||||
|
@ -168,8 +172,11 @@ maybe_create_keyring (char *filename, int force)
|
||||||
rc = 0;
|
rc = 0;
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
release_dotlock (lockhd);
|
if (lockhd)
|
||||||
destroy_dotlock (lockhd);
|
{
|
||||||
|
release_dotlock (lockhd);
|
||||||
|
destroy_dotlock (lockhd);
|
||||||
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue