registry: check for existence of key in regdb_get_secdesc() before proceeding.
[kai/samba.git] / source3 / registry / reg_backend_perflib.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Virtual Windows Registry Layer
4  *  Copyright (C) Gerald Carter     2002-2005
5  *  Copyright (C) Michael Adam      2008
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20
21 /*
22  * perflib registry backend.
23  *
24  * This is a virtual overlay, dynamically presenting perflib values.
25  */
26
27 #include "includes.h"
28
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_REGISTRY
31
32 extern REGISTRY_OPS regdb_ops;
33
34 #define KEY_PERFLIB_NORM        "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PERFLIB"
35 #define KEY_PERFLIB_009_NORM    "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PERFLIB/009"
36
37 static int perflib_params( REGVAL_CTR *regvals )
38 {
39         int base_index = -1;
40         int last_counter = -1;
41         int last_help = -1;
42         int version = 0x00010001;
43         
44         base_index = reg_perfcount_get_base_index();
45         regval_ctr_addvalue(regvals, "Base Index", REG_DWORD, (char *)&base_index, sizeof(base_index));
46         last_counter = reg_perfcount_get_last_counter(base_index);
47         regval_ctr_addvalue(regvals, "Last Counter", REG_DWORD, (char *)&last_counter, sizeof(last_counter));
48         last_help = reg_perfcount_get_last_help(last_counter);
49         regval_ctr_addvalue(regvals, "Last Help", REG_DWORD, (char *)&last_help, sizeof(last_help));
50         regval_ctr_addvalue(regvals, "Version", REG_DWORD, (char *)&version, sizeof(version));
51
52         return regval_ctr_numvals( regvals );
53 }
54
55 static int perflib_009_params( REGVAL_CTR *regvals )
56 {
57         int base_index;
58         int buffer_size;
59         char *buffer = NULL;
60
61         base_index = reg_perfcount_get_base_index();
62         buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
63         regval_ctr_addvalue(regvals, "Counter", REG_MULTI_SZ, buffer, buffer_size);
64         if(buffer_size > 0)
65                 SAFE_FREE(buffer);
66         buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
67         regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, buffer, buffer_size);
68         if(buffer_size > 0)
69                 SAFE_FREE(buffer);
70         
71         return regval_ctr_numvals( regvals );
72 }
73
74 static int perflib_fetch_values(const char *key, REGVAL_CTR *regvals)
75 {
76         char *path = NULL;
77         TALLOC_CTX *ctx = talloc_tos();
78
79         path = talloc_strdup(ctx, key);
80         if (path == NULL) {
81                 return -1;
82         }
83         path = normalize_reg_path(ctx, path);
84         if (path == NULL) {
85                 return -1;
86         }
87
88         if (strncmp(path, KEY_PERFLIB_NORM, strlen(path)) == 0) {
89                 return perflib_params(regvals);
90         } else if (strncmp(path, KEY_PERFLIB_009_NORM, strlen(path)) == 0) {
91                 return perflib_009_params(regvals);
92         } else {
93                 return 0;
94         }
95 }
96
97 static int perflib_fetch_subkeys(const char *key,
98                                          REGSUBKEY_CTR *subkey_ctr)
99 {
100         return regdb_ops.fetch_subkeys(key, subkey_ctr);
101 }
102
103 REGISTRY_OPS perflib_reg_ops = {
104         .fetch_values = perflib_fetch_values,
105         .fetch_subkeys = perflib_fetch_subkeys,
106 };