Added follow parameter to smack_new_label_from_path()
authorJarkko Sakkinen <jarkko.sakkinen@intel.com>
Mon, 27 May 2013 06:54:19 +0000 (09:54 +0300)
committerJarkko Sakkinen <jarkko.sakkinen@intel.com>
Mon, 27 May 2013 06:54:19 +0000 (09:54 +0300)
Added follow parameter to smack_new_label_from_path() so that it
is useful for coreutils commands.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@intel.com>
libsmack/libsmack.c
libsmack/sys/smack.h

index 0e9da03..7e86a5a 100644 (file)
@@ -37,6 +37,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <limits.h>
+#include <attr/xattr.h>
 
 #define ACC_LEN 5
 #define LOAD_LEN (2 * (SMACK_LABEL_LEN + 1) + 2 * ACC_LEN + 1)
@@ -540,13 +541,15 @@ int smack_new_label_from_socket(int fd, char **label)
        return 0;
 }
 
-int smack_new_label_from_path(const char *path, const char *xattr,
+int smack_new_label_from_path(const char *path, const char *xattr, int follow,
                              const char **label)
 {
        char *result;
        ssize_t ret = 0;
 
-       ret = getxattr(path, xattr, NULL, 0);
+       ret = follow ?
+               lgetxattr(path, xattr, NULL, 0) :
+               getxattr(path, xattr, NULL, 0);
        if (ret < 0 && errno != ERANGE)
                return -1;
 
@@ -554,7 +557,9 @@ int smack_new_label_from_path(const char *path, const char *xattr,
        if (result == NULL)
                return -1;
 
-       ret = getxattr(path, xattr, result, ret);
+       ret = follow ?
+               lgetxattr(path, xattr, result, ret) :
+               getxattr(path, xattr, result, ret);
        if (ret < 0) {
                free(result);
                return -1;
index 73392f7..c736a53 100644 (file)
@@ -200,15 +200,18 @@ int smack_new_label_from_self(char **label);
 int smack_new_label_from_socket(int fd, char **label);
 
 /*!
-  * Get the label that is contained in an extended attribute.
+  * Get the SMACK label that is contained in an extended attribute.
   * Caller is responsible of freeing the returned label.
   *
   * @param path path of the file
-  * @param xattr extended attribute containing the label
+  * @param xattr extended attribute containing the SMACK label
+  * @param follow whether or not to follow symbolic link
   * @param label returned label
   * @return 0 on success and negative value on failure.
   */
-int smack_new_label_from_path(const char *path, const char *xattr,
+int smack_new_label_from_path(const char *path,
+                             const char *xattr,
+                             int follow,
                              const char **label);
 
 /*!