1 | /*
|
---|
2 | * Unix SMB/CIFS implementation.
|
---|
3 | * Virtual Windows Registry Layer
|
---|
4 | * Copyright (C) Gerald Carter 2002.
|
---|
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 hook cache tree */
|
---|
22 |
|
---|
23 | #include "includes.h"
|
---|
24 | #include "adt_tree.h"
|
---|
25 |
|
---|
26 | #undef DBGC_CLASS
|
---|
27 | #define DBGC_CLASS DBGC_RPC_SRV
|
---|
28 |
|
---|
29 | static SORTED_TREE *cache_tree;
|
---|
30 | extern REGISTRY_OPS regdb_ops; /* these are the default */
|
---|
31 | static REGISTRY_HOOK default_hook = { KEY_TREE_ROOT, ®db_ops };
|
---|
32 |
|
---|
33 | /**********************************************************************
|
---|
34 | Initialize the cache tree
|
---|
35 | *********************************************************************/
|
---|
36 |
|
---|
37 | BOOL reghook_cache_init( void )
|
---|
38 | {
|
---|
39 | cache_tree = pathtree_init( &default_hook, NULL );
|
---|
40 |
|
---|
41 | return ( cache_tree == NULL );
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**********************************************************************
|
---|
45 | Add a new REGISTRY_HOOK to the cache. Note that the keyname
|
---|
46 | is not in the exact format that a SORTED_TREE expects.
|
---|
47 | *********************************************************************/
|
---|
48 |
|
---|
49 | BOOL reghook_cache_add( REGISTRY_HOOK *hook )
|
---|
50 | {
|
---|
51 | pstring key;
|
---|
52 |
|
---|
53 | if ( !hook )
|
---|
54 | return False;
|
---|
55 |
|
---|
56 | pstrcpy( key, "\\");
|
---|
57 | pstrcat( key, hook->keyname );
|
---|
58 |
|
---|
59 | pstring_sub( key, "\\", "/" );
|
---|
60 |
|
---|
61 | DEBUG(10,("reghook_cache_add: Adding key [%s]\n", key));
|
---|
62 |
|
---|
63 | return pathtree_add( cache_tree, key, hook );
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**********************************************************************
|
---|
67 | Initialize the cache tree
|
---|
68 | *********************************************************************/
|
---|
69 |
|
---|
70 | REGISTRY_HOOK* reghook_cache_find( const char *keyname )
|
---|
71 | {
|
---|
72 | char *key;
|
---|
73 | int len;
|
---|
74 | REGISTRY_HOOK *hook;
|
---|
75 |
|
---|
76 | if ( !keyname )
|
---|
77 | return NULL;
|
---|
78 |
|
---|
79 | /* prepend the string with a '\' character */
|
---|
80 |
|
---|
81 | len = strlen( keyname );
|
---|
82 | if ( !(key = (char *)SMB_MALLOC( len + 2 )) ) {
|
---|
83 | DEBUG(0,("reghook_cache_find: malloc failed for string [%s] !?!?!\n",
|
---|
84 | keyname));
|
---|
85 | return NULL;
|
---|
86 | }
|
---|
87 |
|
---|
88 | *key = '\\';
|
---|
89 | strncpy( key+1, keyname, len+1);
|
---|
90 |
|
---|
91 | /* swap to a form understood by the SORTED_TREE */
|
---|
92 |
|
---|
93 | string_sub( key, "\\", "/", 0 );
|
---|
94 |
|
---|
95 | DEBUG(10,("reghook_cache_find: Searching for keyname [%s]\n", key));
|
---|
96 |
|
---|
97 | hook = (REGISTRY_HOOK *)pathtree_find( cache_tree, key ) ;
|
---|
98 |
|
---|
99 | SAFE_FREE( key );
|
---|
100 |
|
---|
101 | return hook;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**********************************************************************
|
---|
105 | Initialize the cache tree
|
---|
106 | *********************************************************************/
|
---|
107 |
|
---|
108 | void reghook_dump_cache( int debuglevel )
|
---|
109 | {
|
---|
110 | DEBUG(debuglevel,("reghook_dump_cache: Starting cache dump now...\n"));
|
---|
111 |
|
---|
112 | pathtree_print_keys( cache_tree, debuglevel );
|
---|
113 | }
|
---|