I am concerned about putting genhomedircon changesinlibsemanage into Fedora 8.
Subsystems (2)
Quoted 7 lines · Daniel J Walsh
Already have it.
This is a repatch off of libsemanage-2.0.9
It should include your stuff plus it gets the
fallback_userby looking up the__default__login record.
Quoted 8 lines
That way if I change the
__default__record to usexguest_u, it will build all user accounts with this context.
getpwnam_rreturns 0 even if an account does not exist.So you need to check the pointer.
A couple of other translation problems also.
Unfortunately, the return values for getpwnam_r() and getpwent_r() are inconsistent. While getpwnam_r() returns 0 when the user does not exist, getpwent_r() returns ENOENT. I decided to deal with both semantics in the same way so if they are every brought into line the code will still do the right thing.
I made similar fixes to yours for the seuser vs. user mismatches. A merge of your diff and mine follows. I added some error condition fixes and made the style more consistent.
- todd
include/semanage/handle.h +4 -0
@@ -69,6 +69,10 @@* 1 for yes, 0 for no (default) */ void semanage_set_create_store (semanage_handle_t * handle,int create_store); +/* set whether to generate homedir file context +* 1 for yes (default), 0 for no */ +void semanage_set_rebuild_file_context (semanage_handle_t * handle,int do_rebuild_file_context); +/* Set whether or not to disable dontaudits upon commit */ void semanage_set_disable_dontaudit (semanage_handle_t * handle,int disable_dontaudit);
src/handle.h +1 -0
@@ -58,6 +58,7 @@int is_connected;int is_in_transaction;int do_reload;/* whether to reload policy after commit */ +int do_rebuild_file_context;/* whether to generate homedircontext */ int do_rebuild;/* whether to rebuild policy if there were no changes */ int modules_modified;int create_store;/* whether to create the store if it does not exist
src/libsemanage.map +1 -0
@@ -9,6 +9,7 @@ semanage_module_list_nth; semanage_module_get_name; semanage_module_get_version; semanage_select_store; semanage_reload_policy; semanage_set_reload; semanage_set_rebuild; + semanage_set_rebuild_file_context; semanage_user_*; semanage_bool_*; semanage_seuser_*; semanage_iface_*; semanage_port_*; semanage_context_*; semanage_node_*;
src/genhomedircon.c +168 -35
379 lines not on this page · raw message
src/genhomedircon.h +2 -1
@@ -22,6 +22,7 @@#include "utilities.h" -int semanage_genhomedircon (semanage_handle_t * sh,int usepasswd); +int semanage_genhomedircon (semanage_handle_t * sh, +sepol_policydb_t * policydb,int usepasswd);#endif
src/direct_api.c +1 -1
@@ -702,7 +702,7 @@ goto cleanup;if (sh->do_rebuild || modified) { - retval =semanage_install_sandbox (sh); + retval =semanage_install_sandbox (sh, out); } cleanup:
src/semanage_store.c +4 -3
@@ -1148,7 +1148,7 @@ skip_reload: -if ((r = +if (sh->do_rebuild_file_context && (r =semanage_exec_prog (sh, sh->conf->setfiles, store_pol, store_fc)) !=0 ) {ERR (sh,"setfiles returned error code %d." , r);
@@ -1279,7 +1279,8 @@* should be placed within a mutex lock to ensure that it runs * atomically. Returns commit number on success, -1 on error. */ -int semanage_install_sandbox (semanage_handle_t * sh) +int semanage_install_sandbox (semanage_handle_t * sh, +sepol_policydb_t * policydb) {int retval =-1 , commit_num =-1 ;
@@ -1294,7 +1295,7 @@ }if (!sh->conf->disable_genhomedircon) {if ((retval = -semanage_genhomedircon (sh, TRUE)) !=0 ) { +semanage_genhomedircon (sh, policydb, TRUE)) !=0 ) {ERR (sh,"semanage_genhomedircon returned error code %d." , retval); goto cleanup;
src/semanage_store.h +2 -3
@@ -83,8 +83,6 @@int semanage_get_modules_names (semanage_handle_t * sh,char ***filenames,int *len); -int semanage_install_sandbox (semanage_handle_t * sh); -/* lock file routines */ int semanage_get_trans_lock (semanage_handle_t * sh);int semanage_get_active_lock (semanage_handle_t * sh);
@@ -102,7 +100,8 @@int semanage_write_policydb (semanage_handle_t * sh,sepol_policydb_t * policydb); -int semanage_install_sandbox (semanage_handle_t * sh); +int semanage_install_sandbox (semanage_handle_t * sh, +sepol_policydb_t * policydb);int semanage_verify_modules (semanage_handle_t * sh,char **module_filenames,int num_modules);
src/handle.c +12 -0
@@ -68,6 +68,9 @@/* By default do not create store */ sh->create_store =0 ; +/* Rebuild the file_contexts by default */ + sh->do_rebuild_file_context =1 ; +/* Set timeout: some default value for now, later use config */ sh->timeout =SEMANAGE_COMMIT_READ_WAIT ;
@@ -100,6 +103,15 @@return ; } +void semanage_set_rebuild_file_context (semanage_handle_t * sh,int do_rebuild_file_context) +{ + +assert (sh !=NULL ); + + sh->do_rebuild_file_context = do_rebuild_file_context; +return ; +} +void semanage_set_create_store (semanage_handle_t * sh,int create_store) {
Makefile +3 -0
@@ -1,6 +1,9 @@ all: $(MAKE) -C src all +swigify: + $(MAKE) -C src swigify + pywrap: $(MAKE) -C src pywrap
--
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.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Looks good to me.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFG+9P7rlYvE4MpobMRAo4OAKDXNhcDMjVf/0u+fFtnYImC6vIxOgCgtjwq C1RVGkz2aUjid6CW5Yiw+bQ=
=+z9d
-----END PGP SIGNATURE-----
--
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 35 lines · Todd C. Miller
Quoted 7 lines · Daniel J Walsh
Already have it.
This is a repatch off of libsemanage-2.0.9
It should include your stuff plus it gets the
fallback_userby looking up the__default__login record.Quoted 8 lines
That way if I change the
__default__record to usexguest_u, it will build all user accounts with this context.
getpwnam_rreturns 0 even if an account does not exist.So you need to check the pointer.
A couple of other translation problems also.
Unfortunately, the return values for
getpwnam_r()andgetpwent_r()are inconsistent. Whilegetpwnam_r()returns 0 when the user does not exist,getpwent_r()returns ENOENT. I decided to deal with both semantics in the same way so if they are every brought into line the code will still do the right thing.I made similar fixes to yours for the seuser vs. user mismatches. A merge of your diff and mine follows. I added some error condition fixes and made the style more consistent.
- todd
Index:
libsemanage/include/semanage/handle.h
===================================================================
include/semanage/handle.h line 74
Quoted 6 lines
include/semanage/handle.h +3
-0@@ -69,6 +69,10 @@* 1 for yes, 0 for no (default) */ void semanage_set_create_store (semanage_handle_t * handle,int create_store); +/* set whether to generate homedir file context +* 1 for yes (default), 0 for no */ +void semanage_set_rebuild_file_context (semanage_handle_t * handle,int do_rebuild_file_context);
Did you mean to include this change too? When this separate patch was first posted, my suggestion was that the library should internally decide whether it was necessary to do this, not the caller. Also it doesn't seem to be doing what it says it does anymore - it only appears to affect validation of file contexts via setfiles (which should happen on module installs too), not whether genhomedircon runs.
src/handle.h line 61
Quoted 13 lines
include/semanage/handle.h +1
-0+/* Set whether or not to disable dontaudits upon commit */ void semanage_set_disable_dontaudit (semanage_handle_t * handle,int disable_dontaudit);Index:
libsemanage/src/handle.h
===================================================================src/handle.h +1
-0@@ -58,6 +58,7 @@int is_connected;int is_in_transaction;int do_reload;/* whether to reload policy after commit */ +int do_rebuild_file_context;/* whether to generate homedircontext */
Ditto.
src/libsemanage.map line 12
Quoted 12 lines
src/handle.h +0
-0int do_rebuild;/* whether to rebuild policy if there were no changes */ int modules_modified;int create_store;/* whether to create the store if it does not exist Index: libsemanage/src/libsemanage.map
===================================================================src/libsemanage.map +1
-0@@ -9,6 +9,7 @@ semanage_module_list_nth; semanage_module_get_name; semanage_module_get_version; semanage_select_store; semanage_reload_policy; semanage_set_reload; semanage_set_rebuild; + semanage_set_rebuild_file_context;
Ditto.
Quoted 7 lines
src/libsemanage.map +0
-0semanage_user_*; semanage_bool_*; semanage_seuser_*; semanage_iface_*; semanage_port_*; semanage_context_*; semanage_node_*;Index:
libsemanage/src/genhomedircon.c
===================================================================src/genhomedircon.c +0
-0
<snip>
Quoted 8 lines
src/genhomedircon.c +8
-0+static int check_line (genhomedircon_settings_t * s,Ustr *line) +{ +sepol_context_t *ctx_record =NULL ; +const char *ctx_str; +int result; + + ctx_str =extract_context (line); +if (!ctx_str)
src/genhomedircon.c line 393
Quoted 10 lines
src/genhomedircon.c +10
-0+return STATUS_ERR ; + + result =sepol_context_from_string (s->h_semanage->sepolh, + ctx_str, &ctx_record); +if (result ==STATUS_SUCCESS && ctx_record !=NULL ) { +sepol_msg_set_callback (s->h_semanage->sepolh,NULL ,NULL ); + result =sepol_context_check (s->h_semanage->sepolh, + s->policydb, ctx_record); +sepol_msg_set_callback (s->h_semanage->sepolh, + semanage_msg_relay_handler,NULL );
As noted elsewhere, the last NULL needs to be s->h_semanage or subsequent calls to the relay handler will seg fault.
<snip>
src/genhomedircon.c line 558
Quoted 6 lines
src/genhomedircon.c +2
-0@@ -496,6 +554,36 @@free (temp); } +static char *global_fallback_user; +static char *global_fallback_user_prefix;
Not suitable if you want threaded callers - needs to be moved into the genhomedircon settings (best) or made a __thread variable.
Quoted 36 lines
src/genhomedircon.c +27
-0+static char *get_fallback_user (void ) +{ +return global_fallback_user; +} + +static char *get_fallback_user_prefix (void ) +{ +return global_fallback_user_prefix; +} + +static int set_fallback_user (const char *user,const char *prefix) +{ +free (global_fallback_user); +free (global_fallback_user_prefix); + global_fallback_user =strdup (user); + global_fallback_user_prefix =strdup (prefix); +if (!global_fallback_user || !global_fallback_user_prefix) +return -1 ; +return 0 ; +} + +static void free_fallback_user (void ) +{ +free (global_fallback_user); +free (global_fallback_user_prefix); +} +static genhomedircon_user_entry_t *get_users (genhomedircon_settings_t * s,int *errors) {Index:
libsemanage/src/semanage_store.c
===================================================================
src/semanage_store.c line 1152
Quoted 6 lines
src/semanage_store.c +1
-1@@ -1148,7 +1148,7 @@ skip_reload: - if ((r = + if (sh->do_rebuild_file_context && (r = semanage_exec_prog(sh, sh->conf->setfiles, store_pol,
This seems wrong - the interface says it controls whether homedir contexts are generated, but this controls whether setfiles is run to validate the contexts (which should happen on module installs too).
Quoted 2 lines
src/semanage_store.c +0
-0store_fc)) != 0) {ERR (sh,"setfiles returned error code %d." , r);
<snip>
Quoted 19 lines
Index:
libsemanage/src/handle.c
===================================================================src/handle.c +4
-0@@ -68,6 +68,9 @@/* By default do not create store */ sh->create_store =0 ; +/* Rebuild the file_contexts by default */ + sh->do_rebuild_file_context =1 ; +/* Set timeout: some default value for now, later use config */ sh->timeout =SEMANAGE_COMMIT_READ_WAIT ;@@ -100,6 +103,15 @@return ; } +void semanage_set_rebuild_file_context (semanage_handle_t * sh,int do_rebuild_file_context)
src/handle.c line 116
Quoted 10 lines
src/handle.c +8
-0+{ + +assert (sh !=NULL ); + + sh->do_rebuild_file_context = do_rebuild_file_context; +return ; +} +void semanage_set_create_store (semanage_handle_t * sh,int create_store) {
More of the rebuild file context changes, unrelated to this patch.
Makefile line 8
Quoted 13 lines
Index: libsemanage/Makefile
===================================================================Makefile +3
-0@@ -1,6 +1,9 @@ all: $(MAKE) -C src all +swigify: + $(MAKE) -C src swigify + pywrap: $(MAKE) -C src pywrap
This one is fine but is logically separate.
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.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 211 lines · Stephen Smalley
Quoted 34 lines · Todd C. Miller
Quoted 7 lines · Daniel J Walsh
Already have it.
This is a repatch off of libsemanage-2.0.9
It should include your stuff plus it gets the
fallback_userby looking up the__default__login record.Quoted 8 lines
That way if I change the
__default__record to usexguest_u, it will build all user accounts with this context.
getpwnam_rreturns 0 even if an account does not exist.So you need to check the pointer.
A couple of other translation problems also.
Unfortunately, the return values for
getpwnam_r()andgetpwent_r()are inconsistent. Whilegetpwnam_r()returns 0 when the user does not exist,getpwent_r()returns ENOENT. I decided to deal with both semantics in the same way so if they are every brought into line the code will still do the right thing.I made similar fixes to yours for the seuser vs. user mismatches. A merge of your diff and mine follows. I added some error condition fixes and made the style more consistent.
- todd
Index:
libsemanage/include/semanage/handle.h
===================================================================include/semanage/handle.h line 74
Quoted 6 lines
include/semanage/handle.h +3
-0@@ -69,6 +69,10 @@* 1 for yes, 0 for no (default) */ void semanage_set_create_store (semanage_handle_t * handle,int create_store); +/* set whether to generate homedir file context +* 1 for yes (default), 0 for no */ +void semanage_set_rebuild_file_context (semanage_handle_t * handle,int do_rebuild_file_context);Did you mean to include this change too? When this separate patch was first posted, my suggestion was that the library should internally decide whether it was necessary to do this, not the caller. Also it doesn't seem to be doing what it says it does anymore - it only appears to affect validation of file contexts via setfiles (which should happen on module installs too), not whether genhomedircon runs.
src/handle.h line 61
Quoted 13 lines
include/semanage/handle.h +1
-0+/* Set whether or not to disable dontaudits upon commit */ void semanage_set_disable_dontaudit (semanage_handle_t * handle,int disable_dontaudit);Index:
libsemanage/src/handle.h
===================================================================src/handle.h +1
-0@@ -58,6 +58,7 @@int is_connected;int is_in_transaction;int do_reload;/* whether to reload policy after commit */ +int do_rebuild_file_context;/* whether to generate homedircontext */ Ditto.
src/libsemanage.map line 12
Quoted 12 lines
src/handle.h +0
-0int do_rebuild;/* whether to rebuild policy if there were no changes */ int modules_modified;int create_store;/* whether to create the store if it does not exist Index: libsemanage/src/libsemanage.map
===================================================================src/libsemanage.map +1
-0@@ -9,6 +9,7 @@ semanage_module_list_nth; semanage_module_get_name; semanage_module_get_version; semanage_select_store; semanage_reload_policy; semanage_set_reload; semanage_set_rebuild; + semanage_set_rebuild_file_context;Ditto.
Quoted 7 lines
src/libsemanage.map +0
-0semanage_user_*; semanage_bool_*; semanage_seuser_*; semanage_iface_*; semanage_port_*; semanage_context_*; semanage_node_*;Index:
libsemanage/src/genhomedircon.c
===================================================================src/genhomedircon.c +0
-0<snip>
Quoted 8 lines
src/genhomedircon.c +8
-0+static int check_line (genhomedircon_settings_t * s,Ustr *line) +{ +sepol_context_t *ctx_record =NULL ; +const char *ctx_str; +int result; + + ctx_str =extract_context (line); +if (!ctx_str)src/genhomedircon.c line 393
Quoted 10 lines
src/genhomedircon.c +10
-0+return STATUS_ERR ; + + result =sepol_context_from_string (s->h_semanage->sepolh, + ctx_str, &ctx_record); +if (result ==STATUS_SUCCESS && ctx_record !=NULL ) { +sepol_msg_set_callback (s->h_semanage->sepolh,NULL ,NULL ); + result =sepol_context_check (s->h_semanage->sepolh, + s->policydb, ctx_record); +sepol_msg_set_callback (s->h_semanage->sepolh, + semanage_msg_relay_handler,NULL );As noted elsewhere, the last NULL needs to be
s->h_semanageor subsequent calls to the relay handler will seg fault.<snip>
src/genhomedircon.c line 558
Quoted 6 lines
src/genhomedircon.c +2
-0@@ -496,6 +554,36 @@free (temp); } +static char *global_fallback_user; +static char *global_fallback_user_prefix;Not suitable if you want threaded callers - needs to be moved into the genhomedircon settings (best) or made a
__threadvariable.Quoted 36 lines
src/genhomedircon.c +27
-0+static char *get_fallback_user (void ) +{ +return global_fallback_user; +} + +static char *get_fallback_user_prefix (void ) +{ +return global_fallback_user_prefix; +} + +static int set_fallback_user (const char *user,const char *prefix) +{ +free (global_fallback_user); +free (global_fallback_user_prefix); + global_fallback_user =strdup (user); + global_fallback_user_prefix =strdup (prefix); +if (!global_fallback_user || !global_fallback_user_prefix) +return -1 ; +return 0 ; +} + +static void free_fallback_user (void ) +{ +free (global_fallback_user); +free (global_fallback_user_prefix); +} +static genhomedircon_user_entry_t *get_users (genhomedircon_settings_t * s,int *errors) {Index:
libsemanage/src/semanage_store.c
===================================================================src/semanage_store.c line 1152
Quoted 6 lines
src/semanage_store.c +1
-1@@ -1148,7 +1148,7 @@ skip_reload: - if ((r = + if (sh->do_rebuild_file_context && (r = semanage_exec_prog(sh, sh->conf->setfiles, store_pol,This seems wrong - the interface says it controls whether homedir contexts are generated, but this controls whether setfiles is run to validate the contexts (which should happen on module installs too).
Quoted 2 lines
src/semanage_store.c +0
-0store_fc)) != 0) {ERR (sh,"setfiles returned error code %d." , r);<snip>
Quoted 19 lines
Index:
libsemanage/src/handle.c
===================================================================src/handle.c +4
-0@@ -68,6 +68,9 @@/* By default do not create store */ sh->create_store =0 ; +/* Rebuild the file_contexts by default */ + sh->do_rebuild_file_context =1 ; +/* Set timeout: some default value for now, later use config */ sh->timeout =SEMANAGE_COMMIT_READ_WAIT ;@@ -100,6 +103,15 @@return ; } +void semanage_set_rebuild_file_context (semanage_handle_t * sh,int do_rebuild_file_context)src/handle.c line 116
Quoted 10 lines
src/handle.c +8
-0+{ + +assert (sh !=NULL ); + + sh->do_rebuild_file_context = do_rebuild_file_context; +return ; +} +void semanage_set_create_store (semanage_handle_t * sh,int create_store) {More of the rebuild file context changes, unrelated to this patch.
Quoted 8 lines
Index: libsemanage/Makefile
===================================================================Makefile +0
-0@@ -1,6 +1,9 @@ all: $(MAKE) -C src all
Quoted 8 lines
Makefile line 8
Quoted 5 lines
Makefile +3
-0+swigify: + $(MAKE) -C src swigify + pywrap: $(MAKE) -C src pywrapThis one is fine but is logically separate.
Yes, The change to not run genhomedircon should be removed.
libsemanage needs to figure out whether the template_homedir/seusers/users changed and not running genhomedircon or setfiles would be very nice. Basically none of these should run if setsetbool is executed, or semanage ports/interface/fcontext (most of the time)/(semodule most of the time)
It would be nice if there was a way to run semanage (genhomedircon) without running other parts of semanage also. For example if the homedirectory of a user changed.
Making this change would allow me to separate the policy for setsebool from the rest of semanage.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFG/BH1rlYvE4MpobMRAsVxAKCHGCnKdWFFmUvmxyuMX+jZ3/sv2ACfZtDs xRnh81nj6njrl0olAoPJWU0=
=bri9
-----END PGP SIGNATURE-----
--
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.