Skip to contentSkip to conversation

xenstore: don't die on access-denied child nodes in 'xenstore ls'

PATCH New Matthew Daley 1 participant 2 messages Jul 6, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xenstore: don't die on access-denied child nodes in 'xenstore ls'

---
 tools/xenstore/xenstore_client.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
tools/xenstore/xenstore_client.c +11 -4
index 3ac214b..996ee64 100644
@@ -134,8 +134,13 @@ static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms
     unsigned int num, len;
 
     e = xs_directory(h, XBT_NULL, path, &num);
-    if (e == NULL)
+    if (e == NULL) {
+        if(errno == EACCES && cur_depth)
+            /* Don't stop listing just because access was denied to a descendant */
+            return;
+
         err(1, "xs_directory (%s)", path);
+    }
 
     for (i = 0; i<num; i++) {
         char buf[MAX_STRLEN(unsigned int)+1];
@@ -172,7 +177,7 @@ static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms
 
         /* Print value */
         if (val == NULL) {
-            printf(":\n");
+            putchar(':');
         }
         else {
             if (max_width < (linewid + len + TAG_LEN)) {
@@ -192,12 +197,12 @@ static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms
                 }
             }
         }
-        free(val);
 
         if (show_perms) {
             perms = xs_get_permissions(h, XBT_NULL, newpath, &nperms);
             if (perms == NULL) {
-                warn("\ncould not access permissions for %s", e[i]);
+                if (val != NULL)
+                    warn("\ncould not access permissions for %s", e[i]);
             }
             else {
                 int i;
@@ -214,6 +219,8 @@ static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms
 
         putchar('\n');
             
+        free(val);
+
         do_ls(h, newpath, cur_depth+1, show_perms); 
     }
     free(e);
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/2 xenstore: don't leak permissions info in 'xenstore ls -p'

---
 tools/xenstore/xenstore_client.c |    1 +
 1 file changed, 1 insertion(+)
tools/xenstore/xenstore_client.c +1 -0
index 996ee64..f42d06d 100644
@@ -214,6 +214,7 @@ static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_perms
                     fputs(buf, stdout);
                 }
                 putchar(')');
+                free(perms);
             }
         }
 
Signature · 1 line
1.7.10.4