chiark / gitweb /
bus-proxy: read the right policy when running in user mode
[elogind.git] / src / bus-proxyd / bus-policy.c
index c592f501bf3d1d98a547e34806efd161f7a6741e..2234e7af3a6619a5f103af1484f07ddefa6fe0aa 100644 (file)
@@ -83,6 +83,8 @@ static int file_load(Policy *p, const char *path) {
         if (r < 0) {
                 if (r == -ENOENT)
                         return 0;
+                if (r == -EISDIR)
+                        return r;
 
                 log_error("Failed to load %s: %s", path, strerror(-r));
                 return r;
@@ -212,6 +214,7 @@ static int file_load(Policy *p, const char *path) {
                                 free(policy_user);
                                 policy_user = name;
                                 name = NULL;
+                                policy_category = POLICY_CATEGORY_USER;
                                 state = STATE_POLICY;
                         } else {
                                 log_error("Unexpected token (5) in %s:%u.", path, line);
@@ -226,6 +229,7 @@ static int file_load(Policy *p, const char *path) {
                                 free(policy_group);
                                 policy_group = name;
                                 name = NULL;
+                                policy_category = POLICY_CATEGORY_GROUP;
                                 state = STATE_POLICY;
                         } else {
                                 log_error("Unexpected token (6) at %s:%u.", path, line);
@@ -511,24 +515,31 @@ static int file_load(Policy *p, const char *path) {
         }
 }
 
-int policy_load(Policy *p) {
-        _cleanup_strv_free_ char **l = NULL;
+int policy_load(Policy *p, char **files) {
         char **i;
         int r;
 
         assert(p);
 
-        file_load(p, "/etc/dbus-1/system.conf");
-        file_load(p, "/etc/dbus-1/system-local.conf");
+        STRV_FOREACH(i, files) {
 
-        r = conf_files_list(&l, ".conf", NULL, "/etc/dbus-1/system.d/", NULL);
-        if (r < 0) {
-                log_error("Failed to get configuration file list: %s", strerror(-r));
-                return r;
-        }
+                r = file_load(p, *i);
+                if (r == -EISDIR) {
+                        _cleanup_strv_free_ char **l = NULL;
+                        char **j;
+
+                        r = conf_files_list(&l, ".conf", NULL, *i, NULL);
+                        if (r < 0) {
+                                log_error("Failed to get configuration file list: %s", strerror(-r));
+                                return r;
+                        }
+
+                        STRV_FOREACH(j, l)
+                                file_load(p, *j);
+                }
 
-        STRV_FOREACH(i, l)
-                file_load(p, *i);
+                /* We ignore all errors but EISDIR, and just proceed. */
+        }
 
         return 0;
 }
@@ -555,8 +566,6 @@ void policy_free(Policy *p) {
                         LIST_REMOVE(items, first, i);
                         policy_item_free(i);
                 }
-
-                policy_item_free(i);
         }
 
         while ((first = hashmap_steal_first(p->group_items))) {
@@ -565,8 +574,6 @@ void policy_free(Policy *p) {
                         LIST_REMOVE(items, first, i);
                         policy_item_free(i);
                 }
-
-                policy_item_free(i);
         }
 
         hashmap_free(p->user_items);
@@ -636,26 +643,26 @@ static void dump_items(PolicyItem *i) {
 static void dump_hashmap_items(Hashmap *h) {
         PolicyItem *i;
         Iterator j;
-        char *k;
+        void *k;
 
         HASHMAP_FOREACH_KEY(i, k, h, j) {
-                printf("Item for %s", k);
+                printf("Item for %u:\n", PTR_TO_UINT(k));
                 dump_items(i);
         }
 }
 
-void policy_dump(Policy *p) {
+noreturn void policy_dump(Policy *p) {
 
-        printf("→ Default Items:\n");
+        printf("%s Default Items:\n", draw_special_char(DRAW_ARROW));
         dump_items(p->default_items);
 
-        printf("→ Mandatory Items:\n");
+        printf("%s Mandatory Items:\n", draw_special_char(DRAW_ARROW));
         dump_items(p->mandatory_items);
 
-        printf("→ Group Items:\n");
+        printf("%s Group Items:\n", draw_special_char(DRAW_ARROW));
         dump_hashmap_items(p->group_items);
 
-        printf("→ User Items:\n");
+        printf("%s User Items:\n", draw_special_char(DRAW_ARROW));
         dump_hashmap_items(p->user_items);
         exit(0);
 }