2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Gerald Carter 2002.
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.
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.
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.
21 /* Implementation of internal registry database functions. */
26 #define DBGC_CLASS DBGC_RPC_SRV
28 static TDB_CONTEXT
*tdb_reg
;
31 /***********************************************************************
32 Open the registry data in the tdb
33 ***********************************************************************/
35 static BOOL
init_registry_data( void )
38 REGSUBKEY_CTR subkeys
;
40 ZERO_STRUCTP( &subkeys
);
42 regsubkey_ctr_init( &subkeys
);
44 /* HKEY_LOCAL_MACHINE */
46 regsubkey_ctr_init( &subkeys
);
47 pstrcpy( keyname
, KEY_HKLM
);
48 regsubkey_ctr_addkey( &subkeys
, "SYSTEM" );
49 if ( !regdb_store_reg_keys( keyname
, &subkeys
))
51 regsubkey_ctr_destroy( &subkeys
);
53 regsubkey_ctr_init( &subkeys
);
54 pstrcpy( keyname
, KEY_HKLM
);
55 pstrcat( keyname
, "/SYSTEM" );
56 regsubkey_ctr_addkey( &subkeys
, "CurrentControlSet" );
57 if ( !regdb_store_reg_keys( keyname
, &subkeys
))
59 regsubkey_ctr_destroy( &subkeys
);
61 regsubkey_ctr_init( &subkeys
);
62 pstrcpy( keyname
, KEY_HKLM
);
63 pstrcat( keyname
, "/SYSTEM/CurrentControlSet" );
64 regsubkey_ctr_addkey( &subkeys
, "Control" );
65 regsubkey_ctr_addkey( &subkeys
, "services" );
66 if ( !regdb_store_reg_keys( keyname
, &subkeys
))
68 regsubkey_ctr_destroy( &subkeys
);
70 regsubkey_ctr_init( &subkeys
);
71 pstrcpy( keyname
, KEY_HKLM
);
72 pstrcat( keyname
, "/SYSTEM/CurrentControlSet/Control" );
73 regsubkey_ctr_addkey( &subkeys
, "Print" );
74 regsubkey_ctr_addkey( &subkeys
, "ProductOptions" );
75 if ( !regdb_store_reg_keys( keyname
, &subkeys
))
77 regsubkey_ctr_destroy( &subkeys
);
79 pstrcpy( keyname
, KEY_HKLM
);
80 pstrcat( keyname
, "/SYSTEM/CurrentControlSet/Control/ProductOptions" );
81 if ( !regdb_store_reg_keys( keyname
, &subkeys
))
84 regsubkey_ctr_init( &subkeys
);
85 pstrcpy( keyname
, KEY_HKLM
);
86 pstrcat( keyname
, "/SYSTEM/CurrentControlSet/services" );
87 regsubkey_ctr_addkey( &subkeys
, "Netlogon" );
88 if ( !regdb_store_reg_keys( keyname
, &subkeys
))
90 regsubkey_ctr_destroy( &subkeys
);
92 regsubkey_ctr_init( &subkeys
);
93 pstrcpy( keyname
, KEY_HKLM
);
94 pstrcat( keyname
, "/SYSTEM/CurrentControlSet/services/Netlogon" );
95 regsubkey_ctr_addkey( &subkeys
, "parameters" );
96 if ( !regdb_store_reg_keys( keyname
, &subkeys
))
98 regsubkey_ctr_destroy( &subkeys
);
100 pstrcpy( keyname
, KEY_HKLM
);
101 pstrcat( keyname
, "/SYSTEM/CurrentControlSet/services/Netlogon/parameters" );
102 if ( !regdb_store_reg_keys( keyname
, &subkeys
))
107 pstrcpy( keyname
, KEY_HKU
);
108 if ( !regdb_store_reg_keys( keyname
, &subkeys
) )
114 /***********************************************************************
115 Open the registry database
116 ***********************************************************************/
118 BOOL
init_registry_db( void )
120 static pid_t local_pid
;
122 if (tdb_reg
&& local_pid
== sys_getpid())
126 * try to open first without creating so we can determine
127 * if we need to init the data in the registry
130 tdb_reg
= tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT
, O_RDWR
, 0600);
133 tdb_reg
= tdb_open_log(lock_path("registry.tdb"), 0, TDB_DEFAULT
, O_RDWR
|O_CREAT
, 0600);
135 DEBUG(0,("init_registry: Failed to open registry %s (%s)\n",
136 lock_path("registry.tdb"), strerror(errno
) ));
140 DEBUG(10,("init_registry: Successfully created registry tdb\n"));
142 /* create the registry here */
143 if ( !init_registry_data() ) {
144 DEBUG(0,("init_registry: Failed to initiailize data in registry!\n"));
149 local_pid
= sys_getpid();
156 /***********************************************************************
157 Add subkey strings to the registry tdb under a defined key
158 fmt is the same format as tdb_pack except this function only supports
161 The full path to the registry key is used as database after the
162 \'s are converted to /'s.
163 ***********************************************************************/
165 BOOL
regdb_store_reg_keys( char *keyname
, REGSUBKEY_CTR
*ctr
)
168 char *buffer
, *tmpbuf
;
172 uint32 num_subkeys
= regsubkey_ctr_numkeys( ctr
);
177 /* allocate some initial memory */
179 buffer
= malloc(sizeof(pstring
));
180 buflen
= sizeof(pstring
);
183 /* store the number of subkeys */
185 len
+= tdb_pack(buffer
+len
, buflen
-len
, "d", num_subkeys
);
187 /* pack all the strings */
189 for (i
=0; i
<num_subkeys
; i
++) {
190 len
+= tdb_pack( buffer
+len
, buflen
-len
, "f", regsubkey_ctr_specific_key(ctr
, i
) );
191 if ( len
> buflen
) {
192 /* allocate some extra space */
193 if ((tmpbuf
= Realloc( buffer
, len
*2 )) == NULL
) {
194 DEBUG(0,("regdb_store_reg_keys: Failed to realloc memory of size [%d]\n", len
*2));
201 len
= tdb_pack( buffer
+len
, buflen
-len
, "f", regsubkey_ctr_specific_key(ctr
, i
) );
205 /* finally write out the data */
208 kbuf
.dsize
= strlen(keyname
)+1;
211 if ( tdb_store( tdb_reg
, kbuf
, dbuf
, TDB_REPLACE
) == -1) {
221 /***********************************************************************
222 Retrieve an array of strings containing subkeys. Memory should be
223 released by the caller. The subkeys are stored in a catenated string
224 of null terminated character strings
225 ***********************************************************************/
227 int regdb_fetch_reg_keys( char* key
, REGSUBKEY_CTR
*ctr
)
238 pstrcpy( path
, key
);
240 /* convert to key format */
241 pstring_sub( path
, "\\", "/" );
243 dbuf
= tdb_fetch_by_string( tdb_reg
, path
);
249 DEBUG(5,("regdb_fetch_reg_keys: Failed to fetch any subkeys for [%s]\n", key
));
253 len
= tdb_unpack( buf
, buflen
, "d", &num_items
);
255 for (i
=0; i
<num_items
; i
++) {
256 len
+= tdb_unpack( buf
+len
, buflen
-len
, "f", subkeyname
);
257 regsubkey_ctr_addkey( ctr
, subkeyname
);
260 SAFE_FREE(dbuf
.dptr
);
265 /***********************************************************************
266 Retrieve an array of strings containing subkeys. Memory should be
267 released by the caller. The subkeys are stored in a catenated string
268 of null terminated character strings
269 ***********************************************************************/
271 int regdb_fetch_reg_values( char* key
, REGVAL_CTR
*val
)
276 /***********************************************************************
277 Stub function since we do not currently support storing registry
278 values in the registry.tdb
279 ***********************************************************************/
281 BOOL
regdb_store_reg_values( char *key
, REGVAL_CTR
*val
)
288 * Table of function pointers for default access
291 REGISTRY_OPS regdb_ops
= {
292 regdb_fetch_reg_keys
,
293 regdb_fetch_reg_values
,
294 regdb_store_reg_keys
,
295 regdb_store_reg_values