Stub record handlers
The attached patch stubs out most of the record handlers, and has the dbase_* routines fill out parts of the config structure.
src/database_file.c +109 -22
@@ -2,6 +2,7 @@#include <stddef.h> #include "database.h" #include "record_file.h" +#include "record_file_handlers.h" #include "users_file.h" #include "ports_file.h"
@@ -42,11 +43,23 @@ record_t data) {iterate_config_t config; +record_add_arg_t handler_arg; + + handler_arg.rtable = dconfig->rtable; + handler_arg.key = key; + handler_arg.data = data; +/* handler_arg.derr_fatal = */ + config.rtable = dconfig->rtable; +/* config.filename = */ +/* config.parse_arg = */ +/* config.perr_fatal = */ + config.modify =1 ; + config.handler = record_add; + config.handler_arg = &handler_arg; +/* config.merr_fatal = */ /* Stub */ - key =NULL ; - data =NULL ;return -1 ; }
@@ -56,11 +69,23 @@ record_t data) {iterate_config_t config; +record_modify_arg_t handler_arg; + + handler_arg.rtable = dconfig->rtable; + handler_arg.key = key; + handler_arg.data = data; +/* handler_arg.merr_fatal = */ + config.rtable = dconfig->rtable; +/* config.filename = */ +/* config.parse_arg = */ +/* config.perr_fatal = */ + config.modify =1 ; + config.handler = record_modify; + config.handler_arg = &handler_arg; +/* config.merr_fatal = */ /* Stub */ - key =NULL ; - data =NULL ;return -1 ; }
@@ -69,10 +94,21 @@ record_key_t key) {iterate_config_t config; +record_del_arg_t handler_arg; + + handler_arg.rtable = dconfig->rtable; + handler_arg.key = key; + config.rtable = dconfig->rtable; - +/* config.filename = */ +/* config.parse_arg = */ +/* config.perr_fatal = */ + config.modify =1 ; + config.handler = record_add; + config.handler_arg = &handler_arg; +/* config.merr_fatal = */ +/* Stub */ - key =NULL ;return -1 ; }
@@ -82,11 +118,22 @@ record_t* response) {iterate_config_t config; +record_query_arg_t handler_arg; + + handler_arg.rtable = dconfig->rtable; + handler_arg.key = key; + handler_arg.response = response; + config.rtable = dconfig->rtable; - +/* config.filename = */ +/* config.parse_arg = */ +/* config.perr_fatal = */ + config.modify =0 ; + config.handler = record_add; + config.handler_arg = &handler_arg; +/* config.merr_fatal = */ +/* Stub */ - key =NULL ; - response =NULL ;return -1 ; }
@@ -96,11 +143,22 @@ int* response) {iterate_config_t config; +record_exists_arg_t handler_arg; + + handler_arg.rtable = dconfig->rtable; + handler_arg.key = key; + handler_arg.response = response; + config.rtable = dconfig->rtable; - +/* config.filename = */ +/* config.parse_arg = */ +/* config.perr_fatal = */ + config.modify =0 ; + config.handler = record_exists; + config.handler_arg = &handler_arg; +/* config.merr_fatal = */ +/* Stub */ - key =NULL ; - response =NULL ;return -1 ; }
@@ -109,26 +167,48 @@ int* response) {iterate_config_t config; +record_count_arg_t handler_arg; + + handler_arg.rtable = dconfig->rtable; + handler_arg.response = response; + config.rtable = dconfig->rtable; +/* config.filename = */ +/* config.parse_arg = */ +/* config.perr_fatal = */ + config.modify =0 ; + config.handler = record_count; + config.handler_arg = &handler_arg; +/* config.merr_fatal = */ /* Stub */ - response =NULL ;return -1 ; }int dbase_iterate (dbase_config_t * dconfig, -int (*handler) (record_key_t key, -record_t record, -void * varg), -void * handler_arg) { - -iterate_config_t config; - config.rtable = dconfig->rtable; +int (*fn) (record_key_t key, +record_t record, +void * varg), +void * fn_arg) { + +iterate_config_t config; +record_iterate_arg_t handler_arg; + + handler_arg.rtable = dconfig->rtable; + handler_arg.fn = fn; + handler_arg.fn_arg = fn_arg; + + config.rtable = dconfig->rtable; +/* config.filename = */ +/* config.parse_arg = */ +/* config.perr_fatal = */ + config.modify =0 ; + config.handler = record_iterate; + config.handler_arg = &handler_arg; +/* config.merr_fatal = */ /* Stub */ - handler =NULL ; - handler_arg =NULL ;return -1 ; }
@@ -140,6 +220,13 @@iterate_config_t config; config.rtable = dconfig->rtable; +/* config.filename = */ +/* config.parse_arg = */ +/* config.perr_fatal = */ + config.modify =0 ; +/* config.handler = */ +/* config.handler_arg = */ +/* config.merr_fatal = */ /* Stub */ keyset =NULL ;
src/database.h +4 -4
@@ -47,10 +47,10 @@extern int dbase_iterate (dbase_config_t * dconfig, -int (*handler) (record_key_t key, -record_t record, -void * varg), -void * handler_arg); +int (*fn) (record_key_t key, +record_t record, +void * varg), +void * fn_arg); extern int dbase_list( dbase_config_t* dconfig,
src/record_file_handlers.c +71 -0
71 lines not on this page · raw message
src/record_file_handlers.h +62 -0
62 lines not on this page · raw message
Re: [ SEMANAGE ] Fix record handlers, add status codes
The attached patch applies on top of the previous one, and fixes several bugs. It also adds a header with status codes which I need... the debug system should go into this header IMHO, once we decide what the debug system should be.
src/database_file.c +13 -12
@@ -1,5 +1,6 @@#include <stdlib.h> #include <stddef.h> +#include "debug.h" #include "database.h" #include "record_file.h" #include "record_file_handlers.h"
@@ -23,12 +24,12 @@ dbase[DBASE_USERS ]->rtable = &RTABLE_USER ; dbase[DBASE_PORTS ]->rtable = &RTABLE_PORT ; -return 0 ; +return STATUS_SUCCESS ; err:for (i--; i >=0 ; i--)free (dbase[i]); -return -1 ; +return STATUS_ERR ; }void dbase_close () {
@@ -60,7 +61,7 @@/* config.merr_fatal = */ /* Stub */ -return -1 ; +return STATUS_SUCCESS ; } int dbase_modify(
@@ -86,7 +87,7 @@/* config.merr_fatal = */ /* Stub */ -return -1 ; +return STATUS_SUCCESS ; } int dbase_del(
@@ -104,12 +105,12 @@/* config.parse_arg = */ /* config.perr_fatal = */ config.modify =1 ; - config.handler = record_add; + config.handler = record_del; config.handler_arg = &handler_arg;/* config.merr_fatal = */ /* Stub */ -return -1 ; +return STATUS_SUCCESS ; } int dbase_query(
@@ -129,12 +130,12 @@/* config.parse_arg = */ /* config.perr_fatal = */ config.modify =0 ; - config.handler = record_add; + config.handler = record_query; config.handler_arg = &handler_arg;/* config.merr_fatal = */ /* Stub */ -return -1 ; +return STATUS_SUCCESS ; } int dbase_exists(
@@ -159,7 +160,7 @@/* config.merr_fatal = */ /* Stub */ -return -1 ; +return STATUS_SUCCESS ; } int dbase_count(
@@ -182,7 +183,7 @@/* config.merr_fatal = */ /* Stub */ -return -1 ; +return STATUS_SUCCESS ; } int dbase_iterate(
@@ -209,7 +210,7 @@/* config.merr_fatal = */ /* Stub */ -return -1 ; +return STATUS_SUCCESS ; } int dbase_list(
@@ -232,5 +233,5 @@ keyset =NULL ; dataset =NULL ; count =NULL ; -return -1 ; +return STATUS_SUCCESS ; }
src/debug.h +10 -0
@@ -0,0 +1,10 @@ +#ifndef _SEPOL_INTERNAL_DEBUG_H_ +#define _SEPOL_INTERNAL_DEBUG_H_ + +#define STATUS_SUCCESS 0 +#define STATUS_ERR -1 +#define STATUS_NODATA 1 + +/* Define debug system in this header */ + +#endif
src/record_file.c +2 -1
@@ -1,8 +1,9 @@ +#include "debug.h" #include "record_file.h" int record_iterate_file (iterate_config_t * config) {/* Stub */ config =NULL ; -return 0 ; +return STATUS_SUCCESS ; }
src/record_file_handlers.c +3 -2
@@ -1,3 +1,4 @@ +#include "debug.h" #include "record_file.h" #include "record_file_handlers.h"
@@ -7,7 +8,7 @@#define RECORD_DEFINED #endif -int record_query (record_t process_rec,record_t unused,void * varg) { +int record_query (record_t process_rec,record_t * unused,void * varg) {/* Stub */ process_rec =NULL ;
@@ -16,7 +17,7 @@return RECORD_HANDLER_SIGEXIT ; } -int record_exists (record_t process_rec,record_t unused,void * varg) { +int record_exists (record_t process_rec,record_t * unused,void * varg) {/* Stub */ process_rec =NULL ;
src/record_file_handlers.h +2 -2
@@ -51,8 +51,8 @@void * fn_arg; } record_iterate_arg_t; -extern int record_query (record_t rec,record_t unused,void * varg); -extern int record_exists (record_t rec,record_t unused,void * varg); +extern int record_query (record_t rec,record_t * unused,void * varg); +extern int record_exists (record_t rec,record_t * unused,void * varg);extern int record_add (record_t rec,record_t * new_rec,void * varg);extern int record_modify (record_t rec,record_t * new_rec,void * varg);extern int record_del (record_t rec,record_t * unused,void * varg);
Quoted 2 lines · Ivan Gyurdiev
The attached patch stubs out most of the record handlers, and has the dbase_* routines fill out parts of the config structure.
Thanks, 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 ] Fix record handlers, add status codes
In reply to Ivan GyurdievQuoted 4 lines · Ivan Gyurdiev
The attached patch applies on top of the previous one, and fixes several bugs. It also adds a header with status codes which I need... the debug system should go into this header IMHO, once we decide what the debug system should be.
Thanks, merged.
What do you view as still undecided for the debug system?
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 ] Fix record handlers, add status codes
Quoted 6 lines
Thanks, merged.
What do you view as still undecided for the debug system?
I need to determine what's necessary for me to introduce error reporting in future semanage code. In particular:
- I need to pass down the semanage handle (which does not exist yet) down for state. That's pending Joshua's patch.
- I need to decide whether to use write_error, or DEBUG, and put the appropriate debug system in debug.h
- If (write_error) -> needs to be modified to support multiple error messages
- If (DEBUG) -> needs to be modified to support state, and provide a buffering callback
- Independently, I still might need to reduce the number and placement of error messages to make the error message more suitable for the end user.
Basically, error messages a constant PITA, that I'd rather ignore for the moment, partly because of the lack of handle object. There's more important things to take care of... such as the justification for adding a database-like engine in the first place. I think this will be easier to justify once I add an avrule record, to allow policy rules to be parsed and loaded into policy (only avtab rules, no booleans, and no m4). This will also need some code moved (at least duplicated for now... ) from checkpolicy into sepol. The idea of this engine thing is to allow handling of any text file that looks like a collection of records in a consistent manner, with 90% of all code being shared (everything minus the parsing of a single record). It should be trivial to add new structured files, and write arbitrary handlers in C, otherwise the objective is not accomplished.
--
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 ] Fix record handlers, add status codes
Quoted 5 lines · Ivan Gyurdiev
I need to determine what's necessary for me to introduce error reporting in future semanage code. In particular:
- I need to pass down the semanage handle (which does not exist yet) down for state. That's pending Joshua's patch.
Or you could just drop in a stub for now, and he can fill it in later.
Quoted 2 lines
- I need to decide whether to use
write_error, or DEBUG, and put the appropriate debug system indebug.h
The earlier thread seemed to be going toward the latter, with the modifications you mentioned below.
Quoted 2 lines
- If (DEBUG) -> needs to be modified to support state, and provide a buffering callback
Right, caller-supplied state object and level/priority value. Callback can implement buffering as desired.
Quoted 2 lines
- Independently, I still might need to reduce the number and placement of error messages to make the error message more suitable for the end user.
Right, try to get to the point where the call chain DEBUG calls can be purely debug level/priority info and can be discarded for error reporting to the user/client.
Quoted 13 lines
Basically, error messages a constant PITA, that I'd rather ignore for the moment, partly because of the lack of handle object. There's more important things to take care of... such as the justification for adding a database-like engine in the first place. I think this will be easier to justify once I add an avrule record, to allow policy rules to be parsed and loaded into policy (only avtab rules, no booleans, and no m4). This will also need some code moved (at least duplicated for now... ) from checkpolicy into sepol. The idea of this engine thing is to allow handling of any text file that looks like a collection of records in a consistent manner, with 90% of all code being shared (everything minus the parsing of a single record). It should be trivial to add new structured files, and write arbitrary handlers in C, otherwise the objective is not accomplished.
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.