Skip to contentSkip to conversation

Pass key to sepol

SEPOL 5 Ivan Gyurdiev 1 participant 2 messages Oct 22, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

I did ask about this - Joshua didn't seem to care either way...

I am not sure if the key should be passed into sepol - it's double-storing all the key fields, and now needs an "unpack" method. The alternative approach is to pass in a single record structure as both key and response, but I think that's an uglier interface, possibly less able to adapt to future change.

Since no one expressed a strong opinion either way, here's an implementation that passes the key into sepol.
===========

By the way, I was considering three options - keeping the key, dropping the key, or keeping the key in semanage only. I don't like this third option anymore - the same solution should apply to both libraries.

This patch also drops the sepol_bool_set_array function for now...we have the one in genbools to use for mkload.

libsepol/include/sepol/boolean_record.h +4 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/boolean_record.h new/libsepol/include/sepol/boolean_record.h
@@ -13,6 +13,10 @@ extern int sepol_bool_key_create(
 	const char* name,
 	sepol_bool_key_t** key);
 
+extern void sepol_bool_key_unpack(
+	sepol_bool_key_t* key,
+	const char** name);
+
 extern int sepol_bool_key_extract(
 	sepol_bool_t* boolean,
 	sepol_bool_key_t** key_ptr);
libsepol/include/sepol/booleans.h +2 -7
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/booleans.h new/libsepol/include/sepol/booleans.h
@@ -30,13 +30,8 @@ extern int sepol_genbools_array(
 /* Load a boolean into the policy */
 extern int sepol_bool_set (
 	sepol_policydb_t* policydb, 
-	sepol_bool_t* boolean);
-
-/* Load a boolean array into the policy */
-extern int sepol_bool_set_array(
-	sepol_policydb_t* policydb,
-	sepol_bool_t** bool_arr,
-	size_t bool_arr_len);
+	sepol_bool_key_t* key,
+	sepol_bool_t* data);
 
 /* Iterate the booleans
  * The handler may return:
libsepol/include/sepol/iface_record.h +4 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/iface_record.h new/libsepol/include/sepol/iface_record.h
@@ -13,6 +13,10 @@ extern int sepol_iface_compare(
 	sepol_iface_t* iface, 
 	sepol_iface_key_t* key);
 
+extern void sepol_iface_key_unpack(
+	sepol_iface_key_t* key,
+	const char** name);
+
 extern int sepol_iface_key_create(
 	const char* name,
 	sepol_iface_key_t** key_ptr);
libsepol/include/sepol/interfaces.h +6 -6
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/interfaces.h new/libsepol/include/sepol/interfaces.h
@@ -5,16 +5,16 @@
 #include <sepol/iface_record.h>
 #include <stddef.h>
 
-/* Get the current context mapping for this interface */
-extern int sepol_iface_get_context(
+/* Query an interface */
+extern int sepol_iface_query(
 	sepol_policydb_t* policydb,
-	sepol_iface_t* data,
-	char** ifcon_str, size_t* ifcon_str_len,
-	char** msgcon_str, size_t* msgcon_str_len);
+	sepol_iface_key_t* key,
+	sepol_iface_t** response);
 
-/* Load an interface into policy */
+/* Add an interface to policy */
 extern int sepol_iface_add(
 	sepol_policydb_t* policydb,
+	sepol_iface_key_t* key,
 	sepol_iface_t* data);
 
 /* Iterate the interfaces
libsepol/include/sepol/port_record.h +4 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/port_record.h new/libsepol/include/sepol/port_record.h
@@ -20,6 +20,10 @@ extern int sepol_port_key_create(
 	int low, int high, int proto,
 	sepol_port_key_t** key_ptr);
 
+extern void sepol_port_key_unpack(
+	sepol_port_key_t* key,
+	int* low, int* high, int* proto);
+
 extern int sepol_port_key_extract(
 	sepol_port_t* port, 
 	sepol_port_key_t** key_ptr);
libsepol/include/sepol/ports.h +6 -8
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/ports.h new/libsepol/include/sepol/ports.h
@@ -5,18 +5,16 @@
 #include <sepol/port_record.h>
 #include <stddef.h>
 
-/* Get the current context mapping
- * for this port. Returns 1 if no match, -1 on error, 0 on
- * success. The returned data is allocated on the heap */
-int sepol_port_get_context(
+/* Query a port */
+extern int sepol_port_query(
 	sepol_policydb_t* policydb,
-	sepol_port_t* data,
-	char** con_str,
-	size_t* con_str_len);
+	sepol_port_key_t* key,
+	sepol_port_t** response);
 
