summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2005-10-18 03:21:59 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:05:02 -0500
commitafca439d19e3d9e67b127d7060df630e2218bcb2 (patch)
tree91e53687abea4019a542a20d1ec1862f6b447bdc /source3
parent6f72169c7cee4d8334c15e3add711cd1716e618a (diff)
downloadsamba-afca439d19e3d9e67b127d7060df630e2218bcb2.tar.gz
samba-afca439d19e3d9e67b127d7060df630e2218bcb2.tar.bz2
samba-afca439d19e3d9e67b127d7060df630e2218bcb2.zip
r11136: patches from Brian Moran for eventlogadm utility
(This used to be commit 47b626a8f72629fd1bbabf35b68e24d202df2555)
Diffstat (limited to 'source3')
-rw-r--r--source3/registry/reg_eventlog.c29
-rw-r--r--source3/registry/reg_util.c14
-rw-r--r--source3/utils/eventlogadm.c172
3 files changed, 132 insertions, 83 deletions
diff --git a/source3/registry/reg_eventlog.c b/source3/registry/reg_eventlog.c
index bf843e5518..69d8f2f9aa 100644
--- a/source3/registry/reg_eventlog.c
+++ b/source3/registry/reg_eventlog.c
@@ -84,6 +84,7 @@ BOOL eventlog_init_keys( void )
evtlogpath ) );
regdb_fetch_values( evtlogpath, values );
+
if ( !regval_ctr_key_exists( values, "MaxSize" ) ) {
/* assume we have none, add them all */
@@ -153,6 +154,7 @@ BOOL eventlog_init_keys( void )
}
return True;
+
}
/*********************************************************************
@@ -181,7 +183,7 @@ BOOL eventlog_add_source( const char *eventlog, const char *sourcename,
int i;
int numsources;
- for ( i=0; elogs[i]; i++ ) {
+ for ( i = 0; elogs[i]; i++ ) {
if ( strequal( elogs[i], eventlog ) )
break;
}
@@ -207,11 +209,11 @@ BOOL eventlog_add_source( const char *eventlog, const char *sourcename,
regdb_fetch_values( evtlogpath, values );
+
if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
DEBUG( 0, ( "No Sources value for [%s]!\n", eventlog ) );
return False;
}
-
/* perhaps this adding a new string to a multi_sz should be a fn? */
/* check to see if it's there already */
@@ -220,11 +222,8 @@ BOOL eventlog_add_source( const char *eventlog, const char *sourcename,
( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
return False;
}
-
/* convert to a 'regulah' chars to do some comparisons */
- DEBUG( 0, ( "Rval size is %d\n", rval->size ) );
-
already_in = False;
wrklist = NULL;
dump_data( 1, rval->data_p, rval->size );
@@ -232,18 +231,15 @@ BOOL eventlog_add_source( const char *eventlog, const char *sourcename,
regval_convert_multi_sz( ( uint16 * ) rval->data_p, rval->size,
&wrklist ) ) > 0 ) {
- DEBUG( 10, ( "numsources is %d\n", numsources ) );
ii = numsources;
/* see if it's in there already */
wp = wrklist;
+
while ( ii && wp && *wp ) {
- DEBUG( 5,
- ( "Comparing [%s] to [%s]\n", sourcename,
- *wp ) );
if ( strequal( *wp, sourcename ) ) {
DEBUG( 5,
- ( "Source name %s already exists, \n",
- sourcename ) );
+ ( "Source name [%s] already in list for [%s] \n",
+ sourcename, eventlog ) );
already_in = True;
break;
}
@@ -269,26 +265,23 @@ BOOL eventlog_add_source( const char *eventlog, const char *sourcename,
DEBUG( 0, ( "talloc() failed \n" ) );
return False;
}
- DEBUG( 0, ( "Number of sources [%d]\n", numsources ) );
memcpy( wp, wrklist, sizeof( char * ) * numsources );
*( wp + numsources ) = ( char * ) sourcename;
*( wp + numsources + 1 ) = NULL;
mbytes = regval_build_multi_sz( wp, &msz_wp );
- DEBUG( 0, ( "Number of mbytes [%d]\n", mbytes ) );
- dump_data( 1, (char*)msz_wp, mbytes );
+ dump_data( 1, ( char * ) msz_wp, mbytes );
regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
( char * ) msz_wp, mbytes );
regdb_store_values( evtlogpath, values );
TALLOC_FREE( msz_wp );
} else {
- DEBUG( 0,
+ DEBUG( 3,
( "Source name [%s] found in existing list of sources\n",
sourcename ) );
}
TALLOC_FREE( values );
-
- DEBUG( 5,
- ( "Added source to sources string, now adding subkeys\n" ) );
+ if ( wrklist )
+ TALLOC_FREE( wrklist ); /* */
if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
DEBUG( 0, ( "talloc() failure!\n" ) );
diff --git a/source3/registry/reg_util.c b/source3/registry/reg_util.c
index 9fd9dba27d..40b16d0073 100644
--- a/source3/registry/reg_util.c
+++ b/source3/registry/reg_util.c
@@ -128,26 +128,28 @@ char* reg_remaining_path( const char *key )
/**********************************************************************
*********************************************************************/
-int regval_convert_multi_sz( uint16 *multi_string, size_t multi_len, char ***values )
+int regval_convert_multi_sz( uint16 *multi_string, size_t byte_len, char ***values )
{
char **sz;
int i;
int num_strings = 0;
fstring buffer;
uint16 *wp;
+ size_t multi_len = byte_len / 2;
- *values = NULL;
-
if ( !multi_string || !values )
return 0;
+ *values = NULL;
+
/* just count the NULLs */
- for ( i=0; (i<multi_len-1) && !(multi_string[i]==0x0 && multi_string[i+1]==0x0); i+=2 ) {
- if ( multi_string[i] == 0x0 )
+ for ( i=0; (i<multi_len-1) && !(multi_string[i]==0x0 && multi_string[i+1]==0x0); i++ ) {
+ /* peek ahead */
+ if ( multi_string[i+1] == 0x0 )
num_strings++;
}
-
+
if ( num_strings == 0 )
return 0;
diff --git a/source3/utils/eventlogadm.c b/source3/utils/eventlogadm.c
index 172f2b9cd2..e646833617 100644
--- a/source3/utils/eventlogadm.c
+++ b/source3/utils/eventlogadm.c
@@ -1,3 +1,4 @@
+
/*
* Samba Unix/Linux SMB client utility
* Write Eventlog records to a tdb, perform other eventlog related functions
@@ -26,7 +27,6 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_UTIL_EVENTLOG
-Eventlog_entry ee;
extern int optind;
extern char *optarg;
@@ -35,9 +35,12 @@ int opt_debug = 0;
static void usage( char *s )
{
- printf( "\nUsage: %s [-d] [-h] <Eventlog Name>\n", s );
- printf( "\t-d\tturn debug on\n" );
- printf( "\t-h\tdisplay help\n\n" );
+ printf( "\nUsage: %s [OPTION]\n\n", s );
+ printf( " -o write <Eventlog Name> \t\t\t\t\tWrites records to eventlog from STDIN\n" );
+ printf( " -o addsource <EventlogName> <sourcename> <msgfileDLLname> \tAdds the specified source & DLL eventlog registry entry\n" );
+ printf( "\nMiscellaneous options:\n" );
+ printf( " -d\t\t\t\t\t\t\t\tturn debug on\n" );
+ printf( " -h\t\t\t\t\t\t\t\tdisplay help\n\n" );
}
static void display_eventlog_names( void )
@@ -53,73 +56,52 @@ static void display_eventlog_names( void )
}
}
-int main( int argc, char *argv[] )
+int DoAddSourceCommand( int argc, char **argv, BOOL debugflag, char *exename )
{
- FILE *f1;
-
- /* fixed constants are bad bad bad */
- pstring linein;
- BOOL is_eor;
- int pret, opt;
- int rcnum;
- char *argfname, *exename;
- char *tdbname;
-
-
- TDB_CONTEXT *elog_tdb;
-
- opt_debug = 0; /* todo set this from getopts */
-
-
- lp_load( dyn_CONFIGFILE, True, False, False );
-
- exename = argv[0];
-
-#if 1 /* TESTING CODE */
- eventlog_add_source("System","TestSourceX","SomeTestPathX");
-#endif
-
- while ( ( opt = getopt( argc, argv, "dh" ) ) != -1 ) {
- switch ( opt ) {
- case 'h':
- usage( argv[0] );
- display_eventlog_names( );
- exit( 0 );
- break;
- case 'd':
- opt_debug = 1;
- break;
- }
+ if ( argc < 3 ) {
+ printf( "need more arguments:\n" );
+ printf( "-o addsource EventlogName SourceName /path/to/eventlogmsg.dll\n" );
+ return -1;
}
-
- argc -= optind;
- argv += optind;
-
- if ( argc < 1 ) {
- usage( exename );
- exit( 1 );
+ /* must open the registry before we access it */
+ if ( !regdb_init( ) ) {
+ printf( "Can't open the registry.\n" );
+ return -1;
}
+ if ( !eventlog_add_source( argv[0], argv[1], argv[2] ) )
+ return -2;
+ return 0;
+}
+
+int DoWriteCommand( int argc, char **argv, BOOL debugflag, char *exename )
+{
+ FILE *f1;
+ char *argfname;
+ TDB_CONTEXT *elog_tdb;
+ /* fixed constants are bad bad bad */
+ pstring linein;
+ BOOL is_eor;
+ Eventlog_entry ee;
+ int pret, rcnum;
f1 = stdin;
-
if ( !f1 ) {
printf( "Can't open STDIN\n" );
return -1;
}
-
- if ( opt_debug ) {
- printf( "Starting %s for eventlog [%s]\n", exename, argv[0] );
+ if ( debugflag ) {
+ printf( "Starting write for eventlog [%s]\n", argv[0] );
display_eventlog_names( );
}
argfname = argv[0];
- if ( !(elog_tdb = elog_open_tdb( argfname ) ) ) {
- printf( "can't open the eventlog TDB (%s)\n", tdbname );
+ if ( !( elog_tdb = elog_open_tdb( argfname ) ) ) {
+ printf( "can't open the eventlog TDB (%s)\n", argfname );
return -1;
}
@@ -129,27 +111,26 @@ int main( int argc, char *argv[] )
fgets( linein, sizeof( linein ) - 1, f1 );
linein[strlen( linein ) - 1] = 0; /* whack the line delimiter */
- if ( opt_debug )
+ if ( debugflag )
printf( "Read line [%s]\n", linein );
is_eor = False;
+
pret = parse_logentry( ( char * ) &linein, &ee, &is_eor );
+ /* should we do something with the return code? */
if ( is_eor ) {
fixup_eventlog_entry( &ee );
if ( opt_debug )
- printf( "record number [%d], tg [%d] , tw [%d]\n",
- ee.record.record_number,
- ee.record.time_generated,
- ee.record.time_written );
+ printf( "record number [%d], tg [%d] , tw [%d]\n", ee.record.record_number, ee.record.time_generated, ee.record.time_written );
if ( ee.record.time_generated != 0 ) {
/* printf("Writing to the event log\n"); */
- rcnum = write_eventlog_tdb( elog_tdb, &ee );
+ rcnum = write_eventlog_tdb( elog_tdb, &ee );
if ( !rcnum ) {
printf( "Can't write to the event log\n" );
} else {
@@ -169,3 +150,76 @@ int main( int argc, char *argv[] )
return 0;
}
+
+/* would be nice to use the popT stuff here, however doing so forces us to drag in a lot of other infrastructure */
+
+int main( int argc, char *argv[] )
+{
+ int opt, rc;
+ char *exename;
+ char *srcname, *eventlogname;
+
+
+ fstring opname;
+
+ opt_debug = 0; /* todo set this from getopts */
+
+ lp_load( dyn_CONFIGFILE, True, False, False );
+
+ exename = argv[0];
+ srcname = NULL;
+
+ /* default */
+
+ fstrcpy( opname, "write" ); /* the default */
+
+#if 0 /* TESTING CODE */
+ eventlog_add_source( "System", "TestSourceX", "SomeTestPathX" );
+#endif
+ while ( ( opt = getopt( argc, argv, "dho:" ) ) != EOF ) {
+ switch ( opt ) {
+
+ case 'o':
+ fstrcpy( opname, optarg );
+ break;
+
+ case 'h':
+ usage( argv[0] );
+ display_eventlog_names( );
+ exit( 0 );
+ break;
+
+ case 'd':
+ opt_debug = 1;
+ break;
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if ( argc < 1 ) {
+ printf( "\nNot enough arguments!\n" );
+ usage( exename );
+ exit( 1 );
+ }
+
+ /* note that the separate command types should call usage if they need to... */
+ eventlogname = *argv;
+ while ( 1 ) {
+ if ( !StrCaseCmp( opname, "addsource" ) ) {
+ rc = DoAddSourceCommand( argc, argv, opt_debug,
+ exename );
+ break;
+ }
+ if ( !StrCaseCmp( opname, "write" ) ) {
+ rc = DoWriteCommand( argc, argv, opt_debug, exename );
+ break;
+ }
+ printf( "unknown command [%s]\n", opname );
+ usage( exename );
+ exit( 1 );
+ break;
+ }
+ return rc;
+}