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 "nt_printing.h"
24 #include "../librpc/gen_ndr/ndr_spoolss.h"
25 #include "../librpc/gen_ndr/ndr_winreg_c.h"
26 #include "../librpc/gen_ndr/ndr_security.h"
28 #include "../libcli/security/security.h"
29 #include "rpc_client/cli_winreg.h"
30 #include "../libcli/registry/util_reg.h"
31 #include "rpc_client/cli_winreg_spoolss.h"
32 #include "printing/nt_printing_os2.h"
33 #include "rpc_client/init_spoolss.h"
35 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
36 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
37 #define TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY TOP_LEVEL_PRINT_KEY "\\PackageInstallation"
38 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
39 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
41 #define FILL_STRING(mem_ctx, in, out) \
43 if (in && strlen(in)) { \
44 out = talloc_strdup(mem_ctx, in); \
46 out = talloc_strdup(mem_ctx, ""); \
48 W_ERROR_HAVE_NO_MEMORY(out); \
51 #define CHECK_ERROR(result) \
52 if (W_ERROR_IS_OK(result)) continue; \
53 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
54 if (!W_ERROR_IS_OK(result)) break
56 /* FLAGS, NAME, with, height, left, top, right, bottom */
57 static const struct spoolss_FormInfo1 builtin_forms1[] = {
58 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
59 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
60 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
61 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
62 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
63 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
64 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
65 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
66 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
67 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
68 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
69 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
70 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
71 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
72 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
73 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
74 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
75 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
76 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
77 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
78 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
79 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
80 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
81 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
82 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
83 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
84 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
85 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
86 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
87 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
88 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
89 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
90 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
91 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
92 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
93 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
94 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
95 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
96 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} },
97 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
98 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
99 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
100 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
101 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
102 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
103 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
104 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
105 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
106 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
107 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
108 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
109 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
110 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
111 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
112 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
113 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
114 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
115 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
116 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
117 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
118 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
119 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
120 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
121 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
122 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
123 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
124 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
125 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
126 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
127 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
128 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
129 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
130 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
131 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
132 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
133 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
134 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
135 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
136 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
137 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
138 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
139 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
140 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
141 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
142 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
143 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
144 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
145 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
146 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
147 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
148 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
149 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
150 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
151 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
152 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
153 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
154 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
159 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
160 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
161 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
162 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
163 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
164 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
165 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
166 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
167 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
168 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
169 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
170 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
171 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
172 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
173 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
174 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
175 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} }
178 /********************************************************************
179 static helper functions
180 ********************************************************************/
182 /****************************************************************************
183 Update the changeid time.
184 ****************************************************************************/
188 * @brief Update the ChangeID time of a printer.
190 * This is SO NASTY as some drivers need this to change, others need it
191 * static. This value will change every second, and I must hope that this
192 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
195 * @return The ChangeID.
197 static uint32_t winreg_printer_rev_changeid(void)
201 get_process_uptime(&tv);
204 /* Return changeid as msec since spooler restart */
205 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
208 * This setting seems to work well but is too untested
209 * to replace the above calculation. Left in for experimentation
210 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
212 return tv.tv_sec * 10 + tv.tv_usec / 100000;
216 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
217 struct dcerpc_binding_handle *binding_handle,
221 uint32_t access_mask,
222 struct policy_handle *hive_handle,
223 struct policy_handle *key_handle)
225 struct winreg_String wkey, wkeyclass;
228 WERROR result = WERR_OK;
230 status = dcerpc_winreg_OpenHKLM(binding_handle,
236 if (!NT_STATUS_IS_OK(status)) {
237 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
239 return ntstatus_to_werror(status);
241 if (!W_ERROR_IS_OK(result)) {
242 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
243 win_errstr(result)));
248 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
250 keyname = talloc_strdup(mem_ctx, path);
252 if (keyname == NULL) {
253 return WERR_NOT_ENOUGH_MEMORY;
260 enum winreg_CreateAction action = REG_ACTION_NONE;
262 ZERO_STRUCT(wkeyclass);
265 status = dcerpc_winreg_CreateKey(binding_handle,
277 case REG_ACTION_NONE:
278 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
280 case REG_CREATED_NEW_KEY:
281 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
283 case REG_OPENED_EXISTING_KEY:
284 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
288 status = dcerpc_winreg_OpenKey(binding_handle,
297 if (!NT_STATUS_IS_OK(status)) {
298 result = ntstatus_to_werror(status);
300 if (!W_ERROR_IS_OK(result)) {
303 if (is_valid_policy_hnd(hive_handle)) {
304 dcerpc_winreg_CloseKey(binding_handle,
309 ZERO_STRUCTP(hive_handle);
317 static WERROR winreg_printer_open_core_driver(TALLOC_CTX *mem_ctx,
318 struct dcerpc_binding_handle *binding_handle,
319 const char *architecture,
321 uint32_t access_mask,
322 struct policy_handle *hive_handle,
323 struct policy_handle *key_handle)
325 struct winreg_String wkey, wkeyclass;
327 WERROR result = WERR_OK;
329 enum winreg_CreateAction action = REG_ACTION_NONE;
332 status = dcerpc_winreg_OpenHKLM(binding_handle,
338 if (!NT_STATUS_IS_OK(status)) {
339 DEBUG(0,("winreg_printer_open_core_driver: Could not open HKLM hive: %s\n",
341 return ntstatus_to_werror(status);
343 if (!W_ERROR_IS_OK(result)) {
344 DEBUG(0,("winreg_printer_open_core_driver: Could not open HKLM hive: %s\n",
345 win_errstr(result)));
350 wkey.name = TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY;
352 ZERO_STRUCT(wkeyclass);
355 status = dcerpc_winreg_CreateKey(binding_handle,
366 if (!NT_STATUS_IS_OK(status)) {
367 result = ntstatus_to_werror(status);
369 if (!W_ERROR_IS_OK(result)) {
373 dcerpc_winreg_CloseKey(binding_handle, mem_ctx, key_handle, &ignore);
375 path = talloc_asprintf(mem_ctx, "%s\\%s",
376 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
379 result = WERR_NOT_ENOUGH_MEMORY;
385 status = dcerpc_winreg_CreateKey(binding_handle,
396 if (!NT_STATUS_IS_OK(status)) {
397 result = ntstatus_to_werror(status);
399 if (!W_ERROR_IS_OK(result)) {
403 dcerpc_winreg_CloseKey(binding_handle, mem_ctx, key_handle, &ignore);
405 path = talloc_asprintf(mem_ctx, "%s\\%s\\CorePrinterDrivers",
406 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
409 result = WERR_NOT_ENOUGH_MEMORY;
415 status = dcerpc_winreg_CreateKey(binding_handle,
426 if (!NT_STATUS_IS_OK(status)) {
427 result = ntstatus_to_werror(status);
429 if (!W_ERROR_IS_OK(result)) {
433 dcerpc_winreg_CloseKey(binding_handle, mem_ctx, key_handle, &ignore);
435 path = talloc_asprintf(mem_ctx, "%s\\%s\\CorePrinterDrivers\\%s",
436 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
440 result = WERR_NOT_ENOUGH_MEMORY;
446 status = dcerpc_winreg_CreateKey(binding_handle,
457 if (!NT_STATUS_IS_OK(status)) {
458 result = ntstatus_to_werror(status);
460 if (!W_ERROR_IS_OK(result)) {
465 if (is_valid_policy_hnd(hive_handle)) {
466 dcerpc_winreg_CloseKey(binding_handle,
471 ZERO_STRUCTP(hive_handle);
477 * @brief Create the registry keyname for the given printer.
479 * @param[in] mem_ctx The memory context to use.
481 * @param[in] printer The name of the printer to get the registry key.
483 * @return The registry key or NULL on error.
485 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
486 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
489 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
490 struct dcerpc_binding_handle *winreg_handle,
491 const char *drivername,
492 const char *architecture,
494 uint32_t access_mask,
496 struct policy_handle *hive_hnd,
497 struct policy_handle *key_hnd)
502 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
503 TOP_LEVEL_CONTROL_KEY,
504 architecture, version);
506 return WERR_NOT_ENOUGH_MEMORY;
509 result = winreg_printer_openkey(mem_ctx,
520 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
521 struct spoolss_PrinterEnumValues *v,
522 const char *valuename, uint32_t *dw)
524 /* just return if it is not the one we are looking for */
525 if (strcmp(valuename, v->value_name) != 0) {
526 return WERR_NOT_FOUND;
529 if (v->type != REG_DWORD) {
530 return WERR_INVALID_DATATYPE;
533 if (v->data_length != 4) {
538 *dw = IVAL(v->data->data, 0);
542 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
543 struct spoolss_PrinterEnumValues *v,
544 const char *valuename, const char **_str)
546 /* just return if it is not the one we are looking for */
547 if (strcmp(valuename, v->value_name) != 0) {
548 return WERR_NOT_FOUND;
551 if (v->type != REG_SZ) {
552 return WERR_INVALID_DATATYPE;
555 if (v->data_length == 0) {
556 *_str = talloc_strdup(mem_ctx, "");
558 return WERR_NOT_ENOUGH_MEMORY;
563 if (!pull_reg_sz(mem_ctx, v->data, _str)) {
564 return WERR_NOT_ENOUGH_MEMORY;
570 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
571 struct spoolss_PrinterEnumValues *v,
572 const char *valuename,
575 /* just return if it is not the one we are looking for */
576 if (strcmp(valuename, v->value_name) != 0) {
577 return WERR_NOT_FOUND;
580 if (v->type != REG_MULTI_SZ) {
581 return WERR_INVALID_DATATYPE;
584 if (v->data_length == 0) {
585 *array = talloc_array(mem_ctx, const char *, 1);
586 if (*array == NULL) {
587 return WERR_NOT_ENOUGH_MEMORY;
593 if (!pull_reg_multi_sz(mem_ctx, v->data, array)) {
594 return WERR_NOT_ENOUGH_MEMORY;
600 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
601 struct dcerpc_binding_handle *winreg_handle,
602 struct policy_handle *key_handle,
606 struct winreg_String wvalue = { 0, };
608 WERROR result = WERR_OK;
615 str = talloc_strdup(mem_ctx, "01/01/1601");
617 t = nt_time_to_unix(data);
620 return map_werror_from_unix(errno);
622 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
623 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
626 return WERR_NOT_ENOUGH_MEMORY;
630 if (!push_reg_sz(mem_ctx, &blob, str)) {
631 return WERR_NOT_ENOUGH_MEMORY;
633 status = dcerpc_winreg_SetValue(winreg_handle,
641 if (!NT_STATUS_IS_OK(status)) {
642 result = ntstatus_to_werror(status);
644 if (!W_ERROR_IS_OK(result)) {
645 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
646 wvalue.name, win_errstr(result)));
652 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
656 ok = spoolss_timestr_to_NTTIME(str, data);
658 return WERR_INVALID_PARAMETER;
664 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
665 struct dcerpc_binding_handle *winreg_handle,
666 struct policy_handle *key_handle,
670 struct winreg_String wvalue = { 0, };
672 WERROR result = WERR_OK;
677 * this needs to be something like: 6.1.7600.16385
679 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
680 (unsigned)((data >> 48) & 0xFFFF),
681 (unsigned)((data >> 32) & 0xFFFF),
682 (unsigned)((data >> 16) & 0xFFFF),
683 (unsigned)(data & 0xFFFF));
685 return WERR_NOT_ENOUGH_MEMORY;
689 if (!push_reg_sz(mem_ctx, &blob, str)) {
690 return WERR_NOT_ENOUGH_MEMORY;
692 status = dcerpc_winreg_SetValue(winreg_handle,
700 if (!NT_STATUS_IS_OK(status)) {
701 result = ntstatus_to_werror(status);
703 if (!W_ERROR_IS_OK(result)) {
704 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
705 wvalue.name, win_errstr(result)));
711 static WERROR winreg_printer_ver_to_qword(const char *str, uint64_t *data)
715 ok = spoolss_driver_version_to_qword(str, data);
717 return WERR_INVALID_PARAMETER;
723 /********************************************************************
724 Public winreg function for spoolss
725 ********************************************************************/
727 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
728 struct dcerpc_binding_handle *winreg_handle,
729 const char *sharename)
731 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
732 struct policy_handle hive_hnd, key_hnd;
733 struct spoolss_SetPrinterInfo2 *info2;
734 struct security_descriptor *secdesc;
735 struct winreg_String wkey, wkeyclass;
737 const char *subkeys[] = { SPOOL_DSDRIVER_KEY, SPOOL_DSSPOOLER_KEY, SPOOL_PRINTERDATA_KEY };
738 uint32_t i, count = ARRAY_SIZE(subkeys);
739 uint32_t info2_mask = 0;
740 WERROR result = WERR_OK;
744 tmp_ctx = talloc_stackframe();
745 if (tmp_ctx == NULL) {
746 return WERR_NOT_ENOUGH_MEMORY;
749 path = winreg_printer_data_keyname(tmp_ctx, sharename);
751 TALLOC_FREE(tmp_ctx);
752 return WERR_NOT_ENOUGH_MEMORY;
755 ZERO_STRUCT(hive_hnd);
756 ZERO_STRUCT(key_hnd);
758 result = winreg_printer_openkey(tmp_ctx,
766 if (W_ERROR_IS_OK(result)) {
767 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
769 } else if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
770 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
771 } else if (!W_ERROR_IS_OK(result)) {
772 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
773 path, win_errstr(result)));
777 if (is_valid_policy_hnd(&key_hnd)) {
778 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
780 if (is_valid_policy_hnd(&hive_hnd)) {
781 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
784 /* Create the main key */
785 result = winreg_printer_openkey(tmp_ctx,
793 if (!W_ERROR_IS_OK(result)) {
794 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
795 path, win_errstr(result)));
799 if (is_valid_policy_hnd(&key_hnd)) {
800 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
804 for (i = 0; i < count; i++) {
806 enum winreg_CreateAction action = REG_ACTION_NONE;
808 ZERO_STRUCT(key_hnd);
811 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
812 if (wkey.name == NULL) {
813 result = WERR_NOT_ENOUGH_MEMORY;
817 ZERO_STRUCT(wkeyclass);
820 status = dcerpc_winreg_CreateKey(winreg_handle,
831 if (!NT_STATUS_IS_OK(status)) {
832 result = ntstatus_to_werror(status);
834 if (!W_ERROR_IS_OK(result)) {
835 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
836 wkey.name, win_errstr(result)));
840 if (strequal(subkeys[i], SPOOL_DSSPOOLER_KEY)) {
841 const char *dnssuffix;
842 const char *longname;
845 status = dcerpc_winreg_set_sz(tmp_ctx,
848 SPOOL_REG_PRINTERNAME,
851 if (!NT_STATUS_IS_OK(status)) {
852 result = ntstatus_to_werror(status);
854 if (!W_ERROR_IS_OK(result)) {
858 status = dcerpc_winreg_set_sz(tmp_ctx,
861 SPOOL_REG_PRINTSHARENAME,
864 if (!NT_STATUS_IS_OK(status)) {
865 result = ntstatus_to_werror(status);
867 if (!W_ERROR_IS_OK(result)) {
871 status = dcerpc_winreg_set_sz(tmp_ctx,
874 SPOOL_REG_SHORTSERVERNAME,
877 if (!NT_STATUS_IS_OK(status)) {
878 result = ntstatus_to_werror(status);
880 if (!W_ERROR_IS_OK(result)) {
884 /* We make the assumption that the netbios name
885 * is the same as the DNS name since the former
886 * will be what we used to join the domain
888 dnssuffix = get_mydnsdomname(tmp_ctx);
889 if (dnssuffix != NULL && dnssuffix[0] != '\0') {
890 longname = talloc_asprintf(tmp_ctx, "%s.%s", lp_netbios_name(), dnssuffix);
892 longname = talloc_strdup(tmp_ctx, lp_netbios_name());
894 if (longname == NULL) {
895 result = WERR_NOT_ENOUGH_MEMORY;
899 status = dcerpc_winreg_set_sz(tmp_ctx,
902 SPOOL_REG_SERVERNAME,
905 if (!NT_STATUS_IS_OK(status)) {
906 result = ntstatus_to_werror(status);
908 if (!W_ERROR_IS_OK(result)) {
912 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
913 longname, sharename);
914 if (uncname == NULL) {
915 result = WERR_NOT_ENOUGH_MEMORY;
919 status = dcerpc_winreg_set_sz(tmp_ctx,
925 if (!NT_STATUS_IS_OK(status)) {
926 result = ntstatus_to_werror(status);
928 if (!W_ERROR_IS_OK(result)) {
932 status = dcerpc_winreg_set_dword(tmp_ctx,
935 SPOOL_REG_VERSIONNUMBER,
938 if (!NT_STATUS_IS_OK(status)) {
939 result = ntstatus_to_werror(status);
941 if (!W_ERROR_IS_OK(result)) {
945 status = dcerpc_winreg_set_dword(tmp_ctx,
948 SPOOL_REG_PRINTSTARTTIME,
951 if (!NT_STATUS_IS_OK(status)) {
952 result = ntstatus_to_werror(status);
954 if (!W_ERROR_IS_OK(result)) {
958 status = dcerpc_winreg_set_dword(tmp_ctx,
961 SPOOL_REG_PRINTENDTIME,
964 if (!NT_STATUS_IS_OK(status)) {
965 result = ntstatus_to_werror(status);
967 if (!W_ERROR_IS_OK(result)) {
971 status = dcerpc_winreg_set_dword(tmp_ctx,
977 if (!NT_STATUS_IS_OK(status)) {
978 result = ntstatus_to_werror(status);
980 if (!W_ERROR_IS_OK(result)) {
984 status = dcerpc_winreg_set_dword(tmp_ctx,
987 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
990 if (!NT_STATUS_IS_OK(status)) {
991 result = ntstatus_to_werror(status);
993 if (!W_ERROR_IS_OK(result)) {
998 if (is_valid_policy_hnd(&key_hnd)) {
999 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
1002 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
1003 if (info2 == NULL) {
1004 result = WERR_NOT_ENOUGH_MEMORY;
1008 info2->printername = sharename;
1009 if (info2->printername == NULL) {
1010 result = WERR_NOT_ENOUGH_MEMORY;
1013 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1015 info2->sharename = sharename;
1016 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1018 info2->portname = SAMBA_PRINTER_PORT_NAME;
1019 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1021 info2->printprocessor = "winprint";
1022 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1024 info2->datatype = "RAW";
1025 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1027 info2->comment = "";
1028 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1030 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1031 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1033 info2->starttime = 0; /* Minutes since 12:00am GMT */
1034 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1036 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1037 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1039 info2->priority = 1;
1040 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1042 info2->defaultpriority = 1;
1043 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1045 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1046 if (!W_ERROR_IS_OK(result)) {
1049 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1052 * Don't write a default Device Mode to the registry! The Device Mode is
1053 * only written to disk with a SetPrinter level 2 or 8.
1056 result = winreg_update_printer(tmp_ctx,
1065 if (is_valid_policy_hnd(&key_hnd)) {
1066 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1068 if (is_valid_policy_hnd(&hive_hnd)) {
1069 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1072 talloc_free(tmp_ctx);
1076 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1077 struct dcerpc_binding_handle *winreg_handle,
1078 const char *sharename,
1079 uint32_t info2_mask,
1080 struct spoolss_SetPrinterInfo2 *info2,
1081 struct spoolss_DeviceMode *devmode,
1082 struct security_descriptor *secdesc)
1084 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1085 struct policy_handle hive_hnd, key_hnd;
1086 int snum = lp_servicenumber(sharename);
1087 enum ndr_err_code ndr_err;
1090 WERROR result = WERR_OK;
1093 TALLOC_CTX *tmp_ctx;
1095 tmp_ctx = talloc_stackframe();
1096 if (tmp_ctx == NULL) {
1097 return WERR_NOT_ENOUGH_MEMORY;
1100 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1102 TALLOC_FREE(tmp_ctx);
1103 return WERR_NOT_ENOUGH_MEMORY;
1106 ZERO_STRUCT(hive_hnd);
1107 ZERO_STRUCT(key_hnd);
1109 result = winreg_printer_openkey(tmp_ctx,
1117 if (!W_ERROR_IS_OK(result)) {
1118 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1119 path, win_errstr(result)));
1123 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1124 status = dcerpc_winreg_set_dword(tmp_ctx,
1130 if (!NT_STATUS_IS_OK(status)) {
1131 result = ntstatus_to_werror(status);
1133 if (!W_ERROR_IS_OK(result)) {
1139 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1140 status = dcerpc_winreg_set_dword(tmp_ctx,
1146 if (!NT_STATUS_IS_OK(status)) {
1147 result = ntstatus_to_werror(status);
1149 if (!W_ERROR_IS_OK(result)) {
1155 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1156 status = dcerpc_winreg_set_sz(tmp_ctx,
1162 if (!NT_STATUS_IS_OK(status)) {
1163 result = ntstatus_to_werror(status);
1165 if (!W_ERROR_IS_OK(result)) {
1170 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1171 status = dcerpc_winreg_set_sz(tmp_ctx,
1177 if (!NT_STATUS_IS_OK(status)) {
1178 result = ntstatus_to_werror(status);
1180 if (!W_ERROR_IS_OK(result)) {
1185 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1186 status = dcerpc_winreg_set_dword(tmp_ctx,
1190 info2->defaultpriority,
1192 if (!NT_STATUS_IS_OK(status)) {
1193 result = ntstatus_to_werror(status);
1195 if (!W_ERROR_IS_OK(result)) {
1200 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1202 * Some client drivers freak out if there is a NULL devmode
1203 * (probably the driver is not checking before accessing
1204 * the devmode pointer) --jerry
1206 if (devmode == NULL && lp_default_devmode(snum) && info2 != NULL) {
1207 result = spoolss_create_default_devmode(tmp_ctx,
1210 if (!W_ERROR_IS_OK(result)) {
1215 if (devmode->size != (ndr_size_spoolss_DeviceMode(devmode, 0) - devmode->__driverextra_length)) {
1216 result = WERR_INVALID_PARAMETER;
1220 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, devmode,
1221 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1222 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1223 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1224 result = WERR_NOT_ENOUGH_MEMORY;
1228 status = dcerpc_winreg_set_binary(tmp_ctx,
1234 if (!NT_STATUS_IS_OK(status)) {
1235 result = ntstatus_to_werror(status);
1237 if (!W_ERROR_IS_OK(result)) {
1242 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1243 status = dcerpc_winreg_set_sz(tmp_ctx,
1249 if (!NT_STATUS_IS_OK(status)) {
1250 result = ntstatus_to_werror(status);
1252 if (!W_ERROR_IS_OK(result)) {
1257 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1258 status = dcerpc_winreg_set_sz(tmp_ctx,
1264 if (!NT_STATUS_IS_OK(status)) {
1265 result = ntstatus_to_werror(status);
1267 if (!W_ERROR_IS_OK(result)) {
1272 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1273 status = dcerpc_winreg_set_sz(tmp_ctx,
1279 if (!NT_STATUS_IS_OK(status)) {
1280 result = ntstatus_to_werror(status);
1282 if (!W_ERROR_IS_OK(result)) {
1287 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1288 status = dcerpc_winreg_set_sz(tmp_ctx,
1294 if (!NT_STATUS_IS_OK(status)) {
1295 result = ntstatus_to_werror(status);
1297 if (!W_ERROR_IS_OK(result)) {
1302 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1304 * in addprinter: no servername and the printer is the name
1305 * in setprinter: servername is \\server
1306 * and printer is \\server\\printer
1308 * Samba manages only local printers.
1309 * we currently don't support things like i
1310 * path=\\other_server\printer
1312 * We only store the printername, not \\server\printername
1314 const char *p = strrchr(info2->printername, '\\');
1316 p = info2->printername;
1320 status = dcerpc_winreg_set_sz(tmp_ctx,
1326 if (!NT_STATUS_IS_OK(status)) {
1327 result = ntstatus_to_werror(status);
1329 if (!W_ERROR_IS_OK(result)) {
1334 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1335 status = dcerpc_winreg_set_sz(tmp_ctx,
1339 info2->printprocessor,
1341 if (!NT_STATUS_IS_OK(status)) {
1342 result = ntstatus_to_werror(status);
1344 if (!W_ERROR_IS_OK(result)) {
1349 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1350 status = dcerpc_winreg_set_dword(tmp_ctx,
1356 if (!NT_STATUS_IS_OK(status)) {
1357 result = ntstatus_to_werror(status);
1359 if (!W_ERROR_IS_OK(result)) {
1364 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1366 * We need a security descriptor, if it isn't specified by
1367 * AddPrinter{Ex} then create a default descriptor.
1369 if (secdesc == NULL) {
1370 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1371 if (!W_ERROR_IS_OK(result)) {
1375 result = winreg_set_printer_secdesc(tmp_ctx,
1379 if (!W_ERROR_IS_OK(result)) {
1384 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1385 status = dcerpc_winreg_set_sz(tmp_ctx,
1391 if (!NT_STATUS_IS_OK(status)) {
1392 result = ntstatus_to_werror(status);
1394 if (!W_ERROR_IS_OK(result)) {
1399 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1400 status = dcerpc_winreg_set_sz(tmp_ctx,
1406 if (!NT_STATUS_IS_OK(status)) {
1407 result = ntstatus_to_werror(status);
1409 if (!W_ERROR_IS_OK(result)) {
1414 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1415 status = dcerpc_winreg_set_dword(tmp_ctx,
1421 if (!NT_STATUS_IS_OK(status)) {
1422 result = ntstatus_to_werror(status);
1424 if (!W_ERROR_IS_OK(result)) {
1429 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1430 status = dcerpc_winreg_set_dword(tmp_ctx,
1436 if (!NT_STATUS_IS_OK(status)) {
1437 result = ntstatus_to_werror(status);
1439 if (!W_ERROR_IS_OK(result)) {
1444 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1445 status = dcerpc_winreg_set_dword(tmp_ctx,
1451 if (!NT_STATUS_IS_OK(status)) {
1452 result = ntstatus_to_werror(status);
1454 if (!W_ERROR_IS_OK(result)) {
1459 status = dcerpc_winreg_set_dword(tmp_ctx,
1463 winreg_printer_rev_changeid(),
1465 if (!NT_STATUS_IS_OK(status)) {
1466 result = ntstatus_to_werror(status);
1468 if (!W_ERROR_IS_OK(result)) {
1474 if (is_valid_policy_hnd(&key_hnd)) {
1475 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1477 if (is_valid_policy_hnd(&hive_hnd)) {
1478 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1481 TALLOC_FREE(tmp_ctx);
1485 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1486 struct dcerpc_binding_handle *winreg_handle,
1487 const char *printer,
1488 struct spoolss_PrinterInfo2 **pinfo2)
1490 struct spoolss_PrinterInfo2 *info2;
1491 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1492 struct policy_handle hive_hnd, key_hnd;
1493 struct spoolss_PrinterEnumValues enum_value;
1494 struct spoolss_PrinterEnumValues *v = NULL;
1495 enum ndr_err_code ndr_err;
1497 int snum = lp_servicenumber(printer);
1498 uint32_t num_values = 0;
1502 WERROR result = WERR_OK;
1504 const char **enum_names = NULL;
1505 enum winreg_Type *enum_types = NULL;
1506 DATA_BLOB *enum_data_blobs = NULL;
1507 TALLOC_CTX *tmp_ctx;
1509 tmp_ctx = talloc_stackframe();
1510 if (tmp_ctx == NULL) {
1511 return WERR_NOT_ENOUGH_MEMORY;
1514 path = winreg_printer_data_keyname(tmp_ctx, printer);
1516 TALLOC_FREE(tmp_ctx);
1517 return WERR_NOT_ENOUGH_MEMORY;
1520 result = winreg_printer_openkey(tmp_ctx,
1528 if (!W_ERROR_IS_OK(result)) {
1529 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
1530 path, win_errstr(result)));
1534 status = dcerpc_winreg_enumvals(tmp_ctx,
1542 if (!NT_STATUS_IS_OK(status)){
1543 result = ntstatus_to_werror(status);
1546 if (!W_ERROR_IS_OK(result)) {
1547 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1548 path, win_errstr(result)));
1552 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
1553 if (info2 == NULL) {
1554 result = WERR_NOT_ENOUGH_MEMORY;
1558 FILL_STRING(info2, "", info2->servername);
1559 FILL_STRING(info2, "", info2->printername);
1560 FILL_STRING(info2, "", info2->sharename);
1561 FILL_STRING(info2, "", info2->portname);
1562 FILL_STRING(info2, "", info2->drivername);
1563 FILL_STRING(info2, "", info2->comment);
1564 FILL_STRING(info2, "", info2->location);
1565 FILL_STRING(info2, "", info2->sepfile);
1566 FILL_STRING(info2, "", info2->printprocessor);
1567 FILL_STRING(info2, "", info2->datatype);
1568 FILL_STRING(info2, "", info2->parameters);
1570 for (i = 0; i < num_values; i++) {
1571 enum_value.value_name = enum_names[i];
1572 enum_value.value_name_len = 2*strlen_m_term(enum_names[i]);
1573 enum_value.type = enum_types[i];
1574 enum_value.data_length = enum_data_blobs[i].length;
1575 enum_value.data = NULL;
1576 if (enum_value.data_length != 0){
1577 enum_value.data = &enum_data_blobs[i];
1581 result = winreg_enumval_to_sz(info2,
1584 &info2->printername);
1585 CHECK_ERROR(result);
1587 result = winreg_enumval_to_sz(info2,
1591 CHECK_ERROR(result);
1593 result = winreg_enumval_to_sz(info2,
1597 CHECK_ERROR(result);
1599 result = winreg_enumval_to_sz(info2,
1603 CHECK_ERROR(result);
1605 result = winreg_enumval_to_sz(info2,
1609 CHECK_ERROR(result);
1611 result = winreg_enumval_to_sz(info2,
1615 CHECK_ERROR(result);
1617 result = winreg_enumval_to_sz(info2,
1620 &info2->printprocessor);
1621 CHECK_ERROR(result);
1623 result = winreg_enumval_to_sz(info2,
1627 CHECK_ERROR(result);
1629 result = winreg_enumval_to_sz(info2,
1632 &info2->parameters);
1633 CHECK_ERROR(result);
1635 result = winreg_enumval_to_sz(info2,
1638 &info2->drivername);
1639 CHECK_ERROR(result);
1641 result = winreg_enumval_to_dword(info2,
1644 &info2->attributes);
1645 CHECK_ERROR(result);
1647 result = winreg_enumval_to_dword(info2,
1651 CHECK_ERROR(result);
1653 result = winreg_enumval_to_dword(info2,
1656 &info2->defaultpriority);
1657 CHECK_ERROR(result);
1659 result = winreg_enumval_to_dword(info2,
1663 CHECK_ERROR(result);
1665 result = winreg_enumval_to_dword(info2,
1669 CHECK_ERROR(result);
1671 result = winreg_enumval_to_dword(info2,
1675 CHECK_ERROR(result);
1677 result = winreg_enumval_to_dword(info2,
1681 CHECK_ERROR(result);
1684 if (!W_ERROR_IS_OK(result)) {
1685 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
1688 win_errstr(result)));
1692 /* Construct the Device Mode */
1693 status = dcerpc_winreg_query_binary(tmp_ctx,
1699 if (!NT_STATUS_IS_OK(status)) {
1700 result = ntstatus_to_werror(status);
1702 if (W_ERROR_IS_OK(result)) {
1703 info2->devmode = talloc_zero(info2, struct spoolss_DeviceMode);
1704 if (info2->devmode == NULL) {
1705 result = WERR_NOT_ENOUGH_MEMORY;
1708 ndr_err = ndr_pull_struct_blob(&blob,
1711 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
1712 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1713 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
1714 result = WERR_NOT_ENOUGH_MEMORY;
1719 if (info2->devmode == NULL && lp_default_devmode(snum)) {
1720 result = spoolss_create_default_devmode(info2,
1723 if (!W_ERROR_IS_OK(result)) {
1728 if (info2->devmode) {
1729 info2->devmode->size = ndr_size_spoolss_DeviceMode(info2->devmode, 0) - info2->devmode->driverextra_data.length;
1732 result = winreg_get_printer_secdesc(info2,
1736 if (!W_ERROR_IS_OK(result)) {
1740 /* Fix for OS/2 drivers. */
1741 if (get_remote_arch() == RA_OS2) {
1742 spoolss_map_to_os2_driver(info2, &info2->drivername);
1746 *pinfo2 = talloc_move(mem_ctx, &info2);
1751 if (is_valid_policy_hnd(&key_hnd)) {
1752 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1754 if (is_valid_policy_hnd(&hive_hnd)) {
1755 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1758 TALLOC_FREE(tmp_ctx);
1762 static WERROR winreg_get_secdesc(TALLOC_CTX *mem_ctx,
1763 struct dcerpc_binding_handle *winreg_handle,
1765 const char *attribute,
1766 struct spoolss_security_descriptor **psecdesc)
1768 struct spoolss_security_descriptor *secdesc;
1769 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1770 struct policy_handle hive_hnd, key_hnd;
1771 TALLOC_CTX *tmp_ctx;
1776 tmp_ctx = talloc_stackframe();
1777 if (tmp_ctx == NULL) {
1778 return WERR_NOT_ENOUGH_MEMORY;
1781 ZERO_STRUCT(hive_hnd);
1782 ZERO_STRUCT(key_hnd);
1784 result = winreg_printer_openkey(tmp_ctx,
1792 if (!W_ERROR_IS_OK(result)) {
1793 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
1794 goto create_default;
1799 status = dcerpc_winreg_query_sd(tmp_ctx,
1805 if (!NT_STATUS_IS_OK(status)) {
1806 result = ntstatus_to_werror(status);
1808 if (!W_ERROR_IS_OK(result)) {
1809 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
1811 if (is_valid_policy_hnd(&key_hnd)) {
1812 dcerpc_winreg_CloseKey(winreg_handle,
1818 if (is_valid_policy_hnd(&hive_hnd)) {
1819 dcerpc_winreg_CloseKey(winreg_handle,
1824 goto create_default;
1830 *psecdesc = talloc_move(mem_ctx, &secdesc);
1837 result = winreg_printer_openkey(tmp_ctx,
1845 if (!W_ERROR_IS_OK(result)) {
1849 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1850 if (!W_ERROR_IS_OK(result)) {
1854 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
1855 this security descriptor has been created when winbindd was
1856 down. Take ownership of security descriptor. */
1857 if (dom_sid_equal(secdesc->owner_sid, &global_sid_World)) {
1858 struct dom_sid owner_sid;
1860 /* Change sd owner to workgroup administrator */
1862 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid)) {
1863 struct spoolss_security_descriptor *new_secdesc;
1867 sid_append_rid(&owner_sid, DOMAIN_RID_ADMINISTRATOR);
1869 new_secdesc = make_sec_desc(tmp_ctx,
1878 if (new_secdesc == NULL) {
1879 result = WERR_NOT_ENOUGH_MEMORY;
1883 /* Swap with other one */
1884 secdesc = new_secdesc;
1888 status = dcerpc_winreg_set_sd(tmp_ctx,
1894 if (!NT_STATUS_IS_OK(status)) {
1895 result = ntstatus_to_werror(status);
1897 if (!W_ERROR_IS_OK(result)) {
1902 *psecdesc = talloc_move(mem_ctx, &secdesc);
1907 if (is_valid_policy_hnd(&key_hnd)) {
1908 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1910 if (is_valid_policy_hnd(&hive_hnd)) {
1911 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1914 talloc_free(tmp_ctx);
1918 WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
1919 struct dcerpc_binding_handle *winreg_handle,
1920 const char *sharename,
1921 struct spoolss_security_descriptor **psecdesc)
1926 path = winreg_printer_data_keyname(mem_ctx, sharename);
1928 return WERR_NOT_ENOUGH_MEMORY;
1931 result = winreg_get_secdesc(mem_ctx, winreg_handle,
1940 WERROR winreg_get_printserver_secdesc(TALLOC_CTX *mem_ctx,
1941 struct dcerpc_binding_handle *winreg_handle,
1942 struct spoolss_security_descriptor **psecdesc)
1944 return winreg_get_secdesc(mem_ctx, winreg_handle,
1945 TOP_LEVEL_CONTROL_KEY,
1946 "ServerSecurityDescriptor",
1950 static WERROR winreg_set_secdesc(TALLOC_CTX *mem_ctx,
1951 struct dcerpc_binding_handle *winreg_handle,
1953 const char *attribute,
1954 const struct spoolss_security_descriptor *secdesc)
1956 const struct spoolss_security_descriptor *new_secdesc = secdesc;
1957 struct spoolss_security_descriptor *old_secdesc;
1958 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1959 struct policy_handle hive_hnd, key_hnd;
1960 TALLOC_CTX *tmp_ctx;
1965 tmp_ctx = talloc_stackframe();
1966 if (tmp_ctx == NULL) {
1967 return WERR_NOT_ENOUGH_MEMORY;
1971 * The old owner and group sids of the security descriptor are not
1972 * present when new ACEs are added or removed by changing printer
1973 * permissions through NT. If they are NULL in the new security
1974 * descriptor then copy them over from the old one.
1976 if (!secdesc->owner_sid || !secdesc->group_sid) {
1977 struct dom_sid *owner_sid, *group_sid;
1978 struct security_acl *dacl, *sacl;
1981 result = winreg_get_secdesc(tmp_ctx,
1986 if (!W_ERROR_IS_OK(result)) {
1987 talloc_free(tmp_ctx);
1991 /* Pick out correct owner and group sids */
1992 owner_sid = secdesc->owner_sid ?
1993 secdesc->owner_sid :
1994 old_secdesc->owner_sid;
1996 group_sid = secdesc->group_sid ?
1997 secdesc->group_sid :
1998 old_secdesc->group_sid;
2000 dacl = secdesc->dacl ?
2004 sacl = secdesc->sacl ?
2008 /* Make a deep copy of the security descriptor */
2009 new_secdesc = make_sec_desc(tmp_ctx,
2017 if (new_secdesc == NULL) {
2018 talloc_free(tmp_ctx);
2019 return WERR_NOT_ENOUGH_MEMORY;
2023 ZERO_STRUCT(hive_hnd);
2024 ZERO_STRUCT(key_hnd);
2026 result = winreg_printer_openkey(tmp_ctx,
2034 if (!W_ERROR_IS_OK(result)) {
2038 status = dcerpc_winreg_set_sd(tmp_ctx,
2044 if (!NT_STATUS_IS_OK(status)) {
2045 result = ntstatus_to_werror(status);
2049 if (is_valid_policy_hnd(&key_hnd)) {
2050 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2052 if (is_valid_policy_hnd(&hive_hnd)) {
2053 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2056 talloc_free(tmp_ctx);
2060 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
2061 struct dcerpc_binding_handle *winreg_handle,
2062 const char *sharename,
2063 const struct spoolss_security_descriptor *secdesc)
2068 path = winreg_printer_data_keyname(mem_ctx, sharename);
2070 return WERR_NOT_ENOUGH_MEMORY;
2073 result = winreg_set_secdesc(mem_ctx, winreg_handle,
2075 "Security", secdesc);
2081 WERROR winreg_set_printserver_secdesc(TALLOC_CTX *mem_ctx,
2082 struct dcerpc_binding_handle *winreg_handle,
2083 const struct spoolss_security_descriptor *secdesc)
2085 return winreg_set_secdesc(mem_ctx, winreg_handle,
2086 TOP_LEVEL_CONTROL_KEY,
2087 "ServerSecurityDescriptor",
2091 /* Set printer data over the winreg pipe. */
2092 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2093 struct dcerpc_binding_handle *winreg_handle,
2094 const char *printer,
2097 enum winreg_Type type,
2101 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2102 struct policy_handle hive_hnd, key_hnd;
2103 struct winreg_String wvalue = { 0, };
2105 WERROR result = WERR_OK;
2108 TALLOC_CTX *tmp_ctx;
2110 tmp_ctx = talloc_stackframe();
2111 if (tmp_ctx == NULL) {
2112 return WERR_NOT_ENOUGH_MEMORY;
2115 path = winreg_printer_data_keyname(tmp_ctx, printer);
2117 TALLOC_FREE(tmp_ctx);
2118 return WERR_NOT_ENOUGH_MEMORY;
2121 ZERO_STRUCT(hive_hnd);
2122 ZERO_STRUCT(key_hnd);
2124 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2125 key, value, access_mask, printer));
2126 result = winreg_printer_openkey(tmp_ctx,
2134 if (!W_ERROR_IS_OK(result)) {
2135 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2136 key, win_errstr(result)));
2140 wvalue.name = value;
2141 status = dcerpc_winreg_SetValue(winreg_handle,
2149 if (!NT_STATUS_IS_OK(status)) {
2150 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2151 value, nt_errstr(status)));
2152 result = ntstatus_to_werror(status);
2156 if (is_valid_policy_hnd(&key_hnd)) {
2157 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2159 if (is_valid_policy_hnd(&hive_hnd)) {
2160 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2163 TALLOC_FREE(tmp_ctx);
2167 /* Get printer data over a winreg pipe. */
2168 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2169 struct dcerpc_binding_handle *winreg_handle,
2170 const char *printer,
2173 enum winreg_Type *type,
2175 uint32_t *data_size)
2177 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2178 struct policy_handle hive_hnd, key_hnd;
2179 struct winreg_String wvalue;
2180 enum winreg_Type type_in = REG_NONE;
2182 uint8_t *data_in = NULL;
2183 uint32_t data_in_size = 0;
2184 uint32_t value_len = 0;
2185 WERROR result = WERR_OK;
2188 TALLOC_CTX *tmp_ctx;
2190 tmp_ctx = talloc_stackframe();
2191 if (tmp_ctx == NULL) {
2192 return WERR_NOT_ENOUGH_MEMORY;
2195 path = winreg_printer_data_keyname(tmp_ctx, printer);
2197 TALLOC_FREE(tmp_ctx);
2198 return WERR_NOT_ENOUGH_MEMORY;
2201 ZERO_STRUCT(hive_hnd);
2202 ZERO_STRUCT(key_hnd);
2204 result = winreg_printer_openkey(tmp_ctx,
2212 if (!W_ERROR_IS_OK(result)) {
2213 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2214 key, win_errstr(result)));
2218 wvalue.name = value;
2221 * call QueryValue once with data == NULL to get the
2222 * needed memory size to be allocated, then allocate
2223 * data buffer and call again.
2225 status = dcerpc_winreg_QueryValue(winreg_handle,
2234 if (!NT_STATUS_IS_OK(status)) {
2235 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2236 value, nt_errstr(status)));
2237 result = ntstatus_to_werror(status);
2240 if (!W_ERROR_IS_OK(result)) {
2241 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2242 value, win_errstr(result)));
2246 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2247 if (data_in == NULL) {
2248 result = WERR_NOT_ENOUGH_MEMORY;
2253 status = dcerpc_winreg_QueryValue(winreg_handle,
2262 if (!NT_STATUS_IS_OK(status)) {
2263 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2264 value, nt_errstr(status)));
2265 result = ntstatus_to_werror(status);
2268 if (!W_ERROR_IS_OK(result)) {
2269 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2270 value, win_errstr(result)));
2275 *data_size = data_in_size;
2277 *data = talloc_move(mem_ctx, &data_in);
2282 if (is_valid_policy_hnd(&key_hnd)) {
2283 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2285 if (is_valid_policy_hnd(&hive_hnd)) {
2286 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2289 TALLOC_FREE(tmp_ctx);
2293 /* Enumerate on the values of a given key and provide the data. */
2294 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2295 struct dcerpc_binding_handle *winreg_handle,
2296 const char *printer,
2298 uint32_t *pnum_values,
2299 struct spoolss_PrinterEnumValues **penum_values)
2302 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2303 struct policy_handle hive_hnd, key_hnd;
2305 struct spoolss_PrinterEnumValues *enum_values = NULL;
2306 uint32_t num_values = 0;
2308 WERROR result = WERR_OK;
2311 const char **enum_names = NULL;
2312 enum winreg_Type *enum_types = NULL;
2313 DATA_BLOB *enum_data_blobs = NULL;
2315 TALLOC_CTX *tmp_ctx;
2317 tmp_ctx = talloc_stackframe();
2318 if (tmp_ctx == NULL) {
2319 return WERR_NOT_ENOUGH_MEMORY;
2322 path = winreg_printer_data_keyname(tmp_ctx, printer);
2324 TALLOC_FREE(tmp_ctx);
2325 return WERR_NOT_ENOUGH_MEMORY;
2328 result = winreg_printer_openkey(tmp_ctx,
2336 if (!W_ERROR_IS_OK(result)) {
2337 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2338 key, win_errstr(result)));
2342 status = dcerpc_winreg_enumvals(tmp_ctx,
2350 if (!NT_STATUS_IS_OK(status)){
2351 result = ntstatus_to_werror(status);
2354 if (!W_ERROR_IS_OK(result)) {
2355 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2356 key, win_errstr(result)));
2360 enum_values = talloc_array(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
2361 if (enum_values == NULL){
2362 result = WERR_NOT_ENOUGH_MEMORY;
2363 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2364 key, win_errstr(result)));
2368 for (i = 0; i < num_values; i++){
2369 enum_values[i].value_name = enum_names[i];
2370 enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
2371 enum_values[i].type = enum_types[i];
2372 enum_values[i].data_length = enum_data_blobs[i].length;
2373 enum_values[i].data = NULL;
2375 if (enum_values[i].data_length != 0){
2376 enum_values[i].data = &enum_data_blobs[i];
2380 talloc_steal(enum_values, enum_names);
2381 talloc_steal(enum_values, enum_data_blobs);
2383 *pnum_values = num_values;
2385 *penum_values = talloc_move(mem_ctx, &enum_values);
2390 if (is_valid_policy_hnd(&key_hnd)) {
2391 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2393 if (is_valid_policy_hnd(&hive_hnd)) {
2394 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2397 TALLOC_FREE(tmp_ctx);
2401 /* Delete printer data over a winreg pipe. */
2402 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2403 struct dcerpc_binding_handle *winreg_handle,
2404 const char *printer,
2408 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2409 struct policy_handle hive_hnd, key_hnd;
2410 struct winreg_String wvalue = { 0, };
2412 WERROR result = WERR_OK;
2416 TALLOC_CTX *tmp_ctx;
2418 tmp_ctx = talloc_stackframe();
2419 if (tmp_ctx == NULL) {
2420 return WERR_NOT_ENOUGH_MEMORY;
2423 path = winreg_printer_data_keyname(tmp_ctx, printer);
2425 TALLOC_FREE(tmp_ctx);
2426 return WERR_NOT_ENOUGH_MEMORY;
2429 ZERO_STRUCT(hive_hnd);
2430 ZERO_STRUCT(key_hnd);
2432 result = winreg_printer_openkey(tmp_ctx,
2440 if (!W_ERROR_IS_OK(result)) {
2441 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2442 key, win_errstr(result)));
2446 wvalue.name = value;
2447 status = dcerpc_winreg_DeleteValue(winreg_handle,
2452 if (!NT_STATUS_IS_OK(status)) {
2453 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2454 value, nt_errstr(status)));
2455 result = ntstatus_to_werror(status);
2459 if (is_valid_policy_hnd(&key_hnd)) {
2460 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2462 if (is_valid_policy_hnd(&hive_hnd)) {
2463 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2466 TALLOC_FREE(tmp_ctx);
2470 /* Enumerate on the subkeys of a given key and provide the data. */
2471 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2472 struct dcerpc_binding_handle *winreg_handle,
2473 const char *printer,
2475 uint32_t *pnum_subkeys,
2476 const char ***psubkeys)
2478 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2479 struct policy_handle hive_hnd, key_hnd;
2481 const char **subkeys = NULL;
2482 uint32_t num_subkeys = -1;
2484 WERROR result = WERR_OK;
2488 TALLOC_CTX *tmp_ctx;
2490 tmp_ctx = talloc_stackframe();
2491 if (tmp_ctx == NULL) {
2492 return WERR_NOT_ENOUGH_MEMORY;
2495 path = winreg_printer_data_keyname(tmp_ctx, printer);
2497 TALLOC_FREE(tmp_ctx);
2498 return WERR_NOT_ENOUGH_MEMORY;
2501 ZERO_STRUCT(hive_hnd);
2502 ZERO_STRUCT(key_hnd);
2504 result = winreg_printer_openkey(tmp_ctx,
2512 if (!W_ERROR_IS_OK(result)) {
2513 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2514 key, win_errstr(result)));
2518 status = dcerpc_winreg_enum_keys(tmp_ctx,
2524 if (!NT_STATUS_IS_OK(status)) {
2525 result = ntstatus_to_werror(status);
2527 if (!W_ERROR_IS_OK(result)) {
2528 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2529 key, win_errstr(result)));
2533 *pnum_subkeys = num_subkeys;
2535 *psubkeys = talloc_move(mem_ctx, &subkeys);
2540 if (is_valid_policy_hnd(&key_hnd)) {
2541 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2543 if (is_valid_policy_hnd(&hive_hnd)) {
2544 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2547 TALLOC_FREE(tmp_ctx);
2551 /* Delete a key with subkeys of a given printer. */
2552 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
2553 struct dcerpc_binding_handle *winreg_handle,
2554 const char *printer,
2557 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2558 struct policy_handle hive_hnd, key_hnd;
2564 TALLOC_CTX *tmp_ctx;
2566 tmp_ctx = talloc_stackframe();
2567 if (tmp_ctx == NULL) {
2568 return WERR_NOT_ENOUGH_MEMORY;
2571 path = winreg_printer_data_keyname(tmp_ctx, printer);
2573 TALLOC_FREE(tmp_ctx);
2574 return WERR_NOT_ENOUGH_MEMORY;
2577 result = winreg_printer_openkey(tmp_ctx,
2585 if (!W_ERROR_IS_OK(result)) {
2586 /* key doesn't exist */
2587 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
2592 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2593 key, win_errstr(result)));
2597 if (is_valid_policy_hnd(&key_hnd)) {
2598 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
2601 if (key == NULL || key[0] == '\0') {
2604 keyname = talloc_asprintf(tmp_ctx,
2608 if (keyname == NULL) {
2609 result = WERR_NOT_ENOUGH_MEMORY;
2614 status = dcerpc_winreg_delete_subkeys_recursive(tmp_ctx,
2621 if (!NT_STATUS_IS_OK(status)) {
2622 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2623 key, nt_errstr(status)));
2624 result = ntstatus_to_werror(status);
2628 if (!W_ERROR_IS_OK(result)) {
2629 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2630 key, win_errstr(result)));
2635 if (is_valid_policy_hnd(&key_hnd)) {
2636 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2638 if (is_valid_policy_hnd(&hive_hnd)) {
2639 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2642 TALLOC_FREE(tmp_ctx);
2646 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
2647 struct dcerpc_binding_handle *winreg_handle,
2648 const char *printer)
2650 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2651 struct policy_handle hive_hnd, key_hnd;
2656 TALLOC_CTX *tmp_ctx;
2658 tmp_ctx = talloc_stackframe();
2659 if (tmp_ctx == NULL) {
2660 return WERR_NOT_ENOUGH_MEMORY;
2663 path = winreg_printer_data_keyname(tmp_ctx, printer);
2665 TALLOC_FREE(tmp_ctx);
2666 return WERR_NOT_ENOUGH_MEMORY;
2669 ZERO_STRUCT(hive_hnd);
2670 ZERO_STRUCT(key_hnd);
2672 result = winreg_printer_openkey(tmp_ctx,
2680 if (!W_ERROR_IS_OK(result)) {
2681 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2682 path, win_errstr(result)));
2686 status = dcerpc_winreg_set_dword(tmp_ctx,
2690 winreg_printer_rev_changeid(),
2692 if (!NT_STATUS_IS_OK(status)) {
2693 result = ntstatus_to_werror(status);
2695 if (!W_ERROR_IS_OK(result)) {
2701 if (is_valid_policy_hnd(&key_hnd)) {
2702 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2704 if (is_valid_policy_hnd(&hive_hnd)) {
2705 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2708 TALLOC_FREE(tmp_ctx);
2712 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
2713 struct dcerpc_binding_handle *winreg_handle,
2714 const char *printer,
2715 uint32_t *pchangeid)
2717 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2718 struct policy_handle hive_hnd, key_hnd;
2719 uint32_t changeid = 0;
2724 TALLOC_CTX *tmp_ctx;
2726 tmp_ctx = talloc_stackframe();
2727 if (tmp_ctx == NULL) {
2728 return WERR_NOT_ENOUGH_MEMORY;
2731 path = winreg_printer_data_keyname(tmp_ctx, printer);
2733 TALLOC_FREE(tmp_ctx);
2734 return WERR_NOT_ENOUGH_MEMORY;
2737 ZERO_STRUCT(hive_hnd);
2738 ZERO_STRUCT(key_hnd);
2740 result = winreg_printer_openkey(tmp_ctx,
2748 if (!W_ERROR_IS_OK(result)) {
2749 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2750 path, win_errstr(result)));
2754 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path));
2756 status = dcerpc_winreg_query_dword(tmp_ctx,
2762 if (!NT_STATUS_IS_OK(status)) {
2763 result = ntstatus_to_werror(status);
2765 if (!W_ERROR_IS_OK(result)) {
2770 *pchangeid = changeid;
2775 if (is_valid_policy_hnd(&key_hnd)) {
2776 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2778 if (is_valid_policy_hnd(&hive_hnd)) {
2779 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2782 TALLOC_FREE(tmp_ctx);
2787 * The special behaviour of the spoolss forms is documented at the website:
2789 * Managing Win32 Printserver Forms
2790 * http://unixwiz.net/techtips/winspooler-forms.html
2793 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
2794 struct dcerpc_binding_handle *winreg_handle,
2795 struct spoolss_AddFormInfo1 *form)
2797 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2798 struct policy_handle hive_hnd, key_hnd;
2799 struct winreg_String wvalue = { 0, };
2801 uint32_t num_info = 0;
2802 union spoolss_FormInfo *info = NULL;
2807 TALLOC_CTX *tmp_ctx;
2809 tmp_ctx = talloc_stackframe();
2810 if (tmp_ctx == NULL) {
2811 return WERR_NOT_ENOUGH_MEMORY;
2814 ZERO_STRUCT(hive_hnd);
2815 ZERO_STRUCT(key_hnd);
2817 result = winreg_printer_openkey(tmp_ctx,
2819 TOP_LEVEL_CONTROL_FORMS_KEY,
2825 if (!W_ERROR_IS_OK(result)) {
2826 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2827 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2831 result = winreg_printer_enumforms1(tmp_ctx, winreg_handle,
2833 if (!W_ERROR_IS_OK(result)) {
2834 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2835 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2839 /* If form name already exists or is builtin return ALREADY_EXISTS */
2840 for (i = 0; i < num_info; i++) {
2841 if (strequal(info[i].info1.form_name, form->form_name)) {
2842 result = WERR_FILE_EXISTS;
2847 wvalue.name = form->form_name;
2849 blob = data_blob_talloc(tmp_ctx, NULL, 32);
2850 SIVAL(blob.data, 0, form->size.width);
2851 SIVAL(blob.data, 4, form->size.height);
2852 SIVAL(blob.data, 8, form->area.left);
2853 SIVAL(blob.data, 12, form->area.top);
2854 SIVAL(blob.data, 16, form->area.right);
2855 SIVAL(blob.data, 20, form->area.bottom);
2856 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
2857 SIVAL(blob.data, 28, form->flags);
2859 status = dcerpc_winreg_SetValue(winreg_handle,
2867 if (!NT_STATUS_IS_OK(status)) {
2868 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2869 wvalue.name, nt_errstr(status)));
2870 result = ntstatus_to_werror(status);
2874 if (is_valid_policy_hnd(&key_hnd)) {
2875 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2877 if (is_valid_policy_hnd(&hive_hnd)) {
2878 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2882 TALLOC_FREE(tmp_ctx);
2886 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
2887 struct dcerpc_binding_handle *winreg_handle,
2888 uint32_t *pnum_info,
2889 union spoolss_FormInfo **pinfo)
2891 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2892 struct policy_handle hive_hnd, key_hnd;
2893 union spoolss_FormInfo *info;
2894 struct spoolss_PrinterEnumValues *enum_values = NULL;
2895 uint32_t num_values = 0;
2896 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
2901 const char **enum_names = NULL;
2902 enum winreg_Type *enum_types = NULL;
2903 DATA_BLOB *enum_data_blobs = NULL;
2904 TALLOC_CTX *tmp_ctx;
2906 tmp_ctx = talloc_stackframe();
2907 if (tmp_ctx == NULL) {
2908 return WERR_NOT_ENOUGH_MEMORY;
2911 ZERO_STRUCT(hive_hnd);
2912 ZERO_STRUCT(key_hnd);
2914 result = winreg_printer_openkey(tmp_ctx,
2916 TOP_LEVEL_CONTROL_FORMS_KEY,
2922 if (!W_ERROR_IS_OK(result)) {
2923 /* key doesn't exist */
2924 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
2929 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
2930 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2934 status = dcerpc_winreg_enumvals(tmp_ctx,
2942 if (!NT_STATUS_IS_OK(status)){
2943 result = ntstatus_to_werror(status);
2946 if (!W_ERROR_IS_OK(result)) {
2947 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2948 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2952 enum_values = talloc_zero_array(tmp_ctx,
2953 struct spoolss_PrinterEnumValues,
2955 if (enum_values == NULL){
2956 result = WERR_NOT_ENOUGH_MEMORY;
2960 for (i = 0; i < num_values; i++){
2961 enum_values[i].value_name = enum_names[i];
2962 enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
2963 enum_values[i].type = enum_types[i];
2964 enum_values[i].data_length = enum_data_blobs[i].length;
2965 enum_values[i].data = NULL;
2966 if (enum_values[i].data_length != 0){
2967 enum_values[i].data = &enum_data_blobs[i];
2971 if (!W_ERROR_IS_OK(result)) {
2972 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2973 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2977 info = talloc_array(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
2979 result = WERR_NOT_ENOUGH_MEMORY;
2983 /* Enumerate BUILTIN forms */
2984 for (i = 0; i < num_builtin; i++) {
2985 info[i].info1 = builtin_forms1[i];
2988 /* Enumerate registry forms */
2989 for (i = 0; i < num_values; i++) {
2990 union spoolss_FormInfo val;
2992 if (enum_values[i].type != REG_BINARY ||
2993 enum_values[i].data_length != 32) {
2997 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
2998 if (val.info1.form_name == NULL) {
2999 result = WERR_NOT_ENOUGH_MEMORY;
3003 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3004 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3005 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3006 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3007 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3008 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3009 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3010 val.info1.flags = (enum spoolss_FormFlags) IVAL(enum_values[i].data->data, 28);
3012 info[i + num_builtin] = val;
3015 *pnum_info = num_builtin + num_values;
3017 *pinfo = talloc_move(mem_ctx, &info);
3021 if (is_valid_policy_hnd(&key_hnd)) {
3022 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3024 if (is_valid_policy_hnd(&hive_hnd)) {
3025 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3028 TALLOC_FREE(enum_values);
3029 TALLOC_FREE(tmp_ctx);
3033 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3034 struct dcerpc_binding_handle *winreg_handle,
3035 const char *form_name)
3037 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3038 struct policy_handle hive_hnd, key_hnd;
3039 struct winreg_String wvalue = { 0, };
3040 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3042 WERROR result = WERR_OK;
3045 TALLOC_CTX *tmp_ctx;
3047 for (i = 0; i < num_builtin; i++) {
3048 if (strequal(builtin_forms1[i].form_name, form_name)) {
3049 return WERR_INVALID_PARAMETER;
3053 tmp_ctx = talloc_stackframe();
3054 if (tmp_ctx == NULL) {
3055 return WERR_NOT_ENOUGH_MEMORY;
3058 ZERO_STRUCT(hive_hnd);
3059 ZERO_STRUCT(key_hnd);
3061 result = winreg_printer_openkey(tmp_ctx,
3063 TOP_LEVEL_CONTROL_FORMS_KEY,
3069 if (!W_ERROR_IS_OK(result)) {
3070 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3071 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3072 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
3073 result = WERR_INVALID_FORM_NAME;
3078 wvalue.name = form_name;
3079 status = dcerpc_winreg_DeleteValue(winreg_handle,
3084 if (!NT_STATUS_IS_OK(status)) {
3085 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3086 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3087 wvalue.name, nt_errstr(status)));
3088 result = ntstatus_to_werror(status);
3092 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
3093 result = WERR_INVALID_FORM_NAME;
3097 if (is_valid_policy_hnd(&key_hnd)) {
3098 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3100 if (is_valid_policy_hnd(&hive_hnd)) {
3101 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3104 TALLOC_FREE(tmp_ctx);
3108 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3109 struct dcerpc_binding_handle *winreg_handle,
3110 const char *form_name,
3111 struct spoolss_AddFormInfo1 *form)
3113 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3114 struct policy_handle hive_hnd = { 0, };
3115 struct policy_handle key_hnd = { 0, };
3116 struct winreg_String wvalue = { 0, };
3118 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3122 TALLOC_CTX *tmp_ctx = NULL;
3124 for (i = 0; i < num_builtin; i++) {
3125 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3126 result = WERR_INVALID_PARAMETER;
3131 tmp_ctx = talloc_stackframe();
3132 if (tmp_ctx == NULL) {
3133 return WERR_NOT_ENOUGH_MEMORY;
3136 ZERO_STRUCT(hive_hnd);
3137 ZERO_STRUCT(key_hnd);
3139 result = winreg_printer_openkey(tmp_ctx,
3141 TOP_LEVEL_CONTROL_FORMS_KEY,
3147 if (!W_ERROR_IS_OK(result)) {
3148 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3149 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3153 /* If form_name != form->form_name then we renamed the form */
3154 if (strequal(form_name, form->form_name)) {
3155 result = winreg_printer_deleteform1(tmp_ctx, winreg_handle,
3157 if (!W_ERROR_IS_OK(result)) {
3158 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3159 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3164 wvalue.name = form->form_name;
3166 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3167 SIVAL(blob.data, 0, form->size.width);
3168 SIVAL(blob.data, 4, form->size.height);
3169 SIVAL(blob.data, 8, form->area.left);
3170 SIVAL(blob.data, 12, form->area.top);
3171 SIVAL(blob.data, 16, form->area.right);
3172 SIVAL(blob.data, 20, form->area.bottom);
3173 SIVAL(blob.data, 24, 42);
3174 SIVAL(blob.data, 28, form->flags);
3176 status = dcerpc_winreg_SetValue(winreg_handle,
3184 if (!NT_STATUS_IS_OK(status)) {
3185 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3186 wvalue.name, nt_errstr(status)));
3187 result = ntstatus_to_werror(status);
3191 if (winreg_handle != NULL) {
3194 if (is_valid_policy_hnd(&key_hnd)) {
3195 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3197 if (is_valid_policy_hnd(&hive_hnd)) {
3198 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3202 TALLOC_FREE(tmp_ctx);
3206 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3207 struct dcerpc_binding_handle *winreg_handle,
3208 const char *form_name,
3209 struct spoolss_FormInfo1 *r)
3211 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3212 struct policy_handle hive_hnd, key_hnd;
3213 struct winreg_String wvalue;
3214 enum winreg_Type type_in = REG_NONE;
3215 uint8_t *data_in = NULL;
3216 uint32_t data_in_size = 0;
3217 uint32_t value_len = 0;
3218 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3223 TALLOC_CTX *tmp_ctx;
3225 /* check builtin forms first */
3226 for (i = 0; i < num_builtin; i++) {
3227 if (strequal(builtin_forms1[i].form_name, form_name)) {
3228 *r = builtin_forms1[i];
3233 tmp_ctx = talloc_stackframe();
3234 if (tmp_ctx == NULL) {
3235 return WERR_NOT_ENOUGH_MEMORY;
3238 ZERO_STRUCT(hive_hnd);
3239 ZERO_STRUCT(key_hnd);
3241 result = winreg_printer_openkey(tmp_ctx,
3243 TOP_LEVEL_CONTROL_FORMS_KEY,
3249 if (!W_ERROR_IS_OK(result)) {
3250 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3251 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3255 wvalue.name = form_name;
3258 * call QueryValue once with data == NULL to get the
3259 * needed memory size to be allocated, then allocate
3260 * data buffer and call again.
3262 status = dcerpc_winreg_QueryValue(winreg_handle,
3271 if (!NT_STATUS_IS_OK(status)) {
3272 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3273 wvalue.name, nt_errstr(status)));
3274 result = ntstatus_to_werror(status);
3277 if (!W_ERROR_IS_OK(result)) {
3281 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3282 if (data_in == NULL) {
3283 result = WERR_NOT_ENOUGH_MEMORY;
3288 status = dcerpc_winreg_QueryValue(winreg_handle,
3297 if (!NT_STATUS_IS_OK(status)) {
3298 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3299 wvalue.name, nt_errstr(status)));
3300 result = ntstatus_to_werror(status);
3303 if (!W_ERROR_IS_OK(result)) {
3307 r->form_name = talloc_strdup(mem_ctx, form_name);
3308 if (r->form_name == NULL) {
3309 result = WERR_NOT_ENOUGH_MEMORY;
3313 r->size.width = IVAL(data_in, 0);
3314 r->size.height = IVAL(data_in, 4);
3315 r->area.left = IVAL(data_in, 8);
3316 r->area.top = IVAL(data_in, 12);
3317 r->area.right = IVAL(data_in, 16);
3318 r->area.bottom = IVAL(data_in, 20);
3319 /* skip index IVAL(data_in, 24)));*/
3320 r->flags = (enum spoolss_FormFlags) IVAL(data_in, 28);
3324 if (is_valid_policy_hnd(&key_hnd)) {
3325 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3327 if (is_valid_policy_hnd(&hive_hnd)) {
3328 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3331 TALLOC_FREE(tmp_ctx);
3335 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3336 struct dcerpc_binding_handle *winreg_handle,
3337 struct spoolss_AddDriverInfoCtr *r,
3338 const char **driver_name,
3339 uint32_t *driver_version)
3341 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3342 struct policy_handle hive_hnd, key_hnd;
3343 struct spoolss_DriverInfo8 info8;
3344 TALLOC_CTX *tmp_ctx = NULL;
3348 ZERO_STRUCT(hive_hnd);
3349 ZERO_STRUCT(key_hnd);
3352 if (!driver_info_ctr_to_info8(r, &info8)) {
3353 result = WERR_INVALID_PARAMETER;
3357 tmp_ctx = talloc_stackframe();
3358 if (tmp_ctx == NULL) {
3359 return WERR_NOT_ENOUGH_MEMORY;
3362 result = winreg_printer_opendriver(tmp_ctx,
3370 if (!W_ERROR_IS_OK(result)) {
3371 DEBUG(0, ("winreg_add_driver: "
3372 "Could not open driver key (%s,%s,%d): %s\n",
3373 info8.driver_name, info8.architecture,
3374 info8.version, win_errstr(result)));
3378 /* TODO: "Attributes" ? */
3380 status = dcerpc_winreg_set_dword(tmp_ctx,
3386 if (!NT_STATUS_IS_OK(status)) {
3387 result = ntstatus_to_werror(status);
3389 if (!W_ERROR_IS_OK(result)) {
3393 status = dcerpc_winreg_set_sz(tmp_ctx,
3399 if (!NT_STATUS_IS_OK(status)) {
3400 result = ntstatus_to_werror(status);
3402 if (!W_ERROR_IS_OK(result)) {
3406 status = dcerpc_winreg_set_sz(tmp_ctx,
3412 if (!NT_STATUS_IS_OK(status)) {
3413 result = ntstatus_to_werror(status);
3415 if (!W_ERROR_IS_OK(result)) {
3419 status = dcerpc_winreg_set_sz(tmp_ctx,
3422 "Configuration File",
3425 if (!NT_STATUS_IS_OK(status)) {
3426 result = ntstatus_to_werror(status);
3428 if (!W_ERROR_IS_OK(result)) {
3432 status = dcerpc_winreg_set_sz(tmp_ctx,
3438 if (!NT_STATUS_IS_OK(status)) {
3439 result = ntstatus_to_werror(status);
3441 if (!W_ERROR_IS_OK(result)) {
3445 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3449 info8.dependent_files,
3451 if (!NT_STATUS_IS_OK(status)) {
3452 result = ntstatus_to_werror(status);
3454 if (!W_ERROR_IS_OK(result)) {
3458 status = dcerpc_winreg_set_sz(tmp_ctx,
3464 if (!NT_STATUS_IS_OK(status)) {
3465 result = ntstatus_to_werror(status);
3467 if (!W_ERROR_IS_OK(result)) {
3471 status = dcerpc_winreg_set_sz(tmp_ctx,
3475 info8.default_datatype,
3477 if (!NT_STATUS_IS_OK(status)) {
3478 result = ntstatus_to_werror(status);
3480 if (!W_ERROR_IS_OK(result)) {
3484 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3486 &key_hnd, "Previous Names",
3487 info8.previous_names,
3489 if (!NT_STATUS_IS_OK(status)) {
3490 result = ntstatus_to_werror(status);
3492 if (!W_ERROR_IS_OK(result)) {
3496 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3497 &key_hnd, "DriverDate",
3499 if (!W_ERROR_IS_OK(result)) {
3503 result = winreg_printer_write_ver(tmp_ctx, winreg_handle,
3504 &key_hnd, "DriverVersion",
3505 info8.driver_version);
3506 if (!W_ERROR_IS_OK(result)) {
3510 status = dcerpc_winreg_set_sz(tmp_ctx,
3514 info8.manufacturer_name,
3516 if (!NT_STATUS_IS_OK(status)) {
3517 result = ntstatus_to_werror(status);
3519 if (!W_ERROR_IS_OK(result)) {
3523 status = dcerpc_winreg_set_sz(tmp_ctx,
3527 info8.manufacturer_url,
3529 if (!NT_STATUS_IS_OK(status)) {
3530 result = ntstatus_to_werror(status);
3532 if (!W_ERROR_IS_OK(result)) {
3536 status = dcerpc_winreg_set_sz(tmp_ctx,
3542 if (!NT_STATUS_IS_OK(status)) {
3543 result = ntstatus_to_werror(status);
3545 if (!W_ERROR_IS_OK(result)) {
3549 status = dcerpc_winreg_set_sz(tmp_ctx,
3555 if (!NT_STATUS_IS_OK(status)) {
3556 result = ntstatus_to_werror(status);
3558 if (!W_ERROR_IS_OK(result)) {
3562 status = dcerpc_winreg_set_sz(tmp_ctx,
3566 info8.print_processor,
3568 if (!NT_STATUS_IS_OK(status)) {
3569 result = ntstatus_to_werror(status);
3571 if (!W_ERROR_IS_OK(result)) {
3575 status = dcerpc_winreg_set_sz(tmp_ctx,
3581 if (!NT_STATUS_IS_OK(status)) {
3582 result = ntstatus_to_werror(status);
3584 if (!W_ERROR_IS_OK(result)) {
3588 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3592 info8.color_profiles,
3594 if (!NT_STATUS_IS_OK(status)) {
3595 result = ntstatus_to_werror(status);
3597 if (!W_ERROR_IS_OK(result)) {
3601 status = dcerpc_winreg_set_sz(tmp_ctx,
3607 if (!NT_STATUS_IS_OK(status)) {
3608 result = ntstatus_to_werror(status);
3610 if (!W_ERROR_IS_OK(result)) {
3614 status = dcerpc_winreg_set_dword(tmp_ctx,
3617 "PrinterDriverAttributes",
3618 info8.printer_driver_attributes,
3620 if (!NT_STATUS_IS_OK(status)) {
3621 result = ntstatus_to_werror(status);
3623 if (!W_ERROR_IS_OK(result)) {
3627 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3631 info8.core_driver_dependencies,
3633 if (!NT_STATUS_IS_OK(status)) {
3634 result = ntstatus_to_werror(status);
3636 if (!W_ERROR_IS_OK(result)) {
3640 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3641 &key_hnd, "MinInboxDriverVerDate",
3642 info8.min_inbox_driver_ver_date);
3643 if (!W_ERROR_IS_OK(result)) {
3647 result = winreg_printer_write_ver(tmp_ctx, winreg_handle, &key_hnd,
3648 "MinInboxDriverVerVersion",
3649 info8.min_inbox_driver_ver_version);
3650 if (!W_ERROR_IS_OK(result)) {
3654 *driver_name = info8.driver_name;
3655 *driver_version = info8.version;
3658 if (winreg_handle != NULL) {
3661 if (is_valid_policy_hnd(&key_hnd)) {
3662 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3664 if (is_valid_policy_hnd(&hive_hnd)) {
3665 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3669 TALLOC_FREE(tmp_ctx);
3673 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
3674 struct dcerpc_binding_handle *winreg_handle,
3675 const char *architecture,
3676 const char *driver_name,
3677 uint32_t driver_version,
3678 struct spoolss_DriverInfo8 **_info8)
3680 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3681 struct policy_handle hive_hnd, key_hnd;
3682 struct spoolss_DriverInfo8 i8, *info8;
3683 struct spoolss_PrinterEnumValues *enum_values = NULL;
3684 struct spoolss_PrinterEnumValues *v;
3685 uint32_t num_values = 0;
3686 TALLOC_CTX *tmp_ctx;
3690 const char **enum_names = NULL;
3691 enum winreg_Type *enum_types = NULL;
3692 DATA_BLOB *enum_data_blobs = NULL;
3694 ZERO_STRUCT(hive_hnd);
3695 ZERO_STRUCT(key_hnd);
3698 tmp_ctx = talloc_stackframe();
3699 if (tmp_ctx == NULL) {
3700 return WERR_NOT_ENOUGH_MEMORY;
3703 if (driver_version == DRIVER_ANY_VERSION) {
3704 /* look for Win2k first and then for NT4 */
3705 result = winreg_printer_opendriver(tmp_ctx,
3713 if (!W_ERROR_IS_OK(result)) {
3714 result = winreg_printer_opendriver(tmp_ctx,
3724 /* ok normal case */
3725 result = winreg_printer_opendriver(tmp_ctx,
3734 if (!W_ERROR_IS_OK(result)) {
3735 DEBUG(5, ("winreg_get_driver: "
3736 "Could not open driver key (%s,%s,%d): %s\n",
3737 driver_name, architecture,
3738 driver_version, win_errstr(result)));
3742 status = dcerpc_winreg_enumvals(tmp_ctx,
3750 if (!NT_STATUS_IS_OK(status)){
3751 result = ntstatus_to_werror(status);
3754 if (!W_ERROR_IS_OK(result)) {
3755 DEBUG(0, ("winreg_get_driver: "
3756 "Could not enumerate values for (%s,%s,%d): %s\n",
3757 driver_name, architecture,
3758 driver_version, win_errstr(result)));
3762 enum_values = talloc_zero_array(tmp_ctx,
3763 struct spoolss_PrinterEnumValues,
3765 if (enum_values == NULL){
3766 result = WERR_NOT_ENOUGH_MEMORY;
3770 for (i = 0; i < num_values; i++){
3771 enum_values[i].value_name = enum_names[i];
3772 enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
3773 enum_values[i].type = enum_types[i];
3774 enum_values[i].data_length = enum_data_blobs[i].length;
3775 enum_values[i].data = NULL;
3776 if (enum_values[i].data_length != 0){
3777 enum_values[i].data = &enum_data_blobs[i];
3781 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
3782 if (info8 == NULL) {
3783 result = WERR_NOT_ENOUGH_MEMORY;
3787 info8->driver_name = talloc_strdup(info8, driver_name);
3788 if (info8->driver_name == NULL) {
3789 result = WERR_NOT_ENOUGH_MEMORY;
3793 info8->architecture = talloc_strdup(info8, architecture);
3794 if (info8->architecture == NULL) {
3795 result = WERR_NOT_ENOUGH_MEMORY;
3801 for (i = 0; i < num_values; i++) {
3802 const char *tmp_str;
3805 v = &enum_values[i];
3807 result = winreg_enumval_to_dword(info8, v,
3810 if (W_ERROR_IS_OK(result)) {
3811 info8->version = (enum spoolss_DriverOSVersion) tmp;
3813 CHECK_ERROR(result);
3815 result = winreg_enumval_to_sz(info8, v,
3817 &info8->driver_path);
3818 CHECK_ERROR(result);
3820 result = winreg_enumval_to_sz(info8, v,
3823 CHECK_ERROR(result);
3825 result = winreg_enumval_to_sz(info8, v,
3826 "Configuration File",
3827 &info8->config_file);
3828 CHECK_ERROR(result);
3830 result = winreg_enumval_to_sz(info8, v,
3833 CHECK_ERROR(result);
3835 result = winreg_enumval_to_multi_sz(info8, v,
3837 &info8->dependent_files);
3838 CHECK_ERROR(result);
3840 result = winreg_enumval_to_sz(info8, v,
3842 &info8->monitor_name);
3843 CHECK_ERROR(result);
3845 result = winreg_enumval_to_sz(info8, v,
3847 &info8->default_datatype);
3848 CHECK_ERROR(result);
3850 result = winreg_enumval_to_multi_sz(info8, v,
3852 &info8->previous_names);
3853 CHECK_ERROR(result);
3855 result = winreg_enumval_to_sz(info8, v,
3858 if (W_ERROR_IS_OK(result)) {
3859 result = winreg_printer_date_to_NTTIME(tmp_str,
3860 &info8->driver_date);
3862 CHECK_ERROR(result);
3864 result = winreg_enumval_to_sz(info8, v,
3867 if (W_ERROR_IS_OK(result)) {
3868 result = winreg_printer_ver_to_qword(tmp_str,
3869 &info8->driver_version);
3871 CHECK_ERROR(result);
3873 result = winreg_enumval_to_sz(info8, v,
3875 &info8->manufacturer_name);
3876 CHECK_ERROR(result);
3878 result = winreg_enumval_to_sz(info8, v,
3880 &info8->manufacturer_url);
3881 CHECK_ERROR(result);
3883 result = winreg_enumval_to_sz(info8, v,
3885 &info8->hardware_id);
3886 CHECK_ERROR(result);
3888 result = winreg_enumval_to_sz(info8, v,
3891 CHECK_ERROR(result);
3893 result = winreg_enumval_to_sz(info8, v,
3895 &info8->print_processor);
3896 CHECK_ERROR(result);
3898 result = winreg_enumval_to_sz(info8, v,
3900 &info8->vendor_setup);
3901 CHECK_ERROR(result);
3903 result = winreg_enumval_to_multi_sz(info8, v,
3905 &info8->color_profiles);
3906 CHECK_ERROR(result);
3908 result = winreg_enumval_to_sz(info8, v,
3911 CHECK_ERROR(result);
3913 result = winreg_enumval_to_dword(info8, v,
3914 "PrinterDriverAttributes",
3915 &info8->printer_driver_attributes);
3916 CHECK_ERROR(result);
3918 result = winreg_enumval_to_multi_sz(info8, v,
3920 &info8->core_driver_dependencies);
3921 CHECK_ERROR(result);
3923 result = winreg_enumval_to_sz(info8, v,
3924 "MinInboxDriverVerDate",
3926 if (W_ERROR_IS_OK(result)) {
3927 result = winreg_printer_date_to_NTTIME(tmp_str,
3928 &info8->min_inbox_driver_ver_date);
3930 CHECK_ERROR(result);
3932 result = winreg_enumval_to_sz(info8, v,
3933 "MinInboxDriverVerVersion",
3935 if (W_ERROR_IS_OK(result)) {
3936 result = winreg_printer_ver_to_qword(tmp_str,
3937 &info8->min_inbox_driver_ver_version);
3939 CHECK_ERROR(result);
3942 if (!W_ERROR_IS_OK(result)) {
3943 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3944 "for %s: %s\n", v->value_name,
3945 win_errstr(result)));
3949 *_info8 = talloc_steal(mem_ctx, info8);
3952 if (winreg_handle != NULL) {
3955 if (is_valid_policy_hnd(&key_hnd)) {
3956 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3958 if (is_valid_policy_hnd(&hive_hnd)) {
3959 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3963 TALLOC_FREE(tmp_ctx);
3967 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
3968 struct dcerpc_binding_handle *winreg_handle,
3969 struct spoolss_DriverInfo8 *info8,
3972 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3973 struct policy_handle hive_hnd, key_hnd;
3974 TALLOC_CTX *tmp_ctx;
3979 ZERO_STRUCT(hive_hnd);
3980 ZERO_STRUCT(key_hnd);
3982 tmp_ctx = talloc_stackframe();
3983 if (tmp_ctx == NULL) {
3984 return WERR_NOT_ENOUGH_MEMORY;
3987 /* test that the key exists */
3988 result = winreg_printer_opendriver(tmp_ctx,
3991 info8->architecture,
3996 if (!W_ERROR_IS_OK(result)) {
3997 /* key doesn't exist */
3998 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
4003 DEBUG(5, ("winreg_del_driver: "
4004 "Could not open driver (%s,%s,%u): %s\n",
4005 info8->driver_name, info8->architecture,
4006 version, win_errstr(result)));
4011 if (is_valid_policy_hnd(&key_hnd)) {
4012 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
4015 key_name = talloc_asprintf(tmp_ctx,
4016 "%s\\Environments\\%s\\Drivers\\Version-%u\\%s",
4017 TOP_LEVEL_CONTROL_KEY,
4018 info8->architecture, version,
4019 info8->driver_name);
4020 if (key_name == NULL) {
4021 result = WERR_NOT_ENOUGH_MEMORY;
4025 status = dcerpc_winreg_delete_subkeys_recursive(tmp_ctx,
4032 if (!NT_STATUS_IS_OK(status)){
4033 DEBUG(0, ("winreg_del_driver: "
4034 "Could not open driver (%s,%s,%u): %s\n",
4035 info8->driver_name, info8->architecture,
4036 version, nt_errstr(status)));
4040 if (!W_ERROR_IS_OK(result)) {
4041 DEBUG(0, ("winreg_del_driver: "
4042 "Could not open driver (%s,%s,%u): %s\n",
4043 info8->driver_name, info8->architecture,
4044 version, win_errstr(result)));
4050 if (winreg_handle != NULL) {
4053 if (is_valid_policy_hnd(&key_hnd)) {
4054 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4056 if (is_valid_policy_hnd(&hive_hnd)) {
4057 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4061 TALLOC_FREE(tmp_ctx);
4065 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
4066 struct dcerpc_binding_handle *winreg_handle,
4067 const char *architecture,
4069 uint32_t *num_drivers,
4070 const char ***drivers_p)
4072 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4073 struct policy_handle hive_hnd, key_hnd;
4074 const char **drivers;
4075 TALLOC_CTX *tmp_ctx;
4082 ZERO_STRUCT(hive_hnd);
4083 ZERO_STRUCT(key_hnd);
4085 tmp_ctx = talloc_stackframe();
4086 if (tmp_ctx == NULL) {
4087 return WERR_NOT_ENOUGH_MEMORY;
4090 /* use NULL for the driver name so we open the key that is
4091 * parent of all drivers for this architecture and version */
4092 result = winreg_printer_opendriver(tmp_ctx,
4100 if (!W_ERROR_IS_OK(result)) {
4101 DEBUG(5, ("winreg_get_driver_list: "
4102 "Could not open key (%s,%u): %s\n",
4103 architecture, version, win_errstr(result)));
4108 status = dcerpc_winreg_enum_keys(tmp_ctx,
4114 if (!NT_STATUS_IS_OK(status)) {
4115 result = ntstatus_to_werror(status);
4117 if (!W_ERROR_IS_OK(result)) {
4118 DEBUG(0, ("winreg_get_driver_list: "
4119 "Could not enumerate drivers for (%s,%u): %s\n",
4120 architecture, version, win_errstr(result)));
4124 *drivers_p = talloc_steal(mem_ctx, drivers);
4128 if (winreg_handle != NULL) {
4131 if (is_valid_policy_hnd(&key_hnd)) {
4132 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4134 if (is_valid_policy_hnd(&hive_hnd)) {
4135 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4139 TALLOC_FREE(tmp_ctx);
4143 WERROR winreg_get_core_driver(TALLOC_CTX *mem_ctx,
4144 struct dcerpc_binding_handle *winreg_handle,
4145 const char *architecture,
4146 const struct GUID *core_driver_guid,
4147 struct spoolss_CorePrinterDriver **_core_printer_driver)
4149 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4150 struct policy_handle hive_hnd, key_hnd;
4151 struct spoolss_CorePrinterDriver *c;
4152 struct spoolss_PrinterEnumValues *enum_values = NULL;
4153 struct spoolss_PrinterEnumValues *v;
4154 uint32_t num_values = 0;
4155 TALLOC_CTX *tmp_ctx;
4159 const char *guid_str;
4161 const char **enum_names = NULL;
4162 enum winreg_Type *enum_types = NULL;
4163 DATA_BLOB *enum_data_blobs = NULL;
4165 ZERO_STRUCT(hive_hnd);
4166 ZERO_STRUCT(key_hnd);
4168 tmp_ctx = talloc_stackframe();
4169 if (tmp_ctx == NULL) {
4170 return WERR_NOT_ENOUGH_MEMORY;
4173 path = talloc_asprintf(tmp_ctx, "%s\\%s\\CorePrinterDrivers",
4174 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
4177 result = WERR_NOT_ENOUGH_MEMORY;
4181 guid_str = GUID_string2(tmp_ctx, core_driver_guid);
4182 if (guid_str == NULL) {
4183 result = WERR_NOT_ENOUGH_MEMORY;
4187 result = winreg_printer_openkey(tmp_ctx,
4196 if (!W_ERROR_IS_OK(result)) {
4197 DEBUG(5, ("winreg_get_core_driver: "
4198 "Could not open core driver key (%s,%s): %s\n",
4199 guid_str, architecture, win_errstr(result)));
4203 status = dcerpc_winreg_enumvals(tmp_ctx,
4211 if (!NT_STATUS_IS_OK(status)){
4212 result = ntstatus_to_werror(status);
4215 if (!W_ERROR_IS_OK(result)) {
4216 DEBUG(0, ("winreg_get_core_driver: "
4217 "Could not enumerate values for (%s,%s): %s\n",
4218 guid_str, architecture, win_errstr(result)));
4222 enum_values = talloc_zero_array(tmp_ctx,
4223 struct spoolss_PrinterEnumValues,
4225 if (enum_values == NULL){
4226 result = WERR_NOT_ENOUGH_MEMORY;
4230 for (i = 0; i < num_values; i++){
4231 enum_values[i].value_name = enum_names[i];
4232 enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
4233 enum_values[i].type = enum_types[i];
4234 enum_values[i].data_length = enum_data_blobs[i].length;
4235 enum_values[i].data = NULL;
4236 if (enum_values[i].data_length != 0){
4237 enum_values[i].data = &enum_data_blobs[i];
4241 c = talloc_zero(tmp_ctx, struct spoolss_CorePrinterDriver);
4243 result = WERR_NOT_ENOUGH_MEMORY;
4247 c->core_driver_guid = *core_driver_guid;
4251 for (i = 0; i < num_values; i++) {
4252 const char *tmp_str;
4254 v = &enum_values[i];
4256 result = winreg_enumval_to_sz(c, v,
4259 CHECK_ERROR(result);
4261 result = winreg_enumval_to_sz(c, v,
4264 if (W_ERROR_IS_OK(result)) {
4265 result = winreg_printer_date_to_NTTIME(tmp_str,
4268 CHECK_ERROR(result);
4270 result = winreg_enumval_to_sz(c, v,
4273 if (W_ERROR_IS_OK(result)) {
4274 result = winreg_printer_ver_to_qword(tmp_str,
4275 &c->driver_version);
4277 CHECK_ERROR(result);
4280 if (!W_ERROR_IS_OK(result)) {
4281 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4282 "for %s: %s\n", v->value_name,
4283 win_errstr(result)));
4287 *_core_printer_driver = talloc_steal(mem_ctx, c);
4290 if (winreg_handle != NULL) {
4293 if (is_valid_policy_hnd(&key_hnd)) {
4294 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4296 if (is_valid_policy_hnd(&hive_hnd)) {
4297 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4301 TALLOC_FREE(tmp_ctx);
4305 WERROR winreg_add_core_driver(TALLOC_CTX *mem_ctx,
4306 struct dcerpc_binding_handle *winreg_handle,
4307 const char *architecture,
4308 const struct spoolss_CorePrinterDriver *r)
4310 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4311 struct policy_handle hive_hnd, key_hnd;
4312 TALLOC_CTX *tmp_ctx = NULL;
4315 const char *guid_str;
4317 ZERO_STRUCT(hive_hnd);
4318 ZERO_STRUCT(key_hnd);
4320 tmp_ctx = talloc_stackframe();
4321 if (tmp_ctx == NULL) {
4322 return WERR_NOT_ENOUGH_MEMORY;
4325 guid_str = GUID_string2(tmp_ctx, &r->core_driver_guid);
4326 if (guid_str == NULL) {
4327 result = WERR_NOT_ENOUGH_MEMORY;
4331 result = winreg_printer_open_core_driver(tmp_ctx,
4338 if (!W_ERROR_IS_OK(result)) {
4339 DEBUG(0, ("winreg_add_core_driver: "
4340 "Could not open core driver key (%s,%s): %s\n",
4341 guid_str, architecture, win_errstr(result)));
4345 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
4346 &key_hnd, "DriverDate",
4348 if (!W_ERROR_IS_OK(result)) {
4352 result = winreg_printer_write_ver(tmp_ctx, winreg_handle,
4353 &key_hnd, "DriverVersion",
4355 if (!W_ERROR_IS_OK(result)) {
4359 status = dcerpc_winreg_set_sz(tmp_ctx,
4365 if (!NT_STATUS_IS_OK(status)) {
4366 result = ntstatus_to_werror(status);
4368 if (!W_ERROR_IS_OK(result)) {
4374 if (winreg_handle != NULL) {
4377 if (is_valid_policy_hnd(&key_hnd)) {
4378 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4380 if (is_valid_policy_hnd(&hive_hnd)) {
4381 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4385 TALLOC_FREE(tmp_ctx);
4389 WERROR winreg_add_driver_package(TALLOC_CTX *mem_ctx,
4390 struct dcerpc_binding_handle *winreg_handle,
4391 const char *package_id,
4392 const char *architecture,
4393 const char *driver_store_path,
4394 const char *cab_path)
4396 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4397 struct policy_handle hive_hnd, key_hnd;
4398 TALLOC_CTX *tmp_ctx = NULL;
4403 ZERO_STRUCT(hive_hnd);
4404 ZERO_STRUCT(key_hnd);
4406 tmp_ctx = talloc_stackframe();
4407 if (tmp_ctx == NULL) {
4408 return WERR_NOT_ENOUGH_MEMORY;
4411 path = talloc_asprintf(tmp_ctx, "%s\\%s\\DriverPackages",
4412 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
4415 result = WERR_NOT_ENOUGH_MEMORY;
4419 result = winreg_printer_openkey(tmp_ctx,
4422 package_id, /* key */
4428 if (!W_ERROR_IS_OK(result)) {
4429 DEBUG(0, ("winreg_add_driver_package: "
4430 "Could not open driver package key (%s,%s): %s\n",
4431 package_id, architecture, win_errstr(result)));
4435 status = dcerpc_winreg_set_sz(tmp_ctx,
4441 if (!NT_STATUS_IS_OK(status)) {
4442 result = ntstatus_to_werror(status);
4444 if (!W_ERROR_IS_OK(result)) {
4448 status = dcerpc_winreg_set_sz(tmp_ctx,
4454 if (!NT_STATUS_IS_OK(status)) {
4455 result = ntstatus_to_werror(status);
4457 if (!W_ERROR_IS_OK(result)) {
4463 if (winreg_handle != NULL) {
4466 if (is_valid_policy_hnd(&key_hnd)) {
4467 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4469 if (is_valid_policy_hnd(&hive_hnd)) {
4470 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4474 TALLOC_FREE(tmp_ctx);
4478 WERROR winreg_get_driver_package(TALLOC_CTX *mem_ctx,
4479 struct dcerpc_binding_handle *winreg_handle,
4480 const char *package_id,
4481 const char *architecture,
4482 const char **driver_store_path,
4483 const char **cab_path)
4485 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4486 struct policy_handle hive_hnd, key_hnd;
4487 struct spoolss_PrinterEnumValues *enum_values = NULL;
4488 struct spoolss_PrinterEnumValues *v;
4489 uint32_t num_values = 0;
4490 TALLOC_CTX *tmp_ctx;
4495 const char **enum_names = NULL;
4496 enum winreg_Type *enum_types = NULL;
4497 DATA_BLOB *enum_data_blobs = NULL;
4499 ZERO_STRUCT(hive_hnd);
4500 ZERO_STRUCT(key_hnd);
4502 tmp_ctx = talloc_stackframe();
4503 if (tmp_ctx == NULL) {
4504 return WERR_NOT_ENOUGH_MEMORY;
4507 path = talloc_asprintf(tmp_ctx, "%s\\%s\\DriverPackages",
4508 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
4511 result = WERR_NOT_ENOUGH_MEMORY;
4515 result = winreg_printer_openkey(tmp_ctx,
4518 package_id, /* key */
4524 if (!W_ERROR_IS_OK(result)) {
4525 DEBUG(5, ("winreg_get_driver_package: "
4526 "Could not open driver package key (%s,%s): %s\n",
4527 package_id, architecture, win_errstr(result)));
4531 status = dcerpc_winreg_enumvals(tmp_ctx,
4539 if (!NT_STATUS_IS_OK(status)){
4540 result = ntstatus_to_werror(status);
4543 if (!W_ERROR_IS_OK(result)) {
4544 DEBUG(0, ("winreg_get_driver_package: "
4545 "Could not enumerate values for (%s,%s): %s\n",
4546 package_id, architecture, win_errstr(result)));
4550 enum_values = talloc_zero_array(tmp_ctx,
4551 struct spoolss_PrinterEnumValues,
4553 if (enum_values == NULL){
4554 result = WERR_NOT_ENOUGH_MEMORY;
4558 for (i = 0; i < num_values; i++){
4559 enum_values[i].value_name = enum_names[i];
4560 enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
4561 enum_values[i].type = enum_types[i];
4562 enum_values[i].data_length = enum_data_blobs[i].length;
4563 enum_values[i].data = NULL;
4564 if (enum_values[i].data_length != 0){
4565 enum_values[i].data = &enum_data_blobs[i];
4571 for (i = 0; i < num_values; i++) {
4573 v = &enum_values[i];
4575 result = winreg_enumval_to_sz(mem_ctx, v,
4578 CHECK_ERROR(result);
4580 result = winreg_enumval_to_sz(mem_ctx, v,
4583 CHECK_ERROR(result);
4586 if (!W_ERROR_IS_OK(result)) {
4587 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4588 "for %s: %s\n", v->value_name,
4589 win_errstr(result)));
4595 if (winreg_handle != NULL) {
4598 if (is_valid_policy_hnd(&key_hnd)) {
4599 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4601 if (is_valid_policy_hnd(&hive_hnd)) {
4602 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4606 TALLOC_FREE(tmp_ctx);
4610 WERROR winreg_del_driver_package(TALLOC_CTX *mem_ctx,
4611 struct dcerpc_binding_handle *winreg_handle,
4612 const char *package_id,
4613 const char *architecture)
4615 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4616 struct policy_handle hive_hnd, key_hnd;
4617 TALLOC_CTX *tmp_ctx;
4622 ZERO_STRUCT(hive_hnd);
4623 ZERO_STRUCT(key_hnd);
4625 tmp_ctx = talloc_stackframe();
4626 if (tmp_ctx == NULL) {
4627 return WERR_NOT_ENOUGH_MEMORY;
4630 path = talloc_asprintf(tmp_ctx, "%s\\%s\\DriverPackages",
4631 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
4634 result = WERR_NOT_ENOUGH_MEMORY;
4638 result = winreg_printer_openkey(tmp_ctx,
4641 package_id, /* key */
4646 if (!W_ERROR_IS_OK(result)) {
4647 /* key doesn't exist */
4648 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
4653 DEBUG(5, ("winreg_del_driver_package: "
4654 "Could not open driver package key (%s,%s): %s\n",
4655 package_id, architecture, win_errstr(result)));
4660 if (is_valid_policy_hnd(&key_hnd)) {
4661 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
4664 path = talloc_asprintf(tmp_ctx, "%s\\%s\\DriverPackages\\%s",
4665 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
4669 result = WERR_NOT_ENOUGH_MEMORY;
4673 status = dcerpc_winreg_delete_subkeys_recursive(tmp_ctx,
4679 if (!NT_STATUS_IS_OK(status)) {
4680 result = ntstatus_to_werror(status);
4681 DEBUG(5, ("winreg_del_driver_package: "
4682 "Could not delete driver package key (%s,%s): %s\n",
4683 package_id, architecture, nt_errstr(status)));
4687 if (!W_ERROR_IS_OK(result)) {
4688 DEBUG(5, ("winreg_del_driver_package: "
4689 "Could not delete driver package key (%s,%s): %s\n",
4690 package_id, architecture, win_errstr(result)));
4696 if (winreg_handle != NULL) {
4699 if (is_valid_policy_hnd(&key_hnd)) {
4700 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4702 if (is_valid_policy_hnd(&hive_hnd)) {
4703 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4707 TALLOC_FREE(tmp_ctx);