Add parse/print error messages
Add parse/print error messages, and pass handle down to parse_utils. It's pretty verbose right now - I have to figure out a better way to do error reporting... However, lots of messages is better than no messages, so I suggest patch is merged - messages can be sorted out later.
Hmm... I see the MLS user parser seems broken..
[root@cobra test.seusers]# ./test
There are 3 seusers before the transaction.
Now testing list...
Name: phantom, Seuser: phantom, MLS: s0
Name: __default__, Seuser: user_u, MLS: s0
Name: root, Seuser: root, MLS: s0
Now testing iterate...
Name: phantom, Seuser: phantom, MLS: s0
Name: __default__, Seuser: user_u, MLS: s0
Name: root, Seuser: root, MLS: s0
In-Transaction pre-commit iterate (should show modifications)..
Name: test_user, Seuser: test_seuser, MLS: s0:c5,c6-s2:c1,c3,c5
Name: phantom, Seuser: phantom, MLS: s0
Name: __default__, Seuser: user_u, MLS: s0
Name: root, Seuser: root, MLS: s0
libsemanage.parse_assert_ch: expected character ';', but found 's' (/etc/selinux/strict/modules/tmp/users.local: 1):
user Ivan roles { sysadm_r staff_r } level s0 range s0-s0:c1.c2,c3,c4,c55; libsemanage.user_parse: parse error (/etc/selinux/strict/modules/tmp/users.local: 1):
user Ivan roles { sysadm_r staff_r } level s0 range s0-s0:c1.c2,c3,c4,c55; libsemanage.dbase_file_cache: could not cache file database libsemanage.semanage_base_merge_components: could not merge local modifications into policy libsemanage.semanage_expand_sandbox: Unable to merge local modifications into policy.
Error: commit failed
libsemanage/src/database_policydb.c +1 -1
@@ -106,7 +106,7 @@ static int dbase_policydb_cache(free (fname); dbase->cached =1 ;return STATUS_SUCCESS ; - + err:ERR (handle,"unable to cache policy database from %s" , fname);
libsemanage/src/interfaces_file.c +1 -1
@@ -54,7 +54,7 @@ record_file_table_t SEMANAGE_IFACE_FILE_int iface_file_dbase_init (dbase_config_t * dconfig) {if (dbase_file_init ( -"" ,/* FIXME */ +"interfaces.local" , &SEMANAGE_IFACE_RTABLE , &SEMANAGE_IFACE_FILE_RTABLE , &dconfig->dbase) <0 )
libsemanage/src/ports_file.c +1 -1
@@ -135,7 +135,7 @@ record_file_table_t SEMANAGE_PORT_FILE_Rint port_file_dbase_init (dbase_config_t * dconfig) {if (dbase_file_init ( -"port_contexts" , +"ports.local" , &SEMANAGE_PORT_RTABLE , &SEMANAGE_PORT_FILE_RTABLE , &dconfig->dbase) <0 )
libsemanage/src/semanage_store.c +12 -1
@@ -94,7 +94,8 @@ static const char *semanage_sandbox_path"/file_contexts" ,"/homedir_template" ,"/file_contexts.template" , - "/commit_num" +"/commit_num" , + "/seusers" };/* Initialize the paths to config file, lock files and store root.
@@ -851,10 +852,12 @@ static int semanage_install_active(semanconst char *active_kernel =semanage_path (SEMANAGE_ACTIVE ,SEMANAGE_KERNEL );const char *active_fc =semanage_path (SEMANAGE_ACTIVE ,SEMANAGE_FC );const char *active_hd =semanage_path (SEMANAGE_ACTIVE ,SEMANAGE_HOMEDIR_TMPL ); +const char *active_seusers =semanage_path (SEMANAGE_ACTIVE ,SEMANAGE_SEUSERS );const char *running_fc =selinux_file_context_path ();const char *running_hd =selinux_homedir_context_path ();const char *running_policy =selinux_binary_policy_path (); +const char *running_seusers =selinux_usersconf_path ();const char *really_active_store =selinux_policy_root ();/* This is very unelegant, the right thing to do is export the path
@@ -863,11 +866,13 @@ static int semanage_install_active(semanchar store_fc[PATH_MAX ];char store_hd[PATH_MAX ];char store_pol[PATH_MAX ]; +char store_seusers[PATH_MAX ]; len =strlen (really_active_store); running_fc += len; running_hd += len; running_policy += len; + running_seusers += len; len =strlen (selinux_path ()) +strlen (sh->conf->store_path) +1 ; storepath = (char *)malloc (len);
@@ -894,6 +899,12 @@ static int semanage_install_active(seman goto cleanup; } +snprintf (store_seusers,PATH_MAX ,"%s%s" , storepath, running_seusers); +if (semanage_copy_file (active_seusers, store_seusers) ==-1 ) { +ERR (sh,"Could not copy %s to %s." , active_seusers, store_seusers); + goto cleanup; + } +if (!sh->do_reload) goto skip_reload;
libsemanage/src/semanage_store.h +1 -0
@@ -44,6 +44,7 @@ enum semanage_sandbox_defs {SEMANAGE_HOMEDIR_TMPL ,SEMANAGE_FC_TMPL ,SEMANAGE_COMMIT_NUM_FILE , +SEMANAGE_SEUSERS , SEMANAGE_STORE_NUM_PATHS };
libsemanage/src/users_file.c +1 -1
@@ -229,7 +229,7 @@ record_file_table_t SEMANAGE_USER_FILE_Rint user_file_dbase_init (dbase_config_t * dconfig) {if (dbase_file_init ( -"local.users" , +"users.local" , &SEMANAGE_USER_RTABLE , &SEMANAGE_USER_FILE_RTABLE , &dconfig->dbase) <0 )
Quoted 2 lines · Ivan Gyurdiev
Add parse/print error messages, and pass handle down to
parse_utils. It's pretty verbose right now - I have to figure out a better way to do error reporting... However, lots of messages is better than no messages, so I suggest patch is merged - messages can be sorted out later.
I think I sent the install_seusers patch twice. Reattached...
libsemanage/src/booleans_file.c +11 -11
@@ -27,12 +27,11 @@ static int bool_print(int value =semanage_bool_get_value (boolean);if (fprintf (str,"%s=%d\n" , name, value) <0 ) { -/* FIXME: handle error */ +ERR (handle,"error writing boolean %s to stream" , name);return STATUS_ERR ; }return STATUS_SUCCESS ; - handle =NULL ; } static int bool_parse(
@@ -43,13 +42,13 @@ static int bool_parse(int value =0 ;char * str =NULL ; -if (parse_skip_space (info) <0 ) +if (parse_skip_space (handle, info) <0 ) goto err;if (!info->ptr) goto last;/* Extract name */ -if (parse_fetch_string_until (info, &str,'=' ) <0 ) +if (parse_fetch_string_until (handle, info, &str,'=' ) <0 ) goto err;if (semanage_bool_set_name (handle, boolean, str) <0 )
@@ -57,19 +56,19 @@ static int bool_parse(free (str); str =NULL ; -if (parse_skip_space (info) <0 ) +if (parse_skip_space (handle, info) <0 ) goto err; -if (parse_assert_noeof (info) <0 ) +if (parse_assert_noeof (handle, info) <0 ) goto err; -if (parse_assert_ch (info,'=' ) <0 ) +if (parse_assert_ch (handle, info,'=' ) <0 ) goto err; -if (parse_skip_space (info) <0 ) +if (parse_skip_space (handle, info) <0 ) goto err; -if (parse_assert_noeof (info) <0 ) +if (parse_assert_noeof (handle, info) <0 ) goto err;/* Extract value */ -if (parse_fetch_string (info, &str) <0 ) +if (parse_fetch_string (handle, info, &str) <0 ) goto err;if (isdigit (*str)) {
@@ -104,7 +103,8 @@ static int bool_parse(return STATUS_NODATA ; err: -/* FIXME: handle error */ +ERR (handle,"parse error (%s: %u):\n%s" , + info->filename, info->lineno, info->orig_line);free (str);parse_dispose_line (info);return STATUS_ERR ;
libsemanage/src/database_file.c +3 -3
@@ -100,10 +100,10 @@ static int dbase_file_cache(if (construct_filename (handle, dbase, &fname) <0 ) goto err; -if (parse_init (fname,NULL , &parse_info) <0 ) +if (parse_init (handle, fname,NULL , &parse_info) <0 ) goto err; -if (parse_open (parse_info) <0 ) +if (parse_open (handle, parse_info) <0 ) goto err;/* Main processing loop */
@@ -140,7 +140,7 @@ static int dbase_file_cache(return STATUS_SUCCESS ; err: -/* FIXME: handle failure */ +ERR (handle,"could not cache file database" ); dbase->rtable->free (process_record);parse_close (parse_info);parse_release (parse_info);
libsemanage/src/database_policydb.c +1 -2
@@ -108,8 +108,7 @@ static int dbase_policydb_cache(return STATUS_SUCCESS ; err: -ERR (handle,"unable to cache policy database from %s" , fname); - +ERR (handle,"could not cache policy database" );if (fp)fclose (fp);sepol_policydb_free (policydb);
libsemanage/src/parse_utils.c +62 -33
224 lines not on this page · raw message
libsemanage/src/parse_utils.h +11 -0
@@ -2,6 +2,7 @@#define _SEMANAGE_PARSE_UTILS_INTERNAL_H_#include <stdio.h> +#include <semanage/handle.h> typedef struct parse_info { unsigned int lineno; /* Current line number */
@@ -17,6 +18,7 @@ typedef struct parse_info {/* Initialize structure */ extern int parse_init ( +semanage_handle_t * handle,const char * filename,void * parse_arg,parse_info_t ** info);
@@ -27,6 +29,7 @@ extern void parse_release(/* Open file */ extern int parse_open ( +semanage_handle_t * handle,parse_info_t * info);/* Close file */
@@ -39,20 +42,24 @@ extern void parse_dispose_line(/* Skip all whitespace and comments */ extern int parse_skip_space ( +semanage_handle_t * handle,parse_info_t * info);/* Throw an error if we're at the EOF */ extern int parse_assert_noeof ( +semanage_handle_t * handle,parse_info_t * info);/* Throw an error if no whitespace follows, * otherwise eat the whitespace */ extern int parse_assert_space ( +semanage_handle_t * handle,parse_info_t * info);/* Throw an error if the specified character * does not follow, otherwise eat that character */ extern int parse_assert_ch ( +semanage_handle_t * handle,parse_info_t * info,const char ch);
@@ -60,6 +67,7 @@ extern int parse_assert_ch(* does not follow is not found, otherwise * eat the string */ extern int parse_assert_str ( +semanage_handle_t * handle,parse_info_t * info,const char * assert_str);
@@ -80,12 +88,14 @@ extern int parse_optional_str(* at which point return the buffered string. * This function will work on multiple lines */ extern char *parse_filter_space_until ( +semanage_handle_t * handle,parse_info_t * info,const char * substr);/* Extract the next string (delimited by * whitespace), and move the read pointer past it */ extern int parse_fetch_string ( +semanage_handle_t * handle,parse_info_t * info,char ** str_ptr);
@@ -93,6 +103,7 @@ extern int parse_fetch_string(* the specified character, or whitespace), and move the * read pointer past it */ extern int parse_fetch_string_until ( +semanage_handle_t * handle,parse_info_t * info,char ** str_ptr,char delim);
libsemanage/src/policy_components.c +2 -2
@@ -92,10 +92,10 @@ int semanage_base_merge_components( load_arg.mode = components[i].mode;/* Must invoke cache function first */ -if (from->dtable->cache (handle, from->dbase) <0 ) +if (from->dtable->cache (handle, from->dbase) <0 ) goto err; -if (to->dtable->cache (handle, to->dbase) <0 ) +if (to->dtable->cache (handle, to->dbase) <0 ) goto err;/* Now iterate */
libsemanage/src/ports_file.c +3 -2
@@ -65,7 +65,7 @@ static int port_parse(char * context =NULL ;semanage_context_t * con =NULL ; -if (parse_skip_space (info) <0 ) +if (parse_skip_space (handle, info) <0 ) goto err;if (!info->ptr) goto last;
@@ -114,7 +114,8 @@ static int port_parse(return STATUS_NODATA ; err: -/* FIXME: handle error */ +ERR (handle,"parse error (%s: %u):\n%s" , + info->filename, info->lineno, info->orig_line);free (proto);free (context);semanage_context_free (con);
libsemanage/src/seusers_file.c +17 -17
@@ -38,8 +38,7 @@ static int seuser_print(return STATUS_SUCCESS ; err: - handle =NULL ; -/* FIXME: handle error */ +ERR (handle,"error writing seuser %s to stream" , name);return STATUS_ERR ; }
@@ -50,32 +49,32 @@ static int seuser_parse(char * str =NULL ; -if (parse_skip_space (info) <0 ) +if (parse_skip_space (handle, info) <0 ) goto err;if (!info->ptr) goto last;/* Extract name */ -if (parse_fetch_string_until (info, &str,':' ) <0 ) +if (parse_fetch_string_until (handle, info, &str,':' ) <0 ) goto err;if (semanage_seuser_set_name (handle, seuser, str) <0 ) goto err;free (str); str =NULL ; -if (parse_skip_space (info) <0 ) +if (parse_skip_space (handle, info) <0 ) goto err; -if (parse_assert_noeof (info) <0 ) +if (parse_assert_noeof (handle, info) <0 ) goto err; -if (parse_assert_ch (info,':' ) <0 ) +if (parse_assert_ch (handle, info,':' ) <0 ) goto err; -if (parse_skip_space (info) <0 ) +if (parse_skip_space (handle, info) <0 ) goto err; -if (parse_assert_noeof (info) <0 ) +if (parse_assert_noeof (handle, info) <0 ) goto err;/* Extract sename */ -if (parse_fetch_string_until (info, &str,':' ) <0 ) +if (parse_fetch_string_until (handle, info, &str,':' ) <0 ) goto err;if (semanage_seuser_set_sename (handle, seuser, str) <0 ) goto err;
@@ -83,19 +82,19 @@ static int seuser_parse( str =NULL ;if (is_selinux_mls_enabled ()) { -if (parse_skip_space (info) <0 ) +if (parse_skip_space (handle, info) <0 ) goto err; -if (parse_assert_noeof (info) <0 ) +if (parse_assert_noeof (handle, info) <0 ) goto err; -if (parse_assert_ch (info,':' ) <0 ) +if (parse_assert_ch (handle, info,':' ) <0 ) goto err; -if (parse_skip_space (info) <0 ) +if (parse_skip_space (handle, info) <0 ) goto err; -if (parse_assert_noeof (info) <0 ) +if (parse_assert_noeof (handle, info) <0 ) goto err;/* NOTE: does not allow spaces/multiline */ -if (parse_fetch_string (info, &str) <0 ) +if (parse_fetch_string (handle, info, &str) <0 ) goto err;if (semanage_seuser_set_mlsrange (handle, seuser, str) <0 )
@@ -111,7 +110,8 @@ static int seuser_parse(return STATUS_NODATA ; err: -/* FIXME: handle error */ +ERR (handle,"parse error (%s: %u):\n%s" , + info->filename, info->lineno, info->orig_line);free (str);parse_dispose_line (info);return STATUS_ERR ;
libsemanage/src/users_file.c +28 -27
134 lines not on this page · raw message