summaryrefslogtreecommitdiffstats
path: root/login-utils/selinux_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'login-utils/selinux_utils.c')
-rw-r--r--login-utils/selinux_utils.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/login-utils/selinux_utils.c b/login-utils/selinux_utils.c
new file mode 100644
index 0000000..dfd696f
--- /dev/null
+++ b/login-utils/selinux_utils.c
@@ -0,0 +1,29 @@
+#include <selinux/context.h>
+#include <selinux/selinux.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "selinux_utils.h"
+
+access_vector_t get_access_vector(const char *tclass, const char *op)
+{
+ security_class_t tc = string_to_security_class(tclass);
+
+ return tc ? string_to_av_perm(tc, op) : 0;
+}
+
+int setupDefaultContext(char *orig_file)
+{
+ if (is_selinux_enabled() > 0) {
+ security_context_t scontext;
+ if (getfilecon(orig_file, &scontext) < 0)
+ return 1;
+ if (setfscreatecon(scontext) < 0) {
+ freecon(scontext);
+ return 1;
+ }
+ freecon(scontext);
+ }
+ return 0;
+}