Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Feb 2006 19:28:46 GMT
From:      Rob Deker <deker@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 91452 for review
Message-ID:  <200602091928.k19JSkkO028967@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=91452

Change 91452 by deker@deker_build1.columbia.sparta.com on 2006/02/09 19:28:42

	per millert:
	
	"Simpler version of sebsd_enabled()"
	
	Submitted by: millert

Affected files ...

.. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/libselinux/src/system.c#3 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/libselinux/src/system.c#3 (text+ko) ====

@@ -35,37 +35,29 @@
  */
 #include <errno.h>
 #include <stdio.h>
-#include <sys/fcntl.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <sedarwin/sebsd.h>
 #include <sedarwin/sebsd_syscalls.h>
 
-int sebsd_enabled()
+int
+sebsd_enabled(void)
 {
-	int    args[2];
-	int    i;
-	size_t mibn = sizeof(int) * 64;
-	int    mibs[64];
+	int i, error;
 
-	args[0] = 0;
-	args[1] = 3;
-	
-	const char *name = "security.mac.sebsd.enforcing";
-	i = sysctl (args, 2, mibs, &mibn, name, strlen(name));
-	if (i < 0) 
-		return 0;
-	return 1;
+	error = sysctlbyname("security.mac.sebsd.enforcing", &i,
+	    sizeof(i), NULL, 0);
+	return (!error || errno != ENOENT);
 }
 
 int
-sebsd_enforcing()
+sebsd_enforcing(void)
 {
 	int i, error;
-	error = sysctlbyname ("security.mac.sebsd.enforcing", 
-			      &i, sizeof (int), NULL, 0);
-	if (error)
-		return 0;
-	return i;
+
+	error = sysctlbyname("security.mac.sebsd.enforcing", &i,
+	    sizeof(i), NULL, 0);
+	return (error ? 0 : i);
 }
 
 struct lp_args
@@ -87,9 +79,31 @@
 	fseek (fp, 0, SEEK_END);
 	la.len = ftell (fp);
 	fseek (fp, 0, SEEK_SET);
-	la.data = malloc (la.len);
-	if (1 != fread (la.data, la.len, 1, fp))
-		return EIO;
+	if ((la.data = malloc (la.len)) == NULL)
+		return (ENOMEM);
+	if (fread(la.data, la.len, 1, fp) != 1)
+		return (EIO);
+
+	return (mac_syscall(SEBSD_ID_STRING, SEBSDCALL_LOAD_POLICY, &la));
+}
+
+int
+sebsd_load_migscs(const char *path)
+{
+	FILE           *fp;
+	struct lp_args  la;
+
+	fp = fopen (path, "rb");
+	if (fp == NULL)
+		return errno;
+
+	fseek(fp, 0, SEEK_END);
+	la.len = ftell(fp);
+	fseek(fp, 0, SEEK_SET);
+	if ((la.data = malloc(la.len)) == NULL)
+		return (ENOMEM);
+	if (fread(la.data, la.len, 1, fp) != 1)
+		return (EIO);
 
-	return mac_syscall(SEBSD_ID_STRING, SEBSDCALL_LOAD_POLICY, &la);
+	return (mac_syscall(SEBSD_ID_STRING, SEBSDCALL_LOAD_MIGSCS, &la));
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200602091928.k19JSkkO028967>