s3-registry: only include registry headers when really needed.
[kai/samba.git] / source3 / registry / reg_backend_printing.c
index 05bb6efb38bb278a2b5aacd1582549216fe075e3..e4a90c2e4c1d318031fd6872137abb83ad382ca1 100644 (file)
@@ -20,6 +20,7 @@
 /* Implementation of registry virtual views for printing information */
 
 #include "includes.h"
+#include "registry.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_REGISTRY
@@ -255,17 +256,17 @@ static int key_printers_fetch_keys( const char *key, struct regsubkey_ctr *subke
        }
 
        num_subkeys = get_printer_subkeys( printer->info_2->data, printerdatakey?printerdatakey:"", &subkey_names );
-       
+
        for ( i=0; i<num_subkeys; i++ )
                regsubkey_ctr_addkey( subkeys, subkey_names[i] );
-       
+
        free_a_printer( &printer, 2 );
-                       
+
        /* no other subkeys below here */
 
 done:  
        SAFE_FREE( subkey_names );
-       
+
        return num_subkeys;
 }
 
@@ -281,17 +282,17 @@ static bool add_printers_by_registry( struct regsubkey_ctr *subkeys )
        char *printername;
        NT_PRINTER_INFO_LEVEL_2 info2;
        NT_PRINTER_INFO_LEVEL printer;
-       
+
        ZERO_STRUCT( info2 );
        printer.info_2 = &info2;
-       
+
        num_keys = regsubkey_ctr_numkeys( subkeys );
