Count functions
- implements count() for users, ports, booleans, and interfaces.
I think that completes the interface for now.delete() ... won't be implemented at this time, since changes are done by modify or set on commit. list() - I'll implement on top of iterate in semanage.
next:
- must pass the handle everywhere
- must fix the port modify() function to do the right thing
libsepol/include/sepol/booleans.h +5 -0
@@ -33,6 +33,11 @@ extern int sepol_bool_set ( sepol_bool_key_t* key, sepol_bool_t* data); +/* Return the number of booleans */ +extern int sepol_bool_count ( +sepol_policydb_t * p, +int * response); +/* Check if the specified boolean exists */ extern int sepol_bool_exists( sepol_policydb_t* policydb,
libsepol/include/sepol/interfaces.h +5 -0
@@ -5,6 +5,11 @@#include <sepol/iface_record.h> #include <stddef.h> +/* Return the number of interfaces */ +extern int sepol_iface_count ( +sepol_policydb_t * p, +int * response); +/* Check if an interface exists */ extern int sepol_iface_exists( sepol_policydb_t* policydb,
libsepol/include/sepol/ports.h +5 -0
@@ -5,6 +5,11 @@#include <sepol/port_record.h> #include <stddef.h> +/* Return the number of ports */ +extern int sepol_port_count ( +sepol_policydb_t * p, +int * response); +/* Check if a port exists */ extern int sepol_port_exists( sepol_policydb_t* policydb,
libsepol/include/sepol/users.h +5 -0
@@ -29,6 +29,11 @@ extern int sepol_user_modify( sepol_user_key_t* key, sepol_user_t* data); +/* Return the number of users */ +extern int sepol_user_count ( +sepol_policydb_t * p, +int * response); +/* Check if the specified user exists */ extern int sepol_user_exists( sepol_policydb_t* policydb,
libsepol/src/booleans.c +9 -0
@@ -102,6 +102,15 @@ int sepol_bool_set (return STATUS_ERR ; } +int sepol_bool_count ( +sepol_policydb_t * p, +int * response) { + +policydb_t * policydb = &p->p; + *response = policydb->p_bools.nprim; +return STATUS_SUCCESS ; +} + int sepol_bool_exists( sepol_policydb_t* p, sepol_bool_key_t* key,
libsepol/src/interfaces.c +17 -0
@@ -201,6 +201,23 @@ int sepol_iface_modify(return STATUS_ERR ; } +/* Return the number of interfaces */ +extern int sepol_iface_count ( +sepol_policydb_t * p, +int * response) { + +int count =0 ; +ocontext_t *c, *head; +policydb_t * policydb = &p->p; + + head = policydb->ocontexts[OCON_NETIF ]; +for (c = head; c !=NULL ; c = c->next) + count++; + + *response = count; +return STATUS_SUCCESS ; +} + int sepol_iface_iterate( sepol_policydb_t* p, int (*fn)(
libsepol/src/ports.c +17 -0
@@ -130,6 +130,23 @@ static int port_to_record (return STATUS_ERR ; } +/* Return the number of ports */ +extern int sepol_port_count ( +sepol_policydb_t * p, +int * response) { + +int count =0 ; +ocontext_t *c, *head; +policydb_t * policydb = &p->p; + + head = policydb->ocontexts[OCON_PORT ]; +for (c = head; c !=NULL ; c = c->next) + count++; + + *response = count; +return STATUS_SUCCESS ; +} +/* Check if a port exists */ int sepol_port_exists ( sepol_policydb_t* p,
libsepol/src/users.c +9 -0
@@ -312,6 +312,15 @@ int sepol_user_exists(return STATUS_SUCCESS ; } +int sepol_user_count ( +sepol_policydb_t * p, +int * response) { + +policydb_t * policydb = &p->p; + *response = policydb->p_users.nprim; +return STATUS_SUCCESS ; +} + int sepol_user_query( sepol_policydb_t* p, sepol_user_key_t* key,