aboutsummaryrefslogtreecommitdiffstats
path: root/g10/ringedit.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2000-07-14 17:34:53 +0000
committerWerner Koch <[email protected]>2000-07-14 17:34:53 +0000
commit92cd25550836198cf1e3a6aac239eef98364359d (patch)
tree4fad355126fae79c93535e0e7c6afd91e384552a /g10/ringedit.c
parentSee ChangeLog: Thu May 25 18:39:11 CEST 2000 Werner Koch (diff)
downloadgnupg-92cd25550836198cf1e3a6aac239eef98364359d.tar.gz
gnupg-92cd25550836198cf1e3a6aac239eef98364359d.zip
See ChangeLog: Fri Jul 14 19:38:23 CEST 2000 Werner Koch
Diffstat (limited to '')
-rw-r--r--g10/ringedit.c65
1 files changed, 39 insertions, 26 deletions
diff --git a/g10/ringedit.c b/g10/ringedit.c
index 2fa79fd74..3a29654d2 100644
--- a/g10/ringedit.c
+++ b/g10/ringedit.c
@@ -1,5 +1,5 @@
/* ringedit.c - Function for key ring editing
- * Copyright (C) 1998 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 2000 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -51,9 +51,10 @@
#ifdef HAVE_LIBGDBM
#include <gdbm.h>
#endif
+
+#include <gcrypt.h>
#include "util.h"
#include "packet.h"
-#include <gcrypt.h>
#include "iobuf.h"
#include "keydb.h"
#include "host2net.h"
@@ -63,10 +64,6 @@
#include "kbx.h"
-#ifdef MKDIR_TAKES_ONE_ARG
-# undef mkdir
-# define mkdir(a,b) mkdir(a)
-#endif
struct resource_table_struct {
@@ -191,7 +188,6 @@ enum_keyblock_resources( int *sequence, int secret )
}
-
/****************
* Register a resource (which currently may only be a keyring file).
* The first keyring which is added by this function is
@@ -312,24 +308,13 @@ add_keyblock_resource( const char *url, int force, int secret )
*last_slash_in_filename = 0;
if( access(filename, F_OK) ) {
- if( strlen(filename) >= 7
- && !strcmp(filename+strlen(filename)-7, "/.gnupg") ) {
- if( mkdir(filename, S_IRUSR|S_IWUSR|S_IXUSR) )
- {
- log_error( _("%s: can't create directory: %s\n"),
- filename, strerror(errno));
- rc = GPGERR_OPEN_FILE;
- goto leave;
- }
- else if( !opt.quiet )
- log_info( _("%s: directory created\n"), filename );
- copy_options_file( filename );
- }
- else
- {
- rc = GPGERR_OPEN_FILE;
- goto leave;
- }
+ /* on the first time we try to create the default homedir and
+ * in this case the process will be terminated, so that on the
+ * next invocation it can read the options file in on startup
+ */
+ try_make_homedir( filename );
+ rc = GPGERR_OPEN_FILE;
+ goto leave;
}
*last_slash_in_filename = '/';
@@ -363,7 +348,6 @@ add_keyblock_resource( const char *url, int force, int secret )
#endif
break;
-
#ifdef HAVE_LIBGDBM
case rt_GDBM:
resource_table[i].dbf = gdbm_open( filename, 0,
@@ -457,6 +441,35 @@ get_keyblock_handle( const char *filename, int secret, KBPOS *kbpos )
}
+/****************
+ * Return the filename of the firstkeyblock resource which is intended
+ * for write access. This will either be the default resource or in
+ * case this is not writable one of the others. If no writable is found,
+ * the default filename in the homedirectory will be returned.
+ * Caller must free, will never return NULL.
+ */
+char *
+get_writable_keyblock_file( int secret )
+{
+ int i = secret? default_secret_resource : default_public_resource;
+
+ if( resource_table[i].used && !resource_table[i].secret == !secret ) {
+ if( !access( resource_table[i].fname, R_OK|W_OK ) ) {
+ return gcry_xstrdup( resource_table[i].fname );
+ }
+ }
+ for(i=0; i < MAX_RESOURCES; i++ ) {
+ if( resource_table[i].used && !resource_table[i].secret == !secret ) {
+ if( !access( resource_table[i].fname, R_OK|W_OK ) ) {
+ return gcry_xstrdup( resource_table[i].fname );
+ }
+ }
+ }
+ /* Assume the home dir is always writable */
+ return make_filename(opt.homedir, secret? "secring.gpg"
+ : "pubring.gpg", NULL );
+}
+
/****************
* Search a keyblock which starts with the given packet and puts all