libsmack: add function for policy loading at system startup
authorRafal Krypa <r.krypa@samsung.com>
Thu, 13 Mar 2014 17:40:44 +0000 (18:40 +0100)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 13 Mar 2014 17:40:57 +0000 (18:40 +0100)
New function smack_load_policy() is intended to be used by systemd for
policy loading at system startup. It reuses existing code from
utils/common.c, now moved to libsmack/common.c.

Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
libsmack/.gitignore
libsmack/Makefile.am
libsmack/common.c [moved from utils/common.c with 100% similarity]
libsmack/common.h [moved from utils/common.h with 100% similarity]
libsmack/libsmack.c
libsmack/libsmack.sym
libsmack/sys/smack.h
utils/Makefile.am
utils/smackctl.c

index 004a105..dd832c3 100644 (file)
@@ -1,4 +1,4 @@
 .deps/
 .libs/
-libsmack.la
+*.la
 *.lo
index 92fb7a0..f559551 100644 (file)
@@ -11,6 +11,7 @@ libsmack_la_LDFLAGS = \
        -version-info 2:0:1 \
        -Wl,--version-script=$(top_srcdir)/libsmack/libsmack.sym
 libsmack_la_SOURCES = libsmack.c init.c
+libsmack_la_LIBADD = libsmackcommon.la
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libsmack.pc
@@ -18,3 +19,5 @@ pkgconfig_DATA = libsmack.pc
 library_includedir=$(includedir)/sys
 library_include_HEADERS=sys/smack.h
 
+noinst_LTLIBRARIES = libsmackcommon.la
+libsmackcommon_la_SOURCES = common.h common.c
similarity index 100%
rename from utils/common.c
rename to libsmack/common.c
similarity index 100%
rename from utils/common.h
rename to libsmack/common.h
index 472ca43..30044c1 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include "sys/smack.h"
+#include "common.h"
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -1118,3 +1119,22 @@ static struct smack_label *label_add(struct smack_accesses *handle, const char *
 
        return new_label;
 }
+
+int smack_load_policy(void)
+{
+       if (!smack_smackfs_path()) {
+               fprintf(stderr, "SmackFS is not mounted.\n");
+               return -1;
+       }
+
+       if (clear())
+               return -1;
+
+       if (apply_rules(ACCESSES_D_PATH, 0))
+               return -1;
+
+       if (apply_cipso(CIPSO_D_PATH))
+               return -1;
+
+       return 0;
+}
index d19c7f2..2a0a627 100644 (file)
@@ -28,6 +28,7 @@ global:
        smack_label_length;
        smack_set_label_for_path;
        smack_remove_label_for_path;
+        smack_load_policy;
 local:
        *;
 } LIBSMACK_1.0;
index bca2c1c..c099718 100644 (file)
@@ -281,6 +281,16 @@ int smack_revoke_subject(const char *subject);
  */
 ssize_t smack_label_length(const char *label);
 
+/*!
+ * Perform the initial policy load.
+ * This function loads the Smack policy from default location and loads
+ * it to kernel. Smackfs file system must be alreadt mounted.
+ * It is designed for init process to load the policy at system startup.
+ *
+ * @return Returns 0 on success and negative on failure.
+ */
+int smack_load_policy(void);
+
 #ifdef __cplusplus
 }
 #endif
index 21df01f..49713e7 100644 (file)
@@ -3,18 +3,16 @@ bin_PROGRAMS = smackaccess smackload smackcipso chsmack smackctl
 AM_CPPFLAGS = -I$(top_srcdir)/libsmack
 
 smackaccess_SOURCES = smackaccess.c
-smackaccess_LDADD = ../libsmack/libsmack.la
+smackaccess_LDADD = ../libsmack/libsmack.la ../libsmack/libsmackcommon.la
 
-smackload_SOURCES = smackload.c common.c
-smackload_LDADD = ../libsmack/libsmack.la
+smackload_SOURCES = smackload.c
+smackload_LDADD = ../libsmack/libsmack.la ../libsmack/libsmackcommon.la
 
-smackcipso_SOURCES = smackcipso.c common.c
-smackcipso_LDADD = ../libsmack/libsmack.la
+smackcipso_SOURCES = smackcipso.c
+smackcipso_LDADD = ../libsmack/libsmack.la ../libsmack/libsmackcommon.la
 
-smackctl_SOURCES = smackctl.c common.c
-smackctl_LDADD = ../libsmack/libsmack.la
+smackctl_SOURCES = smackctl.c
+smackctl_LDADD = ../libsmack/libsmack.la ../libsmack/libsmackcommon.la
 
 chsmack_SOURCES = chsmack.c
-chsmack_LDADD = ../libsmack/libsmack.la
-
-EXTRA_DIST = common.h
+chsmack_LDADD = ../libsmack/libsmack.la ../libsmack/libsmackcommon.la
index 439c233..dc96323 100644 (file)
 #include <errno.h>
 #include <string.h>
 
-static int apply_all(void)
-{
-       if (!smack_smackfs_path()) {
-               fprintf(stderr, "SmackFS is not mounted.\n");
-               return -1;
-       }
-
-       if (clear())
-               return -1;
-
-       if (apply_rules(ACCESSES_D_PATH, 0))
-               return -1;
-
-       if (apply_cipso(CIPSO_D_PATH))
-               return -1;
-
-       return 0;
-}
-
 int main(int argc, char **argv)
 {
        const char *tmp = smack_smackfs_path();
@@ -53,7 +34,7 @@ int main(int argc, char **argv)
        }
 
        if (!strcmp(argv[1], "apply")) {
-               if (apply_all())
+               if (smack_load_policy())
                        exit(1);
        } else if (!strcmp(argv[1], "clear")) {
                if (clear())