2 * Copyright © 2010 Codethink Limited
3 * Copyright © 2010 Novell, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Authors: Vincent Untz <vuntz@gnome.org>
19 * Ryan Lortie <desrt@desrt.ca>
31 #include "gfileinfo.h"
32 #include "gfileenumerator.h"
33 #include "gfilemonitor.h"
34 #include "gsimplepermission.h"
35 #include "gsettingsbackendinternal.h"
36 #include "giomodule-priv.h"
37 #include "gportalsupport.h"
40 #define G_TYPE_KEYFILE_SETTINGS_BACKEND (g_keyfile_settings_backend_get_type ())
41 #define G_KEYFILE_SETTINGS_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
42 G_TYPE_KEYFILE_SETTINGS_BACKEND, \
43 GKeyfileSettingsBackend))
44 #define G_IS_KEYFILE_SETTINGS_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
45 G_TYPE_KEYFILE_SETTINGS_BACKEND))
48 typedef GSettingsBackendClass GKeyfileSettingsBackendClass;
55 } GKeyfileSettingsBackendProperty;
59 GSettingsBackend parent_instance;
62 GPermission *permission;
65 GKeyFile *system_keyfile;
66 GHashTable *system_locks; /* Used as a set, owning the strings it contains */
74 GFileMonitor *file_monitor;
77 GFileMonitor *dir_monitor;
78 } GKeyfileSettingsBackend;
81 #define EXTENSION_PRIORITY 10
83 #define EXTENSION_PRIORITY (glib_should_use_portal () && !glib_has_dconf_access_in_sandbox () ? 110 : 10)
86 G_DEFINE_TYPE_WITH_CODE (GKeyfileSettingsBackend,
87 g_keyfile_settings_backend,
88 G_TYPE_SETTINGS_BACKEND,
89 _g_io_modules_ensure_extension_points_registered ();
90 g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
91 g_define_type_id, "keyfile", EXTENSION_PRIORITY))
94 compute_checksum (guint8 *digest,
95 gconstpointer contents,
101 checksum = g_checksum_new (G_CHECKSUM_SHA256);
102 g_checksum_update (checksum, contents, length);
103 g_checksum_get_digest (checksum, digest, &len);
104 g_checksum_free (checksum);
105 g_assert (len == 32);
109 g_keyfile_settings_backend_keyfile_write (GKeyfileSettingsBackend *kfsb,
116 contents = g_key_file_to_data (kfsb->keyfile, &length, NULL);
117 success = g_file_replace_contents (kfsb->file, contents, length, NULL, FALSE,
118 G_FILE_CREATE_REPLACE_DESTINATION |
119 G_FILE_CREATE_PRIVATE,
122 compute_checksum (kfsb->digest, contents, length);
129 group_name_matches (const gchar *group_name,
132 /* sort of like g_str_has_prefix() except that it must be an exact
133 * match or the prefix followed by '/'.
135 * for example 'a' is a prefix of 'a' and 'a/b' but not 'ab'.
139 for (i = 0; prefix[i]; i++)
140 if (prefix[i] != group_name[i])
143 return group_name[i] == '\0' || group_name[i] == '/';
147 convert_path (GKeyfileSettingsBackend *kfsb,
152 gsize key_len = strlen (key);
153 const gchar *last_slash;
155 if (key_len < kfsb->prefix_len ||
156 memcmp (key, kfsb->prefix, kfsb->prefix_len) != 0)
159 key_len -= kfsb->prefix_len;
160 key += kfsb->prefix_len;
162 last_slash = strrchr (key, '/');
164 if (kfsb->root_group)
166 /* if a root_group was specified, make sure the user hasn't given
167 * a path that ghosts that group name
169 if (last_slash != NULL && (last_slash - key) == kfsb->root_group_len && memcmp (key, kfsb->root_group, last_slash - key) == 0)
174 /* if no root_group was given, ensure that the user gave a path */
175 if (last_slash == NULL)
181 if (last_slash != NULL)
183 *group = g_memdup2 (key, (last_slash - key) + 1);
184 (*group)[(last_slash - key)] = '\0';
187 *group = g_strdup (kfsb->root_group);
191 *basename = g_memdup2 (last_slash + 1, key_len - (last_slash - key));
197 path_is_valid (GKeyfileSettingsBackend *kfsb,
200 return convert_path (kfsb, path, NULL, NULL);
204 get_from_keyfile (GKeyfileSettingsBackend *kfsb,
205 const GVariantType *type,
208 GVariant *return_value = NULL;
211 if (convert_path (kfsb, key, &group, &name))
218 sysstr = g_key_file_get_value (kfsb->system_keyfile, group, name, NULL);
219 str = g_key_file_get_value (kfsb->keyfile, group, name, NULL);
221 (g_hash_table_contains (kfsb->system_locks, key) ||
225 str = g_steal_pointer (&sysstr);
230 return_value = g_variant_parse (type, str, NULL, NULL, NULL);
232 /* As a special case, support values of type %G_VARIANT_TYPE_STRING
233 * not being quoted, since users keep forgetting to do it and then
234 * getting confused. */
235 if (return_value == NULL &&
236 g_variant_type_equal (type, G_VARIANT_TYPE_STRING) &&
239 GString *s = g_string_sized_new (strlen (str) + 2);
242 g_string_append_c (s, '\"');
246 g_string_append_c (s, '\\');
247 g_string_append_c (s, *p);
250 g_string_append_c (s, '\"');
251 return_value = g_variant_parse (type, s->str, NULL, NULL, NULL);
252 g_string_free (s, TRUE);
267 set_to_keyfile (GKeyfileSettingsBackend *kfsb,
273 if (g_hash_table_contains (kfsb->system_locks, key))
276 if (convert_path (kfsb, key, &group, &name))
280 gchar *str = g_variant_print (value, FALSE);
281 g_key_file_set_value (kfsb->keyfile, group, name, str);
282 g_variant_unref (g_variant_ref_sink (value));
292 groups = g_key_file_get_groups (kfsb->keyfile, NULL);
294 for (i = 0; groups[i]; i++)
295 if (group_name_matches (groups[i], group))
296 g_key_file_remove_group (kfsb->keyfile, groups[i], NULL);
301 g_key_file_remove_key (kfsb->keyfile, group, name, NULL);
314 g_keyfile_settings_backend_read (GSettingsBackend *backend,
316 const GVariantType *expected_type,
317 gboolean default_value)
319 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
324 return get_from_keyfile (kfsb, expected_type, key);
329 GKeyfileSettingsBackend *kfsb;
334 g_keyfile_settings_backend_write_one (gpointer key,
338 WriteManyData *data = user_data;
339 gboolean success G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
341 success = set_to_keyfile (data->kfsb, key, value);
348 g_keyfile_settings_backend_check_one (gpointer key,
352 WriteManyData *data = user_data;
354 return data->failed = g_hash_table_contains (data->kfsb->system_locks, key) ||
355 !path_is_valid (data->kfsb, key);
359 g_keyfile_settings_backend_write_tree (GSettingsBackend *backend,
363 WriteManyData data = { G_KEYFILE_SETTINGS_BACKEND (backend), 0 };
365 GError *error = NULL;
367 if (!data.kfsb->writable)
370 g_tree_foreach (tree, g_keyfile_settings_backend_check_one, &data);
375 g_tree_foreach (tree, g_keyfile_settings_backend_write_one, &data);
376 success = g_keyfile_settings_backend_keyfile_write (data.kfsb, &error);
379 g_warning ("Failed to write keyfile to %s: %s", g_file_peek_path (data.kfsb->file), error->message);
380 g_error_free (error);
383 g_settings_backend_changed_tree (backend, tree, origin_tag);
389 g_keyfile_settings_backend_write (GSettingsBackend *backend,
394 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
396 GError *error = NULL;
401 success = set_to_keyfile (kfsb, key, value);
405 g_settings_backend_changed (backend, key, origin_tag);
406 success = g_keyfile_settings_backend_keyfile_write (kfsb, &error);
409 g_warning ("Failed to write keyfile to %s: %s", g_file_peek_path (kfsb->file), error->message);
410 g_error_free (error);
418 g_keyfile_settings_backend_reset (GSettingsBackend *backend,
422 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
423 GError *error = NULL;
425 if (set_to_keyfile (kfsb, key, NULL))
427 g_keyfile_settings_backend_keyfile_write (kfsb, &error);
430 g_warning ("Failed to write keyfile to %s: %s", g_file_peek_path (kfsb->file), error->message);
431 g_error_free (error);
435 g_settings_backend_changed (backend, key, origin_tag);
439 g_keyfile_settings_backend_get_writable (GSettingsBackend *backend,
442 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
444 return kfsb->writable &&
445 !g_hash_table_contains (kfsb->system_locks, name) &&
446 path_is_valid (kfsb, name);
450 g_keyfile_settings_backend_get_permission (GSettingsBackend *backend,
453 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
455 return g_object_ref (kfsb->permission);
459 keyfile_to_tree (GKeyfileSettingsBackend *kfsb,
467 groups = g_key_file_get_groups (keyfile, NULL);
468 for (i = 0; groups[i]; i++)
470 gboolean is_root_group;
474 is_root_group = g_strcmp0 (kfsb->root_group, groups[i]) == 0;
476 /* reject group names that will form invalid key names */
477 if (!is_root_group &&
478 (g_str_has_prefix (groups[i], "/") ||
479 g_str_has_suffix (groups[i], "/") || strstr (groups[i], "//")))
482 keys = g_key_file_get_keys (keyfile, groups[i], NULL, NULL);
483 g_assert (keys != NULL);
485 for (j = 0; keys[j]; j++)
489 /* reject key names with slashes in them */
490 if (strchr (keys[j], '/'))
494 path = g_strdup_printf ("%s%s", kfsb->prefix, keys[j]);
496 path = g_strdup_printf ("%s%s/%s", kfsb->prefix, groups[i], keys[j]);
498 value = g_key_file_get_value (keyfile, groups[i], keys[j], NULL);
500 if (dup_check && g_strcmp0 (g_tree_lookup (tree, path), value) == 0)
502 g_tree_remove (tree, path);
507 g_tree_insert (tree, path, value);
516 g_keyfile_settings_backend_keyfile_reload (GKeyfileSettingsBackend *kfsb)
525 g_file_load_contents (kfsb->file, NULL, &contents, &length, NULL, NULL);
526 compute_checksum (digest, contents, length);
528 if (memcmp (kfsb->digest, digest, sizeof digest) != 0)
530 GKeyFile *keyfiles[2];
533 tree = g_tree_new_full ((GCompareDataFunc) strcmp, NULL,
536 keyfiles[0] = kfsb->keyfile;
537 keyfiles[1] = g_key_file_new ();
540 g_key_file_load_from_data (keyfiles[1], contents, length,
541 G_KEY_FILE_KEEP_COMMENTS |
542 G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
544 keyfile_to_tree (kfsb, tree, keyfiles[0], FALSE);
545 keyfile_to_tree (kfsb, tree, keyfiles[1], TRUE);
546 g_key_file_free (keyfiles[0]);
547 kfsb->keyfile = keyfiles[1];
549 if (g_tree_nnodes (tree) > 0)
550 g_settings_backend_changed_tree (&kfsb->parent_instance, tree, NULL);
554 memcpy (kfsb->digest, digest, sizeof digest);
561 g_keyfile_settings_backend_keyfile_writable (GKeyfileSettingsBackend *kfsb)
566 fileinfo = g_file_query_info (kfsb->dir, "access::*", 0, NULL, NULL);
571 g_file_info_get_attribute_boolean (fileinfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) &&
572 g_file_info_get_attribute_boolean (fileinfo, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
573 g_object_unref (fileinfo);
578 if (writable != kfsb->writable)
580 kfsb->writable = writable;
581 g_settings_backend_path_writable_changed (&kfsb->parent_instance, "/");
586 g_keyfile_settings_backend_finalize (GObject *object)
588 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (object);
590 g_key_file_free (kfsb->keyfile);
591 g_object_unref (kfsb->permission);
592 g_key_file_unref (kfsb->system_keyfile);
593 g_hash_table_unref (kfsb->system_locks);
594 g_free (kfsb->defaults_dir);
596 g_file_monitor_cancel (kfsb->file_monitor);
597 g_object_unref (kfsb->file_monitor);
598 g_object_unref (kfsb->file);
600 g_file_monitor_cancel (kfsb->dir_monitor);
601 g_object_unref (kfsb->dir_monitor);
602 g_object_unref (kfsb->dir);
604 g_free (kfsb->root_group);
605 g_free (kfsb->prefix);
607 G_OBJECT_CLASS (g_keyfile_settings_backend_parent_class)
612 g_keyfile_settings_backend_init (GKeyfileSettingsBackend *kfsb)
617 file_changed (GFileMonitor *monitor,
620 GFileMonitorEvent event_type,
623 GKeyfileSettingsBackend *kfsb = user_data;
625 /* Ignore file deletions, let the GKeyFile content remain in tact. */
626 if (event_type != G_FILE_MONITOR_EVENT_DELETED)
627 g_keyfile_settings_backend_keyfile_reload (kfsb);
631 dir_changed (GFileMonitor *monitor,
634 GFileMonitorEvent event_type,
637 GKeyfileSettingsBackend *kfsb = user_data;
639 g_keyfile_settings_backend_keyfile_writable (kfsb);
643 load_system_settings (GKeyfileSettingsBackend *kfsb)
645 GError *error = NULL;
646 const char *dir = "/etc/glib-2.0/settings";
650 kfsb->system_keyfile = g_key_file_new ();
651 kfsb->system_locks = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
653 if (kfsb->defaults_dir)
654 dir = kfsb->defaults_dir;
656 path = g_build_filename (dir, "defaults", NULL);
658 /* The defaults are in the same keyfile format that we use for the settings.
659 * It can be produced from a dconf database using: dconf dump
661 if (!g_key_file_load_from_file (kfsb->system_keyfile, path, G_KEY_FILE_NONE, &error))
663 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
664 g_warning ("Failed to read %s: %s", path, error->message);
665 g_clear_error (&error);
668 g_debug ("Loading default settings from %s", path);
672 path = g_build_filename (dir, "locks", NULL);
674 /* The locks file is a text file containing a list paths to lock, one per line.
675 * It can be produced from a dconf database using: dconf list-locks
677 if (!g_file_get_contents (path, &contents, NULL, &error))
679 if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
680 g_warning ("Failed to read %s: %s", path, error->message);
681 g_clear_error (&error);
688 g_debug ("Loading locks from %s", path);
690 lines = g_strsplit (contents, "\n", 0);
691 for (i = 0; lines[i]; i++)
693 char *line = lines[i];
694 if (line[0] == '#' || line[0] == '\0')
700 g_debug ("Locking key %s", line);
701 g_hash_table_add (kfsb->system_locks, g_steal_pointer (&line));
712 g_keyfile_settings_backend_constructed (GObject *object)
714 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (object);
717 if (kfsb->file == NULL)
719 char *filename = g_build_filename (g_get_user_config_dir (),
720 "glib-2.0", "settings", "keyfile",
722 kfsb->file = g_file_new_for_path (filename);
726 if (kfsb->prefix == NULL)
728 kfsb->prefix = g_strdup ("/");
729 kfsb->prefix_len = 1;
732 kfsb->keyfile = g_key_file_new ();
733 kfsb->permission = g_simple_permission_new (TRUE);
735 kfsb->dir = g_file_get_parent (kfsb->file);
736 path = g_file_peek_path (kfsb->dir);
737 if (g_mkdir_with_parents (path, 0700) == -1)
738 g_warning ("Failed to create %s: %s", path, g_strerror (errno));
740 kfsb->file_monitor = g_file_monitor (kfsb->file, G_FILE_MONITOR_NONE, NULL, NULL);
741 kfsb->dir_monitor = g_file_monitor (kfsb->dir, G_FILE_MONITOR_NONE, NULL, NULL);
743 compute_checksum (kfsb->digest, NULL, 0);
745 g_signal_connect (kfsb->file_monitor, "changed",
746 G_CALLBACK (file_changed), kfsb);
747 g_signal_connect (kfsb->dir_monitor, "changed",
748 G_CALLBACK (dir_changed), kfsb);
750 g_keyfile_settings_backend_keyfile_writable (kfsb);
751 g_keyfile_settings_backend_keyfile_reload (kfsb);
753 load_system_settings (kfsb);
757 g_keyfile_settings_backend_set_property (GObject *object,
762 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (object);
764 switch ((GKeyfileSettingsBackendProperty)prop_id)
767 /* Construct only. */
768 g_assert (kfsb->file == NULL);
769 if (g_value_get_string (value))
770 kfsb->file = g_file_new_for_path (g_value_get_string (value));
774 /* Construct only. */
775 g_assert (kfsb->prefix == NULL);
776 kfsb->prefix = g_value_dup_string (value);
778 kfsb->prefix_len = strlen (kfsb->prefix);
781 case PROP_ROOT_GROUP:
782 /* Construct only. */
783 g_assert (kfsb->root_group == NULL);
784 kfsb->root_group = g_value_dup_string (value);
785 if (kfsb->root_group)
786 kfsb->root_group_len = strlen (kfsb->root_group);
789 case PROP_DEFAULTS_DIR:
790 /* Construct only. */
791 g_assert (kfsb->defaults_dir == NULL);
792 kfsb->defaults_dir = g_value_dup_string (value);
796 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
802 g_keyfile_settings_backend_get_property (GObject *object,
807 GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (object);
809 switch ((GKeyfileSettingsBackendProperty)prop_id)
812 g_value_set_string (value, g_file_peek_path (kfsb->file));
816 g_value_set_string (value, kfsb->prefix);
819 case PROP_ROOT_GROUP:
820 g_value_set_string (value, kfsb->root_group);
823 case PROP_DEFAULTS_DIR:
824 g_value_set_string (value, kfsb->defaults_dir);
828 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
834 g_keyfile_settings_backend_class_init (GKeyfileSettingsBackendClass *class)
836 GObjectClass *object_class = G_OBJECT_CLASS (class);
838 object_class->finalize = g_keyfile_settings_backend_finalize;
839 object_class->constructed = g_keyfile_settings_backend_constructed;
840 object_class->get_property = g_keyfile_settings_backend_get_property;
841 object_class->set_property = g_keyfile_settings_backend_set_property;
843 class->read = g_keyfile_settings_backend_read;
844 class->write = g_keyfile_settings_backend_write;
845 class->write_tree = g_keyfile_settings_backend_write_tree;
846 class->reset = g_keyfile_settings_backend_reset;
847 class->get_writable = g_keyfile_settings_backend_get_writable;
848 class->get_permission = g_keyfile_settings_backend_get_permission;
849 /* No need to implement subscribed/unsubscribe: the only point would be to
850 * stop monitoring the file when there's no GSettings anymore, which is no
855 * GKeyfileSettingsBackend:filename:
857 * The location where the settings are stored on disk.
859 * Defaults to `$XDG_CONFIG_HOME/glib-2.0/settings/keyfile`.
861 g_object_class_install_property (object_class,
863 g_param_spec_string ("filename",
867 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
868 G_PARAM_STATIC_STRINGS));
871 * GKeyfileSettingsBackend:root-path:
873 * All settings read to or written from the backend must fall under the
874 * path given in @root_path (which must start and end with a slash and
875 * not contain two consecutive slashes). @root_path may be "/".
879 g_object_class_install_property (object_class,
881 g_param_spec_string ("root-path",
885 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
886 G_PARAM_STATIC_STRINGS));
889 * GKeyfileSettingsBackend:root-group:
891 * If @root_group is non-%NULL then it specifies the name of the keyfile
892 * group used for keys that are written directly below the root path.
896 g_object_class_install_property (object_class,
898 g_param_spec_string ("root-group",
900 P_("The root group"),
902 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
903 G_PARAM_STATIC_STRINGS));
906 * GKeyfileSettingsBackend:default-dir:
908 * The directory where the system defaults and locks are located.
910 * Defaults to `/etc/glib-2.0/settings`.
912 g_object_class_install_property (object_class,
914 g_param_spec_string ("defaults-dir",
918 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
919 G_PARAM_STATIC_STRINGS));
923 * g_keyfile_settings_backend_new:
924 * @filename: the filename of the keyfile
925 * @root_path: the path under which all settings keys appear
926 * @root_group: (nullable): the group name corresponding to
927 * @root_path, or %NULL
929 * Creates a keyfile-backed #GSettingsBackend.
931 * The filename of the keyfile to use is given by @filename.
933 * All settings read to or written from the backend must fall under the
934 * path given in @root_path (which must start and end with a slash and
935 * not contain two consecutive slashes). @root_path may be "/".
937 * If @root_group is non-%NULL then it specifies the name of the keyfile
938 * group used for keys that are written directly below @root_path. For
939 * example, if @root_path is "/apps/example/" and @root_group is
940 * "toplevel", then settings the key "/apps/example/enabled" to a value
941 * of %TRUE will cause the following to appear in the keyfile:
948 * If @root_group is %NULL then it is not permitted to store keys
949 * directly below the @root_path.
951 * For keys not stored directly below @root_path (ie: in a sub-path),
952 * the name of the subpath (with the final slash stripped) is used as
953 * the name of the keyfile group. To continue the example, if
954 * "/apps/example/profiles/default/font-size" were set to
955 * 12 then the following would appear in the keyfile:
962 * The backend will refuse writes (and return writability as being
963 * %FALSE) for keys outside of @root_path and, in the event that
964 * @root_group is %NULL, also for keys directly under @root_path.
965 * Writes will also be refused if the backend detects that it has the
966 * inability to rewrite the keyfile (ie: the containing directory is not
969 * There is no checking done for your key namespace clashing with the
970 * syntax of the key file format. For example, if you have '[' or ']'
971 * characters in your path names or '=' in your key names you may be in
974 * The backend reads default values from a keyfile called `defaults` in
975 * the directory specified by the #GKeyfileSettingsBackend:defaults-dir property,
976 * and a list of locked keys from a text file with the name `locks` in
979 * Returns: (transfer full): a keyfile-backed #GSettingsBackend
982 g_keyfile_settings_backend_new (const gchar *filename,
983 const gchar *root_path,
984 const gchar *root_group)
986 g_return_val_if_fail (filename != NULL, NULL);
987 g_return_val_if_fail (root_path != NULL, NULL);
988 g_return_val_if_fail (g_str_has_prefix (root_path, "/"), NULL);
989 g_return_val_if_fail (g_str_has_suffix (root_path, "/"), NULL);
990 g_return_val_if_fail (strstr (root_path, "//") == NULL, NULL);
992 return G_SETTINGS_BACKEND (g_object_new (G_TYPE_KEYFILE_SETTINGS_BACKEND,
993 "filename", filename,
994 "root-path", root_path,
995 "root-group", root_group,