libsemanage: genhomedircon regressions
cover libsemanage: genhomedircon regressions
This patch set fixes several regressions found in the new genhomedircon replacement. I've broken things up into their logical parts for easy reading. I've also included Dan's do_rebuild_file_context and swigify patches as a 4th diff. If we want to treat that completely separately we can.
- todd
Signature · 4 lines
-- 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.
PATCH 1/4 libsemanage: validate homedir contexts
Validate contexts against the new policy before writing them to file_contexts.homedirs.
--- libsemanage/src/direct_api.c | 2 libsemanage/src/genhomedircon.c | 100 +++++++++++++++++++++++++++++++-------- libsemanage/src/genhomedircon.h | 3 - libsemanage/src/semanage_store.c | 5 + libsemanage/src/semanage_store.h | 5 - 5 files changed, 88 insertions(+), 27 deletions(-)
libsemanage/src/genhomedircon.c +78 -18
@@ -1,5 +1,6 @@ -/* Author: Mark Goldman <[email protected]> -* Paul Rosenfeld <[email protected]> +/* Author: Mark Goldman <[email protected]> +* Paul Rosenfeld <[email protected]> +* Todd C. Miller <[email protected]> * * Copyright (C) 2007 Tresys Technology, LLC *
@@ -23,6 +24,8 @@#include <semanage/seusers_policy.h> #include <semanage/users_policy.h> #include <semanage/user_record.h> +#include <sepol/context.h> +#include <sepol/context_record.h> #include "semanage_store.h" #include "seuser_internal.h" #include "debug.h"
@@ -80,6 +83,7 @@ typedef struct {int usepasswd;const char *homedir_template_path;semanage_handle_t *h_semanage; +sepol_policydb_t *policydb; } genhomedircon_settings_t; typedef struct user_entry {
@@ -352,9 +356,49 @@ static Ustr *replace_all(const char *strreturn retval; } -static int write_home_dir_context (FILE * out,semanage_list_t * tpl, -const char *user,const char *seuser, -const char *home,const char *role_prefix) +static const char *extract_context (Ustr *line) +{ +const char whitespace[] =" \t\n" ; +size_t off, len; + +/* check for trailing whitespace */ + off =ustr_spn_chrs_rev (line,0 , whitespace,strlen (whitespace)); + +/* find the length of the last field in line */ + len =ustr_cspn_chrs_rev (line, off, whitespace,strlen (whitespace)); + +if (len ==0 ) +return NULL ; +return ustr_cstr (line) +ustr_len (line) - (len + off); +} + +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) +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, s->h_semanage); +sepol_context_free (ctx_record); + } +return result; +} + +static int write_home_dir_context (genhomedircon_settings_t * s,FILE * out, +semanage_list_t * tpl,const char *user, +const char *seuser,const char *home, +const char *role_prefix) {replacement_pair_t repl[] = { {.search_for =TEMPLATE_SEUSER ,.replace_with = seuser},
@@ -369,8 +413,12 @@ static int write_home_dir_context(FILE *for (; tpl; tpl = tpl->next) { line =replace_all (tpl->data, repl); -if (!line || !ustr_io_putfileline (&line, out)) +if (!line) goto fail; +if (check_line (s, line) ==STATUS_SUCCESS ) { +if (!ustr_io_putfileline (&line, out)) + goto fail; + }ustr_sc_free (&line); }return STATUS_SUCCESS ;
@@ -380,8 +428,8 @@ static int write_home_dir_context(FILE *return STATUS_ERR ; } -static int write_home_root_context (FILE * out,semanage_list_t * tpl, -char *homedir) +static int write_home_root_context (genhomedircon_settings_t * s,FILE * out, +semanage_list_t * tpl,char *homedir) {replacement_pair_t repl[] = { {.search_for =TEMPLATE_HOME_ROOT ,.replace_with = homedir},
@@ -391,8 +439,12 @@ static int write_home_root_context(FILEfor (; tpl; tpl = tpl->next) { line =replace_all (tpl->data, repl); -if (!line || !ustr_io_putfileline (&line, out)) +if (!line) goto fail; +if (check_line (s, line) ==STATUS_SUCCESS ) { +if (!ustr_io_putfileline (&line, out)) + goto fail; + }ustr_sc_free (&line); }return STATUS_SUCCESS ;
@@ -402,8 +454,9 @@ static int write_home_root_context(FILEreturn STATUS_ERR ; } -static int write_user_context (FILE * out,semanage_list_t * tpl,char *user, -char *seuser,char *role_prefix) +static int write_user_context (genhomedircon_settings_t * s,FILE * out, +semanage_list_t * tpl,const char *user, +const char *seuser,const char *role_prefix) {replacement_pair_t repl[] = { {.search_for =TEMPLATE_USER ,.replace_with = user},
@@ -415,8 +468,12 @@ static int write_user_context(FILE * outfor (; tpl; tpl = tpl->next) { line =replace_all (tpl->data, repl); -if (!line || !ustr_io_putfileline (&line, out)) +if (!line) goto fail; +if (check_line (s, line) ==STATUS_SUCCESS ) { +if (!ustr_io_putfileline (&line, out)) + goto fail; + }ustr_sc_free (&line); }return STATUS_SUCCESS ;
@@ -602,7 +659,7 @@ static genhomedircon_user_entry_t *get_ureturn head; } -static int write_gen_home_dir_context (FILE * out,genhomedircon_settings_t * s, +static int write_gen_home_dir_context (genhomedircon_settings_t * s,FILE * out,semanage_list_t * user_context_tpl,semanage_list_t * homedir_context_tpl) {
@@ -615,13 +672,13 @@ static int write_gen_home_dir_context(FI }for (; users;pop_user_entry (&users)) { -if (write_home_dir_context (out, homedir_context_tpl, +if (write_home_dir_context (s, out, homedir_context_tpl, users->name, users->sename, users->home, users->prefix)) {return STATUS_ERR ; } -if (write_user_context (out, user_context_tpl, users->name, +if (write_user_context (s, out, user_context_tpl, users->name, users->sename, users->prefix)) {return STATUS_ERR ; }
@@ -671,7 +728,7 @@ static int write_context_file(genhomedir goto done; } - if (write_home_dir_context(out, + if (write_home_dir_context(s, out, homedir_context_tpl, FALLBACK_USER, FALLBACK_USER, ustr_cstr(temp), FALLBACK_USER_PREFIX) !=
@@ -680,7 +737,7 @@ static int write_context_file(genhomedir retval =STATUS_ERR ; goto done; } -if (write_home_root_context (out, +if (write_home_root_context (s, out, homeroot_context_tpl, h->data) !=STATUS_SUCCESS ) {ustr_sc_free (&temp);
@@ -711,7 +768,9 @@ static int write_context_file(genhomedirreturn retval; } -int semanage_genhomedircon (semanage_handle_t * sh,int usepasswd) +int semanage_genhomedircon (semanage_handle_t * sh, +sepol_policydb_t * policydb, +int usepasswd) {genhomedircon_settings_t s;FILE *out =NULL ;
@@ -725,6 +784,7 @@ int semanage_genhomedircon(semanage_hand s.usepasswd = usepasswd; s.h_semanage = sh; + s.policydb = policydb;if (!(out =fopen (s.fcfilepath,"w" ))) {/* couldn't open output file */
libsemanage/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
libsemanage/src/direct_api.c +1 -1
@@ -702,7 +702,7 @@ static int semanage_direct_commit(semana goto cleanup;if (sh->do_rebuild || modified) { - retval =semanage_install_sandbox (sh); + retval =semanage_install_sandbox (sh, out); } cleanup:
libsemanage/src/semanage_store.c +3 -2
@@ -1279,7 +1279,8 @@ static int semanage_commit_sandbox(seman* 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 @@ int semanage_install_sandbox(semanage_ha }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;
libsemanage/src/semanage_store.h +2 -3
@@ -83,8 +83,6 @@ int semanage_make_sandbox(semanage_handlint 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_expand_sandbox(semanage_hanint 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);
Signature · 4 lines
-- 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.
PATCH 2/4 libsemanage: fix getpw*_r usage
In reply to Todd C. Millergetpwnam_r() returns 0 when a user doesn't exist and just zeroes the struct passwd pointer. However, getpwent_r() returns ENOENT when there are no more users. This diff deals with both possible behaviors so that if the two functions are brought in line nothing will break. We can also remove the errno check and use the return value directly.
libsemanage/src/genhomedircon.c +7 -5
@@ -158,6 +158,7 @@ static semanage_list_t *get_home_dirs(gesize_t temp;struct passwd pwstorage, *pwbuf;struct stat buf; +int retval; shells =get_shell_list ();assert (shells);
@@ -229,7 +230,7 @@ static semanage_list_t *get_home_dirs(geif (rbuf ==NULL ) goto fail;setpwent (); -for (errno =0 ;getpwent_r (&pwstorage, rbuf, rbuflen, &pwbuf) ==0 ; errno =0 ) { +while ((retval =getpwent_r (&pwstorage, rbuf, rbuflen, &pwbuf)) ==0 ) {if (pwbuf->pw_uid < minuid)continue ;if (!semanage_list_find (shells, pwbuf->pw_shell))
@@ -252,7 +253,7 @@ static semanage_list_t *get_home_dirs(gefree (path); } -if (errno) { +if (retval && retval !=ENOENT ) {WARN (s->h_semanage,"Error while fetching users. " "Returning list so far." ); }
@@ -614,12 +615,13 @@ static genhomedircon_user_entry_t *get_u prefix = name; } - errno =0 ; -if (getpwnam_r (name, &pwstorage, rbuf, rbuflen, &pwent) !=0 ) { -if (errno !=0 ) { + retval =getpwnam_r (name, &pwstorage, rbuf, rbuflen, &pwent); +if (retval !=0 || pwent ==NULL ) { +if (retval !=0 && retval !=ENOENT ) { *errors =STATUS_ERR ; goto cleanup; } +WARN (s->h_semanage,"user %s not in password file" , name);continue ;
Signature · 4 lines
-- 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.
PATCH 3/4 libsemanage: update default user
In reply to Todd C. MillerPatch from dwalsh to update the default user and prefix based on the seusers file. Previously it just assumed user_u and user.
--- libsemanage/src/genhomedircon.c | 86 +++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 13 deletions(-)
libsemanage/src/genhomedircon.c +73 -13
@@ -82,6 +82,8 @@ typedef struct {const char *fcfilepath;int usepasswd;const char *homedir_template_path; +char *fallback_user; +char *fallback_user_prefix;semanage_handle_t *h_semanage;sepol_policydb_t *policydb; } genhomedircon_settings_t;
@@ -554,6 +556,25 @@ static void pop_user_entry(genhomedirconfree (temp); } +static int set_fallback_user (genhomedircon_settings_t *s, +const char *user,const char *prefix) +{ +char *fallback_user =strdup (user); +char *fallback_user_prefix =strdup (prefix); + +if (fallback_user ==NULL || fallback_user_prefix ==NULL ) { +free (fallback_user); +free (fallback_user_prefix); +return STATUS_ERR ; + } + +free (s->fallback_user); +free (s->fallback_user_prefix); + s->fallback_user = fallback_user; + s->fallback_user_prefix = fallback_user_prefix; +return STATUS_SUCCESS ; +} +static genhomedircon_user_entry_t *get_users (genhomedircon_settings_t * s,int *errors) {
@@ -596,13 +617,40 @@ static genhomedircon_user_entry_t *get_ufor (i =0 ; i < nseusers; i++) { name =semanage_seuser_get_name (seuser_list[i]); +if (strcmp (name,DEFAULT_LOGIN ) ==0 ) { + seuname =semanage_seuser_get_sename (seuser_list[i]); + +/* find the user structure given the name */ + u =bsearch (seuname, user_list, nusers, +sizeof (semanage_user_t *), + (int (*)(const void *,const void *)) + &name_user_cmp); +if (u) { + prefix =semanage_user_get_prefix (*u); + }else { + prefix = name; + } + +if (set_fallback_user (s, seuname, prefix) !=0 ) { + *errors =STATUS_ERR ; + goto cleanup; + } +break ; + } + } + +for (i =0 ; i < nseusers; i++) { seuname =semanage_seuser_get_sename (seuser_list[i]); -if (strcmp (seuname,FALLBACK_USER ) ==0 ) +if (strcmp (seuname, s->fallback_user) ==0 )continue ; -if (strcmp (seuname,DEFAULT_LOGIN ) ==0 ) + + name =semanage_seuser_get_name (seuser_list[i]); + +if (strcmp (name,DEFAULT_LOGIN ) ==0 )continue ; -if (strcmp (seuname,TEMPLATE_SEUSER ) ==0 ) + +if (strcmp (name,TEMPLATE_SEUSER ) ==0 )continue ;/* find the user structure given the name */
@@ -721,6 +769,12 @@ static int write_context_file(genhomedir goto done; } +if (write_gen_home_dir_context (s, out, user_context_tpl, + homedir_context_tpl) !=STATUS_SUCCESS ) { + retval =STATUS_ERR ; + goto done; + } +for (h = homedirs; h; h = h->next) {Ustr *temp =ustr_dup_cstr (h->data);
@@ -731,9 +785,10 @@ static int write_context_file(genhomedir }if (write_home_dir_context (s, out, - homedir_context_tpl,FALLBACK_USER , -FALLBACK_USER ,ustr_cstr (temp), -FALLBACK_USER_PREFIX ) != + homedir_context_tpl, + s->fallback_user, s->fallback_user, +ustr_cstr (temp), + s->fallback_user_prefix) !=STATUS_SUCCESS ) {ustr_sc_free (&temp); retval =STATUS_ERR ;
@@ -749,16 +804,12 @@ static int write_context_file(genhomedirustr_sc_free (&temp); } -if (write_user_context (out, user_context_tpl, -".*" ,FALLBACK_USER , -FALLBACK_USER_PREFIX ) !=STATUS_SUCCESS ) { +if (write_user_context (s, out, user_context_tpl, +".*" , s->fallback_user, + s->fallback_user_prefix) !=STATUS_SUCCESS ) { retval =STATUS_ERR ; goto done; } -if (write_gen_home_dir_context (out, s, user_context_tpl, - homedir_context_tpl) !=STATUS_SUCCESS ) { - retval =STATUS_ERR ; - } done:/* Cleanup */
@@ -784,6 +835,11 @@ int semanage_genhomedircon(semanage_handsemanage_path (SEMANAGE_TMP ,SEMANAGE_HOMEDIR_TMPL ); s.fcfilepath =semanage_path (SEMANAGE_TMP ,SEMANAGE_FC_HOMEDIRS ); + s.fallback_user =strdup (FALLBACK_USER ); + s.fallback_user_prefix =strdup (FALLBACK_USER_PREFIX ); +if (s.fallback_user ==NULL || s.fallback_user_prefix ==NULL ) +return STATUS_ERR ; + s.usepasswd = usepasswd; s.h_semanage = sh; s.policydb = policydb;
@@ -797,5 +853,9 @@ int semanage_genhomedircon(semanage_hand retval =write_context_file (&s, out);fclose (out); + +free (s.fallback_user); +free (s.fallback_user_prefix); +return retval; }
Signature · 4 lines
-- 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.
PATCH 4/4 libsemanage: rebuild_file_context option
In reply to Todd C. MillerPatch from dwalsh to allow disabling of file_contexts rebuilding.
--- libsemanage/Makefile | 3 +++ libsemanage/include/semanage/handle.h | 4 ++++ libsemanage/src/handle.c | 12 ++++++++++++ libsemanage/src/handle.h | 1 + libsemanage/src/libsemanage.map | 1 + libsemanage/src/semanage_store.c | 2 +- 6 files changed, 22 insertions(+), 1 deletion(-)
libsemanage/include/semanage/handle.h +4 -0
@@ -69,6 +69,10 @@ void semanage_set_rebuild(semanage_handl* 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);
libsemanage/src/handle.h +1 -0
@@ -58,6 +58,7 @@ struct semanage_handle {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
libsemanage/src/libsemanage.map +1 -0
@@ -9,6 +9,7 @@ LIBSEMANAGE_1.0 { 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_*;
libsemanage/src/semanage_store.c +1 -1
@@ -1148,7 +1148,7 @@ static int semanage_install_active(seman 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);
libsemanage/src/handle.c +12 -0
@@ -68,6 +68,9 @@ semanage_handle_t *semanage_handle_creat/* 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 @@ void semanage_set_reload(semanage_handlereturn ; } +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) {
libsemanage/Makefile +3 -0
@@ -1,6 +1,9 @@ all: $(MAKE) -C src all +swigify: + $(MAKE) -C src swigify + pywrap: $(MAKE) -C src pywrap
Signature · 4 lines
-- 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 · Todd C. Miller
This patch set fixes several regressions found in the new genhomedircon replacement. I've broken things up into their logical parts for easy reading. I've also included Dan's
do_rebuild_file_contextand swigify patches as a 4th diff. If we want to treat that completely separately we can.
patch 1/4 yielded a non-buildable tree, so I applied 1/4 and 3/4 together as a single commit.
2/4 applied as a bug fix independent of the others.
4/4 dropped except for Makefile swigify target.
libsemanage 2.0.10.
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 7 lines · Stephen Smalley
Quoted 5 lines · Todd C. Miller
This patch set fixes several regressions found in the new genhomedircon replacement. I've broken things up into their logical parts for easy reading. I've also included Dan's
do_rebuild_file_contextand swigify patches as a 4th diff. If we want to treat that completely separately we can.
Quoted 8 lines
patch 1/4 yielded a non-buildable tree, so I applied 1/4 and 3/4 together as a single commit.
2/4 applied as a bug fix independent of the others.
4/4 dropped except for
Makefileswigify target.libsemanage 2.0.10.
Looking again at the output, the order differs - the libsemanage genhomedircon puts the specific user entries first and then the generic /home entries, which seems wrong given that later entries take precedence for matchpathcon. genhomedircon script does the opposite.
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 12 lines · Stephen Smalley
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Todd C. Miller
This patch set fixes several regressions found in the new genhomedircon replacement. I've broken things up into their logical parts for easy reading. I've also included Dan's
do_rebuild_file_contextand swigify patches as a 4th diff. If we want to treat that completely separately we can.patch 1/4 yielded a non-buildable tree, so I applied 1/4 and 3/4 together as a single commit.
2/4 applied as a bug fix independent of the others.
Quoted 9 lines
Quoted 3 lines
4/4 dropped except for
Makefileswigify target.libsemanage 2.0.10.
Looking again at the output, the order differs - the libsemanage genhomedircon puts the specific user entries first and then the generic /home entries, which seems wrong given that later entries take precedence for matchpathcon. genhomedircon script does the opposite.
It should be alright because of the specificity is greater.
/home/dwalsh/.*
vs
/home/.*
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFG/QhwrlYvE4MpobMRAs9nAKCBvu1gSUsxBfLLkwCfLeSU7ejQxgCfcYd+ 8i2BugMuBIPJl+UUW5GX6rw=
=Uyti
-----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 26 lines · Daniel J Walsh
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 12 lines · Stephen Smalley
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Todd C. Miller
This patch set fixes several regressions found in the new genhomedircon replacement. I've broken things up into their logical parts for easy reading. I've also included Dan's
do_rebuild_file_contextand swigify patches as a 4th diff. If we want to treat that completely separately we can.patch 1/4 yielded a non-buildable tree, so I applied 1/4 and 3/4 together as a single commit.
2/4 applied as a bug fix independent of the others.
Quoted 9 lines
Quoted 3 lines
4/4 dropped except for
Makefileswigify target.libsemanage 2.0.10.
Looking again at the output, the order differs - the libsemanage genhomedircon puts the specific user entries first and then the generic /home entries, which seems wrong given that later entries take precedence for matchpathcon. genhomedircon script does the opposite.
Quoted 7 lines
It should be alright because of the specificity is greater.
/home/dwalsh/.*vs
/home/.*
I don't think that works out in all cases, e.g. matchpathcon /home/xguest/.ssh yields a different result.
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 29 lines · Stephen Smalley
Quoted 28 lines · Daniel J Walsh
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 12 lines · Stephen Smalley
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Todd C. Miller
This patch set fixes several regressions found in the new genhomedircon replacement. I've broken things up into their logical parts for easy reading. I've also included Dan's
do_rebuild_file_contextand swigify patches as a 4th diff. If we want to treat that completely separately we can.patch 1/4 yielded a non-buildable tree, so I applied 1/4 and 3/4 together as a single commit.
2/4 applied as a bug fix independent of the others.
Quoted 9 lines
Quoted 3 lines
4/4 dropped except for
Makefileswigify target.libsemanage 2.0.10.
Looking again at the output, the order differs - the libsemanage genhomedircon puts the specific user entries first and then the generic /home entries, which seems wrong given that later entries take precedence for matchpathcon. genhomedircon script does the opposite.
It should be alright because of the specificity is greater.
Quoted 8 lines
Quoted 5 lines
/home/dwalsh/.*vs
/home/.*I don't think that works out in all cases, e.g. matchpathcon
/home/xguest/.sshyields a different result.
Old order (genhomedircon script output):
# matchpathcon /home/xguest/.ssh /home/xguest/.ssh xguest_u:object_r:xguest_home_t
New order (latest libsemanage):
# matchpathcon /home/xguest/.ssh /home/xguest/.ssh system_u:object_r:user_home_ssh_t
Which did you want it to be?
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 37 lines · Stephen Smalley
Quoted 27 lines · Stephen Smalley
Quoted 26 lines · Daniel J Walsh
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 12 lines · Stephen Smalley
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Todd C. Miller
This patch set fixes several regressions found in the new genhomedircon replacement. I've broken things up into their logical parts for easy reading. I've also included Dan's
do_rebuild_file_contextand swigify patches as a 4th diff. If we want to treat that completely separately we can.patch 1/4 yielded a non-buildable tree, so I applied 1/4 and 3/4 together as a single commit.
2/4 applied as a bug fix independent of the others.
Quoted 8 lines
Quoted 3 lines
4/4 dropped except for
Makefileswigify target.libsemanage 2.0.10.
Looking again at the output, the order differs - the libsemanage genhomedircon puts the specific user entries first and then the generic /home entries, which seems wrong given that later entries take precedence for matchpathcon. genhomedircon script does the opposite.
It should be alright because of the specificity is greater.
Quoted 7 lines
Quoted 5 lines
/home/dwalsh/.*vs
/home/.*I don't think that works out in all cases, e.g. matchpathcon
/home/xguest/.sshyields a different result.Old order (genhomedircon script output):
Quoted 9 lines
# matchpathcon /home/xguest/.ssh /home/xguest/.ssh xguest_u:object_r:xguest_home_tNew order (latest libsemanage):
# matchpathcon /home/xguest/.ssh /home/xguest/.ssh system_u:object_r:user_home_ssh_tWhich did you want it to be?
Yes you are right.
The problem is we need to find the failsafe account before writing the general account.
How about this patch.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFG/RhdrlYvE4MpobMRAqTmAKDCE7++pT4Cyia9otRgxVKDGliybQCeORmj JjDY5P3SDBwohQRC5uPJwNU=
=HkqG
-----END PGP SIGNATURE-----
src/genhomedircon.c +53 -23
@@ -575,10 +575,8 @@return STATUS_SUCCESS ; } -static genhomedircon_user_entry_t *get_users (genhomedircon_settings_t * s, -int *errors) +static int setup_fallback_user (genhomedircon_settings_t * s) { -genhomedircon_user_entry_t *head =NULL ;semanage_seuser_t **seuser_list =NULL ;unsigned int nseusers =0 ;semanage_user_t **user_list =NULL ;
@@ -587,17 +585,13 @@const char *name =NULL ;const char *seuname =NULL ;const char *prefix =NULL ; -struct passwd pwstorage, *pwent =NULL ;unsigned int i; -long rbuflen; -char *rbuf =NULL ;int retval; - - *errors =0 ; +int errors =0 ; retval =semanage_seuser_list (s->h_semanage, &seuser_list, &nseusers);if (retval <0 || (nseusers <1 )) {/* if there are no users, this function can't do any other work */ -return NULL ; +return errors; }if (semanage_user_list (s->h_semanage, &user_list, &nusers) <0 ) {
@@ -607,14 +601,6 @@qsort (user_list, nusers,sizeof (semanage_user_t *), (int (*)(const void *,const void *))&user_sort_func); -/* Allocate space for the getpwnam_r buffer */ - rbuflen =sysconf (_SC_GETPW_R_SIZE_MAX); -if (rbuflen <=0 ) - goto cleanup; - rbuf =malloc (rbuflen); -if (rbuf ==NULL ) - goto cleanup; -for (i =0 ; i < nseusers; i++) { name =semanage_seuser_get_name (seuser_list[i]);if (strcmp (name,DEFAULT_LOGIN ) ==0 ) {
@@ -630,14 +616,54 @@ }else { prefix = name; } -if (set_fallback_user (s, seuname, prefix) !=0 ) { - *errors =STATUS_ERR ; - goto cleanup; + errors =STATUS_ERR ; }break ; } } +return errors; +} + +static genhomedircon_user_entry_t *get_users (genhomedircon_settings_t * s, +int *errors) +{ +genhomedircon_user_entry_t *head =NULL ; +semanage_seuser_t **seuser_list =NULL ; +unsigned int nseusers =0 ; +semanage_user_t **user_list =NULL ; +unsigned int nusers =0 ; +semanage_user_t **u =NULL ; +const char *name =NULL ; +const char *seuname =NULL ; +const char *prefix =NULL ; +struct passwd pwstorage, *pwent =NULL ; +unsigned int i; +long rbuflen; +char *rbuf =NULL ; +int retval; + + *errors =0 ; + retval =semanage_seuser_list (s->h_semanage, &seuser_list, &nseusers); +if (retval <0 || (nseusers <1 )) { +/* if there are no users, this function can't do any other work */ +return NULL ; + } + +if (semanage_user_list (s->h_semanage, &user_list, &nusers) <0 ) { + nusers =0 ; + } + +qsort (user_list, nusers,sizeof (semanage_user_t *), + (int (*)(const void *,const void *))&user_sort_func); + +/* Allocate space for the getpwnam_r buffer */ + rbuflen =sysconf (_SC_GETPW_R_SIZE_MAX); +if (rbuflen <=0 ) + goto cleanup; + rbuf =malloc (rbuflen); +if (rbuf ==NULL ) + goto cleanup;for (i =0 ; i < nseusers; i++) { seuname =semanage_seuser_get_sename (seuser_list[i]);
@@ -769,12 +795,10 @@ goto done; } -if (write_gen_home_dir_context (s, out, user_context_tpl, - homedir_context_tpl) !=STATUS_SUCCESS ) { +if (setup_fallback_user (s) !=0 ) { retval =STATUS_ERR ; goto done; } -for (h = homedirs; h; h = h->next) {Ustr *temp =ustr_dup_cstr (h->data);
@@ -811,6 +835,12 @@ goto done; } +if (write_gen_home_dir_context (s, out, user_context_tpl, + homedir_context_tpl) !=STATUS_SUCCESS ) { + retval =STATUS_ERR ; + goto done; + } + done:/* Cleanup */ semanage_list_destroy (&homedirs);
Quoted 4 lines · Stephen Smalley
Looking again at the output, the order differs - the libsemanage genhomedircon puts the specific user entries first and then the generic /home entries, which seems wrong given that later entries take precedence for matchpathcon. genhomedircon script does the opposite.
This change was present in the modified diff Dan sent and I preserved that change in the patch set. At the time I had thought it was moved to make the output better match the python script but that appears not to be the case.
It is easy to change back but I'm sure there was a reason for the move. Perhaps Dan can shed some light on this.
- todd
--
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.
Josh just pointed out that unlike file_contexts, file_contexts.homedir isn't sorted via semanage_fc_sort().
This is probably the best solution, though it would mean we lose the comments (they get stripped out during the sorting for obvious reasons).
Thoughts?
- todd
--
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 · Todd Miller
Josh just pointed out that unlike
file_contexts, file_contexts.homedir isn't sorted viasemanage_fc_sort().This is probably the best solution, though it would mean we lose the comments (they get stripped out during the sorting for obvious reasons).
Thoughts?
I'd have assumed that you want the general /home patterns to come first always (lowest precedence), then the per-user patterns (and no conflicts among the per-user patterns). So I'm not sure why you'd want to sort it heuristically like the rest of the file contexts. The heuristics could end up putting the general /home patterns later, which I don't think you ever want.
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 10 lines · Stephen Smalley
Quoted 8 lines · Todd Miller
Josh just pointed out that unlike
file_contexts, file_contexts.homedir isn't sorted viasemanage_fc_sort().This is probably the best solution, though it would mean we lose the comments (they get stripped out during the sorting for obvious reasons).
Thoughts?
Quoted 7 lines
I'd have assumed that you want the general /home patterns to come first always (lowest precedence), then the per-user patterns (and no conflicts among the per-user patterns). So I'm not sure why you'd want to sort it heuristically like the rest of the file contexts. The heuristics could end up putting the general /home patterns later, which I don't think you ever want.
Matchpathcon should already read file_context.homedirs and matches entries in it before going on to the file_context file so using the fc_sort function would just be to sort the homedirs file and not sort both files together.
--
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 20 lines · Joshua Brindle
Quoted 10 lines · Stephen Smalley
Quoted 8 lines · Todd Miller
Josh just pointed out that unlike
file_contexts, file_contexts.homedir isn't sorted viasemanage_fc_sort().This is probably the best solution, though it would mean we lose the comments (they get stripped out during the sorting for obvious reasons).
Thoughts?
Quoted 7 lines
I'd have assumed that you want the general /home patterns to come first always (lowest precedence), then the per-user patterns (and no conflicts among the per-user patterns). So I'm not sure why you'd want to sort it heuristically like the rest of the file contexts. The heuristics could end up putting the general /home patterns later, which I don't think you ever want.
Quoted 4 lines
Matchpathcon should already read file_context.homedirs and matches entries in it before going on to the
file_contextfile so using thefc_sortfunction would just be to sort the homedirs file and not sort both files together.
I know - but my concern is that the fc sort code may get the internal ordering of files_contexts.homedirs wrong. We know that we always want the general /home/.+ patterns in file_contexts.homedirs to precede the per-user entries, and the per-user entries should be disjoint anyway so their ordering relative to one another shouldn't matter.
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 11 lines · Todd Miller
Quoted 4 lines · Stephen Smalley
Looking again at the output, the order differs - the libsemanage genhomedircon puts the specific user entries first and then the generic /home entries, which seems wrong given that later entries take precedence for matchpathcon. genhomedircon script does the opposite.
This change was present in the modified diff Dan sent and I preserved that change in the patch set. At the time I had thought it was moved to make the output better match the python script but that appears not to be the case.
Quoted 4 lines
It is easy to change back but I'm sure there was a reason for the move. Perhaps Dan can shed some light on this.
- todd
THe problem was the fallback_user was not determined at the time it was being written out. I have sent a new patch that separates out the descovery of the fallback_user from gen_users.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFG/RqurlYvE4MpobMRArtLAJ9zp2AKWoO6jUvB25bYYZl19t8KwACfeA5k XSwO4xxrQgvgvsBU10nUyBs=
=CxFA
-----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.