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 */
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
] = {
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
)
55 uint16 key_len
= strlen(KEY_PRINTING
);
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
));
70 p
= path
+ strlen( KEY_PRINTING
);
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" ));
91 /* listed architectures of installed drivers */
99 /**********************************************************************
100 handle enumeration of subkeys below KEY_PRINTING\Forms
101 Really just a stub function, but left here in case it needs to
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 */
117 /**********************************************************************
118 handle enumeration of values below KEY_PRINTING\Forms
119 *********************************************************************/
121 static int print_subpath_values_forms( char *key
, REGVAL_CTR
*val
)
127 DEBUG(10,("print_values_forms: key=>[%s]\n", key
? key
: "NULL" ));
129 /* handle ..\Forms\ */
133 nt_forms_struct
*forms_list
= NULL
;
134 nt_forms_struct
*form
= NULL
;
137 if ( (num_values
= get_ntforms( &forms_list
)) == 0 )
140 DEBUG(10,("print_subpath_values_forms: [%d] user defined forms returned\n",
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
;
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
);
165 /* handle built-on forms */
167 if ( (num_values
= get_builtin_ntforms( &forms_list
)) == 0 )
170 DEBUG(10,("print_subpath_values_forms: [%d] built-in forms returned\n",
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
;
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
);
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();
205 DEBUG(10,("print_subpath_printers: key=>[%s]\n", key
? key
: "NULL" ));
209 /* enumerate all printers */
211 for (snum
=0; snum
<n_services
; snum
++) {
212 if ( !(lp_snum_ok(snum
) && lp_print_ok(snum
) ) )
215 fstrcpy( sname
, lp_servicename(snum
) );
217 regsubkey_ctr_addkey( subkeys
, sname
);
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
232 *********************************************************************/
234 static int handle_printing_subpath( char *key
, REGSUBKEY_CTR
*subkeys
, REGVAL_CTR
*val
)
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 )
255 DEBUG(10,("handle_printing_subpath: base=>[%s], i==[%d]\n", base
, i
));
257 if ( !(i
< MAX_TOP_LEVEL_KEYS
) )
260 /* Call routine to handle each top level key */
263 case KEY_INDEX_ENVIR
:
265 print_subpath_environments( p
, subkeys
);
268 case KEY_INDEX_FORMS
:
270 print_subpath_forms( p
, subkeys
);
272 print_subpath_values_forms( p
, val
);
275 case KEY_INDEX_PRINTER
:
277 print_subpath_printers( p
, subkeys
);
280 /* default case for top level key that has no handler */
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
)
299 BOOL top_level
= False
;
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 */
312 for ( num_subkeys
=0; num_subkeys
<MAX_TOP_LEVEL_KEYS
; num_subkeys
++ )
313 regsubkey_ctr_addkey( subkey_ctr
, top_level_keys
[num_subkeys
] );
316 num_subkeys
= handle_printing_subpath( path
, subkey_ctr
, NULL
);
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
)
331 BOOL top_level
= False
;
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 */
343 /* fill in values from the getprinterdata_printer_server() */
347 num_values
= handle_printing_subpath( path
, NULL
, val
);
353 /**********************************************************************
354 Stub function which always returns failure since we don't want
355 people storing printing information directly via regostry calls
357 *********************************************************************/
359 BOOL
printing_store_subkey( char *key
, REGSUBKEY_CTR
*subkeys
)
364 /**********************************************************************
365 Stub function which always returns failure since we don't want
366 people storing printing information directly via regostry calls
368 *********************************************************************/
370 BOOL
printing_store_value( char *key
, REGVAL_CTR
*val
)
376 * Table of function pointers for accessing printing data
379 REGISTRY_OPS printing_ops
= {
380 printing_subkey_info
,
382 printing_store_subkey
,