Implement NEED_ROOT_OR_IS_DEVICE macro.
authorRichard Jones <rjones@redhat.com>
Sun, 19 Apr 2009 11:41:35 +0000 (12:41 +0100)
committerRichard Jones <rjones@redhat.com>
Sun, 19 Apr 2009 11:41:35 +0000 (12:41 +0100)
daemon/daemon.h
daemon/file.c

index f18e2d4..b2b8152 100644 (file)
@@ -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
index 16dfb00..2439833 100644 (file)
@@ -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)