Skip to contentSkip to conversation

Mls cleanups

SEPOL Ivan Gyurdiev 2 participants 3 messages Nov 15, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

Cleanup some of mls before I add more functions to it for seuser validation. One of those days I'll rewrite the whole file, and add more comments and ERR calls.

ChangeLog:
- Hide functions mls_to_string and mls_from string into internal header, since they have no user in the static lib. I introduced those functions, and we should not be adding any functions to the static lib - we should be removing them.
- Hide functions mls_sid_to_context, mls_context_to_sid, and mls_compute_context_len in the internal header, since they have no user in the static lib *and* are deprecated (though I still use them in a few places)
- Replace internal use of <sepol/policydb/mls.h> with "mls.h"
- Replace rc values for mls_context_to_sid with STATUS_ERR and STATUS_SUCCESS. There are no callers that use the rc values for anything.
- Use the function mls_level_cpy which I added recently to copy low to high, if the high level is missing

Additional cleanups in genusers while I'm looking at this:
- Do not set ENOMEM in genusers - should be set by malloc/calloc internally, shouldn't it?
- The rc variables in genusers are completely ignored... get rid of them, they create confusion

libsepol/include/sepol/policydb/mls.h +0 -29
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION old/libsepol/include/sepol/policydb/mls.h new/libsepol/include/sepol/policydb/mls.h
@@ -35,35 +35,8 @@
 #include <sepol/policydb/context.h>
 #include <sepol/policydb/policydb.h>
 
-extern int mls_from_string(
-	sepol_handle_t* handle,
-	policydb_t* policydb,
-	const char* str,
-	context_struct_t* mls);
-
-extern int mls_to_string(
-	sepol_handle_t* handle,
-	policydb_t* policydb,
-	context_struct_t* mls,
-	char** str);
-
-/* Deprecated */
-extern int mls_compute_context_len(policydb_t *policydb,
-			    context_struct_t * context);
-
-/* Deprecated */
-extern void mls_sid_to_context(policydb_t *policydb,
-                        context_struct_t *context,
-                        char **scontext);
-
 extern int mls_context_isvalid(policydb_t *p, context_struct_t * c);
 
-/* Deprecated */
-extern int mls_context_to_sid(policydb_t *policydb,
-		       char oldc,
-	               char **scontext,
-		       context_struct_t * context);
-
 extern int mls_convert_context(policydb_t * oldp,
 			policydb_t * newp,
 			context_struct_t * context);
@@ -79,7 +52,5 @@ extern int mls_setup_user_range(
 	context_struct_t *fromcon, user_datum_t *user,
 	context_struct_t *usercon, int mls);
 
-
-
 #endif	
 
libsepol/src/context.c +1 -1
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION old/libsepol/src/context.c new/libsepol/src/context.c
@@ -2,12 +2,12 @@
 #include <string.h>
 
 #include <sepol/policydb/policydb.h>
-#include <sepol/policydb/mls.h>
 #include "context_internal.h"
 
 #include "debug.h"
 #include "context.h"
 #include "handle.h"
