| 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 3 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, see <http://www.gnu.org/licenses/>.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | /* Implementation of registry virtual views for printing information */
|
|---|
| 21 |
|
|---|
| 22 | #include "includes.h"
|
|---|
| 23 |
|
|---|
| 24 | #undef DBGC_CLASS
|
|---|
| 25 | #define DBGC_CLASS DBGC_REGISTRY
|
|---|
| 26 |
|
|---|
| 27 | /* registrt paths used in the print_registry[] */
|
|---|
| 28 |
|
|---|
| 29 | #define KEY_MONITORS "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/MONITORS"
|
|---|
| 30 | #define KEY_FORMS "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/FORMS"
|
|---|
| 31 | #define KEY_CONTROL_PRINTERS "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/PRINTERS"
|
|---|
| 32 | #define KEY_ENVIRONMENTS "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/ENVIRONMENTS"
|
|---|
| 33 | #define KEY_CONTROL_PRINT "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT"
|
|---|
| 34 | #define KEY_WINNT_PRINTERS "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PRINT/PRINTERS"
|
|---|
| 35 | #define KEY_WINNT_PRINT "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PRINT"
|
|---|
| 36 | #define KEY_PORTS "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PORTS"
|
|---|
| 37 |
|
|---|
| 38 | /* callback table for various registry paths below the ones we service in this module */
|
|---|
| 39 |
|
|---|
| 40 | struct reg_dyn_tree {
|
|---|
| 41 | /* full key path in normalized form */
|
|---|
| 42 | const char *path;
|
|---|
| 43 |
|
|---|
| 44 | /* callbscks for fetch/store operations */
|
|---|
| 45 | int ( *fetch_subkeys) ( const char *path, REGSUBKEY_CTR *subkeys );
|
|---|
| 46 | bool (*store_subkeys) ( const char *path, REGSUBKEY_CTR *subkeys );
|
|---|
| 47 | int (*fetch_values) ( const char *path, REGVAL_CTR *values );
|
|---|
| 48 | bool (*store_values) ( const char *path, REGVAL_CTR *values );
|
|---|
| 49 | };
|
|---|
| 50 |
|
|---|
| 51 | /*********************************************************************
|
|---|
| 52 | *********************************************************************
|
|---|
| 53 | ** Utility Functions
|
|---|
| 54 | *********************************************************************
|
|---|
| 55 | *********************************************************************/
|
|---|
| 56 |
|
|---|
| 57 | /***********************************************************************
|
|---|
| 58 | simple function to prune a pathname down to the basename of a file
|
|---|
| 59 | **********************************************************************/
|
|---|
| 60 |
|
|---|
| 61 | static const char *dos_basename(const char *path)
|
|---|
| 62 | {
|
|---|
| 63 | const char *p;
|
|---|
| 64 |
|
|---|
| 65 | if (!(p = strrchr( path, '\\'))) {
|
|---|
| 66 | p = path;
|
|---|
| 67 | } else {
|
|---|
| 68 | p++;
|
|---|
| 69 | }
|
|---|
| 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(talloc_tos(), key + strlen(KEY_FORMS));
|
|---|
| 83 |
|
|---|
| 84 | /* no keys below Forms */
|
|---|
| 85 |
|
|---|
| 86 | if (p) {
|
|---|
| 87 | return -1;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | return 0;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | /**********************************************************************
|
|---|
| 94 | *********************************************************************/
|
|---|
| 95 |
|
|---|
| 96 | static int key_forms_fetch_values( const char *key, REGVAL_CTR *values )
|
|---|
| 97 | {
|
|---|
| 98 | uint32 data[8];
|
|---|
| 99 | int i, num_values, form_index = 1;
|
|---|
| 100 | nt_forms_struct *forms_list = NULL;
|
|---|
| 101 | nt_forms_struct *form;
|
|---|
| 102 |
|
|---|
| 103 | DEBUG(10,("print_values_forms: key=>[%s]\n", key ? key : "NULL" ));
|
|---|
| 104 |
|
|---|
| 105 | num_values = get_ntforms( &forms_list );
|
|---|
| 106 |
|
|---|
| 107 | DEBUG(10,("hive_forms_fetch_values: [%d] user defined forms returned\n",
|
|---|
| 108 | num_values));
|
|---|
| 109 |
|
|---|
| 110 | /* handle user defined forms */
|
|---|
| 111 |
|
|---|
| 112 | for ( i=0; i<num_values; i++ ) {
|
|---|
| 113 | form = &forms_list[i];
|
|---|
| 114 |
|
|---|
| 115 | data[0] = form->width;
|
|---|
| 116 | data[1] = form->length;
|
|---|
| 117 | data[2] = form->left;
|
|---|
| 118 | data[3] = form->top;
|
|---|
| 119 | data[4] = form->right;
|
|---|
| 120 | data[5] = form->bottom;
|
|---|
| 121 | data[6] = form_index++;
|
|---|
| 122 | data[7] = form->flag;
|
|---|
| 123 |
|
|---|
| 124 | regval_ctr_addvalue( values, form->name, REG_BINARY, (char*)data, sizeof(data) );
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | SAFE_FREE( forms_list );
|
|---|
| 128 | forms_list = NULL;
|
|---|
| 129 |
|
|---|
| 130 | /* handle built-on forms */
|
|---|
| 131 |
|
|---|
| 132 | num_values = get_builtin_ntforms( &forms_list );
|
|---|
| 133 |
|
|---|
| 134 | DEBUG(10,("print_subpath_values_forms: [%d] built-in forms returned\n",
|
|---|
| 135 | num_values));
|
|---|
| 136 |
|
|---|
| 137 | for ( i=0; i<num_values; i++ ) {
|
|---|
| 138 | form = &forms_list[i];
|
|---|
| 139 |
|
|---|
| 140 | data[0] = form->width;
|
|---|
| 141 | data[1] = form->length;
|
|---|
| 142 | data[2] = form->left;
|
|---|
| 143 | data[3] = form->top;
|
|---|
| 144 | data[4] = form->right;
|
|---|
| 145 | data[5] = form->bottom;
|
|---|
| 146 | data[6] = form_index++;
|
|---|
| 147 | data[7] = form->flag;
|
|---|
| 148 |
|
|---|
| 149 | regval_ctr_addvalue(values, form->name, REG_BINARY, (char*)data, sizeof(data) );
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | SAFE_FREE(forms_list);
|
|---|
| 153 |
|
|---|
| 154 | return regval_ctr_numvals(values);
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | /*********************************************************************
|
|---|
| 158 | *********************************************************************
|
|---|
| 159 | ** "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/PRINTERS"
|
|---|
| 160 | ** "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PRINT/PRINTERS"
|
|---|
| 161 | *********************************************************************
|
|---|
| 162 | *********************************************************************/
|
|---|
| 163 |
|
|---|
| 164 | /*********************************************************************
|
|---|
| 165 | strip off prefix for printers key. DOes return a pointer to static
|
|---|
| 166 | memory.
|
|---|
| 167 | *********************************************************************/
|
|---|
| 168 |
|
|---|
| 169 | static char *strip_printers_prefix(const char *key)
|
|---|
| 170 | {
|
|---|
| 171 | char *subkeypath = NULL;
|
|---|
| 172 | char *path = NULL;
|
|---|
| 173 | TALLOC_CTX *ctx = talloc_tos();
|
|---|
| 174 |
|
|---|
| 175 | path = talloc_strdup(ctx, key);
|
|---|
| 176 | if (!path) {
|
|---|
| 177 | return NULL;
|
|---|
| 178 | }
|
|---|
| 179 | path = normalize_reg_path(ctx, path);
|
|---|
| 180 | if (!path) {
|
|---|
| 181 | return NULL;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | /* normalizing the path does not change length, just key delimiters and case */
|
|---|
| 185 |
|
|---|
| 186 | if (strncmp(path, KEY_WINNT_PRINTERS, strlen(KEY_WINNT_PRINTERS)) == 0) {
|
|---|
| 187 | subkeypath = reg_remaining_path(ctx, key + strlen(KEY_WINNT_PRINTERS));
|
|---|
| 188 | } else {
|
|---|
|
|---|