Matthew Daley
2013-Jul-06 01:50 UTC
[PATCH 1/2] xenstore: don''t die on access-denied child nodes in ''xenstore ls''
Signed-off-by: Matthew Daley <mattjd@gmail.com>
---
tools/xenstore/xenstore_client.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c
index 3ac214b..996ee64 100644
--- a/tools/xenstore/xenstore_client.c
+++ b/tools/xenstore/xenstore_client.c
@@ -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);
--
1.7.10.4
Matthew Daley
2013-Jul-06 01:50 UTC
[PATCH 2/2] xenstore: don''t leak permissions info in ''xenstore ls -p''
Signed-off-by: Matthew Daley <mattjd@gmail.com>
---
tools/xenstore/xenstore_client.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c
index 996ee64..f42d06d 100644
--- a/tools/xenstore/xenstore_client.c
+++ b/tools/xenstore/xenstore_client.c
@@ -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);
}
}
--
1.7.10.4