int main( int argc, char *argv[] ) { int opt, rc; char *exename; TALLOC_CTX *frame = talloc_stackframe(); fstring opname; load_case_tables(); opt_debug = 0; /* todo set this from getopts */ lp_load(get_dyn_CONFIGFILE(), True, False, False, True); exename = argv[0]; /* 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( exename ); 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... */ 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; } TALLOC_FREE(frame); return rc; }
static int DoWriteCommand( int argc, char **argv, bool debugflag, char *exename ) { FILE *f1; char *argfname; ELOG_TDB *etdb; /* fixed constants are bad bad bad */ char linein[1024]; bool is_eor; Eventlog_entry ee; int rcnum; f1 = stdin; if ( !f1 ) { printf( "Can't open STDIN\n" ); return -1; } if ( debugflag ) { printf( "Starting write for eventlog [%s]\n", argv[0] ); display_eventlog_names( ); } argfname = argv[0]; if ( !( etdb = elog_open_tdb( argfname, False ) ) ) { printf( "can't open the eventlog TDB (%s)\n", argfname ); return -1; } ZERO_STRUCT( ee ); /* MUST initialize between records */ while ( !feof( f1 ) ) { if (fgets( linein, sizeof( linein ) - 1, f1 ) == NULL) { break; } linein[strlen( linein ) - 1] = 0; /* whack the line delimiter */ if ( debugflag ) printf( "Read line [%s]\n", linein ); is_eor = False; 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 ); if ( ee.record.time_generated != 0 ) { /* printf("Writing to the event log\n"); */ rcnum = write_eventlog_tdb( ELOG_TDB_CTX(etdb), &ee ); if ( !rcnum ) { printf( "Can't write to the event log\n" ); } else { if ( opt_debug ) printf( "Wrote record %d\n", rcnum ); } } else { if ( opt_debug ) printf( "<null record>\n" ); } ZERO_STRUCT( ee ); /* MUST initialize between records */ } } elog_close_tdb( etdb , False ); return 0; }
static int DoWriteCommand( int argc, char **argv, bool debugflag, char *exename ) { FILE *f1; char *argfname; ELOG_TDB *etdb; NTSTATUS status; /* fixed constants are bad bad bad */ char linein[1024]; bool is_eor; struct eventlog_Record_tdb ee; uint32_t record_number = 0; TALLOC_CTX *mem_ctx = talloc_tos(); f1 = stdin; if ( !f1 ) { printf( "Can't open STDIN\n" ); return -1; } if ( debugflag ) { printf( "Starting write for eventlog [%s]\n", argv[0] ); display_eventlog_names( ); } argfname = argv[0]; if ( !( etdb = elog_open_tdb( argfname, False, False ) ) ) { printf( "can't open the eventlog TDB (%s)\n", argfname ); return -1; } ZERO_STRUCT( ee ); /* MUST initialize between records */ while ( !feof( f1 ) ) { if (fgets( linein, sizeof( linein ) - 1, f1 ) == NULL) { break; } if ((strlen(linein) > 0) && (linein[strlen(linein)-1] == '\n')) { linein[strlen(linein)-1] = 0; } if ( debugflag ) printf( "Read line [%s]\n", linein ); is_eor = False; parse_logentry( mem_ctx, ( char * ) &linein, &ee, &is_eor ); /* should we do something with the return code? */ if ( is_eor ) { fixup_eventlog_record_tdb( &ee ); if ( opt_debug ) printf( "record number [%d], tg [%d] , tw [%d]\n", ee.record_number, (int)ee.time_generated, (int)ee.time_written ); if ( ee.time_generated != 0 ) { /* printf("Writing to the event log\n"); */ status = evlog_push_record_tdb( mem_ctx, ELOG_TDB_CTX(etdb), &ee, &record_number ); if ( !NT_STATUS_IS_OK(status) ) { printf( "Can't write to the event log: %s\n", nt_errstr(status) ); } else { if ( opt_debug ) printf( "Wrote record %d\n", record_number ); } } else { if ( opt_debug ) printf( "<null record>\n" ); } ZERO_STRUCT( ee ); /* MUST initialize between records */ } } elog_close_tdb( etdb , False ); return 0; }