lib: directory_create_or_exist() does not use "uid" parameter
[amitay/samba.git] / source3 / registry / reg_perfcount.c
index cac0e5b4c3bbf5c31b562aea5baae9c6ec8cd08b..b875067721d1d880994fb451a162e2123f648527 100644 (file)
@@ -48,8 +48,8 @@ static char *counters_directory(const char *dbname)
        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);
@@ -77,7 +77,7 @@ uint32 reg_perfcount_get_base_index(void)
        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
@@ -95,7 +95,7 @@ uint32 reg_perfcount_get_base_index(void)
           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));
@@ -158,11 +158,12 @@ static uint32 _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,
        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 
@@ -178,7 +179,11 @@ static uint32 _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,
                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 */
@@ -191,7 +196,11 @@ static uint32 _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,
        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;
 
@@ -347,7 +356,7 @@ static uint32 _reg_perfcount_get_numinst(int objInd, TDB_CONTEXT *names)
        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;
@@ -421,7 +430,7 @@ static bool _reg_perfcount_get_counter_data(TDB_DATA key, TDB_DATA *data)
                return False;
        }    
 
-       *data = tdb_fetch(counters, key);
+       *data = tdb_fetch_compat(counters, key);
 
        tdb_close(counters);
 
@@ -488,7 +497,7 @@ static bool _reg_perfcount_get_counter_info(struct PERF_DATA_BLOCK *block,
        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));
@@ -701,7 +710,7 @@ static bool _reg_perfcount_get_instance_info(struct PERF_INSTANCE_DEFINITION *in
        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 */
@@ -793,7 +802,7 @@ static int _reg_perfcount_assemble_global(struct PERF_DATA_BLOCK *block,
        {
                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))
@@ -831,7 +840,7 @@ static bool _reg_perfcount_get_64(uint64_t *retval,
 
        _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));
@@ -919,13 +928,13 @@ static bool _reg_perfcount_init_data_block(struct PERF_DATA_BLOCK *block,
                                           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);
 
@@ -942,12 +951,15 @@ static bool _reg_perfcount_init_data_block(struct PERF_DATA_BLOCK *block,
        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(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);
@@ -955,8 +967,13 @@ static bool _reg_perfcount_init_data_block(struct PERF_DATA_BLOCK *block,
        /* 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;
 }
 
 /*********************************************************************