Users/booleans - add some missing functions
- Implement users query()
- Implement booleans query()
- Implement booleans exists()
- Change ports and interface query() to set response to NULL, and return STATUS_SUCCESS if not found, instead of STATUS_NODATA (I'll only use this code in special situations - here this is expected behavior).
Passes valgrind.
libsepol/include/sepol/booleans.h +13 -1
@@ -27,12 +27,24 @@ extern int sepol_genbools_array( int nel);/*---------------end compatbility------------*/ -/* Load a boolean into the policy */ +/* Set the specified boolean */ extern int sepol_bool_set (sepol_policydb_t * policydb,sepol_bool_key_t * key,sepol_bool_t * data); +/* Check if the specified boolean exists */ +extern int sepol_bool_exists ( +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_policydb_t * p, +sepol_bool_key_t * key, +sepol_bool_t ** response); +/* Iterate the booleans * The handler may return: * -1 to signal an error condition,
libsepol/include/sepol/interfaces.h +4 -2
@@ -11,13 +11,15 @@ extern int sepol_iface_exists( sepol_iface_key_t* key, int* response); -/* Query an interface */ +/* Query an interface - returns the interface, +* or NULL if not found */ extern int sepol_iface_query (sepol_policydb_t * policydb,sepol_iface_key_t * key,sepol_iface_t ** response); -/* Add an interface to policy */ +/* Modify an interface, or add it, if the key +* is not found */ extern int sepol_iface_modify( sepol_policydb_t* policydb, sepol_iface_key_t* key,
libsepol/include/sepol/ports.h +2 -2
@@ -11,13 +11,13 @@ extern int sepol_port_exists( sepol_port_key_t* key, int* response); -/* Query a port */ +/* Query a port - returns the port, or NULL if not found */ extern int sepol_port_query (sepol_policydb_t * policydb,sepol_port_key_t * key,sepol_port_t ** response); -/* Modify a port into policy */ +/* Modify a port, or add it, if the key is not found */ extern int sepol_port_modify( sepol_policydb_t* policydb, sepol_port_key_t* key,
libsepol/include/sepol/users.h +7 -1
@@ -23,7 +23,7 @@ extern void sepol_set_delusers(int on);/*--------end compatibility----------*/ -/* Add the user if missing, or modify otherwise */ +/* Modify the user, or add it, if the key is not found */ extern int sepol_user_modify( sepol_policydb_t* policydb, sepol_user_key_t* key,
@@ -35,6 +35,12 @@ extern int sepol_user_exists( sepol_user_key_t* key, int* response); +/* Query a user - returns the user or NULL if not found */ +extern int sepol_user_query ( +sepol_policydb_t * p, +sepol_user_key_t * key, +sepol_user_t ** response); +/* Iterate the users * The handler may return: * -1 to signal an error condition,
libsepol/src/booleans.c +58 -0
64 lines not on this page · raw message
libsepol/src/interfaces.c +3 -1
@@ -143,7 +143,9 @@ int sepol_iface_query (return STATUS_SUCCESS ; } } -return STATUS_NODATA ; + + *response =NULL ; +return STATUS_SUCCESS ; err:DEBUG (__FUNCTION__,"could not query interface %s\n" , name);
libsepol/src/ports.c +2 -1
@@ -194,7 +194,8 @@ int sepol_port_query( } } -return STATUS_NODATA ; + *response =NULL ; +return STATUS_SUCCESS ; err: DEBUG(__FUNCTION__, "could not get context for port %i:%d-%d\n",
libsepol/src/users.c +36 -0
@@ -312,6 +312,42 @@ int sepol_user_exists(return STATUS_SUCCESS ; } +int sepol_user_query ( +sepol_policydb_t * p, +sepol_user_key_t * key, +sepol_user_t ** response) { + +policydb_t * policydb = &p->p; +user_datum_t * usrdatum =NULL ; + +const char * cname; +char * name =NULL ; +sepol_user_key_unpack (key, &cname); + name =strdup (cname); + +if (!name) { +/* FIXME: handle error */ + goto err; + } + + usrdatum =hashtab_search (policydb->p_users.table, name); +if (!usrdatum) { + *response =NULL ; +return STATUS_SUCCESS ; + } + +if (user_to_record (policydb, usrdatum->value -1 , response) <0 ) + goto err; + +free (name); +return STATUS_SUCCESS ; + + err: +/* FIXME: handle error */ +free (name); +return STATUS_ERR ; +} + int sepol_user_iterate( sepol_policydb_t* p, int (*fn)(