psss / rpms / libselinux

Forked from rpms/libselinux 5 years ago
Clone
017ea0e
diff --exclude-from=exclude -N -u -r nsalibselinux/include/selinux/selinux.h libselinux-1.25.7/include/selinux/selinux.h
017ea0e
--- nsalibselinux/include/selinux/selinux.h	2005-09-01 11:17:40.000000000 -0400
017ea0e
+++ libselinux-1.25.7/include/selinux/selinux.h	2005-09-12 11:33:32.000000000 -0400
017ea0e
@@ -304,6 +304,12 @@
017ea0e
 extern int selinux_getenforcemode(int *enforce);
017ea0e
 
017ea0e
 /*
017ea0e
+  selinux_gettype reads the /etc/selinux/config file and determines 
017ea0e
+  whether the policy tyep for this machine, type must be freed.
017ea0e
+ */
017ea0e
+extern void selinux_gettype(char **type);
017ea0e
+
017ea0e
+/*
017ea0e
   selinux_policy_root reads the /etc/selinux/config file and returns 
017ea0e
   the directory path under which the compiled policy file and context 
017ea0e
   configuration files exist.
017ea0e
diff --exclude-from=exclude -N -u -r nsalibselinux/src/init.c libselinux-1.25.7/src/init.c
017ea0e
--- nsalibselinux/src/init.c	2005-09-01 13:21:11.000000000 -0400
017ea0e
+++ libselinux-1.25.7/src/init.c	2005-09-12 11:36:33.000000000 -0400
017ea0e
@@ -8,6 +8,7 @@
017ea0e
 #include <asm/page.h>
017ea0e
 #include <stdio.h>
017ea0e
 #include <dlfcn.h>
017ea0e
+#include <limits.h>
017ea0e
 
017ea0e
 #include "dso.h"
017ea0e
 #include "policy.h"
017ea0e
@@ -85,9 +86,14 @@
017ea0e
 static void init_translations(void)
59d6552
 {
017ea0e
 #ifdef SHARED
017ea0e
+	char *path[PATH_MAX];
017ea0e
+	char *type=NULL;
59d6552
 	int (*lib_trans_init)(void) = NULL;
017ea0e
-
017ea0e
-	translation_lib_handle = dlopen("libsetrans.so.0", RTLD_NOW);
017ea0e
+	selinux_gettype(&type);
017ea0e
+	if (!type) return;
017ea0e
+	snprintf(path, PATH_MAX-1, "/lib/selinux/lib%s.so.0", type);
017ea0e
+	free(type);
017ea0e
+	translation_lib_handle = dlopen(path, RTLD_NOW);
59d6552
 	if (!translation_lib_handle)
59d6552
 		return;
e7e35da
 
017ea0e
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinux_config.c libselinux-1.25.7/src/selinux_config.c
017ea0e
--- nsalibselinux/src/selinux_config.c	2005-03-17 14:56:21.000000000 -0500
017ea0e
+++ libselinux-1.25.7/src/selinux_config.c	2005-09-12 11:35:35.000000000 -0400
017ea0e
@@ -85,6 +85,28 @@
59d6552
 
017ea0e
 static int use_compat_file_path;
017ea0e
 
017ea0e
+void selinux_gettype(char **rtype) {
017ea0e
+	char *type=SELINUXDEFAULT;
017ea0e
+	char buf[4097];
017ea0e
+	int len, i;
017ea0e
+	FILE *cfg = fopen(SELINUXCONFIG,"r");
017ea0e
+	if (cfg) {
017ea0e
+		while (fgets_unlocked(buf, 4096, cfg)) {
017ea0e
+			if (strncmp(buf,SELINUXTYPETAG,len)==0) {
017ea0e
+				type=buf+len;
017ea0e
+				break;
017ea0e
+			}
017ea0e
+		}
017ea0e
+		fclose(cfg);
017ea0e
+	}
017ea0e
+	i=strlen(type)-1;
017ea0e
+	while ((i>=0) && 
017ea0e
+	       (isspace(type[i]) || iscntrl(type[i]))) {
017ea0e
+		type[i]=0;
017ea0e
+		i--;
017ea0e
+	}
017ea0e
+	*rtype=strdup(type);
017ea0e
+}
017ea0e
 int selinux_getenforcemode(int *enforce) {
017ea0e
   int ret=-1;
017ea0e
   FILE *cfg = fopen(SELINUXCONFIG,"r");
017ea0e
@@ -122,38 +144,24 @@
017ea0e
 
017ea0e
 static void init_selinux_policyroot(void)
017ea0e
 {
017ea0e
-  char *type=SELINUXDEFAULT;
017ea0e
+  char *type=NULL;
017ea0e
   int i=0, len=sizeof(SELINUXTYPETAG)-1, len2;
017ea0e
-  char buf[4097];
017ea0e
-  FILE *cfg;
017ea0e
   if (selinux_policyroot) return;
017ea0e
   if (access(SELINUXDIR, F_OK) != 0) {
017ea0e
 	  selinux_policyroot = SECURITYDIR;
017ea0e
 	  use_compat_file_path = 1;
017ea0e
 	  return;
017ea0e
   }
017ea0e
-  cfg = fopen(SELINUXCONFIG,"r");
017ea0e
-  if (cfg) {
017ea0e
-    while (fgets_unlocked(buf, 4096, cfg)) {
017ea0e
-      if (strncmp(buf,SELINUXTYPETAG,len)==0) {
017ea0e
-	type=buf+len;
017ea0e
-	break;
017ea0e
-      }
017ea0e
-    }
017ea0e
-    fclose(cfg);
017ea0e
-  }
017ea0e
-  i=strlen(type)-1;
017ea0e
-  while ((i>=0) && 
017ea0e
-	 (isspace(type[i]) || iscntrl(type[i]))) {
017ea0e
-    type[i]=0;
017ea0e
-    i--;
017ea0e
-  }
017ea0e
+  selinux_gettype(&type);
017ea0e
+  if (!type) return;
017ea0e
   len=sizeof(SELINUXDIR) + strlen(type);
017ea0e
   selinux_policyroot=malloc(len);
017ea0e
-  if (!selinux_policyroot)
017ea0e
+  if (!selinux_policyroot) {
017ea0e
+	  free(type);
017ea0e
 	  return;
017ea0e
+  }
017ea0e
   snprintf(selinux_policyroot,len, "%s%s", SELINUXDIR, type);
017ea0e
-  
017ea0e
+  free(type);
017ea0e
   for (i = 0; i < NEL; i++) {
017ea0e
 	  len2 = len + strlen(file_path_suffixes_data.str
017ea0e
 			      + file_path_suffixes_idx[i])+1;