chsmack: use of 'smack_new_label_from_path'
authorJosé Bollo <jose.bollo@open.eurogiciel.org>
Tue, 10 Dec 2013 13:37:31 +0000 (14:37 +0100)
committerJosé Bollo <jose.bollo@open.eurogiciel.org>
Tue, 17 Dec 2013 10:58:55 +0000 (11:58 +0100)
The library libsmack offer a function for reading
Smack labels. It is better to use the function of the
library.

Signed-off-by: José Bollo <jose.bollo@open.eurogiciel.org>
utils/Makefile.am
utils/chsmack.c

index e8a543a..21df01f 100644 (file)
@@ -15,5 +15,6 @@ smackctl_SOURCES = smackctl.c common.c
 smackctl_LDADD = ../libsmack/libsmack.la
 
 chsmack_SOURCES = chsmack.c
+chsmack_LDADD = ../libsmack/libsmack.la
 
 EXTRA_DIST = common.h
index 7069174..0d5cce5 100644 (file)
@@ -82,6 +82,7 @@ int main(int argc, char *argv[])
        static char mmap_buf[SMACK_LABEL_LEN + 1];
        static int options_map[128];
 
+       char *label;
        int transmute_flag = 0;
        int option_flag = 0;
        int rc;
@@ -161,32 +162,32 @@ int main(int argc, char *argv[])
                        /* Print file path. */
                        printf("%s", argv[i]);
 
-                       rc = lgetxattr(argv[i], XATTR_NAME_SMACK, access_buf,
-                                      SMACK_LABEL_LEN + 1);
+                       rc = (int)smack_new_label_from_path(argv[i],
+                                               XATTR_NAME_SMACK, 0, &label);
                        if (rc > 0) {
-                               access_buf[rc] = '\0';
-                               printf(" access=\"%s\"", access_buf);
+                               printf(" access=\"%s\"", label);
+                               free(label);
                        }
 
-                       rc = lgetxattr(argv[i], XATTR_NAME_SMACKEXEC, access_buf,
-                                      SMACK_LABEL_LEN + 1);
+                       rc = (int)smack_new_label_from_path(argv[i],
+                                               XATTR_NAME_SMACKEXEC, 0, &label);
                        if (rc > 0) {
-                               access_buf[rc] = '\0';
-                               printf(" execute=\"%s\"", access_buf);
-
+                               printf(" execute=\"%s\"", label);
+                               free(label);
                        }
-                       rc = lgetxattr(argv[i], XATTR_NAME_SMACKMMAP, access_buf,
-                                      SMACK_LABEL_LEN + 1);
+
+                       rc = (int)smack_new_label_from_path(argv[i],
+                                               XATTR_NAME_SMACKMMAP, 0, &label);
                        if (rc > 0) {
-                               access_buf[rc] = '\0';
-                               printf(" mmap=\"%s\"", access_buf);
+                               printf(" mmap=\"%s\"", label);
+                               free(label);
                        }
 
-                       rc = lgetxattr(argv[i], XATTR_NAME_SMACKTRANSMUTE,
-                                      access_buf, SMACK_LABEL_LEN + 1);
+                       rc = (int)smack_new_label_from_path(argv[i],
+                                               XATTR_NAME_SMACKTRANSMUTE, 0, &label);
                        if (rc > 0) {
-                               access_buf[rc] = '\0';
-                               printf(" transmute=\"%s\"", access_buf);
+                               printf(" transmute=\"%s\"", label);
+                               free(label);
                        }
 
                        printf("\n");