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 */
26 #define DBGC_CLASS DBGC_RPC_SRV
28 /* registrt paths used in the print_registry[] */
30 #define KEY_MONITORS "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/MONITORS"
31 #define KEY_FORMS "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/FORMS"
32 #define KEY_CONTROL_PRINTERS "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/PRINTERS"
33 #define KEY_ENVIRONMENTS "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/ENVIRONMENTS"
34 #define KEY_CONTROL_PRINT "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT"
35 #define KEY_WINNT_PRINTERS "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PRINT/PRINTERS"
36 #define KEY_WINNT_PRINT "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PRINT"
37 #define KEY_PORTS "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PORTS"
39 /* callback table for various registry paths below the ones we service in this module */
42 /* full key path in normalized form */
45 /* callbscks for fetch/store operations */
46 int ( *fetch_subkeys
) ( const char *path
, REGSUBKEY_CTR
*subkeys
);
47 BOOL (*store_subkeys
) ( const char *path
, REGSUBKEY_CTR
*subkeys
);
48 int (*fetch_values
) ( const char *path
, REGVAL_CTR
*values
);
49 BOOL (*store_values
) ( const char *path
, REGVAL_CTR
*values
);
52 /*********************************************************************
53 *********************************************************************
55 *********************************************************************
56 *********************************************************************/
58 /***********************************************************************
59 simple function to prune a pathname down to the basename of a file
60 **********************************************************************/
62 static char* dos_basename ( char *path
)
66 if ( !(p
= strrchr( path
, '\\' )) )
74 /*********************************************************************
75 *********************************************************************
76 ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/FORMS"
77 *********************************************************************
78 *********************************************************************/
80 static int key_forms_fetch_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
82 char *p
= reg_remaining_path( key
+ strlen(KEY_FORMS
) );
84 /* no keys below Forms */
92 /**********************************************************************
93 *********************************************************************/
95 static int key_forms_fetch_values( const char *key
, REGVAL_CTR
*values
)
98 int i
, num_values
, form_index
= 1;
99 nt_forms_struct
*forms_list
= NULL
;
100 nt_forms_struct
*form
;
102 DEBUG(10,("print_values_forms: key=>[%s]\n", key
? key
: "NULL" ));
104 num_values
= get_ntforms( &forms_list
);
106 DEBUG(10,("hive_forms_fetch_values: [%d] user defined forms returned\n",
109 /* handle user defined forms */
111 for ( i
=0; i
<num_values
; i
++ ) {
112 form
= &forms_list
[i
];
114 data
[0] = form
->width
;
115 data
[1] = form
->length
;
116 data
[2] = form
->left
;
118 data
[4] = form
->right
;
119 data
[5] = form
->bottom
;
120 data
[6] = form_index
++;
121 data
[7] = form
->flag
;
123 regval_ctr_addvalue( values
, form
->name
, REG_BINARY
, (char*)data
, sizeof(data
) );
126 SAFE_FREE( forms_list
);
129 /* handle built-on forms */
131 num_values
= get_builtin_ntforms( &forms_list
);
133 DEBUG(10,("print_subpath_values_forms: [%d] built-in forms returned\n",
136 for ( i
=0; i
<num_values
; i
++ ) {
137 form
= &forms_list
[i
];
139 data
[0] = form
->width
;
140 data
[1] = form
->length
;
141 data
[2] = form
->left
;
143 data
[4] = form
->right
;
144 data
[5] = form
->bottom
;
145 data
[6] = form_index
++;
146 data
[7] = form
->flag
;
148 regval_ctr_addvalue( values
, form
->name
, REG_BINARY
, (char*)data
, sizeof(data
) );
151 SAFE_FREE( forms_list
);
153 return regval_ctr_numvals( values
);
156 /*********************************************************************
157 *********************************************************************
158 ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/PRINTERS"
159 ** "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PRINT/PRINTERS"
160 *********************************************************************
161 *********************************************************************/
163 /*********************************************************************
164 strip off prefix for printers key. DOes return a pointer to static
166 *********************************************************************/
168 static char* strip_printers_prefix( const char *key
)
173 pstrcpy( path
, key
);
174 normalize_reg_path( path
);
176 /* normalizing the path does not change length, just key delimiters and case */
178 if ( strncmp( path
, KEY_WINNT_PRINTERS
, strlen(KEY_WINNT_PRINTERS
) ) == 0 )
179 subkeypath
= reg_remaining_path( key
+ strlen(KEY_WINNT_PRINTERS
) );
181 subkeypath
= reg_remaining_path( key
+ strlen(KEY_CONTROL_PRINTERS
) );
186 /*********************************************************************
187 *********************************************************************/
189 static int key_printers_fetch_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
191 int n_services
= lp_numservices();
197 char *printername
, *printerdatakey
;
198 NT_PRINTER_INFO_LEVEL
*printer
= NULL
;
199 fstring
*subkey_names
= NULL
;
201 DEBUG(10,("key_printers_fetch_keys: key=>[%s]\n", key
? key
: "NULL" ));
203 printers_key
= strip_printers_prefix( key
);
205 if ( !printers_key
) {
206 /* enumerate all printers */
208 for (snum
=0; snum
<n_services
; snum
++) {
209 if ( !(lp_snum_ok(snum
) && lp_print_ok(snum
) ) )
212 /* don't report the [printers] share */
214 if ( strequal( lp_servicename(snum
), PRINTERS_NAME
) )
217 fstrcpy( sname
, lp_servicename(snum
) );
219 regsubkey_ctr_addkey( subkeys
, sname
);
222 num_subkeys
= regsubkey_ctr_numkeys( subkeys
);
226 /* get information for a specific printer */
228 reg_split_path( printers_key
, &printername
, &printerdatakey
);
230 if ( find_service(printername
) == -1
231 || !W_ERROR_IS_OK( get_a_printer(NULL
, &printer
, 2, printername
) ) )
236 num_subkeys
= get_printer_subkeys( printer
->info_2
->data
, printerdatakey
?printerdatakey
:"", &subkey_names
);
238 for ( i
=0; i
<num_subkeys
; i
++ )
239 regsubkey_ctr_addkey( subkeys
, subkey_names
[i
] );
241 free_a_printer( &printer
, 2 );
243 /* no other subkeys below here */
246 SAFE_FREE( subkey_names
);
251 /**********************************************************************
252 Take a list of names and call add_printer_hook() if necessary
253 Note that we do this a little differently from Windows since the
254 keyname is the sharename and not the printer name.
255 *********************************************************************/
257 static BOOL
add_printers_by_registry( REGSUBKEY_CTR
*subkeys
)
259 int i
, num_keys
, snum
;
261 NT_PRINTER_INFO_LEVEL_2 info2
;
262 NT_PRINTER_INFO_LEVEL printer
;
264 ZERO_STRUCT( info2
);
265 printer
.info_2
= &info2
;
267 num_keys
= regsubkey_ctr_numkeys( subkeys
);
270 for ( i
=0; i
<num_keys
; i
++ ) {
271 printername
= regsubkey_ctr_specific_key( subkeys
, i
);
272 snum
= find_service( printername
);
274 /* just verify a valied snum for now */
276 fstrcpy( info2
.printername
, printername
);
277 fstrcpy( info2
.sharename
, printername
);
278 if ( !add_printer_hook( NULL
, &printer
) ) {
279 DEBUG(0,("add_printers_by_registry: Failed to add printer [%s]\n",
289 /**********************************************************************
290 *********************************************************************/
292 static BOOL
key_printers_store_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
295 char *printername
, *printerdatakey
;
296 NT_PRINTER_INFO_LEVEL
*printer
= NULL
;
297 int i
, num_subkeys
, num_existing_keys
;
299 fstring
*existing_subkeys
= NULL
;
301 printers_key
= strip_printers_prefix( key
);
303 if ( !printers_key
) {
304 /* have to deal with some new or deleted printer */
305 return add_printers_by_registry( subkeys
);
308 reg_split_path( printers_key
, &printername
, &printerdatakey
);
310 /* lookup the printer */
312 if ( !W_ERROR_IS_OK(get_a_printer(NULL
, &printer
, 2, printername
)) ) {
313 DEBUG(0,("key_printers_store_keys: Tried to store subkey for bad printername %s\n",
318 /* get the top level printer keys */
320 num_existing_keys
= get_printer_subkeys( printer
->info_2
->data
, "", &existing_subkeys
);
322 for ( i
=0; i
<num_existing_keys
; i
++ ) {
324 /* remove the key if it has been deleted */
326 if ( !regsubkey_ctr_key_exists( subkeys
, existing_subkeys
[i
] ) ) {
327 DEBUG(5,("key_printers_store_keys: deleting key %s\n",
328 existing_subkeys
[i
]));
329 delete_printer_key( printer
->info_2
->data
, existing_subkeys
[i
] );
333 num_subkeys
= regsubkey_ctr_numkeys( subkeys
);
334 for ( i
=0; i
<num_subkeys
; i
++ ) {
335 subkeyname
= regsubkey_ctr_specific_key(subkeys
, i
);
336 /* add any missing printer keys */
337 if ( lookup_printerkey(printer
->info_2
->data
, subkeyname
) == -1 ) {
338 DEBUG(5,("key_printers_store_keys: adding key %s\n",
339 existing_subkeys
[i
]));
340 if ( add_new_printer_key( printer
->info_2
->data
, subkeyname
) == -1 )
345 /* write back to disk */
347 mod_a_printer( printer
, 2 );
352 free_a_printer( &printer
, 2 );
357 /**********************************************************************
358 *********************************************************************/
360 static void fill_in_printer_values( NT_PRINTER_INFO_LEVEL_2
*info2
, REGVAL_CTR
*values
)
367 uint32 printer_status
= PRINTER_STATUS_OK
;
370 regval_ctr_addvalue( values
, "Attributes", REG_DWORD
, (char*)&info2
->attributes
, sizeof(info2
->attributes
) );
371 regval_ctr_addvalue( values
, "Priority", REG_DWORD
, (char*)&info2
->priority
, sizeof(info2
->attributes
) );
372 regval_ctr_addvalue( values
, "ChangeID", REG_DWORD
, (char*)&info2
->changeid
, sizeof(info2
->changeid
) );
373 regval_ctr_addvalue( values
, "Default Priority", REG_DWORD
, (char*)&info2
->default_priority
, sizeof(info2
->default_priority
) );
375 /* lie and say everything is ok since we don't want to call print_queue_length() to get the real status */
376 regval_ctr_addvalue( values
, "Status", REG_DWORD
, (char*)&printer_status
, sizeof(info2
->status
) );
378 regval_ctr_addvalue( values
, "StartTime", REG_DWORD
, (char*)&info2
->starttime
, sizeof(info2
->starttime
) );
379 regval_ctr_addvalue( values
, "UntilTime", REG_DWORD
, (char*)&info2
->untiltime
, sizeof(info2
->untiltime
) );
381 /* strip the \\server\ from this string */
382 if ( !(p
= strrchr( info2
->printername
, '\\' ) ) )
383 p
= info2
->printername
;
386 init_unistr2( &data
, p
, UNI_STR_TERMINATE
);
387 regval_ctr_addvalue( values
, "Name", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
389 init_unistr2( &data
, info2
->location
, UNI_STR_TERMINATE
);
390 regval_ctr_addvalue( values
, "Location", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
392 init_unistr2( &data
, info2
->comment
, UNI_STR_TERMINATE
);
393 regval_ctr_addvalue( values
, "Description", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
395 init_unistr2( &data
, info2
->parameters
, UNI_STR_TERMINATE
);
396 regval_ctr_addvalue( values
, "Parameters", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
398 init_unistr2( &data
, info2
->portname
, UNI_STR_TERMINATE
);
399 regval_ctr_addvalue( values
, "Port", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
401 init_unistr2( &data
, info2
->sharename
, UNI_STR_TERMINATE
);
402 regval_ctr_addvalue( values
, "Share Name", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
404 init_unistr2( &data
, info2
->drivername
, UNI_STR_TERMINATE
);
405 regval_ctr_addvalue( values
, "Printer Driver", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
407 init_unistr2( &data
, info2
->sepfile
, UNI_STR_TERMINATE
);
408 regval_ctr_addvalue( values
, "Separator File", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
410 init_unistr2( &data
, "WinPrint", UNI_STR_TERMINATE
);
411 regval_ctr_addvalue( values
, "Print Processor", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
413 init_unistr2( &data
, "RAW", UNI_STR_TERMINATE
);
414 regval_ctr_addvalue( values
, "Datatype", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
417 /* use a prs_struct for converting the devmode and security
418 descriptor to REG_BINARY */
420 prs_init( &prs
, RPC_MAX_PDU_FRAG_LEN
, values
, MARSHALL
);
422 /* stream the device mode */
424 snum
= lp_servicenumber(info2
->sharename
);
425 if ( (devmode
= construct_dev_mode( snum
)) != NULL
) {
426 if ( spoolss_io_devmode( "devmode", &prs
, 0, devmode
) ) {
427 offset
= prs_offset( &prs
);
428 regval_ctr_addvalue( values
, "Default Devmode", REG_BINARY
, prs_data_p(&prs
), offset
);
432 prs_mem_clear( &prs
);
433 prs_set_offset( &prs
, 0 );
435 /* stream the printer security descriptor */
437 if ( info2
->secdesc_buf
&& info2
->secdesc_buf
->len
) {
438 if ( sec_io_desc("sec_desc", &info2
->secdesc_buf
->sec
, &prs
, 0 ) ) {
439 offset
= prs_offset( &prs
);
440 regval_ctr_addvalue( values
, "Security", REG_BINARY
, prs_data_p(&prs
), offset
);
444 prs_mem_free( &prs
);
449 /**********************************************************************
450 *********************************************************************/
452 static int key_printers_fetch_values( const char *key
, REGVAL_CTR
*values
)
456 char *printername
, *printerdatakey
;
457 NT_PRINTER_INFO_LEVEL
*printer
= NULL
;
458 NT_PRINTER_DATA
*p_data
;
461 printers_key
= strip_printers_prefix( key
);
463 /* top level key values stored in the registry has no values */
465 if ( !printers_key
) {
466 /* normalize to the 'HKLM\SOFTWARE\...\Print\Printers' ket */
467 return regdb_fetch_values( KEY_WINNT_PRINTERS
, values
);
470 /* lookup the printer object */
472 reg_split_path( printers_key
, &printername
, &printerdatakey
);
473 if ( !W_ERROR_IS_OK( get_a_printer(NULL
, &printer
, 2, printername
) ) )
476 if ( !printerdatakey
) {
477 fill_in_printer_values( printer
->info_2
, values
);
481 /* iterate over all printer data keys and fill the regval container */
483 p_data
= printer
->info_2
->data
;
484 if ( (key_index
= lookup_printerkey( p_data
, printerdatakey
)) == -1 ) {
485 /* failure....should never happen if the client has a valid open handle first */
486 DEBUG(10,("key_printers_fetch_values: Unknown keyname [%s]\n", printerdatakey
));
488 free_a_printer( &printer
, 2 );
492 num_values
= regval_ctr_numvals( p_data
->keys
[key_index
].values
);
493 for ( i
=0; i
<num_values
; i
++ )
494 regval_ctr_copyvalue( values
, regval_ctr_specific_value(p_data
->keys
[key_index
].values
, i
) );
499 free_a_printer( &printer
, 2 );
501 return regval_ctr_numvals( values
);
504 /**********************************************************************
505 *********************************************************************/
507 #define REG_IDX_ATTRIBUTES 1
508 #define REG_IDX_PRIORITY 2
509 #define REG_IDX_DEFAULT_PRIORITY 3
510 #define REG_IDX_CHANGEID 4
511 #define REG_IDX_STATUS 5
512 #define REG_IDX_STARTTIME 6
513 #define REG_IDX_NAME 7
514 #define REG_IDX_LOCATION 8
515 #define REG_IDX_DESCRIPTION 9
516 #define REG_IDX_PARAMETERS 10
517 #define REG_IDX_PORT 12
518 #define REG_IDX_SHARENAME 13
519 #define REG_IDX_DRIVER 14
520 #define REG_IDX_SEP_FILE 15
521 #define REG_IDX_PRINTPROC 16
522 #define REG_IDX_DATATYPE 17
523 #define REG_IDX_DEVMODE 18
524 #define REG_IDX_SECDESC 19
525 #define REG_IDX_UNTILTIME 20
530 } printer_values_map
[] = {
531 { "Attributes", REG_IDX_ATTRIBUTES
},
532 { "Priority", REG_IDX_PRIORITY
},
533 { "Default Priority", REG_IDX_DEFAULT_PRIORITY
},
534 { "ChangeID", REG_IDX_CHANGEID
},
535 { "Status", REG_IDX_STATUS
},
536 { "StartTime", REG_IDX_STARTTIME
},
537 { "UntilTime", REG_IDX_UNTILTIME
},
538 { "Name", REG_IDX_NAME
},
539 { "Location", REG_IDX_LOCATION
},
540 { "Descrioption", REG_IDX_DESCRIPTION
},
541 { "Parameters", REG_IDX_PARAMETERS
},
542 { "Port", REG_IDX_PORT
},
543 { "Share Name", REG_IDX_SHARENAME
},
544 { "Printer Driver", REG_IDX_DRIVER
},
545 { "Separator File", REG_IDX_SEP_FILE
},
546 { "Print Processor", REG_IDX_PRINTPROC
},
547 { "Datatype", REG_IDX_DATATYPE
},
548 { "Default Devmode", REG_IDX_DEVMODE
},
549 { "Security", REG_IDX_SECDESC
},
554 static int find_valuename_index( const char *valuename
)
558 for ( i
=0; printer_values_map
[i
].name
; i
++ ) {
559 if ( strequal( valuename
, printer_values_map
[i
].name
) )
560 return printer_values_map
[i
].index
;
566 /**********************************************************************
567 *********************************************************************/
569 static void convert_values_to_printer_info_2( NT_PRINTER_INFO_LEVEL_2
*printer2
, REGVAL_CTR
*values
)
571 int num_values
= regval_ctr_numvals( values
);
576 for ( i
=0; i
<num_values
; i
++ ) {
577 val
= regval_ctr_specific_value( values
, i
);
578 value_index
= find_valuename_index( regval_name( val
) );
580 switch( value_index
) {
581 case REG_IDX_ATTRIBUTES
:
582 printer2
->attributes
= (uint32
)(*regval_data_p(val
));
584 case REG_IDX_PRIORITY
:
585 printer2
->priority
= (uint32
)(*regval_data_p(val
));
587 case REG_IDX_DEFAULT_PRIORITY
:
588 printer2
->default_priority
= (uint32
)(*regval_data_p(val
));
590 case REG_IDX_CHANGEID
:
591 printer2
->changeid
= (uint32
)(*regval_data_p(val
));
593 case REG_IDX_STARTTIME
:
594 printer2
->starttime
= (uint32
)(*regval_data_p(val
));
596 case REG_IDX_UNTILTIME
:
597 printer2
->untiltime
= (uint32
)(*regval_data_p(val
));
600 rpcstr_pull( printer2
->printername
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
602 case REG_IDX_LOCATION
:
603 rpcstr_pull( printer2
->location
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
605 case REG_IDX_DESCRIPTION
:
606 rpcstr_pull( printer2
->comment
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
608 case REG_IDX_PARAMETERS
:
609 rpcstr_pull( printer2
->parameters
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
612 rpcstr_pull( printer2
->portname
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
614 case REG_IDX_SHARENAME
:
615 rpcstr_pull( printer2
->sharename
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
618 rpcstr_pull( printer2
->drivername
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
620 case REG_IDX_SEP_FILE
:
621 rpcstr_pull( printer2
->sepfile
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
623 case REG_IDX_PRINTPROC
:
624 rpcstr_pull( printer2
->printprocessor
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
626 case REG_IDX_DATATYPE
:
627 rpcstr_pull( printer2
->datatype
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
629 case REG_IDX_DEVMODE
:
631 case REG_IDX_SECDESC
:
634 /* unsupported value...throw away */
635 DEBUG(8,("convert_values_to_printer_info_2: Unsupported registry value [%s]\n",
636 regval_name( val
) ));
643 /**********************************************************************
644 *********************************************************************/
646 static BOOL
key_printers_store_values( const char *key
, REGVAL_CTR
*values
)
649 char *printername
, *keyname
;
650 NT_PRINTER_INFO_LEVEL
*printer
= NULL
;
653 printers_key
= strip_printers_prefix( key
);
655 /* values in the top level key get stored in the registry */
657 if ( !printers_key
) {
658 /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
659 return regdb_store_values( KEY_WINNT_PRINTERS
, values
);
662 reg_split_path( printers_key
, &printername
, &keyname
);
664 if ( !W_ERROR_IS_OK(get_a_printer(NULL
, &printer
, 2, printername
) ) )
667 /* deal with setting values directly under the printername */
670 convert_values_to_printer_info_2( printer
->info_2
, values
);
673 int num_values
= regval_ctr_numvals( values
);
677 delete_printer_key( printer
->info_2
->data
, keyname
);
679 /* deal with any subkeys */
680 for ( i
=0; i
<num_values
; i
++ ) {
681 val
= regval_ctr_specific_value( values
, i
);
682 result
= set_printer_dataex( printer
, keyname
,
685 regval_data_p( val
),
686 regval_size( val
) );
687 if ( !W_ERROR_IS_OK(result
) ) {
688 DEBUG(0,("key_printers_store_values: failed to set printer data [%s]!\n",
690 free_a_printer( &printer
, 2 );
696 result
= mod_a_printer( printer
, 2 );
698 free_a_printer( &printer
, 2 );
700 return W_ERROR_IS_OK(result
);
703 /*********************************************************************
704 *********************************************************************
705 ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/ENVIRONMENTS"
706 *********************************************************************
707 *********************************************************************/
709 static int key_driver_fetch_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
711 const char *environments
[] = {
715 "Windows NT Alpha_AXP",
716 "Windows NT PowerPC",
720 fstring
*drivers
= NULL
;
721 int i
, env_index
, num_drivers
;
722 char *keystr
, *base
, *subkeypath
;
724 int num_subkeys
= -1;
727 DEBUG(10,("key_driver_fetch_keys key=>[%s]\n", key
? key
: "NULL" ));
729 keystr
= reg_remaining_path( key
+ strlen(KEY_ENVIRONMENTS
) );
731 /* list all possible architectures */
734 for ( num_subkeys
=0; environments
[num_subkeys
]; num_subkeys
++ )
735 regsubkey_ctr_addkey( subkeys
, environments
[num_subkeys
] );
740 /* we are dealing with a subkey of "Environments */
742 pstrcpy( key2
, keystr
);
744 reg_split_path( keystr
, &base
, &subkeypath
);
748 for ( env_index
=0; environments
[env_index
]; env_index
++ ) {
749 if ( strequal( environments
[env_index
], base
) )
752 if ( !environments
[env_index
] )
755 /* ...\Print\Environements\...\ */
758 regsubkey_ctr_addkey( subkeys
, "Drivers" );
759 regsubkey_ctr_addkey( subkeys
, "Print Processors" );
764 /* more of the key path to process */
767 reg_split_path( keystr
, &base
, &subkeypath
);
769 /* ...\Print\Environements\...\Drivers\ */
772 if ( strequal(base
, "Drivers") ) {
773 switch ( env_index
) {
775 regsubkey_ctr_addkey( subkeys
, "Version-0" );
777 default: /* Windows NT based systems */
778 regsubkey_ctr_addkey( subkeys
, "Version-2" );
779 regsubkey_ctr_addkey( subkeys
, "Version-3" );
783 return regsubkey_ctr_numkeys( subkeys
);
784 } else if ( strequal(base
, "Print Processors") ) {
785 if ( env_index
== 1 || env_index
== 5 || env_index
== 6 )
786 regsubkey_ctr_addkey( subkeys
, "winprint" );
788 return regsubkey_ctr_numkeys( subkeys
);
790 return -1; /* bad path */
793 /* we finally get to enumerate the drivers */
795 /* only one possible subkey below PrintProc key */
797 if ( strequal(base
, "Print Processors") ) {
799 reg_split_path( keystr
, &base
, &subkeypath
);
801 /* no subkeys below this point */
806 /* only allow one keyname here -- 'winprint' */
808 return strequal( base
, "winprint" ) ? 0 : -1;
811 /* only dealing with drivers from here on out */
814 reg_split_path( keystr
, &base
, &subkeypath
);
815 version
= atoi(&base
[strlen(base
)-1]);
823 if ( version
!= 2 && version
!= 3 )
830 num_drivers
= get_ntdrivers( &drivers
, environments
[env_index
], version
);
831 for ( i
=0; i
<num_drivers
; i
++ )
832 regsubkey_ctr_addkey( subkeys
, drivers
[i
] );
834 return regsubkey_ctr_numkeys( subkeys
);
837 /* if anything else left, just say if has no subkeys */
839 DEBUG(1,("key_driver_fetch_keys unhandled key [%s] (subkey == %s\n",
846 /**********************************************************************
847 *********************************************************************/
849 static void fill_in_driver_values( NT_PRINTER_DRIVER_INFO_LEVEL_3
*info3
, REGVAL_CTR
*values
)
852 char *buffer2
= NULL
;
858 filename
= dos_basename( info3
->driverpath
);
859 init_unistr2( &data
, filename
, UNI_STR_TERMINATE
);
860 regval_ctr_addvalue( values
, "Driver", REG_SZ
, (char*)data
.buffer
,
861 data
.uni_str_len
*sizeof(uint16
) );
863 filename
= dos_basename( info3
->configfile
);
864 init_unistr2( &data
, filename
, UNI_STR_TERMINATE
);
865 regval_ctr_addvalue( values
, "Configuration File", REG_SZ
, (char*)data
.buffer
,
866 data
.uni_str_len
*sizeof(uint16
) );
868 filename
= dos_basename( info3
->datafile
);
869 init_unistr2( &data
, filename
, UNI_STR_TERMINATE
);
870 regval_ctr_addvalue( values
, "Data File", REG_SZ
, (char*)data
.buffer
,
871 data
.uni_str_len
*sizeof(uint16
) );
873 filename
= dos_basename( info3
->helpfile
);
874 init_unistr2( &data
, filename
, UNI_STR_TERMINATE
);
875 regval_ctr_addvalue( values
, "Help File", REG_SZ
, (char*)data
.buffer
,
876 data
.uni_str_len
*sizeof(uint16
) );
878 init_unistr2( &data
, info3
->defaultdatatype
, UNI_STR_TERMINATE
);
879 regval_ctr_addvalue( values
, "Data Type", REG_SZ
, (char*)data
.buffer
,
880 data
.uni_str_len
*sizeof(uint16
) );
882 regval_ctr_addvalue( values
, "Version", REG_DWORD
, (char*)&info3
->cversion
,
883 sizeof(info3
->cversion
) );
885 if ( info3
->dependentfiles
) {
886 /* place the list of dependent files in a single
887 character buffer, separating each file name by
890 for ( i
=0; strcmp(info3
->dependentfiles
[i
], ""); i
++ ) {
891 /* strip the path to only the file's base name */
893 filename
= dos_basename( info3
->dependentfiles
[i
] );
895 length
= strlen(filename
);
897 buffer2
= SMB_REALLOC( buffer
, buffer_size
+ (length
+ 1)*sizeof(uint16
) );
902 init_unistr2( &data
, filename
, UNI_STR_TERMINATE
);
903 memcpy( buffer
+buffer_size
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
905 buffer_size
+= (length
+ 1)*sizeof(uint16
);
908 /* terminated by double NULL. Add the final one here */
910 buffer2
= SMB_REALLOC( buffer
, buffer_size
+ 2 );
916 buffer
[buffer_size
++] = '\0';
917 buffer
[buffer_size
++] = '\0';
921 regval_ctr_addvalue( values
, "Dependent Files", REG_MULTI_SZ
, buffer
, buffer_size
);
928 /**********************************************************************
929 *********************************************************************/
931 static int driver_arch_fetch_values( char *key
, REGVAL_CTR
*values
)
933 char *keystr
, *base
, *subkeypath
;
934 fstring arch_environment
;
937 NT_PRINTER_DRIVER_INFO_LEVEL driver_ctr
;
940 reg_split_path( key
, &base
, &subkeypath
);
942 /* no values in 'Environments\Drivers\Windows NT x86' */
947 /* We have the Architecture string and some subkey name:
948 Currently we only support
951 Anything else is an error.
954 fstrcpy( arch_environment
, base
);
957 reg_split_path( keystr
, &base
, &subkeypath
);
959 if ( strequal(base
, "Print Processors") )
962 /* only Drivers key can be left */
964 if ( !strequal(base
, "Drivers") )
970 /* We know that we have Architechure\Drivers with some subkey name
971 The subkey name has to be Version-XX */
974 reg_split_path( keystr
, &base
, &subkeypath
);
979 version
= atoi(&base
[strlen(base
)-1]);
981 /* BEGIN PRINTER DRIVER NAME BLOCK */
984 reg_split_path( keystr
, &base
, &subkeypath
);
986 /* don't go any deeper for now */
988 fstrcpy( driver
, base
);
990 w_result
= get_a_printer_driver( &driver_ctr
, 3, driver
, arch_environment
, version
);
992 if ( !W_ERROR_IS_OK(w_result
) )
995 fill_in_driver_values( driver_ctr
.info_3
, values
);
997 free_a_printer_driver( driver_ctr
, 3 );
999 /* END PRINTER DRIVER NAME BLOCK */
1002 DEBUG(8,("key_driver_fetch_values: Exit\n"));
1004 return regval_ctr_numvals( values
);
1007 /**********************************************************************
1008 *********************************************************************/
1010 static int key_driver_fetch_values( const char *key
, REGVAL_CTR
*values
)
1015 DEBUG(8,("key_driver_fetch_values: Enter key => [%s]\n", key
? key
: "NULL"));
1017 /* no values in the Environments key */
1019 if ( !(keystr
= reg_remaining_path( key
+ strlen(KEY_ENVIRONMENTS
) )) )
1022 pstrcpy( subkey
, keystr
);
1024 /* pass off to handle subkeys */
1026 return driver_arch_fetch_values( subkey
, values
);
1029 /*********************************************************************
1030 *********************************************************************
1031 ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT"
1032 *********************************************************************
1033 *********************************************************************/
1035 static int key_print_fetch_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
1037 int key_len
= strlen(key
);
1039 /* no keys below 'Print' handled here */
1041 if ( (key_len
!= strlen(KEY_CONTROL_PRINT
)) && (key_len
!= strlen(KEY_WINNT_PRINT
)) )
1044 regsubkey_ctr_addkey( subkeys
, "Environments" );
1045 regsubkey_ctr_addkey( subkeys
, "Monitors" );
1046 regsubkey_ctr_addkey( subkeys
, "Forms" );
1047 regsubkey_ctr_addkey( subkeys
, "Printers" );
1049 return regsubkey_ctr_numkeys( subkeys
);
1052 /**********************************************************************
1053 *********************************************************************
1054 ** Structure to hold dispatch table of ops for various printer keys.
1055 ** Make sure to always store deeper keys along the same path first so
1056 ** we ge a more specific match.
1057 *********************************************************************
1058 *********************************************************************/
1060 static struct reg_dyn_tree print_registry
[] = {
1061 /* just pass the monitor onto the registry tdb */
1065 ®db_fetch_values
,
1066 ®db_store_values
},
1068 &key_forms_fetch_keys
,
1070 &key_forms_fetch_values
,
1072 { KEY_CONTROL_PRINTERS
,
1073 &key_printers_fetch_keys
,
1074 &key_printers_store_keys
,
1075 &key_printers_fetch_values
,
1076 &key_printers_store_values
},
1078 &key_driver_fetch_keys
,
1080 &key_driver_fetch_values
,
1082 { KEY_CONTROL_PRINT
,
1083 &key_print_fetch_keys
,
1087 { KEY_WINNT_PRINTERS
,
1088 &key_printers_fetch_keys
,
1089 &key_printers_store_keys
,
1090 &key_printers_fetch_values
,
1091 &key_printers_store_values
},
1095 ®db_fetch_values
,
1096 ®db_store_values
},
1098 { NULL
, NULL
, NULL
, NULL
, NULL
}
1102 /**********************************************************************
1103 *********************************************************************
1104 ** Main reg_printing interface functions
1105 *********************************************************************
1106 *********************************************************************/
1108 /***********************************************************************
1109 Lookup a key in the print_registry table, returning its index.
1111 **********************************************************************/
1113 static int match_registry_path( const char *key
)
1121 pstrcpy( path
, key
);
1122 normalize_reg_path( path
);
1124 for ( i
=0; print_registry
[i
].path
; i
++ ) {
1125 if ( strncmp( path
, print_registry
[i
].path
, strlen(print_registry
[i
].path
) ) == 0 )
1132 /***********************************************************************
1133 **********************************************************************/
1135 static int regprint_fetch_reg_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
1137 int i
= match_registry_path( key
);
1142 if ( !print_registry
[i
].fetch_subkeys
)
1145 return print_registry
[i
].fetch_subkeys( key
, subkeys
);
1148 /**********************************************************************
1149 *********************************************************************/
1151 static BOOL
regprint_store_reg_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
1153 int i
= match_registry_path( key
);
1158 if ( !print_registry
[i
].store_subkeys
)
1161 return print_registry
[i
].store_subkeys( key
, subkeys
);
1164 /**********************************************************************
1165 *********************************************************************/
1167 static int regprint_fetch_reg_values( const char *key
, REGVAL_CTR
*values
)
1169 int i
= match_registry_path( key
);
1174 /* return 0 values by default since we know the key had
1175 to exist because the client opened a handle */
1177 if ( !print_registry
[i
].fetch_values
)
1180 return print_registry
[i
].fetch_values( key
, values
);
1183 /**********************************************************************
1184 *********************************************************************/
1186 static BOOL
regprint_store_reg_values( const char *key
, REGVAL_CTR
*values
)
1188 int i
= match_registry_path( key
);
1193 if ( !print_registry
[i
].store_values
)
1196 return print_registry
[i
].store_values( key
, values
);
1200 * Table of function pointers for accessing printing data
1203 REGISTRY_OPS printing_ops
= {
1204 regprint_fetch_reg_keys
,
1205 regprint_fetch_reg_values
,
1206 regprint_store_reg_keys
,
1207 regprint_store_reg_values
,