NTSTATUS evlog_push_record(TALLOC_CTX *mem_ctx, TDB_CONTEXT *tdb, struct EVENTLOGRECORD *r, uint32_t *record_number) { struct eventlog_Record_tdb *t; NTSTATUS status; t = talloc_zero(mem_ctx, struct eventlog_Record_tdb); if (!t) { return NT_STATUS_NO_MEMORY; } status = evlog_evt_entry_to_tdb_entry(t, r, t); if (!NT_STATUS_IS_OK(status)) { talloc_free(t); return status; } status = evlog_push_record_tdb(mem_ctx, tdb, t, record_number); talloc_free(t); return status; }
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; }