*
* 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"
+#include "system/filesys.h"
+#include "../librpc/gen_ndr/perfcount.h"
+#include "registry.h"
+#include "reg_perfcount.h"
+#include "../libcli/registry/util_reg.h"
+#include "util_tdb.h"
#undef DBGC_CLASS
-#define DBGC_CLASS DBGC_RPC_SRV
+#define DBGC_CLASS DBGC_REGISTRY
#define PERFCOUNT_MAX_LEN 256
#define NAMES_DB "names.tdb"
#define DATA_DB "data.tdb"
-PERF_OBJECT_TYPE *_reg_perfcount_find_obj(PERF_DATA_BLOCK *block, int objind);
+struct PERF_OBJECT_TYPE *_reg_perfcount_find_obj(struct PERF_DATA_BLOCK *block, int objind);
/*********************************************************************
*********************************************************************/
-static char* counters_directory( const char *dbname )
+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;
-}
+ char *path = NULL;
+ char *ret = NULL;
+ TALLOC_CTX *ctx = talloc_tos();
-/*********************************************************************
-*********************************************************************/
+ path = state_path(PERFCOUNTDIR);
+ if (!directory_create_or_exist(path, 0755)) {
+ return NULL;
+ }
-void perfcount_init_keys( void )
-{
- char *p = lock_path(PERFCOUNTDIR);
+ path = talloc_asprintf(ctx, "%s/%s", PERFCOUNTDIR, dbname);
+ if (!path) {
+ return NULL;
+ }
- /* no registry keys; just create the perfmon directory */
-
- if ( !directory_exist( p, NULL ) )
- mkdir( p, 0755 );
-
- return;
+ ret = talloc_strdup(ctx, state_path(path));
+ TALLOC_FREE(path);
+ return ret;
}
/*********************************************************************
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));
+ DEBUG(2, ("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
and so on.
So last_counter becomes num_counters*2, and last_help will be last_counter+1 */
kbuf = string_tdb_data(key);
- dbuf = tdb_fetch(names, kbuf);
+ dbuf = tdb_fetch_compat(names, kbuf);
if(dbuf.dptr == NULL)
{
DEBUG(1, ("reg_perfcount_get_base_index: failed to find key \'1\' in [%s].\n", fname));
char temp[256];
char *buf1 = *retbuf;
uint32 working_size = 0;
- UNISTR2 name_index, name;
+ DATA_BLOB name_index, name;
+ bool ok;
memset(temp, 0, sizeof(temp));
snprintf(temp, sizeof(temp), "%d", keyval);
kbuf = string_tdb_data(temp);
- dbuf = tdb_fetch(tdb, kbuf);
+ dbuf = tdb_fetch_compat(tdb, kbuf);
if(dbuf.dptr == NULL)
{
/* If a key isn't there, just bypass it -- this really shouldn't
buffer_size = 0;
return buffer_size;
}
- init_unistr2(&name_index, kbuf.dptr, UNI_STR_TERMINATE);
- memcpy(buf1+buffer_size, (char *)name_index.buffer, working_size);
+ ok = push_reg_sz(talloc_tos(), &name_index, (const char *)kbuf.dptr);
+ if (!ok) {
+ buffer_size = 0;
+ return buffer_size;
+ }
+ memcpy(buf1+buffer_size, (char *)name_index.data, working_size);
buffer_size += working_size;
/* Now encode the actual name */
working_size = (dbuf.dsize + 1)*sizeof(uint16);
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);
+ ok = push_reg_sz(talloc_tos(), &name, temp);
+ if (!ok) {
+ buffer_size = 0;
+ return buffer_size;
+ }
+ memcpy(buf1+buffer_size, (char *)name.data, working_size);
buffer_size += working_size;
*retbuf = buf1;
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_isparent(TDB_DATA data)
+static bool _reg_perfcount_isparent(TDB_DATA data)
{
if(data.dsize > 0)
{
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_ischild(TDB_DATA data)
+static bool _reg_perfcount_ischild(TDB_DATA data)
{
if(data.dsize > 0)
{
char buf[PERFCOUNT_MAX_LEN];
_reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, objInd, "inst");
- data = tdb_fetch(names, key);
+ data = tdb_fetch_compat(names, key);
if(data.dptr == NULL)
return (uint32)PERF_NO_INSTANCES;
-
+
memset(buf, 0, PERFCOUNT_MAX_LEN);
memcpy(buf, data.dptr, data.dsize);
SAFE_FREE(data.dptr);
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_add_object(PERF_DATA_BLOCK *block,
- prs_struct *ps,
+static bool _reg_perfcount_add_instance(struct PERF_OBJECT_TYPE *obj,
+ TALLOC_CTX *mem_ctx,
+ int instInd,
+ TDB_CONTEXT *names);
+
+static bool _reg_perfcount_add_object(struct PERF_DATA_BLOCK *block,
+ TALLOC_CTX *mem_ctx,
int num,
TDB_DATA data,
TDB_CONTEXT *names)
{
int i;
- BOOL success = True;
- PERF_OBJECT_TYPE *obj;
+ bool success = True;
+ struct PERF_OBJECT_TYPE *obj;
- block->objects = (PERF_OBJECT_TYPE *)TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ block->objects = (struct PERF_OBJECT_TYPE *)talloc_realloc(mem_ctx,
block->objects,
- PERF_OBJECT_TYPE,
+ struct 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));
+ memset((void *)&(block->objects[block->NumObjectTypes]), 0, sizeof(struct PERF_OBJECT_TYPE));
block->objects[block->NumObjectTypes].ObjectNameTitleIndex = num;
block->objects[block->NumObjectTypes].ObjectNameTitlePointer = 0;
block->objects[block->NumObjectTypes].ObjectHelpTitleIndex = num+1;
block->NumObjectTypes+=1;
for(i = 0; i < (int)obj->NumInstances; i++) {
- success = _reg_perfcount_add_instance(obj, ps, i, names);
+ success = _reg_perfcount_add_instance(obj, mem_ctx, i, names);
}
return success;
/*********************************************************************
*********************************************************************/
-BOOL _reg_perfcount_get_counter_data(TDB_DATA key, TDB_DATA *data)
+static bool _reg_perfcount_get_counter_data(TDB_DATA key, TDB_DATA *data)
{
TDB_CONTEXT *counters;
const char *fname = counters_directory( DATA_DB );
-
+
counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
if(counters == NULL)
return False;
}
- *data = tdb_fetch(counters, key);
-
+ *data = tdb_fetch_compat(counters, key);
+
tdb_close(counters);
return True;
/*********************************************************************
*********************************************************************/
-static uint32 _reg_perfcount_compute_scale(SMB_BIG_INT data)
+static uint32 _reg_perfcount_compute_scale(int64_t data)
{
int scale = 0;
if(data == 0)
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_get_counter_info(PERF_DATA_BLOCK *block,
- prs_struct *ps,
+static bool _reg_perfcount_get_counter_info(struct PERF_DATA_BLOCK *block,
+ TALLOC_CTX *mem_ctx,
int CounterIndex,
- PERF_OBJECT_TYPE *obj,
+ struct 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];
- SMB_BIG_INT data64;
+ int64_t data64;
uint32 counter_size;
obj->counters[obj->NumCounters].DefaultScale = 0;
padding = 0;
_reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, CounterIndex, "type");
- data = tdb_fetch(names, key);
+ data = tdb_fetch_compat(names, key);
if(data.dptr == NULL)
{
DEBUG(3, ("_reg_perfcount_get_counter_info: No type data for counter [%d].\n", CounterIndex));
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)
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((SMB_BIG_INT)data32);
+ obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale((int64_t)data32);
else
obj->counters[obj->NumCounters].DefaultScale = 0;
dbuf[0] = data32;
SAFE_FREE(data.dptr);
obj->counter_data.ByteLength += dsize + padding;
- obj->counter_data.data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ obj->counter_data.data = talloc_realloc(mem_ctx,
obj->counter_data.data,
uint8,
obj->counter_data.ByteLength - sizeof(uint32));
/*********************************************************************
*********************************************************************/
-PERF_OBJECT_TYPE *_reg_perfcount_find_obj(PERF_DATA_BLOCK *block, int objind)
+struct PERF_OBJECT_TYPE *_reg_perfcount_find_obj(struct PERF_DATA_BLOCK *block, int objind)
{
int i;
- PERF_OBJECT_TYPE *obj = NULL;
+ struct PERF_OBJECT_TYPE *obj = NULL;
for(i = 0; i < block->NumObjectTypes; i++)
{
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_add_counter(PERF_DATA_BLOCK *block,
- prs_struct *ps,
+static bool _reg_perfcount_add_counter(struct PERF_DATA_BLOCK *block,
+ TALLOC_CTX *mem_ctx,
int num,
TDB_DATA data,
TDB_CONTEXT *names)
{
char *begin, *end, *start, *stop;
int parent;
- PERF_OBJECT_TYPE *obj;
- BOOL success = True;
+ struct PERF_OBJECT_TYPE *obj;
+ bool success = True;
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, ']');
+ begin = strchr(buf, '[');
+ end = strchr(buf, ']');
if(begin == NULL || end == NULL)
return False;
start = begin+1;
while(start < end) {
- stop = index(start, ',');
+ stop = strchr(start, ',');
if(stop == NULL)
stop = end;
*stop = '\0';
parent, num));
return False;
}
- obj->counters = (PERF_COUNTER_DEFINITION *)TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ obj->counters = (struct PERF_COUNTER_DEFINITION *)talloc_realloc(mem_ctx,
obj->counters,
- PERF_COUNTER_DEFINITION,
+ struct PERF_COUNTER_DEFINITION,
obj->NumCounters+1);
if(obj->counters == NULL)
return False;
- memset((void *)&(obj->counters[obj->NumCounters]), 0, sizeof(PERF_COUNTER_DEFINITION));
+ memset((void *)&(obj->counters[obj->NumCounters]), 0, sizeof(struct 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->counters[obj->NumCounters].ByteLength = sizeof(struct PERF_COUNTER_DEFINITION);
+ success = _reg_perfcount_get_counter_info(block, mem_ctx, 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 */
/*********************************************************************
*********************************************************************/
-BOOL _reg_perfcount_get_instance_info(PERF_INSTANCE_DEFINITION *inst,
- prs_struct *ps,
- int instId,
- PERF_OBJECT_TYPE *obj,
- TDB_CONTEXT *names)
+static bool _reg_perfcount_get_instance_info(struct PERF_INSTANCE_DEFINITION *inst,
+ TALLOC_CTX *mem_ctx,
+ int instId,
+ struct PERF_OBJECT_TYPE *obj,
+ TDB_CONTEXT *names)
{
TDB_DATA key, data;
char buf[PERFCOUNT_MAX_LEN], temp[PERFCOUNT_MAX_LEN];
- wpstring name;
+ smb_ucs2_t *name = NULL;
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 (!_reg_perfcount_get_counter_data(key, &data)) {
+ DEBUG(3, ("_reg_perfcount_get_counter_data failed\n"));
+ return false;
+ }
if(data.dptr == NULL)
{
DEBUG(3, ("_reg_perfcount_get_instance_info: No instance data for instance [%s].\n",
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 = talloc_realloc(mem_ctx,
inst->counter_data.data,
uint8,
data.dsize);
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);
+ data = tdb_fetch_compat(names, key);
if(data.dptr == NULL)
{
/* Not actually an error, but possibly unintended? -- just logging FYI */
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,
+ memcpy(buf, data.dptr, MIN(PERFCOUNT_MAX_LEN-1,data.dsize));
+ buf[PERFCOUNT_MAX_LEN-1] = '\0';
+ inst->NameLength = rpcstr_push_talloc(mem_ctx, &name, buf);
+ if (inst->NameLength == (uint32_t)-1 || !name) {
+ SAFE_FREE(data.dptr);
+ return False;
+ }
+ inst->data = talloc_realloc(mem_ctx,
inst->data,
uint8,
inst->NameLength);
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 = talloc_realloc(mem_ctx,
inst->data,
uint8,
inst->NameLength + pad);
/*********************************************************************
*********************************************************************/
-BOOL _reg_perfcount_add_instance(PERF_OBJECT_TYPE *obj,
- prs_struct *ps,
- int instInd,
- TDB_CONTEXT *names)
+static bool _reg_perfcount_add_instance(struct PERF_OBJECT_TYPE *obj,
+ TALLOC_CTX *mem_ctx,
+ int instInd,
+ TDB_CONTEXT *names)
{
- PERF_INSTANCE_DEFINITION *inst;
+ struct PERF_INSTANCE_DEFINITION *inst;
if(obj->instances == NULL) {
- obj->instances = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ obj->instances = talloc_realloc(mem_ctx,
obj->instances,
- PERF_INSTANCE_DEFINITION,
+ struct PERF_INSTANCE_DEFINITION,
obj->NumInstances);
}
if(obj->instances == NULL)
return False;
-
- memset(&(obj->instances[instInd]), 0, sizeof(PERF_INSTANCE_DEFINITION));
+
+ memset(&(obj->instances[instInd]), 0, sizeof(struct PERF_INSTANCE_DEFINITION));
inst = &(obj->instances[instInd]);
- return _reg_perfcount_get_instance_info(inst, ps, instInd, obj, names);
+ return _reg_perfcount_get_instance_info(inst, mem_ctx, instInd, obj, names);
}
/*********************************************************************
*********************************************************************/
-static int _reg_perfcount_assemble_global(PERF_DATA_BLOCK *block,
- prs_struct *ps,
+static int _reg_perfcount_assemble_global(struct PERF_DATA_BLOCK *block,
+ TALLOC_CTX *mem_ctx,
int base_index,
TDB_CONTEXT *names)
{
- BOOL success;
+ bool success;
int i, j, retval = 0;
char keybuf[PERFCOUNT_MAX_LEN];
TDB_DATA key, data;
{
j = i*2;
_reg_perfcount_make_key(&key, keybuf, PERFCOUNT_MAX_LEN, j, "rel");
- data = tdb_fetch(names, key);
+ data = tdb_fetch_compat(names, key);
if(data.dptr != NULL)
{
if(_reg_perfcount_isparent(data))
- success = _reg_perfcount_add_object(block, ps, j, data, names);
+ success = _reg_perfcount_add_object(block, mem_ctx, j, data, names);
else if(_reg_perfcount_ischild(data))
- success = _reg_perfcount_add_counter(block, ps, j, data, names);
+ success = _reg_perfcount_add_counter(block, mem_ctx, j, data, names);
else
{
DEBUG(3, ("Bogus relationship [%s] for counter [%d].\n", data.dptr, j));
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_get_64(SMB_BIG_UINT *retval,
+static bool _reg_perfcount_get_64(uint64_t *retval,
TDB_CONTEXT *tdb,
int key_part1,
const char *key_part2)
_reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, key_part1, key_part2);
- data = tdb_fetch(tdb, key);
+ data = tdb_fetch_compat(tdb, key);
if(data.dptr == NULL)
{
DEBUG(3,("_reg_perfcount_get_64: No data found for key [%s].\n", key.dptr));
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_init_data_block_perf(PERF_DATA_BLOCK *block,
+static bool _reg_perfcount_init_data_block_perf(struct PERF_DATA_BLOCK *block,
TDB_CONTEXT *names)
{
- SMB_BIG_UINT PerfFreq, PerfTime, PerfTime100nSec;
+ uint64_t PerfFreq, PerfTime, PerfTime100nSec;
TDB_CONTEXT *counters;
- BOOL status = False;
+ bool status = False;
const char *fname = counters_directory( DATA_DB );
-
+
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)
{
return True;
}
+/*******************************************************************
+********************************************************************/
+
+static bool make_systemtime(struct SYSTEMTIME *systime, struct tm *unixtime)
+{
+ systime->year=unixtime->tm_year+1900;
+ systime->month=unixtime->tm_mon+1;
+ systime->dayofweek=unixtime->tm_wday;
+ systime->day=unixtime->tm_mday;
+ systime->hour=unixtime->tm_hour;
+ systime->minute=unixtime->tm_min;
+ systime->second=unixtime->tm_sec;
+ systime->milliseconds=0;
+
+ return True;
+}
+
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block,
- prs_struct *ps, TDB_CONTEXT *names)
+static bool _reg_perfcount_init_data_block(struct PERF_DATA_BLOCK *block,
+ TALLOC_CTX *mem_ctx, TDB_CONTEXT *names,
+ bool bigendian_data)
{
- wpstring temp;
+ smb_ucs2_t *temp = NULL;
+ TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
time_t tm;
-
- memset(temp, 0, sizeof(temp));
- rpcstr_push((void *)temp, "PERF", sizeof(temp), STR_TERMINATE);
+ size_t sz;
+
+ sz = rpcstr_push_talloc(tmp_ctx, &temp, "PERF");
+ if ((sz == -1) || (temp == NULL)) {
+ goto err_out;
+ }
memcpy(block->Signature, temp, strlen_w(temp) *2);
- if(ps->bigendian_data == RPC_BIG_ENDIAN)
+ if(bigendian_data)
block->LittleEndian = 0;
else
block->LittleEndian = 1;
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);
+
+ sz = rpcstr_push_talloc(tmp_ctx, &temp, lp_netbios_name());
+ if ((sz == -1) || (temp == NULL)) {
+ goto err_out;
+ }
block->SystemNameLength = (strlen_w(temp) * 2) + 2;
- block->data = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint8, block->SystemNameLength + (8 - (block->SystemNameLength % 8)));
+ block->data = talloc_zero_array(mem_ctx, uint8, block->SystemNameLength + (8 - (block->SystemNameLength % 8)));
if (block->data == NULL) {
- return False;
+ goto err_out;
}
memcpy(block->data, temp, block->SystemNameLength);
- block->SystemNameOffset = sizeof(PERF_DATA_BLOCK) - sizeof(block->objects) - sizeof(block->data);
+ block->SystemNameOffset = sizeof(struct 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);
+ talloc_free(tmp_ctx);
- return True;
+ return true;
+
+err_out:
+ talloc_free(tmp_ctx);
+ return false;
}
/*********************************************************************
*********************************************************************/
-static uint32 _reg_perfcount_perf_data_block_fixup(PERF_DATA_BLOCK *block, prs_struct *ps)
+static uint32 _reg_perfcount_perf_data_block_fixup(struct PERF_DATA_BLOCK *block, TALLOC_CTX *mem_ctx)
{
int obj, cnt, inst, pad, i;
- PERF_OBJECT_TYPE *object;
- PERF_INSTANCE_DEFINITION *instance;
- PERF_COUNTER_DEFINITION *counter;
- PERF_COUNTER_BLOCK *counter_data;
+ struct PERF_OBJECT_TYPE *object;
+ struct PERF_INSTANCE_DEFINITION *instance;
+ struct PERF_COUNTER_DEFINITION *counter;
+ struct PERF_COUNTER_BLOCK *counter_data;
char *temp = NULL, *src_addr, *dst_addr;
block->TotalByteLength = 0;
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 = talloc_realloc(mem_ctx,
temp,
char,
counter_data->ByteLength- sizeof(counter_data->ByteLength));
{
pad = 8 - pad;
}
- counter_data->data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
+ counter_data->data = talloc_realloc(mem_ctx,
counter_data->data,
uint8,
counter_data->ByteLength - sizeof(counter_data->ByteLength) + pad);
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 = talloc_realloc(mem_ctx,
object[obj].counter_data.data,
uint8,
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].HeaderLength = sizeof(*object) - (sizeof(counter) + sizeof(instance) + sizeof(struct PERF_COUNTER_BLOCK));
object[obj].TotalByteLength += object[obj].HeaderLength;
object[obj].DefinitionLength += object[obj].HeaderLength;
-
+
block->TotalByteLength += object[obj].TotalByteLength;
}
/*********************************************************************
*********************************************************************/
-uint32 reg_perfcount_get_perf_data_block(uint32 base_index,
- prs_struct *ps,
- PERF_DATA_BLOCK *block,
- const char *object_ids)
+static uint32 reg_perfcount_get_perf_data_block(uint32 base_index,
+ TALLOC_CTX *mem_ctx,
+ struct PERF_DATA_BLOCK *block,
+ const char *object_ids,
+ bool bigendian_data)
{
uint32 buffer_size = 0;
const char *fname = counters_directory( NAMES_DB );
TDB_CONTEXT *names;
int retval = 0;
-
+
names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
if(names == NULL)
return 0;
}
- if (!_reg_perfcount_init_data_block(block, ps, names)) {
+ if (!_reg_perfcount_init_data_block(block, mem_ctx, names, bigendian_data)) {
DEBUG(0, ("_reg_perfcount_init_data_block failed\n"));
tdb_close(names);
return 0;
}
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);
+ retval = _reg_perfcount_assemble_global(block, mem_ctx, 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);
+ retval = _reg_perfcount_assemble_global(block, mem_ctx, base_index, names);
}
- buffer_size = _reg_perfcount_perf_data_block_fixup(block, ps);
+ buffer_size = _reg_perfcount_perf_data_block_fixup(block, mem_ctx);
tdb_close(names);
return buffer_size + block->HeaderLength;
}
+/*******************************************************************
+********************************************************************/
+
+static bool smb_io_system_time(const char *desc, prs_struct *ps, int depth, struct SYSTEMTIME *systime)
+{
+ if(!prs_uint16("year", ps, depth, &systime->year))
+ return False;
+ if(!prs_uint16("month", ps, depth, &systime->month))
+ return False;
+ if(!prs_uint16("dayofweek", ps, depth, &systime->dayofweek))
+ return False;
+ if(!prs_uint16("day", ps, depth, &systime->day))
+ return False;
+ if(!prs_uint16("hour", ps, depth, &systime->hour))
+ return False;
+ if(!prs_uint16("minute", ps, depth, &systime->minute))
+ return False;
+ if(!prs_uint16("second", ps, depth, &systime->second))
+ return False;
+ if(!prs_uint16("milliseconds", ps, depth, &systime->milliseconds))
+ return False;
+
+ return True;
+}
+
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_marshall_perf_data_block(prs_struct *ps, PERF_DATA_BLOCK block, int depth)
+static bool _reg_perfcount_marshall_perf_data_block(prs_struct *ps, struct PERF_DATA_BLOCK block, int depth)
{
int i;
prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_data_block");
return False;
if(!prs_uint32("DefaultObject", ps, depth, &block.DefaultObject))
return False;
- if(!spoolss_io_system_time("SystemTime", ps, depth, &block.SystemTime))
+ if(!smb_io_system_time("SystemTime", ps, depth, &block.SystemTime))
return False;
if(!prs_uint32("Padding", ps, depth, &block.Padding))
return False;
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_marshall_perf_counters(prs_struct *ps,
- PERF_OBJECT_TYPE object,
+static bool _reg_perfcount_marshall_perf_counters(prs_struct *ps,
+ struct PERF_OBJECT_TYPE object,
int depth)
{
int cnt;
- PERF_COUNTER_DEFINITION counter;
+ struct 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];
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_marshall_perf_counter_data(prs_struct *ps,
- PERF_COUNTER_BLOCK counter_data,
+static bool _reg_perfcount_marshall_perf_counter_data(prs_struct *ps,
+ struct 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)))
/*********************************************************************
*********************************************************************/
-static BOOL _reg_perfcount_marshall_perf_instances(prs_struct *ps,
- PERF_OBJECT_TYPE object,
+static bool _reg_perfcount_marshall_perf_instances(prs_struct *ps,
+ struct PERF_OBJECT_TYPE object,
int depth)
{
- PERF_INSTANCE_DEFINITION instance;
+ struct PERF_INSTANCE_DEFINITION instance;
int inst;
prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_instances");
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)
+static bool _reg_perfcount_marshall_perf_objects(prs_struct *ps, struct PERF_DATA_BLOCK block, int depth)
{
int obj;
- PERF_OBJECT_TYPE object;
-
+ struct PERF_OBJECT_TYPE object;
+
prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_objects");
depth++;
/*********************************************************************
*********************************************************************/
-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, const char *object_ids)
{
/*
* promising under
* http://msdn2.microsoft.com/en-us/library/aa373105.aspx -- vl
*/
- PERF_DATA_BLOCK block;
+ struct 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);
+ buffer_size = reg_perfcount_get_perf_data_block(base_index, ps->mem_ctx, &block, object_ids, ps->bigendian_data);
if(buffer_size < max_buf_size)
{
*outbuf_len = buffer_size;
- if(_reg_perfcount_marshall_hkpd(ps, block) == True)
- return WERR_OK;
- else
+
+ if (!_reg_perfcount_marshall_perf_data_block(ps, block, 0))
return WERR_NOMEM;
+
+ if (!_reg_perfcount_marshall_perf_objects(ps, block, 0))
+ return WERR_NOMEM;
+
+ return WERR_OK;
}
else
{
*outbuf_len = max_buf_size;
- _reg_perfcount_marshall_perf_data_block(ps, block, 0);
+ if (!_reg_perfcount_marshall_perf_data_block(ps, block, 0))
+ return WERR_NOMEM;
+
return WERR_INSUFFICIENT_BUFFER;
}
}