Eliminate struct pointer typedefs
PATCH 1/9 Eliminate struct pointer typedefs
The attached patch changes record structure typedefs in libsepol from struct pointer to struct alias. Also adds size_t in a few places.
include/sepol/boolean_record.h +29 -15
@@ -5,36 +5,50 @@struct sepol_bool ;struct sepol_bool_key ; -typedef struct sepol_bool *sepol_bool_t ; -typedef struct sepol_bool_key *sepol_bool_key_t ; +typedef struct sepol_bool sepol_bool_t ; +typedef struct sepol_bool_key sepol_bool_key_t ;/* Key */ extern int sepol_bool_key_create (const char * name, -sepol_bool_key_t * key); +sepol_bool_key_t ** key);extern int sepol_bool_key_extract ( -sepol_bool_t boolean, -sepol_bool_key_t * key_ptr); +sepol_bool_t * boolean, +sepol_bool_key_t ** key_ptr);extern void sepol_bool_key_free ( -sepol_bool_key_t key); +sepol_bool_key_t * key);extern int sepol_bool_compare ( -sepol_bool_t boolean, -sepol_bool_key_t key); +sepol_bool_t * boolean, +sepol_bool_key_t * key);/* Name */ -extern const char *sepol_bool_get_name (sepol_bool_t boolean); -extern int sepol_bool_set_name (sepol_bool_t boolean,const char * name); +extern const char *sepol_bool_get_name ( +sepol_bool_t * boolean); + +extern int sepol_bool_set_name ( +sepol_bool_t * boolean, +const char * name);/* Value */ -extern int sepol_bool_get_value (sepol_bool_t boolean); -extern void sepol_bool_set_value (sepol_bool_t boolean,int value); +extern int sepol_bool_get_value ( +sepol_bool_t * boolean); + +extern void sepol_bool_set_value ( +sepol_bool_t * boolean, +int value);/* Create/Clone/Destroy */ -extern int sepol_bool_create (sepol_bool_t * bool_ptr); -extern int sepol_bool_clone (sepol_bool_t boolean,sepol_bool_t * bool_ptr); -extern void sepol_bool_free (sepol_bool_t boolean); +extern int sepol_bool_create ( +sepol_bool_t ** bool_ptr); + +extern int sepol_bool_clone ( +sepol_bool_t * boolean, +sepol_bool_t ** bool_ptr); + +extern void sepol_bool_free ( +sepol_bool_t * boolean);#endif
include/sepol/booleans.h +4 -3
@@ -1,18 +1,19 @@#ifndef _SEPOL_BOOLEANS_H_#define _SEPOL_BOOLEANS_H_ +#include <stddef.h> #include <sepol/policydb.h> #include <sepol/boolean_record.h> /* Load a boolean into the policy */ extern int sepol_bool_load (policydb_t * policydb, -sepol_bool_t boolean); +sepol_bool_t * boolean);/* Load a boolean array into the policy */ extern int sepol_bool_load_array (policydb_t * policydb, -sepol_bool_t * bool_arr, -int bool_arr_len); +sepol_bool_t ** bool_arr, +size_t bool_arr_len);#endif
include/sepol/context.h +1 -1
@@ -118,7 +118,7 @@extern int sepol_ctx_struct_create (struct policydb *policydb,context_struct_t ** cptr, -sepol_context_t data); +sepol_context_t * data);/* Create a context structure from string representation */ extern int sepol_ctx_struct_from_string(
include/sepol/context_record.h +40 -14
74 lines not on this page · raw message
include/sepol/iface_record.h +35 -17
74 lines not on this page · raw message
include/sepol/interfaces.h +2 -2
@@ -8,13 +8,13 @@/* Get the current context mapping for this interface */ extern int sepol_iface_get_context (policydb_t * policydb, -sepol_iface_t data, +sepol_iface_t * data,char ** ifcon_str,size_t * ifcon_str_len,char ** msgcon_str,size_t * msgcon_str_len);/* Load an interface into policy */ extern int sepol_iface_load (policydb_t * policydb, -sepol_iface_t data); +sepol_iface_t * data);#endif
include/sepol/port_record.h +45 -20
91 lines not on this page · raw message
include/sepol/ports.h +2 -2
@@ -10,13 +10,13 @@* success. The returned data is allocated on the heap */ int sepol_port_get_context (policydb_t * policydb, -sepol_port_t data, +sepol_port_t * data,char ** con_str,size_t * con_str_len);/* Load the given port into policy. No shadowing is allowed. */ extern int sepol_port_load (policydb_t * policydb, -sepol_port_t data); +sepol_port_t * data);#endif
include/sepol/user_record.h +52 -25
115 lines not on this page · raw message
include/sepol/users.h +3 -3
@@ -13,7 +13,7 @@Load allows duplicates, but add does not. */ extern int sepol_user_add (policydb_t * policydb, -sepol_user_t user); +sepol_user_t * user); extern int sepol_user_del( policydb_t* policydb,
@@ -21,7 +21,7 @@extern int sepol_user_load (policydb_t * policydb, -sepol_user_t user); +sepol_user_t * user);/* Check if users or roles are valid */ extern int sepol_user_is_valid(
@@ -43,4 +43,4 @@char *** roles, size_t* nroles); -#endif /* _SEPOL_USERS_H_ */ +#endif
src/boolean_record.c +16 -17
@@ -20,10 +20,10 @@int sepol_bool_key_create (const char * name, -sepol_bool_key_t * key_ptr) { +sepol_bool_key_t ** key_ptr) { -sepol_bool_key_t tmp_key = - (sepol_bool_key_t )malloc (sizeof (struct sepol_bool_key )); +sepol_bool_key_t * tmp_key = + (sepol_bool_key_t *)malloc (sizeof (struct sepol_bool_key ));if (!tmp_key) { DEBUG(__FUNCTION__, "out of memory, "
@@ -37,7 +37,7 @@return STATUS_SUCCESS ; } -int sepol_bool_key_extract (sepol_bool_t boolean,sepol_bool_key_t * key_ptr) { +int sepol_bool_key_extract (sepol_bool_t * boolean,sepol_bool_key_t ** key_ptr) {if (sepol_bool_key_create (boolean->name, key_ptr) <0 ) {DEBUG (__FUNCTION__,"could not extract key from boolean %s\n" , boolean->name);
@@ -47,13 +47,13 @@return STATUS_SUCCESS ; } -void sepol_bool_key_free (sepol_bool_key_t key) { +void sepol_bool_key_free (sepol_bool_key_t * key) {free (key); }int sepol_bool_compare ( -sepol_bool_t boolean, -sepol_bool_key_t key) { +sepol_bool_t * boolean, +sepol_bool_key_t * key) {if (!strcmp (boolean->name, key->name))return 0 ;
@@ -61,11 +61,11 @@ }/* Name */ -const char *sepol_bool_get_name (sepol_bool_t boolean) { +const char *sepol_bool_get_name (sepol_bool_t * boolean) {return boolean->name; } -int sepol_bool_set_name (sepol_bool_t boolean,const char * name) { +int sepol_bool_set_name (sepol_bool_t * boolean,const char * name) { boolean->name =strdup (name);if (!boolean->name) { DEBUG(__FUNCTION__, "out of memory, "
@@ -76,18 +76,17 @@ }/* Value */ -int sepol_bool_get_value (sepol_bool_t boolean) { +int sepol_bool_get_value (sepol_bool_t * boolean) {return boolean->value; } -void sepol_bool_set_value (sepol_bool_t boolean,int value) { +void sepol_bool_set_value (sepol_bool_t * boolean,int value) { boolean->value = value; }/* Create */ -int sepol_bool_create (sepol_bool_t * bool_ptr) { -sepol_bool_t boolean = (sepol_bool_t ) -malloc (sizeof (struct sepol_bool )); +int sepol_bool_create (sepol_bool_t ** bool_ptr) { +sepol_bool_t * boolean = (sepol_bool_t *)malloc (sizeof (sepol_bool_t));if (!boolean) { DEBUG(__FUNCTION__, "out of memory, "
@@ -103,8 +102,8 @@ }/* Deep copy clone */ -int sepol_bool_clone (sepol_bool_t boolean,sepol_bool_t * bool_ptr) { -sepol_bool_t new_bool =NULL ; +int sepol_bool_clone (sepol_bool_t * boolean,sepol_bool_t ** bool_ptr) { +sepol_bool_t * new_bool =NULL ;if (sepol_bool_create (&new_bool) <0 ) goto err;
@@ -124,7 +123,7 @@ }/* Destroy */ -void sepol_bool_free (sepol_bool_t boolean) { +void sepol_bool_free (sepol_bool_t * boolean) {if (!boolean)return ;
src/booleans.c +7 -6
@@ -1,5 +1,6 @@#include <stdio.h> #include <stdlib.h> +#include <stddef.h> #include <errno.h> #include "private.h"
@@ -11,9 +12,9 @@#include <sepol/conditional.h> #include <sepol/boolean_record.h> -static int bool_update ( +static inline int bool_update (policydb_t * policydb, -sepol_bool_t boolean) { +sepol_bool_t * boolean) {char * name =strdup (sepol_bool_get_name (boolean));int value =sepol_bool_get_value (boolean);
@@ -46,7 +47,7 @@ }int sepol_bool_load ( -policydb_t * policydb,sepol_bool_t boolean) { +policydb_t * policydb,sepol_bool_t * boolean) {if (bool_update (policydb, boolean) <0 ) goto err;
@@ -67,10 +68,10 @@int sepol_bool_load_array (policydb_t * policydb, -sepol_bool_t * bool_arr, -int bool_arr_len) { +sepol_bool_t ** bool_arr, +size_t bool_arr_len) { -int i, errors =0 ; +unsigned int i, errors =0 ;for (i =0 ; i < bool_arr_len; i++)if (bool_update (policydb, bool_arr[i]) <0 ) {
src/context.c +2 -2
@@ -122,7 +122,7 @@int sepol_ctx_struct_create (policydb_t * policydb,context_struct_t ** cptr, -sepol_context_t data) { +sepol_context_t * data) {context_struct_t * scontext =NULL ;user_datum_t * usrdatum;
@@ -232,7 +232,7 @@ size_t con_str_len) {char * con_cpy =NULL ; -sepol_context_t ctx_info =NULL ; +sepol_context_t * ctx_info =NULL ;/* sepol_context_from_string expects a NULL-terminated string */ con_cpy =malloc (con_str_len +1 );
src/context_record.c +18 -18
@@ -21,11 +21,11 @@ };/* User */ -const char *sepol_context_get_user (sepol_context_t con) { +const char *sepol_context_get_user (sepol_context_t * con) {return con->user; } -int sepol_context_set_user (sepol_context_t con,const char * user) { +int sepol_context_set_user (sepol_context_t * con,const char * user) { con->user =strdup (user);if (!con->user) { DEBUG(__FUNCTION__, "out of memory, could not set "
@@ -36,11 +36,11 @@ }/* Role */ -const char *sepol_context_get_role (sepol_context_t con) { +const char *sepol_context_get_role (sepol_context_t * con) {return con->role; } -int sepol_context_set_role (sepol_context_t con,const char * role) { +int sepol_context_set_role (sepol_context_t * con,const char * role) { con->role =strdup (role);if (!con->role) { DEBUG(__FUNCTION__, "out of memory, could not set "
@@ -51,11 +51,11 @@ }/* Type */ -const char *sepol_context_get_type (sepol_context_t con) { +const char *sepol_context_get_type (sepol_context_t * con) {return con->type; } -int sepol_context_set_type (sepol_context_t con,const char * type) { +int sepol_context_set_type (sepol_context_t * con,const char * type) { con->type =strdup (type);if (!con->role) { DEBUG(__FUNCTION__, "out of memory, could not set "
@@ -66,11 +66,11 @@ }/* MLS */ -const char *sepol_context_get_mls (sepol_context_t con) { +const char *sepol_context_get_mls (sepol_context_t * con) {return con->mls; } -int sepol_context_set_mls (sepol_context_t con,const char * mls) { +int sepol_context_set_mls (sepol_context_t * con,const char * mls) { con->mls =strdup (mls);if (!con->mls) { DEBUG(__FUNCTION__, "out of memory, could not set "
@@ -81,9 +81,9 @@ }/* Create */ -int sepol_context_create (sepol_context_t * con_ptr) { -sepol_context_t con = - (sepol_context_t )malloc (sizeof (struct sepol_context )); +int sepol_context_create (sepol_context_t ** con_ptr) { +sepol_context_t * con = + (sepol_context_t *)malloc (sizeof (sepol_context_t));if (!con) { DEBUG(__FUNCTION__, "out of memory, could not "
@@ -101,10 +101,10 @@/* Deep copy clone */ int sepol_context_clone ( -sepol_context_t con, -sepol_context_t * con_ptr) { +sepol_context_t * con, +sepol_context_t ** con_ptr) { -sepol_context_t new_con =NULL ; +sepol_context_t * new_con =NULL ;if (sepol_context_create (&new_con) <0 ) goto err;
@@ -133,7 +133,7 @@ }/* Destroy */ -void sepol_context_free (sepol_context_t con) { +void sepol_context_free (sepol_context_t * con) {if (!con)return ;
@@ -144,10 +144,10 @@free (con); } -int sepol_context_from_string (const char * str,sepol_context_t * con) { +int sepol_context_from_string (const char * str,sepol_context_t ** con) {char *tmp =NULL , *low, *high; -sepol_context_t tmp_con =NULL ; +sepol_context_t * tmp_con =NULL ;if (!strcmp (str,"<<none>>" )) { *con =NULL ;
@@ -214,7 +214,7 @@return STATUS_ERR ; } -char *sepol_context_to_string (sepol_context_t con) { +char *sepol_context_to_string (sepol_context_t * con) {const int user_sz =strlen (con->user);const int role_sz =strlen (con->role);
src/iface_record.c +21 -21
117 lines not on this page · raw message
src/interfaces.c +4 -4
@@ -12,10 +12,10 @@/* Create a low level interface structure from * a high level representation */ -static int sepol_iface_struct_create ( +int sepol_iface_struct_create (policydb_t * policydb,ocontext_t ** iface, -sepol_iface_t data) { +sepol_iface_t * data) {ocontext_t * tmp_iface =NULL ;context_struct_t * tmp_ifcon =NULL ;
@@ -60,7 +60,7 @@/* Get the current context mapping for this interface */ int sepol_iface_get_context (policydb_t * policydb, -sepol_iface_t data, +sepol_iface_t * data,char ** ifcon_str,size_t * ifcon_str_len,char ** msgcon_str,size_t * msgcon_str_len) {
@@ -93,7 +93,7 @@/* Load an interface into policy */ int sepol_iface_load (policydb_t * policydb, -sepol_iface_t data) { +sepol_iface_t * data) {ocontext_t * iface =NULL ;char *ifcon_str, *msgcon_str;
src/port_record.c +23 -23
134 lines not on this page · raw message
src/ports.c +4 -4
@@ -25,10 +25,10 @@/* Create a low level port structure from * a high level representation */ -static int sepol_port_struct_create ( +int sepol_port_struct_create (policydb_t * policydb,ocontext_t ** port, -sepol_port_t data) { +sepol_port_t * data) {ocontext_t * tmp_port =NULL ;context_struct_t * tmp_con =NULL ;
@@ -75,7 +75,7 @@/* Get the current context mapping for this port */ int sepol_port_get_context (policydb_t * policydb, -sepol_port_t data, +sepol_port_t * data,char ** con_str,size_t * con_str_len) {
@@ -121,7 +121,7 @@/* Load a port into policy */ int sepol_port_load (policydb_t * policydb, -sepol_port_t data) { +sepol_port_t * data) {ocontext_t * port =NULL ;char * dup_match;
src/user_record.c +26 -27
163 lines not on this page · raw message
src/users.c +2 -2
@@ -81,7 +81,7 @@/* Add a user to the given policydb. The user may not exist already */ -int sepol_user_add (policydb_t * policydb,sepol_user_t user) { +int sepol_user_add (policydb_t * policydb,sepol_user_t * user) {char * name =NULL ;user_datum_t * usrdatum;
@@ -157,7 +157,7 @@* which case the supplied data replaces the existing data. Alternatively, * the user could be new. */ -int sepol_user_load (policydb_t * policydb,sepol_user_t user) { +int sepol_user_load (policydb_t * policydb,sepol_user_t * user) {/* For user data */ const char *tmp_mlslevel, *tmp_mlsrange;
Re: [ 2/9 ] [ SEMANAGE ] Restore sepol compatibility
The attached patch restores compatibility with sepol broken in the previous patch. It also adds stddef.h in a few places. The idea here is to keep things from breaking, not to replace typedefs in this library (this is a later patch).
include/semanage/user_record.h +2 -0
@@ -1,6 +1,8 @@#ifndef _SEMANAGE_USER_RECORD_H_#define _SEMANAGE_USER_RECORD_H_ +#include <stddef.h> +struct semanage_user ;struct semanage_user_key ;typedef struct semanage_user *semanage_user_t ;
src/boolean_record.c +2 -2
@@ -1,7 +1,7 @@#include <sepol/boolean_record.h> -typedef sepol_bool_t semanage_bool_t ; -typedef sepol_bool_key_t semanage_bool_key_t ; +typedef sepol_bool_t *semanage_bool_t ; +typedef sepol_bool_key_t *semanage_bool_key_t ;/* Key */ int semanage_bool_key_create (const char * name,semanage_bool_key_t * key) {
src/context_record.c +1 -1
@@ -1,6 +1,6 @@#include <sepol/context_record.h> -typedef sepol_context_t semanage_context_t ; +typedef sepol_context_t *semanage_context_t ;/* User */ const char *semanage_context_get_user (semanage_context_t con) {
src/iface_record.c +3 -3
@@ -1,8 +1,8 @@#include <sepol/iface_record.h> -typedef sepol_context_t semanage_context_t ; -typedef sepol_iface_t semanage_iface_t ; -typedef sepol_iface_key_t semanage_iface_key_t ; +typedef sepol_context_t *semanage_context_t ; +typedef sepol_iface_t *semanage_iface_t ; +typedef sepol_iface_key_t *semanage_iface_key_t ;/* Key */ int semanage_iface_compare (semanage_iface_t iface,semanage_iface_key_t key) {
src/port_record.c +3 -3
@@ -1,8 +1,8 @@#include <sepol/port_record.h> -typedef sepol_context_t semanage_context_t ; -typedef sepol_port_t semanage_port_t ; -typedef sepol_port_key_t semanage_port_key_t ; +typedef sepol_context_t *semanage_context_t ; +typedef sepol_port_t *semanage_port_t ; +typedef sepol_port_key_t *semanage_port_key_t ;/* Key */ int semanage_port_compare (semanage_port_t port,semanage_port_key_t key) {
src/user_record.c +3 -2
@@ -1,7 +1,8 @@ +#include <stddef.h> #include <sepol/user_record.h> -typedef sepol_user_t semanage_user_t ; -typedef sepol_user_key_t semanage_user_key_t ; +typedef sepol_user_t *semanage_user_t ; +typedef sepol_user_key_t *semanage_user_key_t ;/* Key */ int semanage_user_key_create (const char * name,semanage_user_key_t * key) {
Re: [ 3/9 ] [ SEMANAGE ] Rename files
In reply to Ivan GyurdievThe attached patch renames:
record_file.h -> interfaces.hdatabase_file.h -> database.h
with no changes in those files (hopefully).
This reflects changes in following patches.
Also, add proper status codes to some stubs.
src/database.c +367 -0
@@ -0,0 +1,367 @@ +#include <stdlib.h> +#include <stddef.h> +#include <stdio.h> +#include <stdio_ext.h> +#include <errno.h> +#include "debug.h" +#include "database.h" +#include "interfaces.h" +#include "users_file.h" +#include "ports_file.h" + +/* Representation of the database once loaded in memory */ +typedef struct cache_entry { +record_t data; +struct cache_entry * prev; +struct cache_entry * next; +}cache_entry_t ; + +/* Database-specific configuration */ +struct dbase_config { + +/* What's the format of this database */ +record_table_t * rtable; + +/* Where is it stored */ +const char * filename; + +/* Once parsed, it is cached here */ +cache_entry_t * cache; +size_t cache_sz; +}; + +static int dbase_cache_add ( +dbase_config_t * dconfig, +record_t data) { + +cache_entry_t * entry = + (cache_entry_t *)malloc (sizeof (cache_entry_t)); +if (entry ==NULL ) + goto omem; + entry->data = data; + entry->prev =NULL ; + entry->next = dconfig->cache; +if (dconfig->cache !=NULL ) + dconfig->cache->prev = entry; + dconfig->cache = entry; + dconfig->cache_sz++; + +return STATUS_SUCCESS ; + omem: +/* FIXME: handle error condition */ +return STATUS_ERR ; +} + +static int dbase_open_file (parse_info_t * info) { + + info->file_stream =fopen (info->filename,"r" ); +if (!info->file_stream && (errno !=ENOENT )) { +/* FIXME: handle error condition */ +return STATUS_ERR ; + } +if (info->file_stream) +__fsetlocking (info->file_stream,FSETLOCKING_BYCALLER ); + +return STATUS_SUCCESS ; +} + +static void dbase_close_file (parse_info_t * info) { +if (info->file_stream && (fclose (info->file_stream) <0 )) +/* FIXME: handle error condition */ + info->file_stream =NULL ; +} + +static int dbase_cache_fill ( +dbase_config_t * dconfig) { + +/* Already cached */ +if (dconfig->cache !=NULL ) +return STATUS_SUCCESS ; + +int perr_fatal =0 ; +/* FIXME: pass from caller? */ + +record_t process_record =NULL ; +int pstatus =STATUS_SUCCESS ; +parse_info_t parse_info; + parse_info.filename = dconfig->filename; + parse_info.parse_arg =NULL ; +/* FIXME: pass from caller? */ + +if (dbase_open_file (&parse_info) <0 ) + goto err; + +/* Main processing loop */ +do { +/* Create record */ +if (dconfig->rtable->create (&process_record) <0 ) + goto err; + +/* Parse record */ + pstatus = dconfig->rtable->parse (&parse_info, process_record); + +/* Parse error is fatal, exit */ +if (perr_fatal && (pstatus <0 )) + goto err; + +/* Parse error is not fatal */ +else if (pstatus <0 ) +continue ; + +/* Add record to list */ +if (dbase_cache_add (dconfig, process_record) <0 ) + goto err; + + }while (pstatus !=STATUS_NODATA ); + +dbase_close_file (&parse_info); +return STATUS_SUCCESS ; + + err: +/* FIXME: handle failure */ + dconfig->rtable->free (process_record); +dbase_close_file (&parse_info); +return STATUS_ERR ; +} + +static int dbase_cache_locate ( +dbase_config_t * dconfig, +record_key_t key, +cache_entry_t ** entry) { + +cache_entry_t * ptr; + +if (dbase_cache_fill (dconfig) <0 ) + goto err; + +for (ptr = dconfig->cache; ptr !=NULL ; ptr = ptr->next) { +if (! dconfig->rtable->compare (ptr->data, key)) { + *entry = ptr; +return STATUS_SUCCESS ; + } + } + +return STATUS_NODATA ; + err: +/* FIXME: handle error condition */ +return STATUS_ERR ; +} + +int dbase_add ( +dbase_config_t * dconfig, +record_key_t key, +record_t data) { + +int exists; + +if (dbase_cache_fill (dconfig) <0 ) + goto err; + +if (dbase_exists (dconfig, key, &exists) <0 ) + goto err; + +else if (exists) { +/* FIXME: handle error condition */ + goto err; + } + +if (dbase_cache_add (dconfig, data) <0 ) + goto err; + +return STATUS_SUCCESS ; + + err: +/* FIXME: handle error condition */ +return STATUS_ERR ; +} + +int dbase_modify ( +dbase_config_t * dconfig, +record_key_t key, +record_t data) { + +cache_entry_t * entry; +int status; + +if (dbase_cache_fill (dconfig) <0 ) + goto err; + + status =dbase_cache_locate (dconfig, key, &entry); +if (status <0 ) + goto err; +if (status ==STATUS_NODATA ) +return dbase_add (dconfig,key,data); +else + entry->data = data; + +return STATUS_SUCCESS ; + + err: +/* FIXME: handle error condition */ +return STATUS_ERR ; + +} + +int dbase_del ( +dbase_config_t * dconfig, +record_key_t key) { + +cache_entry_t * entry; +int status; + +if (dbase_cache_fill (dconfig) <0 ) + goto err; + + status =dbase_cache_locate (dconfig, key, &entry); +if (status <0 ) + goto err; + +else if (status !=STATUS_NODATA ) { +if (entry->next !=NULL ) + entry->next->prev = entry->prev; + +if (entry->prev !=NULL ) + entry->prev->next = entry->next; +else + dconfig->cache = entry->next; + + dconfig->rtable->free (entry->data); + dconfig->cache_sz--; +free (entry); + } + +return STATUS_SUCCESS ; + err: +/* FIXME: Handle error condition */ +return STATUS_ERR ; +} + +int dbase_query ( +dbase_config_t * dconfig, +record_key_t key, +record_t * response) { + +cache_entry_t * entry; +int status; + +if (dbase_cache_fill (dconfig) <0 ) + goto err; + + status =dbase_cache_locate (dconfig, key, &entry); +if (status <0 || status ==STATUS_NODATA ) + goto err; + +if (dconfig->rtable->clone (entry->data, *response) <0 ) + goto err; + +return STATUS_SUCCESS ; + err: +/* FIXME: Handle error condition */ +return STATUS_ERR ; +} + +int dbase_exists ( +dbase_config_t * dconfig, +record_key_t key, +int * response) { + +cache_entry_t * entry; +int status; + +if (dbase_cache_fill (dconfig) <0 ) + goto err; + + status =dbase_cache_locate (dconfig, key, &entry); +if (status <0 ) + goto err; + + *response = (status !=STATUS_NODATA ); +return STATUS_SUCCESS ; + + err: +/* FIXME: handle error condition */ +return STATUS_ERR ; +} + +int dbase_count ( +dbase_config_t * dconfig, +int * response) { + +if (dbase_cache_fill (dconfig) <0 ) + goto err; + + *response = dconfig->cache_sz; +return STATUS_SUCCESS ; + + err: +/* FIXME: Handle error condition */ +return STATUS_ERR ; +} + +int dbase_iterate ( +dbase_config_t * dconfig, +int (*fn) (record_t record,void * varg), +void * fn_arg) { + +int status; +cache_entry_t * ptr; + +if (dbase_cache_fill (dconfig) <0 ) + goto err; + +for (ptr = dconfig->cache; ptr !=NULL ; ptr = ptr->next) { + status =fn (ptr->data, fn_arg); +if (status <0 ) + goto err; + +else if (status >0 ) +break ; + } + +return STATUS_SUCCESS ; + + err: +/* FIXME: Handle error condition */ +return STATUS_ERR ; +} + +int dbase_list ( +dbase_config_t * dconfig, +record_t ** records, +size_t * count) { + +cache_entry_t * ptr; +record_t * tmp_records =NULL ; +size_t tmp_count; +int i =0 ; + +if (dbase_cache_fill (dconfig) <0 ) + goto err; + + tmp_count = dconfig->cache_sz; + +if (tmp_count >0 ) { + tmp_records = (record_t *)calloc (tmp_count,sizeof (record_t)); +if (tmp_records ==NULL ) + goto omem; + +for (ptr = dconfig->cache; ptr !=NULL ; ptr = ptr->next) +if (dconfig->rtable->clone (ptr->data, &tmp_records[i++]) <0 ) + goto err; + + } + *records = tmp_records; + *count = tmp_count; + +return STATUS_SUCCESS ; + + omem: +/* FIXME: handle error condition */ + + err: +for (; i >=0 ; i--) +free (tmp_records[i]); +free (tmp_records); +/* FIXME: handle error condition */ +return STATUS_ERR ; +}
src/database_file.c +0 -367
367 lines not on this page · raw message
src/interfaces.h +57 -0
57 lines not on this page · raw message
src/ports_file.c +8 -5
@@ -1,11 +1,14 @@ -#include <stdlib.h> -#include <stdio.h> #include <semanage/port_record.h> typedef semanage_port_t record_t ;typedef semanage_port_key_t record_key_t ;#define RECORD_DEFINED -#include "record_file.h" + +#include <stdlib.h> +#include <stdio.h> +#include <semanage/port_record.h> +#include "debug.h" +#include "interfaces.h" static int semanage_port_print( semanage_port_t port,
@@ -14,7 +17,7 @@/* Stub */ port =NULL ; str =NULL ; -return -1 ; +return STATUS_SUCCESS ; } static int semanage_port_parse(
@@ -24,7 +27,7 @@/* Stub */ info =NULL ; port =NULL ; -return -1 ; +return STATUS_SUCCESS ; }record_table_t RTABLE_PORT = {
src/ports_file.h +1 -1
@@ -1,7 +1,7 @@#ifndef _SEMANAGE_PORTS_FILE_H_#define _SEMANAGE_PORTS_FILE_H_ -#include "record_file.h" +#include "interfaces.h" extern record_table_t RTABLE_PORT ;
src/record_file.h +0 -57
57 lines not on this page · raw message
src/users_file.c +7 -5
@@ -1,11 +1,13 @@ -#include <stdlib.h> -#include <stdio.h> #include <semanage/user_record.h> typedef semanage_user_t record_t ;typedef semanage_user_key_t record_key_t ;#define RECORD_DEFINED -#include "record_file.h" + +#include <stdlib.h> +#include <stdio.h> +#include "interfaces.h" +#include "debug.h" static int semanage_user_print( semanage_user_t user,
@@ -14,7 +16,7 @@/* Stub */ user =NULL ; str =NULL ; -return -1 ; +return STATUS_SUCCESS ; } static int semanage_user_parse(
@@ -24,7 +26,7 @@/* Stub */ info =NULL ; user =NULL ; -return -1 ; +return STATUS_SUCCESS ; }record_table_t RTABLE_USER = {
src/users_file.h +1 -1
@@ -1,7 +1,7 @@#ifndef _SEMANAGE_USERS_FILE_H_#define _SEMANAGE_USERS_FILE_H_ -#include "record_file.h" +#include "interfaces.h" extern record_table_t RTABLE_USER ;
Re: [ 4/9 ] [ SEMANAGE ] Database initialization Stage 1
In reply to Ivan GyurdievThe attached patch breaks up semanage.h/semanage_private.h into modules.h, handle.h, debug.h. It moves the debug function into debug.c. It adds functions to intialize and release database resources, and uses those to add USER and PORT file databases to the handle.
Also, rename some variables and datatypes. Fix caching. Add functions to flush and invalidate the cache.
src/database.c +111 -50
@@ -17,7 +17,7 @@ } cache_entry_t;/* Database-specific configuration */ -struct dbase_config { +struct dbase {/* What's the format of this database */ record_table_t * rtable;
@@ -28,10 +28,69 @@/* Once parsed, it is cached here */ cache_entry_t * cache;size_t cache_sz; +int cached; +int cache_invalid; }; +/* Initialize a database */ +int dbase_init ( +record_table_t * rtable, +const char * filename, +dbase_t ** dbase) { + +dbase_t * tmp_dbase = + (dbase_t *)malloc (sizeof (dbase_t)); + +if (tmp_dbase ==NULL ) + goto omem; + + tmp_dbase->rtable = rtable; + tmp_dbase->filename = filename; + tmp_dbase->cache =NULL ; + tmp_dbase->cache_sz =0 ; + tmp_dbase->cached =0 ; + tmp_dbase->cache_invalid =0 ; + + *dbase = tmp_dbase; +return STATUS_SUCCESS ; + + omem: +/* FIXME: handle error codntion */ +free (tmp_dbase); +return STATUS_ERR ; +} + +/* Release a database */ +void dbase_release ( +dbase_t * dbase) { + +cache_entry_t *prev, *ptr; +while (ptr !=NULL ) { + prev = ptr; + ptr = ptr->next; + dbase->rtable->free (prev->data); +free (prev); + } +} + +/* Invalidate database cache */ +void dbase_invalidate_cache ( +dbase_t * dbase) { + + dbase->cache_invalid =1 ; +} + +/* Flush the database cache */ +int dbase_flush ( +dbase_t * dbase) { + +/* Stub */ + dbase =NULL ; +return STATUS_SUCCESS ; +} +static int dbase_cache_add ( -dbase_config_t * dconfig, +dbase_t * dbase,record_t data) { cache_entry_t* entry =
@@ -40,11 +99,11 @@ goto omem; entry->data = data; entry->prev =NULL ; - entry->next = dconfig->cache; -if (dconfig->cache !=NULL ) - dconfig->cache->prev = entry; - dconfig->cache = entry; - dconfig->cache_sz++; + entry->next = dbase->cache; +if (dbase->cache !=NULL ) + dbase->cache->prev = entry; + dbase->cache = entry; + dbase->cache_sz++;return STATUS_SUCCESS ; omem:
@@ -72,10 +131,10 @@ }static int dbase_cache_fill ( -dbase_config_t * dconfig) { +dbase_t * dbase) {/* Already cached */ -if (dconfig->cache !=NULL ) +if (dbase->cached && (!dbase->cache_invalid))return STATUS_SUCCESS ;int perr_fatal =0 ;
@@ -84,7 +143,7 @@record_t process_record =NULL ;int pstatus =STATUS_SUCCESS ;parse_info_t parse_info; - parse_info.filename = dconfig->filename; + parse_info.filename = dbase->filename; parse_info.parse_arg =NULL ;/* FIXME: pass from caller? */
@@ -94,11 +153,11 @@/* Main processing loop */ do { /* Create record */ - if (dconfig->rtable->create(&process_record) < 0) + if (dbase->rtable->create(&process_record) < 0) goto err; /* Parse record */ - pstatus = dconfig->rtable->parse(&parse_info, process_record); + pstatus = dbase->rtable->parse(&parse_info, process_record); /* Parse error is fatal, exit */ if (perr_fatal && (pstatus < 0))
@@ -109,33 +168,35 @@continue ;/* Add record to list */ -if (dbase_cache_add (dconfig, process_record) <0 ) +if (dbase_cache_add (dbase, process_record) <0 ) goto err; }while (pstatus !=STATUS_NODATA );dbase_close_file (&parse_info); + dbase->cached =1 ; + dbase->cache_invalid =0 ;return STATUS_SUCCESS ; err:/* FIXME: handle failure */ - dconfig->rtable->free (process_record); + dbase->rtable->free (process_record);dbase_close_file (&parse_info);return STATUS_ERR ; }static int dbase_cache_locate ( -dbase_config_t * dconfig, +dbase_t * dbase,record_key_t key,cache_entry_t ** entry) {cache_entry_t * ptr; -if (dbase_cache_fill (dconfig) <0 ) +if (dbase_cache_fill (dbase) <0 ) goto err; -for (ptr = dconfig->cache; ptr !=NULL ; ptr = ptr->next) { -if (! dconfig->rtable->compare (ptr->data, key)) { +for (ptr = dbase->cache; ptr !=NULL ; ptr = ptr->next) { +if (! dbase->rtable->compare (ptr->data, key)) { *entry = ptr;return STATUS_SUCCESS ; }
@@ -148,16 +209,16 @@ }int dbase_add ( -dbase_config_t * dconfig, +dbase_t * dbase,record_key_t key,record_t data) {int exists; -if (dbase_cache_fill (dconfig) <0 ) +if (dbase_cache_fill (dbase) <0 ) goto err; -if (dbase_exists (dconfig, key, &exists) <0 ) +if (dbase_exists (dbase, key, &exists) <0 ) goto err;else if (exists) {
@@ -165,7 +226,7 @@ goto err; } -if (dbase_cache_add (dconfig, data) <0 ) +if (dbase_cache_add (dbase, data) <0 ) goto err;return STATUS_SUCCESS ;
@@ -176,21 +237,21 @@ }int dbase_modify ( -dbase_config_t * dconfig, +dbase_t * dbase,record_key_t key,record_t data) {cache_entry_t * entry;int status; -if (dbase_cache_fill (dconfig) <0 ) +if (dbase_cache_fill (dbase) <0 ) goto err; - status =dbase_cache_locate (dconfig, key, &entry); + status =dbase_cache_locate (dbase, key, &entry);if (status <0 ) goto err;if (status ==STATUS_NODATA ) -return dbase_add (dconfig,key,data); +return dbase_add (dbase,key,data);else entry->data = data;
@@ -203,16 +264,16 @@ }int dbase_del ( -dbase_config_t * dconfig, +dbase_t * dbase,record_key_t key) {cache_entry_t * entry;int status; -if (dbase_cache_fill (dconfig) <0 ) +if (dbase_cache_fill (dbase) <0 ) goto err; - status =dbase_cache_locate (dconfig, key, &entry); + status =dbase_cache_locate (dbase, key, &entry);if (status <0 ) goto err;
@@ -223,10 +284,10 @@if (entry->prev !=NULL ) entry->prev->next = entry->next;else - dconfig->cache = entry->next; + dbase->cache = entry->next; - dconfig->rtable->free (entry->data); - dconfig->cache_sz--; + dbase->rtable->free (entry->data); + dbase->cache_sz--;free (entry); }
@@ -237,21 +298,21 @@ }int dbase_query ( -dbase_config_t * dconfig, +dbase_t * dbase,record_key_t key,record_t * response) {cache_entry_t * entry;int status; -if (dbase_cache_fill (dconfig) <0 ) +if (dbase_cache_fill (dbase) <0 ) goto err; - status =dbase_cache_locate (dconfig, key, &entry); + status =dbase_cache_locate (dbase, key, &entry);if (status <0 || status ==STATUS_NODATA ) goto err; -if (dconfig->rtable->clone (entry->data, *response) <0 ) +if (dbase->rtable->clone (entry->data, *response) <0 ) goto err;return STATUS_SUCCESS ;
@@ -261,17 +322,17 @@ }int dbase_exists ( -dbase_config_t * dconfig, +dbase_t * dbase,record_key_t key,int * response) {cache_entry_t * entry;int status; -if (dbase_cache_fill (dconfig) <0 ) +if (dbase_cache_fill (dbase) <0 ) goto err; - status =dbase_cache_locate (dconfig, key, &entry); + status =dbase_cache_locate (dbase, key, &entry);if (status <0 ) goto err;
@@ -284,13 +345,13 @@ }int dbase_count ( -dbase_config_t * dconfig, +dbase_t * dbase,int * response) { -if (dbase_cache_fill (dconfig) <0 ) +if (dbase_cache_fill (dbase) <0 ) goto err; - *response = dconfig->cache_sz; + *response = dbase->cache_sz;return STATUS_SUCCESS ; err:
@@ -299,17 +360,17 @@ }int dbase_iterate ( -dbase_config_t * dconfig, +dbase_t * dbase,int (*fn) (record_t record,void * varg),void * fn_arg) {int status;cache_entry_t * ptr; -if (dbase_cache_fill (dconfig) <0 ) +if (dbase_cache_fill (dbase) <0 ) goto err; -for (ptr = dconfig->cache; ptr !=NULL ; ptr = ptr->next) { +for (ptr = dbase->cache; ptr !=NULL ; ptr = ptr->next) { status =fn (ptr->data, fn_arg);if (status <0 ) goto err;
@@ -326,7 +387,7 @@ }int dbase_list ( -dbase_config_t * dconfig, +dbase_t * dbase,record_t ** records,size_t * count) {
@@ -335,18 +396,18 @@size_t tmp_count;int i =0 ; -if (dbase_cache_fill (dconfig) <0 ) +if (dbase_cache_fill (dbase) <0 ) goto err; - tmp_count = dconfig->cache_sz; + tmp_count = dbase->cache_sz;if (tmp_count >0 ) { tmp_records = (record_t *)calloc (tmp_count,sizeof (record_t));if (tmp_records ==NULL ) goto omem; -for (ptr = dconfig->cache; ptr !=NULL ; ptr = ptr->next) -if (dconfig->rtable->clone (ptr->data, &tmp_records[i++]) <0 ) +for (ptr = dbase->cache; ptr !=NULL ; ptr = ptr->next) +if (dbase->rtable->clone (ptr->data, &tmp_records[i++]) <0 ) goto err; }
src/database.h +31 -12
84 lines not on this page · raw message
src/debug.c +38 -0
@@ -0,0 +1,38 @@ +/* Author: Joshua Brindle <[email protected] +* Jason Tang <[email protected]> +* +* Copyright (C) 2004-2005 Tresys Technology, LLC +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include <stdarg.h> +#include <stdio.h> +#include "handle.h" +#include "debug.h" + +/* FIXME: redesign with callbacks ? */ + +/* Write an error message to the current error buffer, up to the +* buffer's specified size. */ +#ifdef __GNUC__ +__attribute__ ((format (printf,2 ,3 ))) +#endif +void semanage_write_error (semanage_handle_t *sh,char *fmt, ...) { +va_list ap; +va_start (ap, fmt); +vsnprintf (sh->err_buf,SEMANAGE_ERRBUFSZ , fmt, ap); +va_end (ap); +}
src/debug.h +30 -1
@@ -1,10 +1,39 @@ +/* Author: Joshua Brindle <[email protected]> +* Jason Tang <[email protected]> +* Ivan Gyurdiev <[email protected]> +* +* Copyright (C) 2005 Tresys Technology, LLC +* Copyright (C) 2005 Red Hat Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#ifndef _SEPOL_INTERNAL_DEBUG_H_#define _SEPOL_INTERNAL_DEBUG_H_ +#include "handle.h" +#define STATUS_SUCCESS 0#define STATUS_ERR -1#define STATUS_NODATA 1 -/* Define debug system in this header */ +/* FIXME: redesign with level argument ? */ + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +extern void semanage_write_error (semanage_handle_t *sh,char *fmt, ...);#endif
src/direct_api.c +15 -4
@@ -17,10 +17,6 @@* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "semanage_private.h" -#include "direct_api.h" -#include "semanage_store.h" -#include <sepol/module.h> #include <assert.h>
@@ -30,6 +26,12 @@#include <sys/stat.h> #include <sys/types.h> +#include "debug.h" +#include "handle.h" +#include "modules.h" +#include "direct_api.h" +#include "semanage_store.h" +static void semanage_direct_destroy (semanage_handle_t *sh);static int semanage_direct_disconnect (semanage_handle_t *sh);static int semanage_direct_begintrans (semanage_handle_t *sh);
@@ -68,11 +70,15 @@/* set up function pointers */ sh->funcs = &direct_funcs; + +/* FIXME: configure policy query databases */ +return 0 ; }static void semanage_direct_destroy (semanage_handle_t *sh) {/* do nothing */ + sh =NULL ; }static int semanage_direct_disconnect (semanage_handle_t *sh) {
@@ -85,6 +91,9 @@ }semanage_release_trans_lock (sh); } + +/* FIXME: release policy query databases */ +return 0 ; }
@@ -233,6 +242,8 @@ goto cleanup; } +/* FIXME: write object databases into base */ +/* write the linked base */ if ((linked_filename = semanage_path(SEMANAGE_TMP, SEMANAGE_LINKED)) == NULL || semanage_write_module(sh, linked_filename, base, POLICY_BASE) == -1 ||
src/direct_api.h +1 -1
@@ -20,7 +20,7 @@#ifndef SEMANAGE_DIRECT_API_H #define SEMANAGE_DIRECT_API_H -#include "semanage_private.h" +#include "handle.h" int semanage_direct_connect (semanage_handle_t *sh);
src/handle.c +59 -34
117 lines not on this page · raw message
src/handle.h +95 -0
95 lines not on this page · raw message
src/modules.c +4 -1
@@ -21,7 +21,6 @@/* This file implements only the publicly-visible module functions to libsemanage. */ #include <semanage/semanage.h> -#include "semanage_private.h" #include "direct_api.h" #include "semanage_conf.h" #include "semanage_store.h"
@@ -31,6 +30,10 @@#include <stdlib.h> #include <stdio.h> +#include "handle.h" +#include "modules.h" +#include "debug.h" +int semanage_module_install (semanage_handle_t *sh,char *module_data,size_t data_len) {if (sh->funcs->install ==NULL ) {
src/modules.h +36 -0
@@ -0,0 +1,36 @@ +/* Author: Joshua Brindle <[email protected]> +* Jason Tang <[email protected]> +* +* Copyright (C) 2005 Tresys Technology, LLC +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _SEMANAGE_INTERNAL_MODULES_H_ +#define _SEMANAGE_INTERNAL_MODULES_H_ + +#include <semanage/modules.h> + +struct semanage_module_conn { +int translock_file_fd; +int readlock_file_fd; +}; + +struct semanage_module_info { +char *name;/* Key */ +char *version; +}; + +#endif
src/ports_file.c +16 -1
@@ -9,6 +9,7 @@#include <semanage/port_record.h> #include "debug.h" #include "interfaces.h" +#include "database.h" static int semanage_port_print( semanage_port_t port,
@@ -30,7 +31,7 @@return STATUS_SUCCESS ; } -record_table_t RTABLE_PORT = { +record_table_t SEMANAGE_PORT_RTABLE = {/* Record base functions */ .create = semanage_port_create, .key_extract = semanage_port_key_extract,
@@ -43,3 +44,17 @@ .parse = semanage_port_parse, .print = semanage_port_print, }; + +int port_file_dbase_init (dbase_t ** dbase) { +return dbase_init ( + &SEMANAGE_PORT_RTABLE , +NULL ,/* FIXME */ + dbase); +} + +void port_file_dbase_release (dbase_t * dbase) { +if (dbase ==NULL ) +return ; + +dbase_release (dbase); +}
src/ports_file.h +10 -2
@@ -1,8 +1,16 @@#ifndef _SEMANAGE_PORTS_FILE_H_#define _SEMANAGE_PORTS_FILE_H_ -#include "interfaces.h" +/* +* Header for the port DATA FILE backend +*/ -extern record_table_t RTABLE_PORT ; +#include "database.h" + +int port_file_dbase_init ( +dbase_t ** dbase); + +void port_file_dbase_release ( +dbase_t * dbase);#endif
src/semanage.c +0 -16
@@ -19,7 +19,6 @@*/ #include <semanage/semanage.h> -#include "semanage_private.h" #include "direct_api.h" #include "semanage_conf.h" #include "semanage_store.h"
@@ -27,9 +26,6 @@#include <stdarg.h> #include <assert.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/time.h> int semanage_init (void ) {
@@ -49,15 +45,3 @@ {semanage_init (); } - -/* Write an error message to the current error buffer, up to the -* buffer's specified size. */ -#ifdef __GNUC__ -__attribute__ ((format (printf,2 ,3 ))) -#endif -void semanage_write_error (semanage_handle_t *sh,char *fmt, ...) { -va_list ap; -va_start (ap, fmt); -vsnprintf (sh->err_buf,SEMANAGE_ERRBUFSZ , fmt, ap); -va_end (ap); -}
src/semanage_private.h +0 -86
86 lines not on this page · raw message
src/semanage_store.c +1 -0
@@ -45,6 +45,7 @@#include <sys/types.h> #include <sys/wait.h> +#include "debug.h" /* relative path names to enum semanage_paths to special files and * directories for the module store */
src/semanage_store.h +1 -3
@@ -22,11 +22,9 @@#ifndef SEMANAGE_MODULE_STORE_H #define SEMANAGE_MODULE_STORE_H -#include "semanage_private.h" -#include <sys/time.h> -#include <sepol/module.h> +#include "handle.h" enum semanage_store_defs { SEMANAGE_ACTIVE,
src/users_file.c +17 -1
@@ -7,6 +7,7 @@#include <stdlib.h> #include <stdio.h> #include "interfaces.h" +#include "database.h" #include "debug.h" static int semanage_user_print(
@@ -29,7 +30,7 @@return STATUS_SUCCESS ; } -record_table_t RTABLE_USER = { +record_table_t SEMANAGE_USER_RTABLE = {/* Record base functions */ .create = semanage_user_create, .key_extract = semanage_user_key_extract,
@@ -42,3 +43,18 @@ .parse = semanage_user_parse, .print = semanage_user_print, }; + +int user_file_dbase_init (dbase_t ** dbase) { +return dbase_init ( + &SEMANAGE_USER_RTABLE , +NULL ,/* FIXME */ + dbase); +} + +void user_file_dbase_release (dbase_t * dbase) { +if (dbase ==NULL ) +return ; + +dbase_release (dbase); +} +
src/users_file.h +10 -2
@@ -1,8 +1,16 @@#ifndef _SEMANAGE_USERS_FILE_H_#define _SEMANAGE_USERS_FILE_H_ -#include "interfaces.h" +/** +* Header for the users DATA FILE backend +*/ -extern record_table_t RTABLE_USER ; +#include "database.h" + +int user_file_dbase_init ( +dbase_t ** dbase); + +void user_file_dbase_release ( +dbase_t * dbase);#endif
Re: [ 4/9 ] [ SEMANAGE ] Database initialization Stage 1
Quoted 5 lines
src/database.c +2
-0+/* Release a database */ +void dbase_release(
src/database.c line 74
Quoted 10 lines
src/database.c +10
-0+ dbase_t* dbase) { + +cache_entry_t *prev, *ptr; +while (ptr !=NULL ) { + prev = ptr; + ptr = ptr->next; + dbase->rtable->free (prev->data); +free (prev); + } +}
This is obviously wrong - ptr is not initialized, but I'm sure it's fixed in one of those later patches (the last one..possibly)? Please merge the whole patchset if there's no design issues - if there's bugs I'd much rather fix them with followup patches, than by changing those.
--
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.
Re: [ 5/9 ] [ SEMANAGE ] Change database to singly-linked list
In reply to Ivan GyurdievThis patch changes the previously doubly-linked list in database.c to a singly-linked list, which is sufficient.
src/database.c +15 -22
@@ -12,7 +12,6 @@/* Representation of the database once loaded in memory */ typedef struct cache_entry {record_t data; -struct cache_entry * prev;struct cache_entry * next; }cache_entry_t ;
@@ -98,10 +97,7 @@if (entry ==NULL ) goto omem; entry->data = data; - entry->prev =NULL ; entry->next = dbase->cache; -if (dbase->cache !=NULL ) - dbase->cache->prev = entry; dbase->cache = entry; dbase->cache_sz++;
@@ -267,29 +263,26 @@ dbase_t* dbase, record_key_t key) { -cache_entry_t * entry; -int status; +cache_entry_t *ptr, *prev =NULL ;if (dbase_cache_fill (dbase) <0 ) goto err; - status =dbase_cache_locate (dbase, key, &entry); -if (status <0 ) - goto err; - -else if (status !=STATUS_NODATA ) { -if (entry->next !=NULL ) - entry->next->prev = entry->prev; - -if (entry->prev !=NULL ) - entry->prev->next = entry->next; +for (ptr = dbase->cache; ptr !=NULL ; ptr = ptr->next) { +if (! dbase->rtable->compare (ptr->data, key)) { +if (prev !=NULL ) + prev->next = ptr->next; +else + dbase->cache = ptr->next; + + dbase->rtable->free (ptr->data); + dbase->cache_sz--; +free (ptr); +return STATUS_SUCCESS ; + }else - dbase->cache = entry->next; - - dbase->rtable->free (entry->data); - dbase->cache_sz--; -free (entry); - } + prev = ptr; + }return STATUS_SUCCESS ; err:
Re: [ 6/9 ] [ SEMANAGE ] Database Initialization Stage 2
In reply to Ivan GyurdievThis patch passes the handle down to the dbase_* functions, and selects the correct database in users.c/ports.c. I need to add debugging eventually, that will make use of the handle, but for now it's set to NULL to block unused warning. Also, it may need to be forwarded deeper into the call stack, but I'll leave that for later.
include/semanage/ports.h +9 -0
@@ -3,35 +3,44 @@#include <stddef.h> #include <semanage/port_record.h> +#include <semanage/handle.h> extern int semanage_port_add ( +semanage_handle_t * handle,semanage_port_key_t key,semanage_port_t data);extern int semanage_port_modify ( +semanage_handle_t * handle,semanage_port_key_t key,semanage_port_t data);extern int semanage_port_del ( +semanage_handle_t * handle,semanage_port_key_t key);extern int semanage_port_query ( +semanage_handle_t * handle,semanage_port_key_t key,semanage_port_t * response);extern int semanage_port_exists ( +semanage_handle_t * handle,semanage_port_key_t key,int * response);extern int semanage_port_count ( +semanage_handle_t * handle,int * response);extern int semanage_port_iterate ( +semanage_handle_t * handle,int (*handler) (semanage_port_t record,void * varg),void * handler_arg);extern int semanage_port_list ( +semanage_handle_t * handle,semanage_port_t ** records,size_t * count);
include/semanage/users.h +9 -0
@@ -3,35 +3,44 @@#include <stddef.h> #include <semanage/user_record.h> +#include <semanage/handle.h> extern int semanage_user_add ( +semanage_handle_t * handle,semanage_user_key_t key,semanage_user_t data);extern int semanage_user_modify ( +semanage_handle_t * handle,semanage_user_key_t key,semanage_user_t data);extern int semanage_user_del ( +semanage_handle_t * handle,semanage_user_key_t key);extern int semanage_user_query ( +semanage_handle_t * handle,semanage_user_key_t key,semanage_user_t * response);extern int semanage_user_exists ( +semanage_handle_t * handle,semanage_user_key_t key,int * response);extern int semanage_user_count ( +semanage_handle_t * handle,int * response);extern int semanage_user_iterate ( +semanage_handle_t * handle,int (*handler) (semanage_user_t record,void * varg),void * handler_arg);extern int semanage_user_list ( +semanage_handle_t * handle,semanage_user_t ** records,size_t * count);
src/database.c +21 -7
@@ -6,8 +6,7 @@#include "debug.h" #include "database.h" #include "interfaces.h" -#include "users_file.h" -#include "ports_file.h" +#include "handle.h" /* Representation of the database once loaded in memory */ typedef struct cache_entry {
@@ -183,7 +182,7 @@static int dbase_cache_locate (dbase_t * dbase, -record_key_t key, +record_key_t key,cache_entry_t ** entry) {cache_entry_t * ptr;
@@ -205,6 +204,7 @@ }int dbase_add ( +semanage_handle_t * handle,dbase_t * dbase,record_key_t key,record_t data) {
@@ -214,7 +214,7 @@if (dbase_cache_fill (dbase) <0 ) goto err; -if (dbase_exists (dbase, key, &exists) <0 ) +if (dbase_exists (handle, dbase, key, &exists) <0 ) goto err;else if (exists) {
@@ -228,11 +228,13 @@return STATUS_SUCCESS ; err: + handle =NULL ;/* FIXME: handle error condition */ return STATUS_ERR ; }int dbase_modify ( +semanage_handle_t * handle,dbase_t * dbase,record_key_t key,record_t data) {
@@ -247,19 +249,20 @@if (status <0 ) goto err;if (status ==STATUS_NODATA ) -return dbase_add (dbase,key,data); +return dbase_add (handle, dbase, key, data);else entry->data = data;return STATUS_SUCCESS ; err: + handle =NULL ;/* FIXME: handle error condition */ return STATUS_ERR ; - }int dbase_del ( +semanage_handle_t * handle,dbase_t * dbase,record_key_t key) {
@@ -282,15 +285,17 @@ }else prev = ptr; - } + }return STATUS_SUCCESS ; err: + handle =NULL ;/* FIXME: Handle error condition */ return STATUS_ERR ; }int dbase_query ( +semanage_handle_t * handle,dbase_t * dbase,record_key_t key,record_t * response) {
@@ -310,11 +315,13 @@return STATUS_SUCCESS ; err: + handle =NULL ;/* FIXME: Handle error condition */ return STATUS_ERR ; }int dbase_exists ( +semanage_handle_t * handle,dbase_t * dbase,record_key_t key,int * response) {
@@ -333,11 +340,13 @@return STATUS_SUCCESS ; err: + handle =NULL ;/* FIXME: handle error condition */ return STATUS_ERR ; }int dbase_count ( +semanage_handle_t * handle,dbase_t * dbase,int * response) {
@@ -348,11 +357,13 @@return STATUS_SUCCESS ; err: + handle =NULL ;/* FIXME: Handle error condition */ return STATUS_ERR ; }int dbase_iterate ( +semanage_handle_t * handle,dbase_t * dbase,int (*fn) (record_t record,void * varg),void * fn_arg) {
@@ -375,11 +386,13 @@return STATUS_SUCCESS ; err: + handle =NULL ;/* FIXME: Handle error condition */ return STATUS_ERR ; }int dbase_list ( +semanage_handle_t * handle,dbase_t * dbase,record_t ** records,size_t * count) {
@@ -410,6 +423,7 @@return STATUS_SUCCESS ; omem: + handle =NULL ;/* FIXME: handle error condition */ err:
src/database.h +9 -0
@@ -8,6 +8,7 @@#endif #include <stddef.h> +#include "handle.h" #include "interfaces.h" struct dbase ;
@@ -32,40 +33,48 @@ dbase_t* dbase);extern int dbase_add ( +semanage_handle_t * handle,dbase_t * dbase,record_key_t key,record_t data);extern int dbase_modify ( +semanage_handle_t * handle,dbase_t * dbase,record_key_t key,record_t data);extern int dbase_del ( +semanage_handle_t * handle,dbase_t * dbase,record_key_t key);extern int dbase_query ( +semanage_handle_t * handle,dbase_t * dbase,record_key_t key,record_t * response);extern int dbase_exists ( +semanage_handle_t * handle,dbase_t * dbase,record_key_t key,int * response);extern int dbase_count ( +semanage_handle_t * handle,dbase_t * dbase,int * response);extern int dbase_iterate ( +semanage_handle_t * handle,dbase_t * dbase,int (*fn) (record_t record,void * varg),void * fn_arg);extern int dbase_list ( +semanage_handle_t * handle,dbase_t * dbase,record_t ** records,size_t * count);
src/ports.c +34 -12
98 lines not on this page · raw message
src/users.c +35 -13
99 lines not on this page · raw message
Re: [ 7/9 ] [ SEMANAGE ] Backend separation (Init 3)
In reply to Ivan GyurdievThis patch:
- removes FILE-specific code from the database, and puts that in database_file.[c,h].
- stubs out a second type of database - database_direct.[c,h] (for policy)
- adds user/port interfaces for the POLICY DIRECT database
- splits record table into base (in users.c/ports.c) and extensions - FILE and POLICY DIRECT
- adds polymorphism on the database backend, and uses that in database
- adds init()/release() functions for the backend.
- forwards cache() and flush() operations to the backend
- adds some functions with the intent to use those for moving things from a FILE to POLICY database, but I'm still not entirely sure how this code will work (so it's partially disabled).
src/database.c +23 -117
@@ -1,39 +1,15 @@#include <stdlib.h> #include <stddef.h> -#include <stdio.h> -#include <stdio_ext.h> -#include <errno.h> #include "debug.h" #include "database.h" #include "interfaces.h" #include "handle.h" -/* Representation of the database once loaded in memory */ -typedef struct cache_entry { -record_t data; -struct cache_entry * next; -}cache_entry_t ; - -/* Database-specific configuration */ -struct dbase { - -/* What's the format of this database */ -record_table_t * rtable; - -/* Where is it stored */ -const char * filename; - -/* Once parsed, it is cached here */ -cache_entry_t * cache; -size_t cache_sz; -int cached; -int cache_invalid; -}; -/* Initialize a database */ int dbase_init (record_table_t * rtable, -const char * filename, +dbase_backend_t * backend, +dbase_backend_table_t * btable,dbase_t ** dbase) { dbase_t* tmp_dbase =
@@ -43,7 +19,8 @@ goto omem; tmp_dbase->rtable = rtable; - tmp_dbase->filename = filename; + tmp_dbase->backend = backend; + tmp_dbase->btable = btable; tmp_dbase->cache =NULL ; tmp_dbase->cache_sz =0 ; tmp_dbase->cached =0 ;
@@ -62,13 +39,15 @@void dbase_release (dbase_t * dbase) { -cache_entry_t *prev, *ptr; +cache_entry_t *prev, *ptr = dbase->cache;while (ptr !=NULL ) { prev = ptr; ptr = ptr->next; dbase->rtable->free (prev->data);free (prev); } + +free (dbase); }/* Invalidate database cache */
@@ -82,12 +61,13 @@int dbase_flush (dbase_t * dbase) { -/* Stub */ - dbase =NULL ; +if (dbase->btable->flush (dbase, dbase->backend) <0 ) +return STATUS_ERR ; +return STATUS_SUCCESS ; } -static int dbase_cache_add ( +int dbase_cache_add (dbase_t * dbase,record_t data) {
@@ -106,80 +86,6 @@return STATUS_ERR ; } -static int dbase_open_file (parse_info_t * info) { - - info->file_stream =fopen (info->filename,"r" ); -if (!info->file_stream && (errno !=ENOENT )) { -/* FIXME: handle error condition */ -return STATUS_ERR ; - } -if (info->file_stream) -__fsetlocking (info->file_stream,FSETLOCKING_BYCALLER ); - -return STATUS_SUCCESS ; -} - -static void dbase_close_file (parse_info_t * info) { -if (info->file_stream && (fclose (info->file_stream) <0 )) -/* FIXME: handle error condition */ - info->file_stream =NULL ; -} - -static int dbase_cache_fill ( -dbase_t * dbase) { - -/* Already cached */ -if (dbase->cached && (!dbase->cache_invalid)) -return STATUS_SUCCESS ; - -int perr_fatal =0 ; -/* FIXME: pass from caller? */ - -record_t process_record =NULL ; -int pstatus =STATUS_SUCCESS ; -parse_info_t parse_info; - parse_info.filename = dbase->filename; - parse_info.parse_arg =NULL ; -/* FIXME: pass from caller? */ - -if (dbase_open_file (&parse_info) <0 ) - goto err; - -/* Main processing loop */ -do { -/* Create record */ -if (dbase->rtable->create (&process_record) <0 ) - goto err; - -/* Parse record */ - pstatus = dbase->rtable->parse (&parse_info, process_record); - -/* Parse error is fatal, exit */ -if (perr_fatal && (pstatus <0 )) - goto err; - -/* Parse error is not fatal */ -else if (pstatus <0 ) -continue ; - -/* Add record to list */ -if (dbase_cache_add (dbase, process_record) <0 ) - goto err; - - }while (pstatus !=STATUS_NODATA ); - -dbase_close_file (&parse_info); - dbase->cached =1 ; - dbase->cache_invalid =0 ; -return STATUS_SUCCESS ; - - err: -/* FIXME: handle failure */ - dbase->rtable->free (process_record); -dbase_close_file (&parse_info); -return STATUS_ERR ; -} - static int dbase_cache_locate( dbase_t* dbase, record_key_t key,
@@ -187,7 +93,7 @@cache_entry_t * ptr; -if (dbase_cache_fill (dbase) <0 ) +if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;for (ptr = dbase->cache; ptr !=NULL ; ptr = ptr->next) {
@@ -211,7 +117,7 @@int exists; -if (dbase_cache_fill (dbase) <0 ) +if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;if (dbase_exists (handle, dbase, key, &exists) <0 )
@@ -242,7 +148,7 @@cache_entry_t * entry;int status; -if (dbase_cache_fill (dbase) <0 ) +if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err; status =dbase_cache_locate (dbase, key, &entry);
@@ -268,7 +174,7 @@cache_entry_t *ptr, *prev =NULL ; -if (dbase_cache_fill (dbase) <0 ) +if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;for (ptr = dbase->cache; ptr !=NULL ; ptr = ptr->next) {
@@ -277,15 +183,15 @@ prev->next = ptr->next; else dbase->cache = ptr->next; - + dbase->rtable->free (ptr->data); dbase->cache_sz--;free (ptr);return STATUS_SUCCESS ; - } + }else prev = ptr; - } + }return STATUS_SUCCESS ; err:
@@ -303,7 +209,7 @@cache_entry_t * entry;int status; -if (dbase_cache_fill (dbase) <0 ) +if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err; status =dbase_cache_locate (dbase, key, &entry);
@@ -329,7 +235,7 @@cache_entry_t * entry;int status; -if (dbase_cache_fill (dbase) <0 ) +if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err; status =dbase_cache_locate (dbase, key, &entry);
@@ -350,7 +256,7 @@ dbase_t* dbase, int* response) { -if (dbase_cache_fill (dbase) <0 ) +if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err; *response = dbase->cache_sz;
@@ -371,7 +277,7 @@int status;cache_entry_t * ptr; -if (dbase_cache_fill (dbase) <0 ) +if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;for (ptr = dbase->cache; ptr !=NULL ; ptr = ptr->next) {
@@ -402,7 +308,7 @@size_t tmp_count;int i =0 ; -if (dbase_cache_fill (dbase) <0 ) +if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err; tmp_count = dbase->cache_sz;
src/database_direct.c +94 -0
94 lines not on this page · raw message
src/database_direct.h +24 -0
@@ -0,0 +1,24 @@ +#ifndef _SEMANAGE_DATABASE_DIRECT_INTERNAL_H_ +#define _SEMANAGE_DATABASE_DIRECT_INTERNAL_H_ + +#include "database.h" +#include "interfaces.h" + +struct dbase_direct_backend ; +typedef struct dbase_direct_backend dbase_direct_backend_t ; + +/* POLICY DIRECT backend - initialization */ +extern int dbase_direct_init ( +const char * filename, +policydb_t ** policy_update_ptr, +record_direct_table_t * rptable, +dbase_direct_backend_t ** backend); + +/* POLICY DIRECT backend - release */ +extern void dbase_direct_release ( +dbase_direct_backend_t * backend); + +/* POLICY DIRECT backend - method table implementation */ +extern dbase_backend_table_t SEMANAGE_DIRECT_BTABLE ; + +#endif
src/database_file.c +143 -0
143 lines not on this page · raw message
src/database_file.h +23 -0
@@ -0,0 +1,23 @@ +#ifndef _SEMANAGE_DATABASE_FILE_INTERNAL_H_ +#define _SEMANAGE_DATABASE_FILE_INTERNAL_H_ + +#include "database.h" +#include "interfaces.h" + +struct dbase_file_backend ; +typedef struct dbase_file_backend dbase_file_backend_t ; + +/* FILE backend - initialization */ +extern int dbase_file_init ( +const char * filename, +record_file_table_t * rftable, +dbase_file_backend_t ** backend); + +/* FILE backend - release */ +extern void dbase_file_release ( +dbase_file_backend_t * backend); + +/* FILE backend - method table implementation */ +extern dbase_backend_table_t SEMANAGE_FILE_BTABLE ; + +#endif
src/database.h +52 -3
77 lines not on this page · raw message
src/handle.c +2 -2
@@ -124,8 +124,8 @@semanage_conf_destroy (sh->conf);/* Free object databases */ -dbase_release (sh->dbase[DBASE_USERS ]); -dbase_release (sh->dbase[DBASE_PORTS ]); +user_file_dbase_release (sh->dbase[DBASE_USERS ]); +port_file_dbase_release (sh->dbase[DBASE_PORTS ]);free (sh); }
src/interfaces.h +45 -6
80 lines not on this page · raw message
src/ports.c +11 -0
@@ -13,6 +13,17 @@#include <semanage/ports.h> #include "database.h" #include "handle.h" +#include "interfaces.h" + +/* Port base functions */ +record_table_t SEMANAGE_PORT_RTABLE = { + .create = semanage_port_create, + .key_extract = semanage_port_key_extract, + .key_free = semanage_port_key_free, + .clone = semanage_port_clone, + .compare = semanage_port_compare, + .free = semanage_port_free, +}; int semanage_port_add( semanage_handle_t* handle,
src/ports_direct.c +54 -0
54 lines not on this page · raw message
src/ports_direct.h +16 -0
@@ -0,0 +1,16 @@ +#ifndef _SEMANAGE_PORTS_DIRECT_H_ +#define _SEMANAGE_PORTS_DIRECT_H_ + +/* +* Header for the port POLICY DIRECT backend +*/ + +#include "database.h" + +int port_direct_dbase_init ( +dbase_t ** dbase); + +void port_direct_dbase_release ( +dbase_t * dbase); + +#endif
src/ports_file.c +26 -18
76 lines not on this page · raw message
src/ports_policy.c +69 -0
69 lines not on this page · raw message
src/ports_policy.h +18 -0
@@ -0,0 +1,18 @@ +#ifndef _SEMANAGE_PORTS_POLICY_H_ +#define _SEMANAGE_PORTS_POLICY_H_ + +#include <stddef.h> +#include <semanage/port_record.h> +#include "handle.h" + +int semanage_port_policy_load ( +semanage_handle_t * handle, +semanage_port_key_t key, +semanage_port_t data); + +int semanage_port_policy_list ( +semanage_handle_t * handle, +semanage_port_t ** records, +size_t * count); + +#endif
src/users.c +11 -0
@@ -13,6 +13,17 @@#include <semanage/users.h> #include "handle.h" #include "database.h" +#include "interfaces.h" + +/* Record base functions */ +record_table_t SEMANAGE_USER_RTABLE = { + .create = semanage_user_create, + .key_extract = semanage_user_key_extract, + .key_free = semanage_user_key_free, + .clone = semanage_user_clone, + .compare = semanage_user_compare, + .free = semanage_user_free, +}; int semanage_user_add( semanage_handle_t* handle,
src/users_direct.c +54 -0
54 lines not on this page · raw message
src/users_direct.h +16 -0
@@ -0,0 +1,16 @@ +#ifndef _SEMANAGE_USERS_DIRECT_H_ +#define _SEMANAGE_USERS_DIRECT_H_ + +/* +* Header for the user POLICY DIRECT backend +*/ + +#include "database.h" + +int user_direct_dbase_init ( +dbase_t ** dbase); + +void user_direct_dbase_release ( +dbase_t * dbase); + +#endif
src/users_file.c +25 -17
75 lines not on this page · raw message
src/users_policy.c +69 -0
69 lines not on this page · raw message
src/users_policy.h +18 -0
@@ -0,0 +1,18 @@ +#ifndef _SEMANAGE_USERS_POLICY_H_ +#define _SEMANAGE_USERS_POLICY_H_ + +#include <stddef.h> +#include <semanage/user_record.h> +#include "handle.h" + +int semanage_user_policy_load ( +semanage_handle_t * handle, +semanage_user_key_t key, +semanage_user_t data); + +int semanage_user_policy_list ( +semanage_handle_t * handle, +semanage_user_t ** records, +size_t * count); + +#endif
Re: [ 7/9 ] [ SEMANAGE ] Backend separation (Init 3)
I think this patch is definitely on the right track to separating the cached dbase/list from its backend. Also, remember that I initially wanted to iterate the flat file per function call. I later decided this was a bad idea, after talking to Karl, but pointed out that in some cases we don't want to load the whole database in memory, because it might be too large.
One such case are rules. In particular, rule tables are compressed within the policydb (via pointers to strings that are shared), and you can't really implement a list() function based on records and keep that compression at the same time - it's an internal policy detail and those records are specifically designed _not_ to expose those - each record should be standalone from the policy/other records.
In the general case, what we really want is... an iterate() function in the backend. This addresses the concern of loading a large database in memory by pushing the work to the backend. We still need the iterate() function on the list in memory, because that's faster. However, we should add the ability to mark a dbase "noncachable", and then look at that in dbase_* functions, and if it says noncachable, we should not attempt to construct a memory cache of the database, but instead should use the backend iterate() function. Of course, if what you're really doing is calling the list() function (as opposed to query/count/exists/iterate/*), this won't gain you anything, but really, for rules, who wants to look at the entire ruleset of a zillion rules? What we probably want is a method to loop over them, and apply programmatic changes or analyze them. I can add noncachable support on certain functions one by one - no need to cover all of them now.. no need to implement this on the FILE case either, which is what I was doing initially...
I think this is one of my planned architecture changes before I try to implement operations on a rule record.
--
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.
Re: [ 9/9 ] [ SEPOL ] User list function, Bugfixes
In reply to Ivan GyurdievSteven, I implemented the interfaces you wanted. I think the end result looks just as bad as before, if not worse.
However, it's now hidden away into mls.c, instead of having to implement it in every caller. Also, looks like you were right not to trust me, because I ran the code through valgrind, and found all kinds of bugs, which I fixed (so says valgrind).
mls.c is just evil. Apparently compute_length () returns the size of the context (plus the ':', which I don't want), *minus* the NULL terminator at the end. However, mls_context_to_sid will write the NULL terminator at the end. Not only will it write it, it won't skip over it, but will stop on top of it ( I think), causing mayhem in my code. This interface makes no sense to me - the replacement is based on it, but it hides the detail from the caller.
Attached is my resubmission of the user list function, including new mls functions, and a series of bugfixes for user roles. One of those is particularly bad (realloc fix).
include/sepol/mls.h +16 -1
@@ -34,15 +34,28 @@#include <sepol/context.h> #include <sepol/policydb.h> +extern int mls_struct_from_string ( +policydb_t * policydb, +const char * str, +context_struct_t * mls); + +extern int mls_struct_to_string ( +policydb_t * policydb, +context_struct_t * mls, +char ** str); + +/* Deprecated */ extern int mls_compute_context_len (policydb_t *policydb,context_struct_t * context); +/* Deprecated */ extern void mls_sid_to_context (policydb_t *policydb,context_struct_t *context,char **scontext);extern int mls_context_isvalid (policydb_t *p,context_struct_t * c); +/* Deprecated */ extern int mls_context_to_sid(policydb_t *policydb, char oldc, char **scontext,
@@ -63,5 +76,7 @@ context_struct_t *fromcon, user_datum_t *user, context_struct_t *usercon); -#endif /* _MLS_H_ */ + + +#endif
include/sepol/users.h +3 -3
@@ -32,10 +32,10 @@policydb_t * policydb, const char* role); -/* Obtain an array of all valid users/roles */ -extern int sepol_get_valid_users ( +/* Obtain the user list */ +extern int sepol_user_list (policydb_t * policydb, -char *** users, +sepol_user_t *** users,size_t * nusers); extern int sepol_get_valid_roles(
src/mls.c +57 -0
65 lines not on this page · raw message
src/user_record.c +31 -15
133 lines not on this page · raw message
src/users.c +80 -23
143 lines not on this page · raw message
Memory leaks
In reply to Ivan GyurdievHere's a couple of memory leaks, if anyone wants to investigate. If not, I'll take a look at them eventually. The first one is my fault. The second one isn't. The main binary I used doesn't bother freeing things, but I think valgrind is smart enough to recognize that, and those are real leaks.
==10639== 8 bytes in 2 blocks are definitely lost in loss record 4 of 74
==10639== at 0x1B9017F2: malloc (vg_replace_malloc.c:149) ==10639== by 0x805313F: sepol_user_get_roles (in /home/phantom/rpmbuild/BUILD/test.mls/test) ==10639== by 0x80493D9: main (in /home/phantom/rpmbuild/BUILD/test.mls/test) ==10639== ==10639== ==10639== 64 (32 direct, 32 indirect) bytes in 2 blocks are definitely lost in loss record 21 of 74 ==10639== at 0x1B9017F2: malloc (vg_replace_malloc.c:149) ==10639== by 0x805C46A: ebitmap_read (in /home/phantom/rpmbuild/BUILD/test.mls/test) ==10639== by 0x804EA64: mls_read_range_helper (in /home/phantom/rpmbuild/BUILD/test.mls/test) ==10639== by 0x805044D: user_read (in /home/phantom/rpmbuild/BUILD/test.mls/test) ==10639== by 0x8051923: policydb_read (in /home/phantom/rpmbuild/BUILD/test.mls/test) ==10639== by 0x8051F50: policydb_from_image (in /home/phantom/rpmbuild/BUILD/test.mls/test) ==10639== by 0x804AFE9: sepol_genusers (in /home/phantom/rpmbuild/BUILD/test.mls/test) ==10639== by 0x8049291: main (in /home/phantom/rpmbuild/BUILD/test.mls/test)
--
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.
Re: Memory leaks
Quoted 2 lines · Ivan Gyurdiev
Here's a couple of memory leaks, if anyone wants to investigate. If not, I'll take a look at them eventually. The first one is my fault. The second one isn't. The main binary I used doesn't bother freeing things, but I think valgrind is smart enough to recognize that, and those are real leaks.
Disregard this, I am giving valgrind too much credit....adding free() in main where appropriate fixes those non-leaks.
--
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.
Linking to semanage
In reply to Ivan GyurdievOkay, this test compiled a while ago... and now it won't link. I don't understand why - can someone who knows something about linking give me a hint? I hope I didn't break static linking with my patches somehow (can't see how)...
[phantom@cobra test5]$ ./compile
test.c:(.text+0x1d): undefined reference to semanage_handle_create' test.c:(.text+0x41): undefined reference to semanage_handle_destroy'
collect2: ld returned 1 exit status
[phantom@cobra test5]$ cat compile
gcc -static /usr/lib/libselinux.a /usr/lib/libsepol.a /usr/lib/libsemanage.a test.c -o test [phantom@cobra test5]$ nm /usr/lib/libsemanage.a|grep semanage_handle 00000000 T semanage_handle_create
00000209 T semanage_handle_destroy
--
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.
Re: Linking to semanage
Quoted 1 line · Ivan Gyurdiev
Okay, this test compiled a while ago... and now it won't link. I don't understand why - can someone who knows something about linking give me a hint? I hope I didn't break static linking with my patches somehow (can't see how)...
Hmm..apparently order of arguments to gcc matters for static linking. I did not know that... reordering things differently makes it work.
--
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.
This is the SEMANAGE equivalent to the first patch I sent for SEPOL. It replaces struct pointer typedefs with struct alias for consistency.
include/semanage/boolean_record.h +16 -16
@@ -3,50 +3,50 @@struct semanage_bool ;struct semanage_bool_key ; -typedef struct semanage_bool *semanage_bool_t ; -typedef struct semanage_bool_key *semanage_bool_key_t ; +typedef struct semanage_bool semanage_bool_t ; +typedef struct semanage_bool_key semanage_bool_key_t ;/* Key */ extern int semanage_bool_key_create (const char * name, -semanage_bool_key_t * key); +semanage_bool_key_t ** key);extern int semanage_bool_key_extract ( -semanage_bool_t boolean, -semanage_bool_key_t * key); +semanage_bool_t * boolean, +semanage_bool_key_t ** key);extern void semanage_bool_key_free ( -semanage_bool_key_t key); +semanage_bool_key_t * key);extern int semanage_bool_compare ( -semanage_bool_t boolean, -semanage_bool_key_t key); +semanage_bool_t * boolean, +semanage_bool_key_t * key);/* Name */ extern const char *semanage_bool_get_name ( -semanage_bool_t boolean); +semanage_bool_t * boolean);extern int semanage_bool_set_name ( -semanage_bool_t boolean, +semanage_bool_t * boolean,const char * name);/* Value */ extern int semanage_bool_get_value ( -semanage_bool_t boolean); +semanage_bool_t * boolean);extern void semanage_bool_set_value ( -semanage_bool_t boolean, +semanage_bool_t * boolean,int value);/* Create/Clone/Destroy */ extern int semanage_bool_create ( -semanage_bool_t * bool_ptr); +semanage_bool_t ** bool_ptr);extern int semanage_bool_clone ( -semanage_bool_t boolean, -semanage_bool_t * bool_ptr); +semanage_bool_t * boolean, +semanage_bool_t ** bool_ptr);extern void semanage_bool_free ( -semanage_bool_t boolean); +semanage_bool_t * boolean);#endif
include/semanage/context_record.h +15 -15
@@ -2,57 +2,57 @@#define _SEMANAGE_CONTEXT_RECORD_H_ struct semanage_context; -typedef struct semanage_context *semanage_context_t ; +typedef struct semanage_context semanage_context_t ;/* User */ extern const char *semanage_context_get_user ( -semanage_context_t con); +semanage_context_t * con);extern int semanage_context_set_user ( -semanage_context_t con, +semanage_context_t * con,const char * user);/* Role */ extern const char *semanage_context_get_role ( -semanage_context_t con); +semanage_context_t * con);extern int semanage_context_set_role ( -semanage_context_t con, +semanage_context_t * con,const char * role);/* Type */ extern const char *semanage_context_get_type ( -semanage_context_t con); +semanage_context_t * con);extern int semanage_context_set_type ( -semanage_context_t con, +semanage_context_t * con,const char * type);/* MLS */ extern const char *semanage_context_get_mls ( -semanage_context_t con); +semanage_context_t * con);extern int semanage_context_set_mls ( -semanage_context_t con, +semanage_context_t * con,const char * mls_range);/* Create/Clone/Destroy */ extern int semanage_context_create ( -semanage_context_t * con_ptr); +semanage_context_t ** con_ptr);extern int semanage_context_clone ( -semanage_context_t con, -semanage_context_t * con_ptr); +semanage_context_t * con, +semanage_context_t ** con_ptr);extern void semanage_context_free ( -semanage_context_t con); +semanage_context_t * con);/* Parse to/from string */ extern int semanage_context_from_string (const char * str, -semanage_context_t * con); +semanage_context_t ** con);extern char *semanage_context_to_string ( -semanage_context_t con); +semanage_context_t * con);#endif
include/semanage/iface_record.h +21 -21
78 lines not on this page · raw message
include/semanage/port_record.h +25 -25
97 lines not on this page · raw message
include/semanage/ports.h +10 -10
@@ -7,26 +7,26 @@extern int semanage_port_add (semanage_handle_t * handle, -semanage_port_key_t key, -semanage_port_t data); +semanage_port_key_t * key, +semanage_port_t * data);extern int semanage_port_modify (semanage_handle_t * handle, -semanage_port_key_t key, -semanage_port_t data); +semanage_port_key_t * key, +semanage_port_t * data);extern int semanage_port_del (semanage_handle_t * handle, -semanage_port_key_t key); +semanage_port_key_t * key);extern int semanage_port_query (semanage_handle_t * handle, -semanage_port_key_t key, -semanage_port_t * response); +semanage_port_key_t * key, +semanage_port_t ** response);extern int semanage_port_exists (semanage_handle_t * handle, -semanage_port_key_t key, +semanage_port_key_t * key,int * response); extern int semanage_port_count(
@@ -35,13 +35,13 @@extern int semanage_port_iterate (semanage_handle_t * handle, -int (*handler) (semanage_port_t record, +int (*handler) (semanage_port_t * record,void * varg),void * handler_arg);extern int semanage_port_list (semanage_handle_t * handle, -semanage_port_t ** records, +semanage_port_t *** records,size_t * count);#endif
include/semanage/user_record.h +26 -26
115 lines not on this page · raw message
include/semanage/users.h +10 -10
@@ -7,26 +7,26 @@extern int semanage_user_add (semanage_handle_t * handle, -semanage_user_key_t key, -semanage_user_t data); +semanage_user_key_t * key, +semanage_user_t * data);extern int semanage_user_modify (semanage_handle_t * handle, -semanage_user_key_t key, -semanage_user_t data); +semanage_user_key_t * key, +semanage_user_t * data);extern int semanage_user_del (semanage_handle_t * handle, -semanage_user_key_t key); +semanage_user_key_t * key);extern int semanage_user_query (semanage_handle_t * handle, -semanage_user_key_t key, -semanage_user_t * response); +semanage_user_key_t * key, +semanage_user_t ** response);extern int semanage_user_exists (semanage_handle_t * handle, -semanage_user_key_t key, +semanage_user_key_t * key,int * response); extern int semanage_user_count(
@@ -35,13 +35,13 @@extern int semanage_user_iterate (semanage_handle_t * handle, -int (*handler) (semanage_user_t record, +int (*handler) (semanage_user_t * record,void * varg),void * handler_arg);extern int semanage_user_list (semanage_handle_t * handle, -semanage_user_t ** records, +semanage_user_t *** records,size_t * count);#endif
src/boolean_record.c +39 -13
91 lines not on this page · raw message
src/context_record.c +14 -14
@@ -1,61 +1,61 @@#include <sepol/context_record.h> -typedef sepol_context_t *semanage_context_t ; +typedef sepol_context_t semanage_context_t ;/* User */ -const char *semanage_context_get_user (semanage_context_t con) { +const char *semanage_context_get_user (semanage_context_t * con) {return sepol_context_get_user (con); } -int semanage_context_set_user (semanage_context_t con,const char * user) { +int semanage_context_set_user (semanage_context_t * con,const char * user) {return sepol_context_set_user (con, user); }/* Role */ -const char *semanage_context_get_role (semanage_context_t con) { +const char *semanage_context_get_role (semanage_context_t * con) {return sepol_context_get_role (con); } -int semanage_context_set_role (semanage_context_t con,const char * role) { +int semanage_context_set_role (semanage_context_t * con,const char * role) {return sepol_context_set_role (con, role); }/* Type */ -const char *semanage_context_get_type (semanage_context_t con) { +const char *semanage_context_get_type (semanage_context_t * con) {return sepol_context_get_type (con); } -int semanage_context_set_type (semanage_context_t con,const char * type) { +int semanage_context_set_type (semanage_context_t * con,const char * type) {return sepol_context_set_type (con, type); }/* MLS */ -const char *semanage_context_get_mls (semanage_context_t con) { +const char *semanage_context_get_mls (semanage_context_t * con) {return sepol_context_get_mls (con); } -int semanage_context_set_mls (semanage_context_t con,const char * mls_range) { +int semanage_context_set_mls (semanage_context_t * con,const char * mls_range) {return sepol_context_set_mls (con, mls_range); }/* Create/Clone/Destroy */ -int semanage_context_create (semanage_context_t * con_ptr) { +int semanage_context_create (semanage_context_t ** con_ptr) {return sepol_context_create (con_ptr); } -int semanage_context_clone (semanage_context_t con,semanage_context_t * con_ptr) { +int semanage_context_clone (semanage_context_t * con,semanage_context_t ** con_ptr) {return sepol_context_clone (con, con_ptr); } -void semanage_context_free (semanage_context_t con) { +void semanage_context_free (semanage_context_t * con) {sepol_context_free (con); }/* Parse to/from string */ -int semanage_context_from_string (const char * str,semanage_context_t * con) { +int semanage_context_from_string (const char * str,semanage_context_t ** con) {return sepol_context_from_string (str, con); } -char *semanage_context_to_string (semanage_context_t con) { +char *semanage_context_to_string (semanage_context_t * con) {return sepol_context_to_string (con); }
src/database.c +16 -15
@@ -69,7 +69,7 @@int dbase_cache_add (dbase_t * dbase, -record_t data) { +record_t * data) {cache_entry_t * entry = (cache_entry_t *)malloc (sizeof (cache_entry_t));
@@ -88,7 +88,7 @@static int dbase_cache_locate (dbase_t * dbase, -record_key_t key, +record_key_t * key,cache_entry_t ** entry) {cache_entry_t * ptr;
@@ -112,8 +112,8 @@int dbase_add (semanage_handle_t * handle,dbase_t * dbase, -record_key_t key, -record_t data) { +record_key_t * key, +record_t * data) {int exists;
@@ -142,8 +142,8 @@int dbase_modify (semanage_handle_t * handle,dbase_t * dbase, -record_key_t key, -record_t data) { +record_key_t * key, +record_t * data) {cache_entry_t * entry;int status;
@@ -170,7 +170,7 @@int dbase_del (semanage_handle_t * handle,dbase_t * dbase, -record_key_t key) { +record_key_t * key) {cache_entry_t *ptr, *prev =NULL ;
@@ -203,8 +203,8 @@int dbase_query (semanage_handle_t * handle,dbase_t * dbase, -record_key_t key, -record_t * response) { +record_key_t * key, +record_t ** response) {cache_entry_t * entry;int status;
@@ -216,7 +216,7 @@if (status <0 || status ==STATUS_NODATA ) goto err; -if (dbase->rtable->clone (entry->data, *response) <0 ) +if (dbase->rtable->clone (entry->data, response) <0 ) goto err;return STATUS_SUCCESS ;
@@ -229,7 +229,7 @@int dbase_exists (semanage_handle_t * handle,dbase_t * dbase, -record_key_t key, +record_key_t * key,int * response) {cache_entry_t * entry;
@@ -271,7 +271,7 @@int dbase_iterate (semanage_handle_t * handle,dbase_t * dbase, -int (*fn) (record_t record,void * varg), +int (*fn) (record_t * record,void * varg),void * fn_arg) {int status;
@@ -300,11 +300,11 @@int dbase_list (semanage_handle_t * handle,dbase_t * dbase, -record_t ** records, +record_t *** records,size_t * count) {cache_entry_t * ptr; -record_t * tmp_records =NULL ; +record_t ** tmp_records =NULL ;size_t tmp_count;int i =0 ;
@@ -314,7 +314,8 @@ tmp_count = dbase->cache_sz;if (tmp_count >0 ) { - tmp_records = (record_t *)calloc (tmp_count,sizeof (record_t)); + tmp_records = (record_t **) +calloc (tmp_count,sizeof (record_t *));if (tmp_records ==NULL ) goto omem;
src/database_file.c +1 -1
@@ -50,7 +50,7 @@int perr_fatal =0 ;/* FIXME: pass from caller? */ -record_t process_record =NULL ; +record_t * process_record =NULL ;int pstatus =STATUS_SUCCESS ;parse_info_t parse_info; parse_info.filename = backend->filename;
src/database.h +12 -12
@@ -23,7 +23,7 @@/* Representation of the database once loaded in memory */ typedef struct cache_entry { -record_t data; +record_t * data;struct cache_entry * next; }cache_entry_t ;
@@ -49,7 +49,7 @@/* Add a record to the database cache */ extern int dbase_cache_add (dbase_t * dbase, -record_t data); +record_t * data);/* ====================================== API for use elsewhere:
@@ -84,30 +84,30 @@extern int dbase_add (semanage_handle_t * handle,dbase_t * dbase, -record_key_t key, -record_t data); +record_key_t * key, +record_t * data);extern int dbase_modify (semanage_handle_t * handle,dbase_t * dbase, -record_key_t key, -record_t data); +record_key_t * key, +record_t * data);extern int dbase_del (semanage_handle_t * handle,dbase_t * dbase, -record_key_t key); +record_key_t * key);extern int dbase_query (semanage_handle_t * handle,dbase_t * dbase, -record_key_t key, -record_t * response); +record_key_t * key, +record_t ** response);extern int dbase_exists (semanage_handle_t * handle,dbase_t * dbase, -record_key_t key, +record_key_t * key,int * response); extern int dbase_count(
@@ -118,14 +118,14 @@extern int dbase_iterate (semanage_handle_t * handle,dbase_t * dbase, -int (*fn) (record_t record, +int (*fn) (record_t * record,void * varg),void * fn_arg);extern int dbase_list (semanage_handle_t * handle,dbase_t * dbase, -record_t ** records, +record_t *** records,size_t * count);#endif
src/iface_record.c +44 -17
109 lines not on this page · raw message
src/interfaces.h +10 -10
@@ -37,24 +37,24 @@typedef struct record_table {/* Create a record */ -int (*create) (record_t * rec); +int (*create) (record_t ** rec);/* Extract key from record */ -int (*key_extract) (record_t rec,record_key_t * key); +int (*key_extract) (record_t * rec,record_key_t ** key);/* Free record key */ -void (*key_free) (record_key_t key); +void (*key_free) (record_key_t * key);/* Return 0 if record can be matched against key, * and 1 otherwise */ -int (*compare) (record_t rec,record_key_t key); +int (*compare) (record_t * rec,record_key_t * key);/* Deep-copy clone of this record */ -int (*clone) (record_t rec,record_t * new_rec); +int (*clone) (record_t * rec,record_t ** new_rec);/* Deallocate record resources. Must * sucessfully handle NULL. */ -void (*free) (record_t rec); +void (*free) (record_t * rec); }record_table_t ;
@@ -64,10 +64,10 @@/* Fill record structuure based on supplied parse info. * Parser must return STATUS_NODATA when EOF is encountered. * Parser must handle NULL file stream correctly */ -int (*parse) (parse_info_t * info,record_t record); +int (*parse) (parse_info_t * info,record_t * record);/* Print record to stream */ -int (*print) (record_t record,FILE * str); +int (*print) (record_t * record,FILE * str); } record_file_table_t;
@@ -75,10 +75,10 @@typedef struct record_direct_table {/* Load record into policy store */ -int (*load) (policydb_t * policy,record_t record); +int (*load) (policydb_t * policy,record_t * record);/* Extract records from policy store */ -int (*list) (policydb_t * policy,record_t ** records,size_t * nrecords); +int (*list) (policydb_t * policy,record_t *** records,size_t * nrecords); }record_direct_table_t ;
src/port_record.c +56 -20
134 lines not on this page · raw message
src/ports.c +10 -10
@@ -27,8 +27,8 @@int semanage_port_add (semanage_handle_t * handle, -semanage_port_key_t key, -semanage_port_t data) { +semanage_port_key_t * key, +semanage_port_t * data) {dbase_t * dbase =semanage_port_dbase (handle);return dbase_add (handle, dbase, key, data);
@@ -36,8 +36,8 @@int semanage_port_modify (semanage_handle_t * handle, -semanage_port_key_t key, -semanage_port_t data) { +semanage_port_key_t * key, +semanage_port_t * data) {dbase_t * dbase =semanage_port_dbase (handle);return dbase_modify (handle, dbase, key, data);
@@ -45,7 +45,7 @@int semanage_port_del (semanage_handle_t * handle, -semanage_port_key_t key) { +semanage_port_key_t * key) {dbase_t * dbase =semanage_port_dbase (handle);return dbase_del (handle, dbase, key);
@@ -53,8 +53,8 @@int semanage_port_query (semanage_handle_t * handle, -semanage_port_key_t key, -semanage_port_t * response) { +semanage_port_key_t * key, +semanage_port_t ** response) {dbase_t * dbase =semanage_port_dbase (handle);return dbase_query (handle, dbase, key, response);
@@ -62,7 +62,7 @@int semanage_port_exists (semanage_handle_t * handle, -semanage_port_key_t key, +semanage_port_key_t * key,int * response) {dbase_t * dbase =semanage_port_dbase (handle);
@@ -79,7 +79,7 @@int semanage_port_iterate (semanage_handle_t * handle, -int (*handler) (semanage_port_t record, +int (*handler) (semanage_port_t * record,void * varg),void * handler_arg) {
@@ -89,7 +89,7 @@int semanage_port_list (semanage_handle_t * handle, -semanage_port_t ** records, +semanage_port_t *** records,size_t * count) {dbase_t * dbase =semanage_port_dbase (handle);
src/ports_direct.c +2 -2
@@ -3,8 +3,8 @@*/ #include <sepol/port_record.h> -typedef sepol_port_t *record_t ; -typedef sepol_port_key_t *record_key_t ; +typedef sepol_port_t record_t ; +typedef sepol_port_key_t record_key_t ;#define RECORD_DEFINED struct dbase_direct_backend ;
src/ports_file.c +4 -3
@@ -15,7 +15,7 @@#include "debug.h" static int port_print ( -semanage_port_t port, +semanage_port_t * port,FILE * str) {/* Stub */
@@ -26,7 +26,7 @@static int port_parse (parse_info_t * info, -semanage_port_t port) { +semanage_port_t * port) {/* Stub */ info =NULL ;
@@ -49,7 +49,8 @@if (dbase_file_init (NULL ,/* FIXME */ - &SEMANAGE_PORT_FILE_RTABLE , &backend) <0 ) + &SEMANAGE_PORT_FILE_RTABLE , + &backend) <0 )return STATUS_ERR ; return dbase_init(
src/ports_policy.c +7 -7
@@ -4,8 +4,8 @@#include <sepol/port_record.h> -typedef sepol_port_key_t *record_key_t ; -typedef sepol_port_t *record_t ; +typedef sepol_port_key_t record_key_t ; +typedef sepol_port_t record_t ;#define RECORD_DEFINED #include <semanage/port_record.h>
@@ -18,8 +18,8 @@#include "debug.h" static inline int convert ( -semanage_port_key_t semanage_key, -semanage_port_t semanage_port, +semanage_port_key_t * semanage_key, +semanage_port_t * semanage_port,sepol_port_key_t ** sepol_key,sepol_port_t ** sepol_port) {
@@ -42,8 +42,8 @@#if 0 int semanage_port_policy_load (semanage_handle_t * handle, -semanage_port_key_t key, -semanage_port_t data) { +semanage_port_key_t * key, +semanage_port_t * data) {sepol_port_t * sepol_data;sepol_port_key_t * sepol_key;
@@ -57,7 +57,7 @@int semanage_port_policy_list (semanage_handle_t * handle, -semanage_port_t ** records, +semanage_port_t *** records,size_t * count) {/* Stub */
src/user_record.c +74 -23
174 lines not on this page · raw message
src/users.c +10 -10
@@ -27,8 +27,8 @@int semanage_user_add (semanage_handle_t * handle, -semanage_user_key_t key, -semanage_user_t data) { +semanage_user_key_t * key, +semanage_user_t * data) {dbase_t * dbase =semanage_user_dbase (handle);return dbase_add (handle, dbase, key, data);
@@ -36,8 +36,8 @@int semanage_user_modify (semanage_handle_t * handle, -semanage_user_key_t key, -semanage_user_t data) { +semanage_user_key_t * key, +semanage_user_t * data) {dbase_t * dbase =semanage_user_dbase (handle);return dbase_modify (handle, dbase, key, data);
@@ -45,7 +45,7 @@int semanage_user_del (semanage_handle_t * handle, -semanage_user_key_t key) { +semanage_user_key_t * key) {dbase_t * dbase =semanage_user_dbase (handle);return dbase_del (handle, dbase, key);
@@ -53,8 +53,8 @@int semanage_user_query (semanage_handle_t * handle, -semanage_user_key_t key, -semanage_user_t * response) { +semanage_user_key_t * key, +semanage_user_t ** response) {dbase_t * dbase =semanage_user_dbase (handle);return dbase_query (handle, dbase, key, response);
@@ -62,7 +62,7 @@int semanage_user_exists (semanage_handle_t * handle, -semanage_user_key_t key, +semanage_user_key_t * key,int * response) {dbase_t * dbase =semanage_user_dbase (handle);
@@ -79,7 +79,7 @@int semanage_user_iterate (semanage_handle_t * handle, -int (*handler) (semanage_user_t record, +int (*handler) (semanage_user_t * record,void * varg),void * handler_arg) {
@@ -89,7 +89,7 @@int semanage_user_list (semanage_handle_t * handle, -semanage_user_t ** records, +semanage_user_t *** records,size_t * count) {dbase_t * dbase =semanage_user_dbase (handle);
src/users_direct.c +2 -2
@@ -3,8 +3,8 @@*/ #include <sepol/user_record.h> -typedef sepol_user_t *record_t ; -typedef sepol_user_key_t *record_key_t ; +typedef sepol_user_t record_t ; +typedef sepol_user_key_t record_key_t ;#define RECORD_DEFINED struct dbase_direct_backend ;
src/users_file.c +2 -2
@@ -15,7 +15,7 @@#include "debug.h" static int user_print ( -semanage_user_t user, +semanage_user_t * user,FILE * str) {/* Stub */
@@ -26,7 +26,7 @@static int user_parse (parse_info_t * info, -semanage_user_t user) { +semanage_user_t * user) {/* Stub */ info =NULL ;
src/users_policy.c +7 -7
@@ -4,8 +4,8 @@#include <sepol/user_record.h> -typedef sepol_user_key_t *record_key_t ; -typedef sepol_user_t *record_t ; +typedef sepol_user_key_t record_key_t ; +typedef sepol_user_t record_t ;#define RECORD_DEFINED #include <stddef.h>
@@ -18,8 +18,8 @@#include "debug.h" static inline int convert ( -semanage_user_key_t semanage_key, -semanage_user_t semanage_user, +semanage_user_key_t * semanage_key, +semanage_user_t * semanage_user,sepol_user_key_t ** sepol_key,sepol_user_t ** sepol_user) {
@@ -42,8 +42,8 @@#if 0 int semanage_user_policy_load (semanage_handle_t * handle, -semanage_user_key_t key, -semanage_user_t data) { +semanage_user_key_t * key, +semanage_user_t * data) {sepol_user_t * sepol_data;sepol_user_key_t * sepol_key;
@@ -57,7 +57,7 @@int semanage_user_policy_list (semanage_handle_t * handle, -semanage_user_t ** records, +semanage_user_t *** records,size_t * count) {/* Stub */