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 if (!reg_split_path( printers_key
, &printername
, &printerdatakey
)) {
232 /* validate the printer name */
234 for (snum
=0; snum
<n_services
; snum
++) {
235 if ( !lp_snum_ok(snum
) || !lp_print_ok(snum
) )
237 if (strequal( lp_servicename(snum
), printername
) )
241 if ( snum
>=n_services
242 || !W_ERROR_IS_OK( get_a_printer(NULL
, &printer
, 2, printername
) ) )
247 num_subkeys
= get_printer_subkeys( printer
->info_2
->data
, printerdatakey
?printerdatakey
:"", &subkey_names
);
249 for ( i
=0; i
<num_subkeys
; i
++ )
250 regsubkey_ctr_addkey( subkeys
, subkey_names
[i
] );
252 free_a_printer( &printer
, 2 );
254 /* no other subkeys below here */
257 SAFE_FREE( subkey_names
);
262 /**********************************************************************
263 Take a list of names and call add_printer_hook() if necessary
264 Note that we do this a little differently from Windows since the
265 keyname is the sharename and not the printer name.
266 *********************************************************************/
268 static BOOL
add_printers_by_registry( REGSUBKEY_CTR
*subkeys
)
270 int i
, num_keys
, snum
;
272 NT_PRINTER_INFO_LEVEL_2 info2
;
273 NT_PRINTER_INFO_LEVEL printer
;
275 ZERO_STRUCT( info2
);
276 printer
.info_2
= &info2
;
278 num_keys
= regsubkey_ctr_numkeys( subkeys
);
281 for ( i
=0; i
<num_keys
; i
++ ) {
282 printername
= regsubkey_ctr_specific_key( subkeys
, i
);
283 snum
= find_service( printername
);
285 /* just verify a valied snum for now */
287 fstrcpy( info2
.printername
, printername
);
288 fstrcpy( info2
.sharename
, printername
);
289 if ( !add_printer_hook( NULL
, &printer
) ) {
290 DEBUG(0,("add_printers_by_registry: Failed to add printer [%s]\n",
300 /**********************************************************************
301 *********************************************************************/
303 static BOOL
key_printers_store_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
306 char *printername
, *printerdatakey
;
307 NT_PRINTER_INFO_LEVEL
*printer
= NULL
;
308 int i
, num_subkeys
, num_existing_keys
;
310 fstring
*existing_subkeys
= NULL
;
312 printers_key
= strip_printers_prefix( key
);
314 if ( !printers_key
) {
315 /* have to deal with some new or deleted printer */
316 return add_printers_by_registry( subkeys
);
319 if (!reg_split_path( printers_key
, &printername
, &printerdatakey
)) {
323 /* lookup the printer */
325 if ( !W_ERROR_IS_OK(get_a_printer(NULL
, &printer
, 2, printername
)) ) {
326 DEBUG(0,("key_printers_store_keys: Tried to store subkey for bad printername %s\n",
331 /* get the top level printer keys */
333 num_existing_keys
= get_printer_subkeys( printer
->info_2
->data
, "", &existing_subkeys
);
335 for ( i
=0; i
<num_existing_keys
; i
++ ) {
337 /* remove the key if it has been deleted */
339 if ( !regsubkey_ctr_key_exists( subkeys
, existing_subkeys
[i
] ) ) {
340 DEBUG(5,("key_printers_store_keys: deleting key %s\n",
341 existing_subkeys
[i
]));
342 delete_printer_key( printer
->info_2
->data
, existing_subkeys
[i
] );
346 num_subkeys
= regsubkey_ctr_numkeys( subkeys
);
347 for ( i
=0; i
<num_subkeys
; i
++ ) {
348 subkeyname
= regsubkey_ctr_specific_key(subkeys
, i
);
349 /* add any missing printer keys */
350 if ( lookup_printerkey(printer
->info_2
->data
, subkeyname
) == -1 ) {
351 DEBUG(5,("key_printers_store_keys: adding key %s\n",
352 existing_subkeys
[i
]));
353 if ( add_new_printer_key( printer
->info_2
->data
, subkeyname
) == -1 ) {
354 SAFE_FREE( existing_subkeys
);
360 /* write back to disk */
362 mod_a_printer( printer
, 2 );
367 free_a_printer( &printer
, 2 );
369 SAFE_FREE( existing_subkeys
);
374 /**********************************************************************
375 *********************************************************************/
377 static void fill_in_printer_values( NT_PRINTER_INFO_LEVEL_2
*info2
, REGVAL_CTR
*values
)
384 uint32 printer_status
= PRINTER_STATUS_OK
;
386 regval_ctr_addvalue( values
, "Attributes", REG_DWORD
, (char*)&info2
->attributes
, sizeof(info2
->attributes
) );
387 regval_ctr_addvalue( values
, "Priority", REG_DWORD
, (char*)&info2
->priority
, sizeof(info2
->attributes
) );
388 regval_ctr_addvalue( values
, "ChangeID", REG_DWORD
, (char*)&info2
->changeid
, sizeof(info2
->changeid
) );
389 regval_ctr_addvalue( values
, "Default Priority", REG_DWORD
, (char*)&info2
->default_priority
, sizeof(info2
->default_priority
) );
391 /* lie and say everything is ok since we don't want to call print_queue_length() to get the real status */
392 regval_ctr_addvalue( values
, "Status", REG_DWORD
, (char*)&printer_status
, sizeof(info2
->status
) );
394 regval_ctr_addvalue( values
, "StartTime", REG_DWORD
, (char*)&info2
->starttime
, sizeof(info2
->starttime
) );
395 regval_ctr_addvalue( values
, "UntilTime", REG_DWORD
, (char*)&info2
->untiltime
, sizeof(info2
->untiltime
) );
397 /* strip the \\server\ from this string */
398 if ( !(p
= strrchr( info2
->printername
, '\\' ) ) )
399 p
= info2
->printername
;
402 init_unistr2( &data
, p
, UNI_STR_TERMINATE
);
403 regval_ctr_addvalue( values
, "Name", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
405 init_unistr2( &data
, info2
->location
, UNI_STR_TERMINATE
);
406 regval_ctr_addvalue( values
, "Location", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
408 init_unistr2( &data
, info2
->comment
, UNI_STR_TERMINATE
);
409 regval_ctr_addvalue( values
, "Description", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
411 init_unistr2( &data
, info2
->parameters
, UNI_STR_TERMINATE
);
412 regval_ctr_addvalue( values
, "Parameters", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
414 init_unistr2( &data
, info2
->portname
, UNI_STR_TERMINATE
);
415 regval_ctr_addvalue( values
, "Port", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
417 init_unistr2( &data
, info2
->sharename
, UNI_STR_TERMINATE
);
418 regval_ctr_addvalue( values
, "Share Name", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
420 init_unistr2( &data
, info2
->drivername
, UNI_STR_TERMINATE
);
421 regval_ctr_addvalue( values
, "Printer Driver", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
423 init_unistr2( &data
, info2
->sepfile
, UNI_STR_TERMINATE
);
424 regval_ctr_addvalue( values
, "Separator File", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
426 init_unistr2( &data
, "WinPrint", UNI_STR_TERMINATE
);
427 regval_ctr_addvalue( values
, "Print Processor", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
429 init_unistr2( &data
, "RAW", UNI_STR_TERMINATE
);
430 regval_ctr_addvalue( values
, "Datatype", REG_SZ
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
433 /* use a prs_struct for converting the devmode and security
434 descriptor to REG_BINARY */
436 prs_init( &prs
, RPC_MAX_PDU_FRAG_LEN
, values
, MARSHALL
);
438 /* stream the device mode */
440 if ( (devmode
= construct_dev_mode( info2
->sharename
)) != NULL
) {
441 if ( spoolss_io_devmode( "devmode", &prs
, 0, devmode
) ) {
442 offset
= prs_offset( &prs
);
443 regval_ctr_addvalue( values
, "Default Devmode", REG_BINARY
, prs_data_p(&prs
), offset
);
447 prs_mem_clear( &prs
);
448 prs_set_offset( &prs
, 0 );
450 /* stream the printer security descriptor */
452 if ( info2
->secdesc_buf
&& info2
->secdesc_buf
->sd
) {
453 if ( sec_io_desc("sec_desc", &info2
->secdesc_buf
->sd
, &prs
, 0 ) ) {
454 offset
= prs_offset( &prs
);
455 regval_ctr_addvalue( values
, "Security", REG_BINARY
, prs_data_p(&prs
), offset
);
459 prs_mem_free( &prs
);
464 /**********************************************************************
465 *********************************************************************/
467 static int key_printers_fetch_values( const char *key
, REGVAL_CTR
*values
)
471 char *printername
, *printerdatakey
;
472 NT_PRINTER_INFO_LEVEL
*printer
= NULL
;
473 NT_PRINTER_DATA
*p_data
;
476 printers_key
= strip_printers_prefix( key
);
478 /* top level key values stored in the registry has no values */
480 if ( !printers_key
) {
481 /* normalize to the 'HKLM\SOFTWARE\...\Print\Printers' ket */
482 return regdb_fetch_values( KEY_WINNT_PRINTERS
, values
);
485 /* lookup the printer object */
487 if (!reg_split_path( printers_key
, &printername
, &printerdatakey
)) {
491 if ( !W_ERROR_IS_OK( get_a_printer(NULL
, &printer
, 2, printername
) ) )
494 if ( !printerdatakey
) {
495 fill_in_printer_values( printer
->info_2
, values
);
499 /* iterate over all printer data keys and fill the regval container */
501 p_data
= printer
->info_2
->data
;
502 if ( (key_index
= lookup_printerkey( p_data
, printerdatakey
)) == -1 ) {
503 /* failure....should never happen if the client has a valid open handle first */
504 DEBUG(10,("key_printers_fetch_values: Unknown keyname [%s]\n", printerdatakey
));
506 free_a_printer( &printer
, 2 );
510 num_values
= regval_ctr_numvals( p_data
->keys
[key_index
].values
);
511 for ( i
=0; i
<num_values
; i
++ )
512 regval_ctr_copyvalue( values
, regval_ctr_specific_value(p_data
->keys
[key_index
].values
, i
) );
517 free_a_printer( &printer
, 2 );
519 return regval_ctr_numvals( values
);
522 /**********************************************************************
523 *********************************************************************/
525 #define REG_IDX_ATTRIBUTES 1
526 #define REG_IDX_PRIORITY 2
527 #define REG_IDX_DEFAULT_PRIORITY 3
528 #define REG_IDX_CHANGEID 4
529 #define REG_IDX_STATUS 5
530 #define REG_IDX_STARTTIME 6
531 #define REG_IDX_NAME 7
532 #define REG_IDX_LOCATION 8
533 #define REG_IDX_DESCRIPTION 9
534 #define REG_IDX_PARAMETERS 10
535 #define REG_IDX_PORT 12
536 #define REG_IDX_SHARENAME 13
537 #define REG_IDX_DRIVER 14
538 #define REG_IDX_SEP_FILE 15
539 #define REG_IDX_PRINTPROC 16
540 #define REG_IDX_DATATYPE 17
541 #define REG_IDX_DEVMODE 18
542 #define REG_IDX_SECDESC 19
543 #define REG_IDX_UNTILTIME 20
548 } printer_values_map
[] = {
549 { "Attributes", REG_IDX_ATTRIBUTES
},
550 { "Priority", REG_IDX_PRIORITY
},
551 { "Default Priority", REG_IDX_DEFAULT_PRIORITY
},
552 { "ChangeID", REG_IDX_CHANGEID
},
553 { "Status", REG_IDX_STATUS
},
554 { "StartTime", REG_IDX_STARTTIME
},
555 { "UntilTime", REG_IDX_UNTILTIME
},
556 { "Name", REG_IDX_NAME
},
557 { "Location", REG_IDX_LOCATION
},
558 { "Descrioption", REG_IDX_DESCRIPTION
},
559 { "Parameters", REG_IDX_PARAMETERS
},
560 { "Port", REG_IDX_PORT
},
561 { "Share Name", REG_IDX_SHARENAME
},
562 { "Printer Driver", REG_IDX_DRIVER
},
563 { "Separator File", REG_IDX_SEP_FILE
},
564 { "Print Processor", REG_IDX_PRINTPROC
},
565 { "Datatype", REG_IDX_DATATYPE
},
566 { "Default Devmode", REG_IDX_DEVMODE
},
567 { "Security", REG_IDX_SECDESC
},
572 static int find_valuename_index( const char *valuename
)
576 for ( i
=0; printer_values_map
[i
].name
; i
++ ) {
577 if ( strequal( valuename
, printer_values_map
[i
].name
) )
578 return printer_values_map
[i
].index
;
584 /**********************************************************************
585 *********************************************************************/
587 static void convert_values_to_printer_info_2( NT_PRINTER_INFO_LEVEL_2
*printer2
, REGVAL_CTR
*values
)
589 int num_values
= regval_ctr_numvals( values
);
594 for ( i
=0; i
<num_values
; i
++ ) {
595 val
= regval_ctr_specific_value( values
, i
);
596 value_index
= find_valuename_index( regval_name( val
) );
598 switch( value_index
) {
599 case REG_IDX_ATTRIBUTES
:
600 printer2
->attributes
= (uint32
)(*regval_data_p(val
));
602 case REG_IDX_PRIORITY
:
603 printer2
->priority
= (uint32
)(*regval_data_p(val
));
605 case REG_IDX_DEFAULT_PRIORITY
:
606 printer2
->default_priority
= (uint32
)(*regval_data_p(val
));
608 case REG_IDX_CHANGEID
:
609 printer2
->changeid
= (uint32
)(*regval_data_p(val
));
611 case REG_IDX_STARTTIME
:
612 printer2
->starttime
= (uint32
)(*regval_data_p(val
));
614 case REG_IDX_UNTILTIME
:
615 printer2
->untiltime
= (uint32
)(*regval_data_p(val
));
618 rpcstr_pull( printer2
->printername
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
620 case REG_IDX_LOCATION
:
621 rpcstr_pull( printer2
->location
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
623 case REG_IDX_DESCRIPTION
:
624 rpcstr_pull( printer2
->comment
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
626 case REG_IDX_PARAMETERS
:
627 rpcstr_pull( printer2
->parameters
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
630 rpcstr_pull( printer2
->portname
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
632 case REG_IDX_SHARENAME
:
633 rpcstr_pull( printer2
->sharename
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
636 rpcstr_pull( printer2
->drivername
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
638 case REG_IDX_SEP_FILE
:
639 rpcstr_pull( printer2
->sepfile
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
641 case REG_IDX_PRINTPROC
:
642 rpcstr_pull( printer2
->printprocessor
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
644 case REG_IDX_DATATYPE
:
645 rpcstr_pull( printer2
->datatype
, regval_data_p(val
), sizeof(fstring
), regval_size(val
), 0 );
647 case REG_IDX_DEVMODE
:
649 case REG_IDX_SECDESC
:
652 /* unsupported value...throw away */
653 DEBUG(8,("convert_values_to_printer_info_2: Unsupported registry value [%s]\n",
654 regval_name( val
) ));
661 /**********************************************************************
662 *********************************************************************/
664 static BOOL
key_printers_store_values( const char *key
, REGVAL_CTR
*values
)
667 char *printername
, *keyname
;
668 NT_PRINTER_INFO_LEVEL
*printer
= NULL
;
671 printers_key
= strip_printers_prefix( key
);
673 /* values in the top level key get stored in the registry */
675 if ( !printers_key
) {
676 /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
677 return regdb_store_values( KEY_WINNT_PRINTERS
, values
);
680 if (!reg_split_path( printers_key
, &printername
, &keyname
)) {
684 if ( !W_ERROR_IS_OK(get_a_printer(NULL
, &printer
, 2, printername
) ) )
687 /* deal with setting values directly under the printername */
690 convert_values_to_printer_info_2( printer
->info_2
, values
);
693 int num_values
= regval_ctr_numvals( values
);
697 delete_printer_key( printer
->info_2
->data
, keyname
);
699 /* deal with any subkeys */
700 for ( i
=0; i
<num_values
; i
++ ) {
701 val
= regval_ctr_specific_value( values
, i
);
702 result
= set_printer_dataex( printer
, keyname
,
705 regval_data_p( val
),
706 regval_size( val
) );
707 if ( !W_ERROR_IS_OK(result
) ) {
708 DEBUG(0,("key_printers_store_values: failed to set printer data [%s]!\n",
710 free_a_printer( &printer
, 2 );
716 result
= mod_a_printer( printer
, 2 );
718 free_a_printer( &printer
, 2 );
720 return W_ERROR_IS_OK(result
);
723 /*********************************************************************
724 *********************************************************************
725 ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/ENVIRONMENTS"
726 *********************************************************************
727 *********************************************************************/
729 static int key_driver_fetch_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
731 const char *environments
[] = {
735 "Windows NT Alpha_AXP",
736 "Windows NT PowerPC",
740 fstring
*drivers
= NULL
;
741 int i
, env_index
, num_drivers
;
742 char *keystr
, *base
, *subkeypath
;
744 int num_subkeys
= -1;
747 DEBUG(10,("key_driver_fetch_keys key=>[%s]\n", key
? key
: "NULL" ));
749 keystr
= reg_remaining_path( key
+ strlen(KEY_ENVIRONMENTS
) );
751 /* list all possible architectures */
754 for ( num_subkeys
=0; environments
[num_subkeys
]; num_subkeys
++ )
755 regsubkey_ctr_addkey( subkeys
, environments
[num_subkeys
] );
760 /* we are dealing with a subkey of "Environments */
762 pstrcpy( key2
, keystr
);
764 if (!reg_split_path( keystr
, &base
, &subkeypath
)) {
770 for ( env_index
=0; environments
[env_index
]; env_index
++ ) {
771 if ( strequal( environments
[env_index
], base
) )
774 if ( !environments
[env_index
] )
777 /* ...\Print\Environements\...\ */
780 regsubkey_ctr_addkey( subkeys
, "Drivers" );
781 regsubkey_ctr_addkey( subkeys
, "Print Processors" );
786 /* more of the key path to process */
789 if (!reg_split_path( keystr
, &base
, &subkeypath
)) {
793 /* ...\Print\Environements\...\Drivers\ */
796 if ( strequal(base
, "Drivers") ) {
797 switch ( env_index
) {
799 regsubkey_ctr_addkey( subkeys
, "Version-0" );
801 default: /* Windows NT based systems */
802 regsubkey_ctr_addkey( subkeys
, "Version-2" );
803 regsubkey_ctr_addkey( subkeys
, "Version-3" );
807 return regsubkey_ctr_numkeys( subkeys
);
808 } else if ( strequal(base
, "Print Processors") ) {
809 if ( env_index
== 1 || env_index
== 5 || env_index
== 6 )
810 regsubkey_ctr_addkey( subkeys
, "winprint" );
812 return regsubkey_ctr_numkeys( subkeys
);
814 return -1; /* bad path */
817 /* we finally get to enumerate the drivers */
819 /* only one possible subkey below PrintProc key */
821 if ( strequal(base
, "Print Processors") ) {
823 if (!reg_split_path( keystr
, &base
, &subkeypath
)) {
827 /* no subkeys below this point */
832 /* only allow one keyname here -- 'winprint' */
834 return strequal( base
, "winprint" ) ? 0 : -1;
837 /* only dealing with drivers from here on out */
840 if (!reg_split_path( keystr
, &base
, &subkeypath
)) {
844 version
= atoi(&base
[strlen(base
)-1]);
852 if ( version
!= 2 && version
!= 3 )
859 num_drivers
= get_ntdrivers( &drivers
, environments
[env_index
], version
);
860 for ( i
=0; i
<num_drivers
; i
++ )
861 regsubkey_ctr_addkey( subkeys
, drivers
[i
] );
863 return regsubkey_ctr_numkeys( subkeys
);
866 /* if anything else left, just say if has no subkeys */
868 DEBUG(1,("key_driver_fetch_keys unhandled key [%s] (subkey == %s\n",
875 /**********************************************************************
876 *********************************************************************/
878 static void fill_in_driver_values( NT_PRINTER_DRIVER_INFO_LEVEL_3
*info3
, REGVAL_CTR
*values
)
886 filename
= dos_basename( info3
->driverpath
);
887 init_unistr2( &data
, filename
, UNI_STR_TERMINATE
);
888 regval_ctr_addvalue( values
, "Driver", REG_SZ
, (char*)data
.buffer
,
889 data
.uni_str_len
*sizeof(uint16
) );
891 filename
= dos_basename( info3
->configfile
);
892 init_unistr2( &data
, filename
, UNI_STR_TERMINATE
);
893 regval_ctr_addvalue( values
, "Configuration File", REG_SZ
, (char*)data
.buffer
,
894 data
.uni_str_len
*sizeof(uint16
) );
896 filename
= dos_basename( info3
->datafile
);
897 init_unistr2( &data
, filename
, UNI_STR_TERMINATE
);
898 regval_ctr_addvalue( values
, "Data File", REG_SZ
, (char*)data
.buffer
,
899 data
.uni_str_len
*sizeof(uint16
) );
901 filename
= dos_basename( info3
->helpfile
);
902 init_unistr2( &data
, filename
, UNI_STR_TERMINATE
);
903 regval_ctr_addvalue( values
, "Help File", REG_SZ
, (char*)data
.buffer
,
904 data
.uni_str_len
*sizeof(uint16
) );
906 init_unistr2( &data
, info3
->defaultdatatype
, UNI_STR_TERMINATE
);
907 regval_ctr_addvalue( values
, "Data Type", REG_SZ
, (char*)data
.buffer
,
908 data
.uni_str_len
*sizeof(uint16
) );
910 regval_ctr_addvalue( values
, "Version", REG_DWORD
, (char*)&info3
->cversion
,
911 sizeof(info3
->cversion
) );
913 if ( info3
->dependentfiles
) {
914 /* place the list of dependent files in a single
915 character buffer, separating each file name by
918 for ( i
=0; strcmp(info3
->dependentfiles
[i
], ""); i
++ ) {
919 /* strip the path to only the file's base name */
921 filename
= dos_basename( info3
->dependentfiles
[i
] );
923 length
= strlen(filename
);
925 buffer
= (char *)SMB_REALLOC( buffer
, buffer_size
+ (length
+ 1)*sizeof(uint16
) );
930 init_unistr2( &data
, filename
, UNI_STR_TERMINATE
);
931 memcpy( buffer
+buffer_size
, (char*)data
.buffer
, data
.uni_str_len
*sizeof(uint16
) );
933 buffer_size
+= (length
+ 1)*sizeof(uint16
);
936 /* terminated by double NULL. Add the final one here */
938 buffer
= (char *)SMB_REALLOC( buffer
, buffer_size
+ 2 );
942 buffer
[buffer_size
++] = '\0';
943 buffer
[buffer_size
++] = '\0';
947 regval_ctr_addvalue( values
, "Dependent Files", REG_MULTI_SZ
, buffer
, buffer_size
);
954 /**********************************************************************
955 *********************************************************************/
957 static int driver_arch_fetch_values( char *key
, REGVAL_CTR
*values
)
959 char *keystr
, *base
, *subkeypath
;
960 fstring arch_environment
;
963 NT_PRINTER_DRIVER_INFO_LEVEL driver_ctr
;
966 if (!reg_split_path( key
, &base
, &subkeypath
)) {
970 /* no values in 'Environments\Drivers\Windows NT x86' */
975 /* We have the Architecture string and some subkey name:
976 Currently we only support
979 Anything else is an error.
982 fstrcpy( arch_environment
, base
);
985 if (!reg_split_path( keystr
, &base
, &subkeypath
)) {
989 if ( strequal(base
, "Print Processors") )
992 /* only Drivers key can be left */
994 if ( !strequal(base
, "Drivers") )
1000 /* We know that we have Architechure\Drivers with some subkey name
1001 The subkey name has to be Version-XX */
1003 keystr
= subkeypath
;
1004 if (!reg_split_path( keystr
, &base
, &subkeypath
)) {
1011 version
= atoi(&base
[strlen(base
)-1]);
1013 /* BEGIN PRINTER DRIVER NAME BLOCK */
1015 keystr
= subkeypath
;
1016 if (!reg_split_path( keystr
, &base
, &subkeypath
)) {
1020 /* don't go any deeper for now */
1022 fstrcpy( driver
, base
);
1024 w_result
= get_a_printer_driver( &driver_ctr
, 3, driver
, arch_environment
, version
);
1026 if ( !W_ERROR_IS_OK(w_result
) )
1029 fill_in_driver_values( driver_ctr
.info_3
, values
);
1031 free_a_printer_driver( driver_ctr
, 3 );
1033 /* END PRINTER DRIVER NAME BLOCK */
1036 DEBUG(8,("key_driver_fetch_values: Exit\n"));
1038 return regval_ctr_numvals( values
);
1041 /**********************************************************************
1042 *********************************************************************/
1044 static int key_driver_fetch_values( const char *key
, REGVAL_CTR
*values
)
1049 DEBUG(8,("key_driver_fetch_values: Enter key => [%s]\n", key
? key
: "NULL"));
1051 /* no values in the Environments key */
1053 if ( !(keystr
= reg_remaining_path( key
+ strlen(KEY_ENVIRONMENTS
) )) )
1056 pstrcpy( subkey
, keystr
);
1058 /* pass off to handle subkeys */
1060 return driver_arch_fetch_values( subkey
, values
);
1063 /*********************************************************************
1064 *********************************************************************
1065 ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT"
1066 *********************************************************************
1067 *********************************************************************/
1069 static int key_print_fetch_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
1071 int key_len
= strlen(key
);
1073 /* no keys below 'Print' handled here */
1075 if ( (key_len
!= strlen(KEY_CONTROL_PRINT
)) && (key_len
!= strlen(KEY_WINNT_PRINT
)) )
1078 regsubkey_ctr_addkey( subkeys
, "Environments" );
1079 regsubkey_ctr_addkey( subkeys
, "Monitors" );
1080 regsubkey_ctr_addkey( subkeys
, "Forms" );
1081 regsubkey_ctr_addkey( subkeys
, "Printers" );
1083 return regsubkey_ctr_numkeys( subkeys
);
1086 /**********************************************************************
1087 *********************************************************************
1088 ** Structure to hold dispatch table of ops for various printer keys.
1089 ** Make sure to always store deeper keys along the same path first so
1090 ** we ge a more specific match.
1091 *********************************************************************
1092 *********************************************************************/
1094 static struct reg_dyn_tree print_registry
[] = {
1095 /* just pass the monitor onto the registry tdb */
1099 ®db_fetch_values
,
1100 ®db_store_values
},
1102 &key_forms_fetch_keys
,
1104 &key_forms_fetch_values
,
1106 { KEY_CONTROL_PRINTERS
,
1107 &key_printers_fetch_keys
,
1108 &key_printers_store_keys
,
1109 &key_printers_fetch_values
,
1110 &key_printers_store_values
},
1112 &key_driver_fetch_keys
,
1114 &key_driver_fetch_values
,
1116 { KEY_CONTROL_PRINT
,
1117 &key_print_fetch_keys
,
1121 { KEY_WINNT_PRINTERS
,
1122 &key_printers_fetch_keys
,
1123 &key_printers_store_keys
,
1124 &key_printers_fetch_values
,
1125 &key_printers_store_values
},
1129 ®db_fetch_values
,
1130 ®db_store_values
},
1132 { NULL
, NULL
, NULL
, NULL
, NULL
}
1136 /**********************************************************************
1137 *********************************************************************
1138 ** Main reg_printing interface functions
1139 *********************************************************************
1140 *********************************************************************/
1142 /***********************************************************************
1143 Lookup a key in the print_registry table, returning its index.
1145 **********************************************************************/
1147 static int match_registry_path( const char *key
)
1155 pstrcpy( path
, key
);
1156 normalize_reg_path( path
);
1158 for ( i
=0; print_registry
[i
].path
; i
++ ) {
1159 if ( strncmp( path
, print_registry
[i
].path
, strlen(print_registry
[i
].path
) ) == 0 )
1166 /***********************************************************************
1167 **********************************************************************/
1169 static int regprint_fetch_reg_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
1171 int i
= match_registry_path( key
);
1176 if ( !print_registry
[i
].fetch_subkeys
)
1179 return print_registry
[i
].fetch_subkeys( key
, subkeys
);
1182 /**********************************************************************
1183 *********************************************************************/
1185 static BOOL
regprint_store_reg_keys( const char *key
, REGSUBKEY_CTR
*subkeys
)
1187 int i
= match_registry_path( key
);
1192 if ( !print_registry
[i
].store_subkeys
)
1195 return print_registry
[i
].store_subkeys( key
, subkeys
);
1198 /**********************************************************************
1199 *********************************************************************/
1201 static int regprint_fetch_reg_values( const char *key
, REGVAL_CTR
*values
)
1203 int i
= match_registry_path( key
);
1208 /* return 0 values by default since we know the key had
1209 to exist because the client opened a handle */
1211 if ( !print_registry
[i
].fetch_values
)
1214 return print_registry
[i
].fetch_values( key
, values
);
1217 /**********************************************************************
1218 *********************************************************************/
1220 static BOOL
regprint_store_reg_values( const char *key
, REGVAL_CTR
*values
)
1222 int i
= match_registry_path( key
);
1227 if ( !print_registry
[i
].store_values
)
1230 return print_registry
[i
].store_values( key
, values
);
1234 * Table of function pointers for accessing printing data
1237 REGISTRY_OPS printing_ops
= {
1238 regprint_fetch_reg_keys
,
1239 regprint_fetch_reg_values
,
1240 regprint_store_reg_keys
,
1241 regprint_store_reg_values
,