| 1 | /*
|
|---|
| 2 | * Unix SMB/CIFS implementation.
|
|---|
| 3 | * Virtual Windows Registry Layer
|
|---|
| 4 | * Copyright (C) Gerald Carter 2002-2005
|
|---|
| 5 | *
|
|---|
| 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.
|
|---|
| 10 | *
|
|---|
| 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.
|
|---|
| 15 | *
|
|---|
| 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.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | /* Implementation of registry virtual views for printing information */
|
|---|
| 22 |
|
|---|
| 23 | #include "includes.h"
|
|---|
| 24 |
|
|---|
| 25 | #undef DBGC_CLASS
|
|---|
| 26 | #define DBGC_CLASS DBGC_RPC_SRV
|
|---|
| 27 |
|
|---|
| 28 | /* registrt paths used in the print_registry[] */
|
|---|
| 29 |
|
|---|
| 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"
|
|---|
| 38 |
|
|---|
| 39 | /* callback table for various registry paths below the ones we service in this module */
|
|---|
| 40 |
|
|---|
| 41 | struct reg_dyn_tree {
|
|---|
| 42 | /* full key path in normalized form */
|
|---|
| 43 | const char *path;
|
|---|
| 44 |
|
|---|
| 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 );
|
|---|
| 50 | };
|
|---|
| 51 |
|
|---|
| 52 | /*********************************************************************
|
|---|
| 53 | *********************************************************************
|
|---|
| 54 | ** Utility Functions
|
|---|
| 55 | *********************************************************************
|
|---|
| 56 | *********************************************************************/
|
|---|
| 57 |
|
|---|
| 58 | /***********************************************************************
|
|---|
| 59 | simple function to prune a pathname down to the basename of a file
|
|---|
| 60 | **********************************************************************/
|
|---|
| 61 |
|
|---|
| 62 | static char* dos_basename ( char *path )
|
|---|
| 63 | {
|
|---|
| 64 | char *p;
|
|---|
| 65 |
|
|---|
| 66 | if ( !(p = strrchr( path, '\\' )) )
|
|---|
| 67 | p = path;
|
|---|
| 68 | else
|
|---|
| 69 | p++;
|
|---|
| 70 |
|
|---|
| 71 | return p;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | /*********************************************************************
|
|---|
| 75 | *********************************************************************
|
|---|
| 76 | ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/FORMS"
|
|---|
| 77 | *********************************************************************
|
|---|
| 78 | *********************************************************************/
|
|---|
| 79 |
|
|---|
| 80 | static int key_forms_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
|
|---|
| 81 | {
|
|---|
| 82 | char *p = reg_remaining_path( key + strlen(KEY_FORMS) );
|
|---|
| 83 |
|
|---|
| 84 | /* no keys below Forms */
|
|---|
| 85 |
|
|---|
| 86 | if ( p )
|
|---|
| 87 | return -1;
|
|---|
| 88 |
|
|---|
| 89 | return 0;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | /**********************************************************************
|
|---|
| 93 | *********************************************************************/
|
|---|
| 94 |
|
|---|
| 95 | static int key_forms_fetch_values( const char *key, REGVAL_CTR *values )
|
|---|
| 96 | {
|
|---|
| 97 | uint32 data[8];
|
|---|
| 98 | int i, num_values, form_index = 1;
|
|---|
| 99 | nt_forms_struct *forms_list = NULL;
|
|---|
| 100 | nt_forms_struct *form;
|
|---|
| 101 |
|
|---|
| 102 | DEBUG(10,("print_values_forms: key=>[%s]\n", key ? key : "NULL" ));
|
|---|
| 103 |
|
|---|
| 104 | num_values = get_ntforms( &forms_list );
|
|---|
| 105 |
|
|---|
| 106 | DEBUG(10,("hive_forms_fetch_values: [%d] user defined forms returned\n",
|
|---|
| 107 | num_values));
|
|---|
| 108 |
|
|---|
| 109 | /* handle user defined forms */
|
|---|
| 110 |
|
|---|
| 111 | for ( i=0; i<num_values; i++ ) {
|
|---|
| 112 | form = &forms_list[i];
|
|---|
| 113 |
|
|---|
| 114 | data[0] = form->width;
|
|---|
| 115 | data[1] = form->length;
|
|---|
| 116 | data[2] = form->left;
|
|---|
| 117 | data[3] = form->top;
|
|---|
| 118 | data[4] = form->right;
|
|---|
| 119 | data[5] = form->bottom;
|
|---|
| 120 | data[6] = form_index++;
|
|---|
| 121 | data[7] = form->flag;
|
|---|
| 122 |
|
|---|
| 123 | regval_ctr_addvalue( values, form->name, REG_BINARY, (char*)data, sizeof(data) );
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | SAFE_FREE( forms_list );
|
|---|
| 127 | forms_list = NULL;
|
|---|
| 128 |
|
|---|
| 129 | /* handle built-on forms */
|
|---|
| 130 |
|
|---|
| 131 | num_values = get_builtin_ntforms( &forms_list );
|
|---|
| 132 |
|
|---|
| 133 | DEBUG(10,("print_subpath_values_forms: [%d] built-in forms returned\n",
|
|---|
| 134 | num_values));
|
|---|
| 135 |
|
|---|
| 136 | for ( i=0; i<num_values; i++ ) {
|
|---|
| 137 | form = &forms_list[i];
|
|---|
| 138 |
|
|---|
| 139 | data[0] = form->width;
|
|---|
| 140 | data[1] = form->length;
|
|---|
| 141 | data[2] = form->left;
|
|---|
| 142 | data[3] = form->top;
|
|---|
| 143 | data[4] = form->right;
|
|---|
| 144 | data[5] = form->bottom;
|
|---|
| 145 | data[6] = form_index++;
|
|---|
| 146 | data[7] = form->flag;
|
|---|
| 147 |
|
|---|
| 148 | regval_ctr_addvalue( values, form->name, REG_BINARY, (char*)data, sizeof(data) );
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | SAFE_FREE( forms_list );
|
|---|
| 152 |
|
|---|
| 153 | return regval_ctr_numvals( values );
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | /*********************************************************************
|
|---|
| 157 | *********************************************************************
|
|---|
| 158 | ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/PRINTERS"
|
|---|
| 159 | ** "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PRINT/PRINTERS"
|
|---|
| 160 | *********************************************************************
|
|---|
| 161 | *********************************************************************/
|
|---|
| 162 |
|
|---|
| 163 | /*********************************************************************
|
|---|
| 164 | strip off prefix for printers key. DOes return a pointer to static
|
|---|
| 165 | memory.
|
|---|
| 166 | *********************************************************************/
|
|---|
| 167 |
|
|---|
| 168 | static char* strip_printers_prefix( const char *key )
|
|---|
| 169 | {
|
|---|
| 170 | char *subkeypath;
|
|---|
| 171 | pstring path;
|
|---|
| 172 |
|
|---|
| 173 | pstrcpy( path, key );
|
|---|
| 174 | normalize_reg_path( path );
|
|---|
| 175 |
|
|---|
| 176 | /* normalizing the path does not change length, just key delimiters and case */
|
|---|
| 177 |
|
|---|
| 178 | if ( strncmp( path, KEY_WINNT_PRINTERS, strlen(KEY_WINNT_PRINTERS) ) == 0 )
|
|---|
| 179 | subkeypath = reg_remaining_path( key + strlen(KEY_WINNT_PRINTERS) );
|
|---|
| 180 | else
|
|---|
| 181 | subkeypath = reg_remaining_path( key + strlen(KEY_CONTROL_PRINTERS) );
|
|---|
| 182 |
|
|---|
| 183 | return subkeypath;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | /*********************************************************************
|
|---|
| 187 | *********************************************************************/
|
|---|
| 188 |
|
|---|
| 189 | static int key_printers_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
|
|---|
| 190 | {
|
|---|
| 191 | int n_services = lp_numservices();
|
|---|
| 192 | int snum;
|
|---|
| 193 | fstring sname;
|
|---|
| 194 | int i;
|
|---|
| 195 | int num_subkeys = 0;
|
|---|
| 196 | char *printers_key;
|
|---|
| 197 | char *printername, *printerdatakey;
|
|---|
| 198 | NT_PRINTER_INFO_LEVEL *printer = NULL;
|
|---|
| 199 | fstring *subkey_names = NULL;
|
|---|
| 200 |
|
|---|
| 201 | DEBUG(10,("key_printers_fetch_keys: key=>[%s]\n", key ? key : "NULL" ));
|
|---|
| 202 |
|
|---|
| 203 | printers_key = strip_printers_prefix( key );
|
|---|
| 204 |
|
|---|
| 205 | if ( !printers_key ) {
|
|---|
| 206 | /* enumerate all printers */
|
|---|
| 207 |
|
|---|
| 208 | for (snum=0; snum<n_services; snum++) {
|
|---|
| 209 | if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
|
|---|
| 210 | continue;
|
|---|
| 211 |
|
|---|
| 212 | /* don't report the [printers] share */
|
|---|
| 213 |
|
|---|
| 214 | if ( strequal( lp_servicename(snum), PRINTERS_NAME ) )
|
|---|
| 215 | continue;
|
|---|
| 216 |
|
|---|
| 217 | fstrcpy( sname, lp_servicename(snum) );
|
|---|
| 218 |
|
|---|
| 219 | regsubkey_ctr_addkey( subkeys, sname );
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | num_subkeys = regsubkey_ctr_numkeys( subkeys );
|
|---|
| 223 | goto done;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | /* get information for a specific printer */
|
|---|
| 227 |
|
|---|
| 228 | if (!reg_split_path( printers_key, &printername, &printerdatakey )) {
|
|---|
| 229 | return -1;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | /* validate the printer name */
|
|---|
| 233 |
|
|---|
| 234 | for (snum=0; snum<n_services; snum++) {
|
|---|
| 235 | if ( !lp_snum_ok(snum) || !lp_print_ok(snum) )
|
|---|
| 236 | continue;
|
|---|
| 237 | if (strequal( lp_servicename(snum), printername ) )
|
|---|
| 238 | break;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | if ( snum>=n_services
|
|---|
| 242 | || !W_ERROR_IS_OK( get_a_printer(NULL, &printer, 2, printername) ) )
|
|---|
| 243 | {
|
|---|
| 244 | return -1;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | num_subkeys = get_printer_subkeys( printer->info_2->data, printerdatakey?printerdatakey:"", &subkey_names );
|
|---|
| 248 |
|
|---|
| 249 | for ( i=0; i<num_subkeys; i++ )
|
|---|
| 250 | regsubkey_ctr_addkey( subkeys, subkey_names[i] );
|
|---|
| 251 |
|
|---|
| 252 | free_a_printer( &printer, 2 );
|
|---|
| 253 |
|
|---|
| 254 | /* no other subkeys below here */
|
|---|
| 255 |
|
|---|
| 256 | done:
|
|---|
| 257 | SAFE_FREE( subkey_names );
|
|---|
| 258 |
|
|---|
| 259 | return num_subkeys;
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 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 | *********************************************************************/
|
|---|
| 267 |
|
|---|
| 268 | static BOOL add_printers_by_registry( REGSUBKEY_CTR *subkeys )
|
|---|
| 269 | {
|
|---|
| 270 | int i, num_keys, snum;
|
|---|
| 271 | char *printername;
|
|---|
| 272 | NT_PRINTER_INFO_LEVEL_2 info2;
|
|---|
| 273 | NT_PRINTER_INFO_LEVEL printer;
|
|---|
| 274 |
|
|---|
| 275 | ZERO_STRUCT( info2 );
|
|---|
| 276 | printer.info_2 = &info2;
|
|---|
| 277 |
|
|---|
| 278 | num_keys = regsubkey_ctr_numkeys( subkeys );
|
|---|
| 279 |
|
|---|
| 280 | become_root();
|
|---|
| 281 | for ( i=0; i<num_keys; i++ ) {
|
|---|
| 282 | printername = regsubkey_ctr_specific_key( subkeys, i );
|
|---|
| 283 | snum = find_service( printername );
|
|---|
| 284 |
|
|---|
| 285 | /* just verify a valied snum for now */
|
|---|
| 286 | if ( snum == -1 ) {
|
|---|
| 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",
|
|---|
| 291 | printername));
|
|---|
| 292 | }
|
|---|
| 293 | }
|
|---|
| 294 | }
|
|---|
| 295 | unbecome_root();
|
|---|
| 296 |
|
|---|
| 297 | return True;
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | /**********************************************************************
|
|---|
| 301 | *********************************************************************/
|
|---|
| 302 |
|
|---|
| 303 | static BOOL key_printers_store_keys( const char *key, REGSUBKEY_CTR *subkeys )
|
|---|
| 304 | {
|
|---|
| 305 | char *printers_key;
|
|---|
| 306 | char *printername, *printerdatakey;
|
|---|
| 307 | NT_PRINTER_INFO_LEVEL *printer = NULL;
|
|---|
| 308 | int i, num_subkeys, num_existing_keys;
|
|---|
| 309 | char *subkeyname;
|
|---|
| 310 | fstring *existing_subkeys = NULL;
|
|---|
| 311 |
|
|---|
| 312 | printers_key = strip_printers_prefix( key );
|
|---|
| 313 |
|
|---|
| 314 | if ( !printers_key ) {
|
|---|
| 315 | /* have to deal with some new or deleted printer */
|
|---|
| 316 | return add_printers_by_registry( subkeys );
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | if (!reg_split_path( printers_key, &printername, &printerdatakey )) {
|
|---|
| 320 | return False;
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | /* lookup the printer */
|
|---|
| 324 |
|
|---|
| 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",
|
|---|
| 327 | printername));
|
|---|
| 328 | return False;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | /* get the top level printer keys */
|
|---|
| 332 |
|
|---|
| 333 | num_existing_keys = get_printer_subkeys( printer->info_2->data, "", &existing_subkeys );
|
|---|
| 334 |
|
|---|
| 335 | for ( i=0; i<num_existing_keys; i++ ) {
|
|---|
| 336 |
|
|---|
| 337 | /* remove the key if it has been deleted */
|
|---|
| 338 |
|
|---|
| 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] );
|
|---|
| 343 | }
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 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 );
|
|---|
| 355 | return False;
|
|---|
| 356 | }
|
|---|
| 357 | }
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | /* write back to disk */
|
|---|
| 361 |
|
|---|
| 362 | mod_a_printer( printer, 2 );
|
|---|
| 363 |
|
|---|
| 364 | /* cleanup */
|
|---|
| 365 |
|
|---|
| 366 | if ( printer )
|
|---|
| 367 | free_a_printer( &printer, 2 );
|
|---|
| 368 |
|
|---|
| 369 | SAFE_FREE( existing_subkeys );
|
|---|
| 370 |
|
|---|
| 371 | return True;
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | /**********************************************************************
|
|---|
| 375 | *********************************************************************/
|
|---|
| 376 |
|
|---|
| 377 | static void fill_in_printer_values( NT_PRINTER_INFO_LEVEL_2 *info2, REGVAL_CTR *values )
|
|---|
| 378 | {
|
|---|
| 379 | DEVICEMODE *devmode;
|
|---|
| 380 | prs_struct prs;
|
|---|
| 381 | uint32 offset;
|
|---|
| 382 | UNISTR2 data;
|
|---|
| 383 | char *p;
|
|---|
| 384 | uint32 printer_status = PRINTER_STATUS_OK;
|
|---|
| 385 |
|
|---|
| 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) );
|
|---|
| 390 |
|
|---|
| 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) );
|
|---|
| 393 |
|
|---|
| 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) );
|
|---|
| 396 |
|
|---|
| 397 | /* strip the \\server\ from this string */
|
|---|
| 398 | if ( !(p = strrchr( info2->printername, '\\' ) ) )
|
|---|
| 399 | p = info2->printername;
|
|---|
| 400 | else
|
|---|
| 401 | p++;
|
|---|
| 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) );
|
|---|
| 404 |
|
|---|
| 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) );
|
|---|
| 407 |
|
|---|
| 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) );
|
|---|
| 410 |
|
|---|
| 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) );
|
|---|
| 413 |
|
|---|
| 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) );
|
|---|
| 416 |
|
|---|
| 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) );
|
|---|
| 419 |
|
|---|
| 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) );
|
|---|
| 422 |
|
|---|
| 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) );
|
|---|
| 425 |
|
|---|
| 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) );
|
|---|
| 428 |
|
|---|
| 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) );
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 | /* use a prs_struct for converting the devmode and security
|
|---|
| 434 | descriptor to REG_BINARY */
|
|---|
| 435 |
|
|---|
| 436 | prs_init( &prs, RPC_MAX_PDU_FRAG_LEN, values, MARSHALL);
|
|---|
| 437 |
|
|---|
| 438 | /* stream the device mode */
|
|---|
| 439 |
|
|---|
| 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 );
|
|---|
| 444 | }
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | prs_mem_clear( &prs );
|
|---|
| 448 | prs_set_offset( &prs, 0 );
|
|---|
| 449 |
|
|---|
| 450 | /* stream the printer security descriptor */
|
|---|
| 451 |
|
|---|
| 452 | if ( info2->secdesc_buf && info2->secdesc_buf->len ) {
|
|---|
| 453 | if ( sec_io_desc("sec_desc", &info2->secdesc_buf->sec, &prs, 0 ) ) {
|
|---|
| 454 | offset = prs_offset( &prs );
|
|---|
| 455 | regval_ctr_addvalue( values, "Security", REG_BINARY, prs_data_p(&prs), offset );
|
|---|
| 456 | }
|
|---|
| 457 | }
|
|---|
| 458 |
|
|---|
| 459 | prs_mem_free( &prs );
|
|---|
| 460 |
|
|---|
| 461 | return;
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | /**********************************************************************
|
|---|
| 465 | *********************************************************************/
|
|---|
| 466 |
|
|---|
| 467 | static int key_printers_fetch_values( const char *key, REGVAL_CTR *values )
|
|---|
| 468 | {
|
|---|
| 469 | int num_values;
|
|---|
| 470 | char *printers_key;
|
|---|
| 471 | char *printername, *printerdatakey;
|
|---|
| 472 | NT_PRINTER_INFO_LEVEL *printer = NULL;
|
|---|
| 473 | NT_PRINTER_DATA *p_data;
|
|---|
| 474 | int i, key_index;
|
|---|
| 475 |
|
|---|
| 476 | printers_key = strip_printers_prefix( key );
|
|---|
| 477 |
|
|---|
| 478 | /* top level key values stored in the registry has no values */
|
|---|
| 479 |
|
|---|
| 480 | if ( !printers_key ) {
|
|---|
| 481 | /* normalize to the 'HKLM\SOFTWARE\...\Print\Printers' ket */
|
|---|
| 482 | return regdb_fetch_values( KEY_WINNT_PRINTERS, values );
|
|---|
| 483 | }
|
|---|
| 484 |
|
|---|
| 485 | /* lookup the printer object */
|
|---|
| 486 |
|
|---|
| 487 | if (!reg_split_path( printers_key, &printername, &printerdatakey )) {
|
|---|
| 488 | return -1;
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | if ( !W_ERROR_IS_OK( get_a_printer(NULL, &printer, 2, printername) ) )
|
|---|
| 492 | goto done;
|
|---|
| 493 |
|
|---|
| 494 | if ( !printerdatakey ) {
|
|---|
| 495 | fill_in_printer_values( printer->info_2, values );
|
|---|
| 496 | goto done;
|
|---|
| 497 | }
|
|---|
| 498 |
|
|---|
| 499 | /* iterate over all printer data keys and fill the regval container */
|
|---|
| 500 |
|
|---|
| 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));
|
|---|
| 505 | if ( printer )
|
|---|
| 506 | free_a_printer( &printer, 2 );
|
|---|
| 507 | return -1;
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 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) );
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 | done:
|
|---|
| 516 | if ( printer )
|
|---|
| 517 | free_a_printer( &printer, 2 );
|
|---|
| 518 |
|
|---|
| 519 | return regval_ctr_numvals( values );
|
|---|
| 520 | }
|
|---|
| 521 |
|
|---|
| 522 | /**********************************************************************
|
|---|
| 523 | *********************************************************************/
|
|---|
| 524 |
|
|---|
| 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
|
|---|
| 544 |
|
|---|
| 545 | struct {
|
|---|
| 546 | const char *name;
|
|---|
| 547 | int index;
|
|---|
| 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 | { "Description", 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 },
|
|---|
| 568 | { NULL, -1 }
|
|---|
| 569 | };
|
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 | static int find_valuename_index( const char *valuename )
|
|---|
| 573 | {
|
|---|
| 574 | int i;
|
|---|
| 575 |
|
|---|
| 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;
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | return -1;
|
|---|
| 582 | }
|
|---|
| 583 |
|
|---|
| 584 | /**********************************************************************
|
|---|
| 585 | *********************************************************************/
|
|---|
| 586 |
|
|---|
| 587 | static void convert_values_to_printer_info_2( NT_PRINTER_INFO_LEVEL_2 *printer2, REGVAL_CTR *values )
|
|---|
| 588 | {
|
|---|
| 589 | int num_values = regval_ctr_numvals( values );
|
|---|
| 590 | uint32 value_index;
|
|---|
| 591 | REGISTRY_VALUE *val;
|
|---|
| 592 | int i;
|
|---|
| 593 |
|
|---|
| 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 ) );
|
|---|
| 597 |
|
|---|
| 598 | switch( value_index ) {
|
|---|
| 599 | case REG_IDX_ATTRIBUTES:
|
|---|
| 600 | printer2->attributes = (uint32)(*regval_data_p(val));
|
|---|
| 601 | break;
|
|---|
| 602 | case REG_IDX_PRIORITY:
|
|---|
| 603 | printer2->priority = (uint32)(*regval_data_p(val));
|
|---|
| 604 | break;
|
|---|
| 605 | case REG_IDX_DEFAULT_PRIORITY:
|
|---|
| 606 | printer2->default_priority = (uint32)(*regval_data_p(val));
|
|---|
| 607 | break;
|
|---|
| 608 | case REG_IDX_CHANGEID:
|
|---|
| 609 | printer2->changeid = (uint32)(*regval_data_p(val));
|
|---|
| 610 | break;
|
|---|
| 611 | case REG_IDX_STARTTIME:
|
|---|
| 612 | printer2->starttime = (uint32)(*regval_data_p(val));
|
|---|
| 613 | break;
|
|---|
| 614 | case REG_IDX_UNTILTIME:
|
|---|
| 615 | printer2->untiltime = (uint32)(*regval_data_p(val));
|
|---|
| 616 | break;
|
|---|
| 617 | case REG_IDX_NAME:
|
|---|
| 618 | rpcstr_pull( printer2->printername, regval_data_p(val), sizeof(fstring), regval_size(val), 0 );
|
|---|
| 619 | break;
|
|---|
| 620 | case REG_IDX_LOCATION:
|
|---|
| 621 | rpcstr_pull( printer2->location, regval_data_p(val), sizeof(fstring), regval_size(val), 0 );
|
|---|
| 622 | break;
|
|---|
| 623 | case REG_IDX_DESCRIPTION:
|
|---|
| 624 | rpcstr_pull( printer2->comment, regval_data_p(val), sizeof(fstring), regval_size(val), 0 );
|
|---|
| 625 | break;
|
|---|
| 626 | case REG_IDX_PARAMETERS:
|
|---|
| 627 | rpcstr_pull( printer2->parameters, regval_data_p(val), sizeof(fstring), regval_size(val), 0 );
|
|---|
| 628 | break;
|
|---|
| 629 | case REG_IDX_PORT:
|
|---|
| 630 | rpcstr_pull( printer2->portname, regval_data_p(val), sizeof(fstring), regval_size(val), 0 );
|
|---|
| 631 | break;
|
|---|
| 632 | case REG_IDX_SHARENAME:
|
|---|
| 633 | rpcstr_pull( printer2->sharename, regval_data_p(val), sizeof(fstring), regval_size(val), 0 );
|
|---|
| 634 | break;
|
|---|
| 635 | case REG_IDX_DRIVER:
|
|---|
| 636 | rpcstr_pull( printer2->drivername, regval_data_p(val), sizeof(fstring), regval_size(val), 0 );
|
|---|
| 637 | break;
|
|---|
| 638 | case REG_IDX_SEP_FILE:
|
|---|
| 639 | rpcstr_pull( printer2->sepfile, regval_data_p(val), sizeof(fstring), regval_size(val), 0 );
|
|---|
| 640 | break;
|
|---|
| 641 | case REG_IDX_PRINTPROC:
|
|---|
| 642 | rpcstr_pull( printer2->printprocessor, regval_data_p(val), sizeof(fstring), regval_size(val), 0 );
|
|---|
| 643 | break;
|
|---|
| 644 | case REG_IDX_DATATYPE:
|
|---|
| 645 | rpcstr_pull( printer2->datatype, regval_data_p(val), sizeof(fstring), regval_size(val), 0 );
|
|---|
| 646 | break;
|
|---|
| 647 | case REG_IDX_DEVMODE:
|
|---|
| 648 | break;
|
|---|
| 649 | case REG_IDX_SECDESC:
|
|---|
| 650 | break;
|
|---|
| 651 | default:
|
|---|
| 652 | /* unsupported value...throw away */
|
|---|
| 653 | DEBUG(8,("convert_values_to_printer_info_2: Unsupported registry value [%s]\n",
|
|---|
| 654 | regval_name( val ) ));
|
|---|
| 655 | }
|
|---|
| 656 | }
|
|---|
| 657 |
|
|---|
| 658 | return;
|
|---|
| 659 | }
|
|---|
| 660 |
|
|---|
| 661 | /**********************************************************************
|
|---|
| 662 | *********************************************************************/
|
|---|
| 663 |
|
|---|
| 664 | static BOOL key_printers_store_values( const char *key, REGVAL_CTR *values )
|
|---|
| 665 | {
|
|---|
| 666 | char *printers_key;
|
|---|
| 667 | char *printername, *keyname;
|
|---|
| 668 | NT_PRINTER_INFO_LEVEL *printer = NULL;
|
|---|
| 669 | WERROR result;
|
|---|
| 670 |
|
|---|
| 671 | printers_key = strip_printers_prefix( key );
|
|---|
| 672 |
|
|---|
| 673 | /* values in the top level key get stored in the registry */
|
|---|
| 674 |
|
|---|
| 675 | if ( !printers_key ) {
|
|---|
| 676 | /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
|
|---|
| 677 | return regdb_store_values( KEY_WINNT_PRINTERS, values );
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 | if (!reg_split_path( printers_key, &printername, &keyname )) {
|
|---|
| 681 | return False;
|
|---|
| 682 | }
|
|---|
| 683 |
|
|---|
| 684 | if ( !W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, printername) ) )
|
|---|
| 685 | return False;
|
|---|
| 686 |
|
|---|
| 687 | /* deal with setting values directly under the printername */
|
|---|
| 688 |
|
|---|
| 689 | if ( !keyname ) {
|
|---|
| 690 | convert_values_to_printer_info_2( printer->info_2, values );
|
|---|
| 691 | }
|
|---|
| 692 | else {
|
|---|
| 693 | int num_values = regval_ctr_numvals( values );
|
|---|
| 694 | int i;
|
|---|
| 695 | REGISTRY_VALUE *val;
|
|---|
| 696 |
|
|---|
| 697 | delete_printer_key( printer->info_2->data, keyname );
|
|---|
| 698 |
|
|---|
| 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,
|
|---|
| 703 | regval_name( val ),
|
|---|
| 704 | regval_type( val ),
|
|---|
| 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",
|
|---|
| 709 | keyname));
|
|---|
| 710 | free_a_printer( &printer, 2 );
|
|---|
| 711 | return False;
|
|---|
| 712 | }
|
|---|
| 713 | }
|
|---|
| 714 | }
|
|---|
| 715 |
|
|---|
| 716 | result = mod_a_printer( printer, 2 );
|
|---|
| 717 |
|
|---|
| 718 | free_a_printer( &printer, 2 );
|
|---|
| 719 |
|
|---|
| 720 | return W_ERROR_IS_OK(result);
|
|---|
| 721 | }
|
|---|
| 722 |
|
|---|
| 723 | /*********************************************************************
|
|---|
| 724 | *********************************************************************
|
|---|
| 725 | ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/ENVIRONMENTS"
|
|---|
| 726 | *********************************************************************
|
|---|
| 727 | *********************************************************************/
|
|---|
| 728 |
|
|---|
| 729 | static int key_driver_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
|
|---|
| 730 | {
|
|---|
| 731 | const char *environments[] = {
|
|---|
| 732 | "Windows 4.0",
|
|---|
| 733 | "Windows NT x86",
|
|---|
| 734 | "Windows NT R4000",
|
|---|
| 735 | "Windows NT Alpha_AXP",
|
|---|
| 736 | "Windows NT PowerPC",
|
|---|
| 737 | "Windows IA64",
|
|---|
| 738 | "Windows x64",
|
|---|
| 739 | NULL };
|
|---|
| 740 | fstring *drivers = NULL;
|
|---|
| 741 | int i, env_index, num_drivers;
|
|---|
| 742 | char *keystr, *base, *subkeypath;
|
|---|
| 743 | pstring key2;
|
|---|
| 744 | int num_subkeys = -1;
|
|---|
| 745 | int version;
|
|---|
| 746 |
|
|---|
| 747 | DEBUG(10,("key_driver_fetch_keys key=>[%s]\n", key ? key : "NULL" ));
|
|---|
| 748 |
|
|---|
| 749 | keystr = reg_remaining_path( key + strlen(KEY_ENVIRONMENTS) );
|
|---|
| 750 |
|
|---|
| 751 | /* list all possible architectures */
|
|---|
| 752 |
|
|---|
| 753 | if ( !keystr ) {
|
|---|
| 754 | for ( num_subkeys=0; environments[num_subkeys]; num_subkeys++ )
|
|---|
| 755 | regsubkey_ctr_addkey( subkeys, environments[num_subkeys] );
|
|---|
| 756 |
|
|---|
| 757 | return num_subkeys;
|
|---|
| 758 | }
|
|---|
| 759 |
|
|---|
| 760 | /* we are dealing with a subkey of "Environments */
|
|---|
| 761 |
|
|---|
| 762 | pstrcpy( key2, keystr );
|
|---|
| 763 | keystr = key2;
|
|---|
| 764 | if (!reg_split_path( keystr, &base, &subkeypath )) {
|
|---|
| 765 | return -1;
|
|---|
| 766 | }
|
|---|
| 767 |
|
|---|
| 768 | /* sanity check */
|
|---|
| 769 |
|
|---|
| 770 | for ( env_index=0; environments[env_index]; env_index++ ) {
|
|---|
| 771 | if ( strequal( environments[env_index], base ) )
|
|---|
| 772 | break;
|
|---|
| 773 | }
|
|---|
| 774 | if ( !environments[env_index] )
|
|---|
| 775 | return -1;
|
|---|
| 776 |
|
|---|
| 777 | /* ...\Print\Environements\...\ */
|
|---|
| 778 |
|
|---|
| 779 | if ( !subkeypath ) {
|
|---|
| 780 | regsubkey_ctr_addkey( subkeys, "Drivers" );
|
|---|
| 781 | regsubkey_ctr_addkey( subkeys, "Print Processors" );
|
|---|
| 782 |
|
|---|
| 783 | return 2;
|
|---|
| 784 | }
|
|---|
| 785 |
|
|---|
| 786 | /* more of the key path to process */
|
|---|
| 787 |
|
|---|
| 788 | keystr = subkeypath;
|
|---|
| 789 | if (!reg_split_path( keystr, &base, &subkeypath )) {
|
|---|
| 790 | return -1;
|
|---|
| 791 | }
|
|---|
| 792 |
|
|---|
| 793 | /* ...\Print\Environements\...\Drivers\ */
|
|---|
| 794 |
|
|---|
| 795 | if ( !subkeypath ) {
|
|---|
| 796 | if ( strequal(base, "Drivers") ) {
|
|---|
| 797 | switch ( env_index ) {
|
|---|
| 798 | case 0: /* Win9x */
|
|---|
| 799 | regsubkey_ctr_addkey( subkeys, "Version-0" );
|
|---|
| 800 | break;
|
|---|
| 801 | default: /* Windows NT based systems */
|
|---|
| 802 | regsubkey_ctr_addkey( subkeys, "Version-2" );
|
|---|
| 803 | regsubkey_ctr_addkey( subkeys, "Version-3" );
|
|---|
| 804 | break;
|
|---|
| 805 | }
|
|---|
| 806 |
|
|---|
| 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" );
|
|---|
| 811 |
|
|---|
| 812 | return regsubkey_ctr_numkeys( subkeys );
|
|---|
| 813 | } else
|
|---|
| 814 | return -1; /* bad path */
|
|---|
| 815 | }
|
|---|
| 816 |
|
|---|
| 817 | /* we finally get to enumerate the drivers */
|
|---|
| 818 |
|
|---|
| 819 | /* only one possible subkey below PrintProc key */
|
|---|
| 820 |
|
|---|
| 821 | if ( strequal(base, "Print Processors") ) {
|
|---|
| 822 | keystr = subkeypath;
|
|---|
| 823 | if (!reg_split_path( keystr, &base, &subkeypath )) {
|
|---|
| 824 | return -1;
|
|---|
| 825 | }
|
|---|
| 826 |
|
|---|
| 827 | /* no subkeys below this point */
|
|---|
| 828 |
|
|---|
| 829 | if ( subkeypath )
|
|---|
| 830 | return -1;
|
|---|
| 831 |
|
|---|
| 832 | /* only allow one keyname here -- 'winprint' */
|
|---|
| 833 |
|
|---|
| 834 | return strequal( base, "winprint" ) ? 0 : -1;
|
|---|
| 835 | }
|
|---|
| 836 |
|
|---|
| 837 | /* only dealing with drivers from here on out */
|
|---|
| 838 |
|
|---|
| 839 | keystr = subkeypath;
|
|---|
| 840 | if (!reg_split_path( keystr, &base, &subkeypath )) {
|
|---|
| 841 | return -1;
|
|---|
| 842 | }
|
|---|
| 843 |
|
|---|
| 844 | version = atoi(&base[strlen(base)-1]);
|
|---|
| 845 |
|
|---|
| 846 | switch (env_index) {
|
|---|
| 847 | case 0:
|
|---|
| 848 | if ( version != 0 )
|
|---|
| 849 | return -1;
|
|---|
| 850 | break;
|
|---|
| 851 | default:
|
|---|
| 852 | if ( version != 2 && version != 3 )
|
|---|
| 853 | return -1;
|
|---|
| 854 | break;
|
|---|
| 855 | }
|
|---|
| 856 |
|
|---|
| 857 |
|
|---|
| 858 | if ( !subkeypath ) {
|
|---|
| 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] );
|
|---|
| 862 |
|
|---|
| 863 | return regsubkey_ctr_numkeys( subkeys );
|
|---|
| 864 | }
|
|---|
| 865 |
|
|---|
| 866 | /* if anything else left, just say if has no subkeys */
|
|---|
| 867 |
|
|---|
| 868 | DEBUG(1,("key_driver_fetch_keys unhandled key [%s] (subkey == %s\n",
|
|---|
| 869 | key, subkeypath ));
|
|---|
| 870 |
|
|---|
| 871 | return 0;
|
|---|
| 872 | }
|
|---|
| 873 |
|
|---|
| 874 |
|
|---|
| 875 | /**********************************************************************
|
|---|
| 876 | *********************************************************************/
|
|---|
| 877 |
|
|---|
| 878 | static void fill_in_driver_values( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info3, REGVAL_CTR *values )
|
|---|
| 879 | {
|
|---|
| 880 | char *buffer = NULL;
|
|---|
| 881 | int buffer_size = 0;
|
|---|
| 882 | int i, length;
|
|---|
| 883 | char *filename;
|
|---|
| 884 | UNISTR2 data;
|
|---|
| 885 |
|
|---|
| 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) );
|
|---|
| 890 |
|
|---|
| 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) );
|
|---|
| 895 |
|
|---|
| 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) );
|
|---|
| 900 |
|
|---|
| 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) );
|
|---|
| 905 |
|
|---|
| 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) );
|
|---|
| 909 |
|
|---|
| 910 | regval_ctr_addvalue( values, "Version", REG_DWORD, (char*)&info3->cversion,
|
|---|
| 911 | sizeof(info3->cversion) );
|
|---|
| 912 |
|
|---|
| 913 | if ( info3->dependentfiles ) {
|
|---|
| 914 | /* place the list of dependent files in a single
|
|---|
| 915 | character buffer, separating each file name by
|
|---|
| 916 | a NULL */
|
|---|
| 917 |
|
|---|
| 918 | for ( i=0; strcmp(info3->dependentfiles[i], ""); i++ ) {
|
|---|
| 919 | /* strip the path to only the file's base name */
|
|---|
| 920 |
|
|---|
| 921 | filename = dos_basename( info3->dependentfiles[i] );
|
|---|
| 922 |
|
|---|
| 923 | length = strlen(filename);
|
|---|
| 924 |
|
|---|
| 925 | buffer = (char *)SMB_REALLOC( buffer, buffer_size + (length + 1)*sizeof(uint16) );
|
|---|
| 926 | if ( !buffer ) {
|
|---|
| 927 | break;
|
|---|
| 928 | }
|
|---|
| 929 |
|
|---|
| 930 | init_unistr2( &data, filename, UNI_STR_TERMINATE);
|
|---|
| 931 | memcpy( buffer+buffer_size, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
|
|---|
| 932 |
|
|---|
| 933 | buffer_size += (length + 1)*sizeof(uint16);
|
|---|
| 934 | }
|
|---|
| 935 |
|
|---|
| 936 | /* terminated by double NULL. Add the final one here */
|
|---|
| 937 |
|
|---|
| 938 | buffer = (char *)SMB_REALLOC( buffer, buffer_size + 2 );
|
|---|
| 939 | if ( !buffer ) {
|
|---|
| 940 | buffer_size = 0;
|
|---|
| 941 | } else {
|
|---|
| 942 | buffer[buffer_size++] = '\0';
|
|---|
| 943 | buffer[buffer_size++] = '\0';
|
|---|
| 944 | }
|
|---|
| 945 | }
|
|---|
| 946 |
|
|---|
| 947 | regval_ctr_addvalue( values, "Dependent Files", REG_MULTI_SZ, buffer, buffer_size );
|
|---|
| 948 |
|
|---|
| 949 | SAFE_FREE( buffer );
|
|---|
| 950 |
|
|---|
| 951 | return;
|
|---|
| 952 | }
|
|---|
| 953 |
|
|---|
| 954 | /**********************************************************************
|
|---|
| 955 | *********************************************************************/
|
|---|
| 956 |
|
|---|
| 957 | static int driver_arch_fetch_values( char *key, REGVAL_CTR *values )
|
|---|
| 958 | {
|
|---|
| 959 | char *keystr, *base, *subkeypath;
|
|---|
| 960 | fstring arch_environment;
|
|---|
| 961 | fstring driver;
|
|---|
| 962 | int version;
|
|---|
| 963 | NT_PRINTER_DRIVER_INFO_LEVEL driver_ctr;
|
|---|
| 964 | WERROR w_result;
|
|---|
| 965 |
|
|---|
| 966 | if (!reg_split_path( key, &base, &subkeypath )) {
|
|---|
| 967 | return -1;
|
|---|
| 968 | }
|
|---|
| 969 |
|
|---|
| 970 | /* no values in 'Environments\Drivers\Windows NT x86' */
|
|---|
| 971 |
|
|---|
| 972 | if ( !subkeypath )
|
|---|
| 973 | return 0;
|
|---|
| 974 |
|
|---|
| 975 | /* We have the Architecture string and some subkey name:
|
|---|
| 976 | Currently we only support
|
|---|
| 977 | * Drivers
|
|---|
| 978 | * Print Processors
|
|---|
| 979 | Anything else is an error.
|
|---|
| 980 | */
|
|---|
| 981 |
|
|---|
| 982 | fstrcpy( arch_environment, base );
|
|---|
| 983 |
|
|---|
| 984 | keystr = subkeypath;
|
|---|
| 985 | if (!reg_split_path( keystr, &base, &subkeypath )) {
|
|---|
| 986 | return -1;
|
|---|
| 987 | }
|
|---|
| 988 |
|
|---|
| 989 | if ( strequal(base, "Print Processors") )
|
|---|
| 990 | return 0;
|
|---|
| 991 |
|
|---|
| 992 | /* only Drivers key can be left */
|
|---|
| 993 |
|
|---|
| 994 | if ( !strequal(base, "Drivers") )
|
|---|
| 995 | return -1;
|
|---|
| 996 |
|
|---|
| 997 | if ( !subkeypath )
|
|---|
| 998 | return 0;
|
|---|
| 999 |
|
|---|
| 1000 | /* We know that we have Architechure\Drivers with some subkey name
|
|---|
| 1001 | The subkey name has to be Version-XX */
|
|---|
| 1002 |
|
|---|
| 1003 | keystr = subkeypath;
|
|---|
| 1004 | if (!reg_split_path( keystr, &base, &subkeypath )) {
|
|---|
| 1005 | return -1;
|
|---|
| 1006 | }
|
|---|
| 1007 |
|
|---|
| 1008 | if ( !subkeypath )
|
|---|
| 1009 | return 0;
|
|---|
| 1010 |
|
|---|
| 1011 | version = atoi(&base[strlen(base)-1]);
|
|---|
| 1012 |
|
|---|
| 1013 | /* BEGIN PRINTER DRIVER NAME BLOCK */
|
|---|
| 1014 |
|
|---|
| 1015 | keystr = subkeypath;
|
|---|
| 1016 | if (!reg_split_path( keystr, &base, &subkeypath )) {
|
|---|
| 1017 | return -1;
|
|---|
| 1018 | }
|
|---|
| 1019 |
|
|---|
| 1020 | /* don't go any deeper for now */
|
|---|
| 1021 |
|
|---|
| 1022 | fstrcpy( driver, base );
|
|---|
| 1023 |
|
|---|
| 1024 | w_result = get_a_printer_driver( &driver_ctr, 3, driver, arch_environment, version );
|
|---|
| 1025 |
|
|---|
| 1026 | if ( !W_ERROR_IS_OK(w_result) )
|
|---|
| 1027 | return -1;
|
|---|
| 1028 |
|
|---|
| 1029 | fill_in_driver_values( driver_ctr.info_3, values );
|
|---|
| 1030 |
|
|---|
| 1031 | free_a_printer_driver( driver_ctr, 3 );
|
|---|
| 1032 |
|
|---|
| 1033 | /* END PRINTER DRIVER NAME BLOCK */
|
|---|
| 1034 |
|
|---|
| 1035 |
|
|---|
| 1036 | DEBUG(8,("key_driver_fetch_values: Exit\n"));
|
|---|
| 1037 |
|
|---|
| 1038 | return regval_ctr_numvals( values );
|
|---|
| 1039 | }
|
|---|
| 1040 |
|
|---|
| 1041 | /**********************************************************************
|
|---|
| 1042 | *********************************************************************/
|
|---|
| 1043 |
|
|---|
| 1044 | static int key_driver_fetch_values( const char *key, REGVAL_CTR *values )
|
|---|
| 1045 | {
|
|---|
| 1046 | char *keystr;
|
|---|
| 1047 | pstring subkey;
|
|---|
| 1048 |
|
|---|
| 1049 | DEBUG(8,("key_driver_fetch_values: Enter key => [%s]\n", key ? key : "NULL"));
|
|---|
| 1050 |
|
|---|
| 1051 | /* no values in the Environments key */
|
|---|
| 1052 |
|
|---|
| 1053 | if ( !(keystr = reg_remaining_path( key + strlen(KEY_ENVIRONMENTS) )) )
|
|---|
| 1054 | return 0;
|
|---|
| 1055 |
|
|---|
| 1056 | pstrcpy( subkey, keystr);
|
|---|
| 1057 |
|
|---|
| 1058 | /* pass off to handle subkeys */
|
|---|
| 1059 |
|
|---|
| 1060 | return driver_arch_fetch_values( subkey, values );
|
|---|
| 1061 | }
|
|---|
| 1062 |
|
|---|
| 1063 | /*********************************************************************
|
|---|
| 1064 | *********************************************************************
|
|---|
| 1065 | ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT"
|
|---|
| 1066 | *********************************************************************
|
|---|
| 1067 | *********************************************************************/
|
|---|
| 1068 |
|
|---|
| 1069 | static int key_print_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
|
|---|
| 1070 | {
|
|---|
| 1071 | int key_len = strlen(key);
|
|---|
| 1072 |
|
|---|
| 1073 | /* no keys below 'Print' handled here */
|
|---|
| 1074 |
|
|---|
| 1075 | if ( (key_len != strlen(KEY_CONTROL_PRINT)) && (key_len != strlen(KEY_WINNT_PRINT)) )
|
|---|
| 1076 | return -1;
|
|---|
| 1077 |
|
|---|
| 1078 | regsubkey_ctr_addkey( subkeys, "Environments" );
|
|---|
| 1079 | regsubkey_ctr_addkey( subkeys, "Monitors" );
|
|---|
| 1080 | regsubkey_ctr_addkey( subkeys, "Forms" );
|
|---|
| 1081 | regsubkey_ctr_addkey( subkeys, "Printers" );
|
|---|
| 1082 |
|
|---|
| 1083 | return regsubkey_ctr_numkeys( subkeys );
|
|---|
| 1084 | }
|
|---|
| 1085 |
|
|---|
| 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 | *********************************************************************/
|
|---|
| 1093 |
|
|---|
| 1094 | static struct reg_dyn_tree print_registry[] = {
|
|---|
| 1095 | /* just pass the monitor onto the registry tdb */
|
|---|
| 1096 | { KEY_MONITORS,
|
|---|
| 1097 | ®db_fetch_keys,
|
|---|
| 1098 | ®db_store_keys,
|
|---|
| 1099 | ®db_fetch_values,
|
|---|
| 1100 | ®db_store_values },
|
|---|
| 1101 | { KEY_FORMS,
|
|---|
| 1102 | &key_forms_fetch_keys,
|
|---|
| 1103 | NULL,
|
|---|
| 1104 | &key_forms_fetch_values,
|
|---|
| 1105 | NULL },
|
|---|
| 1106 | { KEY_CONTROL_PRINTERS,
|
|---|
| 1107 | &key_printers_fetch_keys,
|
|---|
| 1108 | &key_printers_store_keys,
|
|---|
| 1109 | &key_printers_fetch_values,
|
|---|
| 1110 | &key_printers_store_values },
|
|---|
| 1111 | { KEY_ENVIRONMENTS,
|
|---|
| 1112 | &key_driver_fetch_keys,
|
|---|
| 1113 | NULL,
|
|---|
| 1114 | &key_driver_fetch_values,
|
|---|
| 1115 | NULL },
|
|---|
| 1116 | { KEY_CONTROL_PRINT,
|
|---|
| 1117 | &key_print_fetch_keys,
|
|---|
| 1118 | NULL,
|
|---|
| 1119 | NULL,
|
|---|
| 1120 | NULL },
|
|---|
| 1121 | { KEY_WINNT_PRINTERS,
|
|---|
| 1122 | &key_printers_fetch_keys,
|
|---|
| 1123 | &key_printers_store_keys,
|
|---|
| 1124 | &key_printers_fetch_values,
|
|---|
| 1125 | &key_printers_store_values },
|
|---|
| 1126 | { KEY_PORTS,
|
|---|
| 1127 | ®db_fetch_keys,
|
|---|
| 1128 | ®db_store_keys,
|
|---|
| 1129 | ®db_fetch_values,
|
|---|
| 1130 | ®db_store_values },
|
|---|
| 1131 |
|
|---|
| 1132 | { NULL, NULL, NULL, NULL, NULL }
|
|---|
| 1133 | };
|
|---|
| 1134 |
|
|---|
| 1135 |
|
|---|
| 1136 | /**********************************************************************
|
|---|
| 1137 | *********************************************************************
|
|---|
| 1138 | ** Main reg_printing interface functions
|
|---|
| 1139 | *********************************************************************
|
|---|
| 1140 | *********************************************************************/
|
|---|
| 1141 |
|
|---|
| 1142 | /***********************************************************************
|
|---|
| 1143 | Lookup a key in the print_registry table, returning its index.
|
|---|
| 1144 | -1 on failure
|
|---|
| 1145 | **********************************************************************/
|
|---|
| 1146 |
|
|---|
| 1147 | static int match_registry_path( const char *key )
|
|---|
| 1148 | {
|
|---|
| 1149 | int i;
|
|---|
| 1150 | pstring path;
|
|---|
| 1151 |
|
|---|
| 1152 | if ( !key )
|
|---|
| 1153 | return -1;
|
|---|
| 1154 |
|
|---|
| 1155 | pstrcpy( path, key );
|
|---|
| 1156 | normalize_reg_path( path );
|
|---|
| 1157 |
|
|---|
| 1158 | for ( i=0; print_registry[i].path; i++ ) {
|
|---|
| 1159 | if ( strncmp( path, print_registry[i].path, strlen(print_registry[i].path) ) == 0 )
|
|---|
| 1160 | return i;
|
|---|
| 1161 | }
|
|---|
| 1162 |
|
|---|
| 1163 | return -1;
|
|---|
| 1164 | }
|
|---|
| 1165 |
|
|---|
| 1166 | /***********************************************************************
|
|---|
| 1167 | **********************************************************************/
|
|---|
| 1168 |
|
|---|
| 1169 | static int regprint_fetch_reg_keys( const char *key, REGSUBKEY_CTR *subkeys )
|
|---|
| 1170 | {
|
|---|
| 1171 | int i = match_registry_path( key );
|
|---|
| 1172 |
|
|---|
| 1173 | if ( i == -1 )
|
|---|
| 1174 | return -1;
|
|---|
| 1175 |
|
|---|
| 1176 | if ( !print_registry[i].fetch_subkeys )
|
|---|
| 1177 | return -1;
|
|---|
| 1178 |
|
|---|
| 1179 | return print_registry[i].fetch_subkeys( key, subkeys );
|
|---|
| 1180 | }
|
|---|
| 1181 |
|
|---|
| 1182 | /**********************************************************************
|
|---|
| 1183 | *********************************************************************/
|
|---|
| 1184 |
|
|---|
| 1185 | static BOOL regprint_store_reg_keys( const char *key, REGSUBKEY_CTR *subkeys )
|
|---|
| 1186 | {
|
|---|
| 1187 | int i = match_registry_path( key );
|
|---|
| 1188 |
|
|---|
| 1189 | if ( i == -1 )
|
|---|
| 1190 | return False;
|
|---|
| 1191 |
|
|---|
| 1192 | if ( !print_registry[i].store_subkeys )
|
|---|
| 1193 | return False;
|
|---|
| 1194 |
|
|---|
| 1195 | return print_registry[i].store_subkeys( key, subkeys );
|
|---|
| 1196 | }
|
|---|
| 1197 |
|
|---|
| 1198 | /**********************************************************************
|
|---|
| 1199 | *********************************************************************/
|
|---|
| 1200 |
|
|---|
| 1201 | static int regprint_fetch_reg_values( const char *key, REGVAL_CTR *values )
|
|---|
| 1202 | {
|
|---|
| 1203 | int i = match_registry_path( key );
|
|---|
| 1204 |
|
|---|
| 1205 | if ( i == -1 )
|
|---|
| 1206 | return -1;
|
|---|
| 1207 |
|
|---|
| 1208 | /* return 0 values by default since we know the key had
|
|---|
| 1209 | to exist because the client opened a handle */
|
|---|
| 1210 |
|
|---|
| 1211 | if ( !print_registry[i].fetch_values )
|
|---|
| 1212 | return 0;
|
|---|
| 1213 |
|
|---|
| 1214 | return print_registry[i].fetch_values( key, values );
|
|---|
| 1215 | }
|
|---|
| 1216 |
|
|---|
| 1217 | /**********************************************************************
|
|---|
| 1218 | *********************************************************************/
|
|---|
| 1219 |
|
|---|
| 1220 | static BOOL regprint_store_reg_values( const char *key, REGVAL_CTR *values )
|
|---|
| 1221 | {
|
|---|
| 1222 | int i = match_registry_path( key );
|
|---|
| 1223 |
|
|---|
| 1224 | if ( i == -1 )
|
|---|
| 1225 | return False;
|
|---|
| 1226 |
|
|---|
| 1227 | if ( !print_registry[i].store_values )
|
|---|
| 1228 | return False;
|
|---|
| 1229 |
|
|---|
| 1230 | return print_registry[i].store_values( key, values );
|
|---|
| 1231 | }
|
|---|
| 1232 |
|
|---|
| 1233 | /*
|
|---|
| 1234 | * Table of function pointers for accessing printing data
|
|---|
| 1235 | */
|
|---|
| 1236 |
|
|---|
| 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,
|
|---|
| 1242 | NULL
|
|---|
| 1243 | };
|
|---|
| 1244 |
|
|---|
| 1245 |
|
|---|