Skip to contentSkip to conversation

Pass handle to user/boolean/interface, and port APIs

SEMANAGE Ivan Gyurdiev 1 participant 1 message Oct 31, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

Changes:
- adds handle to context.c, users.c, ports.c, interfaces.c, and booleans.c
- adds/converts error messages using that handle
- resyncs semanage with those change

- implement all DEBUG calls in services.c as ERR with a NULL handle.

- fix a small memory leak in users.c, on querying a user that isn't found.

=======
Some of those interfaces are getting rather cluttered - take a look in context.h.

libsemanage/src/database_policydb.c +14 -7
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude direct_api.c --exclude semanage_store.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' --exclude Makefile old/libsemanage/src/database_policydb.c new/libsemanage/src/database_policydb.c
@@ -278,7 +278,8 @@ static int dbase_policydb_add (
 	if (enter_rw(handle, dbase) < 0)
 		goto err;
 
-	if (dbase->rptable->add(dbase->policydb, key, data) < 0)
+	if (dbase->rptable->add(handle->sepolh,	
+		dbase->policydb, key, data) < 0)
 		goto err;
 
 	dbase->modified = 1;
@@ -298,7 +299,8 @@ static int dbase_policydb_set(
 	if (enter_rw(handle, dbase) < 0)
 		goto err;
 
-	if (dbase->rptable->set(dbase->policydb, key, data) < 0)
+	if (dbase->rptable->set(handle->sepolh, 
+		dbase->policydb, key, data) < 0)
 		goto err;
 
 	dbase->modified = 1;
@@ -318,7 +320,8 @@ static int dbase_policydb_modify (
 	if (enter_rw(handle, dbase) < 0)
 		goto err;
 
-	if (dbase->rptable->modify(dbase->policydb, key, data) < 0)
+	if (dbase->rptable->modify(handle->sepolh, 
+		dbase->policydb, key, data) < 0)
 		goto err;
 
 	return STATUS_SUCCESS;
@@ -354,7 +357,8 @@ static int dbase_policydb_query (
 	if (enter_ro(handle, dbase) < 0)
 		goto err;
 
-	if (dbase->rptable->query(dbase->policydb, key, response) < 0)
+	if (dbase->rptable->query(handle->sepolh,
+		dbase->policydb, key, response) < 0)
 		goto err;
 
 	exit_ro(handle, dbase);
@@ -375,7 +379,8 @@ static int dbase_policydb_exists (
 	if (enter_ro(handle, dbase) < 0)
 		goto err;
 
-	if (dbase->rptable->exists(dbase->policydb, key, response) < 0)
+	if (dbase->rptable->exists(handle->sepolh, 
+		dbase->policydb, key, response) < 0)
 		goto err;
 
 	exit_ro(handle, dbase);
@@ -395,7 +400,8 @@ static int dbase_policydb_count (
 	if (enter_ro(handle, dbase) < 0)
 		goto err;
 
-	if (dbase->rptable->count(dbase->policydb, response) < 0)
+	if (dbase->rptable->count(handle->sepolh,
+		dbase->policydb, response) < 0)
 		goto err;
 
 	exit_ro(handle, dbase);
@@ -416,7 +422,8 @@ static int dbase_policydb_iterate(
 	if (enter_ro(handle, dbase) < 0)
 		goto err;
 	
-	if (dbase->rptable->iterate(dbase->policydb, fn, arg) < 0) 
+	if (dbase->rptable->iterate(handle->sepolh,
+		dbase->policydb, fn, arg) < 0) 
 		goto err;
 
 	exit_ro(handle, dbase);
libsemanage/src/database_policydb.h +8 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude direct_api.c --exclude semanage_store.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' --exclude Makefile old/libsemanage/src/database_policydb.h new/libsemanage/src/database_policydb.h
@@ -1,6 +1,7 @@
 #ifndef _SEMANAGE_DATABASE_POLICYDB_INTERNAL_H_
 #define _SEMANAGE_DATABASE_POLICYDB_INTERNAL_H_
 
+#include <sepol/handle.h>
 #include <sepol/policydb.h>
 #include "database.h"
 #include "handle.h"
@@ -13,6 +14,7 @@ typedef struct record_policydb_table {
 
 	/* Add policy record */
 	int (*add) (
+		sepol_handle_t* handle,
 		sepol_policydb_t* policydb, 
 		record_key_t* rkey,
 		record_t* record);
@@ -20,12 +22,14 @@ typedef struct record_policydb_table {
 	/* Modify policy record, or add if 
 	 * the key isn't found */
 	int (*modify) (
+		sepol_handle_t* handle,
 		sepol_policydb_t* policydb, 
 		record_key_t* rkey,
 		record_t* record);
 
 	/* Set policy record */
 	int (*set) (
+		sepol_handle_t* handle,
 		sepol_policydb_t* policydb,
 		record_key_t* rkey,
 		record_t* record);
@@ -33,23 +37,27 @@ typedef struct record_policydb_table {
 	/* Query policy record  - return the record
 	 * or NULL if it isn't found */
 	int (*query) (
+		sepol_handle_t* handle,
 		sepol_policydb_t* policydb,
 		record_key_t* rkey,
 		record_t** response);
 
 	/* Count records */
 	int (*count) (
+		sepol_handle_t* handle,
 		sepol_policydb_t* policydb,
 		int* response);
 
 	/* Check if a record exists */
 	int (*exists) (
+		sepol_handle_t* handle,
 		sepol_policydb_t* policydb,
 		record_key_t* rkey,
 		int* response);
 		
 	/* Iterate over records */
 	int (*iterate) (
+		sepol_handle_t* handle,
 		sepol_policydb_t* policydb,
 		int (*fn)(record_t* record, void* fn_arg),
 		void* arg);
libsepol/include/sepol/booleans.h +6 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude direct_api.c --exclude semanage_store.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' --exclude Makefile old/libsepol/include/sepol/booleans.h new/libsepol/include/sepol/booleans.h
@@ -4,6 +4,7 @@
 #include <stddef.h>
 #include <sepol/policydb.h>
 #include <sepol/boolean_record.h>
+#include <sepol/handle.h>
 
 /*--------------compatibility--------------*/
 
@@ -29,23 +30,27 @@ extern int sepol_genbools_array(
 
 /* Set the specified boolean */
 extern int sepol_bool_set (
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb, 
 	sepol_bool_key_t* key,
 	sepol_bool_t* data);
 
 /* Return the number of booleans */
 extern int sepol_bool_count(
+	sepol_handle_t* handle,
 	sepol_policydb_t* p,
 	int* response);
 
 /* Check if the specified boolean exists */
 extern int sepol_bool_exists(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	sepol_bool_key_t* key,
 	int* response);
 
 /* Query a boolean - returns the boolean, or NULL if not found */
 extern int sepol_bool_query(
+	sepol_handle_t* handle,
 	sepol_policydb_t* p,
 	sepol_bool_key_t* key,
 	sepol_bool_t** response);
@@ -57,6 +62,7 @@ extern int sepol_bool_query(
  * 0 to signal continue */
 
 extern int sepol_bool_iterate(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	int (*fn)(
 		sepol_bool_t* boolean,
libsepol/include/sepol/interfaces.h +6 -1
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude direct_api.c --exclude semanage_store.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' --exclude Makefile old/libsepol/include/sepol/interfaces.h new/libsepol/include/sepol/interfaces.h
@@ -3,15 +3,17 @@
 
 #include <sepol/policydb.h>
 #include <sepol/iface_record.h>
-#include <stddef.h>
+#include <sepol/handle.h>
 
 /* Return the number of interfaces */
 extern int sepol_iface_count(
+	sepol_handle_t* handle,
 	sepol_policydb_t* p,
 	int* response);
 
 /* Check if an interface exists */
 extern int sepol_iface_exists(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	sepol_iface_key_t* key,
 	int* response);
@@ -19,6 +21,7 @@ extern int sepol_iface_exists(
 /* Query an interface - returns the interface, 
  * or NULL if not found */
 extern int sepol_iface_query(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	sepol_iface_key_t* key,
 	sepol_iface_t** response);
@@ -26,6 +29,7 @@ extern int sepol_iface_query(
 /* Modify an interface, or add it, if the key
  * is not found */
 extern int sepol_iface_modify(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	sepol_iface_key_t* key,
 	sepol_iface_t* data);
@@ -37,6 +41,7 @@ extern int sepol_iface_modify(
  * 0 to signal continue */
 
 extern int sepol_iface_iterate(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	int (*fn)(
 		sepol_iface_t* iface,
libsepol/include/sepol/ports.h +6 -1
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude direct_api.c --exclude semanage_store.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' --exclude Makefile old/libsepol/include/sepol/ports.h new/libsepol/include/sepol/ports.h
@@ -1,29 +1,33 @@
 #ifndef _SEPOL_PORTS_H_
 #define _SEPOL_PORTS_H_
 
+#include <sepol/handle.h>
 #include <sepol/policydb.h>
 #include <sepol/port_record.h>
-#include <stddef.h>
 
 /* Return the number of ports */
 extern int sepol_port_count(
+	sepol_handle_t* handle,
 	sepol_policydb_t* p,
 	int* response);
 
 /* Check if a port exists */
 extern int sepol_port_exists(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	sepol_port_key_t* key,
 	int* response);
 
 /* Query a port - returns the port, or NULL if not found */
 extern int sepol_port_query(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	sepol_port_key_t* key,
 	sepol_port_t** response);
 
 /* Modify a port, or add it, if the key is not found */
 extern int sepol_port_modify(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb, 
 	sepol_port_key_t* key,
 	sepol_port_t* data);
@@ -35,6 +39,7 @@ extern int sepol_port_modify(
  * 0 to signal continue */
 
 extern int sepol_port_iterate(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	int (*fn)(
 		sepol_port_t* port,
libsepol/include/sepol/users.h +6 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude direct_api.c --exclude semanage_store.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' --exclude Makefile old/libsepol/include/sepol/users.h new/libsepol/include/sepol/users.h
@@ -3,6 +3,7 @@
 
 #include <sepol/policydb.h>
 #include <sepol/user_record.h>
+#include <sepol/handle.h>
 #include <stddef.h>
 
 /*---------compatibility------------*/
@@ -25,23 +26,27 @@ extern void sepol_set_delusers(int on);
 
 /* Modify the user, or add it, if the key is not found */
 extern int sepol_user_modify(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb, 
 	sepol_user_key_t* key,
 	sepol_user_t* data);
 
 /* Return the number of users */
 extern int sepol_user_count(
+	sepol_handle_t* handle,
 	sepol_policydb_t* p,
 	int* response);
 
 /* Check if the specified user exists */
 extern int sepol_user_exists(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	sepol_user_key_t* key,
 	int* response);
 
 /* Query a user - returns the user or NULL if not found */
 extern int sepol_user_query(
+	sepol_handle_t* handle,
 	sepol_policydb_t* p,
 	sepol_user_key_t* key,
 	sepol_user_t** response);
@@ -52,6 +57,7 @@ extern int sepol_user_query(
  * 1 to signal successful exit
  * 0 to signal continue */
 extern int sepol_user_iterate(
+	sepol_handle_t* handle,
 	sepol_policydb_t* policydb,
 	int (*fn)(
 		sepol_user_t* user,
libsepol/src/booleans.c +38 -24

184 lines not on this page · raw message

libsepol/src/context.c +29 -23

168 lines not on this page · raw message

libsepol/src/context.h +5 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude direct_api.c --exclude semanage_store.c --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' --exclude Makefile old/libsepol/src/context.h new/libsepol/src/context.h
@@ -5,20 +5,24 @@
 #include <sepol/context_record.h>
 #include <sepol/policydb/context.h> 
 #include <sepol/policydb/policydb.h>
+#include <sepol/handle.h>
 
 /* Create a context structure from high level representation */
 extern int context_from_record(
+	sepol_handle_t* handle,
 	policydb_t* policydb,
 	context_struct_t** cptr,
 	sepol_context_t* data);
 
 extern int context_to_record(
+	sepol_handle_t* handle,
 	policydb_t* policydb,
 	context_struct_t* context,
 	sepol_context_t** record);
 
 /* Create a context structure from string representation */
 extern int context_from_string(
+	sepol_handle_t* handle,
 	policydb_t* policydb,
 	context_struct_t** cptr,
 	const char* con_str,
@@ -31,6 +35,7 @@ extern int context_is_valid(
 
 /* Extract the context as string */
 extern int context_to_string(
+	sepol_handle_t* handle,
 	policydb_t* policydb,
 	context_struct_t* context,
 	char ** result,
libsepol/src/interfaces.c +26 -17

173 lines not on this page · raw message

libsepol/src/ports.c +52 -37

261 lines not on this page · raw message

libsepol/src/services.c +34 -37

216 lines not on this page · raw message

libsepol/src/users.c +35 -23

185 lines not on this page · raw message