-/* Load the given port into policy. No shadowing is allowed. */
+/* Add a port into policy */
 extern int sepol_port_add(
 	sepol_policydb_t* policydb, 
+	sepol_port_key_t* key,
 	sepol_port_t* data);
 
 /* Iterate the ports 
libsepol/include/sepol/user_record.h +4 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/user_record.h new/libsepol/include/sepol/user_record.h
@@ -13,6 +13,10 @@ extern int sepol_user_key_create(
 	const char* name,
 	sepol_user_key_t** key);
 
+extern void sepol_user_key_unpack(
+	sepol_user_key_t* key,
+	const char** name);
+
 extern int sepol_user_key_extract(
 	sepol_user_t* user,
 	sepol_user_key_t** key_ptr);
libsepol/include/sepol/users.h +3 -2
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/users.h new/libsepol/include/sepol/users.h
@@ -26,12 +26,13 @@ extern void sepol_set_delusers(int on);
 /* Add the user if missing, or modify otherwise */
 extern int sepol_user_modify(
 	sepol_policydb_t* policydb, 
-	sepol_user_t* user);
+	sepol_user_key_t* key,
+	sepol_user_t* data);
 
 /* Check if the specified user exists */
 extern int sepol_user_exists(
 	sepol_policydb_t* policydb,
-	const char* user,
+	sepol_user_key_t* key,
 	int* response);
 
 /* Iterate the users
libsepol/src/boolean_record.c +7 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/src/boolean_record.c new/libsepol/src/boolean_record.c
@@ -37,6 +37,13 @@ int sepol_bool_key_create(
 	return STATUS_SUCCESS;
 }
 
+void sepol_bool_key_unpack(
+	sepol_bool_key_t* key,
+	const char** name) {
+
+	*name = key->name;
+}
+
 int sepol_bool_key_extract(sepol_bool_t* boolean, sepol_bool_key_t** key_ptr) {
 	if (sepol_bool_key_create(boolean->name, key_ptr) < 0) {
 		DEBUG(__FUNCTION__, "could not extract key from boolean %s\n",
libsepol/src/booleans.c +17 -40

86 lines not on this page · raw message

libsepol/src/iface_record.c +7 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/src/iface_record.c new/libsepol/src/iface_record.c
@@ -43,6 +43,13 @@ int sepol_iface_key_create(
 	return STATUS_SUCCESS;
 }
 
+void sepol_iface_key_unpack(
+	sepol_iface_key_t* key,
+	const char** name) {
+
+	*name = key->name;	
+}
+
 int sepol_iface_key_extract(sepol_iface_t* iface, sepol_iface_key_t** key_ptr) {
 	if (sepol_iface_key_create(iface->name, key_ptr) < 0) {
 		DEBUG(__FUNCTION__, "could not extract key from "
libsepol/src/interfaces.c +22 -29

100 lines not on this page · raw message

libsepol/src/port_record.c +10 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/src/port_record.c new/libsepol/src/port_record.c
@@ -46,6 +46,16 @@ int sepol_port_key_create(
 	return STATUS_SUCCESS;
 }
 
+void sepol_port_key_unpack(
+	sepol_port_key_t* key,
+	int* low, int* high, int* proto) {
+
+	*low = key->low;
+	*high = key->high;
+	*proto = key->proto;
+}
+
+
 int sepol_port_key_extract(sepol_port_t* port, sepol_port_key_t** key_ptr) {
 	if (sepol_port_key_create(
 		port->low, port->high, port->proto, key_ptr) < 0) {
libsepol/src/ports.c +28 -30

110 lines not on this page · raw message

libsepol/src/user_record.c +7 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude database_policydb.h --exclude policy_components.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/src/user_record.c new/libsepol/src/user_record.c
@@ -50,6 +50,13 @@ int sepol_user_key_create(
 	return STATUS_SUCCESS;
 }
 
+void sepol_user_key_unpack(
+	sepol_user_key_t* key,
+	const char** name) {
+
+	*name = key->name;
+}
+
 int sepol_user_key_extract(sepol_user_t* user, sepol_user_key_t** key_ptr) {
 	if (sepol_user_key_create(user->name, key_ptr) < 0) {
 		DEBUG(__FUNCTION__, "could not extract key from user %s\n",
libsepol/src/users.c +27 -16

75 lines not on this page · raw message

#1 lore raw
Quoted 6 lines
libsepol/src/interfaces.c +2 -1
-	if (iface_from_record(policydb, &iface, data) < 0)
+	rc = sepol_iface_query(p, key, &query_response);
+	if (rc < 0) 
 		goto err;

libsepol/src/interfaces.c static int iface_to_record ( · line 149

Quoted 10 lines
libsepol/src/interfaces.c +1 -5
 
-	rc = sepol_iface_get_context(
-		p, data, 
-		&ifcon_str, &ifcon_str_len,
-		&msgcon_str, &msgcon_str_len);
-	if (rc < 0) 
+	if (iface_from_record(policydb, &iface, data) < 0)
 		goto err;
 
 	else if (rc != STATUS_NODATA) {

This is a rather stupid bug... pasted in wrong place. Will fix in the next patch... [ SEPOL 6 ]

--
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.