svn commit: samba r10823 - in trunk/source: rpc_server utils

jerry at samba.org jerry at samba.org
Fri Oct 7 16:31:48 GMT 2005


Author: jerry
Date: 2005-10-07 16:31:47 +0000 (Fri, 07 Oct 2005)
New Revision: 10823

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

Log:
cleaning up some of the eventlog tdb location
($(lockdir)/eventlog/filename.tdb))


Modified:
   trunk/source/rpc_server/srv_eventlog_lib.c
   trunk/source/rpc_server/srv_eventlog_nt.c
   trunk/source/utils/wr_eventlog.c


Changeset:
Modified: trunk/source/rpc_server/srv_eventlog_lib.c
===================================================================
--- trunk/source/rpc_server/srv_eventlog_lib.c	2005-10-07 15:43:32 UTC (rev 10822)
+++ trunk/source/rpc_server/srv_eventlog_lib.c	2005-10-07 16:31:47 UTC (rev 10823)
@@ -23,9 +23,11 @@
 #include "includes.h"
 
 
-/****************************************************************
-Init an Eventlog TDB, and return it. If null, something bad happened.
-****************************************************************/
+/********************************************************************
+ Init an Eventlog TDB, and return it. If null, something bad 
+ happened.
+********************************************************************/
+
 TDB_CONTEXT *init_eventlog_tdb( char *tdbfilename )
 {
 	TDB_CONTEXT *the_tdb;
@@ -51,29 +53,20 @@
 	return the_tdb;
 }
 
-/* make the tdb file name for an event log, given destination buffer and size */
-char *mk_tdbfilename( char *dest_buffer, char *eventlog_name, int size_dest )
+/********************************************************************
+ make the tdb file name for an event log, given destination buffer 
+ and size. Caller must free memory.
+********************************************************************/
+
+char *elog_tdbname( const char *name )
 {
-	pstring ondisk_name;
+	fstring path;
+	char *tdb_fullpath;
 
-	if ( !dest_buffer )
-		return NULL;
-
-	pstrcpy( ondisk_name, "EV" );
-	pstrcat( ondisk_name, eventlog_name );
-	pstrcat( ondisk_name, ".tdb" );
-
-	memset( dest_buffer, 0, size_dest );
-
-	/* BAD things could happen if the dest_buffer is not large enough... */
-	if ( strlen( ondisk_name ) > size_dest ) {
-		DEBUG( 3, ( "Buffer not big enough for filename\n" ) );
-		return NULL;
-	}
-
-	strncpy( dest_buffer, ondisk_name, size_dest );
-
-	return dest_buffer;
+	pstr_sprintf( path, "eventlog/%s.tdb", name );
+	tdb_fullpath = SMB_STRDUP( lock_path(path) );
+	
+	return tdb_fullpath;
 }
 
 

Modified: trunk/source/rpc_server/srv_eventlog_nt.c
===================================================================
--- trunk/source/rpc_server/srv_eventlog_nt.c	2005-10-07 15:43:32 UTC (rev 10822)
+++ trunk/source/rpc_server/srv_eventlog_nt.c	2005-10-07 16:31:47 UTC (rev 10823)
@@ -165,15 +165,15 @@
 			return;
 		}
 		for ( j = 0; j < i; j++ ) {
-			pstrcpy( ttdb[j].tdbfname,
-				 lock_path( mk_tdbfilename
-					    ( ttdb[j].tdbfname,
-					      ( char * ) elogs[j],
-					      sizeof( pstring ) ) ) );
+			char *tdbname = elog_tdbname( elogs[j] );
+
+			pstrcpy( ttdb[j].tdbfname, tdbname );
 			pstrcpy( ttdb[j].logname, elogs[j] );
 			DEBUG( 10, ( "Opening tdb for %s\n", elogs[j] ) );
 			ttdb[j].log_tdb =
 				open_eventlog_tdb( ttdb[j].tdbfname );
+
+			SAFE_FREE( tdbname );
 		}
 	}
 	nlogs = i;
@@ -409,14 +409,6 @@
 }
 
 /********************************************************************
- ********************************************************************/
-
-static BOOL open_eventlog_hook( EventlogInfo * info )
-{
-	return True;
-}
-
-/********************************************************************
 ********************************************************************/
 
 /**
@@ -722,7 +714,7 @@
 
 	info->logname = talloc_strdup( info, str );
 
-	DEBUG( 1,
+	DEBUG( 10,
 	       ( "Size of %s is %d\n", info->logname,
 		 eventlog_size( info->logname ) ) );
 
@@ -742,11 +734,6 @@
 		return WERR_NOMEM;
 	}
 
-	if ( !open_eventlog_hook( info ) ) {
-		close_policy_hnd( p, &r_u->handle );
-		return WERR_BADFILE;
-	}
-
 	sync_eventlog_params( info->logname );
 	prune_eventlog( tdb_of( info->logname ) );
 

Modified: trunk/source/utils/wr_eventlog.c
===================================================================
--- trunk/source/utils/wr_eventlog.c	2005-10-07 15:43:32 UTC (rev 10822)
+++ trunk/source/utils/wr_eventlog.c	2005-10-07 16:31:47 UTC (rev 10823)
@@ -57,15 +57,15 @@
 	FILE *f1;
 
 	/* fixed constants are bad bad bad  */
-	char linein[1024];
-	char fname[1024];
+	pstring linein;
 	BOOL is_eor;
 	int pret, opt;
 	int rcnum;
 	char *argfname, *exename;
+	char *tdbname;
 
 
-	TDB_CONTEXT *the_tdb;
+	TDB_CONTEXT *elog_tdb;
 
 	opt_debug = 0;		/* todo set this from getopts */
 
@@ -113,39 +113,47 @@
 
 	argfname = argv[0];
 
-	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 );
+	if ( !(tdbname = elog_tdbname( argfname )) ) {
+		fprintf( stderr, "Unable to create eventlog tdb filename!\n");
 		return -1;
 	}
 
-	if ( the_tdb == NULL ) {
-		printf( "can't open the eventlog TDB\n" );
+
+	if ( !(elog_tdb = open_eventlog_tdb( tdbname ) ) ) {
+		printf( "can't open the eventlog TDB (%s)\n", tdbname );
 		return -1;
 	}
+
+	SAFE_FREE( tdbname );
+
 	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 ( opt_debug )
 			printf( "Read line [%s]\n", linein );
 
 		is_eor = False;
 
 		pret = parse_logentry( ( char * ) &linein, &ee, &is_eor );
+
 		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"); */
-				if ( !
-				     ( rcnum =
-				       write_eventlog_tdb( the_tdb,
-							   &ee ) ) ) {
+
+				rcnum = write_eventlog_tdb( elog_tdb, &ee ); 
+				if ( !rcnum ) {
 					printf( "Can't write to the event log\n" );
 				} else {
 					if ( opt_debug )
@@ -160,5 +168,7 @@
 		}
 	}
 
+	tdb_close( elog_tdb );
+
 	return 0;
 }



More information about the samba-cvs mailing list