Resync to sepol changes (again)
Changes:
- add count function to POLICYDB record extension
- fill in all missing functions in the correct tables
- implement stub: dbase_policydb_count
Bugfixes:
- set STATUS_SUCCESS, not ERR in policydb exists() on the success path
- fix user parser bug, which did not allow multiple spaces between the user name and the "roles"
- replace an error-prone inplace parse helper (which was wrong, and could crash), with a correct, and better one that uses malloc.
libsemanage/src/booleans_policydb.c +3 -2
@@ -25,8 +25,9 @@ record_policydb_table_t SEMANAGE_BOOL_PO .add = NULL, .modify = NULL, .set = sepol_bool_set, - .query = NULL, /* FIXME */ - .exists = NULL, /* FIXME */ + .query = sepol_bool_query, + .count = sepol_bool_count, + .exists = sepol_bool_exists, .iterate = sepol_bool_iterate, };
libsemanage/src/database_policydb.c +5 -4
@@ -379,7 +379,7 @@ static int dbase_policydb_exists ( goto err;exit_ro (handle, dbase); -return STATUS_ERR ; +return STATUS_SUCCESS ; err:/* FIXME: handle error */
@@ -395,10 +395,11 @@ static int dbase_policydb_count (if (enter_ro (handle, dbase) <0 ) goto err; -/* Stub */ - response =NULL ; +if (dbase->rptable->count (dbase->policydb, response) <0 ) + goto err; +exit_ro (handle, dbase); -return STATUS_ERR ; +return STATUS_SUCCESS ; err:/* FIXME: handle error */
libsemanage/src/database_policydb.h +9 -2
@@ -17,7 +17,8 @@ typedef struct record_policydb_table { record_key_t* rkey, record_t* record); -/* Modify policy record */ +/* Modify policy record, or add if +* the key isn't found */ int (*modify) ( sepol_policydb_t* policydb, record_key_t* rkey,
@@ -29,12 +30,18 @@ typedef struct record_policydb_table { record_key_t* rkey, record_t* record); -/* Query policy record */ +/* Query policy record - return the record +* or NULL if it isn't found */ int (*query) (sepol_policydb_t * policydb,record_key_t * rkey,record_t ** response); +/* Count records */ +int (*count) ( +sepol_policydb_t * policydb, +int * response); +/* Check if a record exists */ int (*exists) ( sepol_policydb_t* policydb,
libsemanage/src/interfaces_policydb.c +1 -0
@@ -26,6 +26,7 @@ record_policydb_table_t SEMANAGE_IFACE_P .modify = sepol_iface_modify, .set = NULL, .query = sepol_iface_query, + .count = sepol_iface_count, .exists = sepol_iface_exists, .iterate = sepol_iface_iterate, };
libsemanage/src/parse_utils.c +17 -6
@@ -256,13 +256,24 @@ char* parse_filter_space_until(parse_infreturn NULL ; } - -char *parse_fetch_string_inplace (parse_info_t * info) { +int parse_fetch_string (parse_info_t * info,char ** str) {char * start = info->ptr; +int len =0 ; +char * tmp_str =NULL ; -while (*(info->ptr) && !isspace (*(info->ptr))) +while (*(info->ptr) && !isspace (*(info->ptr))) { info->ptr++; - *(info->ptr)++ ='\0' ; - -return start; + len ++; + } + + tmp_str = (char *)malloc (len +1 ); +if (!tmp_str) { +/* FIXME: handle error */ +return STATUS_ERR ; + } + +strncpy (tmp_str, start, len); + *(tmp_str + len)='\0' ; + *str = tmp_str; +return STATUS_SUCCESS ; }
libsemanage/src/parse_utils.h +5 -5
@@ -81,10 +81,10 @@ extern char* parse_filter_space_until( const char* substr);/* Extract the next string (delimited by -* whitespace), and move the read pointer past it. -* This string is overwritten when the next line -* is read (inplace storage) */ -extern char *parse_fetch_string_inplace ( -parse_info_t * info); +* whitespace), and move the read pointer past it. */ + +extern int parse_fetch_string ( +parse_info_t * info, +char ** str_ptr);#endif
libsemanage/src/ports_policydb.c +1 -0
@@ -26,6 +26,7 @@ record_policydb_table_t SEMANAGE_PORT_PO .modify = sepol_port_modify, .set = NULL, .query = sepol_port_query, + .count = sepol_port_count, .exists = sepol_port_exists, .iterate = sepol_port_iterate, };
libsemanage/src/users_file.c +17 -2
@@ -70,13 +70,14 @@ static int user_parse(int islist =0 ;char * mls =NULL ;char * start; +char * name_str =NULL ;if (parse_skip_space (info) <0 ) goto err;if (!info->ptr) goto last; -/* Parse user name */ +/* Parse user header */ if (parse_assert_str (info,"user" ) <0 ) goto err;
@@ -87,7 +88,21 @@ static int user_parse(if (parse_assert_noeof (info) <0 ) goto err; -if (semanage_user_set_name (user,parse_fetch_string_inplace (info)) <0 ) +/* Parse user name */ +if (parse_fetch_string (info, &name_str) <0 ) + goto err; + +if (semanage_user_set_name (user, name_str) <0 ) { +free (name_str); + goto err; + } +free (name_str); + +if (parse_assert_space (info) <0 ) + goto err; +if (parse_skip_space (info) <0 ) + goto err; +if (parse_assert_noeof (info) <0 ) goto err;/* Parse roles header */
libsemanage/src/users_policydb.c +2 -1
@@ -25,7 +25,8 @@ record_policydb_table_t SEMANAGE_USER_PO .add = NULL, .modify = sepol_user_modify, .set = NULL, - .query = NULL, /* FIXME */ + .query = sepol_user_query, + .count = sepol_user_count, .exists = sepol_user_exists, .iterate = sepol_user_iterate, };