*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
/********************************************************************
********************************************************************/
-static BOOL elog_check_access( EVENTLOG_INFO *info, NT_USER_TOKEN *token )
+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;
+ bool ret;
NTSTATUS ntstatus;
if ( !tdbname )
/********************************************************************
********************************************************************/
-static BOOL elog_validate_logname( const char *name )
+static bool elog_validate_logname( const char *name )
{
int i;
const char **elogs = lp_eventlog_list();
+ if (!elogs) {
+ return False;
+ }
+
for ( i=0; elogs[i]; i++ ) {
if ( strequal( name, elogs[i] ) )
return True;
/********************************************************************
********************************************************************/
-static BOOL get_num_records_hook( EVENTLOG_INFO * info )
+static bool get_num_records_hook( EVENTLOG_INFO * info )
{
int next_record;
int oldest_record;
/********************************************************************
********************************************************************/
-static BOOL get_oldest_entry_hook( EVENTLOG_INFO * info )
+static bool get_oldest_entry_hook( EVENTLOG_INFO * info )
{
/* it's the same thing */
return get_num_records_hook( 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;
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,
/* 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 = (smb_ucs2_t *)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 = (smb_ucs2_t *)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 = (smb_ucs2_t *)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 = (smb_ucs2_t *)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 = (char *)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;
}
since it uses the table to find the tdb handle
********************************************************************/
-static BOOL sync_eventlog_params( EVENTLOG_INFO *info )
+static bool sync_eventlog_params( EVENTLOG_INFO *info )
{
- pstring path;
+ char *path = NULL;
uint32 uiMaxSize;
uint32 uiRetention;
- REGISTRY_KEY *keyinfo;
- REGISTRY_VALUE *val;
- REGVAL_CTR *values;
+ struct registry_key *key;
+ struct registry_value *value;
WERROR wresult;
char *elogname = info->logname;
+ TALLOC_CTX *ctx = talloc_tos();
+ bool ret = false;
DEBUG( 4, ( "sync_eventlog_params with %s\n", elogname ) );
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 );
+ wresult = reg_open_path(ctx, path, REG_KEY_READ, get_root_nt_token(),
+ &key);
if ( !W_ERROR_IS_OK( wresult ) ) {
DEBUG( 4,
( "sync_eventlog_params: Failed to open key [%s] (%s)\n",
path, dos_errstr( wresult ) ) );
- return False;
+ return false;
}
- if ( !( values = TALLOC_ZERO_P( keyinfo, REGVAL_CTR ) ) ) {
- TALLOC_FREE( keyinfo );
- DEBUG( 0, ( "control_eventlog_hook: talloc() failed!\n" ) );
-
- return False;
+ wresult = reg_queryvalue(key, key, "Retention", &value);
+ if (!W_ERROR_IS_OK(wresult)) {
+ DEBUG(4, ("Failed to query value \"Retention\": %s\n",
+ dos_errstr(wresult)));
+ ret = false;
+ goto done;
}
- fetch_reg_values( keyinfo, values );
-
- if ( ( val = regval_ctr_getvalue( values, "Retention" ) ) != NULL )
- uiRetention = IVAL( regval_data_p( val ), 0 );
-
- if ( ( val = regval_ctr_getvalue( values, "MaxSize" ) ) != NULL )
- uiMaxSize = IVAL( regval_data_p( val ), 0 );
-
- TALLOC_FREE( keyinfo );
+ uiRetention = value->v.dword;
+
+ wresult = reg_queryvalue(key, key, "MaxSize", &value);
+ if (!W_ERROR_IS_OK(wresult)) {
+ DEBUG(4, ("Failed to query value \"MaxSize\": %s\n",
+ dos_errstr(wresult)));
+ ret = false;
+ goto done;
+ }
+ uiMaxSize = value->v.dword;
tdb_store_int32( ELOG_TDB_CTX(info->etdb), EVT_MAXSIZE, uiMaxSize );
tdb_store_int32( ELOG_TDB_CTX(info->etdb), EVT_RETENTION, uiRetention );
- return True;
+ ret = true;
+
+done:
+ TALLOC_FREE(ctx);
+ return ret;
}
/********************************************************************
/********************************************************************
********************************************************************/
-static BOOL add_record_to_resp( EVENTLOG_R_READ_EVENTLOG * r_u,
+static bool add_record_to_resp( EVENTLOG_R_READ_EVENTLOG * r_u,
Eventlog_entry * ee_new )
{
Eventlog_entry *insert_point;
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].",
/* 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();
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;
bytes_left = q_u->max_read_size;
- if ( !info->etdb )
+ if ( !info->etdb )
return NT_STATUS_ACCESS_DENIED;
-
+
/* check for valid flags. Can't use the sequential and seek flags together */
elog_read_type = q_u->flags & (EVENTLOG_SEQUENTIAL_READ|EVENTLOG_SEEK_READ);
if ( elog_read_type & EVENTLOG_SEQUENTIAL_READ )
record_number = info->current_record;
- else
+ else
record_number = q_u->offset;
while ( bytes_left > 0 ) {
/* assume that when the record fetch fails, that we are done */
- if ( !get_eventlog_record ( ps, ELOG_TDB_CTX(info->etdb), record_number, &entry ) )
+ entry = get_eventlog_record (ps, ELOG_TDB_CTX(info->etdb), record_number);
+ if (!entry) {
break;
+ }
DEBUG( 8, ( "Retrieved record %d\n", record_number ) );
-
+
/* Now see if there is enough room to add */
- if ( !(ee_new = read_package_entry( ps, q_u, r_u,&entry )) )
+ if ( !(ee_new = read_package_entry( ps, q_u, r_u, entry )) )
return NT_STATUS_NO_MEMORY;
if ( r_u->num_bytes_in_resp + ee_new->record.length > q_u->max_read_size ) {
r_u->bytes_in_next_record = ee_new->record.length;
/* response would be too big to fit in client-size buffer */
-
+
bytes_left = 0;
break;
}
-
+
add_record_to_resp( r_u, ee_new );
bytes_left -= ee_new->record.length;
- ZERO_STRUCT( entry );
+ TALLOC_FREE(entry);
num_records_read = r_u->num_records - num_records_read;
-
+
DEBUG( 10, ( "_eventlog_read_eventlog: read [%d] records for a total "
"of [%d] records using [%d] bytes out of a max of [%d].\n",
num_records_read, r_u->num_records,
record_number++;
else
record_number--;
-
+
/* update the eventlog record pointer */
-
+
info->current_record = record_number;
}
- /* crazy by WinXP uses NT_STATUS_BUFFER_TOO_SMALL to
+ /* crazy by WinXP uses NT_STATUS_BUFFER_TOO_SMALL to
say when there are no more records */
return (num_records_read ? NT_STATUS_OK : NT_STATUS_BUFFER_TOO_SMALL);