summaryrefslogtreecommitdiff
path: root/source3/registry
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2005-09-30 17:13:37 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:04:48 -0500
commit54abd2aa66069e6baf7769c496f46d9dba18db39 (patch)
tree9cf8e88168011797319ba9e9866749201b1eac1e /source3/registry
parent4a2cc231d22a82ed21771a72508f15d21ed63227 (diff)
downloadsamba-54abd2aa66069e6baf7769c496f46d9dba18db39.tar.gz
samba-54abd2aa66069e6baf7769c496f46d9dba18db39.tar.bz2
samba-54abd2aa66069e6baf7769c496f46d9dba18db39.zip
r10656: BIG merge from trunk. Features not copied over
* \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3)
Diffstat (limited to 'source3/registry')
-rw-r--r--source3/registry/reg_db.c12
-rw-r--r--source3/registry/reg_dynamic.c99
-rw-r--r--source3/registry/reg_eventlog.c375
-rw-r--r--source3/registry/reg_frontend.c136
-rw-r--r--source3/registry/reg_objects.c28
-rw-r--r--source3/registry/reg_perfcount.c1225
-rw-r--r--source3/registry/reg_printing.c40
-rw-r--r--source3/registry/reg_util.c28
-rw-r--r--source3/registry/regfio.c2
9 files changed, 1648 insertions, 297 deletions
diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c
index afb5c613c8..ab8fc14d90 100644
--- a/source3/registry/reg_db.c
+++ b/source3/registry/reg_db.c
@@ -92,18 +92,10 @@ static BOOL init_registry_data( void )
fstring keyname, subkeyname;
REGSUBKEY_CTR *subkeys;
REGVAL_CTR *values;
- uint32 *ctx;
int i;
const char *p, *p2;
UNISTR2 data;
- /* create a new top level talloc ctx */
-
- if ( !(ctx = TALLOC_P( NULL, uint32 )) ) {
- DEBUG(0,("init_registry_data: top level talloc() failure!\n"));
- return False;
- }
-
/* loop over all of the predefined paths and add each component */
for ( i=0; builtin_registry_paths[i] != NULL; i++ ) {
@@ -140,7 +132,7 @@ static BOOL init_registry_data( void )
we are about to update the record. We just want any
subkeys already present */
- if ( !(subkeys = TALLOC_ZERO_P( ctx, REGSUBKEY_CTR )) ) {
+ if ( !(subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) {
DEBUG(0,("talloc() failure!\n"));
return False;
}
@@ -158,7 +150,7 @@ static BOOL init_registry_data( void )
/* loop over all of the predefined values and add each component */
for ( i=0; builtin_registry_values[i].path != NULL; i++ ) {
- if ( !(values = TALLOC_ZERO_P( ctx, REGVAL_CTR )) ) {
+ if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) {
DEBUG(0,("talloc() failure!\n"));
return False;
}
diff --git a/source3/registry/reg_dynamic.c b/source3/registry/reg_dynamic.c
index 7f8f664ec6..b1a2a30755 100644
--- a/source3/registry/reg_dynamic.c
+++ b/source3/registry/reg_dynamic.c
@@ -37,7 +37,7 @@ static int netlogon_params( REGVAL_CTR *regvals )
{
uint32 dwValue;
- if ( !account_policy_get(AP_REFUSE_MACHINE_PW_CHANGE, &dwValue) )
+ if ( !pdb_get_account_policy(AP_REFUSE_MACHINE_PW_CHANGE, &dwValue) )
dwValue = 0;
regval_ctr_addvalue( regvals, "RefusePasswordChange", REG_DWORD,
@@ -98,6 +98,99 @@ static int tcpip_params( REGVAL_CTR *regvals )
return regval_ctr_numvals( regvals );
}
+/***********************************************************************
+***********************************************************************/
+
+static int perflib_params( REGVAL_CTR *regvals )
+{
+ int base_index = -1;
+ int last_counter = -1;
+ int last_help = -1;
+ int version = 0x00010001;
+
+ base_index = reg_perfcount_get_base_index();
+ regval_ctr_addvalue(regvals, "Base Index", REG_DWORD, (char *)&base_index, sizeof(base_index));
+ last_counter = reg_perfcount_get_last_counter(base_index);
+ regval_ctr_addvalue(regvals, "Last Counter", REG_DWORD, (char *)&last_counter, sizeof(last_counter));
+ last_help = reg_perfcount_get_last_help(last_counter);
+ regval_ctr_addvalue(regvals, "Last Help", REG_DWORD, (char *)&last_help, sizeof(last_help));
+ regval_ctr_addvalue(regvals, "Version", REG_DWORD, (char *)&version, sizeof(version));
+
+ return regval_ctr_numvals( regvals );
+}
+
+/***********************************************************************
+***********************************************************************/
+
+static int perflib_009_params( REGVAL_CTR *regvals )
+{
+ int base_index;
+ int buffer_size;
+ char *buffer = NULL;
+
+ base_index = reg_perfcount_get_base_index();
+ buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
+ regval_ctr_addvalue(regvals, "Counter", REG_MULTI_SZ, buffer, buffer_size);
+ if(buffer_size > 0)
+ SAFE_FREE(buffer);
+ buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
+ regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, buffer, buffer_size);
+ if(buffer_size > 0)
+ SAFE_FREE(buffer);
+
+ return regval_ctr_numvals( regvals );
+}
+
+/***********************************************************************
+***********************************************************************/
+
+static int hkpt_params( REGVAL_CTR *regvals )
+{
+ uint32 base_index;
+ uint32 buffer_size;
+ char *buffer = NULL;
+
+ /* This is ALMOST the same as perflib_009_params, but HKPT has
+ a "Counters" entry instead of a "Counter" key. <Grrrr> */
+
+ base_index = reg_perfcount_get_base_index();
+ buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
+ regval_ctr_addvalue(regvals, "Counters", REG_MULTI_SZ, buffer, buffer_size);
+
+ if(buffer_size > 0)
+ SAFE_FREE(buffer);
+
+ buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
+ regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, buffer, buffer_size);
+ if(buffer_size > 0)
+ SAFE_FREE(buffer);
+
+ return regval_ctr_numvals( regvals );
+}
+
+/***********************************************************************
+***********************************************************************/
+
+static int current_version( REGVAL_CTR *values )
+{
+ const char *sysroot_string = "c:\\Windows";
+ fstring sysversion;
+ fstring value;
+ uint32 value_length;
+
+ value_length = push_ucs2( value, value, sysroot_string, sizeof(value),
+ STR_TERMINATE|STR_NOALIGN );
+ regval_ctr_addvalue( values, "SystemRoot", REG_SZ, value, value_length );
+
+ fstr_sprintf( sysversion, "%d.%d", lp_major_announce_version(), lp_minor_announce_version() );
+ value_length = push_ucs2( value, value, sysversion, sizeof(value),
+ STR_TERMINATE|STR_NOALIGN );
+ regval_ctr_addvalue( values, "CurrentVersion", REG_SZ, value, value_length );
+
+
+ return regval_ctr_numvals( values );
+}
+
/***********************************************************************
Structure holding the registry paths and pointers to the value
@@ -108,6 +201,10 @@ static struct reg_dyn_values dynamic_values[] = {
{ "HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/NETLOGON/PARAMETERS", &netlogon_params },
{ "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRODUCTOPTIONS", &prod_options },
{ "HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/TCPIP/PARAMETERS", &tcpip_params },
+ { "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PERFLIB", &perflib_params },
+ { "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PERFLIB/009", &perflib_009_params },
+ { "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION", &current_version },
+ { "HKPT", &hkpt_params },
{ NULL, NULL }
};
diff --git a/source3/registry/reg_eventlog.c b/source3/registry/reg_eventlog.c
index b20eb046db..bed9e1d59a 100644
--- a/source3/registry/reg_eventlog.c
+++ b/source3/registry/reg_eventlog.c
@@ -1,7 +1,8 @@
/*
* Unix SMB/CIFS implementation.
* Virtual Windows Registry Layer
- * Copyright (C) Marcin Krzysztof Porwit 2005.
+ * Copyright (C) Marcin Krzysztof Porwit 2005,
+ * Copyright (C) Gerald (Jerry) Carter 2005.
*
* 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
@@ -20,288 +21,168 @@
#include "includes.h"
+
/**********************************************************************
- handle enumeration of values AT KEY_EVENTLOG
- *********************************************************************/
-
-static int eventlog_topkey_values( char *key, REGVAL_CTR *val )
+ Enumerate registry subkey names given a registry path.
+*********************************************************************/
+
+static int elog_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
{
- int num_values = 0;
- char *keystr, *key2 = NULL;
- char *base, *new_path;
- fstring evtlogname;
- UNISTR2 data;
- int iDisplayNameId;
- int iMaxSize;
-
- /*
- * TODO - callout to get these values...
- */
+ const char **elogs = lp_eventlog_list();
+ char *path;
+ int i;
- if ( key )
- {
- key2 = SMB_STRDUP( key );
- keystr = key2;
- reg_split_path( keystr, &base, &new_path );
+ path = reg_remaining_path( key + strlen(KEY_EVENTLOG) );
- iDisplayNameId = 0x00000100;
- iMaxSize= 0x00080000;
-
- fstrcpy( evtlogname, base );
- DEBUG(10,("eventlog_topkey_values: subkey root=> [%s] subkey path=>[%s]\n", base,new_path));
-
- if ( !new_path )
- {
- iDisplayNameId = 0x01;
- regval_ctr_addvalue( val, "ErrorControl", REG_DWORD, (char*)&iDisplayNameId, sizeof(int) );
-
- init_unistr2( &data, "EventLog", UNI_STR_TERMINATE);
- regval_ctr_addvalue( val, "DisplayName", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
-
- num_values = regval_ctr_numvals( val );
-
-
- num_values = 0;
- }
- }
+ DEBUG(10,("elog_fetch_keys: entire key => [%s], subkey => [%s]\n",
+ key, path));
- SAFE_FREE( key2 );
- return num_values;
-}
+ if ( !path ) {
+
+ if ( !elogs || !*elogs )
+ return 0;
-/**********************************************************************
- handle enumeration of values below KEY_EVENTLOG\<Eventlog>
- *********************************************************************/
-
-static int eventlog_subkey_values( char *key, REGVAL_CTR *val )
-{
- int num_values = 0;
- char *keystr, *key2 = NULL;
- char *base, *new_path;
- fstring evtlogname;
- UNISTR2 data;
- int iDisplayNameId;
- int iMaxSize;
- int iRetention;
-
- /*
- * TODO - callout to get these values...
- */
-
- if ( !key )
- return num_values;
-
- key2 = SMB_STRDUP( key );
- keystr = key2;
- reg_split_path( keystr, &base, &new_path );
-
- iDisplayNameId = 0x00000100;
- /* MaxSize is limited to 0xFFFF0000 (UINT_MAX - USHRT_MAX) as per MSDN documentation */
- iMaxSize= 0xFFFF0000;
- /* records in the samba log are not overwritten */
- iRetention = 0xFFFFFFFF;
-
- fstrcpy( evtlogname, base );
- DEBUG(10,("eventlog_subpath_values_printer: eventlogname [%s]\n", base));
- DEBUG(10,("eventlog_subpath_values_printer: new_path [%s]\n", new_path));
- if ( !new_path )
- {
-#if 0
- regval_ctr_addvalue( val, "DisplayNameId", REG_DWORD, (char*)&iDisplayNameId, sizeof(int) );
-
- init_unistr2( &data, "%SystemRoot%\\system32\\els.dll", UNI_STR_TERMINATE);
- regval_ctr_addvalue( val, "DisplayNameFile", REG_EXPAND_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
-#endif
- regval_ctr_addvalue( val, "MaxSize", REG_DWORD, (char*)&iMaxSize, sizeof(int));
- regval_ctr_addvalue( val, "Retention", REG_DWORD, (char *)&iRetention, sizeof(int));
-#if 0
- init_unistr2( &data, lp_logfile(), UNI_STR_TERMINATE);
- regval_ctr_addvalue( val, "File", REG_EXPAND_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
-#endif
- init_unistr2( &data, base, UNI_STR_TERMINATE);
- regval_ctr_addvalue( val, "PrimaryModule", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
-
- init_unistr2( &data, base, UNI_STR_TERMINATE);
- regval_ctr_addvalue( val, "Sources", REG_MULTI_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
-
- num_values = regval_ctr_numvals( val );
-
- }
- else
- {
- iDisplayNameId = 0x07;
- regval_ctr_addvalue( val, "CategoryCount", REG_DWORD, (char*)&iDisplayNameId, sizeof(int) );
-
- init_unistr2( &data, "%SystemRoot%\\system32\\eventlog.dll", UNI_STR_TERMINATE);
- regval_ctr_addvalue( val, "CategoryMessageFile", REG_EXPAND_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
-
- num_values = regval_ctr_numvals( val );
+ DEBUG(10,("elog_fetch_keys: Adding eventlog subkeys from smb.conf\n"));
+
+ for ( i=0; elogs[i]; i++ )
+ regsubkey_ctr_addkey( subkeys, elogs[i] );
+
+ return regsubkey_ctr_numkeys( subkeys );
+ }
- num_values = 0;
- }
-
- SAFE_FREE( key2 );
- return num_values;
-}
+ /* if we get <logname>/<logname> then we don't add anymore */
+ if ( strchr( path, '\\' ) ) {
+ DEBUG(10,("elog_fetch_keys: Not adding subkey to %s\n",path));
+ return 0;
+ }
-/**********************************************************************
- It is safe to assume that every registry path passed into on of
- the exported functions here begins with KEY_EVENTLOG else
- these functions would have never been called. This is a small utility
- function to strip the beginning of the path and make a copy that the
- caller can modify. Note that the caller is responsible for releasing
- the memory allocated here.
- **********************************************************************/
+ /* add in a subkey with the same name as the eventlog... */
-static char* trim_eventlog_reg_path( const char *path )
-{
- const char *p;
- uint16 key_len = strlen(KEY_EVENTLOG);
-
- /*
- * sanity check...this really should never be True.
- * It is only here to prevent us from accessing outside
- * the path buffer in the extreme case.
- */
-
- if ( strlen(path) < key_len ) {
- DEBUG(0,("trim_reg_path: Registry path too short! [%s]\n", path));
- DEBUG(0,("trim_reg_path: KEY_EVENTLOG => [%s]!\n", KEY_EVENTLOG));
- return NULL;
- }
-
-
- p = path + strlen( KEY_EVENTLOG );
-
- if ( *p == '\\' )
- p++;
-
- if ( *p )
- return SMB_STRDUP(p);
- else
- return NULL;
-}
-/**********************************************************************
- Enumerate registry subkey names given a registry path.
- Caller is responsible for freeing memory to **subkeys
- *********************************************************************/
-static int eventlog_subkey_info( const char *key, REGSUBKEY_CTR *subkey_ctr )
-{
- char *path;
- BOOL top_level = False;
- int num_subkeys = 0;
- const char **evtlog_list;
-
- path = trim_eventlog_reg_path( key );
- DEBUG(10,("eventlog_subkey_info: entire key=>[%s] SUBkey=>[%s]\n", key,path));
-
- /* check to see if we are dealing with the top level key */
- num_subkeys = 0;
-
- if ( !path )
- top_level = True;
-
- num_subkeys = 0;
- if ( !(evtlog_list = lp_eventlog_list()) ) {
- SAFE_FREE(path);
- return num_subkeys;
- }
+ DEBUG(10,("elog_fetch_keys: Looking to add eventlog subkey to %s\n",path));
-
- if ( top_level )
- {
- /* todo - get the eventlog subkey values from the smb.conf file
- for ( num_subkeys=0; num_subkeys<MAX_TOP_LEVEL_KEYS; num_subkeys++ )
- regsubkey_ctr_addkey( subkey_ctr, top_level_keys[num_subkeys] ); */
- DEBUG(10,("eventlog_subkey_info: Adding eventlog subkeys from globals\n"));
- /* TODO - make this from the globals.szEventLogs list */
-
- while (*evtlog_list)
- {
- DEBUG(10,("eventlog_subkey_info: Adding subkey =>[%s]\n",*evtlog_list));
- regsubkey_ctr_addkey( subkey_ctr, *evtlog_list);
- evtlog_list++;
- num_subkeys++;
- }
- }
- else
- {
- while (*evtlog_list && (0==num_subkeys) )
- {
- if (0 == StrCaseCmp(path,*evtlog_list))
- {
- DEBUG(10,("eventlog_subkey_info: Adding subkey [%s] for key =>[%s]\n",path,*evtlog_list));
- regsubkey_ctr_addkey( subkey_ctr, *evtlog_list);
- num_subkeys = 1;
- }
- evtlog_list++;
+ /* look for a match */
+
+ if ( !elogs )
+ return -1;
+
+ for ( i=0; elogs[i]; i++ ) {
+ /* just verify that the keyname is a valid log name */
+ if ( strequal( path, elogs[i] ) )
+ return 0;
}
- if (0==num_subkeys)
- DEBUG(10,("eventlog_subkey_info: No match on SUBkey=>[%s]\n", path));
- }
-
- SAFE_FREE( path );
- return num_subkeys;
+ return -1;
}
/**********************************************************************
Enumerate registry values given a registry path.
Caller is responsible for freeing memory
- *********************************************************************/
+*********************************************************************/
-static int eventlog_value_info( const char *key, REGVAL_CTR *val )
+static int elog_fetch_values( const char *key, REGVAL_CTR *values )
{
- char *path;
- BOOL top_level = False;
- int num_values = 0;
+ char *path;
+ uint32 uiDisplayNameId, uiMaxSize, uiRetention;
+ char *base, *new_path;
+ UNISTR2 data;
- DEBUG(10,("eventlog_value_info: key=>[%s]\n", key));
+ DEBUG(10,("elog_fetch_values: key=>[%s]\n", key));
- path = trim_eventlog_reg_path( key );
+ path = reg_remaining_path( key + strlen(KEY_EVENTLOG) );
/* check to see if we are dealing with the top level key */
- if ( !path )
- top_level = True;
- if ( top_level )
- num_values = eventlog_topkey_values(path,val);
- else
- {
- DEBUG(10,("eventlog_value_info: SUBkey=>[%s]\n", path));
- num_values = eventlog_subkey_values(path,val);
- }
- return num_values;
+ if ( !path )
+ return regdb_fetch_values( KEY_EVENTLOG, values );
+
+ /* deal with a log name */
+
+ reg_split_path( path, &base, &new_path );
+
+ /* MaxSize is limited to 0xFFFF0000 (UINT_MAX - USHRT_MAX) as per MSDN documentation */
+
+
+ if ( !new_path ) {
+
+ /* try to fetch from the registry */
+
+ regdb_fetch_values( key, values );
+
+ /* just verify one of the important keys. If this
+ fails, then assume the values have not been initialized */
+
+ if ( regval_ctr_getvalue( values, "Retention" ) )
+ return regval_ctr_numvals( values );
+
+ /* hard code some initial values */
+
+ uiDisplayNameId = 0x00000100;
+ uiMaxSize = 0x00080000;
+ uiRetention = 0x93A80;
+
+ regval_ctr_addvalue( values, "MaxSize", REG_DWORD, (char*)&uiMaxSize, sizeof(uint32));
+ regval_ctr_addvalue( values, "Retention", REG_DWORD, (char *)&uiRetention, sizeof(uint32));
+
+ init_unistr2( &data, base, UNI_STR_TERMINATE);
+ regval_ctr_addvalue( values, "PrimaryModule", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
+
+ init_unistr2( &data, base, UNI_STR_TERMINATE);
+ regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
+
+ /* store them for later updates. Complain if this fails but continue on */
+
+ if ( !regdb_store_values( key, values ) ) {
+ DEBUG(0,("elog_fetch_values: Failed to store initial values for log [%s]\n",
+ base ));
+ }
+
+ return regval_ctr_numvals( values );
+ }
+
+#if 0
+ /* hmmm....what to do here? A subkey underneath the log name ? */
+
+ uiDisplayNameId = 0x07;
+ regval_ctr_addvalue( values, "CategoryCount", REG_DWORD, (char*)&uiDisplayNameId, sizeof(uint32) );
+
+ init_unistr2( &data, "%SystemRoot%\\system32\\eventlog.dll", UNI_STR_TERMINATE);
+ regval_ctr_addvalue( values, "CategoryMessageFile", REG_EXPAND_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
+#endif
+
+ return regval_ctr_numvals( values );
}
/**********************************************************************
- Stub function which always returns failure since we don't want
- people storing eventlog information directly via registry calls
- (for now at least)
- *********************************************************************/
-static BOOL eventlog_store_subkey( const char *key, REGSUBKEY_CTR *subkeys )
+*********************************************************************/
+
+static BOOL elog_store_keys( const char *key, REGSUBKEY_CTR *subkeys )
{
+ /* cannot create any subkeys here */
+
return False;
}
/**********************************************************************
- Stub function which always returns failure since we don't want
- people storing eventlog information directly via registry calls
- (for now at least)
- *********************************************************************/
-static BOOL eventlog_store_value( const char *key, REGVAL_CTR *val )
+ Allow storing of particular values related to eventlog operation.
+*********************************************************************/
+
+static BOOL elog_store_value( const char *key, REGVAL_CTR *values )
{
- return False;
+ /* the client had to have a valid handle to get here
+ so just hand off to the registry tdb */
+
+ return regdb_store_values( key, values );
}
-/*
- * Table of function pointers for accessing eventlog data
- */
+/********************************************************************
+ Table of function pointers for accessing eventlog data
+ *******************************************************************/
+
REGISTRY_OPS eventlog_ops = {
- eventlog_subkey_info,
- eventlog_value_info,
- eventlog_store_subkey,
- eventlog_store_value,
+ elog_fetch_keys,
+ elog_fetch_values,
+ elog_store_keys,
+ elog_store_value,
NULL
};
diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c
index d6e0288461..f41c5885bc 100644
--- a/source3/registry/reg_frontend.c
+++ b/source3/registry/reg_frontend.c
@@ -38,15 +38,70 @@ REGISTRY_HOOK reg_hooks[] = {
{ KEY_PRINTING, &printing_ops },
{ KEY_PRINTING_2K, &printing_ops },
{ KEY_PRINTING_PORTS, &printing_ops },
-#if 0
{ KEY_EVENTLOG, &eventlog_ops },
-#endif
{ KEY_SHARES, &shares_reg_ops },
#endif
{ NULL, NULL }
};
+static struct generic_mapping reg_generic_map =
+ { REG_KEY_READ, REG_KEY_WRITE, REG_KEY_EXECUTE, REG_KEY_ALL };
+
+/********************************************************************
+********************************************************************/
+
+static NTSTATUS registry_access_check( SEC_DESC *sec_desc, NT_USER_TOKEN *token,
+ uint32 access_desired, uint32 *access_granted )
+{
+ NTSTATUS result;
+
+ if ( geteuid() == sec_initial_uid() ) {
+ DEBUG(5,("registry_access_check: using root's token\n"));
+ token = get_root_nt_token();
+ }
+
+ se_map_generic( &access_desired, &reg_generic_map );
+ se_access_check( sec_desc, token, access_desired, access_granted, &result );
+
+ return result;
+}
+
+/********************************************************************
+********************************************************************/
+
+static SEC_DESC* construct_registry_sd( TALLOC_CTX *ctx )
+{
+ SEC_ACE ace[2];
+ SEC_ACCESS mask;
+ size_t i = 0;
+ SEC_DESC *sd;
+ SEC_ACL *acl;
+ size_t sd_size;
+
+ /* basic access for Everyone */
+
+ init_sec_access(&mask, REG_KEY_READ );
+ init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
+
+ /* Full Access 'BUILTIN\Administrators' */
+
+ init_sec_access(&mask, REG_KEY_ALL );
+ init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
+
+
+ /* create the security descriptor */
+
+ if ( !(acl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) )
+ return NULL;
+
+ if ( !(sd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, acl, &sd_size)) )
+ return NULL;
+
+ return sd;
+}
+
+
/***********************************************************************
Open the registry database and initialize the REGISTRY_HOOK cache
***********************************************************************/
@@ -55,11 +110,12 @@ BOOL init_registry( void )
{
int i;
+
if ( !init_registry_db() ) {
DEBUG(0,("init_registry: failed to initialize the registry tdb!\n"));
return False;
}
-
+
/* build the cache tree of registry hooks */
reghook_cache_init();
@@ -72,6 +128,14 @@ BOOL init_registry( void )
if ( DEBUGLEVEL >= 20 )
reghook_dump_cache(20);
+ /* inform the external eventlog machinery of the change */
+
+ eventlog_refresh_external_parameters( get_root_nt_token() );
+
+ /* add any services keys */
+
+ svcctl_init_keys();
+
return True;
}
@@ -277,4 +341,70 @@ BOOL regkey_access_check( REGISTRY_KEY *key, uint32 requested, uint32 *granted,
return key->hook->ops->reg_access_check( key->name, requested, granted, token );
}
+/***********************************************************************
+***********************************************************************/
+
+WERROR regkey_open_internal( REGISTRY_KEY **regkey, const char *path,
+ NT_USER_TOKEN *token, uint32 access_desired )
+{
+ WERROR result = WERR_OK;
+ REGISTRY_KEY *keyinfo;
+ REGSUBKEY_CTR *subkeys = NULL;
+ uint32 access_granted;
+
+ DEBUG(7,("regkey_open_internal: name = [%s]\n", path));
+ if ( !(*regkey = TALLOC_ZERO_P(NULL, REGISTRY_KEY)) )
+ return WERR_NOMEM;
+
+ keyinfo = *regkey;
+
+ /* initialization */
+
+ keyinfo->type = REG_KEY_GENERIC;
+ keyinfo->name = talloc_strdup( keyinfo, path );
+
+
+ /* Tag this as a Performance Counter Key */
+
+ if( StrnCaseCmp(path, KEY_HKPD, strlen(KEY_HKPD)) == 0 )
+ keyinfo->type = REG_KEY_HKPD;
+
+ /* Look up the table of registry I/O operations */
+
+ if ( !(keyinfo->hook = reghook_cache_find( keyinfo->name )) ) {
+ DEBUG(0,("open_registry_key: Failed to assigned a REGISTRY_HOOK to [%s]\n",
+ keyinfo->name ));
+ result = WERR_BADFILE;
+ goto done;
+ }
+
+ /* check if the path really exists; failed is indicated by -1 */
+ /* if the subkey count failed, bail out */
+
+ if ( !(subkeys = TALLOC_ZERO_P( keyinfo, REGSUBKEY_CTR )) ) {
+ result = WERR_NOMEM;
+ goto done;
+ }
+
+ if ( fetch_reg_keys( keyinfo, subkeys ) == -1 ) {
+ result = WERR_BADFILE;
+ goto done;
+ }
+
+ TALLOC_FREE( subkeys );
+
+ if ( !regkey_access_check( keyinfo, access_desired, &access_granted, token ) ) {
+ result = WERR_ACCESS_DENIED;
+ goto done;
+ }
+
+ keyinfo->access_granted = access_granted;
+
+done:
+ if ( !W_ERROR_IS_OK(result) ) {
+ TALLOC_FREE( *regkey );
+ }
+
+ return result;
+}
diff --git a/source3/registry/reg_objects.c b/source3/registry/reg_objects.c
index 70410a6740..05567d561c 100644
--- a/source3/registry/reg_objects.c
+++ b/source3/registry/reg_objects.c
@@ -236,7 +236,7 @@ uint32 regval_type( REGISTRY_VALUE *val )
/***********************************************************************
Retreive a pointer to a specific value. Caller shoud dup the structure
- since this memory may go away with a regval_ctr_destroy()
+ since this memory will go away when the ctr is free()'d
**********************************************************************/
REGISTRY_VALUE* regval_ctr_specific_value( REGVAL_CTR *ctr, uint32 idx )
@@ -385,3 +385,29 @@ REGISTRY_VALUE* regval_ctr_getvalue( REGVAL_CTR *ctr, const char *name )
return NULL;
}
+/***********************************************************************
+ return the data_p as a uint32
+ **********************************************************************/
+
+uint32 regval_dword( REGISTRY_VALUE *val )
+{
+ uint32 data;
+
+ data = IVAL( regval_data_p(val), 0 );
+
+ return data;
+}
+
+/***********************************************************************
+ return the data_p as a character string
+ **********************************************************************/
+
+char* regval_sz( REGISTRY_VALUE *val )
+{
+ static pstring data;
+
+ rpcstr_pull( data, regval_data_p(val), sizeof(data), regval_size(val), 0 );
+
+ return data;
+}
+
diff --git a/source3/registry/reg_perfcount.c b/source3/registry/reg_perfcount.c
new file mode 100644
index 0000000000..609f86da6c
--- /dev/null
+++ b/source3/registry/reg_perfcount.c
@@ -0,0 +1,1225 @@
+#include "includes.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_RPC_SRV
+
+#define PERFCOUNT_MAX_LEN 256
+
+uint32 reg_perfcount_get_base_index(void)
+{
+ pstring fname;
+ TDB_CONTEXT *names;
+ TDB_DATA kbuf, dbuf;
+ char key[] = "1";
+ uint32 retval = 0;
+ char buf[PERFCOUNT_MAX_LEN];
+ const char *counter_dir = lp_counters_dir();
+
+
+ if ( !*counter_dir )
+ return 0;
+
+ pstr_sprintf( fname, "%s/names.tdb", counter_dir );
+
+ names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
+
+ if ( !names ) {
+ DEBUG(1, ("reg_perfcount_get_base_index: unable to open [%s].\n", fname));
+ return 0;
+ }
+ /* needs to read the value of key "1" from the counter_names.tdb file, as that is
+ where the total number of counters is stored. We're assuming no holes in the
+ enumeration.
+ The format for the counter_names.tdb file is:
+ key value
+ 1 num_counters
+ 2 perf_counter1
+ 3 perf_counter1_help
+ 4 perf_counter2
+ 5 perf_counter2_help
+ even_num perf_counter<even_num>
+ even_num+1 perf_counter<even_num>_help
+ and so on.
+ So last_counter becomes num_counters*2, and last_help will be last_counter+1 */
+ kbuf.dptr = key;
+ kbuf.dsize = strlen(key);
+ dbuf = tdb_fetch(names, kbuf);
+ if(dbuf.dptr == NULL)
+ {
+ DEBUG(1, ("reg_perfcount_get_base_index: failed to find key \'1\' in [%s].\n", fname));
+ tdb_close(names);
+ return 0;
+ }
+ else
+ {
+ tdb_close(names);
+ memset(buf, 0, PERFCOUNT_MAX_LEN);
+ memcpy(buf, dbuf.dptr, dbuf.dsize);
+ retval = (uint32)atoi(buf);
+ SAFE_FREE(dbuf.dptr);
+ return retval;
+ }
+ return 0;
+}
+
+uint32 reg_perfcount_get_last_counter(uint32 base_index)
+{
+ uint32 retval;
+
+ if(base_index == 0)
+ retval = 0;
+ else
+ retval = base_index * 2;
+
+ return retval;
+}
+
+uint32 reg_perfcount_get_last_help(uint32 last_counter)
+{
+ uint32 retval;
+
+ if(last_counter == 0)
+ retval = 0;
+ else
+ retval = last_counter + 1;
+
+ return retval;
+}
+
+static uint32 _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,
+ int keyval,
+ char **retbuf,
+ uint32 buffer_size)
+{
+ TDB_DATA kbuf, dbuf;
+ char temp[256];
+ char *buf1 = *retbuf, *buf2 = NULL;
+ uint32 working_size = 0;
+ UNISTR2 name_index, name;
+
+ memset(temp, 0, sizeof(temp));
+ snprintf(temp, sizeof(temp), "%d", keyval);
+ kbuf.dptr = temp;
+ kbuf.dsize = strlen(temp);
+ dbuf = tdb_fetch(tdb, kbuf);
+ if(dbuf.dptr == NULL)
+ {
+ /* If a key isn't there, just bypass it -- this really shouldn't
+ happen unless someone's mucking around with the tdb */
+ DEBUG(3, ("_reg_perfcount_multi_sz_from_tdb: failed to find key [%s] in [%s].\n",
+ temp, tdb->name));
+ return buffer_size;
+ }
+ /* First encode the name_index */
+ working_size = (kbuf.dsize + 1)*sizeof(uint16);
+ buf2 = SMB_REALLOC(buf1, buffer_size + working_size);
+ if(!buf2)
+ {
+ SAFE_FREE(buf1);
+ buffer_size = 0;
+ return buffer_size;
+ }
+ buf1 = buf2;
+ init_unistr2(&name_index, kbuf.dptr, UNI_STR_TERMINATE);
+ memcpy(buf1+buffer_size, (char *)name_index.buffer, working_size);
+ buffer_size += working_size;
+ /* Now encode the actual name */
+ working_size = (dbuf.dsize + 1)*sizeof(uint16);
+ buf2 = SMB_REALLOC(buf1, buffer_size + working_size);
+ if(!buf2)
+ {
+ SAFE_FREE(buf1);
+ buffer_size = 0;
+ return buffer_size;
+ }
+ buf1 = buf2;
+ memset(temp, 0, sizeof(temp));
+ memcpy(temp, dbuf.dptr, dbuf.dsize);
+ SAFE_FREE(dbuf.dptr);
+ init_unistr2(&name, temp, UNI_STR_TERMINATE);
+ memcpy(buf1+buffer_size, (char *)name.buffer, working_size);
+ buffer_size += working_size;
+
+ *retbuf = buf1;
+
+ return buffer_size;
+}
+
+uint32 reg_perfcount_get_counter_help(uint32 base_index, char **retbuf)
+{
+ char *buf1 = NULL, *buf2 = NULL;
+ uint32 buffer_size = 0;
+ TDB_CONTEXT *names;
+ pstring fname;
+ int i;
+
+ if(base_index == 0)
+ return 0;
+
+ pstrcpy(fname, lp_counters_dir());
+ pstrcat(fname, "/names.tdb");
+
+ names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
+
+ if(names == NULL)
+ {
+ DEBUG(1, ("reg_perfcount_get_counter_help: unable to open [%s].\n", fname));
+ return 0;
+ }
+
+ for(i = 1; i <= base_index; i++)
+ {
+ buffer_size = _reg_perfcount_multi_sz_from_tdb(names, (i*2)+1, retbuf, buffer_size);
+ }
+ tdb_close(names);
+
+ /* Now terminate the MULTI_SZ with a double unicode NULL */
+ buf1 = *retbuf;
+ buf2 = SMB_REALLOC(buf1, buffer_size + 2);
+ if(!buf2)
+ {
+ SAFE_FREE(buf1);
+ buffer_size = 0;
+ }
+ else
+ {
+ buf1 = buf2;
+ buf1[buffer_size++] = '\0';
+ buf1[buffer_size++] = '\0';
+ }
+
+ *retbuf = buf1;
+
+ return buffer_size;
+}
+
+uint32 reg_perfcount_get_counter_names(uint32 base_index, char **retbuf)
+{
+ char *buf1 = NULL, *buf2 = NULL;
+ uint32 buffer_size = 0;
+ TDB_CONTEXT *names;
+ pstring fname;
+ int i;
+
+ if(base_index == 0)
+ return 0;
+
+ pstrcpy(fname, lp_counters_dir());
+ pstrcat(fname, "/names.tdb");
+
+ names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
+
+ if(names == NULL)
+ {
+ DEBUG(1, ("reg_perfcount_get_counter_names: unable to open [%s].\n", fname));
+ return 0;
+ }
+
+ buffer_size = _reg_perfcount_multi_sz_from_tdb(names, 1, retbuf, buffer_size);
+
+ for(i = 1; i <= base_index; i++)
+ {
+ buffer_size = _reg_perfcount_multi_sz_from_tdb(names, i*2, retbuf, buffer_size);
+ }
+ tdb_close(names);
+
+ /* Now terminate the MULTI_SZ with a double unicode NULL */
+ buf1 = *retbuf;
+ buf2 = SMB_REALLOC(buf1, buffer_size + 2);
+ if(!buf2)
+ {
+ SAFE_FREE(buf1);
+ buffer_size = 0;
+ }
+ else
+ {
+ buf1 = buf2;
+ buf1[buffer_size++] = '\0';
+ buf1[buffer_size++] = '\0';
+ }
+
+ *retbuf=buf1;
+
+ return buffer_size;
+}
+
+static void _reg_perfcount_make_key(TDB_DATA *key,
+ char *buf,
+ int buflen,
+ int key_part1,
+ const char *key_part2)
+{
+ memset(buf, 0, buflen);
+ if(key_part2 != NULL)
+ snprintf(buf, buflen,"%d%s", key_part1, key_part2);
+ else
+ snprintf(buf, buflen, "%d", key_part1);
+
+ key->dptr = buf;
+ key->dsize = strlen(buf);
+
+ return;
+}
+
+static BOOL _reg_perfcount_isparent(TDB_DATA data)
+{
+ if(data.dsize > 0)
+ {
+ if(data.dptr[0] == 'p')
+ return True;
+ else
+ return False;
+ }
+ return False;
+}
+
+static BOOL _reg_perfcount_ischild(TDB_DATA data)
+{
+ if(data.dsize > 0)
+ {
+ if(data.dptr[0] == 'c')
+ return True;
+ else
+ return False;
+ }
+ return False;
+}
+
+static uint32 _reg_perfcount_get_numinst(int objInd, TDB_CONTEXT *names)
+{
+ TDB_DATA key, data;
+ char buf[PERFCOUNT_MAX_LEN];
+
+ _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, objInd, "inst");
+ data = tdb_fetch(names, key);
+
+ if(data.dptr == NULL)
+ return (uint32)PERF_NO_INSTANCES;
+
+ memset(buf, 0, PERFCOUNT_MAX_LEN);
+ memcpy(buf, data.dptr, data.dsize);
+ return (uint32)atoi(buf);
+}
+
+static BOOL _reg_perfcount_add_object(PERF_DATA_BLOCK *block,
+ prs_struct *ps,
+ int num,
+ TDB_DATA data,
+ TDB_CONTEXT *names)
+{
+ int i;
+ BOOL success = False;
+ PERF_OBJECT_TYPE *obj;
+
+ block->objects = (PERF_OBJECT_TYPE *)TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ block->objects,
+ PERF_OBJECT_TYPE,
+ block->NumObjectTypes+1);
+ if(block->objects == NULL)
+ return False;
+ obj = &(block->objects[block->NumObjectTypes]);
+ memset((void *)&(block->objects[block->NumObjectTypes]), 0, sizeof(PERF_OBJECT_TYPE));
+ block->objects[block->NumObjectTypes].ObjectNameTitleIndex = num;
+ block->objects[block->NumObjectTypes].ObjectNameTitlePointer = 0;
+ block->objects[block->NumObjectTypes].ObjectHelpTitleIndex = num+1;
+ block->objects[block->NumObjectTypes].ObjectHelpTitlePointer = 0;
+ block->objects[block->NumObjectTypes].NumCounters = 0;
+ block->objects[block->NumObjectTypes].DefaultCounter = 0;
+ block->objects[block->NumObjectTypes].NumInstances = _reg_perfcount_get_numinst(num, names);
+ block->objects[block->NumObjectTypes].counters = NULL;
+ block->objects[block->NumObjectTypes].instances = NULL;
+ block->objects[block->NumObjectTypes].counter_data.ByteLength = sizeof(uint32);
+ block->objects[block->NumObjectTypes].counter_data.data = NULL;
+ block->objects[block->NumObjectTypes].DetailLevel = PERF_DETAIL_NOVICE;
+ block->NumObjectTypes+=1;
+
+ for(i = 0; i < (int)obj->NumInstances; i++)
+ {
+ success = _reg_perfcount_add_instance(obj, ps, i, names);
+ }
+
+ return True;
+}
+
+BOOL _reg_perfcount_get_counter_data(TDB_DATA key, TDB_DATA *data)
+{
+ TDB_CONTEXT *counters;
+
+ pstring fname;
+
+ pstrcpy(fname, lp_counters_dir());
+ pstrcat(fname, "/data.tdb");
+
+ counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
+
+ if(counters == NULL)
+ {
+ DEBUG(1, ("reg_perfcount_get_counter_data: unable to open [%s].\n", fname));
+ return False;
+ }
+
+ *data = tdb_fetch(counters, key);
+
+ tdb_close(counters);
+
+ return True;
+}
+
+static uint32 _reg_perfcount_get_size_field(uint32 CounterType)
+{
+ uint32 retval;
+
+ retval = CounterType;
+
+ /* First mask out reserved lower 8 bits */
+ retval = retval & 0xFFFFFF00;
+ retval = retval << 22;
+ retval = retval >> 22;
+
+ return retval;
+}
+
+static uint32 _reg_perfcount_compute_scale(long long int data)
+{
+ int scale = 0;
+ if(data == 0)
+ return scale;
+ while(data > 100)
+ {
+ data /= 10;
+ scale--;
+ }
+ while(data < 10)
+ {
+ data *= 10;
+ scale++;
+ }
+
+ return (uint32)scale;
+}
+
+static BOOL _reg_perfcount_get_counter_info(PERF_DATA_BLOCK *block,
+ prs_struct *ps,
+ int CounterIndex,
+ PERF_OBJECT_TYPE *obj,
+ TDB_CONTEXT *names)
+{
+ TDB_DATA key, data;
+ char buf[PERFCOUNT_MAX_LEN];
+ size_t dsize, padding;
+ long int data32, dbuf[2];
+ long long int data64;
+ uint32 counter_size;
+
+ obj->counters[obj->NumCounters].DefaultScale = 0;
+ dbuf[0] = dbuf[1] = 0;
+ padding = 0;
+
+ _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, CounterIndex, "type");
+ data = tdb_fetch(names, key);
+ if(data.dptr == NULL)
+ {
+ DEBUG(3, ("_reg_perfcount_get_counter_info: No type data for counter [%d].\n", CounterIndex));
+ return False;
+ }
+ memset(buf, 0, PERFCOUNT_MAX_LEN);
+ memcpy(buf, data.dptr, data.dsize);
+ obj->counters[obj->NumCounters].CounterType = atoi(buf);
+ DEBUG(10, ("_reg_perfcount_get_counter_info: Got type [%d] for counter [%d].\n",
+ obj->counters[obj->NumCounters].CounterType, CounterIndex));
+ free(data.dptr);
+
+ /* Fetch the actual data */
+ _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, CounterIndex, "");
+ _reg_perfcount_get_counter_data(key, &data);
+ if(data.dptr == NULL)
+ {
+ DEBUG(3, ("_reg_perfcount_get_counter_info: No counter data for counter [%d].\n", CounterIndex));
+ return False;
+ }
+
+ counter_size = _reg_perfcount_get_size_field(obj->counters[obj->NumCounters].CounterType);
+
+ if(counter_size == PERF_SIZE_DWORD)
+ {
+ dsize = sizeof(data32);
+ memset(buf, 0, PERFCOUNT_MAX_LEN);
+ memcpy(buf, data.dptr, data.dsize);
+ data32 = strtol(buf, NULL, 0);
+ if((obj->counters[obj->NumCounters].CounterType & 0x00000F00) == PERF_TYPE_NUMBER)
+ obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale((long long int)data32);
+ else
+ obj->counters[obj->NumCounters].DefaultScale = 0;
+ dbuf[0] = data32;
+ padding = (dsize - (obj->counter_data.ByteLength%dsize)) % dsize;
+ }
+ else if(counter_size == PERF_SIZE_LARGE)
+ {
+ dsize = sizeof(data64);
+ memset(buf, 0, PERFCOUNT_MAX_LEN);
+ memcpy(buf, data.dptr, data.dsize);
+ data64 = strtoll(buf, NULL, 0);
+ if((obj->counters[obj->NumCounters].CounterType & 0x00000F00) == PERF_TYPE_NUMBER)
+ obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale(data64);
+ else
+ obj->counters[obj->NumCounters].DefaultScale = 0;
+ memcpy((void *)dbuf, (const void *)&data64, dsize);
+ padding = (dsize - (obj->counter_data.ByteLength%dsize)) % dsize;
+ }
+ else /* PERF_SIZE_VARIABLE_LEN */
+ {
+ dsize = data.dsize;
+ memset(buf, 0, PERFCOUNT_MAX_LEN);
+ memcpy(buf, data.dptr, data.dsize);
+ }
+ free(data.dptr);
+
+ obj->counter_data.ByteLength += dsize + padding;
+ obj->counter_data.data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ obj->counter_data.data,
+ uint8,
+ obj->counter_data.ByteLength - sizeof(uint32));
+ if(obj->counter_data.data == NULL)
+ return False;
+ if(dbuf[0] != 0 || dbuf[1] != 0)
+ {
+ memcpy((void *)(obj->counter_data.data +
+ (obj->counter_data.ByteLength - (sizeof(uint32) + dsize))),
+ (const void *)dbuf, dsize);
+ }
+ else
+ {
+ /* Handling PERF_SIZE_VARIABLE_LEN */
+ memcpy((void *)(obj->counter_data.data +
+ (obj->counter_data.ByteLength - (sizeof(uint32) + dsize))),
+ (const void *)buf, dsize);
+ }
+ obj->counters[obj->NumCounters].CounterOffset = obj->counter_data.ByteLength - dsize;
+ if(obj->counters[obj->NumCounters].CounterOffset % dsize != 0)
+ {
+ DEBUG(3,("Improperly aligned counter [%d]\n", obj->NumCounters));
+ }
+ obj->counters[obj->NumCounters].CounterSize = dsize;
+
+ return True;
+}
+
+PERF_OBJECT_TYPE *_reg_perfcount_find_obj(PERF_DATA_BLOCK *block, int objind)
+{
+ int i;
+
+ PERF_OBJECT_TYPE *obj = NULL;
+
+ for(i = 0; i < block->NumObjectTypes; i++)
+ {
+ if(block->objects[i].ObjectNameTitleIndex == objind)
+ {
+ obj = &(block->objects[i]);
+ }
+ }
+
+ return obj;
+}
+
+static BOOL _reg_perfcount_add_counter(PERF_DATA_BLOCK *block,
+ prs_struct *ps,
+ int num,
+ TDB_DATA data,
+ TDB_CONTEXT *names)
+{
+ char *begin, *end, *start, *stop;
+ int parent;
+ PERF_OBJECT_TYPE *obj;
+ BOOL success = False;
+ char buf[PERFCOUNT_MAX_LEN];
+
+ obj = NULL;
+ memset(buf, 0, PERFCOUNT_MAX_LEN);
+ memcpy(buf, data.dptr, data.dsize);
+ begin = index(buf, '[');
+ end = index(buf, ']');
+ if(begin == NULL || end == NULL)
+ return False;
+ start = begin+1;
+
+ while(start < end)
+ {
+ stop = index(start, ',');
+ if(stop == NULL)
+ stop = end;
+ *stop = '\0';
+ parent = atoi(start);
+
+ obj = _reg_perfcount_find_obj(block, parent);
+ if(obj == NULL)
+ {
+ /* At this point we require that the parent object exist.
+ This can probably be handled better at some later time */
+ DEBUG(3, ("_reg_perfcount_add_counter: Could not find parent object [%d] for counter [%d].\n",
+ parent, num));
+ return False;
+ }
+ obj->counters = (PERF_COUNTER_DEFINITION *)TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ obj->counters,
+ PERF_COUNTER_DEFINITION,
+ obj->NumCounters+1);
+ if(obj->counters == NULL)
+ return False;
+ memset((void *)&(obj->counters[obj->NumCounters]), 0, sizeof(PERF_COUNTER_DEFINITION));
+ obj->counters[obj->NumCounters].CounterNameTitleIndex=num;
+ obj->counters[obj->NumCounters].CounterHelpTitleIndex=num+1;
+ obj->counters[obj->NumCounters].DetailLevel = PERF_DETAIL_NOVICE;
+ obj->counters[obj->NumCounters].ByteLength = sizeof(PERF_COUNTER_DEFINITION);
+ success = _reg_perfcount_get_counter_info(block, ps, num, obj, names);
+ obj->NumCounters += 1;
+ start = stop + 1;
+ }
+
+ /* Handle case of Objects/Counters without any counter data, which would suggest
+ that the required instances are not there yet, so change NumInstances from
+ PERF_NO_INSTANCES to 0 */
+
+ return True;
+}
+
+BOOL _reg_perfcount_get_instance_info(PERF_INSTANCE_DEFINITION *inst,
+ prs_struct *ps,
+ int instId,
+ PERF_OBJECT_TYPE *obj,
+ TDB_CONTEXT *names)
+{
+ TDB_DATA key, data;
+ char buf[PERFCOUNT_MAX_LEN], temp[PERFCOUNT_MAX_LEN];
+ wpstring name;
+ int pad;
+
+ /* First grab the instance data from the data file */
+ memset(temp, 0, PERFCOUNT_MAX_LEN);
+ snprintf(temp, PERFCOUNT_MAX_LEN, "i%d", instId);
+ _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
+ _reg_perfcount_get_counter_data(key, &data);
+ if(data.dptr == NULL)
+ {
+ DEBUG(3, ("_reg_perfcount_get_instance_info: No instance data for instance [%s].\n",
+ buf));
+ return False;
+ }
+ inst->counter_data.ByteLength = data.dsize + sizeof(inst->counter_data.ByteLength);
+ inst->counter_data.data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ inst->counter_data.data,
+ uint8,
+ data.dsize);
+ if(inst->counter_data.data == NULL)
+ return False;
+ memset(inst->counter_data.data, 0, data.dsize);
+ memcpy(inst->counter_data.data, data.dptr, data.dsize);
+ free(data.dptr);
+
+ /* Fetch instance name */
+ memset(temp, 0, PERFCOUNT_MAX_LEN);
+ snprintf(temp, PERFCOUNT_MAX_LEN, "i%dname", instId);
+ _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
+ data = tdb_fetch(names, key);
+ if(data.dptr == NULL)
+ {
+ /* Not actually an error, but possibly unintended? -- just logging FYI */
+ DEBUG(3, ("_reg_perfcount_get_instance_info: No instance name for instance [%s].\n",
+ buf));
+ inst->NameLength = 0;
+ }
+ else
+ {
+ memset(buf, 0, PERFCOUNT_MAX_LEN);
+ memcpy(buf, data.dptr, data.dsize);
+ rpcstr_push((void *)name, buf, sizeof(name), STR_TERMINATE);
+ inst->NameLength = (strlen_w(name) * 2) + 2;
+ inst->data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ inst->data,
+ uint8,
+ inst->NameLength);
+ memcpy(inst->data, name, inst->NameLength);
+ free(data.dptr);
+ }
+
+ inst->ParentObjectTitleIndex = 0;
+ inst->ParentObjectTitlePointer = 0;
+ inst->UniqueID = PERF_NO_UNIQUE_ID;
+ inst->NameOffset = 6 * sizeof(uint32);
+
+ inst->ByteLength = inst->NameOffset + inst->NameLength;
+ /* Need to be aligned on a 64-bit boundary here for counter_data */
+ if((pad = (inst->ByteLength % 8)))
+ {
+ pad = 8 - pad;
+ inst->data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ inst->data,
+ uint8,
+ inst->NameLength + pad);
+ memset(inst->data + inst->NameLength, 0, pad);
+ inst->ByteLength += pad;
+ }
+
+ return True;
+}
+
+BOOL _reg_perfcount_add_instance(PERF_OBJECT_TYPE *obj,
+ prs_struct *ps,
+ int instInd,
+ TDB_CONTEXT *names)
+{
+ BOOL success;
+ PERF_INSTANCE_DEFINITION *inst;
+
+ success = False;
+
+ if(obj->instances == NULL)
+ {
+ obj->instances = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ obj->instances,
+ PERF_INSTANCE_DEFINITION,
+ obj->NumInstances);
+ }
+ if(obj->instances == NULL)
+ return False;
+
+ memset(&(obj->instances[instInd]), 0, sizeof(PERF_INSTANCE_DEFINITION));
+ inst = &(obj->instances[instInd]);
+ success = _reg_perfcount_get_instance_info(inst, ps, instInd, obj, names);
+
+ return True;
+}
+
+static int _reg_perfcount_assemble_global(PERF_DATA_BLOCK *block,
+ prs_struct *ps,
+ int base_index,
+ TDB_CONTEXT *names)
+{
+ BOOL success;
+ int i, j, retval = 0;
+ char keybuf[PERFCOUNT_MAX_LEN];
+ TDB_DATA key, data;
+
+ for(i = 1; i <= base_index; i++)
+ {
+ j = i*2;
+ _reg_perfcount_make_key(&key, keybuf, PERFCOUNT_MAX_LEN, j, "rel");
+ data = tdb_fetch(names, key);
+ if(data.dptr != NULL)
+ {
+ if(_reg_perfcount_isparent(data))
+ success = _reg_perfcount_add_object(block, ps, j, data, names);
+ else if(_reg_perfcount_ischild(data))
+ success = _reg_perfcount_add_counter(block, ps, j, data, names);
+ else
+ {
+ DEBUG(3, ("Bogus relationship [%s] for counter [%d].\n", data.dptr, j));
+ success = False;
+ }
+ if(success == False)
+ {
+ DEBUG(3, ("_reg_perfcount_assemble_global: Failed to add new relationship for counter [%d].\n", j));
+ retval = -1;
+ }
+ free(data.dptr);
+ }
+ else
+ DEBUG(3, ("NULL relationship for counter [%d] using key [%s].\n", j, keybuf));
+ }
+ return retval;
+}
+
+static BOOL _reg_perfcount_get_64(unsigned long long *retval,
+ TDB_CONTEXT *tdb,
+ int key_part1,
+ const char *key_part2)
+{
+ TDB_DATA key, data;
+ char buf[PERFCOUNT_MAX_LEN];
+
+ _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, key_part1, key_part2);
+
+ data = tdb_fetch(tdb, key);
+ if(data.dptr == NULL)
+ {
+ DEBUG(3,("_reg_perfcount_get_64: No data found for key [%s].\n", key.dptr));
+ return False;
+ }
+
+ memset(buf, 0, PERFCOUNT_MAX_LEN);
+ memcpy(buf, data.dptr, data.dsize);
+ free(data.dptr);
+
+ *retval = strtoll(buf, NULL, 0);
+
+ return True;
+}
+
+static BOOL _reg_perfcount_init_data_block_perf(PERF_DATA_BLOCK *block,
+ TDB_CONTEXT *names)
+{
+ unsigned long long PerfFreq, PerfTime, PerfTime100nSec;
+ TDB_CONTEXT *counters;
+ BOOL status;
+ pstring fname;
+
+ status = False;
+
+ pstrcpy(fname, lp_counters_dir());
+ pstrcat(fname, "/data.tdb");
+
+ counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
+
+ if(counters == NULL)
+ {
+ DEBUG(1, ("reg_perfcount_init_data_block_perf: unable to open [%s].\n", fname));
+ return False;
+ }
+
+ status = _reg_perfcount_get_64(&PerfFreq, names, 0, "PerfFreq");
+ if(status == False)
+ {
+ tdb_close(counters);
+ return status;
+ }
+ memcpy((void *)&(block->PerfFreq), (const void *)&PerfFreq, sizeof(PerfFreq));
+
+ status = _reg_perfcount_get_64(&PerfTime, counters, 0, "PerfTime");
+ if(status == False)
+ {
+ tdb_close(counters);
+ return status;
+ }
+ memcpy((void *)&(block->PerfTime), (const void *)&PerfTime, sizeof(PerfTime));
+
+ status = _reg_perfcount_get_64(&PerfTime100nSec, counters, 0, "PerfTime100nSec");
+ if(status == False)
+ {
+ tdb_close(counters);
+ return status;
+ }
+ memcpy((void *)&(block->PerfTime100nSec), (const void *)&PerfTime100nSec, sizeof(PerfTime100nSec));
+
+ tdb_close(counters);
+ return True;
+}
+
+static void _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block, prs_struct *ps, TDB_CONTEXT *names)
+{
+ wpstring temp;
+ time_t tm;
+
+ memset(temp, 0, sizeof(temp));
+ rpcstr_push((void *)temp, "PERF", sizeof(temp), STR_TERMINATE);
+ memcpy(block->Signature, temp, strlen_w(temp) *2);
+
+ if(ps->bigendian_data == RPC_BIG_ENDIAN)
+ block->LittleEndian = 0;
+ else
+ block->LittleEndian = 1;
+ block->Version = 1;
+ block->Revision = 1;
+ block->TotalByteLength = 0;
+ block->NumObjectTypes = 0;
+ block->DefaultObject = -1;
+ block->objects = NULL;
+ tm = time(NULL);
+ make_systemtime(&(block->SystemTime), gmtime(&tm));
+ _reg_perfcount_init_data_block_perf(block, names);
+ memset(temp, 0, sizeof(temp));
+ rpcstr_push((void *)temp, global_myname(), sizeof(temp), STR_TERMINATE);
+ block->SystemNameLength = (strlen_w(temp) * 2) + 2;
+ block->data = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint8, block->SystemNameLength + (8 - (block->SystemNameLength % 8)));
+ memcpy(block->data, temp, block->SystemNameLength);
+ block->SystemNameOffset = sizeof(PERF_DATA_BLOCK) - sizeof(block->objects) - sizeof(block->data);
+ block->HeaderLength = block->SystemNameOffset + block->SystemNameLength;
+ /* Make sure to adjust for 64-bit alignment for when we finish writing the system name,
+ so that the PERF_OBJECT_TYPE struct comes out 64-bit aligned */
+ block->HeaderLength += 8 - (block->HeaderLength % 8);
+
+ return;
+}
+
+static uint32 _reg_perfcount_perf_data_block_fixup(PERF_DATA_BLOCK *block, prs_struct *ps)
+{
+ int obj, cnt, inst, pad, i;
+ PERF_OBJECT_TYPE *object;
+ PERF_INSTANCE_DEFINITION *instance;
+ PERF_COUNTER_DEFINITION *counter;
+ PERF_COUNTER_BLOCK *counter_data;
+ char *temp = NULL, *src_addr, *dst_addr;
+
+ block->TotalByteLength = 0;
+ object = block->objects;
+ for(obj = 0; obj < block->NumObjectTypes; obj++)
+ {
+ object[obj].TotalByteLength = 0;
+ object[obj].DefinitionLength = 0;
+ instance = object[obj].instances;
+ counter = object[obj].counters;
+ for(cnt = 0; cnt < object[obj].NumCounters; cnt++)
+ {
+ object[obj].TotalByteLength += counter[cnt].ByteLength;
+ object[obj].DefinitionLength += counter[cnt].ByteLength;
+ }
+ if(object[obj].NumInstances != PERF_NO_INSTANCES)
+ {
+ for(inst = 0; inst < object[obj].NumInstances; inst++)
+ {
+ instance = &(object[obj].instances[inst]);
+ object[obj].TotalByteLength += instance->ByteLength;
+ counter_data = &(instance->counter_data);
+ counter = &(object[obj].counters[object[obj].NumCounters - 1]);
+ counter_data->ByteLength = counter->CounterOffset + counter->CounterSize + sizeof(counter_data->ByteLength);
+ temp = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ temp,
+ uint8,
+ counter_data->ByteLength- sizeof(counter_data->ByteLength));
+ memset(temp, 0, counter_data->ByteLength - sizeof(counter_data->ByteLength));
+ src_addr = counter_data->data;
+ for(i = 0; i < object[obj].NumCounters; i++)
+ {
+ counter = &(object[obj].counters[i]);
+ dst_addr = temp + counter->CounterOffset - sizeof(counter_data->ByteLength);
+ memcpy(dst_addr, src_addr, counter->CounterSize);
+ src_addr += counter->CounterSize;
+ }
+ /* Make sure to be 64-bit aligned */
+ if((pad = (counter_data->ByteLength % 8)))
+ {
+ pad = 8 - pad;
+ }
+ counter_data->data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ counter_data->data,
+ uint8,
+ counter_data->ByteLength - sizeof(counter_data->ByteLength) + pad);
+ memset(counter_data->data, 0, counter_data->ByteLength - sizeof(counter_data->ByteLength) + pad);
+ memcpy(counter_data->data, temp, counter_data->ByteLength - sizeof(counter_data->ByteLength));
+ counter_data->ByteLength += pad;
+ object[obj].TotalByteLength += counter_data->ByteLength;
+ }
+ }
+ else
+ {
+ /* Need to be 64-bit aligned at the end of the counter_data block, so pad counter_data to a 64-bit boundary,
+ so that the next PERF_OBJECT_TYPE can start on a 64-bit alignment */
+ if((pad = (object[obj].counter_data.ByteLength % 8)))
+ {
+ pad = 8 - pad;
+ object[obj].counter_data.data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ object[obj].counter_data.data,
+ uint8,
+ object[obj].counter_data.ByteLength + pad);
+ memset((void *)(object[obj].counter_data.data + object[obj].counter_data.ByteLength), 0, pad);
+ object[obj].counter_data.ByteLength += pad;
+ }
+ object[obj].TotalByteLength += object[obj].counter_data.ByteLength;
+ }
+ object[obj].HeaderLength = sizeof(*object) - (sizeof(counter) + sizeof(instance) + sizeof(PERF_COUNTER_BLOCK));
+ object[obj].TotalByteLength += object[obj].HeaderLength;
+ object[obj].DefinitionLength += object[obj].HeaderLength;
+
+ block->TotalByteLength += object[obj].TotalByteLength;
+ }
+
+ return block->TotalByteLength;
+}
+
+uint32 reg_perfcount_get_perf_data_block(uint32 base_index,
+ prs_struct *ps,
+ PERF_DATA_BLOCK *block,
+ char *object_ids)
+{
+ uint32 buffer_size = 0, last_counter;
+ pstring fname;
+ TDB_CONTEXT *names;
+ int retval;
+
+ pstrcpy(fname, lp_counters_dir());
+ pstrcat(fname, "/names.tdb");
+
+ names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
+
+ if(names == NULL)
+ {
+ DEBUG(1, ("reg_perfcount_get_perf_data_block: unable to open [%s].\n", fname));
+ return 0;
+ }
+
+ _reg_perfcount_init_data_block(block, ps, names);
+
+ last_counter = reg_perfcount_get_last_counter(base_index);
+
+ if(object_ids == NULL)
+ {
+ /* we're getting a request for "Global" here */
+ retval = _reg_perfcount_assemble_global(block, ps, base_index, names);
+ }
+ else
+ {
+ /* we're getting a request for a specific set of PERF_OBJECT_TYPES */
+ retval = _reg_perfcount_assemble_global(block, ps, base_index, names);
+ }
+ buffer_size = _reg_perfcount_perf_data_block_fixup(block, ps);
+
+ tdb_close(names);
+
+ return buffer_size + block->HeaderLength;
+}
+
+static BOOL _reg_perfcount_marshall_perf_data_block(prs_struct *ps, PERF_DATA_BLOCK block, int depth)
+{
+ int i;
+ prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_data_block");
+ depth++;
+
+ if(!prs_align(ps))
+ return False;
+ for(i = 0; i < 4; i++)
+ {
+ if(!prs_uint16("Signature", ps, depth, &block.Signature[i]))
+ return False;
+ }
+ if(!prs_uint32("Little Endian", ps, depth, &block.LittleEndian))
+ return False;
+ if(!prs_uint32("Version", ps, depth, &block.Version))
+ return False;
+ if(!prs_uint32("Revision", ps, depth, &block.Revision))
+ return False;
+ if(!prs_uint32("TotalByteLength", ps, depth, &block.TotalByteLength))
+ return False;
+ if(!prs_uint32("HeaderLength", ps, depth, &block.HeaderLength))
+ return False;
+ if(!prs_uint32("NumObjectTypes", ps, depth, &block.NumObjectTypes))
+ return False;
+ if(!prs_uint32("DefaultObject", ps, depth, &block.DefaultObject))
+ return False;
+ if(!spoolss_io_system_time("SystemTime", ps, depth, &block.SystemTime))
+ return False;
+ if(!prs_uint32("Padding", ps, depth, &block.Padding))
+ return False;
+ if(!prs_align_uint64(ps))
+ return False;
+ if(!prs_uint64("PerfTime", ps, depth, &block.PerfTime))
+ return False;
+ if(!prs_uint64("PerfFreq", ps, depth, &block.PerfFreq))
+ return False;
+ if(!prs_uint64("PerfTime100nSec", ps, depth, &block.PerfTime100nSec))
+ return False;
+ if(!prs_uint32("SystemNameLength", ps, depth, &block.SystemNameLength))
+ return False;
+ if(!prs_uint32("SystemNameOffset", ps, depth, &block.SystemNameOffset))
+ return False;
+ /* hack to make sure we're 64-bit aligned at the end of this whole mess */
+ if(!prs_uint8s(False, "SystemName", ps, depth, block.data,
+ block.HeaderLength - block.SystemNameOffset))
+ return False;
+
+ return True;
+}
+
+static BOOL _reg_perfcount_marshall_perf_counters(prs_struct *ps,
+ PERF_OBJECT_TYPE object,
+ int depth)
+{
+ int cnt;
+ PERF_COUNTER_DEFINITION counter;
+
+ prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_counters");
+ depth++;
+
+ for(cnt = 0; cnt < object.NumCounters; cnt++)
+ {
+ counter = object.counters[cnt];
+
+ if(!prs_align(ps))
+ return False;
+ if(!prs_uint32("ByteLength", ps, depth, &counter.ByteLength))
+ return False;
+ if(!prs_uint32("CounterNameTitleIndex", ps, depth, &counter.CounterNameTitleIndex))
+ return False;
+ if(!prs_uint32("CounterNameTitlePointer", ps, depth, &counter.CounterNameTitlePointer))
+ return False;
+ if(!prs_uint32("CounterHelpTitleIndex", ps, depth, &counter.CounterHelpTitleIndex))
+ return False;
+ if(!prs_uint32("CounterHelpTitlePointer", ps, depth, &counter.CounterHelpTitlePointer))
+ return False;
+ if(!prs_uint32("DefaultScale", ps, depth, &counter.DefaultScale))
+ return False;
+ if(!prs_uint32("DetailLevel", ps, depth, &counter.DetailLevel))
+ return False;
+ if(!prs_uint32("CounterType", ps, depth, &counter.CounterType))
+ return False;
+ if(!prs_uint32("CounterSize", ps, depth, &counter.CounterSize))
+ return False;
+ if(!prs_uint32("CounterOffset", ps, depth, &counter.CounterOffset))
+ return False;
+ }
+
+ return True;
+}
+
+static BOOL _reg_perfcount_marshall_perf_counter_data(prs_struct *ps,
+ PERF_COUNTER_BLOCK counter_data,
+ int depth)
+{
+ prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_counter_data");
+ depth++;
+
+ if(!prs_align_uint64(ps))
+ return False;
+
+ if(!prs_uint32("ByteLength", ps, depth, &counter_data.ByteLength))
+ return False;
+ if(!prs_uint8s(False, "CounterData", ps, depth, counter_data.data, counter_data.ByteLength - sizeof(uint32)))
+ return False;
+ if(!prs_align_uint64(ps))
+ return False;
+
+ return True;
+}
+
+static BOOL _reg_perfcount_marshall_perf_instances(prs_struct *ps,
+ PERF_OBJECT_TYPE object,
+ int depth)
+{
+ PERF_INSTANCE_DEFINITION instance;
+ int inst;
+
+ prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_instances");
+ depth++;
+
+ for(inst = 0; inst < object.NumInstances; inst++)
+ {
+ instance = object.instances[inst];
+
+ if(!prs_align(ps))
+ return False;
+ if(!prs_uint32("ByteLength", ps, depth, &instance.ByteLength))
+ return False;
+ if(!prs_uint32("ParentObjectTitleIndex", ps, depth, &instance.ParentObjectTitleIndex))
+ return False;
+ if(!prs_uint32("ParentObjectTitlePointer", ps, depth, &instance.ParentObjectTitlePointer))
+ return False;
+ if(!prs_uint32("UniqueID", ps, depth, &instance.UniqueID))
+ return False;
+ if(!prs_uint32("NameOffset", ps, depth, &instance.NameOffset))
+ return False;
+ if(!prs_uint32("NameLength", ps, depth, &instance.NameLength))
+ return False;
+ if(!prs_uint8s(False, "InstanceName", ps, depth, instance.data,
+ instance.ByteLength - instance.NameOffset))
+ return False;
+ if(_reg_perfcount_marshall_perf_counter_data(ps, instance.counter_data, depth) == False)
+ return False;
+ }
+
+ return True;
+}
+
+static BOOL _reg_perfcount_marshall_perf_objects(prs_struct *ps, PERF_DATA_BLOCK block, int depth)
+{
+ int obj;
+
+ PERF_OBJECT_TYPE object;
+
+ prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_objects");
+ depth++;
+
+ for(obj = 0; obj < block.NumObjectTypes; obj++)
+ {
+ object = block.objects[obj];
+
+ if(!prs_align(ps))
+ return False;
+
+ if(!prs_uint32("TotalByteLength", ps, depth, &object.TotalByteLength))
+ return False;
+ if(!prs_uint32("DefinitionLength", ps, depth, &object.DefinitionLength))
+ return False;
+ if(!prs_uint32("HeaderLength", ps, depth, &object.HeaderLength))
+ return False;
+ if(!prs_uint32("ObjectNameTitleIndex", ps, depth, &object.ObjectNameTitleIndex))
+ return False;
+ if(!prs_uint32("ObjectNameTitlePointer", ps, depth, &object.ObjectNameTitlePointer))
+ return False;
+ if(!prs_uint32("ObjectHelpTitleIndex", ps, depth, &object.ObjectHelpTitleIndex))
+ return False;
+ if(!prs_uint32("ObjectHelpTitlePointer", ps, depth, &object.ObjectHelpTitlePointer))
+ return False;
+ if(!prs_uint32("DetailLevel", ps, depth, &object.DetailLevel))
+ return False;
+ if(!prs_uint32("NumCounters", ps, depth, &object.NumCounters))
+ return False;
+ if(!prs_uint32("DefaultCounter", ps, depth, &object.DefaultCounter))
+ return False;
+ if(!prs_uint32("NumInstances", ps, depth, &object.NumInstances))
+ return False;
+ if(!prs_uint32("CodePage", ps, depth, &object.CodePage))
+ return False;
+ if(!prs_align_uint64(ps))
+ return False;
+ if(!prs_uint64("PerfTime", ps, depth, &object.PerfTime))
+ return False;
+ if(!prs_uint64("PerfFreq", ps, depth, &object.PerfFreq))
+ return False;
+
+ /* Now do the counters */
+ /* If no instances, encode counter_data */
+ /* If instances, encode instace plus counter data for each instance */
+ if(_reg_perfcount_marshall_perf_counters(ps, object, depth) == False)
+ return False;
+ if(object.NumInstances == PERF_NO_INSTANCES)
+ {
+ if(_reg_perfcount_marshall_perf_counter_data(ps, object.counter_data, depth) == False)
+ return False;
+ }
+ else
+ {
+ if(_reg_perfcount_marshall_perf_instances(ps, object, depth) == False)
+ return False;
+ }
+ }
+
+ return True;
+}
+
+static BOOL _reg_perfcount_marshall_hkpd(prs_struct *ps, PERF_DATA_BLOCK block)
+{
+ int depth = 0;
+ if(_reg_perfcount_marshall_perf_data_block(ps, block, depth) == True)
+ {
+ if(_reg_perfcount_marshall_perf_objects(ps, block, depth) == True)
+ return True;
+ }
+ return False;
+}
+WERROR reg_perfcount_get_hkpd(prs_struct *ps, uint32 max_buf_size, uint32 *outbuf_len, char *object_ids)
+{
+ /*
+ * For a detailed description of the layout of this structure,
+ * see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/performance_data_format.asp
+ */
+ PERF_DATA_BLOCK block;
+ uint32 buffer_size, base_index;
+
+ buffer_size = 0;
+ base_index = reg_perfcount_get_base_index();
+ ZERO_STRUCT(block);
+
+ buffer_size = reg_perfcount_get_perf_data_block(base_index, ps, &block, object_ids);
+
+ if(buffer_size < max_buf_size)
+ {
+ *outbuf_len = buffer_size;
+ if(_reg_perfcount_marshall_hkpd(ps, block) == True)
+ return WERR_OK;
+ else
+ return WERR_NOMEM;
+ }
+ else
+ {
+ *outbuf_len = max_buf_size;
+ _reg_perfcount_marshall_perf_data_block(ps, block, 0);
+ return WERR_INSUFFICIENT_BUFFER;
+ }
+}
diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c
index d0f7daa926..b07c8e9644 100644
--- a/source3/registry/reg_printing.c
+++ b/source3/registry/reg_printing.c
@@ -55,34 +55,6 @@ struct reg_dyn_tree {
*********************************************************************
*********************************************************************/
-/**********************************************************************
- move to next non-delimter character
-*********************************************************************/
-
-static char* remaining_path( const char *key )
-{
- static pstring new_path;
- char *p;
-
- if ( !key || !*key )
- return NULL;
-
- pstrcpy( new_path, key );
- /* normalize_reg_path( new_path ); */
-
- if ( !(p = strchr( new_path, '\\' )) )
- {
- if ( !(p = strchr( new_path, '/' )) )
- p = new_path;
- else
- p++;
- }
- else
- p++;
-
- return p;
-}
-
/***********************************************************************
simple function to prune a pathname down to the basename of a file
**********************************************************************/
@@ -107,7 +79,7 @@ static char* dos_basename ( char *path )
static int key_forms_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
{
- char *p = remaining_path( key + strlen(KEY_FORMS) );
+ char *p = reg_remaining_path( key + strlen(KEY_FORMS) );
/* no keys below Forms */
@@ -204,9 +176,9 @@ static char* strip_printers_prefix( const char *key )
/* normalizing the path does not change length, just key delimiters and case */
if ( strncmp( path, KEY_WINNT_PRINTERS, strlen(KEY_WINNT_PRINTERS) ) == 0 )
- subkeypath = remaining_path( key + strlen(KEY_WINNT_PRINTERS) );
+ subkeypath = reg_remaining_path( key + strlen(KEY_WINNT_PRINTERS) );
else
- subkeypath = remaining_path( key + strlen(KEY_CONTROL_PRINTERS) );
+ subkeypath = reg_remaining_path( key + strlen(KEY_CONTROL_PRINTERS) );
return subkeypath;
}
@@ -445,7 +417,7 @@ static void fill_in_printer_values( NT_PRINTER_INFO_LEVEL_2 *info2, REGVAL_CTR *
/* use a prs_struct for converting the devmode and security
descriptor to REG_BINARY */
- prs_init( &prs, MAX_PDU_FRAG_LEN, values, MARSHALL);
+ prs_init( &prs, RPC_MAX_PDU_FRAG_LEN, values, MARSHALL);
/* stream the device mode */
@@ -754,7 +726,7 @@ static int key_driver_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
DEBUG(10,("key_driver_fetch_keys key=>[%s]\n", key ? key : "NULL" ));
- keystr = remaining_path( key + strlen(KEY_ENVIRONMENTS) );
+ keystr = reg_remaining_path( key + strlen(KEY_ENVIRONMENTS) );
/* list all possible architectures */
@@ -1044,7 +1016,7 @@ static int key_driver_fetch_values( const char *key, REGVAL_CTR *values )
/* no values in the Environments key */
- if ( !(keystr = remaining_path( key + strlen(KEY_ENVIRONMENTS) )) )
+ if ( !(keystr = reg_remaining_path( key + strlen(KEY_ENVIRONMENTS) )) )
return 0;
pstrcpy( subkey, keystr);
diff --git a/source3/registry/reg_util.c b/source3/registry/reg_util.c
index 165292cf2f..9f19db2646 100644
--- a/source3/registry/reg_util.c
+++ b/source3/registry/reg_util.c
@@ -97,3 +97,31 @@ void normalize_reg_path( pstring keyname )
strupper_m( keyname );
}
+/**********************************************************************
+ move to next non-delimter character
+*********************************************************************/
+
+char* reg_remaining_path( const char *key )
+{
+ static pstring new_path;
+ char *p;
+
+ if ( !key || !*key )
+ return NULL;
+
+ pstrcpy( new_path, key );
+ /* normalize_reg_path( new_path ); */
+
+ if ( !(p = strchr( new_path, '\\' )) )
+ {
+ if ( !(p = strchr( new_path, '/' )) )
+ p = new_path;
+ else
+ p++;
+ }
+ else
+ p++;
+
+ return p;
+}
+
diff --git a/source3/registry/regfio.c b/source3/registry/regfio.c
index e7b8cdc8bb..954f4ae7bd 100644
--- a/source3/registry/regfio.c
+++ b/source3/registry/regfio.c
@@ -561,7 +561,7 @@ static REGF_HBIN* lookup_hbin_block( REGF_FILE *file, uint32 offset )
/* start with the open list */
for ( hbin=file->block_list; hbin; hbin=hbin->next ) {
- DEBUG(10,("lookup_hbin_block: address = 0x%x [0x%x]\n", hbin->file_off, (uint32)hbin ));
+ DEBUG(10,("lookup_hbin_block: address = 0x%x [0x%lx]\n", hbin->file_off, (unsigned long)hbin ));
if ( hbin_contains_offset( hbin, offset ) )
return hbin;
}