* fix to display correct form information in REG_BINARY information
[Samba.git] / source / registry / reg_printing.c
blobf4c1feb281f72436da30b50cb8c5a5aae99a0bab
1 /*
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 registry virtual views for printing information */
23 #include "includes.h"
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_RPC_SRV
28 #define MAX_TOP_LEVEL_KEYS 3
30 /* some symbolic indexes into the top_level_keys */
32 #define KEY_INDEX_ENVIR 0
33 #define KEY_INDEX_FORMS 1
34 #define KEY_INDEX_PRINTER 2
36 static char *top_level_keys[MAX_TOP_LEVEL_KEYS] = {
37 "Environments",
38 "Forms",
39 "Printers"
43 /**********************************************************************
44 It is safe to assume that every registry path passed into on of
45 the exported functions here begins with KEY_PRINTING else
46 these functions would have never been called. This is a small utility
47 function to strip the beginning of the path and make a copy that the
48 caller can modify. Note that the caller is responsible for releasing
49 the memory allocated here.
50 **********************************************************************/
52 static char* trim_reg_path( char *path )
54 char *p;
55 uint16 key_len = strlen(KEY_PRINTING);
57 /*
58 * sanity check...this really should never be True.
59 * It is only here to prevent us from accessing outside
60 * the path buffer in the extreme case.
63 if ( strlen(path) < key_len ) {
64 DEBUG(0,("trim_reg_path: Registry path too short! [%s]\n", path));
65 DEBUG(0,("trim_reg_path: KEY_PRINTING => [%s]!\n", KEY_PRINTING));
66 return NULL;
70 p = path + strlen( KEY_PRINTING );
72 if ( *p == '\\' )
73 p++;
75 if ( *p )
76 return strdup(p);
77 else
78 return NULL;
81 /**********************************************************************
82 handle enumeration of subkeys below KEY_PRINTING\Environments
83 *********************************************************************/
85 static int print_subpath_environments( char *key, REGSUBKEY_CTR *subkeys )
87 DEBUG(10,("print_subpath_environments: key=>[%s]\n", key ? key : "NULL" ));
89 if ( !key )
91 /* listed architectures of installed drivers */
96 return 0;
99 /**********************************************************************
100 handle enumeration of subkeys below KEY_PRINTING\Forms
101 Really just a stub function, but left here in case it needs to
102 be expanded later on
103 *********************************************************************/
105 static int print_subpath_forms( char *key, REGSUBKEY_CTR *subkeys )
107 DEBUG(10,("print_subpath_forms: key=>[%s]\n", key ? key : "NULL" ));
109 /* there are no subkeys */
111 if ( key )
112 return -1;
114 return 0;
117 /**********************************************************************
118 handle enumeration of values below KEY_PRINTING\Forms
119 *********************************************************************/
121 static int print_subpath_values_forms( char *key, REGVAL_CTR *val )
123 int num_values = 0;
124 uint32 data[8];
125 int form_index = 1;
127 DEBUG(10,("print_values_forms: key=>[%s]\n", key ? key : "NULL" ));
129 /* handle ..\Forms\ */
131 if ( !key )
133 nt_forms_struct *forms_list = NULL;
134 nt_forms_struct *form = NULL;
135 int i;
137 if ( (num_values = get_ntforms( &forms_list )) == 0 )
138 return 0;
140 DEBUG(10,("print_subpath_values_forms: [%d] user defined forms returned\n",
141 num_values));
143 /* handle user defined forms */
145 for ( i=0; i<num_values; i++ )
147 form = &forms_list[i];
149 data[0] = form->width;
150 data[1] = form->length;
151 data[2] = form->left;
152 data[3] = form->top;
153 data[4] = form->right;
154 data[5] = form->bottom;
155 data[6] = form_index++;
156 data[7] = form->flag;
158 regval_ctr_addvalue( val, form->name, REG_BINARY, (char*)data, sizeof(data) );
162 SAFE_FREE( forms_list );
163 forms_list = NULL;
165 /* handle built-on forms */
167 if ( (num_values = get_builtin_ntforms( &forms_list )) == 0 )
168 return 0;
170 DEBUG(10,("print_subpath_values_forms: [%d] built-in forms returned\n",
171 num_values));
173 for ( i=0; i<num_values; i++ )
175 form = &forms_list[i];
177 data[0] = form->width;
178 data[1] = form->length;
179 data[2] = form->left;
180 data[3] = form->top;
181 data[4] = form->right;
182 data[5] = form->bottom;
183 data[6] = form_index++;
184 data[7] = form->flag;
186 regval_ctr_addvalue( val, form->name, REG_BINARY, (char*)data, sizeof(data) );
189 SAFE_FREE( forms_list );
192 return num_values;
195 /**********************************************************************
196 handle enumeration of subkeys below KEY_PRINTING\Printers
197 *********************************************************************/
199 static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys )
201 int n_services = lp_numservices();
202 int snum;
203 fstring sname;
205 DEBUG(10,("print_subpath_printers: key=>[%s]\n", key ? key : "NULL" ));
207 if ( !key )
209 /* enumerate all printers */
211 for (snum=0; snum<n_services; snum++) {
212 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
213 continue;
215 fstrcpy( sname, lp_servicename(snum) );
217 regsubkey_ctr_addkey( subkeys, sname );
220 else
222 /* get information for a specific printer */
225 return regsubkey_ctr_numkeys( subkeys );
228 /**********************************************************************
229 Routine to handle enumeration of subkeys and values
230 below KEY_PRINTING (depending on whether or not subkeys/val are
231 valid pointers.
232 *********************************************************************/
234 static int handle_printing_subpath( char *key, REGSUBKEY_CTR *subkeys, REGVAL_CTR *val )
236 int result = 0;
237 char *p, *base;
238 int i;
240 DEBUG(10,("handle_printing_subpath: key=>[%s]\n", key ));
243 * break off the first part of the path
244 * topmost base **must** be one of the strings
245 * in top_level_keys[]
248 reg_split_path( key, &base, &p);
250 for ( i=0; i<MAX_TOP_LEVEL_KEYS; i++ ) {
251 if ( StrCaseCmp( top_level_keys[i], base ) == 0 )
252 break;
255 DEBUG(10,("handle_printing_subpath: base=>[%s], i==[%d]\n", base, i));
257 if ( !(i < MAX_TOP_LEVEL_KEYS) )
258 return -1;
260 /* Call routine to handle each top level key */
261 switch ( i )
263 case KEY_INDEX_ENVIR:
264 if ( subkeys )
265 print_subpath_environments( p, subkeys );
266 break;
268 case KEY_INDEX_FORMS:
269 if ( subkeys )
270 print_subpath_forms( p, subkeys );
271 if ( val )
272 print_subpath_values_forms( p, val );
273 break;
275 case KEY_INDEX_PRINTER:
276 if ( subkeys )
277 print_subpath_printers( p, subkeys );
278 break;
280 /* default case for top level key that has no handler */
282 default:
283 break;
288 return result;
291 /**********************************************************************
292 Enumerate registry subkey names given a registry path.
293 Caller is responsible for freeing memory to **subkeys
294 *********************************************************************/
296 int printing_subkey_info( char *key, REGSUBKEY_CTR *subkey_ctr )
298 char *path;
299 BOOL top_level = False;
300 int num_subkeys = 0;
302 DEBUG(10,("printing_subkey_info: key=>[%s]\n", key));
304 path = trim_reg_path( key );
306 /* check to see if we are dealing with the top level key */
308 if ( !path )
309 top_level = True;
311 if ( top_level ) {
312 for ( num_subkeys=0; num_subkeys<MAX_TOP_LEVEL_KEYS; num_subkeys++ )
313 regsubkey_ctr_addkey( subkey_ctr, top_level_keys[num_subkeys] );
315 else
316 num_subkeys = handle_printing_subpath( path, subkey_ctr, NULL );
318 SAFE_FREE( path );
320 return num_subkeys;
323 /**********************************************************************
324 Enumerate registry values given a registry path.
325 Caller is responsible for freeing memory
326 *********************************************************************/
328 int printing_value_info( char *key, REGVAL_CTR *val )
330 char *path;
331 BOOL top_level = False;
332 int num_values = 0;
334 DEBUG(10,("printing_value_info: key=>[%s]\n", key));
336 path = trim_reg_path( key );
338 /* check to see if we are dealing with the top level key */
340 if ( !path )
341 top_level = True;
343 /* fill in values from the getprinterdata_printer_server() */
344 if ( top_level )
345 num_values = 0;
346 else
347 num_values = handle_printing_subpath( path, NULL, val );
350 return num_values;
353 /**********************************************************************
354 Stub function which always returns failure since we don't want
355 people storing printing information directly via regostry calls
356 (for now at least)
357 *********************************************************************/
359 BOOL printing_store_subkey( char *key, REGSUBKEY_CTR *subkeys )
361 return False;
364 /**********************************************************************
365 Stub function which always returns failure since we don't want
366 people storing printing information directly via regostry calls
367 (for now at least)
368 *********************************************************************/
370 BOOL printing_store_value( char *key, REGVAL_CTR *val )
372 return False;
376 * Table of function pointers for accessing printing data
379 REGISTRY_OPS printing_ops = {
380 printing_subkey_info,
381 printing_value_info,
382 printing_store_subkey,
383 printing_store_value