+/*
+ * Unix SMB/CIFS implementation.
+ * Virtual Windows Registry Layer
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * 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.
+ */
+
#include "includes.h"
#undef DBGC_CLASS
#define PERFCOUNT_MAX_LEN 256
+#define PERFCOUNTDIR "perfmon"
+#define NAMES_DB "names.tdb"
+#define DATA_DB "data.tdb"
+
+/*********************************************************************
+*********************************************************************/
+
+static char* counters_directory( const char *dbname )
+{
+ static pstring fname;
+ fstring path;
+
+ if ( !dbname )
+ return NULL;
+
+ fstr_sprintf( path, "%s/%s", PERFCOUNTDIR, dbname );
+
+ pstrcpy( fname, lock_path( path ) );
+
+ return fname;
+}
+
+/*********************************************************************
+*********************************************************************/
+
+void perfcount_init_keys( void )
+{
+ char *p = lock_path(PERFCOUNTDIR);
+
+ /* no registry keys; just create the perfmon directory */
+
+ if ( !directory_exist( p, NULL ) )
+ mkdir( p, 0755 );
+
+ return;
+}
+
+/*********************************************************************
+*********************************************************************/
+
uint32 reg_perfcount_get_base_index(void)
{
- pstring fname;
+ const char *fname = counters_directory( NAMES_DB );
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);
return 0;
}
+/*********************************************************************
+*********************************************************************/
+
uint32 reg_perfcount_get_last_counter(uint32 base_index)
{
uint32 retval;
return retval;
}
+/*********************************************************************
+*********************************************************************/
+
uint32 reg_perfcount_get_last_help(uint32 last_counter)
{
uint32 retval;
return retval;
}
+
+/*********************************************************************
+*********************************************************************/
+
static uint32 _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,
int keyval,
char **retbuf,
{
TDB_DATA kbuf, dbuf;
char temp[256];
- char *buf1 = *retbuf, *buf2 = NULL;
+ char *buf1 = *retbuf;
uint32 working_size = 0;
UNISTR2 name_index, name;
/* 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));
+ temp, tdb_name(tdb)));
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);
+ buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
+ if(!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);
+ buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
+ if(!buf1) {
buffer_size = 0;
return buffer_size;
}
- buf1 = buf2;
memset(temp, 0, sizeof(temp));
memcpy(temp, dbuf.dptr, dbuf.dsize);
SAFE_FREE(dbuf.dptr);
return buffer_size;
}
+/*********************************************************************
+*********************************************************************/
+
uint32 reg_perfcount_get_counter_help(uint32 base_index, char **retbuf)
{
- char *buf1 = NULL, *buf2 = NULL;
+ char *buf1 = NULL;
uint32 buffer_size = 0;
TDB_CONTEXT *names;
- pstring fname;
+ const char *fname = counters_directory( NAMES_DB );
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)
/* Now terminate the MULTI_SZ with a double unicode NULL */
buf1 = *retbuf;
- buf2 = SMB_REALLOC(buf1, buffer_size + 2);
- if(!buf2)
- {
- SAFE_FREE(buf1);
+ buf1 = (char *)SMB_REALLOC(buf1, buffer_size + 2);
+ if(!buf1) {
buffer_size = 0;
- }
- else
- {
- buf1 = buf2;
+ } else {
buf1[buffer_size++] = '\0';
buf1[buffer_size++] = '\0';
}
return buffer_size;
}
+/*********************************************************************
+*********************************************************************/
+
uint32 reg_perfcount_get_counter_names(uint32 base_index, char **retbuf)
{
- char *buf1 = NULL, *buf2 = NULL;
+ char *buf1 = NULL;
uint32 buffer_size = 0;
TDB_CONTEXT *names;
- pstring fname;
+ const char *fname = counters_directory( NAMES_DB );
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)
/* Now terminate the MULTI_SZ with a double unicode NULL */
buf1 = *retbuf;
- buf2 = SMB_REALLOC(buf1, buffer_size + 2);
- if(!buf2)
- {
- SAFE_FREE(buf1);
+ buf1 = (char *)SMB_REALLOC(buf1, buffer_size + 2);
+ if(!buf1) {
buffer_size = 0;
- }
- else
- {
- buf1 = buf2;
+ } else {
buf1[buffer_size++] = '\0';
buf1[buffer_size++] = '\0';
}
return buffer_size;
}
+/*********************************************************************
+*********************************************************************/
+
static void _reg_perfcount_make_key(TDB_DATA *key,
char *buf,
int buflen,
return;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_isparent(TDB_DATA data)
{
if(data.dsize > 0)
return False;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_ischild(TDB_DATA data)
{
if(data.dsize > 0)
return False;
}
+/*********************************************************************
+*********************************************************************/
+
static uint32 _reg_perfcount_get_numinst(int objInd, TDB_CONTEXT *names)
{
TDB_DATA key, data;
return (uint32)atoi(buf);
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_add_object(PERF_DATA_BLOCK *block,
prs_struct *ps,
int num,
TDB_CONTEXT *names)
{
int i;
- BOOL success = False;
+ BOOL success = True;
PERF_OBJECT_TYPE *obj;
block->objects = (PERF_OBJECT_TYPE *)TALLOC_REALLOC_ARRAY(ps->mem_ctx,
block->objects[block->NumObjectTypes].DetailLevel = PERF_DETAIL_NOVICE;
block->NumObjectTypes+=1;
- for(i = 0; i < (int)obj->NumInstances; i++)
- {
+ for(i = 0; i < (int)obj->NumInstances; i++) {
success = _reg_perfcount_add_instance(obj, ps, i, names);
}
- return True;
+ return success;
}
+/*********************************************************************
+*********************************************************************/
+
BOOL _reg_perfcount_get_counter_data(TDB_DATA key, TDB_DATA *data)
{
TDB_CONTEXT *counters;
-
- pstring fname;
+ const char *fname = counters_directory( DATA_DB );
- pstrcpy(fname, lp_counters_dir());
- pstrcat(fname, "/data.tdb");
-
counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
if(counters == NULL)
return True;
}
+/*********************************************************************
+*********************************************************************/
+
static uint32 _reg_perfcount_get_size_field(uint32 CounterType)
{
uint32 retval;
return retval;
}
-static uint32 _reg_perfcount_compute_scale(long long int data)
+/*********************************************************************
+*********************************************************************/
+
+static uint32 _reg_perfcount_compute_scale(SMB_BIG_INT data)
{
int scale = 0;
if(data == 0)
return (uint32)scale;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_get_counter_info(PERF_DATA_BLOCK *block,
prs_struct *ps,
int CounterIndex,
char buf[PERFCOUNT_MAX_LEN];
size_t dsize, padding;
long int data32, dbuf[2];
- long long int data64;
+ SMB_BIG_INT data64;
uint32 counter_size;
obj->counters[obj->NumCounters].DefaultScale = 0;
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);
+ SAFE_FREE(data.dptr);
/* Fetch the actual data */
_reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, CounterIndex, "");
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);
+ obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale((SMB_BIG_INT)data32);
else
obj->counters[obj->NumCounters].DefaultScale = 0;
dbuf[0] = data32;
dsize = sizeof(data64);
memset(buf, 0, PERFCOUNT_MAX_LEN);
memcpy(buf, data.dptr, data.dsize);
- data64 = strtoll(buf, NULL, 0);
+ data64 = atof(buf);
if((obj->counters[obj->NumCounters].CounterType & 0x00000F00) == PERF_TYPE_NUMBER)
obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale(data64);
else
memset(buf, 0, PERFCOUNT_MAX_LEN);
memcpy(buf, data.dptr, data.dsize);
}
- free(data.dptr);
+ SAFE_FREE(data.dptr);
obj->counter_data.ByteLength += dsize + padding;
obj->counter_data.data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
return True;
}
+/*********************************************************************
+*********************************************************************/
+
PERF_OBJECT_TYPE *_reg_perfcount_find_obj(PERF_DATA_BLOCK *block, int objind)
{
int i;
return obj;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_add_counter(PERF_DATA_BLOCK *block,
prs_struct *ps,
int num,
char *begin, *end, *start, *stop;
int parent;
PERF_OBJECT_TYPE *obj;
- BOOL success = False;
+ BOOL success = True;
char buf[PERFCOUNT_MAX_LEN];
obj = NULL;
return False;
start = begin+1;
- while(start < end)
- {
+ while(start < end) {
stop = index(start, ',');
if(stop == NULL)
stop = end;
parent = atoi(start);
obj = _reg_perfcount_find_obj(block, parent);
- if(obj == NULL)
- {
+ 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",
that the required instances are not there yet, so change NumInstances from
PERF_NO_INSTANCES to 0 */
- return True;
+ return success;
}
+/*********************************************************************
+*********************************************************************/
+
BOOL _reg_perfcount_get_instance_info(PERF_INSTANCE_DEFINITION *inst,
prs_struct *ps,
int instId,
return False;
memset(inst->counter_data.data, 0, data.dsize);
memcpy(inst->counter_data.data, data.dptr, data.dsize);
- free(data.dptr);
+ SAFE_FREE(data.dptr);
/* Fetch instance name */
memset(temp, 0, PERFCOUNT_MAX_LEN);
inst->data,
uint8,
inst->NameLength);
+ if (inst->data == NULL) {
+ SAFE_FREE(data.dptr);
+ return False;
+ }
memcpy(inst->data, name, inst->NameLength);
- free(data.dptr);
+ SAFE_FREE(data.dptr);
}
inst->ParentObjectTitleIndex = 0;
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)
- {
+ if(obj->instances == NULL) {
obj->instances = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
obj->instances,
PERF_INSTANCE_DEFINITION,
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;
+ return _reg_perfcount_get_instance_info(inst, ps, instInd, obj, names);
}
+/*********************************************************************
+*********************************************************************/
+
static int _reg_perfcount_assemble_global(PERF_DATA_BLOCK *block,
prs_struct *ps,
int base_index,
DEBUG(3, ("_reg_perfcount_assemble_global: Failed to add new relationship for counter [%d].\n", j));
retval = -1;
}
- free(data.dptr);
+ SAFE_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,
+/*********************************************************************
+*********************************************************************/
+
+static BOOL _reg_perfcount_get_64(SMB_BIG_UINT *retval,
TDB_CONTEXT *tdb,
int key_part1,
const char *key_part2)
memset(buf, 0, PERFCOUNT_MAX_LEN);
memcpy(buf, data.dptr, data.dsize);
- free(data.dptr);
+ SAFE_FREE(data.dptr);
- *retval = strtoll(buf, NULL, 0);
+ *retval = atof(buf);
return True;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_init_data_block_perf(PERF_DATA_BLOCK *block,
TDB_CONTEXT *names)
{
- unsigned long long PerfFreq, PerfTime, PerfTime100nSec;
+ SMB_BIG_UINT PerfFreq, PerfTime, PerfTime100nSec;
TDB_CONTEXT *counters;
- BOOL status;
- pstring fname;
-
- status = False;
-
- pstrcpy(fname, lp_counters_dir());
- pstrcat(fname, "/data.tdb");
+ BOOL status = False;
+ const char *fname = counters_directory( DATA_DB );
counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
return True;
}
-static void _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block, prs_struct *ps, TDB_CONTEXT *names)
+/*********************************************************************
+*********************************************************************/
+
+static BOOL _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block,
+ prs_struct *ps, TDB_CONTEXT *names)
{
wpstring temp;
time_t tm;
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)));
+ if (block->data == NULL) {
+ return False;
+ }
memcpy(block->data, temp, block->SystemNameLength);
block->SystemNameOffset = sizeof(PERF_DATA_BLOCK) - sizeof(block->objects) - sizeof(block->data);
block->HeaderLength = block->SystemNameOffset + block->SystemNameLength;
so that the PERF_OBJECT_TYPE struct comes out 64-bit aligned */
block->HeaderLength += 8 - (block->HeaderLength % 8);
- return;
+ return True;
}
+/*********************************************************************
+*********************************************************************/
+
static uint32 _reg_perfcount_perf_data_block_fixup(PERF_DATA_BLOCK *block, prs_struct *ps)
{
int obj, cnt, inst, pad, i;
temp,
char,
counter_data->ByteLength- sizeof(counter_data->ByteLength));
+ if (temp == NULL) {
+ return 0;
+ }
memset(temp, 0, counter_data->ByteLength - sizeof(counter_data->ByteLength));
src_addr = (char *)counter_data->data;
for(i = 0; i < object[obj].NumCounters; i++)
counter_data->data,
uint8,
counter_data->ByteLength - sizeof(counter_data->ByteLength) + pad);
+ if (counter_data->data == NULL) {
+ return 0;
+ }
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;
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;
+ uint32 buffer_size = 0;
+ const char *fname = counters_directory( NAMES_DB );
TDB_CONTEXT *names;
- int retval;
-
- pstrcpy(fname, lp_counters_dir());
- pstrcat(fname, "/names.tdb");
-
+ int retval = 0;
+
names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
if(names == NULL)
return 0;
}
- _reg_perfcount_init_data_block(block, ps, names);
+ if (!_reg_perfcount_init_data_block(block, ps, names)) {
+ DEBUG(0, ("_reg_perfcount_init_data_block failed\n"));
+ tdb_close(names);
+ return 0;
+ }
- last_counter = reg_perfcount_get_last_counter(base_index);
+ reg_perfcount_get_last_counter(base_index);
if(object_ids == NULL)
{
tdb_close(names);
+ if (retval == -1) {
+ return 0;
+ }
+
return buffer_size + block->HeaderLength;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_marshall_perf_data_block(prs_struct *ps, PERF_DATA_BLOCK block, int depth)
{
int i;
return True;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_marshall_perf_counters(prs_struct *ps,
PERF_OBJECT_TYPE object,
int depth)
return True;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_marshall_perf_counter_data(prs_struct *ps,
PERF_COUNTER_BLOCK counter_data,
int depth)
return True;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_marshall_perf_instances(prs_struct *ps,
PERF_OBJECT_TYPE object,
int depth)
return True;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_marshall_perf_objects(prs_struct *ps, PERF_DATA_BLOCK block, int depth)
{
int obj;
return True;
}
+/*********************************************************************
+*********************************************************************/
+
static BOOL _reg_perfcount_marshall_hkpd(prs_struct *ps, PERF_DATA_BLOCK block)
{
int depth = 0;
}
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
+ *
+ * By 2006-11-23 this link did not work anymore, I found something
+ * promising under
+ * http://msdn2.microsoft.com/en-us/library/aa373105.aspx -- vl
*/
PERF_DATA_BLOCK block;
uint32 buffer_size, base_index;