r7415: * big change -- volker's new async winbindd from trunk
[Samba/gbeck.git] / source / registry / reg_printing.c
blob8e1e8ae40b2658061e64d67bb9badb63c4a38e42
1 /*
2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Gerald Carter 2002-2005
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 const 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(path);
56 uint16 base_key_len;
58 int key_printing_len = strlen( KEY_PRINTING );
59 int key_printing2k_len = strlen( KEY_PRINTING_2K );
60 int key_printing_ports_len = strlen( KEY_PRINTING_PORTS );
64 /*
65 * sanity check...this really should never be True.
66 * It is only here to prevent us from accessing outside
67 * the path buffer in the extreme case.
70 if ( (key_len < key_printing_len)
71 && (key_len < key_printing2k_len)
72 && (key_len < key_printing_ports_len) )
74 DEBUG(0,("trim_reg_path: Registry path too short! [%s]\n", path));
75 return NULL;
78 base_key_len = 0;
79 if ( StrnCaseCmp( KEY_PRINTING, path, key_printing_len ) == 0 ) {
80 base_key_len = key_printing_len;
82 else if ( StrnCaseCmp( KEY_PRINTING_2K, path, key_printing2k_len ) == 0 ) {
83 base_key_len = key_printing2k_len;
85 else if ( StrnCaseCmp( KEY_PRINTING_PORTS, path, key_printing2k_len ) == 0 ) {
86 base_key_len = key_printing_ports_len;
88 else {
89 DEBUG(0,("trim_reg_path: invalid path [%s]\n", path ));
90 return NULL;
93 p = path + base_key_len;
95 if ( *p == '\\' )
96 p++;
98 if ( *p )
99 return SMB_STRDUP(p);
100 else
101 return NULL;
104 /**********************************************************************
105 *********************************************************************/
107 static int fill_ports_values( REGVAL_CTR *values )
109 int numlines, i;
110 char **lines;
111 UNISTR2 data;
112 WERROR result;
114 result = enumports_hook( &numlines, &lines );
116 if ( !W_ERROR_IS_OK(result) )
117 return -1;
119 init_unistr2( &data, "", UNI_STR_TERMINATE);
120 for ( i=0; i<numlines; i++ )
121 regval_ctr_addvalue( values, lines[i], REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
123 return numlines;
127 /**********************************************************************
128 handle enumeration of subkeys below KEY_PRINTING\Environments
129 Environments\$ARCH\Print Processors
130 Environments\$ARCH\Drivers\{0,2,3}
131 *********************************************************************/
133 #define ENVIRONMENT_DRIVERS 1
134 #define ENVIRONMENT_PRINTPROC 2
136 static int print_subpath_environments( char *key, REGSUBKEY_CTR *subkeys )
138 const char *environments[] = {
139 "Windows 4.0",
140 "Windows NT x86",
141 "Windows NT R4000",
142 "Windows NT Alpha_AXP",
143 "Windows NT PowerPC",
144 "Windows IA64",
145 "Windows x64",
146 NULL };
147 fstring *drivers = NULL;
148 int i, env_index, num_drivers;
149 char *keystr, *base, *subkeypath;
150 pstring key2;
151 int num_subkeys = -1;
152 int env_subkey_type = 0;
153 int version;
155 DEBUG(10,("print_subpath_environments: key=>[%s]\n", key ? key : "NULL" ));
157 /* list all possible architectures */
159 if ( !key ) {
160 for ( num_subkeys=0; environments[num_subkeys]; num_subkeys++ )
161 regsubkey_ctr_addkey( subkeys, environments[num_subkeys] );
163 return num_subkeys;
166 /* we are dealing with a subkey of "Environments */
168 pstrcpy( key2, key );
169 keystr = key2;
170 reg_split_path( keystr, &base, &subkeypath );
172 /* sanity check */
174 for ( env_index=0; environments[env_index]; env_index++ ) {
175 if ( strequal( environments[env_index], base ) )
176 break;
178 if ( !environments[env_index] )
179 return -1;
181 /* ...\Print\Environements\...\ */
183 if ( !subkeypath ) {
184 regsubkey_ctr_addkey( subkeys, "Drivers" );
185 regsubkey_ctr_addkey( subkeys, "Print Processors" );
187 return 2;
190 /* more of the key path to process */
192 keystr = subkeypath;
193 reg_split_path( keystr, &base, &subkeypath );
195 /* ...\Print\Environements\...\Drivers\ */
197 if ( strequal(base, "Drivers") )
198 env_subkey_type = ENVIRONMENT_DRIVERS;
199 else if ( strequal(base, "Print Processors") )
200 env_subkey_type = ENVIRONMENT_PRINTPROC;
201 else
202 /* invalid path */
203 return -1;
205 if ( !subkeypath ) {
206 switch ( env_subkey_type ) {
207 case ENVIRONMENT_DRIVERS:
208 switch ( env_index ) {
209 case 0: /* Win9x */
210 regsubkey_ctr_addkey( subkeys, "Version-0" );
211 break;
212 default: /* Windows NT based systems */
213 regsubkey_ctr_addkey( subkeys, "Version-2" );
214 regsubkey_ctr_addkey( subkeys, "Version-3" );
215 break;
218 return regsubkey_ctr_numkeys( subkeys );
220 case ENVIRONMENT_PRINTPROC:
221 if ( env_index == 1 || env_index == 5 || env_index == 6 )
222 regsubkey_ctr_addkey( subkeys, "winprint" );
224 return regsubkey_ctr_numkeys( subkeys );
228 /* we finally get to enumerate the drivers */
230 keystr = subkeypath;
231 reg_split_path( keystr, &base, &subkeypath );
233 /* get thr print processors key out of the way */
234 if ( env_subkey_type == ENVIRONMENT_PRINTPROC ) {
235 if ( !strequal( base, "winprint" ) )
236 return -1;
237 return !subkeypath ? 0 : -1;
240 /* only dealing with drivers from here on out */
242 version = atoi(&base[strlen(base)-1]);
244 switch (env_index) {
245 case 0:
246 if ( version != 0 )
247 return -1;
248 break;
249 default:
250 if ( version != 2 && version != 3 )
251 return -1;
252 break;
256 if ( !subkeypath ) {
257 num_drivers = get_ntdrivers( &drivers, environments[env_index], version );
258 for ( i=0; i<num_drivers; i++ )
259 regsubkey_ctr_addkey( subkeys, drivers[i] );
261 return regsubkey_ctr_numkeys( subkeys );
264 /* if anything else left, just say if has no subkeys */
266 DEBUG(1,("print_subpath_environments: unhandled key [%s] (subkey == %s\n",
267 key, subkeypath ));
269 return 0;
272 /***********************************************************************
273 simple function to prune a pathname down to the basename of a file
274 **********************************************************************/
276 static char* dos_basename ( char *path )
278 char *p;
280 p = strrchr( path, '\\' );
281 if ( p )
282 p++;
283 else
284 p = path;
286 return p;
289 /**********************************************************************
290 handle enumeration of values below
291 KEY_PRINTING\Environments\<arch>\<version>\<drivername>
292 *********************************************************************/
294 static int print_subpath_values_environments( char *key, REGVAL_CTR *val )
296 char *keystr, *base, *subkeypath;
297 pstring key2;
298 fstring arch_environment;
299 fstring driver;
300 int version;
301 NT_PRINTER_DRIVER_INFO_LEVEL driver_ctr;
302 NT_PRINTER_DRIVER_INFO_LEVEL_3 *info3;
303 WERROR w_result;
304 char *buffer = NULL;
305 char *buffer2 = NULL;
306 int buffer_size = 0;
307 int i, length;
308 char *filename;
309 UNISTR2 data;
310 int env_subkey_type = 0;
313 DEBUG(8,("print_subpath_values_environments: Enter key => [%s]\n", key ? key : "NULL"));
315 if ( !key )
316 return 0;
318 /* The only keys below KEY_PRINTING\Environments is the
319 specific printer driver info */
321 /* environment */
323 pstrcpy( key2, key );
324 keystr = key2;
325 reg_split_path( keystr, &base, &subkeypath );
326 if ( !subkeypath )
327 return 0;
328 fstrcpy( arch_environment, base );
330 /* Driver */
332 keystr = subkeypath;
333 reg_split_path( keystr, &base, &subkeypath );
335 if ( strequal(base, "Drivers") )
336 env_subkey_type = ENVIRONMENT_DRIVERS;
337 else if ( strequal(base, "Print Processors") )
338 env_subkey_type = ENVIRONMENT_PRINTPROC;
339 else
340 /* invalid path */
341 return -1;
343 if ( !subkeypath )
344 return 0;
346 /* for now bail out if we are seeing anything other than the drivers key */
348 if ( env_subkey_type == ENVIRONMENT_PRINTPROC )
349 return 0;
351 keystr = subkeypath;
352 reg_split_path( keystr, &base, &subkeypath );
354 version = atoi(&base[strlen(base)-1]);
356 /* printer driver name */
358 keystr = subkeypath;
359 reg_split_path( keystr, &base, &subkeypath );
360 /* don't go any deeper for now */
361 if ( subkeypath )
362 return 0;
363 fstrcpy( driver, base );
365 w_result = get_a_printer_driver( &driver_ctr, 3, driver, arch_environment, version );
367 if ( !W_ERROR_IS_OK(w_result) )
368 return -1;
370 /* build the values out of the driver information */
371 info3 = driver_ctr.info_3;
373 filename = dos_basename( info3->driverpath );
374 init_unistr2( &data, filename, UNI_STR_TERMINATE);
375 regval_ctr_addvalue( val, "Driver", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
377 filename = dos_basename( info3->configfile );
378 init_unistr2( &data, filename, UNI_STR_TERMINATE);
379 regval_ctr_addvalue( val, "Configuration File", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
381 filename = dos_basename( info3->datafile );
382 init_unistr2( &data, filename, UNI_STR_TERMINATE);
383 regval_ctr_addvalue( val, "Data File", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
385 filename = dos_basename( info3->helpfile );
386 init_unistr2( &data, filename, UNI_STR_TERMINATE);
387 regval_ctr_addvalue( val, "Help File", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
389 init_unistr2( &data, info3->defaultdatatype, UNI_STR_TERMINATE);
390 regval_ctr_addvalue( val, "Data Type", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
392 regval_ctr_addvalue( val, "Version", REG_DWORD, (char*)&info3->cversion, sizeof(info3->cversion) );
394 if ( info3->dependentfiles ) {
395 /* place the list of dependent files in a single
396 character buffer, separating each file name by
397 a NULL */
399 for ( i=0; strcmp(info3->dependentfiles[i], ""); i++ ) {
400 /* strip the path to only the file's base name */
402 filename = dos_basename( info3->dependentfiles[i] );
404 length = strlen(filename);
406 buffer2 = SMB_REALLOC( buffer, buffer_size + (length + 1)*sizeof(uint16) );
407 if ( !buffer2 )
408 break;
409 buffer = buffer2;
411 init_unistr2( &data, filename, UNI_STR_TERMINATE);
412 memcpy( buffer+buffer_size, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
414 buffer_size += (length + 1)*sizeof(uint16);
417 /* terminated by double NULL. Add the final one here */
419 buffer2 = SMB_REALLOC( buffer, buffer_size + 2 );
420 if ( !buffer2 ) {
421 SAFE_FREE( buffer );
422 buffer_size = 0;
423 } else {
424 buffer = buffer2;
425 buffer[buffer_size++] = '\0';
426 buffer[buffer_size++] = '\0';
430 regval_ctr_addvalue( val, "Dependent Files", REG_MULTI_SZ, buffer, buffer_size );
432 free_a_printer_driver( driver_ctr, 3 );
434 SAFE_FREE( buffer );
436 DEBUG(8,("print_subpath_values_environments: Exit\n"));
438 return regval_ctr_numvals( val );
442 /**********************************************************************
443 handle enumeration of subkeys below KEY_PRINTING\Forms
444 Really just a stub function, but left here in case it needs to
445 be expanded later on
446 *********************************************************************/
448 static int print_subpath_forms( char *key, REGSUBKEY_CTR *subkeys )
450 DEBUG(10,("print_subpath_forms: key=>[%s]\n", key ? key : "NULL" ));
452 /* there are no subkeys */
454 if ( key )
455 return -1;
457 return 0;
460 /**********************************************************************
461 handle enumeration of values below KEY_PRINTING\Forms
462 *********************************************************************/
464 static int print_subpath_values_forms( char *key, REGVAL_CTR *val )
466 int num_values = 0;
467 uint32 data[8];
468 int form_index = 1;
470 DEBUG(10,("print_values_forms: key=>[%s]\n", key ? key : "NULL" ));
472 /* handle ..\Forms\ */
474 if ( !key )
476 nt_forms_struct *forms_list = NULL;
477 nt_forms_struct *form = NULL;
478 int i;
480 if ( (num_values = get_ntforms( &forms_list )) == 0 )
481 return 0;
483 DEBUG(10,("print_subpath_values_forms: [%d] user defined forms returned\n",
484 num_values));
486 /* handle user defined forms */
488 for ( i=0; i<num_values; i++ )
490 form = &forms_list[i];
492 data[0] = form->width;
493 data[1] = form->length;
494 data[2] = form->left;
495 data[3] = form->top;
496 data[4] = form->right;
497 data[5] = form->bottom;
498 data[6] = form_index++;
499 data[7] = form->flag;
501 regval_ctr_addvalue( val, form->name, REG_BINARY, (char*)data, sizeof(data) );
505 SAFE_FREE( forms_list );
506 forms_list = NULL;
508 /* handle built-on forms */
510 if ( (num_values = get_builtin_ntforms( &forms_list )) == 0 )
511 return 0;
513 DEBUG(10,("print_subpath_values_forms: [%d] built-in forms returned\n",
514 num_values));
516 for ( i=0; i<num_values; i++ )
518 form = &forms_list[i];
520 data[0] = form->width;
521 data[1] = form->length;
522 data[2] = form->left;
523 data[3] = form->top;
524 data[4] = form->right;
525 data[5] = form->bottom;
526 data[6] = form_index++;
527 data[7] = form->flag;
529 regval_ctr_addvalue( val, form->name, REG_BINARY, (char*)data, sizeof(data) );
532 SAFE_FREE( forms_list );
535 return num_values;
538 /**********************************************************************
539 handle enumeration of subkeys below KEY_PRINTING\Printers
540 *********************************************************************/
542 static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys )
544 int n_services = lp_numservices();
545 int snum;
546 fstring sname;
547 int i;
548 int num_subkeys = 0;
549 char *keystr, *key2 = NULL;
550 char *base, *new_path;
551 NT_PRINTER_INFO_LEVEL *printer = NULL;
552 fstring *subkey_names = NULL;
554 DEBUG(10,("print_subpath_printers: key=>[%s]\n", key ? key : "NULL" ));
556 if ( !key )
558 /* enumerate all printers */
560 for (snum=0; snum<n_services; snum++) {
561 if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
562 continue;
564 /* don't report the [printers] share */
566 if ( strequal( lp_servicename(snum), PRINTERS_NAME ) )
567 continue;
569 fstrcpy( sname, lp_servicename(snum) );
571 regsubkey_ctr_addkey( subkeys, sname );
574 num_subkeys = regsubkey_ctr_numkeys( subkeys );
575 goto done;
578 /* get information for a specific printer */
580 key2 = SMB_STRDUP( key );
581 keystr = key2;
582 reg_split_path( keystr, &base, &new_path );
584 if ( !W_ERROR_IS_OK( get_a_printer(NULL, &printer, 2, base) ) )
585 goto done;
587 num_subkeys = get_printer_subkeys( &printer->info_2->data, new_path?new_path:"", &subkey_names );
589 for ( i=0; i<num_subkeys; i++ )
590 regsubkey_ctr_addkey( subkeys, subkey_names[i] );
592 free_a_printer( &printer, 2 );
594 /* no other subkeys below here */
596 done:
597 SAFE_FREE( key2 );
598 SAFE_FREE( subkey_names );
600 return num_subkeys;
603 /**********************************************************************
604 handle enumeration of values below KEY_PRINTING\Printers
605 *********************************************************************/
607 static int print_subpath_values_printers( char *key, REGVAL_CTR *val )
609 int num_values = 0;
610 char *keystr, *key2 = NULL;
611 char *base, *new_path;
612 NT_PRINTER_INFO_LEVEL *printer = NULL;
613 NT_PRINTER_INFO_LEVEL_2 *info2;
614 DEVICEMODE *devmode;
615 prs_struct prs;
616 uint32 offset;
617 int snum;
618 fstring printername;
619 NT_PRINTER_DATA *p_data;
620 int i, key_index;
621 UNISTR2 data;
624 * Theres are tw cases to deal with here
625 * (1) enumeration of printer_info_2 values
626 * (2) enumeration of the PrinterDriverData subney
629 if ( !key ) {
630 /* top level key has no values */
631 goto done;
634 key2 = SMB_STRDUP( key );
635 keystr = key2;
636 reg_split_path( keystr, &base, &new_path );
638 fstrcpy( printername, base );
640 if ( !new_path ) {
641 char *p;
643 /* we are dealing with the printer itself */
645 if ( !W_ERROR_IS_OK( get_a_printer(NULL, &printer, 2, printername) ) )
646 goto done;
648 info2 = printer->info_2;
651 regval_ctr_addvalue( val, "Attributes", REG_DWORD, (char*)&info2->attributes, sizeof(info2->attributes) );
652 regval_ctr_addvalue( val, "Priority", REG_DWORD, (char*)&info2->priority, sizeof(info2->attributes) );
653 regval_ctr_addvalue( val, "ChangeID", REG_DWORD, (char*)&info2->changeid, sizeof(info2->changeid) );
654 regval_ctr_addvalue( val, "Default Priority", REG_DWORD, (char*)&info2->default_priority, sizeof(info2->default_priority) );
655 regval_ctr_addvalue( val, "Status", REG_DWORD, (char*)&info2->status, sizeof(info2->status) );
656 regval_ctr_addvalue( val, "StartTime", REG_DWORD, (char*)&info2->starttime, sizeof(info2->starttime) );
657 regval_ctr_addvalue( val, "UntilTime", REG_DWORD, (char*)&info2->untiltime, sizeof(info2->untiltime) );
659 /* strip the \\server\ from this string */
660 if ( !(p = strrchr( info2->printername, '\\' ) ) )
661 p = info2->printername;
662 else
663 p++;
664 init_unistr2( &data, p, UNI_STR_TERMINATE);
665 regval_ctr_addvalue( val, "Name", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
667 init_unistr2( &data, info2->location, UNI_STR_TERMINATE);
668 regval_ctr_addvalue( val, "Location", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
670 init_unistr2( &data, info2->comment, UNI_STR_TERMINATE);
671 regval_ctr_addvalue( val, "Description", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
673 init_unistr2( &data, info2->parameters, UNI_STR_TERMINATE);
674 regval_ctr_addvalue( val, "Parameters", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
676 init_unistr2( &data, info2->portname, UNI_STR_TERMINATE);
677 regval_ctr_addvalue( val, "Port", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
679 init_unistr2( &data, info2->sharename, UNI_STR_TERMINATE);
680 regval_ctr_addvalue( val, "Share Name", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
682 init_unistr2( &data, info2->drivername, UNI_STR_TERMINATE);
683 regval_ctr_addvalue( val, "Printer Driver", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
685 init_unistr2( &data, info2->sepfile, UNI_STR_TERMINATE);
686 regval_ctr_addvalue( val, "Separator File", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
688 init_unistr2( &data, "WinPrint", UNI_STR_TERMINATE);
689 regval_ctr_addvalue( val, "Print Processor", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
691 init_unistr2( &data, "RAW", UNI_STR_TERMINATE);
692 regval_ctr_addvalue( val, "Datatype", REG_SZ, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
695 /* use a prs_struct for converting the devmode and security
696 descriptor to REG_BINARY */
698 prs_init( &prs, MAX_PDU_FRAG_LEN, regval_ctr_getctx(val), MARSHALL);
700 /* stream the device mode */
702 snum = lp_servicenumber(info2->sharename);
703 if ( (devmode = construct_dev_mode( snum )) != NULL )
705 if ( spoolss_io_devmode( "devmode", &prs, 0, devmode ) ) {
707 offset = prs_offset( &prs );
709 regval_ctr_addvalue( val, "Default Devmode", REG_BINARY, prs_data_p(&prs), offset );
715 prs_mem_clear( &prs );
716 prs_set_offset( &prs, 0 );
718 if ( info2->secdesc_buf && info2->secdesc_buf->len )
720 if ( sec_io_desc("sec_desc", &info2->secdesc_buf->sec, &prs, 0 ) ) {
722 offset = prs_offset( &prs );
724 regval_ctr_addvalue( val, "Security", REG_BINARY, prs_data_p(&prs), offset );
728 prs_mem_free( &prs );
730 num_values = regval_ctr_numvals( val );
732 goto done;
736 /* now enumerate the key */
738 if ( !W_ERROR_IS_OK( get_a_printer(NULL, &printer, 2, printername) ) )
739 goto done;
741 /* iterate over all printer data and fill the regval container */
743 p_data = &printer->info_2->data;
744 if ( (key_index = lookup_printerkey( p_data, new_path )) == -1 ) {
745 DEBUG(10,("print_subpath_values_printer: Unknown keyname [%s]\n", new_path));
746 goto done;
749 num_values = regval_ctr_numvals( &p_data->keys[key_index].values );
751 for ( i=0; i<num_values; i++ )
752 regval_ctr_copyvalue( val, regval_ctr_specific_value(&p_data->keys[key_index].values, i) );
755 done:
756 if ( printer )
757 free_a_printer( &printer, 2 );
759 SAFE_FREE( key2 );
761 return num_values;
764 /**********************************************************************
765 Routine to handle enumeration of subkeys and values
766 below KEY_PRINTING (depending on whether or not subkeys/val are
767 valid pointers.
768 *********************************************************************/
770 static int handle_printing_subpath( char *key, REGSUBKEY_CTR *subkeys, REGVAL_CTR *val )
772 int result = 0;
773 char *p, *base;
774 int i;
776 DEBUG(10,("handle_printing_subpath: key=>[%s]\n", key ));
779 * break off the first part of the path
780 * topmost base **must** be one of the strings
781 * in top_level_keys[]
784 reg_split_path( key, &base, &p);
786 for ( i=0; i<MAX_TOP_LEVEL_KEYS; i++ ) {
787 if ( StrCaseCmp( top_level_keys[i], base ) == 0 )
788 break;
791 DEBUG(10,("handle_printing_subpath: base=>[%s], i==[%d]\n", base, i));
793 if ( !(i < MAX_TOP_LEVEL_KEYS) )
794 return -1;
796 /* Call routine to handle each top level key */
797 switch ( i )
799 case KEY_INDEX_ENVIR:
800 if ( subkeys )
801 print_subpath_environments( p, subkeys );
802 if ( val )
803 print_subpath_values_environments( p, val );
804 break;
806 case KEY_INDEX_FORMS:
807 if ( subkeys )
808 print_subpath_forms( p, subkeys );
809 if ( val )
810 print_subpath_values_forms( p, val );
811 break;
813 case KEY_INDEX_PRINTER:
814 if ( subkeys )
815 print_subpath_printers( p, subkeys );
816 if ( val )
817 print_subpath_values_printers( p, val );
818 break;
820 /* default case for top level key that has no handler */
822 default:
823 break;
828 return result;
831 /**********************************************************************
832 Enumerate registry subkey names given a registry path.
833 Caller is responsible for freeing memory to **subkeys
834 *********************************************************************/
836 static int printing_subkey_info( char *key, REGSUBKEY_CTR *subkey_ctr )
838 char *path;
839 BOOL top_level = False;
840 int num_subkeys = 0;
842 DEBUG(10,("printing_subkey_info: key=>[%s]\n", key));
844 path = trim_reg_path( key );
846 /* check to see if we are dealing with the top level key */
848 if ( !path )
849 top_level = True;
851 if ( top_level ) {
852 /* check between the two top level keys here */
854 if ( strequal( KEY_PRINTING, key ) ) {
855 regsubkey_ctr_addkey( subkey_ctr, "Environments" );
856 regsubkey_ctr_addkey( subkey_ctr, "Forms" );
858 else if ( strequal( KEY_PRINTING_2K, key ) ) {
859 regsubkey_ctr_addkey( subkey_ctr, "Printers" );
862 else
863 num_subkeys = handle_printing_subpath( path, subkey_ctr, NULL );
865 SAFE_FREE( path );
867 return num_subkeys;
870 /**********************************************************************
871 Enumerate registry values given a registry path.
872 Caller is responsible for freeing memory
873 *********************************************************************/
875 static int printing_value_info( char *key, REGVAL_CTR *val )
877 char *path;
878 BOOL top_level = False;
879 int num_values = 0;
881 DEBUG(10,("printing_value_info: key=>[%s]\n", key));
883 path = trim_reg_path( key );
885 /* check to see if we are dealing with the top level key */
887 if ( !path )
888 top_level = True;
890 /* fill in values from the getprinterdata_printer_server() */
891 if ( top_level ) {
892 if ( strequal( key, KEY_PRINTING_PORTS ) )
893 num_values = fill_ports_values( val );
894 } else
895 num_values = handle_printing_subpath( path, NULL, val );
898 return num_values;
901 /**********************************************************************
902 Stub function which always returns failure since we don't want
903 people storing printing information directly via regostry calls
904 (for now at least)
905 *********************************************************************/
907 static BOOL printing_store_subkey( char *key, REGSUBKEY_CTR *subkeys )
909 return True;
912 /**********************************************************************
913 Stub function which always returns failure since we don't want
914 people storing printing information directly via regostry calls
915 (for now at least)
916 *********************************************************************/
918 static BOOL printing_store_value( char *key, REGVAL_CTR *val )
920 return True;
924 * Table of function pointers for accessing printing data
927 REGISTRY_OPS printing_ops = {
928 printing_subkey_info,
929 printing_value_info,
930 printing_store_subkey,
931 printing_store_value