libsmack: add functions for setting and removing labels on files
authorRafal Krypa <r.krypa@samsung.com>
Thu, 20 Feb 2014 14:04:57 +0000 (15:04 +0100)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Wed, 5 Mar 2014 10:26:25 +0000 (12:26 +0200)
Jóse Bollo implemented two functions as part of this various
improvements for the chsmack command-line utility:

- smack_set_label_for_path() (see f1dfd85)
- smack_remove_label_for_path() (see 5da1a22)

Since they are generally useful, they should be part of the
API in libsmack 1.1.

This patch migrates these functions to libsmack and exports
the symbols. Also, the chsmack is modified to use the new API
instead of the internal functions.

[jsakkine: rewrote the patch description]

Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
libsmack/libsmack.c
libsmack/libsmack.sym
libsmack/sys/smack.h
utils/chsmack.c

index 34e3134..472ca43 100644 (file)
@@ -646,6 +646,31 @@ ssize_t smack_new_label_from_path(const char *path, const char *xattr,
        return ret;
 }
 
+int smack_set_label_for_path(const char *path,
+                                 const char *xattr,
+                                 int follow,
+                                 const char *label)
+{
+       int len;
+       int ret;
+
+       len = (int)smack_label_length(label);
+       if (len < 0)
+               return -2;
+
+       ret = follow ?
+               setxattr(path, xattr, label, len, 0) :
+               lsetxattr(path, xattr, label, len, 0);
+       return ret;
+}
+
+int smack_remove_label_for_path(const char *path,
+                                 const char *xattr,
+                                 int follow)
+{
+       return follow ? removexattr(path, xattr) : lremovexattr(path, xattr);
+}
+
 int smack_set_label_for_self(const char *label)
 {
        int len;
index f0a49d3..d19c7f2 100644 (file)
@@ -26,6 +26,8 @@ local:
 LIBSMACK_1.1 {
 global:
        smack_label_length;
+       smack_set_label_for_path;
+       smack_remove_label_for_path;
 local:
        *;
 } LIBSMACK_1.0;
index e2f94e3..bca2c1c 100644 (file)
@@ -230,6 +230,33 @@ ssize_t smack_new_label_from_path(const char *path,
                                  char **label);
 
 /*!
+  * Set the SMACK label in an extended attribute.
+  *
+  * @param path path of the file
+  * @param xattr the extended attribute containing the SMACK label
+  * @param follow whether or not to follow symbolic link
+  * @param label output variable for the returned label
+  * @return Returns length of the label on success and negative value
+  * on failure.
+  */
+int smack_set_label_for_path(const char *path,
+                                 const char *xattr,
+                                 int follow,
+                                 const char *label);
+
+/*!
+  * Remove the SMACK label in an extended attribute.
+  *
+  * @param path path of the file
+  * @param xattr the extended attribute containing the SMACK label
+  * @param follow whether or not to follow symbolic link
+  * @return Returns 0 on success and negative on failure.
+  */
+int smack_remove_label_for_path(const char *path,
+                                 const char *xattr,
+                                 int follow);
+
+/*!
  * Set the label associated with the callers process. The caller must have
  * CAP_MAC_ADMIN POSIX capability in order to do this.
  *
index 062252d..641c531 100644 (file)
@@ -43,49 +43,6 @@ static const char usage[] =
        " -L --dereference   tell to follow the symbolic links\n"
 ;
 
-/*!
-  * Set the SMACK label in an extended attribute.
-  *
-  * @param path path of the file
-  * @param xattr the extended attribute containing the SMACK label
-  * @param follow whether or not to follow symbolic link
-  * @param label output variable for the returned label
-  * @return Returns length of the label on success and negative value
-  * on failure.
-  */
-static int smack_set_label_for_path(const char *path,
-                                 const char *xattr,
-                                 int follow,
-                                 const char *label)
-{
-       int len;
-       int ret;
-
-       len = (int)smack_label_length(label);
-       if (len < 0)
-               return -2;
-
-       ret = follow ?
-               setxattr(path, xattr, label, len, 0) :
-               lsetxattr(path, xattr, label, len, 0);
-       return ret;
-}
-
-/*!
-  * Remove the SMACK label in an extended attribute.
-  *
-  * @param path path of the file
-  * @param xattr the extended attribute containing the SMACK label
-  * @param follow whether or not to follow symbolic link
-  * @return Returns 0 on success and negative on failure.
-  */
-static int smack_remove_label_for_path(const char *path,
-                                 const char *xattr,
-                                 int follow)
-{
-       return follow ? removexattr(path, xattr) : lremovexattr(path, xattr);
-}
-
 /* main */
 int main(int argc, char *argv[])
 {