2 * Unix SMB/CIFS implementation.
4 * SPOOLSS RPC Pipe server / winreg client routines
6 * Copyright (c) 2010 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "srv_spoolss_util.h"
24 #include "../librpc/gen_ndr/srv_winreg.h"
25 #include "../librpc/gen_ndr/cli_winreg.h"
27 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
28 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
29 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
30 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
32 #define EMPTY_STRING ""
33 static const char *empty_string_array[1] = { NULL };
34 #define EMPTY_STRING_ARRAY empty_string_array
36 #define CHECK_ERROR(result) \
37 if (W_ERROR_IS_OK(result)) continue; \
38 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
39 if (!W_ERROR_IS_OK(result)) break
41 /* FLAGS, NAME, with, height, left, top, right, bottom */
42 static const struct spoolss_FormInfo1 builtin_forms1[] = {
43 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
44 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
45 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
46 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
47 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
48 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
49 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
50 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
51 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
52 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
53 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
54 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
55 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
56 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
57 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
58 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
59 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
60 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
61 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
62 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
63 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
64 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
65 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
66 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
67 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
68 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
69 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
70 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
71 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
72 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
73 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
74 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
75 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
76 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
77 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
78 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
79 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
80 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
81 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} },
82 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
83 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
84 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
85 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
86 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
87 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
88 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
89 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
90 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
91 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
92 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
93 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
94 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
95 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
96 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
97 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
98 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
99 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
100 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
101 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
102 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
103 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
104 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
105 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
106 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
107 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
108 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
109 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
110 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
111 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
112 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
113 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
114 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
115 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
116 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
117 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
118 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
119 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
120 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
121 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
122 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
123 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
124 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
125 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
126 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
127 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
128 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
129 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
130 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
131 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
132 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
133 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
134 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
135 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
136 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
137 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
138 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
139 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
140 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
141 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
142 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
143 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
144 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
145 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
146 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
147 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
148 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
149 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
150 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
151 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
152 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
153 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
154 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
159 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
160 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} }
163 /********************************************************************
164 static helper functions
165 ********************************************************************/
167 /****************************************************************************
168 Update the changeid time.
169 ****************************************************************************/
173 * @brief Update the ChangeID time of a printer.
175 * This is SO NASTY as some drivers need this to change, others need it
176 * static. This value will change every second, and I must hope that this
177 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
180 * @return The ChangeID.
182 static uint32_t winreg_printer_rev_changeid(void)
186 get_process_uptime(&tv);
189 /* Return changeid as msec since spooler restart */
190 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
193 * This setting seems to work well but is too untested
194 * to replace the above calculation. Left in for experiementation
195 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
197 return tv.tv_sec * 10 + tv.tv_usec / 100000;
201 static struct spoolss_DeviceMode *winreg_printer_create_default_devmode(TALLOC_CTX *mem_ctx,
202 const char *default_devicename)
204 char adevice[MAXDEVICENAME];
205 struct spoolss_DeviceMode *devmode;
207 devmode = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
208 if (devmode == NULL) {
212 slprintf(adevice, sizeof(adevice), "%s", default_devicename);
213 devmode->devicename = talloc_strdup(mem_ctx, adevice);
214 if (devmode->devicename == NULL) {
218 devmode->formname = "Letter";
220 devmode->specversion = DMSPEC_NT4_AND_ABOVE;
221 devmode->driverversion = 0x0400;
222 devmode->size = 0x00DC;
223 devmode->__driverextra_length = 0;
224 devmode->fields = DEVMODE_FORMNAME |
226 DEVMODE_PRINTQUALITY |
227 DEVMODE_DEFAULTSOURCE |
232 devmode->orientation = DMORIENT_PORTRAIT;
233 devmode->papersize = DMPAPER_LETTER;
234 devmode->paperlength = 0;
235 devmode->paperwidth = 0;
236 devmode->scale = 0x64;
238 devmode->defaultsource = DMBIN_FORMSOURCE;
239 devmode->printquality = DMRES_HIGH; /* 0x0258 */
240 devmode->color = DMRES_MONOCHROME;
241 devmode->duplex = DMDUP_SIMPLEX;
242 devmode->yresolution = 0;
243 devmode->ttoption = DMTT_SUBDEV;
244 devmode->collate = DMCOLLATE_FALSE;
245 devmode->icmmethod = 0;
246 devmode->icmintent = 0;
247 devmode->mediatype = 0;
248 devmode->dithertype = 0;
250 devmode->logpixels = 0;
251 devmode->bitsperpel = 0;
252 devmode->pelswidth = 0;
253 devmode->pelsheight = 0;
254 devmode->displayflags = 0;
255 devmode->displayfrequency = 0;
256 devmode->reserved1 = 0;
257 devmode->reserved2 = 0;
258 devmode->panningwidth = 0;
259 devmode->panningheight = 0;
261 devmode->driverextra_data.data = NULL;
262 devmode->driverextra_data.length = 0;
270 * @brief Connect to the interal winreg server and open the given printer key.
272 * The function will create the needed subkeys if they don't exist.
274 * @param[in] mem_ctx The memory context to use.
276 * @param[in] server_info The supplied server info.
278 * @param[out] winreg_pipe A pointer for the winreg rpc client pipe.
280 * @param[in] path The path to the key to open.
282 * @param[in] key The key to open.
284 * @param[in] create_key Set to true if the key should be created if it
287 * @param[in] access_mask The access mask to open the key.
289 * @param[out] hive_handle A policy handle for the opened hive.
291 * @param[out] key_handle A policy handle for the opened key.
293 * @return WERR_OK on success, the corresponding DOS error
294 * code if something gone wrong.
296 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
297 struct auth_serversupplied_info *server_info,
298 struct rpc_pipe_client **winreg_pipe,
302 uint32_t access_mask,
303 struct policy_handle *hive_handle,
304 struct policy_handle *key_handle)
306 struct rpc_pipe_client *pipe_handle;
307 struct winreg_String wkey, wkeyclass;
310 WERROR result = WERR_OK;
312 /* create winreg connection */
313 status = rpc_pipe_open_internal(mem_ctx,
314 &ndr_table_winreg.syntax_id,
318 if (!NT_STATUS_IS_OK(status)) {
319 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg_pipe: %s\n",
321 return ntstatus_to_werror(status);
324 status = rpccli_winreg_OpenHKLM(pipe_handle,
330 if (!NT_STATUS_IS_OK(status)) {
331 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
333 talloc_free(pipe_handle);
334 if (!W_ERROR_IS_OK(result)) {
337 return ntstatus_to_werror(status);
341 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
343 keyname = talloc_strdup(mem_ctx, path);
345 if (keyname == NULL) {
346 talloc_free(pipe_handle);
354 enum winreg_CreateAction action = REG_ACTION_NONE;
356 ZERO_STRUCT(wkeyclass);
359 status = rpccli_winreg_CreateKey(pipe_handle,
371 case REG_ACTION_NONE:
372 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
374 case REG_CREATED_NEW_KEY:
375 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
377 case REG_OPENED_EXISTING_KEY:
378 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
382 status = rpccli_winreg_OpenKey(pipe_handle,
391 if (!NT_STATUS_IS_OK(status)) {
392 talloc_free(pipe_handle);
393 if (!W_ERROR_IS_OK(result)) {
396 return ntstatus_to_werror(status);
399 *winreg_pipe = pipe_handle;
405 * @brief Create the registry keyname for the given printer.
407 * @param[in] mem_ctx The memory context to use.
409 * @param[in] printer The name of the printer to get the registry key.
411 * @return The registry key or NULL on error.
413 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
414 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
420 * @brief Enumerate values of an opened key handle and retrieve the data.
422 * @param[in] mem_ctx The memory context to use.
424 * @param[in] pipe_handle The pipe handle for the rpc connection.
426 * @param[in] key_hnd The opened key handle.
428 * @param[out] pnum_values A pointer to store he number of values found.
430 * @param[out] pnum_values A pointer to store the number of values we found.
432 * @return WERR_OK on success, the corresponding DOS error
433 * code if something gone wrong.
435 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
436 struct rpc_pipe_client *pipe_handle,
437 struct policy_handle *key_hnd,
438 uint32_t *pnum_values,
439 struct spoolss_PrinterEnumValues **penum_values)
442 uint32_t num_subkeys, max_subkeylen, max_classlen;
443 uint32_t num_values, max_valnamelen, max_valbufsize;
444 uint32_t secdescsize;
446 NTTIME last_changed_time;
447 struct winreg_String classname;
449 struct spoolss_PrinterEnumValues *enum_values;
451 WERROR result = WERR_OK;
454 tmp_ctx = talloc_new(mem_ctx);
455 if (tmp_ctx == NULL) {
459 ZERO_STRUCT(classname);
461 status = rpccli_winreg_QueryInfoKey(pipe_handle,
474 if (!NT_STATUS_IS_OK(status)) {
475 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
477 if (!W_ERROR_IS_OK(result)) {
480 result = ntstatus_to_werror(status);
484 if (num_values == 0) {
486 TALLOC_FREE(tmp_ctx);
490 enum_values = TALLOC_ARRAY(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
491 if (enum_values == NULL) {
496 for (i = 0; i < num_values; i++) {
497 struct spoolss_PrinterEnumValues val;
498 struct winreg_ValNameBuf name_buf;
499 enum winreg_Type type = REG_NONE;
500 uint8_t *data = NULL;
506 name_buf.size = max_valnamelen + 2;
509 data_size = max_valbufsize;
510 data = (uint8_t *) TALLOC(tmp_ctx, data_size);
513 status = rpccli_winreg_EnumValue(pipe_handle,
523 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
525 status = NT_STATUS_OK;
529 if (!NT_STATUS_IS_OK(status)) {
530 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
532 if (!W_ERROR_IS_OK(result)) {
535 result = ntstatus_to_werror(status);
539 if (name_buf.name == NULL) {
540 result = WERR_INVALID_PARAMETER;
544 val.value_name = talloc_strdup(enum_values, name_buf.name);
545 if (val.value_name == NULL) {
549 val.value_name_len = strlen_m_term(val.value_name) * 2;
552 val.data_length = data_size;
554 if (val.data_length) {
555 val.data = talloc(enum_values, DATA_BLOB);
556 if (val.data == NULL) {
560 *val.data = data_blob_talloc(enum_values, data, data_size);
563 enum_values[i] = val;
566 *pnum_values = num_values;
568 *penum_values = talloc_move(mem_ctx, &enum_values);
574 TALLOC_FREE(tmp_ctx);
581 * @brief Enumerate subkeys of an opened key handle and get the names.
583 * @param[in] mem_ctx The memory context to use.
585 * @param[in] pipe_handle The pipe handle for the rpc connection.
587 * @param[in] key_hnd The opened key handle.
589 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
591 * @param[in] psubkeys A pointer to an array to store the found names of
594 * @return WERR_OK on success, the corresponding DOS error
595 * code if something gone wrong.
597 static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
598 struct rpc_pipe_client *pipe_handle,
599 struct policy_handle *key_hnd,
600 uint32_t *pnum_subkeys,
601 const char ***psubkeys)
604 const char **subkeys;
605 uint32_t num_subkeys, max_subkeylen, max_classlen;
606 uint32_t num_values, max_valnamelen, max_valbufsize;
608 NTTIME last_changed_time;
609 uint32_t secdescsize;
610 struct winreg_String classname;
611 WERROR result = WERR_OK;
614 tmp_ctx = talloc_new(mem_ctx);
615 if (tmp_ctx == NULL) {
619 ZERO_STRUCT(classname);
621 status = rpccli_winreg_QueryInfoKey(pipe_handle,
634 if (!NT_STATUS_IS_OK(status)) {
635 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
637 if (!W_ERROR_IS_OK(result)) {
640 result = ntstatus_to_werror(status);
644 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
645 if (subkeys == NULL) {
650 if (num_subkeys == 0) {
651 subkeys[0] = talloc_strdup(subkeys, "");
652 if (subkeys[0] == NULL) {
658 *psubkeys = talloc_move(mem_ctx, &subkeys);
661 TALLOC_FREE(tmp_ctx);
665 for (i = 0; i < num_subkeys; i++) {
669 struct winreg_StringBuf class_buf;
670 struct winreg_StringBuf name_buf;
674 class_buf.size = max_classlen + 2;
675 class_buf.length = 0;
678 name_buf.size = max_subkeylen + 2;
681 ZERO_STRUCT(modtime);
683 status = rpccli_winreg_EnumKey(pipe_handle,
691 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
693 status = NT_STATUS_OK;
697 if (!NT_STATUS_IS_OK(status)) {
698 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
700 if (!W_ERROR_IS_OK(result)) {
703 result = ntstatus_to_werror(status);
707 if (name_buf.name == NULL) {
708 result = WERR_INVALID_PARAMETER;
712 name = talloc_strdup(subkeys, name_buf.name);
721 *pnum_subkeys = num_subkeys;
723 *psubkeys = talloc_move(mem_ctx, &subkeys);
727 TALLOC_FREE(tmp_ctx);
734 * @brief A function to delete a key and its subkeys recurively.
736 * @param[in] mem_ctx The memory context to use.
738 * @param[in] pipe_handle The pipe handle for the rpc connection.
740 * @param[in] hive_handle A opened hive handle to the key.
742 * @param[in] access_mask The access mask to access the key.
744 * @param[in] key The key to delete
746 * @return WERR_OK on success, the corresponding DOS error
747 * code if something gone wrong.
749 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
750 struct rpc_pipe_client *pipe_handle,
751 struct policy_handle *hive_handle,
752 uint32_t access_mask,
755 const char **subkeys = NULL;
756 uint32_t num_subkeys = 0;
757 struct policy_handle key_hnd;
758 struct winreg_String wkey;
759 WERROR result = WERR_OK;
763 ZERO_STRUCT(key_hnd);
766 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
768 status = rpccli_winreg_OpenKey(pipe_handle,
776 if (!NT_STATUS_IS_OK(status)) {
777 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
778 wkey.name, nt_errstr(status)));
779 if (!W_ERROR_IS_OK(result)) {
782 return ntstatus_to_werror(status);
785 result = winreg_printer_enumkeys(mem_ctx,
790 if (!W_ERROR_IS_OK(result)) {
794 for (i = 0; i < num_subkeys; i++) {
795 /* create key + subkey */
796 char *subkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkeys[i]);
797 if (subkey == NULL) {
801 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey));
802 result = winreg_printer_delete_subkeys(mem_ctx,
807 if (!W_ERROR_IS_OK(result)) {
812 if (is_valid_policy_hnd(&key_hnd)) {
813 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
818 status = rpccli_winreg_DeleteKey(pipe_handle,
825 if (is_valid_policy_hnd(&key_hnd)) {
826 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
832 static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
833 struct rpc_pipe_client *pipe_handle,
834 struct policy_handle *key_handle,
838 struct winreg_String wvalue;
840 WERROR result = WERR_OK;
845 blob = data_blob_string_const("");
847 if (!push_reg_sz(mem_ctx, NULL, &blob, data)) {
848 DEBUG(0, ("winreg_printer_write_sz: Could not marshall string %s for %s\n",
853 status = rpccli_winreg_SetValue(pipe_handle,
861 if (!NT_STATUS_IS_OK(status)) {
862 DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: %s\n",
863 wvalue.name, win_errstr(result)));
864 if (!W_ERROR_IS_OK(result)) {
865 result = ntstatus_to_werror(status);
872 static WERROR winreg_printer_write_dword(TALLOC_CTX *mem_ctx,
873 struct rpc_pipe_client *pipe_handle,
874 struct policy_handle *key_handle,
878 struct winreg_String wvalue;
880 WERROR result = WERR_OK;
884 blob = data_blob_talloc(mem_ctx, NULL, 4);
885 SIVAL(blob.data, 0, data);
887 status = rpccli_winreg_SetValue(pipe_handle,
895 if (!NT_STATUS_IS_OK(status)) {
896 DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: %s\n",
897 wvalue.name, win_errstr(result)));
898 if (!W_ERROR_IS_OK(result)) {
899 result = ntstatus_to_werror(status);
906 static WERROR winreg_printer_write_binary(TALLOC_CTX *mem_ctx,
907 struct rpc_pipe_client *pipe_handle,
908 struct policy_handle *key_handle,
912 struct winreg_String wvalue;
913 WERROR result = WERR_OK;
917 status = rpccli_winreg_SetValue(pipe_handle,
925 if (!NT_STATUS_IS_OK(status)) {
926 DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: %s\n",
927 wvalue.name, win_errstr(result)));
928 if (!W_ERROR_IS_OK(result)) {
929 result = ntstatus_to_werror(status);
936 static WERROR winreg_printer_query_binary(TALLOC_CTX *mem_ctx,
937 struct rpc_pipe_client *pipe_handle,
938 struct policy_handle *key_handle,
942 struct winreg_String wvalue;
943 enum winreg_Type type;
944 WERROR result = WERR_OK;
945 uint32_t value_len = 0;
946 uint32_t data_size = 0;
951 status = rpccli_winreg_QueryValue(pipe_handle,
960 if (!NT_STATUS_IS_OK(status)) {
961 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
962 wvalue.name, nt_errstr(status)));
963 if (!W_ERROR_IS_OK(result)) {
966 result = ntstatus_to_werror(status);
970 if (type != REG_BINARY) {
971 result = WERR_INVALID_DATATYPE;
974 blob = data_blob_talloc(mem_ctx, NULL, data_size);
975 if (blob.data == NULL) {
981 status = rpccli_winreg_QueryValue(pipe_handle,
990 if (!NT_STATUS_IS_OK(status)) {
991 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
992 wvalue.name, nt_errstr(status)));
993 if (!W_ERROR_IS_OK(result)) {
994 result = ntstatus_to_werror(status);
1000 data->data = blob.data;
1001 data->length = blob.length;
1007 static WERROR winreg_printer_query_dword(TALLOC_CTX *mem_ctx,
1008 struct rpc_pipe_client *pipe_handle,
1009 struct policy_handle *key_handle,
1013 struct winreg_String wvalue;
1014 enum winreg_Type type;
1015 WERROR result = WERR_OK;
1016 uint32_t value_len = 0;
1017 uint32_t data_size = 0;
1021 wvalue.name = value;
1022 status = rpccli_winreg_QueryValue(pipe_handle,
1031 if (!NT_STATUS_IS_OK(status)) {
1032 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1033 wvalue.name, nt_errstr(status)));
1034 if (!W_ERROR_IS_OK(result)) {
1037 result = ntstatus_to_werror(status);
1041 if (type != REG_DWORD) {
1042 result = WERR_INVALID_DATATYPE;
1046 if (data_size != 4) {
1047 result = WERR_INVALID_DATA;
1051 blob = data_blob_talloc(mem_ctx, NULL, data_size);
1052 if (blob.data == NULL) {
1053 result = WERR_NOMEM;
1058 status = rpccli_winreg_QueryValue(pipe_handle,
1067 if (!NT_STATUS_IS_OK(status)) {
1068 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1069 wvalue.name, nt_errstr(status)));
1070 if (!W_ERROR_IS_OK(result)) {
1071 result = ntstatus_to_werror(status);
1077 *data = IVAL(blob.data, 0);
1083 static WERROR winreg_printer_write_multi_sz(TALLOC_CTX *mem_ctx,
1084 struct rpc_pipe_client *pipe_handle,
1085 struct policy_handle *key_handle,
1089 struct winreg_String wvalue;
1091 WERROR result = WERR_OK;
1094 wvalue.name = value;
1095 if (!push_reg_multi_sz(mem_ctx, NULL, &blob, data)) {
1098 status = rpccli_winreg_SetValue(pipe_handle,
1106 if (!NT_STATUS_IS_OK(status)) {
1107 DEBUG(0, ("winreg_printer_write_multi_sz: Could not set value %s: %s\n",
1108 wvalue.name, win_errstr(result)));
1109 if (!W_ERROR_IS_OK(result)) {
1110 result = ntstatus_to_werror(status);
1117 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
1118 struct auth_serversupplied_info *server_info,
1119 const char *drivername,
1120 const char *architecture,
1122 uint32_t access_mask,
1124 struct rpc_pipe_client **winreg_pipe,
1125 struct policy_handle *hive_hnd,
1126 struct policy_handle *key_hnd)
1131 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
1132 TOP_LEVEL_CONTROL_KEY,
1133 architecture, version);
1138 result = winreg_printer_openkey(mem_ctx,
1150 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
1151 struct spoolss_PrinterEnumValues *v,
1152 const char *valuename, uint32_t *dw)
1154 /* just return if it is not the one we are looking for */
1155 if (strcmp(valuename, v->value_name) != 0) {
1156 return WERR_NOT_FOUND;
1159 if (v->type != REG_DWORD) {
1160 return WERR_INVALID_DATATYPE;
1163 *dw = IVAL(v->data->data, 0);
1167 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
1168 struct spoolss_PrinterEnumValues *v,
1169 const char *valuename, const char **_str)
1171 /* just return if it is not the one we are looking for */
1172 if (strcmp(valuename, v->value_name) != 0) {
1173 return WERR_NOT_FOUND;
1176 if (v->type != REG_SZ) {
1177 return WERR_INVALID_DATATYPE;
1180 if (!pull_reg_sz(mem_ctx, NULL, v->data, _str)) {
1187 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
1188 struct spoolss_PrinterEnumValues *v,
1189 const char *valuename,
1190 const char ***array)
1192 /* just return if it is not the one we are looking for */
1193 if (strcmp(valuename, v->value_name) != 0) {
1194 return WERR_NOT_FOUND;
1197 if (v->type != REG_MULTI_SZ) {
1198 return WERR_INVALID_DATATYPE;
1201 if (!pull_reg_multi_sz(mem_ctx, NULL, v->data, array)) {
1208 static WERROR winreg_enumval_to_blob(TALLOC_CTX *mem_ctx,
1209 struct spoolss_PrinterEnumValues *v,
1210 const char *valuename,
1213 /* just return if it is not the one we are looking for */
1214 if (strcmp(valuename, v->value_name) != 0) {
1215 return WERR_NOT_FOUND;
1218 if (v->type != REG_BINARY) {
1219 return WERR_INVALID_DATATYPE;
1222 blob->data = v->data->data;
1223 blob->length = v->data_length;
1228 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
1229 struct rpc_pipe_client *pipe_handle,
1230 struct policy_handle *key_handle,
1234 struct winreg_String wvalue;
1236 WERROR result = WERR_OK;
1242 t = nt_time_to_unix(data);
1244 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
1245 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
1250 wvalue.name = value;
1251 if (!push_reg_sz(mem_ctx, NULL, &blob, str)) {
1254 status = rpccli_winreg_SetValue(pipe_handle,
1262 if (!NT_STATUS_IS_OK(status)) {
1263 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1264 wvalue.name, win_errstr(result)));
1265 if (!W_ERROR_IS_OK(result)) {
1266 result = ntstatus_to_werror(status);
1273 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
1280 if (sscanf(str, "%d/%d/%d",
1281 &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3) {
1282 return WERR_INVALID_PARAMETER;
1289 unix_to_nt_time(data, t);
1294 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
1295 struct rpc_pipe_client *pipe_handle,
1296 struct policy_handle *key_handle,
1300 struct winreg_String wvalue;
1302 WERROR result = WERR_OK;
1306 /* FIXME: check format is right,
1307 * this needs to be something like: 6.1.7600.16385 */
1308 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
1309 (unsigned)((data >> 48) & 0xFFFF),
1310 (unsigned)((data >> 32) & 0xFFFF),
1311 (unsigned)((data >> 16) & 0xFFFF),
1312 (unsigned)(data & 0xFFFF));
1317 wvalue.name = value;
1318 if (!push_reg_sz(mem_ctx, NULL, &blob, str)) {
1321 status = rpccli_winreg_SetValue(pipe_handle,
1329 if (!NT_STATUS_IS_OK(status)) {
1330 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1331 wvalue.name, win_errstr(result)));
1332 if (!W_ERROR_IS_OK(result)) {
1333 result = ntstatus_to_werror(status);
1340 static WERROR winreg_printer_ver_to_dword(const char *str, uint64_t *data)
1342 unsigned int v1, v2, v3, v4;
1344 if (sscanf(str, "%u.%u.%u.%u", &v1, &v2, &v3, &v4) != 4) {
1345 return WERR_INVALID_PARAMETER;
1348 *data = ((uint64_t)(v1 & 0xFFFF) << 48) +
1349 ((uint64_t)(v2 & 0xFFFF) << 32) +
1350 ((uint64_t)(v3 & 0xFFFF) << 16) +
1351 (uint64_t)(v2 & 0xFFFF);
1356 /********************************************************************
1357 Public winreg function for spoolss
1358 ********************************************************************/
1360 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
1361 struct auth_serversupplied_info *server_info,
1362 const char *servername,
1363 const char *sharename)
1365 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1366 struct rpc_pipe_client *winreg_pipe = NULL;
1367 struct policy_handle hive_hnd, key_hnd;
1368 struct spoolss_SetPrinterInfo2 *info2;
1369 struct spoolss_DeviceMode *devmode = NULL;
1370 struct security_descriptor *secdesc;
1371 struct winreg_String wkey, wkeyclass;
1373 const char *subkeys[] = { "DsDriver", "DsSpooler", "PrinterDriverData" };
1374 uint32_t i, count = ARRAY_SIZE(subkeys);
1375 int snum = lp_servicenumber(sharename);
1376 uint32_t info2_mask = 0;
1377 WERROR result = WERR_OK;
1378 TALLOC_CTX *tmp_ctx;
1380 tmp_ctx = talloc_new(mem_ctx);
1381 if (tmp_ctx == NULL) {
1385 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1387 TALLOC_FREE(tmp_ctx);
1391 ZERO_STRUCT(hive_hnd);
1392 ZERO_STRUCT(key_hnd);
1394 result = winreg_printer_openkey(tmp_ctx,
1403 if (W_ERROR_IS_OK(result)) {
1404 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
1406 } else if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1407 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
1408 } else if (!W_ERROR_IS_OK(result)) {
1409 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
1410 path, win_errstr(result)));
1414 /* Create the main key */
1415 result = winreg_printer_openkey(tmp_ctx,
1424 if (!W_ERROR_IS_OK(result)) {
1425 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1426 path, win_errstr(result)));
1430 if (is_valid_policy_hnd(&key_hnd)) {
1431 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1434 /* Create subkeys */
1435 for (i = 0; i < count; i++) {
1437 enum winreg_CreateAction action = REG_ACTION_NONE;
1439 ZERO_STRUCT(key_hnd);
1442 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
1443 if (wkey.name == NULL) {
1444 result = WERR_NOMEM;
1448 ZERO_STRUCT(wkeyclass);
1449 wkeyclass.name = "";
1451 status = rpccli_winreg_CreateKey(winreg_pipe,
1462 if (!NT_STATUS_IS_OK(status)) {
1463 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1464 wkey.name, win_errstr(result)));
1465 if (!W_ERROR_IS_OK(result)) {
1466 result = ntstatus_to_werror(status);
1471 if (is_valid_policy_hnd(&key_hnd)) {
1472 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1475 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
1476 if (info2 == NULL) {
1477 result = WERR_NOMEM;
1481 info2->printername = sharename;
1482 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1484 info2->sharename = sharename;
1485 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1487 info2->portname = SAMBA_PRINTER_PORT_NAME;
1488 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1490 info2->printprocessor = "winprint";
1491 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1493 info2->datatype = "RAW";
1494 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1496 info2->comment = "";
1497 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1499 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1500 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1502 info2->starttime = 0; /* Minutes since 12:00am GMT */
1503 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1505 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1506 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1508 info2->priority = 1;
1509 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1511 info2->defaultpriority = 1;
1512 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1514 /* info2->setuptime = (uint32_t) time(NULL); */
1516 if (lp_default_devmode(snum)) {
1517 devmode = winreg_printer_create_default_devmode(tmp_ctx,
1518 info2->printername);
1519 if (devmode == NULL) {
1520 result = WERR_NOMEM;
1524 info2_mask |= SPOOLSS_PRINTER_INFO_DEVMODE;
1527 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1528 if (!W_ERROR_IS_OK(result)) {
1531 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1533 result = winreg_update_printer(tmp_ctx,
1542 if (winreg_pipe != NULL) {
1543 if (is_valid_policy_hnd(&key_hnd)) {
1544 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1546 if (is_valid_policy_hnd(&hive_hnd)) {
1547 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1551 talloc_free(tmp_ctx);
1555 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1556 struct auth_serversupplied_info *server_info,
1557 const char *sharename,
1558 uint32_t info2_mask,
1559 struct spoolss_SetPrinterInfo2 *info2,
1560 struct spoolss_DeviceMode *devmode,
1561 struct security_descriptor *secdesc)
1563 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1564 struct rpc_pipe_client *winreg_pipe = NULL;
1565 struct policy_handle hive_hnd, key_hnd;
1566 enum ndr_err_code ndr_err;
1569 WERROR result = WERR_OK;
1570 TALLOC_CTX *tmp_ctx;
1572 tmp_ctx = talloc_new(mem_ctx);
1573 if (tmp_ctx == NULL) {
1577 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1579 TALLOC_FREE(tmp_ctx);
1583 ZERO_STRUCT(hive_hnd);
1584 ZERO_STRUCT(key_hnd);
1586 result = winreg_printer_openkey(tmp_ctx,
1595 if (!W_ERROR_IS_OK(result)) {
1596 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1597 path, win_errstr(result)));
1601 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1602 result = winreg_printer_write_dword(tmp_ctx,
1607 if (!W_ERROR_IS_OK(result)) {
1613 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1614 result = winreg_printer_write_dword(tmp_ctx,
1619 if (!W_ERROR_IS_OK(result)) {
1625 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1626 result = winreg_printer_write_sz(tmp_ctx,
1631 if (!W_ERROR_IS_OK(result)) {
1636 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1637 result = winreg_printer_write_sz(tmp_ctx,
1642 if (!W_ERROR_IS_OK(result)) {
1647 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1648 result = winreg_printer_write_dword(tmp_ctx,
1652 info2->defaultpriority);
1653 if (!W_ERROR_IS_OK(result)) {
1658 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1659 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, NULL, devmode,
1660 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1661 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1662 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1663 result = WERR_NOMEM;
1667 result = winreg_printer_write_binary(tmp_ctx,
1672 if (!W_ERROR_IS_OK(result)) {
1677 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1678 result = winreg_printer_write_sz(tmp_ctx,
1683 if (!W_ERROR_IS_OK(result)) {
1688 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1689 result = winreg_printer_write_sz(tmp_ctx,
1694 if (!W_ERROR_IS_OK(result)) {
1699 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1700 result = winreg_printer_write_sz(tmp_ctx,
1705 if (!W_ERROR_IS_OK(result)) {
1710 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1711 result = winreg_printer_write_sz(tmp_ctx,
1716 if (!W_ERROR_IS_OK(result)) {
1721 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1723 * in addprinter: no servername and the printer is the name
1724 * in setprinter: servername is \\server
1725 * and printer is \\server\\printer
1727 * Samba manages only local printers.
1728 * we currently don't support things like i
1729 * path=\\other_server\printer
1731 * We only store the printername, not \\server\printername
1733 const char *p = strrchr(info2->printername, '\\');
1735 p = info2->printername;
1739 result = winreg_printer_write_sz(tmp_ctx,
1744 if (!W_ERROR_IS_OK(result)) {
1749 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1750 result = winreg_printer_write_sz(tmp_ctx,
1754 info2->printprocessor);
1755 if (!W_ERROR_IS_OK(result)) {
1760 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1761 result = winreg_printer_write_dword(tmp_ctx,
1766 if (!W_ERROR_IS_OK(result)) {
1771 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1773 * We need a security descriptor, if it isn't specified by
1774 * AddPrinter{Ex} then create a default descriptor.
1776 if (secdesc == NULL) {
1777 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1778 if (!W_ERROR_IS_OK(result)) {
1782 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, NULL, secdesc,
1783 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
1784 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1785 DEBUG(0, ("winreg_update_printer: Failed to marshall security descriptor\n"));
1786 result = WERR_NOMEM;
1790 result = winreg_printer_write_binary(tmp_ctx,
1795 if (!W_ERROR_IS_OK(result)) {
1800 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1801 result = winreg_printer_write_sz(tmp_ctx,
1806 if (!W_ERROR_IS_OK(result)) {
1811 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1812 result = winreg_printer_write_sz(tmp_ctx,
1817 if (!W_ERROR_IS_OK(result)) {
1822 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1823 result = winreg_printer_write_dword(tmp_ctx,
1828 if (!W_ERROR_IS_OK(result)) {
1833 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1834 result = winreg_printer_write_dword(tmp_ctx,
1839 if (!W_ERROR_IS_OK(result)) {
1844 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1845 result = winreg_printer_write_dword(tmp_ctx,
1850 if (!W_ERROR_IS_OK(result)) {
1855 result = winreg_printer_write_dword(tmp_ctx,
1859 winreg_printer_rev_changeid());
1860 if (!W_ERROR_IS_OK(result)) {
1866 if (winreg_pipe != NULL) {
1867 if (is_valid_policy_hnd(&key_hnd)) {
1868 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1870 if (is_valid_policy_hnd(&hive_hnd)) {
1871 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1875 TALLOC_FREE(tmp_ctx);
1879 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1880 struct auth_serversupplied_info *server_info,
1881 const char *servername,
1882 const char *printer,
1883 struct spoolss_PrinterInfo2 **pinfo2)
1885 struct spoolss_PrinterInfo2 *info2;
1886 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1887 struct rpc_pipe_client *winreg_pipe = NULL;
1888 struct policy_handle hive_hnd, key_hnd;
1889 struct spoolss_PrinterEnumValues *enum_values = NULL;
1890 struct spoolss_PrinterEnumValues *v;
1891 enum ndr_err_code ndr_err;
1893 uint32_t num_values = 0;
1896 WERROR result = WERR_OK;
1897 TALLOC_CTX *tmp_ctx;
1899 tmp_ctx = talloc_new(mem_ctx);
1900 if (tmp_ctx == NULL) {
1904 path = winreg_printer_data_keyname(tmp_ctx, printer);
1906 TALLOC_FREE(tmp_ctx);
1910 result = winreg_printer_openkey(tmp_ctx,
1919 if (!W_ERROR_IS_OK(result)) {
1920 DEBUG(0, ("winreg_get_printer: Could not open key %s: %s\n",
1921 path, win_errstr(result)));
1925 result = winreg_printer_enumvalues(tmp_ctx,
1930 if (!W_ERROR_IS_OK(result)) {
1931 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1932 path, win_errstr(result)));
1936 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
1937 if (info2 == NULL) {
1938 result = WERR_NOMEM;
1942 info2->servername = EMPTY_STRING;
1943 info2->printername = EMPTY_STRING;
1944 info2->sharename = EMPTY_STRING;
1945 info2->portname = EMPTY_STRING;
1946 info2->drivername = EMPTY_STRING;
1947 info2->comment = EMPTY_STRING;
1948 info2->location = EMPTY_STRING;
1949 info2->sepfile = EMPTY_STRING;
1950 info2->printprocessor = EMPTY_STRING;
1951 info2->datatype = EMPTY_STRING;
1952 info2->parameters = EMPTY_STRING;
1954 if (servername != NULL && servername[0] != '\0') {
1955 info2->servername = talloc_asprintf(info2, "\\\\%s", servername);
1956 if (info2->servername == NULL) {
1957 result = WERR_NOMEM;
1962 for (i = 0; i < num_values; i++) {
1963 v = &enum_values[i];
1965 result = winreg_enumval_to_sz(info2,
1968 &info2->printername);
1969 if (W_ERROR_IS_OK(result) && info2->servername[0] != '\0') {
1970 char *p = talloc_asprintf(info2, "%s\\%s",
1972 info2->printername);
1974 result = WERR_NOMEM;
1976 info2->printername = p;
1978 CHECK_ERROR(result);
1980 result = winreg_enumval_to_sz(info2,
1984 CHECK_ERROR(result);
1986 result = winreg_enumval_to_sz(info2,
1990 CHECK_ERROR(result);
1992 result = winreg_enumval_to_sz(info2,
1996 CHECK_ERROR(result);
1998 result = winreg_enumval_to_sz(info2,
2002 CHECK_ERROR(result);
2004 result = winreg_enumval_to_sz(info2,
2008 CHECK_ERROR(result);
2010 result = winreg_enumval_to_sz(info2,
2013 &info2->printprocessor);
2014 CHECK_ERROR(result);
2016 result = winreg_enumval_to_sz(info2,
2020 CHECK_ERROR(result);
2022 result = winreg_enumval_to_sz(info2,
2025 &info2->parameters);
2026 CHECK_ERROR(result);
2028 result = winreg_enumval_to_sz(info2,
2031 &info2->drivername);
2032 CHECK_ERROR(result);
2034 result = winreg_enumval_to_dword(info2,
2037 &info2->attributes);
2038 CHECK_ERROR(result);
2040 result = winreg_enumval_to_dword(info2,
2044 CHECK_ERROR(result);
2046 result = winreg_enumval_to_dword(info2,
2049 &info2->defaultpriority);
2050 CHECK_ERROR(result);
2052 result = winreg_enumval_to_dword(info2,
2056 CHECK_ERROR(result);
2058 result = winreg_enumval_to_dword(info2,
2062 CHECK_ERROR(result);
2064 result = winreg_enumval_to_dword(info2,
2068 CHECK_ERROR(result);
2070 result = winreg_enumval_to_dword(info2,
2074 CHECK_ERROR(result);
2076 result = winreg_enumval_to_blob(info2,
2080 if (W_ERROR_IS_OK(result)) {
2081 info2->devmode = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
2082 if (info2->devmode == NULL) {
2083 result = WERR_NOMEM;
2086 ndr_err = ndr_pull_struct_blob(&blob,
2090 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
2091 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2092 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2093 result = WERR_NOMEM;
2097 CHECK_ERROR(result);
2099 result = winreg_enumval_to_blob(info2,
2103 if (W_ERROR_IS_OK(result)) {
2104 info2->secdesc = talloc_zero(mem_ctx, struct spoolss_security_descriptor);
2105 if (info2->secdesc == NULL) {
2106 result = WERR_NOMEM;
2109 ndr_err = ndr_pull_struct_blob(&blob,
2113 (ndr_pull_flags_fn_t) ndr_pull_security_descriptor);
2114 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2115 DEBUG(0, ("winreg_get_printer: Failed to unmarshall security descriptor\n"));
2116 result = WERR_NOMEM;
2120 CHECK_ERROR(result);
2123 if (!W_ERROR_IS_OK(result)) {
2124 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2127 win_errstr(result)));
2132 *pinfo2 = talloc_move(mem_ctx, &info2);
2137 if (winreg_pipe != NULL) {
2138 if (is_valid_policy_hnd(&key_hnd)) {
2139 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2141 if (is_valid_policy_hnd(&hive_hnd)) {
2142 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2146 TALLOC_FREE(tmp_ctx);
2150 /* Set printer data over the winreg pipe. */
2151 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2152 struct auth_serversupplied_info *server_info,
2153 const char *printer,
2156 enum winreg_Type type,
2160 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2161 struct rpc_pipe_client *winreg_pipe = NULL;
2162 struct policy_handle hive_hnd, key_hnd;
2163 struct winreg_String wvalue;
2165 WERROR result = WERR_OK;
2167 TALLOC_CTX *tmp_ctx;
2169 tmp_ctx = talloc_new(mem_ctx);
2170 if (tmp_ctx == NULL) {
2174 path = winreg_printer_data_keyname(tmp_ctx, printer);
2176 TALLOC_FREE(tmp_ctx);
2180 ZERO_STRUCT(hive_hnd);
2181 ZERO_STRUCT(key_hnd);
2183 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2184 key, value, access_mask, printer));
2185 result = winreg_printer_openkey(tmp_ctx,
2194 if (!W_ERROR_IS_OK(result)) {
2195 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2196 key, win_errstr(result)));
2200 wvalue.name = value;
2201 status = rpccli_winreg_SetValue(winreg_pipe,
2209 if (!NT_STATUS_IS_OK(status)) {
2210 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2211 value, nt_errstr(status)));
2212 if (!W_ERROR_IS_OK(result)) {
2215 result = ntstatus_to_werror(status);
2221 if (winreg_pipe != NULL) {
2222 if (is_valid_policy_hnd(&key_hnd)) {
2223 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2225 if (is_valid_policy_hnd(&hive_hnd)) {
2226 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2230 TALLOC_FREE(tmp_ctx);
2234 /* Get printer data over a winreg pipe. */
2235 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2236 struct auth_serversupplied_info *server_info,
2237 const char *printer,
2240 enum winreg_Type *type,
2242 uint32_t *data_size)
2244 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2245 struct rpc_pipe_client *winreg_pipe = NULL;
2246 struct policy_handle hive_hnd, key_hnd;
2247 struct winreg_String wvalue;
2248 enum winreg_Type type_in;
2251 uint32_t data_in_size = 0;
2252 uint32_t value_len = 0;
2253 WERROR result = WERR_OK;
2255 TALLOC_CTX *tmp_ctx;
2257 tmp_ctx = talloc_new(mem_ctx);
2258 if (tmp_ctx == NULL) {
2262 path = winreg_printer_data_keyname(tmp_ctx, printer);
2264 TALLOC_FREE(tmp_ctx);
2268 ZERO_STRUCT(hive_hnd);
2269 ZERO_STRUCT(key_hnd);
2271 result = winreg_printer_openkey(tmp_ctx,
2280 if (!W_ERROR_IS_OK(result)) {
2281 DEBUG(0, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2282 key, win_errstr(result)));
2286 wvalue.name = value;
2289 * call QueryValue once with data == NULL to get the
2290 * needed memory size to be allocated, then allocate
2291 * data buffer and call again.
2293 status = rpccli_winreg_QueryValue(winreg_pipe,
2302 if (!NT_STATUS_IS_OK(status)) {
2303 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2304 value, nt_errstr(status)));
2305 if (!W_ERROR_IS_OK(result)) {
2308 result = ntstatus_to_werror(status);
2312 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2313 if (data_in == NULL) {
2314 result = WERR_NOMEM;
2319 status = rpccli_winreg_QueryValue(winreg_pipe,
2328 if (!NT_STATUS_IS_OK(status)) {
2329 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2330 value, nt_errstr(status)));
2331 if (!W_ERROR_IS_OK(result)) {
2332 result = ntstatus_to_werror(status);
2338 *data_size = data_in_size;
2340 *data = talloc_move(mem_ctx, &data_in);
2345 if (winreg_pipe != NULL) {
2346 if (is_valid_policy_hnd(&key_hnd)) {
2347 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2349 if (is_valid_policy_hnd(&hive_hnd)) {
2350 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2354 TALLOC_FREE(tmp_ctx);
2358 /* Enumerate on the values of a given key and provide the data. */
2359 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2360 struct auth_serversupplied_info *server_info,
2361 const char *printer,
2363 uint32_t *pnum_values,
2364 struct spoolss_PrinterEnumValues **penum_values)
2366 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2367 struct rpc_pipe_client *winreg_pipe = NULL;
2368 struct policy_handle hive_hnd, key_hnd;
2370 struct spoolss_PrinterEnumValues *enum_values = NULL;
2371 uint32_t num_values = 0;
2373 WERROR result = WERR_OK;
2375 TALLOC_CTX *tmp_ctx;
2377 tmp_ctx = talloc_new(mem_ctx);
2378 if (tmp_ctx == NULL) {
2382 path = winreg_printer_data_keyname(tmp_ctx, printer);
2384 TALLOC_FREE(tmp_ctx);
2388 result = winreg_printer_openkey(tmp_ctx,
2397 if (!W_ERROR_IS_OK(result)) {
2398 DEBUG(0, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2399 key, win_errstr(result)));
2403 result = winreg_printer_enumvalues(tmp_ctx,
2408 if (!W_ERROR_IS_OK(result)) {
2409 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2410 key, win_errstr(result)));
2414 *pnum_values = num_values;
2416 *penum_values = talloc_move(mem_ctx, &enum_values);
2421 if (winreg_pipe != NULL) {
2422 if (is_valid_policy_hnd(&key_hnd)) {
2423 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2425 if (is_valid_policy_hnd(&hive_hnd)) {
2426 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2430 TALLOC_FREE(tmp_ctx);
2434 /* Delete printer data over a winreg pipe. */
2435 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2436 struct auth_serversupplied_info *server_info,
2437 const char *printer,
2441 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2442 struct rpc_pipe_client *winreg_pipe = NULL;
2443 struct policy_handle hive_hnd, key_hnd;
2444 struct winreg_String wvalue;
2446 WERROR result = WERR_OK;
2449 TALLOC_CTX *tmp_ctx;
2451 tmp_ctx = talloc_new(mem_ctx);
2452 if (tmp_ctx == NULL) {
2456 path = winreg_printer_data_keyname(tmp_ctx, printer);
2458 TALLOC_FREE(tmp_ctx);
2462 ZERO_STRUCT(hive_hnd);
2463 ZERO_STRUCT(key_hnd);
2465 result = winreg_printer_openkey(tmp_ctx,
2474 if (!W_ERROR_IS_OK(result)) {
2475 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2476 key, win_errstr(result)));
2480 wvalue.name = value;
2481 status = rpccli_winreg_DeleteValue(winreg_pipe,
2486 if (!NT_STATUS_IS_OK(status)) {
2487 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2488 value, nt_errstr(status)));
2489 if (!W_ERROR_IS_OK(result)) {
2492 result = ntstatus_to_werror(status);
2498 if (winreg_pipe != NULL) {
2499 if (is_valid_policy_hnd(&key_hnd)) {
2500 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2502 if (is_valid_policy_hnd(&hive_hnd)) {
2503 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2507 TALLOC_FREE(tmp_ctx);
2511 /* Enumerate on the subkeys of a given key and provide the data. */
2512 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2513 struct auth_serversupplied_info *server_info,
2514 const char *printer,
2516 uint32_t *pnum_subkeys,
2517 const char ***psubkeys)
2519 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2520 struct rpc_pipe_client *winreg_pipe = NULL;
2521 struct policy_handle hive_hnd, key_hnd;
2523 const char **subkeys = NULL;
2524 uint32_t num_subkeys = -1;
2526 WERROR result = WERR_OK;
2528 TALLOC_CTX *tmp_ctx;
2530 tmp_ctx = talloc_new(mem_ctx);
2531 if (tmp_ctx == NULL) {
2535 path = winreg_printer_data_keyname(tmp_ctx, printer);
2537 TALLOC_FREE(tmp_ctx);
2541 ZERO_STRUCT(hive_hnd);
2542 ZERO_STRUCT(key_hnd);
2544 result = winreg_printer_openkey(tmp_ctx,
2553 if (!W_ERROR_IS_OK(result)) {
2554 DEBUG(0, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2555 key, win_errstr(result)));
2559 result = winreg_printer_enumkeys(tmp_ctx,
2564 if (!W_ERROR_IS_OK(result)) {
2565 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2566 key, win_errstr(result)));
2570 *pnum_subkeys = num_subkeys;
2572 *psubkeys = talloc_move(mem_ctx, &subkeys);
2577 if (winreg_pipe != NULL) {
2578 if (is_valid_policy_hnd(&key_hnd)) {
2579 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2581 if (is_valid_policy_hnd(&hive_hnd)) {
2582 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2586 TALLOC_FREE(tmp_ctx);
2590 /* Delete a key with subkeys of a given printer. */
2591 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
2592 struct auth_serversupplied_info *server_info,
2593 const char *printer,
2596 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2597 struct rpc_pipe_client *winreg_pipe = NULL;
2598 struct policy_handle hive_hnd, key_hnd;
2602 TALLOC_CTX *tmp_ctx;
2604 tmp_ctx = talloc_new(mem_ctx);
2605 if (tmp_ctx == NULL) {
2609 path = winreg_printer_data_keyname(tmp_ctx, printer);
2611 TALLOC_FREE(tmp_ctx);
2615 result = winreg_printer_openkey(tmp_ctx,
2624 if (!W_ERROR_IS_OK(result)) {
2625 /* key doesn't exist */
2626 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2631 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2632 key, win_errstr(result)));
2636 if (is_valid_policy_hnd(&key_hnd)) {
2637 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2640 if (key == NULL || key[0] == '\0') {
2643 keyname = talloc_asprintf(tmp_ctx,
2647 if (keyname == NULL) {
2648 result = WERR_NOMEM;
2653 result = winreg_printer_delete_subkeys(tmp_ctx,
2658 if (!W_ERROR_IS_OK(result)) {
2659 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2660 key, win_errstr(result)));
2665 if (winreg_pipe != NULL) {
2666 if (is_valid_policy_hnd(&key_hnd)) {
2667 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2669 if (is_valid_policy_hnd(&hive_hnd)) {
2670 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2674 TALLOC_FREE(tmp_ctx);
2678 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
2679 struct auth_serversupplied_info *server_info,
2680 const char *printer)
2682 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2683 struct rpc_pipe_client *winreg_pipe = NULL;
2684 struct policy_handle hive_hnd, key_hnd;
2687 TALLOC_CTX *tmp_ctx;
2689 tmp_ctx = talloc_new(mem_ctx);
2690 if (tmp_ctx == NULL) {
2694 path = winreg_printer_data_keyname(tmp_ctx, printer);
2696 TALLOC_FREE(tmp_ctx);
2700 ZERO_STRUCT(hive_hnd);
2701 ZERO_STRUCT(key_hnd);
2703 result = winreg_printer_openkey(tmp_ctx,
2712 if (!W_ERROR_IS_OK(result)) {
2713 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2714 path, win_errstr(result)));
2718 result = winreg_printer_write_dword(tmp_ctx,
2722 winreg_printer_rev_changeid());
2723 if (!W_ERROR_IS_OK(result)) {
2729 if (winreg_pipe != NULL) {
2730 if (is_valid_policy_hnd(&key_hnd)) {
2731 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2733 if (is_valid_policy_hnd(&hive_hnd)) {
2734 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2738 TALLOC_FREE(tmp_ctx);
2742 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
2743 struct auth_serversupplied_info *server_info,
2744 const char *printer,
2745 uint32_t *pchangeid)
2747 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2748 struct rpc_pipe_client *winreg_pipe = NULL;
2749 struct policy_handle hive_hnd, key_hnd;
2750 uint32_t changeid = 0;
2753 TALLOC_CTX *tmp_ctx;
2755 tmp_ctx = talloc_new(mem_ctx);
2756 if (tmp_ctx == NULL) {
2760 path = winreg_printer_data_keyname(tmp_ctx, printer);
2762 TALLOC_FREE(tmp_ctx);
2766 ZERO_STRUCT(hive_hnd);
2767 ZERO_STRUCT(key_hnd);
2769 result = winreg_printer_openkey(tmp_ctx,
2778 if (!W_ERROR_IS_OK(result)) {
2779 DEBUG(0, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2780 path, win_errstr(result)));
2784 DEBUG(0, ("winreg_printer_get_changeid: get changeid from %s\n", path));
2785 result = winreg_printer_query_dword(tmp_ctx,
2790 if (!W_ERROR_IS_OK(result)) {
2795 *pchangeid = changeid;
2800 if (winreg_pipe != NULL) {
2801 if (is_valid_policy_hnd(&key_hnd)) {
2802 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2804 if (is_valid_policy_hnd(&hive_hnd)) {
2805 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2809 TALLOC_FREE(tmp_ctx);
2814 * The special behaviour of the spoolss forms is documented at the website:
2816 * Managing Win32 Printserver Forms
2817 * http://unixwiz.net/techtips/winspooler-forms.html
2820 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
2821 struct auth_serversupplied_info *server_info,
2822 struct spoolss_AddFormInfo1 *form)
2824 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2825 struct rpc_pipe_client *winreg_pipe = NULL;
2826 struct policy_handle hive_hnd, key_hnd;
2827 struct winreg_String wvalue;
2829 uint32_t num_info = 0;
2830 union spoolss_FormInfo *info = NULL;
2834 TALLOC_CTX *tmp_ctx;
2836 tmp_ctx = talloc_new(mem_ctx);
2837 if (tmp_ctx == NULL) {
2841 ZERO_STRUCT(hive_hnd);
2842 ZERO_STRUCT(key_hnd);
2844 result = winreg_printer_openkey(tmp_ctx,
2847 TOP_LEVEL_CONTROL_FORMS_KEY,
2853 if (!W_ERROR_IS_OK(result)) {
2854 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2855 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2859 result = winreg_printer_enumforms1(tmp_ctx, server_info, &num_info, &info);
2860 if (!W_ERROR_IS_OK(result)) {
2861 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2862 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2866 /* If form name already exists or is builtin return ALREADY_EXISTS */
2867 for (i = 0; i < num_info; i++) {
2868 if (strequal(info[i].info1.form_name, form->form_name)) {
2869 result = WERR_FILE_EXISTS;
2874 wvalue.name = form->form_name;
2876 blob = data_blob_talloc(tmp_ctx, NULL, 32);
2877 SIVAL(blob.data, 0, form->size.width);
2878 SIVAL(blob.data, 4, form->size.height);
2879 SIVAL(blob.data, 8, form->area.left);
2880 SIVAL(blob.data, 12, form->area.top);
2881 SIVAL(blob.data, 16, form->area.right);
2882 SIVAL(blob.data, 20, form->area.bottom);
2883 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
2884 SIVAL(blob.data, 28, form->flags);
2886 status = rpccli_winreg_SetValue(winreg_pipe,
2894 if (!NT_STATUS_IS_OK(status)) {
2895 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2896 wvalue.name, nt_errstr(status)));
2897 if (!W_ERROR_IS_OK(result)) {
2900 result = ntstatus_to_werror(status);
2906 if (winreg_pipe != NULL) {
2907 if (is_valid_policy_hnd(&key_hnd)) {
2908 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2910 if (is_valid_policy_hnd(&hive_hnd)) {
2911 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2916 TALLOC_FREE(tmp_ctx);
2920 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
2921 struct auth_serversupplied_info *server_info,
2922 uint32_t *pnum_info,
2923 union spoolss_FormInfo **pinfo)
2925 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2926 struct rpc_pipe_client *winreg_pipe = NULL;
2927 struct policy_handle hive_hnd, key_hnd;
2928 union spoolss_FormInfo *info;
2929 struct spoolss_PrinterEnumValues *enum_values = NULL;
2930 uint32_t num_values = 0;
2931 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
2934 TALLOC_CTX *tmp_ctx;
2936 tmp_ctx = talloc_new(mem_ctx);
2937 if (tmp_ctx == NULL) {
2941 ZERO_STRUCT(hive_hnd);
2942 ZERO_STRUCT(key_hnd);
2944 result = winreg_printer_openkey(tmp_ctx,
2947 TOP_LEVEL_CONTROL_FORMS_KEY,
2953 if (!W_ERROR_IS_OK(result)) {
2954 /* key doesn't exist */
2955 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2960 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
2961 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2965 result = winreg_printer_enumvalues(tmp_ctx,
2970 if (!W_ERROR_IS_OK(result)) {
2971 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2972 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2976 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
2978 result = WERR_NOMEM;
2982 /* Enumerate BUILTIN forms */
2983 for (i = 0; i < num_builtin; i++) {
2984 info[i].info1 = builtin_forms1[i];
2987 /* Enumerate registry forms */
2988 for (i = 0; i < num_values; i++) {
2989 union spoolss_FormInfo val;
2991 if (enum_values[i].type != REG_BINARY ||
2992 enum_values[i].data_length != 32) {
2996 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
2997 if (val.info1.form_name == NULL) {
2998 result = WERR_NOMEM;
3002 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3003 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3004 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3005 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3006 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3007 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3008 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3009 val.info1.flags = IVAL(enum_values[i].data->data, 28);
3011 info[i + num_builtin] = val;
3014 *pnum_info = num_builtin + num_values;
3016 *pinfo = talloc_move(mem_ctx, &info);
3020 if (winreg_pipe != NULL) {
3021 if (is_valid_policy_hnd(&key_hnd)) {
3022 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3024 if (is_valid_policy_hnd(&hive_hnd)) {
3025 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3029 TALLOC_FREE(enum_values);
3030 TALLOC_FREE(tmp_ctx);
3034 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3035 struct auth_serversupplied_info *server_info,
3036 const char *form_name)
3038 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3039 struct rpc_pipe_client *winreg_pipe = NULL;
3040 struct policy_handle hive_hnd, key_hnd;
3041 struct winreg_String wvalue;
3042 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3044 WERROR result = WERR_OK;
3046 TALLOC_CTX *tmp_ctx;
3048 for (i = 0; i < num_builtin; i++) {
3049 if (strequal(builtin_forms1[i].form_name, form_name)) {
3050 return WERR_INVALID_PARAMETER;
3054 tmp_ctx = talloc_new(mem_ctx);
3055 if (tmp_ctx == NULL) {
3059 ZERO_STRUCT(hive_hnd);
3060 ZERO_STRUCT(key_hnd);
3062 result = winreg_printer_openkey(tmp_ctx,
3065 TOP_LEVEL_CONTROL_FORMS_KEY,
3071 if (!W_ERROR_IS_OK(result)) {
3072 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3073 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3074 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3075 result = WERR_INVALID_FORM_NAME;
3080 wvalue.name = form_name;
3081 status = rpccli_winreg_DeleteValue(winreg_pipe,
3086 if (!NT_STATUS_IS_OK(status)) {
3087 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3088 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3089 result = WERR_INVALID_FORM_NAME;
3092 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3093 wvalue.name, nt_errstr(status)));
3094 if (!W_ERROR_IS_OK(result)) {
3097 result = ntstatus_to_werror(status);
3103 if (winreg_pipe != NULL) {
3104 if (is_valid_policy_hnd(&key_hnd)) {
3105 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3107 if (is_valid_policy_hnd(&hive_hnd)) {
3108 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3112 TALLOC_FREE(tmp_ctx);
3116 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3117 struct auth_serversupplied_info *server_info,
3118 const char *form_name,
3119 struct spoolss_AddFormInfo1 *form)
3121 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3122 struct rpc_pipe_client *winreg_pipe = NULL;
3123 struct policy_handle hive_hnd, key_hnd;
3124 struct winreg_String wvalue;
3126 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3130 TALLOC_CTX *tmp_ctx = NULL;
3132 for (i = 0; i < num_builtin; i++) {
3133 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3134 result = WERR_INVALID_PARAM;
3139 tmp_ctx = talloc_new(mem_ctx);
3140 if (tmp_ctx == NULL) {
3144 ZERO_STRUCT(hive_hnd);
3145 ZERO_STRUCT(key_hnd);
3147 result = winreg_printer_openkey(tmp_ctx,
3150 TOP_LEVEL_CONTROL_FORMS_KEY,
3156 if (!W_ERROR_IS_OK(result)) {
3157 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3158 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3162 /* If form_name != form->form_name then we renamed the form */
3163 if (strequal(form_name, form->form_name)) {
3164 result = winreg_printer_deleteform1(tmp_ctx, server_info, form_name);
3165 if (!W_ERROR_IS_OK(result)) {
3166 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3167 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3172 wvalue.name = form->form_name;
3174 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3175 SIVAL(blob.data, 0, form->size.width);
3176 SIVAL(blob.data, 4, form->size.height);
3177 SIVAL(blob.data, 8, form->area.left);
3178 SIVAL(blob.data, 12, form->area.top);
3179 SIVAL(blob.data, 16, form->area.right);
3180 SIVAL(blob.data, 20, form->area.bottom);
3181 SIVAL(blob.data, 24, 42);
3182 SIVAL(blob.data, 28, form->flags);
3184 status = rpccli_winreg_SetValue(winreg_pipe,
3192 if (!NT_STATUS_IS_OK(status)) {
3193 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3194 wvalue.name, nt_errstr(status)));
3195 if (!W_ERROR_IS_OK(result)) {
3198 result = ntstatus_to_werror(status);
3204 if (winreg_pipe != NULL) {
3205 if (is_valid_policy_hnd(&key_hnd)) {
3206 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3208 if (is_valid_policy_hnd(&hive_hnd)) {
3209 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3213 TALLOC_FREE(tmp_ctx);
3217 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3218 struct auth_serversupplied_info *server_info,
3219 const char *form_name,
3220 struct spoolss_FormInfo1 *r)
3222 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3223 struct rpc_pipe_client *winreg_pipe = NULL;
3224 struct policy_handle hive_hnd, key_hnd;
3225 struct winreg_String wvalue;
3226 enum winreg_Type type_in;
3228 uint32_t data_in_size = 0;
3229 uint32_t value_len = 0;
3230 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3234 TALLOC_CTX *tmp_ctx;
3236 /* check builtin forms first */
3237 for (i = 0; i < num_builtin; i++) {
3238 if (strequal(builtin_forms1[i].form_name, form_name)) {
3239 *r = builtin_forms1[i];
3244 tmp_ctx = talloc_new(mem_ctx);
3245 if (tmp_ctx == NULL) {
3249 ZERO_STRUCT(hive_hnd);
3250 ZERO_STRUCT(key_hnd);
3252 result = winreg_printer_openkey(tmp_ctx,
3255 TOP_LEVEL_CONTROL_FORMS_KEY,
3261 if (!W_ERROR_IS_OK(result)) {
3262 DEBUG(0, ("winreg_printer_getform1: Could not open key %s: %s\n",
3263 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3267 wvalue.name = form_name;
3270 * call QueryValue once with data == NULL to get the
3271 * needed memory size to be allocated, then allocate
3272 * data buffer and call again.
3274 status = rpccli_winreg_QueryValue(winreg_pipe,
3283 if (!NT_STATUS_IS_OK(status)) {
3284 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3285 wvalue.name, nt_errstr(status)));
3286 if (!W_ERROR_IS_OK(result)) {
3289 result = ntstatus_to_werror(status);
3293 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3294 if (data_in == NULL) {
3295 result = WERR_NOMEM;
3300 status = rpccli_winreg_QueryValue(winreg_pipe,
3309 if (!NT_STATUS_IS_OK(status)) {
3310 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3311 wvalue.name, nt_errstr(status)));
3312 if (!W_ERROR_IS_OK(result)) {
3315 result = ntstatus_to_werror(status);
3319 r->form_name = talloc_strdup(mem_ctx, form_name);
3320 if (r->form_name == NULL) {
3321 result = WERR_NOMEM;
3325 r->size.width = IVAL(data_in, 0);
3326 r->size.height = IVAL(data_in, 4);
3327 r->area.left = IVAL(data_in, 8);
3328 r->area.top = IVAL(data_in, 12);
3329 r->area.right = IVAL(data_in, 16);
3330 r->area.bottom = IVAL(data_in, 20);
3331 /* skip index IVAL(data_in, 24)));*/
3332 r->flags = IVAL(data_in, 28);
3336 if (winreg_pipe != NULL) {
3337 if (is_valid_policy_hnd(&key_hnd)) {
3338 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3340 if (is_valid_policy_hnd(&hive_hnd)) {
3341 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3345 TALLOC_FREE(tmp_ctx);
3349 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3350 struct auth_serversupplied_info *server_info,
3351 struct spoolss_AddDriverInfoCtr *r,
3352 const char **driver_name,
3353 uint32_t *driver_version)
3355 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3356 struct rpc_pipe_client *winreg_pipe = NULL;
3357 struct policy_handle hive_hnd, key_hnd;
3358 struct spoolss_DriverInfo8 info8;
3359 TALLOC_CTX *tmp_ctx = NULL;
3362 ZERO_STRUCT(hive_hnd);
3363 ZERO_STRUCT(key_hnd);
3366 if (!driver_info_ctr_to_info8(r, &info8)) {
3367 result = WERR_INVALID_PARAMETER;
3371 tmp_ctx = talloc_new(mem_ctx);
3372 if (tmp_ctx == NULL) {
3376 result = winreg_printer_opendriver(tmp_ctx,
3385 if (!W_ERROR_IS_OK(result)) {
3386 DEBUG(0, ("winreg_add_driver: "
3387 "Could not open driver key (%s,%s,%d): %s\n",
3388 info8.driver_name, info8.architecture,
3389 info8.version, win_errstr(result)));
3393 /* TODO: "Attributes" ? */
3395 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe,
3396 &key_hnd, "Version",
3398 if (!W_ERROR_IS_OK(result)) {
3402 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3405 if (!W_ERROR_IS_OK(result)) {
3409 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3410 &key_hnd, "Data File",
3412 if (!W_ERROR_IS_OK(result)) {
3416 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3417 &key_hnd, "Configuration File",
3419 if (!W_ERROR_IS_OK(result)) {
3423 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3424 &key_hnd, "Help File",
3426 if (!W_ERROR_IS_OK(result)) {
3430 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3431 &key_hnd, "Dependent Files",
3432 info8.dependent_files);
3433 if (!W_ERROR_IS_OK(result)) {
3437 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3438 &key_hnd, "Monitor",
3439 info8.monitor_name);
3440 if (!W_ERROR_IS_OK(result)) {
3444 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3445 &key_hnd, "Datatype",
3446 info8.default_datatype);
3447 if (!W_ERROR_IS_OK(result)) {
3451 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3452 &key_hnd, "Previous Names",
3453 info8.previous_names);
3454 if (!W_ERROR_IS_OK(result)) {
3458 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3459 &key_hnd, "DriverDate",
3461 if (!W_ERROR_IS_OK(result)) {
3465 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe,
3466 &key_hnd, "DriverVersion",
3467 info8.driver_version);
3468 if (!W_ERROR_IS_OK(result)) {
3472 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3473 &key_hnd, "Manufacturer",
3474 info8.manufacturer_name);
3475 if (!W_ERROR_IS_OK(result)) {
3479 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3480 &key_hnd, "OEM URL",
3481 info8.manufacturer_url);
3482 if (!W_ERROR_IS_OK(result)) {
3486 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3487 &key_hnd, "HardwareID",
3489 if (!W_ERROR_IS_OK(result)) {
3493 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3494 &key_hnd, "Provider",
3496 if (!W_ERROR_IS_OK(result)) {
3500 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3501 &key_hnd, "Print Processor",
3502 info8.print_processor);
3503 if (!W_ERROR_IS_OK(result)) {
3507 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3508 &key_hnd, "VendorSetup",
3509 info8.vendor_setup);
3510 if (!W_ERROR_IS_OK(result)) {
3514 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3515 &key_hnd, "Color Profiles",
3516 info8.color_profiles);
3517 if (!W_ERROR_IS_OK(result)) {
3521 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3522 &key_hnd, "InfPath",
3524 if (!W_ERROR_IS_OK(result)) {
3528 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe, &key_hnd,
3529 "PrinterDriverAttributes",
3530 info8.printer_driver_attributes);
3531 if (!W_ERROR_IS_OK(result)) {
3535 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3536 &key_hnd, "CoreDependencies",
3537 info8.core_driver_dependencies);
3538 if (!W_ERROR_IS_OK(result)) {
3542 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3543 &key_hnd, "MinInboxDriverVerDate",
3544 info8.min_inbox_driver_ver_date);
3545 if (!W_ERROR_IS_OK(result)) {
3549 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe, &key_hnd,
3550 "MinInboxDriverVerVersion",
3551 info8.min_inbox_driver_ver_version);
3552 if (!W_ERROR_IS_OK(result)) {
3556 *driver_name = info8.driver_name;
3557 *driver_version = info8.version;
3560 if (winreg_pipe != NULL) {
3561 if (is_valid_policy_hnd(&key_hnd)) {
3562 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3564 if (is_valid_policy_hnd(&hive_hnd)) {
3565 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3569 TALLOC_FREE(tmp_ctx);
3573 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
3574 struct auth_serversupplied_info *server_info,
3575 const char *architecture,
3576 const char *driver_name,
3577 uint32_t driver_version,
3578 struct spoolss_DriverInfo8 **_info8)
3580 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3581 struct rpc_pipe_client *winreg_pipe = NULL;
3582 struct policy_handle hive_hnd, key_hnd;
3583 struct spoolss_DriverInfo8 i8, *info8;
3584 struct spoolss_PrinterEnumValues *enum_values = NULL;
3585 struct spoolss_PrinterEnumValues *v;
3586 uint32_t num_values = 0;
3587 TALLOC_CTX *tmp_ctx;
3591 ZERO_STRUCT(hive_hnd);
3592 ZERO_STRUCT(key_hnd);
3595 tmp_ctx = talloc_new(mem_ctx);
3596 if (tmp_ctx == NULL) {
3600 if (driver_version == DRIVER_ANY_VERSION) {
3601 /* look for Win2k first and then for NT4 */
3602 result = winreg_printer_opendriver(tmp_ctx,
3611 if (!W_ERROR_IS_OK(result)) {
3612 result = winreg_printer_opendriver(tmp_ctx,
3623 /* ok normal case */
3624 result = winreg_printer_opendriver(tmp_ctx,
3634 if (!W_ERROR_IS_OK(result)) {
3635 DEBUG(5, ("winreg_get_driver: "
3636 "Could not open driver key (%s,%s,%d): %s\n",
3637 driver_name, architecture,
3638 driver_version, win_errstr(result)));
3642 result = winreg_printer_enumvalues(tmp_ctx,
3647 if (!W_ERROR_IS_OK(result)) {
3648 DEBUG(0, ("winreg_get_driver: "
3649 "Could not enumerate values for (%s,%s,%d): %s\n",
3650 driver_name, architecture,
3651 driver_version, win_errstr(result)));
3655 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
3656 if (info8 == NULL) {
3657 result = WERR_NOMEM;
3661 info8->driver_name = talloc_strdup(info8, driver_name);
3662 if (info8->driver_name == NULL) {
3663 result = WERR_NOMEM;
3667 info8->architecture = talloc_strdup(info8, architecture);
3668 if (info8->architecture == NULL) {
3669 result = WERR_NOMEM;
3673 info8->config_file = EMPTY_STRING;
3674 info8->data_file = EMPTY_STRING;
3675 info8->default_datatype = EMPTY_STRING;
3676 info8->driver_path = EMPTY_STRING;
3677 info8->hardware_id = EMPTY_STRING;
3678 info8->help_file = EMPTY_STRING;
3679 info8->inf_path = EMPTY_STRING;
3680 info8->manufacturer_name = EMPTY_STRING;
3681 info8->manufacturer_url = EMPTY_STRING;
3682 info8->monitor_name = EMPTY_STRING;
3683 info8->print_processor = EMPTY_STRING;
3684 info8->provider = EMPTY_STRING;
3685 info8->vendor_setup = EMPTY_STRING;
3687 info8->color_profiles = empty_string_array;
3688 info8->core_driver_dependencies = EMPTY_STRING_ARRAY;
3689 info8->dependent_files = EMPTY_STRING_ARRAY;
3690 info8->previous_names = EMPTY_STRING_ARRAY;
3694 for (i = 0; i < num_values; i++) {
3695 const char *tmp_str;
3697 v = &enum_values[i];
3699 result = winreg_enumval_to_dword(info8, v,
3702 CHECK_ERROR(result);
3704 result = winreg_enumval_to_sz(info8, v,
3706 &info8->driver_path);
3707 CHECK_ERROR(result);
3709 result = winreg_enumval_to_sz(info8, v,
3712 CHECK_ERROR(result);
3714 result = winreg_enumval_to_sz(info8, v,
3715 "Configuration File",
3716 &info8->config_file);
3717 CHECK_ERROR(result);
3719 result = winreg_enumval_to_sz(info8, v,
3722 CHECK_ERROR(result);
3724 result = winreg_enumval_to_multi_sz(info8, v,
3726 &info8->dependent_files);
3727 CHECK_ERROR(result);
3729 result = winreg_enumval_to_sz(info8, v,
3731 &info8->monitor_name);
3732 CHECK_ERROR(result);
3734 result = winreg_enumval_to_sz(info8, v,
3736 &info8->default_datatype);
3737 CHECK_ERROR(result);
3739 result = winreg_enumval_to_multi_sz(info8, v,
3741 &info8->previous_names);
3742 CHECK_ERROR(result);
3744 result = winreg_enumval_to_sz(info8, v,
3747 if (W_ERROR_IS_OK(result)) {
3748 result = winreg_printer_date_to_NTTIME(tmp_str,
3749 &info8->driver_date);
3751 CHECK_ERROR(result);
3753 result = winreg_enumval_to_sz(info8, v,
3756 if (W_ERROR_IS_OK(result)) {
3757 result = winreg_printer_ver_to_dword(tmp_str,
3758 &info8->driver_version);
3760 CHECK_ERROR(result);
3762 result = winreg_enumval_to_sz(info8, v,
3764 &info8->manufacturer_name);
3765 CHECK_ERROR(result);
3767 result = winreg_enumval_to_sz(info8, v,
3769 &info8->manufacturer_url);
3770 CHECK_ERROR(result);
3772 result = winreg_enumval_to_sz(info8, v,
3774 &info8->hardware_id);
3775 CHECK_ERROR(result);
3777 result = winreg_enumval_to_sz(info8, v,
3780 CHECK_ERROR(result);
3782 result = winreg_enumval_to_sz(info8, v,
3784 &info8->print_processor);
3785 CHECK_ERROR(result);
3787 result = winreg_enumval_to_sz(info8, v,
3789 &info8->vendor_setup);
3790 CHECK_ERROR(result);
3792 result = winreg_enumval_to_multi_sz(info8, v,
3794 &info8->color_profiles);
3795 CHECK_ERROR(result);
3797 result = winreg_enumval_to_sz(info8, v,
3800 CHECK_ERROR(result);
3802 result = winreg_enumval_to_dword(info8, v,
3803 "PrinterDriverAttributes",
3804 &info8->printer_driver_attributes);
3805 CHECK_ERROR(result);
3807 result = winreg_enumval_to_multi_sz(info8, v,
3809 &info8->core_driver_dependencies);
3810 CHECK_ERROR(result);
3812 result = winreg_enumval_to_sz(info8, v,
3813 "MinInboxDriverVerDate",
3815 if (W_ERROR_IS_OK(result)) {
3816 result = winreg_printer_date_to_NTTIME(tmp_str,
3817 &info8->min_inbox_driver_ver_date);
3819 CHECK_ERROR(result);
3821 result = winreg_enumval_to_sz(info8, v,
3822 "MinInboxDriverVerVersion",
3824 if (W_ERROR_IS_OK(result)) {
3825 result = winreg_printer_ver_to_dword(tmp_str,
3826 &info8->min_inbox_driver_ver_version);
3828 CHECK_ERROR(result);
3831 if (!W_ERROR_IS_OK(result)) {
3832 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3833 "for %s: %s\n", v->value_name,
3834 win_errstr(result)));
3838 *_info8 = talloc_steal(mem_ctx, info8);
3841 if (winreg_pipe != NULL) {
3842 if (is_valid_policy_hnd(&key_hnd)) {
3843 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3845 if (is_valid_policy_hnd(&hive_hnd)) {
3846 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3850 TALLOC_FREE(tmp_ctx);
3854 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
3855 struct auth_serversupplied_info *server_info,
3856 struct spoolss_DriverInfo8 *info8,
3859 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3860 struct rpc_pipe_client *winreg_pipe = NULL;
3861 struct policy_handle hive_hnd, key_hnd;
3862 TALLOC_CTX *tmp_ctx;
3866 ZERO_STRUCT(hive_hnd);
3867 ZERO_STRUCT(key_hnd);
3869 tmp_ctx = talloc_new(mem_ctx);
3870 if (tmp_ctx == NULL) {
3874 /* test that the key exists */
3875 result = winreg_printer_opendriver(tmp_ctx,
3878 info8->architecture,
3884 if (!W_ERROR_IS_OK(result)) {
3885 /* key doesn't exist */
3886 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3891 DEBUG(5, ("winreg_del_driver: "
3892 "Could not open driver (%s,%s,%u): %s\n",
3893 info8->driver_name, info8->architecture,
3894 version, win_errstr(result)));
3899 if (is_valid_policy_hnd(&key_hnd)) {
3900 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3903 key_name = talloc_asprintf(tmp_ctx,
3904 "%s\\Environments\\%s\\Drivers\\Version-%u",
3905 TOP_LEVEL_CONTROL_KEY,
3906 info8->architecture, version);
3907 if (key_name == NULL) {
3908 result = WERR_NOMEM;
3912 result = winreg_printer_delete_subkeys(tmp_ctx,
3917 if (!W_ERROR_IS_OK(result)) {
3918 DEBUG(0, ("winreg_del_driver: "
3919 "Could not open driver (%s,%s,%u): %s\n",
3920 info8->driver_name, info8->architecture,
3921 version, win_errstr(result)));
3927 if (winreg_pipe != NULL) {
3928 if (is_valid_policy_hnd(&key_hnd)) {
3929 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3931 if (is_valid_policy_hnd(&hive_hnd)) {
3932 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3936 TALLOC_FREE(tmp_ctx);
3940 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
3941 struct auth_serversupplied_info *server_info,
3942 const char *architecture,
3944 uint32_t *num_drivers,
3945 const char ***drivers_p)
3947 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3948 struct rpc_pipe_client *winreg_pipe = NULL;
3949 struct policy_handle hive_hnd, key_hnd;
3950 const char **drivers;
3951 TALLOC_CTX *tmp_ctx;
3957 ZERO_STRUCT(hive_hnd);
3958 ZERO_STRUCT(key_hnd);
3960 tmp_ctx = talloc_new(mem_ctx);
3961 if (tmp_ctx == NULL) {
3965 /* use NULL for the driver name so we open the key that is
3966 * parent of all drivers for this architecture and version */
3967 result = winreg_printer_opendriver(tmp_ctx,
3976 if (!W_ERROR_IS_OK(result)) {
3977 DEBUG(5, ("winreg_get_driver_list: "
3978 "Could not open key (%s,%u): %s\n",
3979 architecture, version, win_errstr(result)));
3984 result = winreg_printer_enumkeys(tmp_ctx,
3989 if (!W_ERROR_IS_OK(result)) {
3990 DEBUG(0, ("winreg_get_driver_list: "
3991 "Could not enumerate drivers for (%s,%u): %s\n",
3992 architecture, version, win_errstr(result)));
3996 *drivers_p = talloc_steal(mem_ctx, drivers);
4000 if (winreg_pipe != NULL) {
4001 if (is_valid_policy_hnd(&key_hnd)) {
4002 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4004 if (is_valid_policy_hnd(&hive_hnd)) {
4005 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4009 TALLOC_FREE(tmp_ctx);