-       
+
        become_root();
        for ( i=0; i<num_keys; i++ ) {
                printername = regsubkey_ctr_specific_key( subkeys, i );
                snum = find_service( printername );
-               
+
                /* just verify a valied snum for now */
                if ( snum == -1 ) {
                        fstrcpy( info2.printername, printername );
@@ -318,34 +319,34 @@ static bool key_printers_store_keys( const char *key, struct regsubkey_ctr *subk
        int i, num_subkeys, num_existing_keys;
        char *subkeyname;
        fstring *existing_subkeys = NULL;
-       
+
        printers_key = strip_printers_prefix( key );
-       
+
        if ( !printers_key ) {
                /* have to deal with some new or deleted printer */
                return add_printers_by_registry( subkeys );
        }
-       
+
        if (!reg_split_path( printers_key, &printername, &printerdatakey )) {
                return False;
        }
-       
+
        /* lookup the printer */
-       
+
        if ( !W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, printername)) ) {
                DEBUG(0,("key_printers_store_keys: Tried to store subkey for bad printername %s\n", 
                        printername));
                return False;
        }
-       
+
        /* get the top level printer keys */
-       
+
        num_existing_keys = get_printer_subkeys( printer->info_2->data, "", &existing_subkeys );
-       
+
        for ( i=0; i<num_existing_keys; i++ ) {
-       
+
                /* remove the key if it has been deleted */
-               
+
                if ( !regsubkey_ctr_key_exists( subkeys, existing_subkeys[i] ) ) {
                        DEBUG(5,("key_printers_store_keys: deleting key %s\n", 
                                existing_subkeys[i]));
@@ -366,13 +367,13 @@ static bool key_printers_store_keys( const char *key, struct regsubkey_ctr *subk
                        }
                }
        }
-       
+
        /* write back to disk */
-       
+
        mod_a_printer( printer, 2 );
-       
+
        /* cleanup */
-       
+
        free_a_printer( &printer, 2 );
 
        SAFE_FREE( existing_subkeys );
@@ -388,12 +389,12 @@ static void fill_in_printer_values(NT_PRINTER_INFO_LEVEL_2 *info2, struct regval
        struct spoolss_DeviceMode *devmode;
        char            *p;
        uint32 printer_status = PRINTER_STATUS_OK;
-       
+
        regval_ctr_addvalue( values, "Attributes",       REG_DWORD, (char*)&info2->attributes,       sizeof(info2->attributes) );
        regval_ctr_addvalue( values, "Priority",         REG_DWORD, (char*)&info2->priority,         sizeof(info2->attributes) );
        regval_ctr_addvalue( values, "ChangeID",         REG_DWORD, (char*)&info2->changeid,         sizeof(info2->changeid) );
        regval_ctr_addvalue( values, "Default Priority", REG_DWORD, (char*)&info2->default_priority, sizeof(info2->default_priority) );
-       
+
        /* lie and say everything is ok since we don't want to call print_queue_length() to get the real status */
        regval_ctr_addvalue( values, "Status",           REG_DWORD, (char*)&printer_status,          sizeof(info2->status) );
 
@@ -414,8 +415,8 @@ static void fill_in_printer_values(NT_PRINTER_INFO_LEVEL_2 *info2, struct regval
        regval_ctr_addvalue_sz(values, "Share Name", info2->sharename);
        regval_ctr_addvalue_sz(values, "Printer Driver", info2->drivername);
        regval_ctr_addvalue_sz(values, "Separator File", info2->sepfile);
-       regval_ctr_addvalue_sz(values, "Print Processor", "WinPrint");
-       regval_ctr_addvalue_sz(values, "Datatype", "RAW");
+       regval_ctr_addvalue_sz(values, "Print Processor", info2->printprocessor);
+       regval_ctr_addvalue_sz(values, "Datatype", info2->datatype);
 
        /* stream the device mode */
 
@@ -464,32 +465,32 @@ static int key_printers_fetch_values(const char *key, struct regval_ctr *values)
        NT_PRINTER_INFO_LEVEL   *printer = NULL;
        NT_PRINTER_DATA *p_data;
        int             i, key_index;
-       
+
        printers_key = strip_printers_prefix( key );    
-       
+
        /* top level key values stored in the registry has no values */
-       
+
        if ( !printers_key ) {
                /* normalize to the 'HKLM\SOFTWARE\...\Print\Printers' key */
                return regdb_fetch_values( KEY_WINNT_PRINTERS, values );
        }
-       
+
        /* lookup the printer object */
-       
+
        if (!reg_split_path( printers_key, &printername, &printerdatakey )) {
                return -1;
        }
-       
+
        if ( !W_ERROR_IS_OK( get_a_printer(NULL, &printer, 2, printername) ) )
                goto done;
-               
+
        if ( !printerdatakey ) {
                fill_in_printer_values( printer->info_2, values );
                goto done;
        }
-               
+
        /* iterate over all printer data keys and fill the regval container */
-       
+
        p_data = printer->info_2->data;
        if ( (key_index = lookup_printerkey( p_data, printerdatakey )) == -1  ) {
                /* failure....should never happen if the client has a valid open handle first */
@@ -497,16 +498,16 @@ static int key_printers_fetch_values(const char *key, struct regval_ctr *values)
                free_a_printer( &printer, 2 );
                return -1;
        }
-       
+
        num_values = regval_ctr_numvals( p_data->keys[key_index].values );      
        for ( i=0; i<num_values; i++ )
                regval_ctr_copyvalue( values, regval_ctr_specific_value(p_data->keys[key_index].values, i) );
-                       
+
 
 done:
        if ( printer )
                free_a_printer( &printer, 2 );
-               
+
        return regval_ctr_numvals( values );
 }
 
@@ -563,12 +564,12 @@ struct {
 static int find_valuename_index( const char *valuename )
 {
        int i;
-       
+
        for ( i=0; printer_values_map[i].name; i++ ) {
                if ( strequal( valuename, printer_values_map[i].name ) )
                        return printer_values_map[i].index;
        }
-       
+
        return -1;
 }
 
@@ -578,7 +579,7 @@ static int find_valuename_index( const char *valuename )
 static void pull_reg_sz_fstring(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, fstring s)
 {
        const char *str;
-       pull_reg_sz(mem_ctx, blob, &str);
+       pull_reg_sz(mem_ctx, NULL, blob, &str);
        fstrcpy(s, str);
 }
 
@@ -590,14 +591,14 @@ static void convert_values_to_printer_info_2(TALLOC_CTX *mem_ctx,
        uint32 value_index;
        struct regval_blob *val;
        int i;
-       
+
        for ( i=0; i<num_values; i++ ) {
                DATA_BLOB blob;
                val = regval_ctr_specific_value( values, i );
                value_index = find_valuename_index( regval_name( val ) );
 
                blob = data_blob_const(regval_data_p(val), regval_size(val));
-               
+
                switch( value_index ) {
                        case REG_IDX_ATTRIBUTES:
                                printer2->attributes = (uint32)(*regval_data_p(val));
@@ -657,7 +658,7 @@ static void convert_values_to_printer_info_2(TALLOC_CTX *mem_ctx,
                                        regval_name( val ) ));
                }
        }
-       
+
        return;
 }      
 
@@ -671,16 +672,16 @@ static bool key_printers_store_values(const char *key, struct regval_ctr *values
        NT_PRINTER_INFO_LEVEL   *printer = NULL;
        WERROR result;
        TALLOC_CTX *mem_ctx = talloc_init("key_printers_store_values");
-       
+
        printers_key = strip_printers_prefix( key );
-       
+
        /* values in the top level key get stored in the registry */
 
        if ( !printers_key ) {
                /* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
                return regdb_store_values( KEY_WINNT_PRINTERS, values );
        }
-       
+
        if (!reg_split_path( printers_key, &printername, &keyname )) {
                return False;
        }
@@ -697,9 +698,9 @@ static bool key_printers_store_values(const char *key, struct regval_ctr *values
                int num_values = regval_ctr_numvals( values );
                int i;
                struct regval_blob *val;
-               
+
                delete_printer_key( printer->info_2->data, keyname );
-               
+
                /* deal with any subkeys */
                for ( i=0; i<num_values; i++ ) {
                        val = regval_ctr_specific_value( values, i );
@@ -884,7 +885,7 @@ static int key_driver_fetch_keys( const char *key, struct regsubkey_ctr *subkeys
 /**********************************************************************
  *********************************************************************/
 
-static void fill_in_driver_values(const struct spoolss_DriverInfo3 *info3,
+static void fill_in_driver_values(const struct spoolss_DriverInfo8 *r,
                                  struct regval_ctr *values)
 {
        char *buffer = NULL;
@@ -893,32 +894,33 @@ static void fill_in_driver_values(const struct spoolss_DriverInfo3 *info3,
        const char *filename;
        DATA_BLOB data;
 
-       filename = dos_basename(info3->driver_path);
+       filename = dos_basename(r->driver_path);
        regval_ctr_addvalue_sz(values, "Driver", filename);
 
-       filename = dos_basename(info3->config_file);
+       filename = dos_basename(r->config_file);
        regval_ctr_addvalue_sz(values, "Configuration File", filename);
 
-       filename = dos_basename(info3->data_file);
+       filename = dos_basename(r->data_file);
        regval_ctr_addvalue_sz(values, "Data File", filename);
 
-       filename = dos_basename(info3->help_file);
+       filename = dos_basename(r->help_file);
        regval_ctr_addvalue_sz(values, "Help File", filename);
 
-       regval_ctr_addvalue_sz(values, "Data Type", info3->default_datatype);
+       regval_ctr_addvalue_sz(values, "Datatype", r->default_datatype);
+       regval_ctr_addvalue_sz(values, "Monitor", r->monitor_name);
 
-       regval_ctr_addvalue( values, "Version", REG_DWORD, (char*)&info3->version,
-               sizeof(info3->version) );
+       regval_ctr_addvalue( values, "Version", REG_DWORD, (char*)&r->version,
+               sizeof(r->version) );
 
-       if (info3->dependent_files) {
+       if (r->dependent_files) {
                /* place the list of dependent files in a single
                   character buffer, separating each file name by
                   a NULL */
 
-               for (i=0; info3->dependent_files[i] && strcmp(info3->dependent_files[i], ""); i++) {
+               for (i=0; r->dependent_files[i] && strcmp(r->dependent_files[i], ""); i++) {
                        /* strip the path to only the file's base name */
 
-                       filename = dos_basename(info3->dependent_files[i]);
+                       filename = dos_basename(r->dependent_files[i]);
 
                        length = strlen(filename);
 
@@ -927,7 +929,7 @@ static void fill_in_driver_values(const struct spoolss_DriverInfo3 *info3,
                                break;
                        }
 
-                       push_reg_sz(talloc_tos(), &data, filename);
+                       push_reg_sz(talloc_tos(), NULL, &data, filename);
                        memcpy( buffer+buffer_size, (char*)data.data, data.length);
 
                        buffer_size += (length + 1)*sizeof(uint16);
@@ -960,7 +962,7 @@ static int driver_arch_fetch_values(char *key, struct regval_ctr *values)
        fstring         arch_environment;
        fstring         driver;
        int             version;
-       union spoolss_DriverInfo *driver_ctr;
+       struct spoolss_DriverInfo8 *driver_ctr;
        WERROR          w_result;
 
        if (!reg_split_path( key, &base, &subkeypath )) {
@@ -1021,12 +1023,12 @@ static int driver_arch_fetch_values(char *key, struct regval_ctr *values)
 
        fstrcpy( driver, base );
 
-       w_result = get_a_printer_driver(talloc_tos(), &driver_ctr, 3, driver, arch_environment, version);
+       w_result = get_a_printer_driver(talloc_tos(), &driver_ctr, driver, arch_environment, version);
 
        if ( !W_ERROR_IS_OK(w_result) )
                return -1;
 
-       fill_in_driver_values(&driver_ctr->info3, values);
+       fill_in_driver_values(driver_ctr, values);
 
        free_a_printer_driver(driver_ctr);