+#include "mls.h"
 
 /* ----- Compatibility ---- */
 int policydb_context_isvalid(
libsepol/src/genusers.c +5 -13
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION old/libsepol/src/genusers.c new/libsepol/src/genusers.c
@@ -6,12 +6,12 @@
 #include <limits.h>
 
 #include <sepol/policydb/policydb.h>
-#include <sepol/policydb/mls.h>
 #include <stdarg.h>
 
 #include "debug.h"
 #include "private.h"
 #include "dso.h"
+#include "mls.h"
 
 void sepol_set_delusers(int on __attribute((unused))) {
 	WARN(NULL, "Deprecated interface");
@@ -29,7 +29,6 @@ static int load_users(struct policydb *p
 	char *buffer = NULL, *p, *q, oldc;
 	size_t len = 0;
 	ssize_t nread;
-	int rc;
 	unsigned lineno = 0, islist = 0, bit;
 	user_datum_t *usrdatum;
 	role_datum_t *roldatum;
@@ -78,7 +77,6 @@ static int load_users(struct policydb *p
 			usrdatum = (user_datum_t *) malloc(sizeof(user_datum_t));
 			if (!id || !usrdatum) {
 				ERR(NULL, "out of memory");
-				errno = ENOMEM;
 				free(buffer);
 				fclose(fp);
 				return -1;
@@ -86,11 +84,9 @@ static int load_users(struct policydb *p
 			memset(usrdatum, 0, sizeof(user_datum_t));
 			usrdatum->value = ++policydb->p_users.nprim;
 			ebitmap_init(&usrdatum->roles.roles);
-			rc = hashtab_insert(policydb->p_users.table,
-					    id, (hashtab_datum_t) usrdatum);
-			if (rc) {
+			if (hashtab_insert(policydb->p_users.table, 
+				id, (hashtab_datum_t) usrdatum)) {
 				ERR(NULL, "out of memory");
-				errno = ENOMEM;
 				free(buffer);
 				fclose(fp);
 				return -1;
@@ -145,7 +141,6 @@ static int load_users(struct policydb *p
 				if (ebitmap_node_get_bit(rnode, bit))
 					if (ebitmap_set_bit(&usrdatum->roles.roles, bit, 1)) {
 						ERR(NULL, "out of memory");
-						errno = ENOMEM;
 						free(buffer);
 						fclose(fp);
 						return -1;
@@ -196,8 +191,7 @@ static int load_users(struct policydb *p
 			r = scontext;
 
 			context_init(&context);
-			rc = mls_context_to_sid(policydb, oldc, &r, &context);
-			if (rc) {
+			if (mls_context_to_sid(policydb, oldc, &r, &context) < 0) {
 				ERR(NULL, "invalid level %s (%s:%u)",
 					scontext, path, lineno);
 				free(scontext);
@@ -226,7 +220,6 @@ static int load_users(struct policydb *p
 			scontext = malloc(p - q);
 			if (!scontext) {
 				ERR(NULL, "out of memory");
-				errno = ENOMEM;
 				free(buffer);
 				fclose(fp);
 				return -1;
@@ -242,8 +235,7 @@ static int load_users(struct policydb *p
 			r = scontext;
 
 			context_init(&context);
-			rc = mls_context_to_sid(policydb, oldc, &r, &context);
-			if (rc) {
+			if (mls_context_to_sid(policydb, oldc, &r, &context) < 0) {
 				ERR(NULL, "invalid range %s (%s:%u)",
 					scontext, path, lineno);
 				free(scontext);
libsepol/src/mls.c +34 -45

151 lines not on this page · raw message

libsepol/src/mls.h +41 -0

41 lines not on this page · raw message

libsepol/src/users.c +1 -1
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION old/libsepol/src/users.c new/libsepol/src/users.c
@@ -8,8 +8,8 @@
 
 #include <sepol/policydb/policydb.h>
 #include <sepol/policydb/expand.h>
-#include <sepol/policydb/mls.h>
 #include "user_internal.h"
+#include "mls.h"
 
 static int user_to_record (
 	sepol_handle_t* handle,
#1 lore raw

Re: [ SEPOL ] Mls cleanups (2)

Quoted 7 lines

- Hide functions mls_to_string and mls_from string into internal
header, since they have no user in the static lib. I introduced those functions, and we should not be adding any functions to the static lib
- we should be removing them.
- Hide functions mls_sid_to_context, mls_context_to_sid, and
mls_compute_context_len in the internal header, since they have no user in the static lib *and* are deprecated (though I still use them in a few places)

On second thought, this whole header is not used outside of libsepol (no in-tree users). Move the rest of it into src/mls.h. Applies on top of the other patch.

libsepol/include/sepol/policydb/mls.h +0 -56
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION old/libsepol/include/sepol/policydb/mls.h new/libsepol/include/sepol/policydb/mls.h
@@ -1,56 +0,0 @@
-
-/* Author : Stephen Smalley, <[email protected]> */
-/*
- * Updated: Trusted Computer Solutions, Inc. <[email protected]>
- *
- *	Support for enhanced MLS infrastructure.
- *
- * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-/* FLASK */
-
-/*
- * Multi-level security (MLS) policy operations.
- */
-
-#ifndef _SEPOL_POLICYDB_MLS_H_
-#define _SEPOL_POLICYDB_MLS_H_
-
-#include <sepol/handle.h>
-#include <sepol/policydb/context.h>
-#include <sepol/policydb/policydb.h>
-
-extern int mls_context_isvalid(policydb_t *p, context_struct_t * c);
-
-extern int mls_convert_context(policydb_t * oldp,
-			policydb_t * newp,
-			context_struct_t * context);
-
-extern int mls_compute_sid(policydb_t *policydb,
-		    context_struct_t *scontext,
-		    context_struct_t *tcontext,
-		    sepol_security_class_t tclass,
-		    uint32_t specified,
-		    context_struct_t *newcontext);
-
-extern int mls_setup_user_range(
-	context_struct_t *fromcon, user_datum_t *user,
-	context_struct_t *usercon, int mls);
-
-#endif	
-
libsepol/src/mls.h +43 -1

57 lines not on this page · raw message

libsepol/src/policydb.c +1 -1
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION old/libsepol/src/policydb.c new/libsepol/src/policydb.c
@@ -46,12 +46,12 @@
 
 #include <sepol/policydb/policydb.h>
 #include <sepol/policydb/expand.h>
-#include <sepol/policydb/mls.h>
 #include <sepol/policydb/conditional.h>
 #include <sepol/policydb/avrule_block.h>
 
 #include "private.h"
 #include "debug.h"
+#include "mls.h"
 
 /* These need to be updated if SYM_NUM or OCON_NUM changes */
 static struct policydb_compat_info policydb_compat[] = {
libsepol/src/services.c +1 -1
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION old/libsepol/src/services.c new/libsepol/src/services.c
@@ -52,7 +52,6 @@
 #include <sepol/policydb/policydb.h>
 #include <sepol/policydb/sidtab.h>
 #include <sepol/policydb/services.h>
-#include <sepol/policydb/mls.h>
 #include <sepol/policydb/conditional.h>
 #include <sepol/policydb/flask.h>
 
@@ -61,6 +60,7 @@
 #include "context.h"
 #include "av_permissions.h"
 #include "dso.h"
+#include "mls.h"
 
 #define BUG() do { ERR(NULL, "Badness at %s:%d", __FILE__, __LINE__); } while (0)
 #define BUG_ON(x) do { if (x) ERR(NULL, "Badness at %s:%d", __FILE__, __LINE__); } while (0)
libsepol/src/write.c +1 -1
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION old/libsepol/src/write.c new/libsepol/src/write.c
@@ -36,13 +36,13 @@
 
 #include <sepol/policydb/ebitmap.h>
 #include <sepol/policydb/avtab.h>
-#include <sepol/policydb/mls.h>
 #include <sepol/policydb/policydb.h>
 #include <sepol/policydb/conditional.h>
 #include <sepol/policydb/expand.h>
 
 #include "debug.h"
 #include "private.h"
+#include "mls.h"
 
 struct policy_data
 {
#2 lore raw

Re: [ SEPOL ] Mls cleanups (2)

Quoted 9 lines · Ivan Gyurdiev
Quoted 9 lines

- Hide functions mls_to_string and mls_from string into internal header, since they have no user in the static lib. I introduced those functions, and we should not be adding any functions to the static lib
- we should be removing them.
- Hide functions mls_sid_to_context, mls_context_to_sid, and mls_compute_context_len in the internal header, since they have no user in the static lib *and* are deprecated (though I still use them in a few places)

Quoted 3 lines

On second thought, this whole header is not used outside of libsepol (no in-tree users).
Move the rest of it into src/mls.h. Applies on top of the other patch.

Thanks, both merged as of libsepol 1.9.40.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.