psss / rpms / libselinux

Forked from rpms/libselinux 5 years ago
Clone
8389437
diff --exclude-from=exclude -N -u -r nsalibselinux/include/selinux/selinux.h libselinux-1.30.12/include/selinux/selinux.h
8389437
--- nsalibselinux/include/selinux/selinux.h	2006-05-18 12:11:17.000000000 -0400
8389437
+++ libselinux-1.30.12/include/selinux/selinux.h	2006-06-09 15:29:18.000000000 -0400
8389437
@@ -361,6 +361,13 @@
8389437
 extern int selinux_getenforcemode(int *enforce);
8f927c4
 
8389437
 /*
8389437
+  selinux_getpolicytype reads the /etc/selinux/config file and determines 
8389437
+  what the default policy for the machine is.  Calling application must 
8389437
+  free policytype.
8389437
+ */
8389437
+extern int selinux_getpolicytype(char **policytype);
f3cb9dc
+
8389437
+/*
8389437
   selinux_policy_root reads the /etc/selinux/config file and returns 
8389437
   the directory path under which the compiled policy file and context 
8389437
   configuration files exist.
8389437
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinux_config.c libselinux-1.30.12/src/selinux_config.c
8389437
--- nsalibselinux/src/selinux_config.c	2006-05-23 06:19:32.000000000 -0400
8389437
+++ libselinux-1.30.12/src/selinux_config.c	2006-06-09 15:42:35.000000000 -0400
8389437
@@ -124,6 +124,37 @@
8389437
 }
8389437
 hidden_def(selinux_getenforcemode)
8f927c4
 
8389437
+int selinux_getpolicytype(char **intype) {
8389437
+  int ret=-1;
8389437
+  char *type=NULL;
8389437
+  char *end=NULL;
8389437
+  FILE *cfg = fopen(SELINUXCONFIG,"r");
8389437
+  char buf[4097];
8389437
+  int len=sizeof(SELINUXTYPETAG)-1;
8389437
+  if (!cfg) {
8389437
+    cfg = fopen(SECURITYCONFIG,"r");
8389437
+  }
8389437
+  if (cfg) {
8389437
+    while (fgets_unlocked(buf, 4096, cfg)) {
8389437
+      if (strncmp(buf,SELINUXTYPETAG,len))
8389437
+	continue;
8389437
+      type = strdupa(buf+sizeof(SELINUXTYPETAG)-1);
8389437
+      end  = type + strlen(type)-1;
8389437
+      while ((end > type) && 
8389437
+	     (isspace(*end) || iscntrl(*end))) {
8389437
+	      *end = 0;
8389437
+	      end--;
8389437
+      }
8389437
+      *intype=type;
8389437
+      ret=0;
8389437
+      break;
8389437
+    }
8389437
+    fclose(cfg);
8389437
+  }
8389437
+  return ret;
8389437
+}
8389437
+hidden_def(selinux_getpolicytype)
8f927c4
+
8389437
 static char *selinux_policyroot = NULL;
8389437
 static char *selinux_rootpath = NULL;
8f927c4
 
8389437
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinux_internal.h libselinux-1.30.12/src/selinux_internal.h
8389437
--- nsalibselinux/src/selinux_internal.h	2006-05-23 06:19:32.000000000 -0400
8389437
+++ libselinux-1.30.12/src/selinux_internal.h	2006-06-09 15:29:18.000000000 -0400
8389437
@@ -64,6 +64,7 @@
8389437
 hidden_proto(selinux_usersconf_path);
8389437
 hidden_proto(selinux_translations_path);
8389437
 hidden_proto(selinux_getenforcemode);
8389437
+hidden_proto(selinux_getpolicytype);
8389437
 hidden_proto(selinux_raw_to_trans_context);
8389437
 hidden_proto(selinux_trans_to_raw_context);
8f927c4
 
8389437
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinux.py libselinux-1.30.12/src/selinux.py
8389437
--- nsalibselinux/src/selinux.py	2006-05-15 09:43:24.000000000 -0400
8389437
+++ libselinux-1.30.12/src/selinux.py	2006-06-09 15:29:18.000000000 -0400
8389437
@@ -102,6 +102,7 @@
8389437
 is_context_customizable = _selinux.is_context_customizable
8389437
 selinux_trans_to_raw_context = _selinux.selinux_trans_to_raw_context
8389437
 selinux_raw_to_trans_context = _selinux.selinux_raw_to_trans_context
8389437
+selinux_getpolicytype = _selinux.selinux_getpolicytype
8389437
 getseuserbyname = _selinux.getseuserbyname
8f927c4
 
8f927c4
 
8389437
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinuxswig.i libselinux-1.30.12/src/selinuxswig.i
8389437
--- nsalibselinux/src/selinuxswig.i	2006-05-15 09:43:24.000000000 -0400
8389437
+++ libselinux-1.30.12/src/selinuxswig.i	2006-06-09 15:29:18.000000000 -0400
8389437
@@ -126,4 +126,5 @@
8389437
 %typemap(argout) char ** {
8389437
 	$result = SWIG_Python_AppendOutput($result, PyString_FromString(*$1));
8389437
 }
8389437
+extern int selinux_getpolicytype(char **enforce);
8389437
 extern int getseuserbyname(const char *linuxuser, char **seuser, char **level);
8389437
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinuxswig_wrap.c libselinux-1.30.12/src/selinuxswig_wrap.c
8389437
--- nsalibselinux/src/selinuxswig_wrap.c	2006-05-15 09:43:24.000000000 -0400
8389437
+++ libselinux-1.30.12/src/selinuxswig_wrap.c	2006-06-09 15:29:18.000000000 -0400
8389437
@@ -4153,6 +4153,27 @@
8389437
 }
8f927c4
 
8f927c4
 
8389437
+SWIGINTERN PyObject *_wrap_selinux_getpolicytype(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
8389437
+  PyObject *resultobj = 0;
8389437
+  char **arg1 = (char **) 0 ;
8389437
+  int result;
8389437
+  char *temp1 ;
8389437
+  
8389437
+  {
8389437
+    arg1 = &temp1;
8389437
+  }
8389437
+  if (!PyArg_ParseTuple(args,(char *)":selinux_getpolicytype")) SWIG_fail;
8389437
+  result = (int)selinux_getpolicytype(arg1);
8389437
+  resultobj = SWIG_From_int((int)(result));
8389437
+  {
8389437
+    resultobj = SWIG_Python_AppendOutput(resultobj, PyString_FromString(*arg1));
8389437
+  }
8389437
+  return resultobj;
8389437
+fail:
8389437
+  return NULL;
8389437
+}
f3cb9dc
+
f3cb9dc
+
8389437
 SWIGINTERN PyObject *_wrap_getseuserbyname(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
8389437
   PyObject *resultobj = 0;
8389437
   char *arg1 = (char *) 0 ;
8389437
@@ -4253,6 +4274,7 @@
8389437
 	 { (char *)"is_context_customizable", _wrap_is_context_customizable, METH_VARARGS, NULL},
8389437
 	 { (char *)"selinux_trans_to_raw_context", _wrap_selinux_trans_to_raw_context, METH_VARARGS, NULL},
8389437
 	 { (char *)"selinux_raw_to_trans_context", _wrap_selinux_raw_to_trans_context, METH_VARARGS, NULL},
8389437
+	 { (char *)"selinux_getpolicytype", _wrap_selinux_getpolicytype, METH_VARARGS, NULL},
8389437
 	 { (char *)"getseuserbyname", _wrap_getseuserbyname, METH_VARARGS, NULL},
8389437
 	 { NULL, NULL, 0, NULL }
8389437
 };
c923175
--- libselinux-1.30.12/src/setrans_client.c~	2006-06-05 13:20:37.000000000 -0400
c923175
+++ libselinux-1.30.12/src/setrans_client.c	2006-06-12 13:39:55.000000000 -0400
c923175
@@ -16,6 +16,9 @@
c923175
 #include "selinux_internal.h"
c923175
 #include "setrans_internal.h"
c923175
 
c923175
+static int mls_enabled=-1;
c923175
+#define MLSENABLED ((mls_enabled==-1) ? (mls_enabled=is_selinux_mls_enabled()) : mls_enabled)
c923175
+
c923175
 // Simple cache
c923175
 static	__thread security_context_t prev_t2r_trans=NULL;
c923175
 static	__thread security_context_t prev_t2r_raw=NULL;
c923175
@@ -243,6 +246,12 @@
c923175
 		*rawp = NULL;
c923175
 		return 0;
c923175
 	}
c923175
+
c923175
+	if (! MLSENABLED) {
c923175
+		*rawp = strdup(trans);
c923175
+		return 0;
c923175
+	}
c923175
+
c923175
 	if (cache_trans) {
c923175
 		if (prev_t2r_trans && strcmp(prev_t2r_trans, trans) == 0) {
c923175
 			*rawp=strdup(prev_t2r_raw);
c923175
@@ -279,6 +288,11 @@
c923175
 		return 0;
c923175
 	}
c923175
 
c923175
+	if (! MLSENABLED) {
c923175
+		*transp = strdup(raw);
c923175
+		return 0;
c923175
+	}
c923175
+
c923175
 	if (cache_trans) {
c923175
 		if (prev_r2t_raw && strcmp(prev_r2t_raw, raw) == 0) {
c923175
 			*transp=strdup(prev_r2t_trans);