Add seuser and user_extra to package format
PATCH 1/1 Add seuser and user_extra to package format
This patch adds seuser and user_extra to the package format, adds arguments to semodule_package and libsemanage code to write the files to the store.
src/direct_api.c +19 -3
@@ -406,7 +406,7 @@ static int semanage_write_module(semanag*/ static int semanage_direct_commit (semanage_handle_t *sh) {char **mod_filenames =NULL ; -const char *linked_filename =NULL , *fc_filename =NULL ; +const char *linked_filename =NULL , *ofilename =NULL ;sepol_module_package_t *base =NULL ;int retval =-1 , num_modfiles =0 , i;sepol_policydb_t * out =NULL ;
@@ -476,8 +476,8 @@ static int semanage_direct_commit(semana/* ==================== File contexts ================== */ /* write the linked file contexts template */ -if ((fc_filename =semanage_path (SEMANAGE_TMP ,SEMANAGE_FC_TMPL )) ==NULL || -write_file (sh, fc_filename,sepol_module_package_get_file_contexts (base), +if ((ofilename =semanage_path (SEMANAGE_TMP ,SEMANAGE_FC_TMPL )) ==NULL || +write_file (sh, ofilename,sepol_module_package_get_file_contexts (base),sepol_module_package_get_file_contexts_len (base)) ==-1 ) { goto cleanup; }
@@ -488,6 +488,22 @@ static int semanage_direct_commit(semana pfcontexts->dtable->drop_cache (pfcontexts->dbase);/* ==================== Other file-backed ================== */ + +if (sepol_module_package_get_seusers_len (base)) { +if ((ofilename =semanage_path (SEMANAGE_TMP ,SEMANAGE_SEUSERS_SYSTEM )) ==NULL || +write_file (sh, ofilename,sepol_module_package_get_seusers (base), +sepol_module_package_get_seusers_len (base)) ==-1 ) { + goto cleanup; + } + } + +if (sepol_module_package_get_user_extra_len (base)) { +if ((ofilename =semanage_path (SEMANAGE_TMP ,SEMANAGE_USER_EXTRA_SYSTEM )) ==NULL || +write_file (sh, ofilename,sepol_module_package_get_user_extra (base), +sepol_module_package_get_user_extra_len (base)) ==-1 ) { + goto cleanup; + } + }/* Clear any cache, will be regenerated */ if (pusers_extra->dtable->clear (sh, pusers_extra->dbase) <0 )
src/semanage_store.c +3 -1
@@ -96,7 +96,9 @@ static const char *semanage_sandbox_path"/homedir_template" ,"/file_contexts.template" ,"/commit_num" , - "/seusers.final" +"/seusers.final" , +"/seusers.system" , + "/users_extra.system" };/* Initialize the paths to config file, lock files and store root.
src/semanage_store.h +2 -0
@@ -46,6 +46,8 @@ enum semanage_sandbox_defs {SEMANAGE_FC_TMPL ,SEMANAGE_COMMIT_NUM_FILE ,SEMANAGE_SEUSERS , +SEMANAGE_SEUSERS_SYSTEM , +SEMANAGE_USER_EXTRA_SYSTEM , SEMANAGE_STORE_NUM_PATHS };
include/sepol/module.h +17 -0
@@ -25,6 +25,23 @@ extern int sepol_module_package_set_filechar *data, size_t len); +extern char *sepol_module_package_get_seusers (sepol_module_package_t *p); + +extern size_t sepol_module_package_get_seusers_len (sepol_module_package_t *p); + +extern int sepol_module_package_set_seusers (sepol_module_package_t *p, +char *data, +size_t len); + +extern char *sepol_module_package_get_user_extra (sepol_module_package_t *p); + +extern size_t sepol_module_package_get_user_extra_len (sepol_module_package_t *p); + +extern int sepol_module_package_set_user_extra (sepol_module_package_t *p, +char *data, +size_t len); + +extern sepol_policydb_t *sepol_module_package_get_policy (sepol_module_package_t *p); extern int sepol_link_packages(sepol_handle_t *handle,
include/sepol/policydb/module.h +4 -0
@@ -35,6 +35,10 @@ struct sepol_module_package {uint32_t version;char *file_contexts;size_t file_contexts_len; +char *seusers; +size_t seusers_len; +char *user_extra; +size_t user_extra_len; };extern int sepol_module_package_init (sepol_module_package_t *p);
src/module.c +192 -30
315 lines not on this page · raw message
semodule_package/semodule_package.c +43 -6
95 lines not on this page · raw message
Please try with the following patch on top:
- removes system databases, which are unnecessary, write directly to the final file
- fix 64-bit bugs Joshua's introducing :)
I will resync my nodecon patch tomorrow - let me know if anything's wrong with it, otherwise will submit as is (ordering pending in a later patch).
libsemanage/src/direct_api.c +9 -26
@@ -150,15 +150,6 @@ int semanage_direct_connect(semanage_han semanage_seuser_dbase_local(sh)) < 0) goto err; -/* Object databases: policy */ -if (user_extra_file_dbase_init (sh,"users_extra.system" , -semanage_user_extra_dbase_system (sh)) <0 ) - goto err; - -if (seuser_file_dbase_init (sh,"seusers.system" , -semanage_seuser_dbase_system (sh)) <0 ) - goto err; -/* Object databases: local modifications + policy */ if (user_base_policydb_dbase_init (sh,semanage_user_base_dbase_policy (sh)) <0 )
@@ -229,10 +220,6 @@ static int semanage_direct_disconnect(sefcontext_file_dbase_release (semanage_fcontext_dbase_local (sh));seuser_file_dbase_release (semanage_seuser_dbase_local (sh)); -/* Release object databases: policy */ -user_extra_file_dbase_release (semanage_user_extra_dbase_system (sh)); -seuser_file_dbase_release (semanage_seuser_dbase_system (sh)); -/* Release object databases: local modifications + policy */ user_base_policydb_dbase_release (semanage_user_base_dbase_policy (sh));user_extra_file_dbase_release (semanage_user_extra_dbase_policy (sh));
@@ -473,7 +460,7 @@ static int semanage_direct_commit(semana goto cleanup; } -/* ==================== File contexts ================== */ +/* ==================== File-backed ================== */ /* write the linked file contexts template */ if ((ofilename = semanage_path(SEMANAGE_TMP, SEMANAGE_FC_TMPL)) == NULL ||
@@ -482,15 +469,11 @@ static int semanage_direct_commit(semana goto cleanup; } -/* Create file_contexts(.homedirs) and drop any previous cache */ if (semanage_split_fc (sh)) goto cleanup; - pfcontexts->dtable->drop_cache (pfcontexts->dbase); - -/* ==================== Other file-backed ================== */ if (sepol_module_package_get_seusers_len (base)) { -if ((ofilename =semanage_path (SEMANAGE_TMP ,SEMANAGE_SEUSERS_SYSTEM )) ==NULL || +if ((ofilename =semanage_path (SEMANAGE_TMP ,SEMANAGE_SEUSERS )) ==NULL ||write_file (sh, ofilename,sepol_module_package_get_seusers (base),sepol_module_package_get_seusers_len (base)) ==-1 ) { goto cleanup;
@@ -498,19 +481,19 @@ static int semanage_direct_commit(semana }if (sepol_module_package_get_user_extra_len (base)) { -if ((ofilename =semanage_path (SEMANAGE_TMP ,SEMANAGE_USER_EXTRA_SYSTEM )) ==NULL || +if ((ofilename =semanage_path (SEMANAGE_TMP ,SEMANAGE_USER_EXTRA )) ==NULL ||write_file (sh, ofilename,sepol_module_package_get_user_extra (base),sepol_module_package_get_user_extra_len (base)) ==-1 ) { goto cleanup; } } -/* Clear any cache, will be regenerated */ -if (pusers_extra->dtable->clear (sh, pusers_extra->dbase) <0 ) - goto cleanup; - -if (pseusers->dtable->clear (sh, pseusers->dbase) <0 ) - goto cleanup; +/* Drop any cached content for file_contexts, seusers, or users_extra, +* since it is now superceded by the files just written, and needs to be +* re-cached */ + pfcontexts->dtable->drop_cache (pfcontexts->dbase); + pseusers->dtable->drop_cache (pseusers->dbase); + pusers_extra->dtable->drop_cache (pusers_extra->dbase);/* ==================== Policydb-backed ================ */
libsemanage/src/handle.h +10 -26
@@ -78,7 +78,7 @@ struct semanage_handle {struct semanage_policy_table * funcs;/* Object databases */ -#define DBASE_COUNT 19 +#define DBASE_COUNT 17/* Local modifications */ #define DBASE_LOCAL_USERS_BASE 0
@@ -90,22 +90,18 @@ struct semanage_handle {#define DBASE_LOCAL_FCONTEXTS 6#define DBASE_LOCAL_SEUSERS 7 -/* Policy */ -#define DBASE_SYSTEM_USERS_EXTRA 8 -#define DBASE_SYSTEM_SEUSERS 9 -/* Policy + Local modifications */ -#define DBASE_POLICY_USERS_BASE 10 -#define DBASE_POLICY_USERS_EXTRA 11 -#define DBASE_POLICY_USERS 12 -#define DBASE_POLICY_PORTS 13 -#define DBASE_POLICY_INTERFACES 14 -#define DBASE_POLICY_BOOLEANS 15 -#define DBASE_POLICY_FCONTEXTS 16 -#define DBASE_POLICY_SEUSERS 17 +#define DBASE_POLICY_USERS_BASE 8 +#define DBASE_POLICY_USERS_EXTRA 9 +#define DBASE_POLICY_USERS 10 +#define DBASE_POLICY_PORTS 11 +#define DBASE_POLICY_INTERFACES 12 +#define DBASE_POLICY_BOOLEANS 13 +#define DBASE_POLICY_FCONTEXTS 14 +#define DBASE_POLICY_SEUSERS 15/* Active kernel policy */ -#define DBASE_ACTIVE_BOOLEANS 18 +#define DBASE_ACTIVE_BOOLEANS 16dbase_config_t dbase[DBASE_COUNT ]; };
@@ -150,18 +146,6 @@ dbase_config_t* semanage_seuser_dbase_loreturn &handle->dbase[DBASE_LOCAL_SEUSERS ]; } -/* === Policy === */ -static inline -dbase_config_t *semanage_user_extra_dbase_system (semanage_handle_t * handle) { -return &handle->dbase[DBASE_SYSTEM_USERS_EXTRA ]; -} - -static inline -dbase_config_t *semanage_seuser_dbase_system (semanage_handle_t * handle) { -return &handle->dbase[DBASE_SYSTEM_SEUSERS ]; -} - -/* === Policy + Local modifications === */ static inline dbase_config_t *semanage_user_base_dbase_policy (semanage_handle_t * handle) {
libsemanage/src/policy_components.c +0 -6
@@ -130,9 +130,6 @@ int semanage_base_merge_components( {semanage_user_base_dbase_local (handle), semanage_user_base_dbase_policy(handle), MODE_MODIFY }, - { semanage_user_extra_dbase_system(handle), - semanage_user_extra_dbase_policy(handle), MODE_MODIFY }, - { semanage_user_extra_dbase_local(handle), semanage_user_extra_dbase_policy(handle), MODE_MODIFY },
@@ -148,9 +145,6 @@ int semanage_base_merge_components( {semanage_fcontext_dbase_local (handle), semanage_fcontext_dbase_policy(handle), MODE_MODIFY }, - { semanage_seuser_dbase_system(handle), - semanage_seuser_dbase_policy(handle), MODE_MODIFY }, - { semanage_seuser_dbase_local(handle), semanage_seuser_dbase_policy(handle), MODE_MODIFY }, };
libsemanage/src/semanage_store.c +1 -2
@@ -97,8 +97,7 @@ static const char *semanage_sandbox_path"/file_contexts.template" ,"/commit_num" ,"/seusers.final" , -"/seusers.system" , - "/users_extra.system" + "/users_extra", };/* Initialize the paths to config file, lock files and store root.
libsemanage/src/semanage_store.h +1 -2
@@ -46,8 +46,7 @@ enum semanage_sandbox_defs {SEMANAGE_FC_TMPL ,SEMANAGE_COMMIT_NUM_FILE ,SEMANAGE_SEUSERS , -SEMANAGE_SEUSERS_SYSTEM , -SEMANAGE_USER_EXTRA_SYSTEM , +SEMANAGE_USER_EXTRA , SEMANAGE_STORE_NUM_PATHS };
libsepol/src/module.c +6 -3
@@ -460,7 +460,8 @@ int sepol_module_package_read(sepol_modubreak ;default :/* unknown section, ignore */ -ERR (file->handle,"unknown magic number at section %u, offset: %zx, number: %zx " ,i, offsets[i],le32_to_cpu (buf[0 ])); +ERR (file->handle,"unknown magic number at section %u, offset: %zx, number: %ux " , + i, offsets[i],le32_to_cpu (buf[0 ]));break ; } }
@@ -636,8 +637,10 @@ cleanup:return -1 ; } -static int write_helper (char *data,int len,struct policy_file *file) { -int idx =0 , len2; +static int write_helper (char *data,size_t len,struct policy_file *file) { +int idx =0 ; +size_t len2; +while (len) {if (len >BUFSIZ ) len2 =BUFSIZ ;
Quoted 7 lines · Ivan Gyurdiev
Please try with the following patch on top:
- removes system databases, which are unnecessary, write directly to the final file
- fix 64-bit bugs Joshua's introducing :)I will resync my nodecon patch tomorrow - let me know if anything's wrong with it, otherwise will submit as is (ordering pending in a later patch).
<snip>
libsepol/src/module.c int sepol_module_package_read(sepol_modu · line 466
Quoted 12 lines
diff -Naurp --exclude-from excludes
old/libsepol/src/module.cnew/libsepol/src/module.clibsepol/src/module.c +2
-1@@ -460,7 +460,8 @@ int sepol_module_package_read(sepol_modubreak ;default :/* unknown section, ignore */ -ERR (file->handle,"unknown magic number at section %u, offset: %zx, number: %zx " ,i, offsets[i],le32_to_cpu (buf[0 ])); +ERR (file->handle,"unknown magic number at section %u, offset: %zx, number: %ux " , + i, offsets[i],le32_to_cpu (buf[0 ]));break ; }
oops, I meant to remove that, it was there for debugging.
--
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 5 lines · Ivan Gyurdiev
Please try with the following patch on top:
- removes system databases, which are unnecessary, write directly to the final file
- fix 64-bit bugs Joshua's introducing :)
Merged both patches.
Quoted 3 lines
I will resync my nodecon patch tomorrow - let me know if anything's wrong with it, otherwise will submit as is (ordering pending in a later patch).
I still wasn't clear on the disposition of the pylist patch.
For the nodecon patch, I wasn't sure if we were sufficiently confident in the ABI/API stability to include it for FC5 or if it should wait on FC6 devel. It would likely help to have feedback from potential users of the nodecon API.
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
Quoted 3 lines
I will resync my nodecon patch tomorrow - let me know if anything's wrong with it, otherwise will submit as is (ordering pending in a later patch).
I still wasn't clear on the disposition of the pylist patch.
I think the typemap code would be sufficiently different in diff. languages, that we can (and will have to) write a completely new .i file for another language. I doubt the current typemap code is language portable (I don't know how adding things to output vector will translate to other languages). It seems to me that the portable portion of the code is generated by swig, and any typemaps we add on top will be mostly language specific.
Dan, maybe you can comment on this. I added a patch that translates out-bound C list (type**, int) to an actual PyList, which is garbage collected, and you can have a for-in loop range over it without an index, and you don't need get_*_by_idx. There are probably other advantages that I don't know about. Would this be useful to a python developer? What about an in-bound PyList (for set_roles)? Do iterate() function pointers work currently? If not, maybe better python integration can help make them work?
Quoted 5 lines
For the nodecon patch, I wasn't sure if we were sufficiently confident in the ABI/API stability to include it for FC5 or if it should wait on FC6 devel. It would likely help to have feedback from potential users of the nodecon API.
Ok... I would like to hear any recommendations on byte order/byte array handling.
--
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 9 lines · Ivan Gyurdiev
Quoted 6 lines
Quoted 3 lines
I will resync my nodecon patch tomorrow - let me know if anything's wrong with it, otherwise will submit as is (ordering pending in a later patch).
I still wasn't clear on the disposition of the pylist patch.
I think the typemap code would be sufficiently different in diff. languages, that we can (and will have to) write a completely new .i file for another language. I doubt the current typemap code is language portable (I don't know how adding things to output vector will translate to other languages). It seems to me that the portable portion of the code is generated by swig, and any typemaps we add on top will be mostly language specific.
Dan, maybe you can comment on this. I added a patch that translates out-bound C list (type**, int) to an actual PyList, which is garbage collected, and you can have a for-in loop range over it without an index, and you don't need get_*_by_idx. There are probably other advantages that I don't know about. Would this be useful to a python developer? What about an in-bound PyList (for
set_roles)? Doiterate()function pointers work currently? If not, maybe better python integration can help make them work?
Yes I think that would be preferable to the current rather clunky interface.
Quoted 7 lines
Quoted 6 lines
For the nodecon patch, I wasn't sure if we were sufficiently confident in the ABI/API stability to include it for FC5 or if it should wait on FC6 devel. It would likely help to have feedback from potential users of the nodecon API.
Ok... I would like to hear any recommendations on byte order/byte array handling.
--
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 7 lines · Stephen Smalley
Quoted 5 lines · Ivan Gyurdiev
Please try with the following patch on top:
- removes system databases, which are unnecessary, write directly to the final file
- fix 64-bit bugs Joshua's introducing :)
Quoted 5 lines
Merged both patches.
Quoted 1 line
I will resync my nodecon patch tomorrow - let me know if anything's wrong with it, otherwise will submit as is (ordering pending in a later patch).
I still wasn't clear on the disposition of the pylist patch.
IMO we should leave the semanageswig.i as the language neutral interface file (and not remove the _by_idx functions) and make language specific files include it. Then all the common parts are in semanageswig.i and python specific ones are in another file. That way we are free to use better features for python without eliminating the possibility of building the wrappers for another language and it shouldn't make maintenance any harder.
Quoted 6 lines
For the nodecon patch, I wasn't sure if we were sufficiently confident in the ABI/API stability to include it for FC5 or if it should wait on FC6 devel. It would likely help to have feedback from potential users of the nodecon API.
--
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 8 lines · Joshua Brindle
Quoted 7 lines · Stephen Smalley
Quoted 5 lines · Ivan Gyurdiev
Please try with the following patch on top:
- removes system databases, which are unnecessary, write directly to the final file
- fix 64-bit bugs Joshua's introducing :)
Quoted 18 lines
Quoted 5 lines
Merged both patches.
Quoted 1 line
I will resync my nodecon patch tomorrow - let me know if anything's wrong with it, otherwise will submit as is (ordering pending in a later patch).
I still wasn't clear on the disposition of the pylist patch.
IMO we should leave the semanageswig.i as the language neutral interface file (and not remove the
_by_idxfunctions) and make language specific files include it. Then all the common parts are in semanageswig.i and python specific ones are in another file. That way we are free to use better features for python without eliminating the possibility of building the wrappers for another language and it shouldn't make maintenance any harder.Quoted 6 lines
For the nodecon patch, I wasn't sure if we were sufficiently confident in the ABI/API stability to include it for FC5 or if it should wait on FC6 devel. It would likely help to have feedback from potential users of the nodecon API.
I agree.
--
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 3 lines
IMO we should leave the semanageswig.i as the language neutral interface file (and not remove the
_by_idxfunctions) and make language specific files include it. Then all the common parts are in semanageswig.i and python specific ones are in another file. That way we are free to use better features for python without eliminating the possibility of building the wrappers for another language and it shouldn't make maintenance any harder.
Have you tried to see if the current typemaps work on any other language?
I don't think the t_output_helper function you're using is defined in any other language except for python.
--
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 · Ivan Gyurdiev
Quoted 3 lines
IMO we should leave the semanageswig.i as the language neutral interface file (and not remove the
_by_idxfunctions) and make language specific files include it. Then all the common parts are in semanageswig.i and python specific ones are in another file. That way we are free to use better features for python without eliminating the possibility of building the wrappers for another language and it shouldn't make maintenance any harder.Have you tried to see if the current typemaps work on any other language?
I don't think thet_output_helperfunction you're using is defined in any other language except for python.
Ok, it looks like you are right, I just tried it on perl and t_output_helper was undefined. So aside from the #includes and the *_by_idx pretty much everything in the current .i file is python specific.
It looks like this library is sufficiently complex that there will need to be a .i file for each language supported, unfortunately.
We can still use the semanageswig.i to pull in all the headers that we are wrapping and put language specific things in their own .i file.
--
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.