[SCM] Samba Shared Repository - branch v3-2-test updated -
initial-v3-2-unstable-378-g55b4f9d
Jeremy Allison
jra at samba.org
Tue Nov 27 19:23:33 GMT 2007
The branch, v3-2-test has been updated
via 55b4f9d003b036af69085f7b64e0df08c5ba440d (commit)
from 172f7ce96dc12cfc7d2209d8ed56aeebefd6207b (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test
- Log -----------------------------------------------------------------
commit 55b4f9d003b036af69085f7b64e0df08c5ba440d
Author: Jeremy Allison <jra at samba.org>
Date: Tue Nov 27 11:22:58 2007 -0800
Remove pstring from everything in rpc_server except
srv_spoolss_nt.c and srv_srvsvc_nt.c.
They're next :-).
Jeremy.
-----------------------------------------------------------------------
Summary of changes:
source/include/rpc_eventlog.h | 10 +-
source/rpc_server/srv_eventlog_lib.c | 151 ++++++++++----------
source/rpc_server/srv_eventlog_nt.c | 162 ++++++++++++++--------
source/rpc_server/srv_netlog_nt.c | 27 ++--
source/rpc_server/srv_samr_util.c | 3 +-
source/rpc_server/srv_srvsvc_nt.c | 2 +-
source/rpc_server/srv_svcctl_nt.c | 25 ++--
source/rpc_server/srv_winreg_nt.c | 256 +++++++++++++++++++--------------
8 files changed, 363 insertions(+), 273 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source/include/rpc_eventlog.h b/source/include/rpc_eventlog.h
index 849c62b..9ec76a0 100644
--- a/source/include/rpc_eventlog.h
+++ b/source/include/rpc_eventlog.h
@@ -134,15 +134,15 @@ typedef struct {
typedef struct {
uint32 source_name_len;
- wpstring source_name;
+ smb_ucs2_t *source_name;
uint32 computer_name_len;
- wpstring computer_name;
+ smb_ucs2_t *computer_name;
uint32 sid_padding;
- wpstring sid;
+ smb_ucs2_t *sid;
uint32 strings_len;
- wpstring strings;
+ smb_ucs2_t *strings;
uint32 user_data_len;
- pstring user_data;
+ char *user_data;
uint32 data_padding;
} Eventlog_data_record;
diff --git a/source/rpc_server/srv_eventlog_lib.c b/source/rpc_server/srv_eventlog_lib.c
index 00afe5b..b964828 100644
--- a/source/rpc_server/srv_eventlog_lib.c
+++ b/source/rpc_server/srv_eventlog_lib.c
@@ -62,17 +62,16 @@ TDB_CONTEXT *elog_init_tdb( char *tdbfilename )
and size. Caller must free memory.
********************************************************************/
-char *elog_tdbname( const char *name )
+char *elog_tdbname(TALLOC_CTX *ctx, const char *name )
{
- fstring path;
- char *tdb_fullpath;
- char *eventlogdir = state_path( "eventlog" );
-
- pstr_sprintf( path, "%s/%s.tdb", eventlogdir, name );
- strlower_m( path );
- tdb_fullpath = SMB_STRDUP( path );
-
- return tdb_fullpath;
+ char *path = talloc_asprintf(ctx, "%s/%s.tdb",
+ state_path("eventlog"),
+ name);
+ if (!path) {
+ return NULL;
+ }
+ strlower_m(path);
+ return path;
}
@@ -320,13 +319,13 @@ ELOG_TDB *elog_open_tdb( char *logname, bool force_clear )
TDB_CONTEXT *tdb = NULL;
uint32 vers_id;
ELOG_TDB *ptr;
- char *tdbfilename;
- pstring tdbpath;
+ char *tdbpath = NULL;
ELOG_TDB *tdb_node = NULL;
char *eventlogdir;
+ TALLOC_CTX *ctx = talloc_tos();
/* first see if we have an open context */
-
+
for ( ptr=open_elog_list; ptr; ptr=ptr->next ) {
if ( strequal( ptr->name, logname ) ) {
ptr->ref_count++;
@@ -345,27 +344,28 @@ ELOG_TDB *elog_open_tdb( char *logname, bool force_clear )
return ptr;
}
}
-
+
/* make sure that the eventlog dir exists */
-
+
eventlogdir = state_path( "eventlog" );
if ( !directory_exist( eventlogdir, NULL ) )
- mkdir( eventlogdir, 0755 );
-
+ mkdir( eventlogdir, 0755 );
+
/* get the path on disk */
-
- tdbfilename = elog_tdbname( logname );
- pstrcpy( tdbpath, tdbfilename );
- SAFE_FREE( tdbfilename );
- DEBUG(7,("elog_open_tdb: Opening %s...(force_clear == %s)\n",
+ tdbpath = elog_tdbname(ctx, logname);
+ if (!tdbpath) {
+ return NULL;
+ }
+
+ DEBUG(7,("elog_open_tdb: Opening %s...(force_clear == %s)\n",
tdbpath, force_clear?"True":"False" ));
-
+
/* the tdb wasn't already open or this is a forced clear open */
if ( !force_clear ) {
- tdb = tdb_open_log( tdbpath, 0, TDB_DEFAULT, O_RDWR , 0 );
+ tdb = tdb_open_log( tdbpath, 0, TDB_DEFAULT, O_RDWR , 0 );
if ( tdb ) {
vers_id = tdb_fetch_int32( tdb, EVT_VERSION );
@@ -593,9 +593,8 @@ void fixup_eventlog_entry( Eventlog_entry * ee )
bool parse_logentry( char *line, Eventlog_entry * entry, bool * eor )
{
+ TALLOC_CTX *ctx = talloc_tos();
char *start = NULL, *stop = NULL;
- pstring temp;
- int temp_len = 0;
start = line;
@@ -661,62 +660,69 @@ bool parse_logentry( char *line, Eventlog_entry * entry, bool * eor )
} else if ( 0 == strncmp( start, "USL", stop - start ) ) {
entry->record.user_sid_length = atoi( stop + 1 );
} else if ( 0 == strncmp( start, "SRC", stop - start ) ) {
- memset( temp, 0, sizeof( temp ) );
stop++;
while ( isspace( stop[0] ) ) {
stop++;
}
- temp_len = strlen( stop );
- strncpy( temp, stop, temp_len );
- rpcstr_push( ( void * ) ( entry->data_record.source_name ),
- temp, sizeof( entry->data_record.source_name ),
- STR_TERMINATE );
- entry->data_record.source_name_len =
- ( strlen_w( entry->data_record.source_name ) * 2 ) +
- 2;
+ entry->data_record.source_name_len = rpcstr_push_talloc(ctx,
+ &entry->data_record.source_name,
+ stop);
+ if (entry->data_record.source_name_len == (size_t)-1 ||
+ entry->data_record.source_name == NULL) {
+ return false;
+ }
} else if ( 0 == strncmp( start, "SRN", stop - start ) ) {
- memset( temp, 0, sizeof( temp ) );
stop++;
while ( isspace( stop[0] ) ) {
stop++;
}
- temp_len = strlen( stop );
- strncpy( temp, stop, temp_len );
- rpcstr_push( ( void * ) ( entry->data_record.computer_name ),
- temp, sizeof( entry->data_record.computer_name ),
- STR_TERMINATE );
- entry->data_record.computer_name_len =
- ( strlen_w( entry->data_record.computer_name ) * 2 ) +
- 2;
+ entry->data_record.computer_name_len = rpcstr_push_talloc(ctx,
+ &entry->data_record.computer_name,
+ stop);
+ if (entry->data_record.computer_name_len == (size_t)-1 ||
+ entry->data_record.computer_name == NULL) {
+ return false;
+ }
} else if ( 0 == strncmp( start, "SID", stop - start ) ) {
- memset( temp, 0, sizeof( temp ) );
stop++;
while ( isspace( stop[0] ) ) {
stop++;
}
- temp_len = strlen( stop );
- strncpy( temp, stop, temp_len );
- rpcstr_push( ( void * ) ( entry->data_record.sid ), temp,
- sizeof( entry->data_record.sid ),
- STR_TERMINATE );
- entry->record.user_sid_length =
- ( strlen_w( entry->data_record.sid ) * 2 ) + 2;
+ entry->record.user_sid_length = rpcstr_push_talloc(ctx,
+ &entry->data_record.sid,
+ stop);
+ if (entry->record.user_sid_length == (size_t)-1 ||
+ entry->data_record.sid == NULL) {
+ return false;
+ }
} else if ( 0 == strncmp( start, "STR", stop - start ) ) {
+ smb_ucs2_t *temp = NULL;
+ size_t tmp_len;
+ uint32_t old_len;
/* skip past initial ":" */
stop++;
/* now skip any other leading whitespace */
- while ( isspace( stop[0] ) ) {
+ while ( isspace(stop[0])) {
stop++;
}
- temp_len = strlen( stop );
- memset( temp, 0, sizeof( temp ) );
- strncpy( temp, stop, temp_len );
- rpcstr_push( ( void * ) ( entry->data_record.strings +
- ( entry->data_record.strings_len / 2 ) ),
- temp,
- sizeof( entry->data_record.strings ) -
- ( entry->data_record.strings_len / 2 ), STR_TERMINATE );
- entry->data_record.strings_len += ( temp_len * 2 ) + 2;
+ tmp_len = rpcstr_push_talloc(ctx,
+ &temp,
+ stop);
+ if (tmp_len == (size_t)-1 || !temp) {
+ return false;
+ }
+ old_len = entry->data_record.strings_len;
+ entry->data_record.strings = (smb_ucs2_t *)TALLOC_REALLOC_ARRAY(ctx,
+ entry->data_record.strings,
+ char,
+ old_len + tmp_len);
+ if (!entry->data_record.strings) {
+ return false;
+ }
+ memcpy(entry->data_record.strings + old_len,
+ temp,
+ tmp_len);
+ entry->data_record.strings_len += tmp_len;
entry->record.num_strings++;
} else if ( 0 == strncmp( start, "DAT", stop - start ) ) {
/* skip past initial ":" */
@@ -725,25 +731,18 @@ bool parse_logentry( char *line, Eventlog_entry * entry, bool * eor )
while ( isspace( stop[0] ) ) {
stop++;
}
- entry->data_record.user_data_len = strlen( stop );
- memset( entry->data_record.user_data, 0,
- sizeof( entry->data_record.user_data ) );
- if ( entry->data_record.user_data_len > 0 ) {
- /* copy no more than the first 1024 bytes */
- if ( entry->data_record.user_data_len >
- sizeof( entry->data_record.user_data ) )
- entry->data_record.user_data_len =
- sizeof( entry->data_record.
- user_data );
- memcpy( entry->data_record.user_data, stop,
- entry->data_record.user_data_len );
+ entry->data_record.user_data_len = strlen(stop);
+ entry->data_record.user_data = talloc_strdup(ctx,
+ stop);
+ if (!entry->data_record.user_data) {
+ return false;
}
} else {
/* some other eventlog entry -- not implemented, so dropping on the floor */
DEBUG( 10, ( "Unknown entry [%s]. Ignoring.\n", line ) );
/* For now return true so that we can keep on parsing this mess. Eventually
we will return False here. */
- return True;
+ return true;
}
- return True;
+ return true;
}
diff --git a/source/rpc_server/srv_eventlog_nt.c b/source/rpc_server/srv_eventlog_nt.c
index d86da90..cd06be1 100644
--- a/source/rpc_server/srv_eventlog_nt.c
+++ b/source/rpc_server/srv_eventlog_nt.c
@@ -69,7 +69,7 @@ static EVENTLOG_INFO *find_eventlog_info_by_hnd( pipes_struct * p,
static bool elog_check_access( EVENTLOG_INFO *info, NT_USER_TOKEN *token )
{
- char *tdbname = elog_tdbname( info->logname );
+ char *tdbname = elog_tdbname(talloc_tos(), info->logname );
SEC_DESC *sec_desc;
bool ret;
NTSTATUS ntstatus;
@@ -280,22 +280,28 @@ static int elog_size( EVENTLOG_INFO *info )
}
/********************************************************************
- For the given tdb, get the next eventlog record into the passed
+ For the given tdb, get the next eventlog record into the passed
Eventlog_entry. returns NULL if it can't get the record for some reason.
********************************************************************/
-static Eventlog_entry *get_eventlog_record( prs_struct * ps, TDB_CONTEXT * tdb,
- int recno, Eventlog_entry * ee )
+static Eventlog_entry *get_eventlog_record(prs_struct *ps,
+ TDB_CONTEXT *tdb,
+ int recno)
{
+ Eventlog_entry *ee = NULL;
TDB_DATA ret, key;
int srecno;
int reclen;
int len;
- pstring *wpsource, *wpcomputer, *wpsid, *wpstrs, *puserdata;
+ char *wpsource = NULL;
+ char *wpcomputer = NULL;
+ char *wpsid = NULL;
+ char *wpstrs = NULL;
+ char *puserdata = NULL;
- key.dsize = sizeof( int32 );
+ key.dsize = sizeof(int32);
srecno = recno;
key.dptr = ( uint8 * ) &srecno;
@@ -316,10 +322,11 @@ static Eventlog_entry *get_eventlog_record( prs_struct * ps, TDB_CONTEXT * tdb,
if ( !len )
return NULL;
- /* ee = PRS_ALLOC_MEM(ps, Eventlog_entry, 1); */
-
- if ( !ee )
+ ee = TALLOC_ARRAY(ps->mem_ctx, Eventlog_entry, 1);
+ if (!ee) {
return NULL;
+ }
+ ZERO_STRUCTP(ee);
len = tdb_unpack( ret.dptr, ret.dsize, "ddddddwwwwddddddBBdBBBd",
&ee->record.length, &ee->record.reserved1,
@@ -347,36 +354,67 @@ static Eventlog_entry *get_eventlog_record( prs_struct * ps, TDB_CONTEXT * tdb,
/* have to do the following because the tdb_unpack allocs a buff, stuffs a pointer to the buff
into it's 2nd argment for 'B' */
- if ( wpcomputer )
- memcpy( ee->data_record.computer_name, wpcomputer,
- ee->data_record.computer_name_len );
- if ( wpsource )
- memcpy( ee->data_record.source_name, wpsource,
- ee->data_record.source_name_len );
-
- if ( wpsid )
- memcpy( ee->data_record.sid, wpsid,
- ee->record.user_sid_length );
- if ( wpstrs )
- memcpy( ee->data_record.strings, wpstrs,
- ee->data_record.strings_len );
-
- /* note that userdata is a pstring */
- if ( puserdata )
- memcpy( ee->data_record.user_data, puserdata,
- ee->data_record.user_data_len );
-
- SAFE_FREE( wpcomputer );
- SAFE_FREE( wpsource );
- SAFE_FREE( wpsid );
- SAFE_FREE( wpstrs );
- SAFE_FREE( puserdata );
+ if (wpcomputer) {
+ ee->data_record.computer_name = TALLOC_MEMDUP(ee,
+ wpcomputer,
+ ee->data_record.computer_name_len);
+ if (!ee->data_record.computer_name) {
+ TALLOC_FREE(ee);
+ goto out;
+ }
+ }
+ if (wpsource) {
+ ee->data_record.source_name = TALLOC_MEMDUP(ee,
+ wpsource,
+ ee->data_record.source_name_len);
+ if (!ee->data_record.source_name) {
+ TALLOC_FREE(ee);
+ goto out;
+ }
+ }
+
+ if (wpsid) {
+ ee->data_record.sid = TALLOC_MEMDUP(ee,
+ wpsid,
+ ee->record.user_sid_length);
+ if (!ee->data_record.sid) {
+ TALLOC_FREE(ee);
+ goto out;
+ }
+ }
+ if (wpstrs) {
+ ee->data_record.strings = TALLOC_MEMDUP(ee,
+ wpstrs,
+ ee->data_record.strings_len);
+ if (!ee->data_record.strings) {
+ TALLOC_FREE(ee);
+ goto out;
+ }
+ }
+
+ if (puserdata) {
+ ee->data_record.user_data = TALLOC_MEMDUP(ee,
+ puserdata,
+ ee->data_record.user_data_len);
+ if (!ee->data_record.user_data) {
+ TALLOC_FREE(ee);
+ goto out;
+ }
+ }
+
+ out:
+
+ SAFE_FREE(wpcomputer);
+ SAFE_FREE(wpsource);
+ SAFE_FREE(wpsid);
+ SAFE_FREE(wpstrs);
+ SAFE_FREE(puserdata);
DEBUG( 10, ( "get_eventlog_record: read back %d\n", len ) );
DEBUG( 10,
( "get_eventlog_record: computer_name %d is ",
ee->data_record.computer_name_len ) );
- SAFE_FREE( ret.dptr );
+ SAFE_FREE(ret.dptr);
return ee;
}
@@ -387,7 +425,7 @@ static Eventlog_entry *get_eventlog_record( prs_struct * ps, TDB_CONTEXT * tdb,
static bool sync_eventlog_params( EVENTLOG_INFO *info )
{
- pstring path;
+ char *path = NULL;
uint32 uiMaxSize;
uint32 uiRetention;
REGISTRY_KEY *keyinfo;
@@ -395,6 +433,7 @@ static bool sync_eventlog_params( EVENTLOG_INFO *info )
REGVAL_CTR *values;
WERROR wresult;
char *elogname = info->logname;
+ TALLOC_CTX *ctx = talloc_tos();
DEBUG( 4, ( "sync_eventlog_params with %s\n", elogname ) );
@@ -412,7 +451,10 @@ static bool sync_eventlog_params( EVENTLOG_INFO *info )
to use the same fetch/store api that we use in
srv_reg_nt.c */
- pstr_sprintf( path, "%s/%s", KEY_EVENTLOG, elogname );
+ path = talloc_asprintf(ctx, "%s/%s", KEY_EVENTLOG, elogname );
+ if (!path) {
+ return false;
+ }
wresult = regkey_open_internal( NULL, &keyinfo, path,
get_root_nt_token( ), REG_KEY_READ );
@@ -624,16 +666,20 @@ NTSTATUS _eventlog_clear_eventlog( pipes_struct * p,
EVENTLOG_R_CLEAR_EVENTLOG * r_u )
{
EVENTLOG_INFO *info = find_eventlog_info_by_hnd( p, &q_u->handle );
- pstring backup_file_name;
+ char *backup_file_name = NULL;
if ( !info )
return NT_STATUS_INVALID_HANDLE;
- pstrcpy( backup_file_name, "" );
- if ( q_u->backupfile.string ) {
- rpcstr_pull( backup_file_name, q_u->backupfile.string->buffer,
- sizeof( backup_file_name ),
- q_u->backupfile.string->uni_str_len * 2, 0 );
+ if (q_u->backupfile.string) {
+ size_t len = rpcstr_pull_talloc(p->mem_ctx,
+ &backup_file_name,
+ q_u->backupfile.string->buffer,
+ q_u->backupfile.string->uni_str_len * 2,
+ 0 );
+ if (len == (size_t)-1 || !backup_file_name) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
DEBUG(8,( "_eventlog_clear_eventlog: Using [%s] as the backup "
"file name for log [%s].",
@@ -647,7 +693,7 @@ NTSTATUS _eventlog_clear_eventlog( pipes_struct * p,
/* Force a close and reopen */
- elog_close_tdb( info->etdb, True );
+ elog_close_tdb( info->etdb, True );
become_root();
info->etdb = elog_open_tdb( info->logname, True );
unbecome_root();
@@ -674,7 +720,7 @@ NTSTATUS _eventlog_read_eventlog( pipes_struct * p,
EVENTLOG_R_READ_EVENTLOG * r_u )
{
EVENTLOG_INFO *info = find_eventlog_info_by_hnd( p, &q_u->handle );
- Eventlog_entry entry, *ee_new;
+ Eventlog_entry *entry = NULL, *ee_new = NULL;
uint32 num_records_read = 0;
prs_struct *ps;
int bytes_left, record_number;
@@ -689,9 +735,9 @@ NTSTATUS _eventlog_read_eventlog( pipes_struct * p,
bytes_left = q_u->max_read_size;
- if ( !info->etdb )
+ if ( !info->etdb )
return NT_STATUS_ACCESS_DENIED;
-
--
Samba Shared Repository
More information about the samba-cvs
mailing list