2 * Samba Unix/Linux SMB client utility
3 * Write Eventlog records to a tdb
5 * Copyright (C) Brian Moran 2005.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define DBGC_CLASS DBGC_UTIL_EVENTLOG
35 static void usage( char *s )
37 printf( "\nUsage: %s [-d] [-h] <Eventlog Name>\n", s );
38 printf( "\t-d\tturn debug on\n" );
39 printf( "\t-h\tdisplay help\n\n" );
42 static void display_eventlog_names( void )
47 elogs = lp_eventlog_list( );
48 printf( "Active eventlog names (from smb.conf):\n" );
49 printf( "--------------------------------------\n" );
50 for ( i = 0; elogs[i]; i++ ) {
51 printf( "\t%s\n", elogs[i] );
55 int main( int argc, char *argv[] )
59 /* fixed constants are bad bad bad */
64 char *argfname, *exename;
68 TDB_CONTEXT *elog_tdb;
70 opt_debug = 0; /* todo set this from getopts */
73 lp_load( dyn_CONFIGFILE, True, False, False );
77 while ( ( opt = getopt( argc, argv, "dh" ) ) != -1 ) {
81 display_eventlog_names( );
104 printf( "Can't open STDIN\n" );
110 printf( "Starting %s for eventlog [%s]\n", exename, argv[0] );
111 display_eventlog_names( );
116 if ( !(elog_tdb = elog_open_tdb( argfname ) ) ) {
117 printf( "can't open the eventlog TDB (%s)\n", tdbname );
121 ZERO_STRUCT( ee ); /* MUST initialize between records */
123 while ( !feof( f1 ) ) {
124 fgets( linein, sizeof( linein ) - 1, f1 );
125 linein[strlen( linein ) - 1] = 0; /* whack the line delimiter */
128 printf( "Read line [%s]\n", linein );
132 pret = parse_logentry( ( char * ) &linein, &ee, &is_eor );
135 fixup_eventlog_entry( &ee );
138 printf( "record number [%d], tg [%d] , tw [%d]\n",
139 ee.record.record_number,
140 ee.record.time_generated,
141 ee.record.time_written );
143 if ( ee.record.time_generated != 0 ) {
145 /* printf("Writing to the event log\n"); */
147 rcnum = write_eventlog_tdb( elog_tdb, &ee );
149 printf( "Can't write to the event log\n" );
152 printf( "Wrote record %d\n",
157 printf( "<null record>\n" );
159 ZERO_STRUCT( ee ); /* MUST initialize between records */
163 tdb_close( elog_tdb );