2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Gerald Carter 2002-2005
5 * Copyright (c) Andreas Schneider <asn@samba.org> 2010
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.
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.
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/>.
21 /* Implementation of registry virtual views for printing information */
25 #include "reg_util_internal.h"
28 #define DBGC_CLASS DBGC_REGISTRY
30 extern struct registry_ops regdb_ops
;
32 /* registry paths used in the print_registry[] */
33 #define KEY_CONTROL_PRINTERS "HKLM\\SYSTEM\\CURRENTCONTROLSET\\CONTROL\\PRINT\\PRINTERS"
34 #define KEY_WINNT_PRINTERS "HKLM\\SOFTWARE\\MICROSOFT\\WINDOWS NT\\CURRENTVERSION\\PRINT\\PRINTERS"
36 /* callback table for various registry paths below the ones we service in this module */
39 /* full key path in normalized form */
42 /* callbscks for fetch/store operations */
43 int ( *fetch_subkeys
) ( const char *path
, struct regsubkey_ctr
*subkeys
);
44 bool (*store_subkeys
) ( const char *path
, struct regsubkey_ctr
*subkeys
);
45 int (*fetch_values
) ( const char *path
, struct regval_ctr
*values
);
46 bool (*store_values
) ( const char *path
, struct regval_ctr
*values
);
49 /*********************************************************************
50 *********************************************************************
51 ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/PRINTERS"
52 ** "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PRINT/PRINTERS"
53 *********************************************************************
54 *********************************************************************/
56 static char *create_printer_registry_path(TALLOC_CTX
*mem_ctx
, const char *key
) {
60 path
= talloc_strdup(mem_ctx
, key
);
65 path
= normalize_reg_path(mem_ctx
, path
);
70 if (strncmp(path
, KEY_CONTROL_PRINTERS
, strlen(KEY_CONTROL_PRINTERS
)) == 0) {
71 subkey
= reg_remaining_path(mem_ctx
, key
+ strlen(KEY_CONTROL_PRINTERS
));
75 return talloc_asprintf(mem_ctx
, "%s\\%s", KEY_WINNT_PRINTERS
, subkey
);
81 /*********************************************************************
82 *********************************************************************/
84 static int key_printers_fetch_keys( const char *key
, struct regsubkey_ctr
*subkeys
)
86 TALLOC_CTX
*ctx
= talloc_tos();
89 printers_key
= create_printer_registry_path(ctx
, key
);
90 if (printers_key
== NULL
) {
91 /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
92 return regdb_ops
.fetch_subkeys(KEY_WINNT_PRINTERS
, subkeys
);
95 return regdb_ops
.fetch_subkeys(printers_key
, subkeys
);
98 /**********************************************************************
99 *********************************************************************/
101 static bool key_printers_store_keys( const char *key
, struct regsubkey_ctr
*subkeys
)
103 TALLOC_CTX
*ctx
= talloc_tos();
106 printers_key
= create_printer_registry_path(ctx
, key
);
107 if (printers_key
== NULL
) {
108 /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
109 return regdb_ops
.store_subkeys(KEY_WINNT_PRINTERS
, subkeys
);
112 return regdb_ops
.store_subkeys(printers_key
, subkeys
);
115 /**********************************************************************
116 *********************************************************************/
118 static int key_printers_fetch_values(const char *key
, struct regval_ctr
*values
)
120 TALLOC_CTX
*ctx
= talloc_tos();
123 printers_key
= create_printer_registry_path(ctx
, key
);
124 if (printers_key
== NULL
) {
125 /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
126 return regdb_ops
.fetch_values(KEY_WINNT_PRINTERS
, values
);
129 return regdb_ops
.fetch_values(printers_key
, values
);
132 /**********************************************************************
133 *********************************************************************/
135 static bool key_printers_store_values(const char *key
, struct regval_ctr
*values
)
137 TALLOC_CTX
*ctx
= talloc_tos();
140 printers_key
= create_printer_registry_path(ctx
, key
);
141 if (printers_key
== NULL
) {
142 /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
143 return regdb_ops
.store_values(KEY_WINNT_PRINTERS
, values
);
146 return regdb_ops
.store_values(printers_key
, values
);
149 /**********************************************************************
150 *********************************************************************
151 ** Structure to hold dispatch table of ops for various printer keys.
152 ** Make sure to always store deeper keys along the same path first so
153 ** we ge a more specific match.
154 *********************************************************************
155 *********************************************************************/
157 static struct reg_dyn_tree print_registry
[] = {
158 { KEY_CONTROL_PRINTERS
,
159 &key_printers_fetch_keys
,
160 &key_printers_store_keys
,
161 &key_printers_fetch_values
,
162 &key_printers_store_values
},
164 { NULL
, NULL
, NULL
, NULL
, NULL
}
168 /**********************************************************************
169 *********************************************************************
170 ** Main reg_printing interface functions
171 *********************************************************************
172 *********************************************************************/
174 /***********************************************************************
175 Lookup a key in the print_registry table, returning its index.
177 **********************************************************************/
179 static int match_registry_path(const char *key
)
183 TALLOC_CTX
*ctx
= talloc_tos();
188 path
= talloc_strdup(ctx
, key
);
192 path
= normalize_reg_path(ctx
, path
);
197 for ( i
=0; print_registry
[i
].path
; i
++ ) {
198 if (strncmp( path
, print_registry
[i
].path
, strlen(print_registry
[i
].path
) ) == 0 )
205 /***********************************************************************
206 **********************************************************************/
208 static int regprint_fetch_reg_keys( const char *key
, struct regsubkey_ctr
*subkeys
)
210 int i
= match_registry_path( key
);
215 if ( !print_registry
[i
].fetch_subkeys
)
218 return print_registry
[i
].fetch_subkeys( key
, subkeys
);
221 /**********************************************************************
222 *********************************************************************/
224 static bool regprint_store_reg_keys( const char *key
, struct regsubkey_ctr
*subkeys
)
226 int i
= match_registry_path( key
);
231 if ( !print_registry
[i
].store_subkeys
)
234 return print_registry
[i
].store_subkeys( key
, subkeys
);
237 /**********************************************************************
238 *********************************************************************/
240 static int regprint_fetch_reg_values(const char *key
, struct regval_ctr
*values
)
242 int i
= match_registry_path( key
);
247 /* return 0 values by default since we know the key had
248 to exist because the client opened a handle */
250 if ( !print_registry
[i
].fetch_values
)
253 return print_registry
[i
].fetch_values( key
, values
);
256 /**********************************************************************
257 *********************************************************************/
259 static bool regprint_store_reg_values(const char *key
, struct regval_ctr
*values
)
261 int i
= match_registry_path( key
);
266 if ( !print_registry
[i
].store_values
)
269 return print_registry
[i
].store_values( key
, values
);
273 * Table of function pointers for accessing printing data
276 struct registry_ops printing_ops
= {
277 .fetch_subkeys
= regprint_fetch_reg_keys
,
278 .fetch_values
= regprint_fetch_reg_values
,
279 .store_subkeys
= regprint_store_reg_keys
,
280 .store_values
= regprint_store_reg_values
,