[10 / 9] [ SEMANAGE ] FIx placement of function table
In one of my patches I broke up semanage_private.h into pieces. However, I've placed things incorrectly, because I misunderstood what things were supposed to do.
This corrects one of the problems - it moves the function table into a new file called policy_connection.h. It also renames that structure, because I use at least 3 or 4 different types of func_tables in my code. For consistency this should go into interfaces.h, but perhaps I should split up interfaces.h into several headers instead (?)
The other problem is the connection object - module_conn_t. I put that in modules.h, because it said "module", but it doesn't look like it belongs there. Karl, where should I move this? Should it go into direct_api.h ? I see the semanage_store makes use of that... is the semanage_store specific to the direct API?
On a related note, where can I put policydb pointers - I need two of them for starters - ACTIVE, and LOCAL_MOD... the actual policydb objects will be created on demand (say when the user decides to query something), or when commit decides to re-create the active policy from scratch, but I need the pointers to them in a data structure linked into the handle (that's specific to direct api?) Should this go into conn.module (renaming that to conn.direct ?)
src/direct_api.c +2 -1
@@ -31,6 +31,7 @@#include "modules.h" #include "direct_api.h" #include "semanage_store.h" +#include "policy_connection.h" static void semanage_direct_destroy (semanage_handle_t *sh);static int semanage_direct_disconnect (semanage_handle_t *sh);
@@ -46,7 +47,7 @@static int semanage_direct_list (semanage_handle_t *sh,semanage_module_info_t **modinfo,int *num_modules); -static struct semanage_func_table direct_funcs = { +static struct semanage_policy_table direct_funcs = { .destroy = semanage_direct_destroy, .disconnect = semanage_direct_disconnect, .begin_trans = semanage_direct_begintrans,
src/handle.h +2 -14
@@ -27,23 +27,11 @@#include <semanage/handle.h> #include "modules.h" #include "semanage_conf.h" +#include "policy_connection.h" /* Can't include - circular dependency */ struct dbase ; -/* FIXME: Some of this needs to go into modules.h */ -struct semanage_func_table { -void (*destroy)(semanage_handle_t *); -int (*disconnect)(semanage_handle_t *); -int (*begin_trans)(semanage_handle_t *); -int (*commit)(semanage_handle_t *); -int (*install)(semanage_handle_t *,char *,size_t ); -int (*upgrade)(semanage_handle_t *,char *,size_t ); -int (*install_base)(semanage_handle_t *,char *,size_t ); -int (*remove)(semanage_handle_t *,char *); -int (*list)(semanage_handle_t *,semanage_module_info_t **,int *); -}; -struct semanage_handle {int con_id;/* Connection ID */ int policy_serial;/* Policy serial number at connect time */
@@ -72,7 +60,7 @@/* these function pointers will point to the appropriate * routine given the connection type. think of these as * simulating polymorphism for non-OO languages. */ -struct semanage_func_table *funcs; +struct semanage_policy_table * funcs;/* Object databases */ #define DBASE_COUNT 2
src/policy_connection.h +55 -0
55 lines not on this page · raw message
Quoted 16 lines · Ivan Gyurdiev
In one of my patches I broke up
semanage_private.hinto pieces. However, I've placed things incorrectly, because I misunderstood what things were supposed to do.This corrects one of the problems - it moves the function table into a new file called
policy_connection.h. It also renames that structure, because I use at least 3 or 4 different types offunc_tablesin my code. For consistency this should go intointerfaces.h, but perhaps I should split upinterfaces.hinto several headers instead (?)The other problem is the connection object -
module_conn_t. I put that inmodules.h, because it said "module", but it doesn't look like it belongs there. Karl, where should I move this? Should it go intodirect_api.h? I see thesemanage_storemakes use of that... is thesemanage_storespecific to the direct API?
Quoted 7 lines
On a related note, where can I put policydb pointers - I need two of them for starters - ACTIVE, and
LOCAL_MOD... the actual policydb objects will be created on demand (say when the user decides to query something), or when commit decides to re-create the active policy from scratch, but I need the pointers to them in a data structure linked into the handle (that's specific to direct api?) Should this go into conn.module (renaming that to conn.direct ?)
Hmmm...I just got done merging the others (available in the sourceforge CVS), although naturally all of this is still open to debate and can be reverted at any time.
I think at this point I'll wait for clarification from Karl et al on whether this patch (and the prior ones as well) are consistent with their plans for libsemanage.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 10 lines
Hmmm...I just got done merging the others (available in the sourceforge CVS), although naturally all of this is still open to debate and can be reverted at any time.
I think at this point I'll wait for clarification from Karl et al on whether this patch (and the prior ones as well) are consistent with their plans for libsemanage.
Okay...
It's just a question of where things are supposed to be placed. I think Karl agreed earlier that headers should follow the code, and that's what I was thinking about, but my first patch moved things to the wrong places.
----
The policy function table being discussed is an interface (to be used for the purposes of polymorphism). Because this is an interface, there is no associated code - implementations use the specific type, and include a header to fill the table . At the same time, semanage_private.h was containing random things, so this is probably better off on its own, which this patch sets up (or bundled with the rest of interfaces.h, but handle.h is probably the wrong place for it).
The other thing I moved was handle code (that's fine IMHO), debug code (fine), and a conn object. I can't figure out exactly what the conn object is planned for, so that's why I asked... I suspect it's the connection state object for direct API (so it goes in direct_api.h)
--
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: [ SEMANAGE ] [ SEPOL ] Backend iterate function
Well, while you figure out if you want to merge the last patch I sent, here's a couple of other patches.
List() is basically a special case of iterate. As I mentioned in my other email, we *need* iterate functionality for large databases, because it won't be practical to load them in memory (at least in expanded form) - one such database is the list of all rules in base policy.
---
The first patch here replaces the user list() function which I just wrote with an iterate() one. This exercise wasn't useless - most of the code is exactly the same - we just don't put the users in an array, and we call a handler. List is removed, because it can be implemented on top of iterate. In fact, most of the other functions in the sepol users/interfaces/ports API should be removed once semanage is properly functioning. I've also added iterate() on interfaces, ports, and booleans. Tried this, and it seems to work fine - print handler prints out all the data.
The second patch corrects the corresponding table in semanage (the record_direct_table_t), and sets those functions in the tables for users and ports. It also adds an iterate() function to the backend table, and stubs for that. Finally, it adds cacheable parameter to each database, that will indicate whether the database should be cached. If it says 0, then .... it will fallback to implementation via iterate() in the backend (without making a list of records)) (I haven't set this up yet). Currently all databases are cacheable.
Again, the point of this is :
- for large POLICY databases (list of rules), not to expand the shared list of strings into an array of stand-alone records, which will take up tons of space.
- for large FILE databases, not to load the contents of the FILE in memory (not sure if I'll implement this).
include/sepol/booleans.h +13 -0
@@ -16,4 +16,17 @@sepol_bool_t ** bool_arr, size_t bool_arr_len); +/* Iterate the booleans +* The handler may return: +* -1 to signal an error condition, +* 1 to signal successful exit +* 0 to signal continue */ + +extern int sepol_bool_iterate ( +policydb_t * policydb, +int (*fn)( +sepol_bool_t * boolean, +void * fn_arg), +void * arg); +#endif
include/sepol/interfaces.h +13 -0
@@ -17,4 +17,17 @@ policydb_t* policydb, sepol_iface_t* data); +/* Iterate the interfaces +* The handler may return: +* -1 to signal an error condition, +* 1 to signal successful exit +* 0 to signal continue */ + +extern int sepol_iface_iterate ( +policydb_t * policydb, +int (*fn)( +sepol_iface_t * iface, +void * fn_arg), +void * arg); +#endif
include/sepol/ports.h +13 -0
@@ -19,4 +19,17 @@ policydb_t* policydb, sepol_port_t* data); +/* Iterate the ports +* The handler may return: +* -1 to signal an error condition, +* 1 to signal successful exit +* 0 to signal continue */ + +extern int sepol_port_iterate ( +policydb_t * policydb, +int (*fn)( +sepol_port_t * port, +void * fn_arg), +void * arg); +#endif
include/sepol/users.h +11 -4
@@ -32,11 +32,18 @@policydb_t * policydb, const char* role); -/* Obtain the user list */ -extern int sepol_user_list ( +/* Iterate the users +* The handler may return: +* -1 to signal an error condition, +* 1 to signal successful exit +* 0 to signal continue */ + +extern int sepol_user_iterate (policydb_t * policydb, -sepol_user_t *** users, -size_t * nusers); +int (*fn)( +sepol_user_t * user, +void * fn_arg), +void * arg); extern int sepol_get_valid_roles( policydb_t* policydb,
src/booleans.c +48 -0
51 lines not on this page · raw message
src/interfaces.c +79 -0
82 lines not on this page · raw message
src/ports.c +82 -1
92 lines not on this page · raw message
src/users.c +29 -29
105 lines not on this page · raw message
src/database.c +16 -3
@@ -10,6 +10,7 @@ record_table_t* rtable, dbase_backend_t* backend, dbase_backend_table_t* btable, + int cacheable, dbase_t** dbase) { dbase_t* tmp_dbase =
@@ -25,6 +26,7 @@ tmp_dbase->cache_sz =0 ; tmp_dbase->cached =0 ; tmp_dbase->cache_invalid =0 ; + tmp_dbase->cacheable = cacheable; *dbase = tmp_dbase;return STATUS_SUCCESS ;
@@ -54,15 +56,17 @@void dbase_invalidate_cache (dbase_t * dbase) { - dbase->cache_invalid =1 ; +if (dbase->cacheable) + dbase->cache_invalid =1 ; }/* Flush the database cache */ int dbase_flush (dbase_t * dbase) { -if (dbase->btable->flush (dbase, dbase->backend) <0 ) -return STATUS_ERR ; +if (dbase->cacheable) +if (dbase->btable->flush (dbase, dbase->backend) <0 ) +return STATUS_ERR ;return STATUS_SUCCESS ; }
@@ -93,6 +97,7 @@cache_entry_t * ptr; +/* FIXME: respect cacheable */ if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;
@@ -117,6 +122,7 @@int exists; +/* FIXME: respect cacheable */ if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;
@@ -148,6 +154,7 @@cache_entry_t * entry;int status; +/* FIXME: respect cacheable */ if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;
@@ -174,6 +181,7 @@cache_entry_t *ptr, *prev =NULL ; +/* FIXME: respect cacheable */ if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;
@@ -209,6 +217,7 @@cache_entry_t * entry;int status; +/* FIXME: respect cacheable */ if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;
@@ -235,6 +244,7 @@cache_entry_t * entry;int status; +/* FIXME: respect cacheable */ if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;
@@ -256,6 +266,7 @@ dbase_t* dbase, int* response) { +/* FIXME: respect cacheable */ if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;
@@ -277,6 +288,7 @@int status;cache_entry_t * ptr; +/* FIXME: respect cacheable */ if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;
@@ -308,6 +320,7 @@size_t tmp_count;int i =0 ; +/* FIXME: respect cacheable */ if (dbase->btable->cache (dbase, dbase->backend) <0 ) goto err;
src/database_direct.c +15 -0
@@ -87,8 +87,23 @@free (backend); } +/* Iterate over backend */ +int dbase_direct_iterate ( +dbase_direct_backend_t * backend, +int (*fn) (record_t * record,void * fn_arg), +void * arg) { + +/* Stub */ + backend =NULL ; + fn =NULL ; + arg =NULL ; + +return STATUS_SUCCESS ; +} +/* DIRECT POLICY backend - method table implementation */ dbase_backend_table_t SEMANAGE_DIRECT_BTABLE = { .cache = dbase_direct_cache, .flush = dbase_direct_flush, + .iterate = dbase_direct_iterate, };
src/database_file.c +15 -0
@@ -136,8 +136,23 @@free (backend); } +/* Iterate over backend */ +int dbase_file_iterate ( +dbase_file_backend_t * backend, +int (*fn) (record_t * record,void * fn_arg), +void * arg) { + +/* Stub */ + backend =NULL ; + fn =NULL ; + arg =NULL ; + +return STATUS_SUCCESS ; +} +/* FILE backend - method table implementation */ dbase_backend_table_t SEMANAGE_FILE_BTABLE = { .cache = dbase_file_cache, .flush = dbase_file_flush, + .iterate = dbase_file_iterate, };
src/database.h +2 -0
@@ -44,6 +44,7 @@size_t cache_sz;int cached;int cache_invalid; +int cacheable; } dbase_t;/* Add a record to the database cache */
@@ -60,6 +61,7 @@ record_table_t* rtable, dbase_backend_t* backend, dbase_backend_table_t* btable, + int cacheable, dbase_t** dbase);/* Get back the backend object */
src/interfaces.h +12 -3
@@ -74,11 +74,14 @@/* POLICY DIRECT extension to RECORD interface - method table */ typedef struct record_direct_table { -/* Load record into policy store */ +/* Load record into the policy database */ int (*load) (policydb_t * policy,record_t * record); -/* Extract records from policy store */ -int (*list) (policydb_t * policy,record_t *** records,size_t * nrecords); +/* Iterate over records */ +int (*iterate) ( +policydb_t * policydb, +int (*fn)(record_t * record,void * fn_arg), +void * arg); }record_direct_table_t ;
@@ -91,6 +94,12 @@/* Flush dbase to backend */ int (*flush) (struct dbase * dbase,dbase_backend_t * backend); +/* Iterate over backend */ +int (*iterate) ( +dbase_backend_t * backend, +int (*fn)(record_t * record,void * fn_arg), + void* arg); + } dbase_backend_table_t;#endif
src/ports_direct.c +9 -8
@@ -25,23 +25,24 @@/* PORT RECORD (SEPOL): POLICY DIRECT extension : method table */ record_direct_table_t SEMANAGE_PORT_DIRECT_RTABLE = { .load = sepol_port_load, - .list =NULL ,/* sepol_port_list, */ + .iterate = sepol_port_iterate, };int port_direct_dbase_init (dbase_t ** dbase) {dbase_direct_backend_t * backend;if (dbase_direct_init ( -NULL ,/* FIXME */ -NULL ,/* FIXME */ - &SEMANAGE_PORT_DIRECT_RTABLE , - &backend) <0 ) +NULL ,/* FIXME: backing file */ +NULL ,/* FIXME: policydb pointer */ + &SEMANAGE_PORT_DIRECT_RTABLE ,/* record backend method table */ + &backend) <0 )return STATUS_ERR ;return dbase_init ( - &SEPOL_PORT_RTABLE , - backend, - &SEMANAGE_DIRECT_BTABLE , + &SEPOL_PORT_RTABLE ,/* record base method table */ + backend,/* backend */ + &SEMANAGE_DIRECT_BTABLE ,/* backend method table */ +1 ,/* cacheable */ dbase); }
src/ports_file.c +6 -5
@@ -48,15 +48,16 @@dbase_file_backend_t * backend;if (dbase_file_init ( -NULL ,/* FIXME */ - &SEMANAGE_PORT_FILE_RTABLE , +NULL ,/* FIXME: backing file */ + &SEMANAGE_PORT_FILE_RTABLE ,/* record backend method table */ &backend) <0 )return STATUS_ERR ;return dbase_init ( - &SEMANAGE_PORT_RTABLE , - backend, - &SEMANAGE_FILE_BTABLE , + &SEMANAGE_PORT_RTABLE ,/* record base method table */ + backend,/* backend */ + &SEMANAGE_FILE_BTABLE ,/* backend method table */ +1 ,/* cacheable */ dbase); }
src/users_direct.c +8 -7
@@ -25,23 +25,24 @@/* USER RECRORD (SEPOL): POLICY DIRECT extension: method table */ record_direct_table_t SEMANAGE_USER_DIRECT_RTABLE = { .load = sepol_user_load, - .list =NULL ,/* sepol_user_list */ + .iterate = sepol_user_iterate, };int user_direct_dbase_init (dbase_t ** dbase) {dbase_direct_backend_t * backend;if (dbase_direct_init ( -NULL ,/* FIXME */ -NULL ,/* FIXME */ - &SEMANAGE_USER_DIRECT_RTABLE , +NULL ,/* FIXME: backing file */ +NULL ,/* FIXME: policydb pointer */ + &SEMANAGE_USER_DIRECT_RTABLE ,/* record backend method table */ &backend) <0 )return STATUS_ERR ;return dbase_init ( - &SEPOL_USER_RTABLE , - backend, - &SEMANAGE_DIRECT_BTABLE , + &SEPOL_USER_RTABLE ,/* record base method table */ + backend,/* backend */ + &SEMANAGE_DIRECT_BTABLE ,/* backend method table */ +1 ,/* cacheable */ dbase); }
src/users_file.c +6 -5
@@ -47,15 +47,16 @@dbase_file_backend_t * backend;if (dbase_file_init ( -NULL ,/* FIXME */ - &SEMANAGE_USER_FILE_RTABLE , +NULL ,/* FIXME: backing file */ + &SEMANAGE_USER_FILE_RTABLE ,/* record backend method table */ &backend) <0 )return STATUS_ERR ;return dbase_init ( - &SEMANAGE_USER_RTABLE , - backend, - &SEMANAGE_FILE_BTABLE , + &SEMANAGE_USER_RTABLE ,/* record base method table */ + backend,/* backend */ + &SEMANAGE_FILE_BTABLE ,/* backend method table */ +1 ,/* cacheable */ dbase); }
Re: [ SEMANAGE ] Break up interfaces.h, implement parsing helpers
Here's one more.
Patch redistributes interfaces.h back into database.h, database_file.h, database_direct.h. I promise I'll stop moving functionality around now - I'm very happy with where it's at (for now :)
Moves parse stuff into parse_utils.[c,h]. Implement parsing helpers that will be used for the user parser (and others). Testing?
It used to work (and pass valgrind) back when I was implementing it for libselinux and libsepol. Haven't tested it since then, but nothing's changed. Since nothing's using this code, I thought it'd be okay to merge - even if it has bugs (which it shouldn't). I'll do more testing when I get the rest of the framework set up, so I can read the files.
src/database.c +0 -1
@@ -2,7 +2,6 @@#include <stddef.h> #include "debug.h" #include "database.h" -#include "interfaces.h" #include "handle.h" /* Initialize a database */
src/database_direct.c +1 -2
@@ -1,11 +1,10 @@struct dbase_direct_backend ;typedef struct dbase_direct_backend dbase_backend_t ; -#define BACKEND_DEFINED +#define DBASE_BACKEND_DEFINED #include <stdlib.h> #include <sepol/policydb.h> #include "database_direct.h" -#include "interfaces.h" #include "debug.h" /* POLICY DIRECT backend */
src/database_direct.h +15 -1
@@ -1,12 +1,26 @@#ifndef _SEMANAGE_DATABASE_DIRECT_INTERNAL_H_#define _SEMANAGE_DATABASE_DIRECT_INTERNAL_H_ +#include <sepol/policydb.h> #include "database.h" -#include "interfaces.h" struct dbase_direct_backend ;typedef struct dbase_direct_backend dbase_direct_backend_t ; +/* POLICY DIRECT extension to RECORD interface - method table */ +typedef struct record_direct_table { + +/* Load record into the policy database */ +int (*load) (policydb_t * policy,record_t * record); + +/* Iterate over records */ +int (*iterate) ( +policydb_t * policydb, +int (*fn)(record_t * record,void * fn_arg), +void * arg); + +}record_direct_table_t ; +/* POLICY DIRECT backend - initialization */ extern int dbase_direct_init( const char* filename,
src/database_file.c +5 -27
@@ -1,13 +1,10 @@struct dbase_file_backend ;typedef struct dbase_file_backend dbase_backend_t ; -#define BACKEND_DEFINED +#define DBASE_BACKEND_DEFINED -#include <stdio.h> #include <stdlib.h> -#include <errno.h> -#include <stdio_ext.h> #include "debug.h" -#include "interfaces.h" +#include "parse_utils.h" #include "database_file.h" /* FILE backend */
@@ -20,25 +17,6 @@record_file_table_t * rftable; }; -static int dbase_file_open (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_file_close (parse_info_t * info) { -if (info->file_stream && (fclose (info->file_stream) <0 )) -/* FIXME: handle error condition */ - info->file_stream =NULL ; -} -static int dbase_file_cache (dbase_t * dbase,dbase_file_backend_t * backend) {
@@ -57,7 +35,7 @@ parse_info.parse_arg =NULL ;/* FIXME: pass from caller? */ -if (dbase_file_open (&parse_info) <0 ) +if (parse_open (&parse_info) <0 ) goto err;/* Main processing loop */
@@ -83,7 +61,7 @@ }while (pstatus !=STATUS_NODATA ); -dbase_file_close (&parse_info); +parse_close (&parse_info); dbase->cached =1 ; dbase->cache_invalid =0 ;return STATUS_SUCCESS ;
@@ -91,7 +69,7 @@ err:/* FIXME: handle failure */ dbase->rtable->free (process_record); -dbase_file_close (&parse_info); +parse_close (&parse_info);return STATUS_ERR ; }
src/database_file.h +15 -1
@@ -1,12 +1,26 @@#ifndef _SEMANAGE_DATABASE_FILE_INTERNAL_H_#define _SEMANAGE_DATABASE_FILE_INTERNAL_H_ +#include <stdio.h> #include "database.h" -#include "interfaces.h" +#include "parse_utils.h" struct dbase_file_backend ;typedef struct dbase_file_backend dbase_file_backend_t ; +/* FILE extension to RECORD interface - method table */ +typedef struct record_file_table { + +/* 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); + +/* Print record to stream */ +int (*print) (record_t * record,FILE * str); + +}record_file_table_t ; +/* FILE backend - initialization */ extern int dbase_file_init( const char* filename,
src/database.h +52 -5
78 lines not on this page · raw message
src/interfaces.h +0 -105
105 lines not on this page · raw message
src/parse_utils.c +268 -0
268 lines not on this page · raw message
src/parse_utils.h +90 -0
90 lines not on this page · raw message
src/ports.c +1 -2
@@ -6,14 +6,13 @@typedef semanage_port_key_t record_key_t ;typedef semanage_port_t record_t ; -#define RECORD_DEFINED +#define DBASE_RECORD_DEFINED #include <stddef.h> #include <stdlib.h> #include <semanage/ports.h> #include "database.h" #include "handle.h" -#include "interfaces.h" /* Port base functions */ record_table_t SEMANAGE_PORT_RTABLE = {
src/ports_direct.c +2 -3
@@ -5,18 +5,17 @@typedef sepol_port_t record_t ;typedef sepol_port_key_t record_key_t ; -#define RECORD_DEFINED +#define DBASE_RECORD_DEFINED struct dbase_direct_backend ;typedef struct dbase_direct_backend dbase_backend_t ; -#define BACKEND_DEFINED +#define DBASE_BACKEND_DEFINED #include <stddef.h> #include <sepol/ports.h> #include <sepol/policydb.h> #include "ports_direct.h" #include "debug.h" -#include "interfaces.h" #include "database_direct.h" /* PORT RECORD (SEPOL): method table (ports_policy.c) */
src/ports_file.c +3 -3
@@ -2,16 +2,16 @@typedef semanage_port_t record_t ;typedef semanage_port_key_t record_key_t ; -#define RECORD_DEFINED +#define DBASE_RECORD_DEFINED struct dbase_file_backend ;typedef struct dbase_file_backend dbase_backend_t ; -#define BACKEND_DEFINED +#define DBASE_BACKEND_DEFINED #include <stdlib.h> #include <stdio.h> -#include "interfaces.h" #include "database_file.h" +#include "parse_utils.h" #include "debug.h" static int port_print(
src/ports_policy.c +1 -2
@@ -6,14 +6,13 @@typedef sepol_port_key_t record_key_t ;typedef sepol_port_t record_t ; -#define RECORD_DEFINED +#define DBASE_RECORD_DEFINED #include <semanage/port_record.h> #include <stddef.h> #include <stdlib.h> #include "handle.h" #include "database.h" -#include "interfaces.h" #include "ports_policy.h" #include "debug.h"
src/record.h +35 -0
@@ -0,0 +1,35 @@ +#ifndef _SEMANAGE_RECORD_H_ +#define _SEMANAGE_RECORD_H_ + +#ifndef RECORD_DEFINED +typedef void *record_t ; +typedef void *record_key_t ; +#define RECORD_DEFINED +#endif + +/* RECORD interface - method table */ +typedef struct record_table { + +/* Create a record */ +int (*create) (record_t ** rec); + +/* Extract key from record */ +int (*key_extract) (record_t * rec,record_key_t ** key); + +/* Free record 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); + +/* Deep-copy clone of this record */ +int (*clone) (record_t * rec,record_t ** new_rec); + +/* Deallocate record resources. Must +* sucessfully handle NULL. */ +void (*free) (record_t * rec); + +}record_table_t ; + +#endif
src/users.c +1 -2
@@ -6,14 +6,13 @@typedef semanage_user_key_t record_key_t ;typedef semanage_user_t record_t ; -#define RECORD_DEFINED +#define DBASE_RECORD_DEFINED #include <stddef.h> #include <stdlib.h> #include <semanage/users.h> #include "handle.h" #include "database.h" -#include "interfaces.h" /* Record base functions */ record_table_t SEMANAGE_USER_RTABLE = {
src/users_direct.c +2 -3
@@ -5,18 +5,17 @@typedef sepol_user_t record_t ;typedef sepol_user_key_t record_key_t ; -#define RECORD_DEFINED +#define DBASE_RECORD_DEFINED struct dbase_direct_backend ;typedef struct dbase_direct_backend dbase_backend_t ; -#define BACKEND_DEFINED +#define DBASE_BACKEND_DEFINED #include <stddef.h> #include <sepol/users.h> #include <sepol/policydb.h> #include "users_direct.h" #include "debug.h" -#include "interfaces.h" #include "database_direct.h" /* USER RECORD (SEPOL): method table (users_policy.c) */
src/users_file.c +3 -3
@@ -2,16 +2,16 @@typedef semanage_user_t record_t ;typedef semanage_user_key_t record_key_t ; -#define RECORD_DEFINED +#define DBASE_RECORD_DEFINED struct dbase_file_backend ;typedef struct dbase_file_backend dbase_backend_t ; -#define BACKEND_DEFINED +#define DBASE_BACKEND_DEFINED #include <stdlib.h>#include <stdio.h> -#include "interfaces.h" #include "database_file.h" +#include "parse_utils.h" #include "debug.h" static int user_print(
src/users_policy.c +1 -2
@@ -6,14 +6,13 @@typedef sepol_user_key_t record_key_t ;typedef sepol_user_t record_t ; -#define RECORD_DEFINED +#define DBASE_RECORD_DEFINED #include <stddef.h> #include <stdlib.h> #include <semanage/user_record.h> #include "handle.h" #include "database.h" -#include "interfaces.h" #include "users_policy.h" #include "debug.h"
Re: [ SEMANAGE ] Break up interfaces.h, implement parsing helpers
Quoted 5 lines · Ivan Gyurdiev
Patch redistributes
interfaces.hback intodatabase.h,database_file.h,database_direct.h.
I promise I'll stop moving functionality around now - I'm very happy with where it's at (for now :)
Quoted 7 lines
Moves parse stuff into parse_utils.[c,h]. Implement parsing helpers that will be used for the user parser (and others). Testing?
It used to work (and pass valgrind) back when I was implementing it for libselinux and libsepol. Haven't tested it since then, but nothing's changed. Since nothing's using this code, I thought it'd be okay to merge - even if it has bugs (which it shouldn't). I'll do more testing when I get the rest of the framework set up, so I can read the files.
Merged.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [ SEMANAGE ] [ SEPOL ] Backend iterate function
In reply to Ivan GyurdievQuoted 10 lines · Ivan Gyurdiev
The first patch here replaces the user
list()function which I just wrote with aniterate()one. This exercise wasn't useless - most of the code is exactly the same - we just don't put the users in an array, and we call a handler. List is removed, because it can be implemented on top of iterate. In fact, most of the other functions in the sepol users/interfaces/ports API should be removed once semanage is properly functioning. I've also addediterate()on interfaces, ports, and booleans. Tried this, and it seems to work fine - print handler prints out all the data.
Quoted 8 lines
The second patch corrects the corresponding table in semanage (the
record_direct_table_t), and sets those functions in the tables for users and ports. It also adds aniterate()function to the backend table, and stubs for that. Finally, it adds cacheable parameter to each database, that will indicate whether the database should be cached. If it says 0, then .... it will fallback to implementation viaiterate()in the backend (without making a list of records)) (I haven't set this up yet). Currently all databases are cacheable.
Merged.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 32 lines
-----Original Message-----
From: Stephen Smalley [mailto:[email protected]]
Sent: Friday, September 30, 2005 4:28 PM
To: Ivan Gyurdiev
Cc: [email protected]; Karl MacMillan
Subject: Re: [10 / 9] [ SEMANAGE ] FIx placement of function tableQuoted 16 lines · Ivan Gyurdiev
In one of my patches I broke up
semanage_private.hinto pieces. However, I've placed things incorrectly, because I misunderstood what things were supposed to do.This corrects one of the problems - it moves the function table into a new file called
policy_connection.h. It also renames that structure, because I use at least 3 or 4 different types offunc_tablesin my code. For consistency this should go intointerfaces.h, but perhaps I should split upinterfaces.hinto several headers instead (?)The other problem is the connection object -
module_conn_t. I put that inmodules.h, because it said "module", but it doesn't look like it belongs there. Karl, where should I move this? Should it go intodirect_api.h? I see thesemanage_storemakes use of that... is thesemanage_storespecific to the direct API?Quoted 7 lines
On a related note, where can I put policydb pointers - I need two of them for starters - ACTIVE, and
LOCAL_MOD... the actual policydb objects will be created on demand (say when the user decides to query something), or when commit decides to re-create the active policy from scratch, but I need the pointers to them in a data structure linked into the handle (that's specific to direct api?) Should this go into conn.module (renaming that to conn.direct ?)
Quoted 8 lines
Hmmm...I just got done merging the others (available in the sourceforge CVS), although naturally all of this is still open to debate and can be reverted at any time.
I think at this point I'll wait for clarification from Karl et al on whether this patch (and the prior ones as well) are consistent with their plans for libsemanage.
We're looking - should have some thoughts later today.
Karl
------
Karl MacMillan
Tresys Technology
http://www.tresys.com
Quoted 3 lines
--
Stephen Smalley
National Security Agency
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 16 lines · Ivan Gyurdiev
In one of my patches I broke up
semanage_private.hinto pieces. However, I've placed things incorrectly, because I misunderstood what things were supposed to do.This corrects one of the problems - it moves the function table into a new file called
policy_connection.h. It also renames that structure, because I use at least 3 or 4 different types offunc_tablesin my code. For consistency this should go intointerfaces.h, but perhaps I should split upinterfaces.hinto several headers instead (?)The other problem is the connection object -
module_conn_t. I put that inmodules.h, because it said "module", but it doesn't look like it belongs there. Karl, where should I move this? Should it go intodirect_api.h? I see thesemanage_storemakes use of that... is thesemanage_storespecific to the direct API?
Quoted 7 lines
On a related note, where can I put policydb pointers - I need two of them for starters - ACTIVE, and
LOCAL_MOD... the actual policydb objects will be created on demand (say when the user decides to query something), or when commit decides to re-create the active policy from scratch, but I need the pointers to them in a data structure linked into the handle (that's specific to direct api?) Should this go into conn.module (renaming that to conn.direct ?)
Merged. Karl, did you have any opinions on the above questions?
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Synchronization/Caching
Quoted 8 lines
Quoted 5 lines
The other problem is the connection object -
module_conn_t. I put that inmodules.h, because it said "module", but it doesn't look like it belongs there. Karl, where should I move this? Should it go intodirect_api.h? I see thesemanage_storemakes use of that... is thesemanage_storespecific to the direct API?On a related note, where can I put policydb pointers - I need two of them for starters - ACTIVE, and
LOCAL_MOD... the actual policydb objects will be created on demand (say when the user decides to query something), or when commit decides to re-create the active policy from scratch, but I need the pointers to them in a data structure linked into the handle (that's specific to direct api?) Should this go into conn.module (renaming that to conn.direct ?)Merged. Karl, did you have any opinions on the above questions?
I am still interested in the answer to the first question (where should conn be placed?).
The second question.... is a bit more complicated than I originally thought, because having a policydb in memory (or a linked list in memory for the contents of a file) is kind of a problem - it requires synchronization. It brings up the issue of whether queries will be done outside of transaction, on the active sandbox (and if so, what kind of cache procedures will be implemented (none - drop the cache on function exit?)), or inside of transaction, on the tmp sandbox, with the transaction lock held. Also, I'm not sure when and where the read lock is to be used.
Also, I don't particularly like the way the current direct_databse takes a pointer to a policydb elsewhere - that's kind of a hack, that's intended to get multiple dbase views to share the same in-memory policydb object, but I doubt it's going to work, so I think I'll get rid of it for now, and figure out how to implement this properly - will we even have a persistent cache of policy/files across functions outside of transaction mode?
--
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.