summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-19 12:41:35 +0100
committerRichard Jones <rjones@redhat.com>2009-04-19 12:41:35 +0100
commitd73a4f097f96e7246718671b0a85cb94f0d3a88f (patch)
tree78c4a98fe90cb0c8cdff924a8fd5aa551ec5c94f
parent749708a7ec8930c34605ec58c18fefe0ed8e7981 (diff)
downloadlibguestfs-d73a4f097f96e7246718671b0a85cb94f0d3a88f.tar.gz
libguestfs-d73a4f097f96e7246718671b0a85cb94f0d3a88f.tar.xz
libguestfs-d73a4f097f96e7246718671b0a85cb94f0d3a88f.zip
Implement NEED_ROOT_OR_IS_DEVICE macro.
-rw-r--r--daemon/daemon.h13
-rw-r--r--daemon/file.c2
2 files changed, 14 insertions, 1 deletions
diff --git a/daemon/daemon.h b/daemon/daemon.h
index f18e2d49..b2b81523 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -114,6 +114,19 @@ extern void reply (xdrproc_t xdrp, char *ret);
} \
} while (0)
+/* Helper for functions which need either an absolute path in the
+ * mounted filesystem, OR a /dev/ device which exists.
+ */
+#define NEED_ROOT_OR_IS_DEVICE(path,errcode) \
+ do { \
+ if (strncmp ((path), "/dev/", 5) == 0) \
+ IS_DEVICE ((path),(errcode)); \
+ else { \
+ NEED_ROOT ((path),(errcode)); \
+ ABS_PATH ((path),(errcode)); \
+ } \
+ } while (0)
+
/* NB:
* (1) You must match CHROOT_IN and CHROOT_OUT even along error paths.
* (2) You must not change directory! cwd must always be "/", otherwise
diff --git a/daemon/file.c b/daemon/file.c
index 16dfb009..24398339 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -323,7 +323,7 @@ do_file (const char *path)
int r, len, freeit = 0;
char *buf;
- /*NEED_ROOT (NULL); - no: we allow people to run this on /dev devices. */
+ NEED_ROOT_OR_IS_DEVICE (path, NULL);
ABS_PATH (path, NULL);
if (strncmp (path, "/dev/", 5) == 0)