1 | /*
|
---|
2 | * Unix SMB/CIFS implementation.
|
---|
3 | * Virtual Windows Registry Layer
|
---|
4 | * Copyright (C) Gerald Carter 2002-2005
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | */
|
---|
20 |
|
---|
21 | /* Implementation of registry frontend view functions. */
|
---|
22 |
|
---|
23 | #include "includes.h"
|
---|
24 |
|
---|
25 | #undef DBGC_CLASS
|
---|
26 | #define DBGC_CLASS DBGC_RPC_SRV
|
---|
27 |
|
---|
28 | struct reg_dyn_values {
|
---|
29 | const char *path;
|
---|
30 | int (*fetch_values) ( REGVAL_CTR *val );
|
---|
31 | };
|
---|
32 |
|
---|
33 | /***********************************************************************
|
---|
34 | ***********************************************************************/
|
---|
35 |
|
---|
36 | static int netlogon_params( REGVAL_CTR *regvals )
|
---|
37 | {
|
---|
38 | uint32 dwValue;
|
---|
39 |
|
---|
40 | if ( !pdb_get_account_policy(AP_REFUSE_MACHINE_PW_CHANGE, &dwValue) )
|
---|
41 | dwValue = 0;
|
---|
42 |
|
---|
43 | regval_ctr_addvalue( regvals, "RefusePasswordChange", REG_DWORD,
|
---|
44 | (char*)&dwValue, sizeof(dwValue) );
|
---|
45 |
|
---|
46 | return regval_ctr_numvals( regvals );
|
---|
47 | }
|
---|
48 |
|
---|
49 | /***********************************************************************
|
---|
50 | ***********************************************************************/
|
---|
51 |
|
---|
52 | static int prod_options( REGVAL_CTR *regvals )
|
---|
53 | {
|
---|
54 | const char *value_ascii = "";
|
---|
55 | fstring value;
|
---|
56 | int value_length;
|
---|
57 |
|
---|
58 | switch (lp_server_role()) {
|
---|
59 | case ROLE_DOMAIN_PDC:
|
---|
60 | case ROLE_DOMAIN_BDC:
|
---|
61 | value_ascii = "LanmanNT";
|
---|
62 | break;
|
---|
63 | case ROLE_STANDALONE:
|
---|
64 | value_ascii = "ServerNT";
|
---|
65 | break;
|
---|
66 | case ROLE_DOMAIN_MEMBER:
|
---|
67 | value_ascii = "WinNT";
|
---|
68 | break;
|
---|
69 | }
|
---|
70 |
|
---|
71 | value_length = push_ucs2( value, value, value_ascii, sizeof(value),
|
---|
72 | STR_TERMINATE|STR_NOALIGN );
|
---|
73 | regval_ctr_addvalue( regvals, "ProductType", REG_SZ, value,
|
---|
74 | value_length );
|
---|
75 |
|
---|
76 | return regval_ctr_numvals( regvals );
|
---|
77 | }
|
---|
78 |
|
---|
79 | /***********************************************************************
|
---|
80 | ***********************************************************************/
|
---|
81 |
|
---|
82 | static int tcpip_params( REGVAL_CTR *regvals )
|
---|
83 | {
|
---|
84 | fstring value;
|
---|
85 | int value_length;
|
---|
86 | char *hname;
|
---|
87 | fstring mydomainname;
|
---|
88 |
|
---|
89 |
|
---|
90 | hname = myhostname();
|
---|
91 | value_length = push_ucs2( value, value, hname, sizeof(value), STR_TERMINATE|STR_NOALIGN);
|
---|
92 | regval_ctr_addvalue( regvals, "Hostname",REG_SZ, value, value_length );
|
---|
93 |
|
---|
94 | get_mydnsdomname( mydomainname );
|
---|
95 | value_length = push_ucs2( value, value, mydomainname, sizeof(value), STR_TERMINATE|STR_NOALIGN);
|
---|
96 | regval_ctr_addvalue( regvals, "Domain", REG_SZ, value, value_length );
|
---|
97 |
|
---|
98 | return regval_ctr_numvals( regvals );
|
---|
99 | }
|
---|
100 |
|
---|
101 | /***********************************************************************
|
---|
102 | ***********************************************************************/
|
---|
103 |
|
---|
104 | static int perflib_params( REGVAL_CTR *regvals )
|
---|
105 | {
|
---|
106 | int base_index = -1;
|
---|
107 | int last_counter = -1;
|
---|
108 | int last_help = -1;
|
---|
109 | int version = 0x00010001;
|
---|
110 |
|
---|
111 | base_index = reg_perfcount_get_base_index();
|
---|
112 | regval_ctr_addvalue(regvals, "Base Index", REG_DWORD, (char *)&base_index, sizeof(base_index));
|
---|
113 | last_counter = reg_perfcount_get_last_counter(base_index);
|
---|
114 | regval_ctr_addvalue(regvals, "Last Counter", REG_DWORD, (char *)&last_counter, sizeof(last_counter));
|
---|
115 | last_help = reg_perfcount_get_last_help(last_counter);
|
---|
116 | regval_ctr_addvalue(regvals, "Last Help", REG_DWORD, (char *)&last_help, sizeof(last_help));
|
---|
117 | regval_ctr_addvalue(regvals, "Version", REG_DWORD, (char *)&version, sizeof(version));
|
---|
118 |
|
---|
119 | return regval_ctr_numvals( regvals );
|
---|
120 | }
|
---|
121 |
|
---|
122 | /***********************************************************************
|
---|
123 | ***********************************************************************/
|
---|
124 |
|
---|
125 | static int perflib_009_params( REGVAL_CTR *regvals )
|
---|
126 | {
|
---|
127 | int base_index;
|
---|
128 | int buffer_size;
|
---|
129 | char *buffer = NULL;
|
---|
130 |
|
---|
131 | base_index = reg_perfcount_get_base_index();
|
---|
132 | buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
|
---|
133 | regval_ctr_addvalue(regvals, "Counter", REG_MULTI_SZ, buffer, buffer_size);
|
---|
134 | if(buffer_size > 0)
|
---|
135 | SAFE_FREE(buffer);
|
---|
136 | buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
|
---|
137 | regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, buffer, buffer_size);
|
---|
138 | if(buffer_size > 0)
|
---|
139 | SAFE_FREE(buffer);
|
---|
140 |
|
---|
141 | return regval_ctr_numvals( regvals );
|
---|
142 | }
|
---|
143 |
|
---|
144 | /***********************************************************************
|
---|
145 | ***********************************************************************/
|
---|
146 |
|
---|
147 | static int hkpt_params( REGVAL_CTR *regvals )
|
---|
148 | {
|
---|
149 | uint32 base_index;
|
---|
150 | uint32 buffer_size;
|
---|
151 | char *buffer = NULL;
|
---|
152 |
|
---|
153 | /* This is ALMOST the same as perflib_009_params, but HKPT has
|
---|
154 | a "Counters" entry instead of a "Counter" key. <Grrrr> */
|
---|
155 |
|
---|
156 | base_index = reg_perfcount_get_base_index();
|
---|
157 | buffer_size = reg_perfcount_get_counter_names(base_index, &buffer);
|
---|
158 | regval_ctr_addvalue(regvals, "Counters", REG_MULTI_SZ, buffer, buffer_size);
|
---|
159 |
|
---|
160 | if(buffer_size > 0)
|
---|
161 | SAFE_FREE(buffer);
|
---|
162 |
|
---|
163 | buffer_size = reg_perfcount_get_counter_help(base_index, &buffer);
|
---|
164 | regval_ctr_addvalue(regvals, "Help", REG_MULTI_SZ, buffer, buffer_size);
|
---|
165 | if(buffer_size > 0)
|
---|
166 | SAFE_FREE(buffer);
|
---|
167 |
|
---|
168 | return regval_ctr_numvals( regvals );
|
---|
169 | }
|
---|
170 |
|
---|
171 | /***********************************************************************
|
---|
172 | ***********************************************************************/
|
---|
173 |
|
---|
174 | static int current_version( REGVAL_CTR *values )
|
---|
175 | {
|
---|
176 | const char *sysroot_string = "c:\\Windows";
|
---|
177 | fstring sysversion;
|
---|
178 | fstring value;
|
---|
179 | uint32 value_length;
|
---|
180 |
|
---|
181 | value_length = push_ucs2( value, value, sysroot_string, sizeof(value),
|
---|
182 | STR_TERMINATE|STR_NOALIGN );
|
---|
183 | regval_ctr_addvalue( values, "SystemRoot", REG_SZ, value, value_length );
|
---|
184 |
|
---|
185 | fstr_sprintf( sysversion, "%d.%d", lp_major_announce_version(), lp_minor_announce_version() );
|
---|
186 | value_length = push_ucs2( value, value, sysversion, sizeof(value),
|
---|
187 | STR_TERMINATE|STR_NOALIGN );
|
---|
188 | regval_ctr_addvalue( values, "CurrentVersion", REG_SZ, value, value_length );
|
---|
189 |
|
---|
190 |
|
---|
191 | return regval_ctr_numvals( values );
|
---|
192 | }
|
---|
193 |
|
---|
194 |
|
---|
195 | /***********************************************************************
|
---|
196 | Structure holding the registry paths and pointers to the value
|
---|
197 | enumeration functions
|
---|
198 | ***********************************************************************/
|
---|
199 |
|
---|
200 | static struct reg_dyn_values dynamic_values[] = {
|
---|
201 | { "HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/NETLOGON/PARAMETERS", &netlogon_params },
|
---|
202 | { "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRODUCTOPTIONS", &prod_options },
|
---|
203 | { "HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/TCPIP/PARAMETERS", &tcpip_params },
|
---|
204 | { "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PERFLIB", &perflib_params },
|
---|
205 | { "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PERFLIB/009", &perflib_009_params },
|
---|
206 | { "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION", ¤t_version },
|
---|
207 | { "HKPT", &hkpt_params },
|
---|
208 | { NULL, NULL }
|
---|
209 | };
|
---|
210 |
|
---|
211 | /***********************************************************************
|
---|
212 | ***********************************************************************/
|
---|
213 |
|
---|
214 | int fetch_dynamic_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
|
---|
215 | {
|
---|
216 | int i;
|
---|
217 | pstring path;
|
---|
218 |
|
---|
219 | pstrcpy( path, key->name );
|
---|
220 | normalize_reg_path( path );
|
---|
221 |
|
---|
222 | for ( i=0; dynamic_values[i].path; i++ ) {
|
---|
223 | if ( strcmp( path, dynamic_values[i].path ) == 0 )
|
---|
224 | return dynamic_values[i].fetch_values( val );
|
---|
225 | }
|
---|
226 |
|
---|
227 | return -1;
|
---|
228 | }
|
---|
229 |
|
---|
230 | /***********************************************************************
|
---|
231 | ***********************************************************************/
|
---|
232 |
|
---|
233 | BOOL check_dynamic_reg_values( REGISTRY_KEY *key )
|
---|
234 | {
|
---|
235 | int i;
|
---|
236 | pstring path;
|
---|
237 |
|
---|
238 | pstrcpy( path, key->name );
|
---|
239 | normalize_reg_path( path );
|
---|
240 |
|
---|
241 | for ( i=0; dynamic_values[i].path; i++ ) {
|
---|
242 | /* can't write to dynamic keys */
|
---|
243 | if ( strcmp( path, dynamic_values[i].path ) == 0 )
|
---|
244 | return True;
|
---|
245 | }
|
---|
246 |
|
---|
247 | return False;
|
---|
248 | }
|
---|
249 |
|
---|