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 char *environments[] = {
91 "Windows NT Alpha_AXP",
94 fstring *drivers = NULL;
95 int i, env_index, num_drivers;
96 BOOL valid_env = False;
97 char *base, *new_path;
100 int num_subkeys = -1;
102 DEBUG(10,("print_subpath_environments: key=>[%s]\n", key ? key : "NULL" ));
104 /* listed architectures of installed drivers */
108 /* Windows 9x drivers */
110 if ( get_ntdrivers( &drivers, environments[0], 0 ) )
111 regsubkey_ctr_addkey( subkeys, environments[0] );
112 SAFE_FREE( drivers );
114 /* Windows NT/2k intel drivers */
116 if ( get_ntdrivers( &drivers, environments[1], 2 )
117 || get_ntdrivers( &drivers, environments[1], 3 ) )
119 regsubkey_ctr_addkey( subkeys, environments[1] );
121 SAFE_FREE( drivers );
123 /* Windows NT 4.0; non-intel drivers */
124 for ( i=2; environments[i]; i++ ) {
125 if ( get_ntdrivers( &drivers, environments[i], 2 ) )
126 regsubkey_ctr_addkey( subkeys, environments[i] );
129 SAFE_FREE( drivers );
131 num_subkeys = regsubkey_ctr_numkeys( subkeys );
135 /* we are dealing with a subkey of "Environments */
137 key2 = strdup( key );
139 reg_split_path( keystr, &base, &new_path );
143 for ( env_index=0; environments[env_index]; env_index++ ) {
144 if ( StrCaseCmp( environments[env_index], base ) == 0 ) {
153 /* enumerate driver versions; environment is environments[env_index] */
156 switch ( env_index ) {
158 if ( get_ntdrivers( &drivers, environments[0], 0 ) ) {
159 regsubkey_ctr_addkey( subkeys, "0" );
160 SAFE_FREE( drivers );
163 case 1: /* Windows NT/2k - intel */
164 if ( get_ntdrivers( &drivers, environments[1], 2 ) ) {
165 regsubkey_ctr_addkey( subkeys, "2" );
166 SAFE_FREE( drivers );
168 if ( get_ntdrivers( &drivers, environments[1], 3 ) ) {
169 regsubkey_ctr_addkey( subkeys, "3" );
170 SAFE_FREE( drivers );
173 default: /* Windows NT - nonintel */
174 if ( get_ntdrivers( &drivers, environments[env_index], 2 ) ) {
175 regsubkey_ctr_addkey( subkeys, "2" );
176 SAFE_FREE( drivers );
181 num_subkeys = regsubkey_ctr_numkeys( subkeys );
185 /* we finally get to enumerate the drivers */
188 reg_split_path( keystr, &base, &new_path );
191 num_drivers = get_ntdrivers( &drivers, environments[env_index], atoi(base) );
192 for ( i=0; i<num_drivers; i++ )
193 regsubkey_ctr_addkey( subkeys, drivers[i] );
195 num_subkeys = regsubkey_ctr_numkeys( subkeys );
205 /***********************************************************************
206 simple function to prune a pathname down to the basename of a file
207 **********************************************************************/
209 static char* dos_basename ( char *path )
213 p = strrchr( path, '\\' );
222 /**********************************************************************
223 handle enumeration of values below
224 KEY_PRINTING\Environments\<arch>\<version>\<drivername>
225 *********************************************************************/
227 static int print_subpath_values_environments( char *key, REGVAL_CTR *val )
231 char *base, *new_path;
235 NT_PRINTER_DRIVER_INFO_LEVEL driver_ctr;
236 NT_PRINTER_DRIVER_INFO_LEVEL_3 *info3;
239 char *buffer2 = NULL;
244 DEBUG(8,("print_subpath_values_environments: Enter key => [%s]\n", key ? key : "NULL"));
250 * The only key below KEY_PRINTING\Environments that
251 * posseses values is each specific printer driver
252 * First get the arch, version, & driver name
257 key2 = strdup( key );
259 reg_split_path( keystr, &base, &new_path );
260 if ( !base || !new_path )
262 fstrcpy( env, base );
267 reg_split_path( keystr, &base, &new_path );
268 if ( !base || !new_path )
270 version = atoi( base );
272 /* printer driver name */
275 reg_split_path( keystr, &base, &new_path );
276 /* new_path should be NULL here since this must be the last key */
277 if ( !base || new_path )
279 fstrcpy( driver, base );
281 w_result = get_a_printer_driver( &driver_ctr, 3, driver, env, version );
283 if ( !W_ERROR_IS_OK(w_result) )
286 /* build the values out of the driver information */
287 info3 = driver_ctr.info_3;
289 filename = dos_basename( info3->driverpath );
290 regval_ctr_addvalue( val, "Driver", REG_SZ, filename, strlen(filename)+1 );
291 filename = dos_basename( info3->configfile );
292 regval_ctr_addvalue( val, "Configuration File", REG_SZ, filename, strlen(filename)+1 );
293 filename = dos_basename( info3->datafile );
294 regval_ctr_addvalue( val, "Data File", REG_SZ, filename, strlen(filename)+1 );
295 filename = dos_basename( info3->helpfile );
296 regval_ctr_addvalue( val, "Help File", REG_SZ, filename, strlen(filename)+1 );
298 regval_ctr_addvalue( val, "Data Type", REG_SZ, info3->defaultdatatype, strlen(info3->defaultdatatype)+1 );
300 regval_ctr_addvalue( val, "Version", REG_DWORD, (char*)&info3->cversion, sizeof(info3->cversion) );
302 if ( info3->dependentfiles )
304 /* place the list of dependent files in a single
305 character buffer, separating each file name by
308 for ( i=0; strcmp(info3->dependentfiles[i], ""); i++ )
310 /* strip the path to only the file's base name */
312 filename = dos_basename( info3->dependentfiles[i] );
314 length = strlen(filename);
316 buffer2 = Realloc( buffer, buffer_size + length + 1 );
321 memcpy( buffer+buffer_size, filename, length+1 );
323 buffer_size += length + 1;
326 /* terminated by double NULL. Add the final one here */
328 buffer2 = Realloc( buffer, buffer_size + 1 );
335 buffer[buffer_size++] = '\0';
339 regval_ctr_addvalue( val, "Dependent Files", REG_MULTI_SZ, buffer, buffer_size );
341 free_a_printer_driver( driver_ctr, 3 );
345 DEBUG(8,("print_subpath_values_environments: Exit\n"));
347 return regval_ctr_numvals( val );
351 /**********************************************************************
352 handle enumeration of subkeys below KEY_PRINTING\Forms
353 Really just a stub function, but left here in case it needs to
355 *********************************************************************/
357 static int print_subpath_forms( char *key, REGSUBKEY_CTR *subkeys )
359 DEBUG(10,("print_subpath_forms: key=>[%s]\n", key ? key : "NULL" ));
361 /* there are no subkeys */
369 /**********************************************************************
370 handle enumeration of values below KEY_PRINTING\Forms
371 *********************************************************************/
373 static int print_subpath_values_forms( char *key, REGVAL_CTR *val )
379 DEBUG(10,("print_values_forms: key=>[%s]\n", key ? key : "NULL" ));
381 /* handle ..\Forms\ */
385 nt_forms_struct *forms_list = NULL;
386 nt_forms_struct *form = NULL;
389 if ( (num_values = get_ntforms( &forms_list )) == 0 )
392 DEBUG(10,("print_subpath_values_forms: [%d] user defined forms returned\n",
395 /* handle user defined forms */
397 for ( i=0; i<num_values; i++ )
399 form = &forms_list[i];
401 data[0] = form->width;
402 data[1] = form->length;
403 data[2] = form->left;
405 data[4] = form->right;
406 data[5] = form->bottom;
407 data[6] = form_index++;
408 data[7] = form->flag;
410 regval_ctr_addvalue( val, form->name, REG_BINARY, (char*)data, sizeof(data) );
414 SAFE_FREE( forms_list );
417 /* handle built-on forms */
419 if ( (num_values = get_builtin_ntforms( &forms_list )) == 0 )
422 DEBUG(10,("print_subpath_values_forms: [%d] built-in forms returned\n",
425 for ( i=0; i<num_values; i++ )
427 form = &forms_list[i];
429 data[0] = form->width;
430 data[1] = form->length;
431 data[2] = form->left;
433 data[4] = form->right;
434 data[5] = form->bottom;
435 data[6] = form_index++;
436 data[7] = form->flag;
438 regval_ctr_addvalue( val, form->name, REG_BINARY, (char*)data, sizeof(data) );
441 SAFE_FREE( forms_list );
447 /**********************************************************************
448 handle enumeration of subkeys below KEY_PRINTING\Printers
449 *********************************************************************/
451 static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys )
453 int n_services = lp_numservices();
457 DEBUG(10,("print_subpath_printers: key=>[%s]\n", key ? key : "NULL" ));
461 /* enumerate all printers */
463 for (snum=0; snum<n_services; snum++) {
464 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
467 fstrcpy( sname, lp_servicename(snum) );
469 regsubkey_ctr_addkey( subkeys, sname );
474 /* get information for a specific printer */
477 return regsubkey_ctr_numkeys( subkeys );
480 /**********************************************************************
481 Routine to handle enumeration of subkeys and values
482 below KEY_PRINTING (depending on whether or not subkeys/val are
484 *********************************************************************/
486 static int handle_printing_subpath( char *key, REGSUBKEY_CTR *subkeys, REGVAL_CTR *val )
492 DEBUG(10,("handle_printing_subpath: key=>[%s]\n", key ));
495 * break off the first part of the path
496 * topmost base **must** be one of the strings
497 * in top_level_keys[]
500 reg_split_path( key, &base, &p);
502 for ( i=0; i<MAX_TOP_LEVEL_KEYS; i++ ) {
503 if ( StrCaseCmp( top_level_keys[i], base ) == 0 )
507 DEBUG(10,("handle_printing_subpath: base=>[%s], i==[%d]\n", base, i));
509 if ( !(i < MAX_TOP_LEVEL_KEYS) )
512 /* Call routine to handle each top level key */
515 case KEY_INDEX_ENVIR:
517 print_subpath_environments( p, subkeys );
519 print_subpath_values_environments( p, val );
522 case KEY_INDEX_FORMS:
524 print_subpath_forms( p, subkeys );
526 print_subpath_values_forms( p, val );
529 case KEY_INDEX_PRINTER:
531 print_subpath_printers( p, subkeys );
534 /* default case for top level key that has no handler */
545 /**********************************************************************
546 Enumerate registry subkey names given a registry path.
547 Caller is responsible for freeing memory to **subkeys
548 *********************************************************************/
550 int printing_subkey_info( char *key, REGSUBKEY_CTR *subkey_ctr )
553 BOOL top_level = False;
556 DEBUG(10,("printing_subkey_info: key=>[%s]\n", key));
558 path = trim_reg_path( key );
560 /* check to see if we are dealing with the top level key */
566 for ( num_subkeys=0; num_subkeys<MAX_TOP_LEVEL_KEYS; num_subkeys++ )
567 regsubkey_ctr_addkey( subkey_ctr, top_level_keys[num_subkeys] );
570 num_subkeys = handle_printing_subpath( path, subkey_ctr, NULL );
577 /**********************************************************************
578 Enumerate registry values given a registry path.
579 Caller is responsible for freeing memory
580 *********************************************************************/
582 int printing_value_info( char *key, REGVAL_CTR *val )
585 BOOL top_level = False;
588 DEBUG(10,("printing_value_info: key=>[%s]\n", key));
590 path = trim_reg_path( key );
592 /* check to see if we are dealing with the top level key */
597 /* fill in values from the getprinterdata_printer_server() */
601 num_values = handle_printing_subpath( path, NULL, val );
607 /**********************************************************************
608 Stub function which always returns failure since we don't want
609 people storing printing information directly via regostry calls
611 *********************************************************************/
613 BOOL printing_store_subkey( char *key, REGSUBKEY_CTR *subkeys )
618 /**********************************************************************
619 Stub function which always returns failure since we don't want
620 people storing printing information directly via regostry calls
622 *********************************************************************/
624 BOOL printing_store_value( char *key, REGVAL_CTR *val )
630 * Table of function pointers for accessing printing data
633 REGISTRY_OPS printing_ops = {
634 printing_subkey_info,
636 printing_store_subkey,