mirror of
git://git.gnupg.org/gnupg.git
synced 2024-11-10 21:38:50 +01:00
g10: Make sure to have the directory for trustdb.
* g10/tdbio.c (tdbio_set_dbname): Return earlier if !CREATE. Check the directory and create it if none before calling take_write_lock. -- Thanks to Marc Deslauriers for the bug report and his patch. GnuPG-bug-id: 2246 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org> (backport from master commit 2f3e42047d17313eeb38d354048f343158402a8d)
This commit is contained in:
parent
22caa5c2d4
commit
d957e4388f
43
g10/tdbio.c
43
g10/tdbio.c
@ -477,7 +477,7 @@ create_version_record (void)
|
||||
int
|
||||
tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile)
|
||||
{
|
||||
char *fname;
|
||||
char *fname, *p;
|
||||
struct stat statbuf;
|
||||
static int initialized = 0;
|
||||
|
||||
@ -512,31 +512,39 @@ tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile)
|
||||
if (stat (fname, &statbuf) == 0 && statbuf.st_size > 0)
|
||||
/* OK, we have the valid trustdb.gpg already. */
|
||||
return 0;
|
||||
|
||||
take_write_lock ();
|
||||
|
||||
if( access( fname, R_OK ) ) {
|
||||
if( errno != ENOENT )
|
||||
log_fatal( _("can't access `%s': %s\n"), fname, strerror(errno) );
|
||||
|
||||
if (!create)
|
||||
else if (!create) {
|
||||
*r_nofile = 1;
|
||||
else {
|
||||
FILE *fp;
|
||||
TRUSTREC rec;
|
||||
int rc;
|
||||
char *p = strrchr( fname, DIRSEP_C );
|
||||
mode_t oldmask;
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(p);
|
||||
/* Here comes: No valid trustdb.gpg AND CREATE==1 */
|
||||
|
||||
/*
|
||||
* Make sure the directory exists. This should be done before
|
||||
* acquiring the lock, which assumes the directory existence.
|
||||
*/
|
||||
p = strrchr( fname, DIRSEP_C );
|
||||
assert(p); /* See the code above. Always, it has DIRSEP_C. */
|
||||
*p = 0;
|
||||
if( access( fname, F_OK ) ) {
|
||||
try_make_homedir( fname );
|
||||
if (access (fname, F_OK ))
|
||||
log_fatal (_("%s: directory does not exist!\n"), fname);
|
||||
log_fatal (_("%s: directory does not exist!\n"), p);
|
||||
}
|
||||
*p = DIRSEP_C;
|
||||
|
||||
take_write_lock ();
|
||||
|
||||
/* Check the file after aquiring the lock. */
|
||||
if( access( fname, R_OK ) ) {
|
||||
FILE *fp;
|
||||
TRUSTREC rec;
|
||||
int rc;
|
||||
mode_t oldmask;
|
||||
|
||||
if( errno != ENOENT )
|
||||
log_fatal( _("can't access `%s': %s\n"), fname, strerror(errno) );
|
||||
|
||||
oldmask=umask(077);
|
||||
if (is_secured_filename (fname)) {
|
||||
fp = NULL;
|
||||
@ -563,7 +571,6 @@ tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile)
|
||||
if( !opt.quiet )
|
||||
log_info(_("%s: trustdb created\n"), db_name);
|
||||
}
|
||||
}
|
||||
|
||||
release_write_lock ();
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user