1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-02-26 20:31:06 +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:
NIIBE Yutaka 2016-02-12 10:15:52 +09:00
parent 776bee6d37
commit eb7806d63d

View File

@ -479,9 +479,10 @@ create_version_record (void)
int int
tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile) tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile)
{ {
char *fname; char *fname, *p;
struct stat statbuf; struct stat statbuf;
static int initialized = 0; static int initialized = 0;
int save_slash;
if( !initialized ) { if( !initialized ) {
atexit( cleanup ); atexit( cleanup );
@ -514,23 +515,19 @@ tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile)
if (stat (fname, &statbuf) == 0 && statbuf.st_size > 0) if (stat (fname, &statbuf) == 0 && statbuf.st_size > 0)
/* OK, we have the valid trustdb.gpg already. */ /* OK, we have the valid trustdb.gpg already. */
return 0; return 0;
else if (!create)
take_write_lock (); {
if( access( fname, R_OK ) ) {
if( errno != ENOENT )
log_fatal( _("can't access `%s': %s\n"), fname, strerror(errno) );
if (!create)
*r_nofile = 1; *r_nofile = 1;
else { return 0;
FILE *fp; }
TRUSTREC rec;
int rc;
char *p = strrchr( fname, DIRSEP_C );
mode_t oldmask;
int save_slash;
/* 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 existence of the directory.
*/
p = strrchr( fname, DIRSEP_C );
#if HAVE_W32_SYSTEM #if HAVE_W32_SYSTEM
{ {
/* Windows may either have a slash or a backslash. Take /* Windows may either have a slash or a backslash. Take
@ -550,6 +547,18 @@ tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile)
} }
*p = save_slash; *p = save_slash;
take_write_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); oldmask=umask(077);
if (is_secured_filename (fname)) { if (is_secured_filename (fname)) {
fp = NULL; fp = NULL;
@ -576,7 +585,6 @@ tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile)
if( !opt.quiet ) if( !opt.quiet )
log_info(_("%s: trustdb created\n"), db_name); log_info(_("%s: trustdb created\n"), db_name);
} }
}
release_write_lock (); release_write_lock ();
return 0; return 0;