TALLOC_CTX *ctx = talloc_tos();
path = state_path(PERFCOUNTDIR);
- if (!directory_exist(path)) {
- mkdir(path, 0755);
+ if (!directory_create_or_exist(path, 0755)) {
+ return NULL;
}
path = talloc_asprintf(ctx, "%s/%s", PERFCOUNTDIR, dbname);
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 *buf1 = *retbuf;
uint32 working_size = 0;
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;
}
- push_reg_sz(talloc_tos(), &name_index, (const char *)kbuf.dptr);
+ 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 */
memset(temp, 0, sizeof(temp));
memcpy(temp, dbuf.dptr, dbuf.dsize);
SAFE_FREE(dbuf.dptr);
- push_reg_sz(talloc_tos(), &name, temp);
+ 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;
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;
return False;
}
- *data = tdb_fetch(counters, key);
+ *data = tdb_fetch_compat(counters, key);
tdb_close(counters);
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));
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 */
{
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))
_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));
bool bigendian_data)
{
smb_ucs2_t *temp = NULL;
+ TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
time_t tm;
+ size_t sz;
- if (rpcstr_push_talloc(mem_ctx, &temp, "PERF")==(size_t)-1) {
- return false;
- }
- if (!temp) {
- return false;
+ sz = rpcstr_push_talloc(tmp_ctx, &temp, "PERF");
+ if ((sz == -1) || (temp == NULL)) {
+ goto err_out;
}
memcpy(block->Signature, temp, strlen_w(temp) *2);
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, lp_netbios_name(), 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(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(struct PERF_DATA_BLOCK) - sizeof(block->objects) - sizeof(block->data);
/* 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;
}
/*********************************************************************