[Libguestfs] [PATCH 05/46] daemon: cap-get-file: Return empty string if no capability on file (RHBZ#989356).

Richard W.M. Jones rjones at redhat.com
Sat Aug 24 12:36:41 UTC 2013


From: "Richard W.M. Jones" <rjones at redhat.com>

Return an empty string (instead of an error) if no capabilities are
set on a file, and document that in the API.

(cherry picked from commit c663ab3bb9ab02fb3ca6209333c2d5402081c4de)
(cherry picked from commit 01df523fffebfb586baac869f3e4febb8d79ce45)
---
 daemon/cap.c         | 12 ++++++++++++
 generator/actions.ml |  4 +++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/daemon/cap.c b/daemon/cap.c
index d1f0398..1d732c5 100644
--- a/daemon/cap.c
+++ b/daemon/cap.c
@@ -48,6 +48,18 @@ do_cap_get_file (const char *path)
   CHROOT_OUT;
 
   if (cap == NULL) {
+    /* The getcap utility (part of libcap) ignores ENODATA.  It just
+     * means there is no capability attached to the file (RHBZ#989356).
+     */
+    if (errno == ENODATA) {
+      ret = strdup ("");
+      if (ret == NULL) {
+        reply_with_perror ("strdup");
+        return NULL;
+      }
+      return ret;
+    }
+
     reply_with_perror ("%s", path);
     return NULL;
   }
diff --git a/generator/actions.ml b/generator/actions.ml
index f202b9f..b0f93d2 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -10529,7 +10529,9 @@ attached to directory C<dir>." };
     shortdesc = "get the Linux capabilities attached to a file";
     longdesc = "\
 This function returns the Linux capabilities attached to C<path>.
-The capabilities set is returned in text form (see L<cap_to_text(3)>)." };
+The capabilities set is returned in text form (see L<cap_to_text(3)>).
+
+If no capabilities are attached to a file, an empty string is returned." };
 
   { defaults with
     name = "cap_set_file";
-- 
1.8.3.1




More information about the Libguestfs mailing list