2
* GConf BerkeleyDB back-end
4
* Copyright (C) 2000 Sun Microsystems Inc
5
* Contributed to the GConf project.
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
24
#include <sys/types.h>
29
#include <gconf/gconf-backend.h>
30
#include <gconf/gconf-internals.h>
31
#include <gconf/gconf.h>
33
/* mode_to_to_mode: copied from xml-dir.c - needs to be a common utility */
35
mode_t_to_mode(mode_t orig)
70
free_list_element (gpointer data, gpointer user_data)
75
/* g_free()s each element's data, then free's the list */
77
_gconf_slist_free_all (GSList * list)
81
g_slist_foreach (list, free_list_element, NULL);
85
/* NOTE: body of _gconf_get_root_dir() is taken directly from initial code in
86
xml-backend.c:resolve_address() */
88
/* parses root directory of a file-based GConf database and checks
89
* directory existence/writeability/locking
92
_gconf_get_root_dir (const char *address, guint * pflags,
93
const gchar * dbtype, GError ** err)
97
guint dir_mode = 0700;
98
guint file_mode = 0600;
100
GConfLock *lock = NULL;
102
root_dir = gconf_address_resource (address);
104
if (root_dir == NULL)
106
gconf_set_error (err, GCONF_ERROR_BAD_ADDRESS,
108
("Couldn't find the %s root directory in the address `%s'"),
113
/* Chop trailing '/' to canonicalize */
114
len = strlen (root_dir);
116
if (root_dir[len - 1] == '/')
117
root_dir[len - 1] = '\0';
119
if (mkdir (root_dir, dir_mode) < 0)
123
gconf_set_error (err, GCONF_ERROR_FAILED,
124
_("Could not make directory `%s': %s"),
125
(gchar *) root_dir, strerror (errno));
131
/* Already exists, base our dir_mode on it */
133
if (stat (root_dir, &statbuf) == 0)
135
dir_mode = mode_t_to_mode (statbuf.st_mode);
136
/* dir_mode without search bits */
137
file_mode = dir_mode & (~0111);
143
/* See if we're writeable */
144
gboolean writeable = FALSE;
148
testfile = g_strconcat (root_dir, "/.testing.writeability", NULL);
150
fd = open (testfile, O_CREAT | O_WRONLY, S_IRWXU);
163
flags |= GCONF_SOURCE_ALL_WRITEABLE;
165
/* We only do locking if it's writeable,
166
which is sort of broken but close enough
172
lockdir = gconf_concat_dir_and_key (root_dir, "%gconf-backend.lock");
174
lock = gconf_get_lock (lockdir, err);
177
gconf_log (GCL_DEBUG, "Acquired %s lock directory `%s'", dbtype,
191
/* see if we're readable */
192
gboolean readable = FALSE;
195
d = opendir (root_dir);
204
flags |= GCONF_SOURCE_ALL_READABLE;
207
if (!(flags & GCONF_SOURCE_ALL_READABLE) &&
208
!(flags & GCONF_SOURCE_ALL_WRITEABLE))
210
gconf_set_error (err, GCONF_ERROR_BAD_ADDRESS,
212
("Can't read from or write to the %s root directory in the address `%s'"),