Debugging system
PATCH RESEND 1/1 Debugging system
Okay, here's version 2. I'm not sure if I like this very much, but I've done all the changes you requested:
- variadic list passed to callback **
- message structure dropped
- message structure fields embedded in the handle (ugh.. I had to do this, because of circular dependencies)
- handle passed to callback
- msg_write is a macro
- also fixed extra newline
- also added newlines to every single Tresys error message
- libsemanage.map is modified this time
Because of (**) I now can't submit the sepol patch, because my compat handler is broken .... Do we need compatibility with sepol_enable/disable_debug ? Have we released an official libsepol with those functions? I know Dan's been building that library, but I'm pretty sure no one is using those functions yet, and that's rawhide. It would be nice if those could be removed, so I don't have to support two callback systems simultaneously.
include/semanage/debug.h +58 -0
@@ -0,0 +1,58 @@ +/* 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 _SEMANAGE_DEBUG_H_ +#define _SEMANAGE_DEBUG_H_ + +#include <semanage/handle.h> + +#define SEMANAGE_MSG_ERR 1 +#define SEMANAGE_MSG_WARN 2 +#define SEMANAGE_MSG_INFO 3 + +extern int semanage_msg_get_level ( +semanage_handle_t * handle); + +extern const char *semanage_msg_get_channel ( +semanage_handle_t * handle); + +extern const char *semanage_msg_get_fname ( +semanage_handle_t * handle); + +/* Set the messaging callback. +* By the default, the callback will print +* the message on standard output, in a +* particular format. Passing NULL here +* indicates that messaging should be suppressed */ +extern void semanage_msg_set_callback ( +semanage_handle_t * handle, +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif +void (*msg_callback) ( +void * varg, +semanage_handle_t * handle, +const char * fmt, + ...), +void * msg_callback_arg); + +#endif
include/semanage/handle.h +0 -22
@@ -51,14 +51,6 @@* error. */ int semanage_disconnect (semanage_handle_t *); -/* Return a string describing the most recently encountered error -* associated with a semanage_handle_t. The returned string must not -* be modified by the caller. Be aware that this string is not -* persistent; future calls to this library may alter the buffer -* contents, so make a copy of it if necessary. -*/ -const char *semanage_strerror (semanage_handle_t *); -/* Attempt to obtain a transaction lock on the manager. If another * process has the lock then this function may block, depending upon * the timeout value in the handle.
@@ -75,18 +67,4 @@*/ int semanage_commit (semanage_handle_t *); -/* META NOTES -* -* All of the other interfaces expect a semanage_handle as its first -* parameter. If an error occurs then the function returns a negative -* value. Call semanage_strerror() to retrieve a string that fully -* describes the error. -* -* For all functions a non-negative number indicates success. For query -* fucntions a >=0 returned value is the "policy sequence number". This -* number keeps tracks of policy revisions and is used to detect if -* one semanage client has committed policy changes while another is -* still connected. -*/ -#endif
include/semanage/semanage.h +1 -0
@@ -23,6 +23,7 @@#include <semanage/handle.h> #include <semanage/modules.h> +#include <semanage/debug.h> /* * Explicit libsemanage initialization.
src/database_file.c +2 -1
@@ -170,6 +170,7 @@ } dbase->cached =0 ; + dbase->modified =0 ; handle =NULL ; }
@@ -199,6 +200,7 @@ goto err; } + dbase->modified =0 ;fclose (str);free (fname);return STATUS_SUCCESS ;
@@ -237,7 +239,6 @@dbase_file_drop_cache (handle, dbase); } -static int enter_rw (semanage_handle_t * handle,dbase_file_t * dbase) {
src/debug.c +59 -7
86 lines not on this page · raw message
src/debug.h +35 -5
@@ -20,20 +20,50 @@* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _SEPOL_INTERNAL_DEBUG_H_ -#define _SEPOL_INTERNAL_DEBUG_H_ +#ifndef _SEMANAGE_INTERNAL_DEBUG_H_ +#define _SEMANAGE_INTERNAL_DEBUG_H_ +#include <stdio.h> +#include <semanage/debug.h> #include "handle.h" #define STATUS_SUCCESS 0#define STATUS_ERR -1#define STATUS_NODATA 1 -/* FIXME: redesign with level argument ? */ +#define msg_write (handle_arg, level_arg, \ + channel_arg, func_arg, ...) { \ + \ + if (handle_arg->msg_callback) { \ + handle_arg->msg_fname = func_arg; \ + handle_arg->msg_channel = channel_arg; \ + handle_arg->msg_level = level_arg; \ + \ + handle_arg->msg_callback( \ + handle_arg->msg_callback_arg, \ + handle_arg, __VA_ARGS__); \ + } \ +} + +#define ERR (handle, ...) \ + msg_write(handle, SEMANAGE_MSG_ERR, "libsemanage", \ + __FUNCTION__, __VA_ARGS__) + +#define INFO (handle, ...) \ + msg_write(handle, SEMANAGE_MSG_INFO, "libsemanage", \ + __FUNCTION__, __VA_ARGS__) + +#define WARN (handle, ...) \ + msg_write(handle, SEMANAGE_MSG_WARN, "libsemanage", \ + __FUNCTION__, __VA_ARGS__)#ifdef __GNUC__ -__attribute__ ((format (printf, 2, 3))) +__attribute__ ((format (printf, 3, 4)))#endif -extern void semanage_write_error (semanage_handle_t *sh,char *fmt, ...); +extern void semanage_msg_default_handler ( +void * varg, +semanage_handle_t * handle, +const char * fmt, + ...);#endif
src/direct_api.c +37 -25
186 lines not on this page · raw message
src/handle.c +9 -12
@@ -41,11 +41,11 @@#define SEMANAGE_COMMIT_READ_WAIT 5semanage_handle_t *semanage_handle_create (void ) { -semanage_handle_t *sh; -const char *conf_name; +semanage_handle_t *sh =NULL ; +const char *conf_name =NULL ;/* Allocate handle */ -if ((sh =calloc (1 ,sizeof (*sh))) ==NULL ) +if ((sh =calloc (1 ,sizeof (semanage_handle_t))) ==NULL ) goto omem;/* Policy root */
@@ -66,6 +66,10 @@/* Set timeout: some default value for now, later use config */ sh->timeout =SEMANAGE_COMMIT_READ_WAIT ; +/* Set callback */ + sh->msg_callback = semanage_msg_default_handler; + sh->msg_callback_arg =NULL ; +/* Configure object databases * Hardcore DATA FILE backend for now */ if (user_file_dbase_init (&sh->dbase[DBASE_USERS ]) <0 )
@@ -130,19 +134,12 @@free (sh); } -const char *semanage_strerror (semanage_handle_t *sh) { -if (sh ==NULL ) { -return "Could not parse semange.conf or out of memory." ; - } -return sh->err_buf; -} -/********************* public transaction functions *********************/ int semanage_begin_transaction (semanage_handle_t *sh) {assert (sh !=NULL && sh->funcs !=NULL && sh->funcs->begin_trans !=NULL );if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected.\n" );return -1 ; }if (sh->is_in_transaction) {
@@ -160,7 +157,7 @@int retval;assert (sh !=NULL && sh->funcs !=NULL && sh->funcs->commit !=NULL );if (!sh->is_in_transaction) { -semanage_write_error (sh,"Will not commit because caller does not have a tranaction lock yet." ); +ERR (sh,"Will not commit because caller does not have a tranaction lock yet.\n" );return -1 ; } retval = sh->funcs->commit (sh);
src/handle.h +15 -5
@@ -27,17 +27,27 @@#include <semanage/handle.h> #include "modules.h" #include "semanage_conf.h" -#include "policy_connection.h" +#include "policy.h" #include "database.h" struct semanage_handle {int con_id;/* Connection ID */ int policy_serial;/* Policy serial number at connect time */ -/* Error management */ -/* FIXME: re-design error system using callbacks (?) */ -#define SEMANAGE_ERRBUFSZ 1024 -char err_buf[SEMANAGE_ERRBUFSZ ]; +/* Error handling */ +int msg_level; +const char * msg_channel; +const char * msg_fname; +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif + void (*msg_callback) ( + void* varg, + semanage_handle_t* handle, + const char* fmt, + ...); + void* msg_callback_arg; + /* ================ */ /* one of these connections will actually be used while * working with the module store -- the particular one if
src/libsemanage.map +1 -1
@@ -1,7 +1,7 @@ LIBSEMANAGE_1.0 { global: semanage_handle_create; semanage_handle_destroy; semanage_connect; semanage_disconnect; - semanage_strerror; + semanage_msg_*; semanage_begin_transaction; semanage_commit; semanage_module_install; semanage_module_upgrade; semanage_module_install_base; semanage_module_remove;
src/modules.c +10 -10
@@ -37,11 +37,11 @@int semanage_module_install (semanage_handle_t *sh,char *module_data,size_t data_len) {if (sh->funcs->install ==NULL ) { -semanage_write_error (sh,"No install function defined for this connection type." ); +ERR (sh,"No install function defined for this connection type.\n" );return -1 ; }else if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected.\n" );return -1 ; }else if (!sh->is_in_transaction) {
@@ -55,11 +55,11 @@int semanage_module_upgrade (semanage_handle_t *sh,char *module_data,size_t data_len) {if (sh->funcs->upgrade ==NULL ) { -semanage_write_error (sh,"No upgrade function defined for this connection type." ); +ERR (sh,"No upgrade function defined for this connection type.\n" );return -1 ; }else if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected.\n" );return -1 ; }else if (!sh->is_in_transaction) {
@@ -73,11 +73,11 @@int semanage_module_install_base (semanage_handle_t *sh,char *module_data,size_t data_len) {if (sh->funcs->install_base ==NULL ) { -semanage_write_error (sh,"No install base function defined for this connection type." ); +ERR (sh,"No install base function defined for this connection type.\n" );return -1 ; }else if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected.\n" );return -1 ; }else if (!sh->is_in_transaction) {
@@ -91,11 +91,11 @@int semanage_module_remove (semanage_handle_t *sh,char *module_name) {if (sh->funcs->remove ==NULL ) { -semanage_write_error (sh,"No remove function defined for this connection type." ); +ERR (sh,"No remove function defined for this connection type.\n" );return -1 ; }else if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected.\n" );return -1 ; }else if (!sh->is_in_transaction) {
@@ -109,11 +109,11 @@int semanage_module_list (semanage_handle_t *sh,semanage_module_info_t **modinfo,int *num_modules) {if (sh->funcs->list ==NULL ) { -semanage_write_error (sh,"No list function defined for this connection type." ); +ERR (sh,"No list function defined for this connection type.\n" );return -1 ; }else if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected.\n" );return -1 ; }return sh->funcs->list (sh, modinfo, num_modules);
src/modules.h +0 -5
@@ -23,11 +23,6 @@#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;
src/policy_connection.h +0 -55
55 lines not on this page · raw message
src/policy.h +77 -0
77 lines not on this page · raw message
src/semanage_store.c +71 -50
386 lines not on this page · raw message
Quoted 2 lines · Ivan Gyurdiev
Okay, here's version 2. I'm not sure if I like this very much, but I've done all the changes you requested:
What don't you like? Or what did you like better about the prior version?
Quoted 9 lines
- variadic list passed to callback **
- message structure dropped
- message structure fields embedded in the handle (ugh.. I had to do this, because of circular dependencies)
- handle passed to callback
-msg_writeis a macro
- also fixed extra newline
- also added newlines to every single Tresys error message
Why require the newline in the individual error messages?
Quoted 9 lines
- libsemanage.map is modified this time
Because of (**) I now can't submit the sepol patch, because my compat handler is broken .... Do we need compatibility with sepol_enable/disable_debug ? Have we released an official libsepol with those functions? I know Dan's been building that library, but I'm pretty sure no one is using those functions yet, and that's rawhide. It would be nice if those could be removed, so I don't have to support two callback systems simultaneously.
If there are no users, it can still change, and I don't see any.
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 8 lines · Stephen Smalley
Quoted 2 lines · Ivan Gyurdiev
Okay, here's version 2. I'm not sure if I like this very much, but I've done all the changes you requested:
What don't you like? Or what did you like better about the prior version?
It looks more complicated now.... and more disorganized. I guess it's fine, as long as it's easy to use.
Quoted 10 lines
Quoted 9 lines
- variadic list passed to callback **
- message structure dropped
- message structure fields embedded in the handle (ugh.. I had to do this, because of circular dependencies)
- handle passed to callback
-msg_writeis a macro
- also fixed extra newline
- also added newlines to every single Tresys error message
Quoted 2 lines
Why require the newline in the individual error messages?
The newline is part of the message - it's not a good idea to push it into the messaging system. Eventually we will run into a case where we don't want a newline printed, and the messaging system wouldn't be able to handle that....happens every time I try to do this.
Quoted 7 lines
Quoted 4 lines
- libsemanage.map is modified this time
Because of (**) I now can't submit the sepol patch, because my compat handler is broken .... Do we need compatibility with sepol_enable/disable_debug ? Have we released an official libsepol with those functions? I know Dan's been building that library, but I'm pretty sure no one is using those functions yet, and that's rawhide. It would be nice if those could be removed, so I don't have to support two callback systems simultaneously.
If there are no users, it can still change, and I don't see any.
Okay, in that case I will remove those functions...
--
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 2 lines · Ivan Gyurdiev
It looks more complicated now.... and more disorganized. I guess it's fine, as long as it's easy to use.
Ok, from my POV, it is nicer, because:
a) No extraneous abstractions introduced, just using the handle as designed,
b) Direct pass through to the callback with no internal buffering and no new failure cases (memory allocation) introduced.
Quoted 4 lines
The newline is part of the message - it's not a good idea to push it into the messaging system. Eventually we will run into a case where we don't want a newline printed, and the messaging system wouldn't be able to handle that....happens every time I try to do this.
Hmm...I was thinking that the callback could add it as desired. Each invocation of the callback constitutes a separate message, and the callback is free to introduce message separators as desired.
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 5 lines
Hmm...I was thinking that the callback could add it as desired. Each invocation of the callback constitutes a separate message, and the callback is free to introduce message separators as desired
I guess we are already chopping up the info stream into messages, so pushing the separator into the messaging system might make sense... argh... I guess I'll redo the patch again, and next time I'll package up sepol as well, and drop enable_debug/disable_debug.
--
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: [ SEPOL ] [ SEMANAGE ] Debug v3, some database things
...resending patch again...
Everything from before, plus:
- newline removed from all ERR calls (justification is that info stream is already logically chopped into messages) - callback can write separator of choice.
- newline added to default semanage handler
- newline _not_ added to sepol handler, until DEBUG is eradicated
- sepol_enable_debug and sepol_disable debug dropped, and removed from the interface. sepol_debug is kept, since it has been around for a while during official releases, and has users (plus it's trivial to implement using new system)
- added my policy_components.c file - kind of work in progress, but it might give you an idea of what I plan to do. Those NULL arguments should probably be calling the functions in [users/ports]_policy.c, that are currently if-deff'ed out (or at least calling handlers that call those functions). Things that are in this file, should, ideally, be backend independent, so I don't want to see them being copied in 5 places depending on whether we use files, policy servers, LDAP, or whatever - that's why we use interfaces, and not implementations. You can also see I've put modules in there (commented out), since I hope I can make the list of modules appear as a database someday.... - added some database fixes for modified parameter
- added a couple of functions to attach/detach direct database from a policydb object for sharing (those are specific to direct backend, and not added to the database interface).
- draw in all sepol headers into sepol.h
libsemanage/include/semanage/debug.h +58 -0
@@ -0,0 +1,58 @@ +/* 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 _SEMANAGE_DEBUG_H_ +#define _SEMANAGE_DEBUG_H_ + +#include <semanage/handle.h> + +#define SEMANAGE_MSG_ERR 1 +#define SEMANAGE_MSG_WARN 2 +#define SEMANAGE_MSG_INFO 3 + +extern int semanage_msg_get_level ( +semanage_handle_t * handle); + +extern const char *semanage_msg_get_channel ( +semanage_handle_t * handle); + +extern const char *semanage_msg_get_fname ( +semanage_handle_t * handle); + +/* Set the messaging callback. +* By the default, the callback will print +* the message on standard output, in a +* particular format. Passing NULL here +* indicates that messaging should be suppressed */ +extern void semanage_msg_set_callback ( +semanage_handle_t * handle, +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif +void (*msg_callback) ( +void * varg, +semanage_handle_t * handle, +const char * fmt, + ...), +void * msg_callback_arg); + +#endif
libsemanage/include/semanage/handle.h +0 -22
@@ -51,14 +51,6 @@* error. */ int semanage_disconnect (semanage_handle_t *); -/* Return a string describing the most recently encountered error -* associated with a semanage_handle_t. The returned string must not -* be modified by the caller. Be aware that this string is not -* persistent; future calls to this library may alter the buffer -* contents, so make a copy of it if necessary. -*/ -const char *semanage_strerror (semanage_handle_t *); -/* Attempt to obtain a transaction lock on the manager. If another * process has the lock then this function may block, depending upon * the timeout value in the handle.
@@ -75,18 +67,4 @@*/ int semanage_commit (semanage_handle_t *); -/* META NOTES -* -* All of the other interfaces expect a semanage_handle as its first -* parameter. If an error occurs then the function returns a negative -* value. Call semanage_strerror() to retrieve a string that fully -* describes the error. -* -* For all functions a non-negative number indicates success. For query -* fucntions a >=0 returned value is the "policy sequence number". This -* number keeps tracks of policy revisions and is used to detect if -* one semanage client has committed policy changes while another is -* still connected. -*/ -#endif
libsemanage/include/semanage/semanage.h +1 -0
@@ -23,6 +23,7 @@#include <semanage/handle.h> #include <semanage/modules.h> +#include <semanage/debug.h> /* * Explicit libsemanage initialization.
libsemanage/src/database_direct.c +29 -3
@@ -3,6 +3,7 @@#define DBASE_DEFINED #include <stdlib.h> +#include <string.h> #include <stdio.h> #include <fcntl.h> #include <sys/types.h>
@@ -31,6 +32,7 @@sepol_policydb_t * policy;int cached;int modified; +int attached; }; static int construct_filename(
@@ -66,7 +68,7 @@char * fname =NULL ;/* Already cached */ -if (dbase->cached) +if (dbase->cached || dbase->attached)return STATUS_SUCCESS ;if (construct_filename (handle, dbase, &fname) <0 )
@@ -128,11 +130,10 @@if (!dbase->modified || !dbase->cached)return STATUS_SUCCESS ; -/* FIXME: sepol_policydb_to_image always writes a KERN policy */ + dbase->modified =0 ;/* Stub */ handle =NULL ; - dbase =NULL ;return STATUS_SUCCESS ; }
@@ -144,6 +145,7 @@if (dbase->cached) {sepol_policydb_free (dbase->policy); dbase->cached =0 ; + dbase->modified =0 ; } handle =NULL ;
@@ -219,6 +221,7 @@ tmp_dbase->policy =NULL ; tmp_dbase->cached =0 ; tmp_dbase->modified =0 ; + tmp_dbase->attached =0 ; *dbase = tmp_dbase;return STATUS_SUCCESS ;
@@ -239,6 +242,29 @@free (dbase); } +/* Attach to a shared policydb. +* This implies drop_cache(), +* and prevents flush() and drop_cache() +* until detached. */ +void dbase_direct_attach ( +semanage_handle_t * handle, +dbase_direct_t * dbase, +sepol_policydb_t * policydb) { + + dbase->attached =1 ; +dbase_direct_drop_cache (handle, dbase); + dbase->policy = policydb; +} + +/* Detach from a shared policdb. +* This implies drop_cache. */ +void dbase_direct_detach ( +semanage_handle_t * handle, +dbase_direct_t * dbase) { + + dbase->attached =0 ; +} + static int dbase_direct_add ( semanage_handle_t* handle, dbase_direct_t* dbase,
libsemanage/src/database_direct.h +16 -1
@@ -12,7 +12,7 @@ typedef struct record_direct_table { /* Add record into the policy database */ - int (*add) (sepol_policydb_t* policy, record_t* record); + int (*add) (sepol_policydb_t* policydb, record_t* record); /* Modify record into the policy database */ int (*modify) (sepol_policydb_t* policydb, record_t* record);
@@ -32,6 +32,21 @@ record_direct_table_t* rptable, dbase_direct_t** dbase); +/* Attach to a shared policydb. +* This implies drop_cache(). +* and prevents flush() and drop_cache() +* until detached. */ +extern void dbase_direct_attach ( +semanage_handle_t * handle, +dbase_direct_t * dbase, +sepol_policydb_t * policydb); + +/* Detach from a shared policdb. +* This implies drop_cache. */ +extern void dbase_direct_detach ( +semanage_handle_t * handle, +dbase_direct_t * dbase); +/* Release allocated resources */ extern void dbase_direct_release( semanage_handle_t* handle,
libsemanage/src/database_file.c +2 -1
@@ -170,6 +170,7 @@ } dbase->cached =0 ; + dbase->modified =0 ; handle =NULL ; }
@@ -199,6 +200,7 @@ goto err; } + dbase->modified =0 ;fclose (str);free (fname);return STATUS_SUCCESS ;
@@ -237,7 +239,6 @@dbase_file_drop_cache (handle, dbase); } -static int enter_rw (semanage_handle_t * handle,dbase_file_t * dbase) {
libsemanage/src/debug.c +61 -7
88 lines not on this page · raw message
libsemanage/src/debug.h +35 -5
@@ -20,20 +20,50 @@* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _SEPOL_INTERNAL_DEBUG_H_ -#define _SEPOL_INTERNAL_DEBUG_H_ +#ifndef _SEMANAGE_INTERNAL_DEBUG_H_ +#define _SEMANAGE_INTERNAL_DEBUG_H_ +#include <stdio.h> +#include <semanage/debug.h> #include "handle.h" #define STATUS_SUCCESS 0#define STATUS_ERR -1#define STATUS_NODATA 1 -/* FIXME: redesign with level argument ? */ +#define msg_write (handle_arg, level_arg, \ + channel_arg, func_arg, ...) { \ + \ + if (handle_arg->msg_callback) { \ + handle_arg->msg_fname = func_arg; \ + handle_arg->msg_channel = channel_arg; \ + handle_arg->msg_level = level_arg; \ + \ + handle_arg->msg_callback( \ + handle_arg->msg_callback_arg, \ + handle_arg, __VA_ARGS__); \ + } \ +} + +#define ERR (handle, ...) \ + msg_write(handle, SEMANAGE_MSG_ERR, "libsemanage", \ + __FUNCTION__, __VA_ARGS__) + +#define INFO (handle, ...) \ + msg_write(handle, SEMANAGE_MSG_INFO, "libsemanage", \ + __FUNCTION__, __VA_ARGS__) + +#define WARN (handle, ...) \ + msg_write(handle, SEMANAGE_MSG_WARN, "libsemanage", \ + __FUNCTION__, __VA_ARGS__)#ifdef __GNUC__ -__attribute__ ((format (printf, 2, 3))) +__attribute__ ((format (printf, 3, 4)))#endif -extern void semanage_write_error (semanage_handle_t *sh,char *fmt, ...); +extern void semanage_msg_default_handler ( +void * varg, +semanage_handle_t * handle, +const char * fmt, + ...);#endif
libsemanage/src/direct_api.c +37 -27
194 lines not on this page · raw message
libsemanage/src/handle.c +9 -12
@@ -41,11 +41,11 @@#define SEMANAGE_COMMIT_READ_WAIT 5semanage_handle_t *semanage_handle_create (void ) { -semanage_handle_t *sh; -const char *conf_name; +semanage_handle_t *sh =NULL ; +const char *conf_name =NULL ;/* Allocate handle */ -if ((sh =calloc (1 ,sizeof (*sh))) ==NULL ) +if ((sh =calloc (1 ,sizeof (semanage_handle_t))) ==NULL ) goto omem;/* Policy root */
@@ -66,6 +66,10 @@/* Set timeout: some default value for now, later use config */ sh->timeout =SEMANAGE_COMMIT_READ_WAIT ; +/* Set callback */ + sh->msg_callback = semanage_msg_default_handler; + sh->msg_callback_arg =NULL ; +/* Configure object databases * Hardcore DATA FILE backend for now */ if (user_file_dbase_init (&sh->dbase[DBASE_USERS ]) <0 )
@@ -130,19 +134,12 @@free (sh); } -const char *semanage_strerror (semanage_handle_t *sh) { -if (sh ==NULL ) { -return "Could not parse semange.conf or out of memory." ; - } -return sh->err_buf; -} -/********************* public transaction functions *********************/ int semanage_begin_transaction (semanage_handle_t *sh) {assert (sh !=NULL && sh->funcs !=NULL && sh->funcs->begin_trans !=NULL );if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected." );return -1 ; }if (sh->is_in_transaction) {
@@ -160,7 +157,7 @@int retval;assert (sh !=NULL && sh->funcs !=NULL && sh->funcs->commit !=NULL );if (!sh->is_in_transaction) { -semanage_write_error (sh,"Will not commit because caller does not have a tranaction lock yet." ); +ERR (sh,"Will not commit because caller does not have a tranaction lock yet." );return -1 ; } retval = sh->funcs->commit (sh);
libsemanage/src/handle.h +15 -5
@@ -27,17 +27,27 @@#include <semanage/handle.h> #include "modules.h" #include "semanage_conf.h" -#include "policy_connection.h" +#include "policy.h" #include "database.h" struct semanage_handle {int con_id;/* Connection ID */ int policy_serial;/* Policy serial number at connect time */ -/* Error management */ -/* FIXME: re-design error system using callbacks (?) */ -#define SEMANAGE_ERRBUFSZ 1024 -char err_buf[SEMANAGE_ERRBUFSZ ]; +/* Error handling */ +int msg_level; +const char * msg_channel; +const char * msg_fname; +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif + void (*msg_callback) ( + void* varg, + semanage_handle_t* handle, + const char* fmt, + ...); + void* msg_callback_arg; + /* ================ */ /* one of these connections will actually be used while * working with the module store -- the particular one if
libsemanage/src/libsemanage.map +1 -1
@@ -1,7 +1,7 @@ LIBSEMANAGE_1.0 { global: semanage_handle_create; semanage_handle_destroy; semanage_connect; semanage_disconnect; - semanage_strerror; + semanage_msg_*; semanage_begin_transaction; semanage_commit; semanage_module_install; semanage_module_upgrade; semanage_module_install_base; semanage_module_remove;
libsemanage/src/modules.c +10 -10
@@ -37,11 +37,11 @@int semanage_module_install (semanage_handle_t *sh,char *module_data,size_t data_len) {if (sh->funcs->install ==NULL ) { -semanage_write_error (sh,"No install function defined for this connection type." ); +ERR (sh,"No install function defined for this connection type." );return -1 ; }else if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected." );return -1 ; }else if (!sh->is_in_transaction) {
@@ -55,11 +55,11 @@int semanage_module_upgrade (semanage_handle_t *sh,char *module_data,size_t data_len) {if (sh->funcs->upgrade ==NULL ) { -semanage_write_error (sh,"No upgrade function defined for this connection type." ); +ERR (sh,"No upgrade function defined for this connection type." );return -1 ; }else if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected." );return -1 ; }else if (!sh->is_in_transaction) {
@@ -73,11 +73,11 @@int semanage_module_install_base (semanage_handle_t *sh,char *module_data,size_t data_len) {if (sh->funcs->install_base ==NULL ) { -semanage_write_error (sh,"No install base function defined for this connection type." ); +ERR (sh,"No install base function defined for this connection type." );return -1 ; }else if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected." );return -1 ; }else if (!sh->is_in_transaction) {
@@ -91,11 +91,11 @@int semanage_module_remove (semanage_handle_t *sh,char *module_name) {if (sh->funcs->remove ==NULL ) { -semanage_write_error (sh,"No remove function defined for this connection type." ); +ERR (sh,"No remove function defined for this connection type." );return -1 ; }else if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected." );return -1 ; }else if (!sh->is_in_transaction) {
@@ -109,11 +109,11 @@int semanage_module_list (semanage_handle_t *sh,semanage_module_info_t **modinfo,int *num_modules) {if (sh->funcs->list ==NULL ) { -semanage_write_error (sh,"No list function defined for this connection type." ); +ERR (sh,"No list function defined for this connection type." );return -1 ; }else if (!sh->is_connected) { -semanage_write_error (sh,"Not connected." ); +ERR (sh,"Not connected." );return -1 ; }return sh->funcs->list (sh, modinfo, num_modules);
libsemanage/src/modules.h +0 -5
@@ -23,11 +23,6 @@#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;
libsemanage/src/policy_components.c +86 -0
86 lines not on this page · raw message
libsemanage/src/policy_connection.h +0 -55
55 lines not on this page · raw message
libsemanage/src/policy.h +75 -0
75 lines not on this page · raw message
libsemanage/src/semanage_store.c +71 -50
386 lines not on this page · raw message
libsepol/include/sepol/debug.h +34 -4
@@ -1,9 +1,39 @@#ifndef _SEPOL_DEBUG_H_#define _SEPOL_DEBUG_H_ -extern void sepol_enable_debug ( -void (*fn)(const char * fname,const char *fmt, ...)); +#include <sepol/handle.h> -extern void sepol_disable_debug (); +/* Deprecated */ +extern void sepol_debug (int on); +/* End deprecated */ -#endif /* _SEPOL_DEBUG_H_ */ +#define SEPOL_MSG_ERR 1 +#define SEPOL_MSG_WARN 2 +#define SEPOL_MSG_INFO 3 + +extern int sepol_msg_get_level ( +sepol_handle_t * handle); + +extern const char *sepol_msg_get_channel ( +sepol_handle_t * handle); + +extern const char *sepol_msg_get_fname ( +sepol_handle_t * handle); + +/* Set the messaging callback. +* By the default, the callback will print +* the message on standard output, in a +* particular format. Passing NULL here +* indicates that messaging should be suppressed */ +extern void sepol_msg_set_callback ( +sepol_handle_t * handle, +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif +void (*msg_callback) ( +void * varg, +sepol_handle_t * handle, +const char * fmt, + ...), +void * msg_callback_arg); +#endif
libsepol/include/sepol/handle.h +13 -0
@@ -0,0 +1,13 @@ +#ifndef _SEPOL_HANDLE_H_ +#define _SEPOL_HANDLE_H_ + +struct sepol_handle ; +typedef struct sepol_handle sepol_handle_t ; + +/* Create and return a sepol handle. */ +sepol_handle_t *sepol_handle_create (void ); + +/* Destroy a sepol handle. */ +void sepol_handle_destroy (sepol_handle_t *); + +#endif
libsepol/include/sepol/sepol.h +15 -2
@@ -4,6 +4,21 @@#include <stddef.h> #include <stdio.h> +#include <sepol/user_record.h> +#include <sepol/context_record.h> +#include <sepol/iface_record.h> +#include <sepol/port_record.h> +#include <sepol/boolean_record.h> + +#include <sepol/booleans.h> +#include <sepol/interfaces.h> +#include <sepol/ports.h> +#include <sepol/users.h> +#include <sepol/handle.h> +#include <sepol/debug.h> +#include <sepol/policydb.h> +#include <sepol/module.h> +/* Given an existing binary policy (starting at 'data', with length 'len') and a boolean configuration file named by 'boolpath', rewrite the binary policy for the boolean settings in the boolean configuration file.
@@ -37,6 +52,4 @@/* Check context validity against currently set binary policy. */ extern int sepol_check_context (char *context); -/* Turn on or off sepol error messages. */ -extern void sepol_debug (int on);#endif
libsepol/src/context.c +4 -2
@@ -191,14 +191,16 @@/* Validity check */ if (!sepol_ctx_struct_is_valid (policydb, scontext)) { -if (mls) +if (mls) {DEBUG (__FUNCTION__,"invalid security context: %s:%s:%s:%s\n" , user, role, type, mls); -else + } +else {DEBUG (__FUNCTION__,"invalid security context: %s:%s:%s\n" , user, role, type); + } goto err_destroy; }
libsepol/src/debug.c +69 -34
119 lines not on this page · raw message
libsepol/src/debug.h +44 -6
61 lines not on this page · raw message
libsepol/src/handle.c +21 -0
@@ -0,0 +1,21 @@ +#include <stdlib.h> +#include "handle.h" +#include "debug.h" + +sepol_handle_t *sepol_handle_create (void ) { + +sepol_handle_t *sh =malloc (sizeof (sepol_handle_t)); +if (sh ==NULL ) +return NULL ; + +/* Set callback */ + sh->msg_callback = sepol_msg_default_handler; + sh->msg_callback_arg =NULL ; + +return sh; +} + +void sepol_handle_destroy (sepol_handle_t *sh) { +free (sh); +} +
libsepol/src/handle.h +22 -0
@@ -0,0 +1,22 @@ +#ifndef _SEPOL_INTERNAL_HANDLE_H_ +#define _SEPOL_INTERNAL_HANDLE_H_ + +#include <sepol/handle.h> + +struct sepol_handle { +/* Error handling */ +int msg_level; +const char * msg_channel; +const char * msg_fname; +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif +void (*msg_callback) ( +void * varg, +sepol_handle_t * handle, +const char * fmt, + ...); +void * msg_callback_arg; +}; + +#endif
libsepol/src/libsepol.map +2 -1
@@ -14,8 +14,9 @@ sepol_module_package_read; sepol_module_package_info; sepol_module_package_write; sepol_module_package_create_file; sepol_link_modules; sepol_expand_module; - sepol_bool*; sepol_context*; sepol_enable_debug; sepol_disable_debug; + sepol_bool*; sepol_context*; sepol_iface*; sepol_port*; sepol_user*; sepol_clear_unused_users; sepol_role_is_valid; sepol_set_delusers; + sepol_msg_*; sepol_handle_*; local: *; };
Re: [ SEPOL ] [ SEMANAGE ] Debug v3, some database things
Bugfix:
Can you please add ( ) around every dereference of handle_arg in msg_write (for both semanage and sepol) I can send a followup patch if you prefer. Macros are evil...
Warning:
The following code is no longer valid - this is now a syntax error. if (blah) DEBUG(a); else ..
--
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: [ SEPOL ] [ SEMANAGE ] Debug v3, some database things
Quoted 8 lines · Ivan Gyurdiev
Bugfix:
Can you please add ( ) around every dereference ofhandle_arginmsg_write(for both semanage and sepol)
I can send a followup patch if you prefer. Macros are evil...Warning:
The following code is no longer valid - this is now a syntax error. if (blah) DEBUG(a); else ..
Wrap the definition with
do {
} while (0)
and you'll be fine.
That's a widely used trick in the kernel.
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: [ SEPOL ] [ SEMANAGE ] Debug v3, some database things
Quoted 9 lines
Wrap the definition with do {
} while (0)
and you'll be fine.
That's a widely used trick in the kernel.
Allright, attached fix patch applies on top of the other one.
libsemanage/src/database_direct.c +1 -0
@@ -263,6 +263,7 @@ dbase_direct_t* dbase) { dbase->attached =0 ; + handle =NULL ; } static int dbase_direct_add (
libsemanage/src/debug.h +9 -9
@@ -32,18 +32,18 @@#define STATUS_NODATA 1#define msg_write (handle_arg, level_arg, \ - channel_arg, func_arg, ...) { \ + channel_arg, func_arg, ...) do { \ + \ + if ((handle_arg)->msg_callback) { \ + (handle_arg)->msg_fname = func_arg; \ + (handle_arg)->msg_channel = channel_arg; \ + (handle_arg)->msg_level = level_arg; \ \ - if (handle_arg->msg_callback) { \ - handle_arg->msg_fname = func_arg; \ - handle_arg->msg_channel = channel_arg; \ - handle_arg->msg_level = level_arg; \ - \ - handle_arg->msg_callback( \ - handle_arg->msg_callback_arg, \ + (handle_arg)->msg_callback( \ + (handle_arg)->msg_callback_arg, \ handle_arg, __VA_ARGS__); \ } \ -} +} while(0)#define ERR (handle, ...) \ msg_write(handle, SEMANAGE_MSG_ERR, "libsemanage", \
libsepol/src/debug.h +9 -9
@@ -10,18 +10,18 @@#define STATUS_NODATA 1#define msg_write (handle_arg, level_arg, \ - channel_arg, func_arg, ...) { \ + channel_arg, func_arg, ...) do { \ \ - if (handle_arg->msg_callback) { \ - handle_arg->msg_fname = func_arg; \ - handle_arg->msg_channel = channel_arg; \ - handle_arg->msg_level = level_arg; \ + if ((handle_arg)->msg_callback) { \ + (handle_arg)->msg_fname = func_arg; \ + (handle_arg)->msg_channel = channel_arg; \ + (handle_arg)->msg_level = level_arg; \ \ - handle_arg->msg_callback( \ - handle_arg->msg_callback_arg, \ + (handle_arg)->msg_callback( \ + (handle_arg)->msg_callback_arg, \ handle_arg, __VA_ARGS__); \ } \ -} +} while(0)#define ERR (handle, ...) \ msg_write(handle, SEPOL_MSG_ERR, "libsepol", \
@@ -48,7 +48,7 @@extern struct sepol_handle sepol_compat_handle;#define DEBUG (fname, ...) \ - msg_write((&sepol_compat_handle), SEPOL_MSG_ERR, "libsepol", \ + msg_write(&sepol_compat_handle, SEPOL_MSG_ERR, "libsepol", \ fname, __VA_ARGS__)/* End deprecated */
Re: [ SEPOL ] [ SEMANAGE ] Debug v3, some database things
In reply to Ivan GyurdievQuoted 1 line · Ivan Gyurdiev
...resending patch again...
Ok, merged along with fix patch and corresponding update to policycoreutils (semodule) for the removal of semanage_strerror. I left the remaining portion of the meta note comment in handle.h intact, only pruning the part about strerror. There were two rejects against the current tree, but I merged by hand.
Merged as of libsepol 1.9.16, libsemanage 1.3.12, policycoreutils 1.27.8.
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.