User and port apis - policy database
The following patch adds the relay functions (implements some, and stubs others) to dbase for user and port policy databases (as opposed to file databases). These are the users and ports _in policy_ - you'd call those functions to add/modify a semanage user in active policy, or to iterate all the users in active policy, etc..
I intend to expose some of those APIs to libsemanage clients, but I haven't decided which ones right now (the modify APIs likely should not be exposed, since policy modifications are all done on commit, internally), so for now all those functions are internal only. The idea is to have two sets of functions - one which works on locally customizable users/ports, and the other works on all users/ports in the expanded policy.
These functions aren't quite as simple as the ones in users.c, and ports.c, because the database works in terms of sepol objects, and we need to convert the semanage objects to those. "Convert" right now means a simple cast, but in case that every changes, I've made it into an (inlined) function.
==================
Also in this patch:
- use the inline functions that get each database from the handle in direct_api.c and handle.c
- rename DBASE_BASE to DBASE_POLICY, since BASE implies working on "base.pp", while here we are working on "policy.kern".
src/direct_api.c +12 -8
@@ -80,17 +80,21 @@/* set up function pointers */ sh->funcs = &direct_funcs; -if (user_direct_dbase_init (&sh->dbase[DBASE_BASE_USERS ]) <0 ) +if (user_direct_dbase_init ( +semanage_user_dbase_policy (sh)) <0 ) goto err; -if (port_direct_dbase_init (&sh->dbase[DBASE_BASE_PORTS ]) <0 ) +if (port_direct_dbase_init ( +semanage_port_dbase_policy (sh)) <0 ) goto err;#if 0 -if (iface_direct_dbase_init (&sh->dbase[DBASE_BASE_INTERFACES ]) <0 ) +if (iface_direct_dbase_init ( +semanage_iface_dbase_policy (sh)) <0 ) goto err; -if (bool_direct_dbase_init (&sh->dbase[DBASE_BASE_BOOLEANS ]) <0 ) +if (bool_direct_dbase_init ( +semanage_bool_dbase_policy (sh)) <0 ) goto err;#endif
@@ -118,11 +122,11 @@ }/* Remove object databases */ -user_direct_dbase_release (sh, &sh->dbase[DBASE_BASE_USERS ]); -port_direct_dbase_release (sh, &sh->dbase[DBASE_BASE_PORTS ]); +user_direct_dbase_release (sh,semanage_user_dbase_policy (sh)); +port_direct_dbase_release (sh,semanage_port_dbase_policy (sh));#if 0 -iface_direct_dbase_release (sh, &sh->dbase[DBASE_BASE_INTERFACES ]); -bool_direct_dbase_release (sh, &sh->dbase[DBASE_BASE_BOOLEANS ]); +iface_direct_dbase_release (sh,semanage_iface_dbase_policy (sh)); +bool_direct_dbase_release (sh,semanage_port_dbase_policy (sh));#endif return 0 ;
src/handle.c +10 -10
@@ -75,19 +75,19 @@/* Configure object databases * Hardcore DATA FILE backend for now */ -if (user_file_dbase_init (&sh->dbase[DBASE_USERS ]) <0 ) +if (user_file_dbase_init (semanage_user_dbase (sh)) <0 ) goto err; -if (port_file_dbase_init (&sh->dbase[DBASE_PORTS ]) <0 ) +if (port_file_dbase_init (semanage_port_dbase (sh)) <0 ) goto err; -if (iface_file_dbase_init (&sh->dbase[DBASE_INTERFACES ]) <0 ) +if (iface_file_dbase_init (semanage_iface_dbase (sh)) <0 ) goto err; -if (bool_file_dbase_init (&sh->dbase[DBASE_BOOLEANS ]) <0 ) +if (bool_file_dbase_init (semanage_bool_dbase (sh)) <0 ) goto err; -if (seuser_file_dbase_init (&sh->dbase[DBASE_SEUSERS ]) <0 ) +if (seuser_file_dbase_init (semanage_seuser_dbase (sh)) <0 ) goto err;return sh;
@@ -140,11 +140,11 @@semanage_conf_destroy (sh->conf);/* Free object databases */ -user_file_dbase_release (sh, &sh->dbase[DBASE_USERS ]); -port_file_dbase_release (sh, &sh->dbase[DBASE_PORTS ]); -iface_file_dbase_release (sh, &sh->dbase[DBASE_INTERFACES ]); -bool_file_dbase_release (sh, &sh->dbase[DBASE_BOOLEANS ]); -seuser_file_dbase_release (sh, &sh->dbase[DBASE_SEUSERS ]); +user_file_dbase_release (sh,semanage_user_dbase (sh)); +port_file_dbase_release (sh,semanage_port_dbase (sh)); +iface_file_dbase_release (sh,semanage_iface_dbase (sh)); +bool_file_dbase_release (sh,semanage_bool_dbase (sh)); +seuser_file_dbase_release (sh,semanage_seuser_dbase (sh));free (sh); }
src/handle.h +12 -12
@@ -79,11 +79,11 @@#define DBASE_BOOLEANS 3#define DBASE_SEUSERS 4 -#define DBASE_BASE_USERS 5 -#define DBASE_BASE_PORTS 6 +#define DBASE_POLICY_USERS 5 +#define DBASE_POLICY_PORTS 6#if 0 -#define DBASE_BASE_INTERFACES 7 -#define DBASE_BASE_BOOLEANS 8 +#define DBASE_POLICY_INTERFACES 7 +#define DBASE_POLICY_BOOLEANS 8#endif dbase_config_t dbase[DBASE_COUNT ]; };
@@ -114,24 +114,24 @@ }static inline -dbase_config_t *semanage_base_user_dbase (semanage_handle_t * handle) { -return &handle->dbase[DBASE_BASE_USERS ]; +dbase_config_t *semanage_user_dbase_policy (semanage_handle_t * handle) { +return &handle->dbase[DBASE_POLICY_USERS ]; }static inline -dbase_config_t *semanage_base_port_dbase (semanage_handle_t * handle) { -return &handle->dbase[DBASE_BASE_PORTS ]; +dbase_config_t *semanage_port_dbase_policy (semanage_handle_t * handle) { +return &handle->dbase[DBASE_POLICY_PORTS ]; }#if 0 static inline -dbase_config_t *semanage_base_iface_dbase (semanage_handle_t * handle) { -return &handle->dbase[DBASE_BASE_INTERFACES ]; +dbase_config_t *semanage_iface_dbase_policy (semanage_handle_t * handle) { +return &handle->dbase[DBASE_POLICY_INTERFACES ]; }static inline -dbase_config_t *semanage_base_bool_dbase (semanage_handle_t * handle) { -return &handle->dbase[DBASE_BASE_BOOLEANS ]; +dbase_config_t *semanage_bool_dbase_policy (semanage_handle_t * handle) { +return &handle->dbase[DBASE_POLICY_BOOLEANS ]; }#endif
src/ports_policy.c +144 -16
194 lines not on this page · raw message
src/ports_policy.h +40 -9
58 lines not on this page · raw message
src/users_policy.c +143 -15
185 lines not on this page · raw message
src/users_policy.h +40 -9
58 lines not on this page · raw message
By the way, I don't particularly enjoy writing the same APIs and relay functions for each record (even though I didn't actually write them 5 times, I just ran an example through sed). If you prefer I can try to come up with some macro scheme to write them once, and include ".c" file or something like that... but that would complicate things....
--
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.