Reorganize users.c
Okay, I need to clean up and stabilize my parts of the sepol API. This is a small patch that works toward that goal.
Patch:
- renames is_valid functions to exists name to match semanage
- renames get_valid_xxx function to list to match semanage (I might still get rid of that function completely later by the way, and only implement it in semanage over sepol iterate - we'll see).
- makes is_valid/exists function update a parameter, rather than mixing response and return status code
- removes sepol_user_add (which we do not need at the sepol layer at this time) - we'll use modify and exists
- moves role-related functions into a file called roles.c, and a header called roles.h. I see the necessity to add a role_record.h, but for now, remove role-related functions from the map file.
TODO:
- figure out whether or not clean_unused_users actually works, how it works (hey... I stole most of it from genusers - I'm still not clear on how this "defined" stuff works entirely)... and probably get rid of it.
- pass handle down where needed
- possibly pass key down where needed (or alternatively, pass the whole record, but do _not_ use specific record fields in the API).
- change ports and interfaces add() -> modify(), so overerides are allowed.
libsemanage/src/users_policydb.c +1 -1
@@ -22,7 +22,7 @@ extern record_table_t SEPOL_USER_RTABLE;/* USER RECRORD (SEPOL): POLICYDB extension: method table */ record_policydb_table_t SEMANAGE_USER_POLICYDB_RTABLE = { - .add = sepol_user_add, + .add =NULL ,/* FIXME */ .modify = sepol_user_modify, .iterate = sepol_user_iterate, };
libsepol/include/sepol/roles.h +14 -0
@@ -0,0 +1,14 @@ +#ifndef _SEPOL_ROLES_H_ +#define _SEPOL_ROLES_H_ + +extern int sepol_role_exists ( +sepol_policydb_t * policydb, +const char * role, +int * response); + +extern int sepol_role_list ( +sepol_policydb_t * policydb, +char *** roles, +size_t * nroles); + +#endif
libsepol/include/sepol/users.h +6 -19
@@ -9,35 +9,27 @@extern void sepol_clear_unused_users (sepol_policydb_t * policydb); -/* Add/delete/load users from the policy -Load allows duplicates, but add does not. */ -extern int sepol_user_add ( -sepol_policydb_t * policydb, -sepol_user_t * user); - +/* Delete the user */ extern int sepol_user_del (sepol_policydb_t * policydb,const char *username); +/* Add the user if missing, or modify otherwise */ extern int sepol_user_modify (sepol_policydb_t * policydb,sepol_user_t * user); -/* Check if users or roles are valid */ -extern int sepol_user_is_valid ( -sepol_policydb_t * policydb, -const char * user); - -extern int sepol_role_is_valid ( +/* Check if the specified user exists */ +extern int sepol_user_exists (sepol_policydb_t * policydb, -const char * role); +const char * user, +int * response);/* Iterate the users * The handler may return: * -1 to signal an error condition, * 1 to signal successful exit * 0 to signal continue */ - extern int sepol_user_iterate( sepol_policydb_t* policydb, int (*fn)(
@@ -45,9 +37,4 @@ extern int sepol_user_iterate( void* fn_arg), void* arg); -extern int sepol_get_valid_roles ( -sepol_policydb_t * policydb, -char *** roles, -size_t * nroles); -#endif
libsepol/src/libsepol.map +1 -1
@@ -20,7 +20,7 @@ sepol_link_modules; sepol_expand_module; sepol_bool*; sepol_context*; sepol_iface*; sepol_port*; sepol_user*; sepol_clear_unused_users; - sepol_role_is_valid; sepol_set_delusers; + sepol_set_delusers; sepol_msg_*; sepol_handle_*; local: *; };
libsepol/src/roles.c +61 -0
61 lines not on this page · raw message
libsepol/src/users.c +6 -88
119 lines not on this page · raw message
Quoted 3 lines
- makes is_valid/exists function update a parameter, rather than mixing response and return status code
Oops...forgot to initialize status in the success path. Corrected patch attach (gets rid of the variable).
libsemanage/src/users_policydb.c +1 -1
@@ -22,7 +22,7 @@ extern record_table_t SEPOL_USER_RTABLE;/* USER RECRORD (SEPOL): POLICYDB extension: method table */ record_policydb_table_t SEMANAGE_USER_POLICYDB_RTABLE = { - .add = sepol_user_add, + .add =NULL ,/* FIXME */ .modify = sepol_user_modify, .iterate = sepol_user_iterate, };
libsepol/include/sepol/roles.h +14 -0
@@ -0,0 +1,14 @@ +#ifndef _SEPOL_ROLES_H_ +#define _SEPOL_ROLES_H_ + +extern int sepol_role_exists ( +sepol_policydb_t * policydb, +const char * role, +int * response); + +extern int sepol_role_list ( +sepol_policydb_t * policydb, +char *** roles, +size_t * nroles); + +#endif
libsepol/include/sepol/users.h +6 -19
@@ -9,35 +9,27 @@extern void sepol_clear_unused_users (sepol_policydb_t * policydb); -/* Add/delete/load users from the policy -Load allows duplicates, but add does not. */ -extern int sepol_user_add ( -sepol_policydb_t * policydb, -sepol_user_t * user); - +/* Delete the user */ extern int sepol_user_del (sepol_policydb_t * policydb,const char *username); +/* Add the user if missing, or modify otherwise */ extern int sepol_user_modify (sepol_policydb_t * policydb,sepol_user_t * user); -/* Check if users or roles are valid */ -extern int sepol_user_is_valid ( -sepol_policydb_t * policydb, -const char * user); - -extern int sepol_role_is_valid ( +/* Check if the specified user exists */ +extern int sepol_user_exists (sepol_policydb_t * policydb, -const char * role); +const char * user, +int * response);/* Iterate the users * The handler may return: * -1 to signal an error condition, * 1 to signal successful exit * 0 to signal continue */ - extern int sepol_user_iterate( sepol_policydb_t* policydb, int (*fn)(
@@ -45,9 +37,4 @@ extern int sepol_user_iterate( void* fn_arg), void* arg); -extern int sepol_get_valid_roles ( -sepol_policydb_t * policydb, -char *** roles, -size_t * nroles); -#endif
libsepol/src/libsepol.map +1 -1
@@ -20,7 +20,7 @@ sepol_link_modules; sepol_expand_module; sepol_bool*; sepol_context*; sepol_iface*; sepol_port*; sepol_user*; sepol_clear_unused_users; - sepol_role_is_valid; sepol_set_delusers; + sepol_set_delusers; sepol_msg_*; sepol_handle_*; local: *; };
libsepol/src/roles.c +60 -0
60 lines not on this page · raw message
libsepol/src/users.c +7 -90
120 lines not on this page · raw message
Quoted 2 lines · Ivan Gyurdiev
Okay, I need to clean up and stabilize my parts of the sepol API. This is a small patch that works toward that goal.
<snip>
Quoted 3 lines
- figure out whether or not
clean_unused_usersactually works, how it works (hey... I stole most of it from genusers - I'm still not clear on how this "defined" stuff works entirely)... and probably get rid of it.
I thought delete was going away from sepol, as all local customizations outside of policy modules will be add-or-modify or modify-if-exists.
For genusers, we processed both system.users (generated from the policy users file) and local.users, marking each user in the policydb as defined if it had an entry in either of those files, and then (if delusers was enabled) purged users that had no definition at all in the flat files. Hence, you could remove a user by modifying a flat file. However, as that was viewed as too dangerous (risk of losing your system_u, user_u, and root entries), it was disabled by default.
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Quoted 4 lines
I thought delete was going away from sepol, as all local customizations outside of policy modules will be add-or-modify or modify-if-exists.
Hmm, sure we can get rid of delete...
Quoted 8 lines
For genusers, we processed both system.users (generated from the policy users file) and local.users, marking each user in the policydb as defined if it had an entry in either of those files, and then (if delusers was enabled) purged users that had no definition at all in the flat files. Hence, you could remove a user by modifying a flat file. However, as that was viewed as too dangerous (risk of losing your
system_u,user_u, and root entries), it was disabled by default.
Where do you set defined = 0 ? Calloc?
What's the benefit of this - should we remove this function (and the corresponding policydb field)? (or are you thinking of adding a preserve users flag to load_policy ? )
--
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.
Quoted 1 line · Ivan Gyurdiev
Where do you set defined = 0 ? Calloc?
memset in user_read(). The field only exists in the in-memory policydb, not the binary policy image / file.
Quoted 3 lines
What's the benefit of this - should we remove this function (and the corresponding policydb field)?
(or are you thinking of adding a preserve users flag toload_policy? )
I think we can remove delete support (and use of ->defined) from your new functions, but I'd leave the field and the genusers code alone. No one is using it AFAIK, but sepol_set_delusers is part of the ABI of prior releases of libsepol.
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Quoted 6 lines
I think we can remove delete support (and use of ->defined) from your new functions, but I'd leave the field and the genusers code alone. No one is using it AFAIK, but
sepol_set_delusersis part of the ABI of prior releases of libsepol.
Ok agreed...
--
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.
Quoted 4 lines · Ivan Gyurdiev
Quoted 2 lines
- makes is_valid/exists function update a parameter, rather than mixing response and return status code
Oops...forgot to initialize status in the success path. Corrected patch attach (gets rid of the variable).
Merged as of libsepol 1.9.24 and libsemanage 1.3.31.
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.