Author: jerry
Date: 2005-10-07 12:41:43 +0000 (Fri, 07 Oct 2005)
New Revision: 10821

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=10821

Log:
adding some updates to teh evelog record writer tool from Brian
Modified:
   trunk/source/Makefile.in
   trunk/source/utils/wr_eventlog.c


Changeset:
Modified: trunk/source/Makefile.in
===================================================================
--- trunk/source/Makefile.in    2005-10-07 12:30:46 UTC (rev 10820)
+++ trunk/source/Makefile.in    2005-10-07 12:41:43 UTC (rev 10821)
@@ -617,8 +617,7 @@
                $(PASSDB_OBJ) $(SMBLDAP_OBJ) $(GROUPDB_OBJ)
 
 WR_EVENTLOG_OBJ        = utils/wr_eventlog.o rpc_server/srv_eventlog_lib.o \
-               $(PARAM_OBJ) \
-               $(LIB_NONSMBD_OBJ) \
+               $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) 
 
 TALLOCTORT_OBJ = lib/talloctort.o $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) 
libsmb/nterr.o
 

Modified: trunk/source/utils/wr_eventlog.c
===================================================================
--- trunk/source/utils/wr_eventlog.c    2005-10-07 12:30:46 UTC (rev 10820)
+++ trunk/source/utils/wr_eventlog.c    2005-10-07 12:41:43 UTC (rev 10821)
@@ -1,4 +1,25 @@
+/*
+ * Samba Unix/Linux SMB client utility 
+ * Write Eventlog records to a tdb
+ *
+ * Copyright (C) Brian Moran                2005.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 
+
 #include "includes.h"
 
 #undef  DBGC_CLASS
@@ -6,52 +27,93 @@
 
 Eventlog_entry ee;
 
-int main( int argc, char **argv )
+extern int optind;
+extern char *optarg;
+
+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" );
+}
+
+static void display_eventlog_names( void )
+{
+       const char **elogs;
+       int i;
+
+       elogs = lp_eventlog_list(  );
+       printf( "Active eventlog names (from smb.conf):\n" );
+       printf( "--------------------------------------\n" );
+       for ( i = 0; elogs[i]; i++ ) {
+               printf( "\t%s\n", elogs[i] );
+       }
+}
+
+int main( int argc, char *argv[] )
+{
        FILE *f1;
-       char linein[1024];
 
        /* fixed constants are bad bad bad  */
+       char linein[1024];
        char fname[1024];
-
        BOOL is_eor;
-       int pret, i;
+       int pret, opt;
        int rcnum;
-       int debug;
-       const char **elogs;
+       char *argfname, *exename;
 
+
        TDB_CONTEXT *the_tdb;
 
-       debug = 1;              /* todo set this from getopts */
+       opt_debug = 0;          /* todo set this from getopts */
 
+
        lp_load( dyn_CONFIGFILE, True, False, False );
 
-       if ( argc < 2 ) {
-               printf( "Usage %s <Eventlog Name>\n", argv[0] );
-               return -1;
+       exename = argv[0];
+
+       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;
+               }
        }
 
-       /* f1 = fopen("foo.txt","r"); */
+       argc -= optind;
+       argv += optind;
+
+       if ( argc < 1 ) {
+               usage( exename );
+               exit( 1 );
+       }
+
+
+
        f1 = stdin;
+
        if ( !f1 ) {
                printf( "Can't open STDIN\n" );
                return -1;
        }
 
-       elogs = lp_eventlog_list(  );
 
-       if ( debug ) {
-               printf( "%s starting for [%s] ... valid eventlogs:\n",
-                       argv[0], argv[1] );
-               for ( i = 0; elogs[i]; i++ ) {
-                       printf( "%s\n", elogs[i] );
-               }
+       if ( opt_debug ) {
+               printf( "Starting %s for eventlog [%s]\n", exename, argv[0] );
+               display_eventlog_names(  );
        }
 
-       /* todo - check for the eventlog name being passed as being something 
that smb.conf
-          knows about -- and defer the open in case we have an chicken and egg 
issue */
+       argfname = argv[0];
 
-       if ( mk_tdbfilename( ( char * ) &fname, argv[1], sizeof( fname ) ) ) {
+       if ( mk_tdbfilename( ( char * ) &fname, argfname, sizeof( fname ) ) ) {
                the_tdb = open_eventlog_tdb( lock_path( ( char * ) &fname ) );
        } else {
                printf( "can't open filename [%s]\n", fname );
@@ -62,11 +124,11 @@
                printf( "can't open the eventlog TDB\n" );
                return -1;
        }
-       memset( &ee, 0, sizeof( Eventlog_entry ) );     /* MUST initialize 
between records */
+       ZERO_STRUCT( ee );      /* MUST initialize between records */
        while ( !feof( f1 ) ) {
                fgets( linein, sizeof( linein ) - 1, f1 );
                linein[strlen( linein ) - 1] = 0;       /* whack the line 
delimiter */
-               if ( debug )
+               if ( opt_debug )
                        printf( "Read line [%s]\n", linein );
 
                is_eor = False;
@@ -75,7 +137,7 @@
                if ( is_eor ) {
                        fixup_eventlog_entry( &ee );
 
-                       if ( debug )
+                       if ( opt_debug )
                                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 ) {
@@ -86,15 +148,15 @@
                                                           &ee ) ) ) {
                                        printf( "Can't write to the event 
log\n" );
                                } else {
-                                       if ( debug )
+                                       if ( opt_debug )
                                                printf( "Wrote record %d\n",
                                                        rcnum );
                                }
                        } else {
-                               if ( debug )
+                               if ( opt_debug )
                                        printf( "<null record>\n" );
                        }
-                       memset( &ee, 0, sizeof( Eventlog_entry ) );     /* MUST 
initialize between records */
+                       ZERO_STRUCT( ee );      /* MUST initialize between 
records */
                }
        }
 

Reply via email to