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 EMPTY_STRING ""
43 #define FILL_STRING(mem_ctx, in, out) \
45 if (in && strlen(in)) { \
46 out = talloc_strdup(mem_ctx, in); \
48 out = talloc_strdup(mem_ctx, ""); \
50 W_ERROR_HAVE_NO_MEMORY(out); \
53 #define CHECK_ERROR(result) \
54 if (W_ERROR_IS_OK(result)) continue; \
55 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
56 if (!W_ERROR_IS_OK(result)) break
58 /* FLAGS, NAME, with, height, left, top, right, bottom */
59 static const struct spoolss_FormInfo1 builtin_forms1[] = {
60 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
61 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
62 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
63 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
64 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
65 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
66 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
67 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
68 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
69 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
70 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
71 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
72 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
73 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
74 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
75 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
76 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
77 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
78 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
79 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
80 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
81 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
82 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
83 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
84 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
85 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
86 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
87 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
88 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
89 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
90 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
91 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
92 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
93 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
94 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
95 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
96 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
97 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
98 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} },
99 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
100 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
101 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
102 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
103 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
104 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
105 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
106 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
107 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
108 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
109 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
110 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
111 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
112 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
113 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
114 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
115 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
116 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
117 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
118 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
119 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
120 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
121 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
122 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
123 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
124 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
125 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
126 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
127 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
128 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
129 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
130 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
131 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
132 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
133 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
134 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
135 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
136 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
137 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
138 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
139 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
140 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
141 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
142 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
143 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
144 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
145 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
146 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
147 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
148 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
149 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
150 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
151 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
152 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
153 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
154 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
159 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
160 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
161 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
162 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
163 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
164 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
165 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
166 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
167 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
168 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
169 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
170 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
171 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
172 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
173 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
174 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
175 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
176 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
177 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} }
180 /********************************************************************
181 static helper functions
182 ********************************************************************/
184 /****************************************************************************
185 Update the changeid time.
186 ****************************************************************************/
190 * @brief Update the ChangeID time of a printer.
192 * This is SO NASTY as some drivers need this to change, others need it
193 * static. This value will change every second, and I must hope that this
194 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
197 * @return The ChangeID.
199 static uint32_t winreg_printer_rev_changeid(void)
203 get_process_uptime(&tv);
206 /* Return changeid as msec since spooler restart */
207 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
210 * This setting seems to work well but is too untested
211 * to replace the above calculation. Left in for experimentation
212 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
214 return tv.tv_sec * 10 + tv.tv_usec / 100000;
218 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
219 struct dcerpc_binding_handle *binding_handle,
223 uint32_t access_mask,
224 struct policy_handle *hive_handle,
225 struct policy_handle *key_handle)
227 struct winreg_String wkey, wkeyclass;
230 WERROR result = WERR_OK;
232 status = dcerpc_winreg_OpenHKLM(binding_handle,
238 if (!NT_STATUS_IS_OK(status)) {
239 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
241 return ntstatus_to_werror(status);
243 if (!W_ERROR_IS_OK(result)) {
244 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
245 win_errstr(result)));
250 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
252 keyname = talloc_strdup(mem_ctx, path);
254 if (keyname == NULL) {
255 return WERR_NOT_ENOUGH_MEMORY;
262 enum winreg_CreateAction action = REG_ACTION_NONE;
264 ZERO_STRUCT(wkeyclass);
267 status = dcerpc_winreg_CreateKey(binding_handle,
279 case REG_ACTION_NONE:
280 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
282 case REG_CREATED_NEW_KEY:
283 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
285 case REG_OPENED_EXISTING_KEY:
286 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
290 status = dcerpc_winreg_OpenKey(binding_handle,
299 if (!NT_STATUS_IS_OK(status)) {
300 result = ntstatus_to_werror(status);
302 if (!W_ERROR_IS_OK(result)) {
305 if (is_valid_policy_hnd(hive_handle)) {
306 dcerpc_winreg_CloseKey(binding_handle,
311 ZERO_STRUCTP(hive_handle);
320 * @brief Create the registry keyname for the given printer.
322 * @param[in] mem_ctx The memory context to use.
324 * @param[in] printer The name of the printer to get the registry key.
326 * @return The registry key or NULL on error.
328 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
329 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
332 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
333 struct dcerpc_binding_handle *winreg_handle,
334 const char *drivername,
335 const char *architecture,
337 uint32_t access_mask,
339 struct policy_handle *hive_hnd,
340 struct policy_handle *key_hnd)
345 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
346 TOP_LEVEL_CONTROL_KEY,
347 architecture, version);
349 return WERR_NOT_ENOUGH_MEMORY;
352 result = winreg_printer_openkey(mem_ctx,
363 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
364 struct spoolss_PrinterEnumValues *v,
365 const char *valuename, uint32_t *dw)
367 /* just return if it is not the one we are looking for */
368 if (strcmp(valuename, v->value_name) != 0) {
369 return WERR_NOT_FOUND;
372 if (v->type != REG_DWORD) {
373 return WERR_INVALID_DATATYPE;
376 if (v->data_length != 4) {
381 *dw = IVAL(v->data->data, 0);
385 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
386 struct spoolss_PrinterEnumValues *v,
387 const char *valuename, const char **_str)
389 /* just return if it is not the one we are looking for */
390 if (strcmp(valuename, v->value_name) != 0) {
391 return WERR_NOT_FOUND;
394 if (v->type != REG_SZ) {
395 return WERR_INVALID_DATATYPE;
398 if (v->data_length == 0) {
399 *_str = talloc_strdup(mem_ctx, EMPTY_STRING);
401 return WERR_NOT_ENOUGH_MEMORY;
406 if (!pull_reg_sz(mem_ctx, v->data, _str)) {
407 return WERR_NOT_ENOUGH_MEMORY;
413 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
414 struct spoolss_PrinterEnumValues *v,
415 const char *valuename,
418 /* just return if it is not the one we are looking for */
419 if (strcmp(valuename, v->value_name) != 0) {
420 return WERR_NOT_FOUND;
423 if (v->type != REG_MULTI_SZ) {
424 return WERR_INVALID_DATATYPE;
427 if (v->data_length == 0) {
428 *array = talloc_array(mem_ctx, const char *, 1);
429 if (*array == NULL) {
430 return WERR_NOT_ENOUGH_MEMORY;
436 if (!pull_reg_multi_sz(mem_ctx, v->data, array)) {
437 return WERR_NOT_ENOUGH_MEMORY;
443 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
444 struct dcerpc_binding_handle *winreg_handle,
445 struct policy_handle *key_handle,
449 struct winreg_String wvalue = { 0, };
451 WERROR result = WERR_OK;
458 str = talloc_strdup(mem_ctx, "01/01/1601");
460 t = nt_time_to_unix(data);
463 return map_werror_from_unix(errno);
465 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
466 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
469 return WERR_NOT_ENOUGH_MEMORY;
473 if (!push_reg_sz(mem_ctx, &blob, str)) {
474 return WERR_NOT_ENOUGH_MEMORY;
476 status = dcerpc_winreg_SetValue(winreg_handle,
484 if (!NT_STATUS_IS_OK(status)) {
485 result = ntstatus_to_werror(status);
487 if (!W_ERROR_IS_OK(result)) {
488 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
489 wvalue.name, win_errstr(result)));
495 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
499 ok = spoolss_timestr_to_NTTIME(str, data);
501 return WERR_INVALID_PARAMETER;
507 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
508 struct dcerpc_binding_handle *winreg_handle,
509 struct policy_handle *key_handle,
513 struct winreg_String wvalue = { 0, };
515 WERROR result = WERR_OK;
520 * this needs to be something like: 6.1.7600.16385
522 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
523 (unsigned)((data >> 48) & 0xFFFF),
524 (unsigned)((data >> 32) & 0xFFFF),
525 (unsigned)((data >> 16) & 0xFFFF),
526 (unsigned)(data & 0xFFFF));
528 return WERR_NOT_ENOUGH_MEMORY;
532 if (!push_reg_sz(mem_ctx, &blob, str)) {
533 return WERR_NOT_ENOUGH_MEMORY;
535 status = dcerpc_winreg_SetValue(winreg_handle,
543 if (!NT_STATUS_IS_OK(status)) {
544 result = ntstatus_to_werror(status);
546 if (!W_ERROR_IS_OK(result)) {
547 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
548 wvalue.name, win_errstr(result)));
554 static WERROR winreg_printer_ver_to_qword(const char *str, uint64_t *data)
558 ok = spoolss_driver_version_to_qword(str, data);
560 return WERR_INVALID_PARAMETER;
566 /********************************************************************
567 Public winreg function for spoolss
568 ********************************************************************/
570 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
571 struct dcerpc_binding_handle *winreg_handle,
572 const char *sharename)
574 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
575 struct policy_handle hive_hnd, key_hnd;
576 struct spoolss_SetPrinterInfo2 *info2;
577 struct security_descriptor *secdesc;
578 struct winreg_String wkey, wkeyclass;
580 const char *subkeys[] = { SPOOL_DSDRIVER_KEY, SPOOL_DSSPOOLER_KEY, SPOOL_PRINTERDATA_KEY };
581 uint32_t i, count = ARRAY_SIZE(subkeys);
582 uint32_t info2_mask = 0;
583 WERROR result = WERR_OK;
587 tmp_ctx = talloc_stackframe();
588 if (tmp_ctx == NULL) {
589 return WERR_NOT_ENOUGH_MEMORY;
592 path = winreg_printer_data_keyname(tmp_ctx, sharename);
594 TALLOC_FREE(tmp_ctx);
595 return WERR_NOT_ENOUGH_MEMORY;
598 ZERO_STRUCT(hive_hnd);
599 ZERO_STRUCT(key_hnd);
601 result = winreg_printer_openkey(tmp_ctx,
609 if (W_ERROR_IS_OK(result)) {
610 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
612 } else if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
613 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
614 } else if (!W_ERROR_IS_OK(result)) {
615 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
616 path, win_errstr(result)));
620 if (is_valid_policy_hnd(&key_hnd)) {
621 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
623 if (is_valid_policy_hnd(&hive_hnd)) {
624 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
627 /* Create the main key */
628 result = winreg_printer_openkey(tmp_ctx,
636 if (!W_ERROR_IS_OK(result)) {
637 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
638 path, win_errstr(result)));
642 if (is_valid_policy_hnd(&key_hnd)) {
643 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
647 for (i = 0; i < count; i++) {
649 enum winreg_CreateAction action = REG_ACTION_NONE;
651 ZERO_STRUCT(key_hnd);
654 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
655 if (wkey.name == NULL) {
656 result = WERR_NOT_ENOUGH_MEMORY;
660 ZERO_STRUCT(wkeyclass);
663 status = dcerpc_winreg_CreateKey(winreg_handle,
674 if (!NT_STATUS_IS_OK(status)) {
675 result = ntstatus_to_werror(status);
677 if (!W_ERROR_IS_OK(result)) {
678 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
679 wkey.name, win_errstr(result)));
683 if (strequal(subkeys[i], SPOOL_DSSPOOLER_KEY)) {
684 const char *dnssuffix;
685 const char *longname;
688 status = dcerpc_winreg_set_sz(tmp_ctx,
691 SPOOL_REG_PRINTERNAME,
694 if (!NT_STATUS_IS_OK(status)) {
695 result = ntstatus_to_werror(status);
697 if (!W_ERROR_IS_OK(result)) {
701 status = dcerpc_winreg_set_sz(tmp_ctx,
704 SPOOL_REG_SHORTSERVERNAME,
707 if (!NT_STATUS_IS_OK(status)) {
708 result = ntstatus_to_werror(status);
710 if (!W_ERROR_IS_OK(result)) {
714 /* We make the assumption that the netbios name
715 * is the same as the DNS name since the former
716 * will be what we used to join the domain
718 dnssuffix = get_mydnsdomname(tmp_ctx);
719 if (dnssuffix != NULL && dnssuffix[0] != '\0') {
720 longname = talloc_asprintf(tmp_ctx, "%s.%s", lp_netbios_name(), dnssuffix);
722 longname = talloc_strdup(tmp_ctx, lp_netbios_name());
724 if (longname == NULL) {
725 result = WERR_NOT_ENOUGH_MEMORY;
729 status = dcerpc_winreg_set_sz(tmp_ctx,
732 SPOOL_REG_SERVERNAME,
735 if (!NT_STATUS_IS_OK(status)) {
736 result = ntstatus_to_werror(status);
738 if (!W_ERROR_IS_OK(result)) {
742 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
743 longname, sharename);
744 if (uncname == NULL) {
745 result = WERR_NOT_ENOUGH_MEMORY;
749 status = dcerpc_winreg_set_sz(tmp_ctx,
755 if (!NT_STATUS_IS_OK(status)) {
756 result = ntstatus_to_werror(status);
758 if (!W_ERROR_IS_OK(result)) {
762 status = dcerpc_winreg_set_dword(tmp_ctx,
765 SPOOL_REG_VERSIONNUMBER,
768 if (!NT_STATUS_IS_OK(status)) {
769 result = ntstatus_to_werror(status);
771 if (!W_ERROR_IS_OK(result)) {
775 status = dcerpc_winreg_set_dword(tmp_ctx,
778 SPOOL_REG_PRINTSTARTTIME,
781 if (!NT_STATUS_IS_OK(status)) {
782 result = ntstatus_to_werror(status);
784 if (!W_ERROR_IS_OK(result)) {
788 status = dcerpc_winreg_set_dword(tmp_ctx,
791 SPOOL_REG_PRINTENDTIME,
794 if (!NT_STATUS_IS_OK(status)) {
795 result = ntstatus_to_werror(status);
797 if (!W_ERROR_IS_OK(result)) {
801 status = dcerpc_winreg_set_dword(tmp_ctx,
807 if (!NT_STATUS_IS_OK(status)) {
808 result = ntstatus_to_werror(status);
810 if (!W_ERROR_IS_OK(result)) {
814 status = dcerpc_winreg_set_dword(tmp_ctx,
817 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
820 if (!NT_STATUS_IS_OK(status)) {
821 result = ntstatus_to_werror(status);
823 if (!W_ERROR_IS_OK(result)) {
828 if (is_valid_policy_hnd(&key_hnd)) {
829 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
832 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
834 result = WERR_NOT_ENOUGH_MEMORY;
838 info2->printername = sharename;
839 if (info2->printername == NULL) {
840 result = WERR_NOT_ENOUGH_MEMORY;
843 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
845 info2->sharename = sharename;
846 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
848 info2->portname = SAMBA_PRINTER_PORT_NAME;
849 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
851 info2->printprocessor = "winprint";
852 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
854 info2->datatype = "RAW";
855 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
858 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
860 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
861 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
863 info2->starttime = 0; /* Minutes since 12:00am GMT */
864 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
866 info2->untiltime = 0; /* Minutes since 12:00am GMT */
867 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
870 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
872 info2->defaultpriority = 1;
873 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
875 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
876 if (!W_ERROR_IS_OK(result)) {
879 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
882 * Don't write a default Device Mode to the registry! The Device Mode is
883 * only written to disk with a SetPrinter level 2 or 8.
886 result = winreg_update_printer(tmp_ctx,
895 if (is_valid_policy_hnd(&key_hnd)) {
896 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
898 if (is_valid_policy_hnd(&hive_hnd)) {
899 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
902 talloc_free(tmp_ctx);
906 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
907 struct dcerpc_binding_handle *winreg_handle,
908 const char *sharename,
910 struct spoolss_SetPrinterInfo2 *info2,
911 struct spoolss_DeviceMode *devmode,
912 struct security_descriptor *secdesc)
914 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
915 struct policy_handle hive_hnd, key_hnd;
916 int snum = lp_servicenumber(sharename);
917 enum ndr_err_code ndr_err;
920 WERROR result = WERR_OK;
925 tmp_ctx = talloc_stackframe();
926 if (tmp_ctx == NULL) {
927 return WERR_NOT_ENOUGH_MEMORY;
930 path = winreg_printer_data_keyname(tmp_ctx, sharename);
932 TALLOC_FREE(tmp_ctx);
933 return WERR_NOT_ENOUGH_MEMORY;
936 ZERO_STRUCT(hive_hnd);
937 ZERO_STRUCT(key_hnd);
939 result = winreg_printer_openkey(tmp_ctx,
947 if (!W_ERROR_IS_OK(result)) {
948 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
949 path, win_errstr(result)));
953 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
954 status = dcerpc_winreg_set_dword(tmp_ctx,
960 if (!NT_STATUS_IS_OK(status)) {
961 result = ntstatus_to_werror(status);
963 if (!W_ERROR_IS_OK(result)) {
969 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
970 status = dcerpc_winreg_set_dword(tmp_ctx,
976 if (!NT_STATUS_IS_OK(status)) {
977 result = ntstatus_to_werror(status);
979 if (!W_ERROR_IS_OK(result)) {
985 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
986 status = dcerpc_winreg_set_sz(tmp_ctx,
992 if (!NT_STATUS_IS_OK(status)) {
993 result = ntstatus_to_werror(status);
995 if (!W_ERROR_IS_OK(result)) {
1000 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1001 status = dcerpc_winreg_set_sz(tmp_ctx,
1007 if (!NT_STATUS_IS_OK(status)) {
1008 result = ntstatus_to_werror(status);
1010 if (!W_ERROR_IS_OK(result)) {
1015 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1016 status = dcerpc_winreg_set_dword(tmp_ctx,
1020 info2->defaultpriority,
1022 if (!NT_STATUS_IS_OK(status)) {
1023 result = ntstatus_to_werror(status);
1025 if (!W_ERROR_IS_OK(result)) {
1030 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1032 * Some client drivers freak out if there is a NULL devmode
1033 * (probably the driver is not checking before accessing
1034 * the devmode pointer) --jerry
1036 if (devmode == NULL && lp_default_devmode(snum) && info2 != NULL) {
1037 result = spoolss_create_default_devmode(tmp_ctx,
1040 if (!W_ERROR_IS_OK(result)) {
1045 if (devmode->size != (ndr_size_spoolss_DeviceMode(devmode, 0) - devmode->__driverextra_length)) {
1046 result = WERR_INVALID_PARAMETER;
1050 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, devmode,
1051 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1052 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1053 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1054 result = WERR_NOT_ENOUGH_MEMORY;
1058 status = dcerpc_winreg_set_binary(tmp_ctx,
1064 if (!NT_STATUS_IS_OK(status)) {
1065 result = ntstatus_to_werror(status);
1067 if (!W_ERROR_IS_OK(result)) {
1072 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1073 status = dcerpc_winreg_set_sz(tmp_ctx,
1079 if (!NT_STATUS_IS_OK(status)) {
1080 result = ntstatus_to_werror(status);
1082 if (!W_ERROR_IS_OK(result)) {
1087 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1088 status = dcerpc_winreg_set_sz(tmp_ctx,
1094 if (!NT_STATUS_IS_OK(status)) {
1095 result = ntstatus_to_werror(status);
1097 if (!W_ERROR_IS_OK(result)) {
1102 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1103 status = dcerpc_winreg_set_sz(tmp_ctx,
1109 if (!NT_STATUS_IS_OK(status)) {
1110 result = ntstatus_to_werror(status);
1112 if (!W_ERROR_IS_OK(result)) {
1117 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1118 status = dcerpc_winreg_set_sz(tmp_ctx,
1124 if (!NT_STATUS_IS_OK(status)) {
1125 result = ntstatus_to_werror(status);
1127 if (!W_ERROR_IS_OK(result)) {
1132 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1134 * in addprinter: no servername and the printer is the name
1135 * in setprinter: servername is \\server
1136 * and printer is \\server\\printer
1138 * Samba manages only local printers.
1139 * we currently don't support things like i
1140 * path=\\other_server\printer
1142 * We only store the printername, not \\server\printername
1144 const char *p = strrchr(info2->printername, '\\');
1146 p = info2->printername;
1150 status = dcerpc_winreg_set_sz(tmp_ctx,
1156 if (!NT_STATUS_IS_OK(status)) {
1157 result = ntstatus_to_werror(status);
1159 if (!W_ERROR_IS_OK(result)) {
1164 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1165 status = dcerpc_winreg_set_sz(tmp_ctx,
1169 info2->printprocessor,
1171 if (!NT_STATUS_IS_OK(status)) {
1172 result = ntstatus_to_werror(status);
1174 if (!W_ERROR_IS_OK(result)) {
1179 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1180 status = dcerpc_winreg_set_dword(tmp_ctx,
1186 if (!NT_STATUS_IS_OK(status)) {
1187 result = ntstatus_to_werror(status);
1189 if (!W_ERROR_IS_OK(result)) {
1194 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1196 * We need a security descriptor, if it isn't specified by
1197 * AddPrinter{Ex} then create a default descriptor.
1199 if (secdesc == NULL) {
1200 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1201 if (!W_ERROR_IS_OK(result)) {
1205 result = winreg_set_printer_secdesc(tmp_ctx,
1209 if (!W_ERROR_IS_OK(result)) {
1214 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1215 status = dcerpc_winreg_set_sz(tmp_ctx,
1221 if (!NT_STATUS_IS_OK(status)) {
1222 result = ntstatus_to_werror(status);
1224 if (!W_ERROR_IS_OK(result)) {
1229 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1230 status = dcerpc_winreg_set_sz(tmp_ctx,
1236 if (!NT_STATUS_IS_OK(status)) {
1237 result = ntstatus_to_werror(status);
1239 if (!W_ERROR_IS_OK(result)) {
1244 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1245 status = dcerpc_winreg_set_dword(tmp_ctx,
1251 if (!NT_STATUS_IS_OK(status)) {
1252 result = ntstatus_to_werror(status);
1254 if (!W_ERROR_IS_OK(result)) {
1259 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1260 status = dcerpc_winreg_set_dword(tmp_ctx,
1266 if (!NT_STATUS_IS_OK(status)) {
1267 result = ntstatus_to_werror(status);
1269 if (!W_ERROR_IS_OK(result)) {
1274 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1275 status = dcerpc_winreg_set_dword(tmp_ctx,
1281 if (!NT_STATUS_IS_OK(status)) {
1282 result = ntstatus_to_werror(status);
1284 if (!W_ERROR_IS_OK(result)) {
1289 status = dcerpc_winreg_set_dword(tmp_ctx,
1293 winreg_printer_rev_changeid(),
1295 if (!NT_STATUS_IS_OK(status)) {
1296 result = ntstatus_to_werror(status);
1298 if (!W_ERROR_IS_OK(result)) {
1304 if (is_valid_policy_hnd(&key_hnd)) {
1305 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1307 if (is_valid_policy_hnd(&hive_hnd)) {
1308 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1311 TALLOC_FREE(tmp_ctx);
1315 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1316 struct dcerpc_binding_handle *winreg_handle,
1317 const char *printer,
1318 struct spoolss_PrinterInfo2 **pinfo2)
1320 struct spoolss_PrinterInfo2 *info2;
1321 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1322 struct policy_handle hive_hnd, key_hnd;
1323 struct spoolss_PrinterEnumValues enum_value;
1324 struct spoolss_PrinterEnumValues *v = NULL;
1325 enum ndr_err_code ndr_err;
1327 int snum = lp_servicenumber(printer);
1328 uint32_t num_values = 0;
1332 WERROR result = WERR_OK;
1334 const char **enum_names = NULL;
1335 enum winreg_Type *enum_types = NULL;
1336 DATA_BLOB *enum_data_blobs = NULL;
1337 TALLOC_CTX *tmp_ctx;
1339 tmp_ctx = talloc_stackframe();
1340 if (tmp_ctx == NULL) {
1341 return WERR_NOT_ENOUGH_MEMORY;
1344 path = winreg_printer_data_keyname(tmp_ctx, printer);
1346 TALLOC_FREE(tmp_ctx);
1347 return WERR_NOT_ENOUGH_MEMORY;
1350 result = winreg_printer_openkey(tmp_ctx,
1358 if (!W_ERROR_IS_OK(result)) {
1359 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
1360 path, win_errstr(result)));
1364 status = dcerpc_winreg_enumvals(tmp_ctx,
1372 if (!NT_STATUS_IS_OK(status)){
1373 result = ntstatus_to_werror(status);
1376 if (!W_ERROR_IS_OK(result)) {
1377 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1378 path, win_errstr(result)));
1382 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
1383 if (info2 == NULL) {
1384 result = WERR_NOT_ENOUGH_MEMORY;
1388 FILL_STRING(info2, EMPTY_STRING, info2->servername);
1389 FILL_STRING(info2, EMPTY_STRING, info2->printername);
1390 FILL_STRING(info2, EMPTY_STRING, info2->sharename);
1391 FILL_STRING(info2, EMPTY_STRING, info2->portname);
1392 FILL_STRING(info2, EMPTY_STRING, info2->drivername);
1393 FILL_STRING(info2, EMPTY_STRING, info2->comment);
1394 FILL_STRING(info2, EMPTY_STRING, info2->location);
1395 FILL_STRING(info2, EMPTY_STRING, info2->sepfile);
1396 FILL_STRING(info2, EMPTY_STRING, info2->printprocessor);
1397 FILL_STRING(info2, EMPTY_STRING, info2->datatype);
1398 FILL_STRING(info2, EMPTY_STRING, info2->parameters);
1400 for (i = 0; i < num_values; i++) {
1401 enum_value.value_name = enum_names[i];
1402 enum_value.value_name_len = 2*strlen_m_term(enum_names[i]);
1403 enum_value.type = enum_types[i];
1404 enum_value.data_length = enum_data_blobs[i].length;
1405 enum_value.data = NULL;
1406 if (enum_value.data_length != 0){
1407 enum_value.data = &enum_data_blobs[i];
1411 result = winreg_enumval_to_sz(info2,
1414 &info2->printername);
1415 CHECK_ERROR(result);
1417 result = winreg_enumval_to_sz(info2,
1421 CHECK_ERROR(result);
1423 result = winreg_enumval_to_sz(info2,
1427 CHECK_ERROR(result);
1429 result = winreg_enumval_to_sz(info2,
1433 CHECK_ERROR(result);
1435 result = winreg_enumval_to_sz(info2,
1439 CHECK_ERROR(result);
1441 result = winreg_enumval_to_sz(info2,
1445 CHECK_ERROR(result);
1447 result = winreg_enumval_to_sz(info2,
1450 &info2->printprocessor);
1451 CHECK_ERROR(result);
1453 result = winreg_enumval_to_sz(info2,
1457 CHECK_ERROR(result);
1459 result = winreg_enumval_to_sz(info2,
1462 &info2->parameters);
1463 CHECK_ERROR(result);
1465 result = winreg_enumval_to_sz(info2,
1468 &info2->drivername);
1469 CHECK_ERROR(result);
1471 result = winreg_enumval_to_dword(info2,
1474 &info2->attributes);
1475 CHECK_ERROR(result);
1477 result = winreg_enumval_to_dword(info2,
1481 CHECK_ERROR(result);
1483 result = winreg_enumval_to_dword(info2,
1486 &info2->defaultpriority);
1487 CHECK_ERROR(result);
1489 result = winreg_enumval_to_dword(info2,
1493 CHECK_ERROR(result);
1495 result = winreg_enumval_to_dword(info2,
1499 CHECK_ERROR(result);
1501 result = winreg_enumval_to_dword(info2,
1505 CHECK_ERROR(result);
1507 result = winreg_enumval_to_dword(info2,
1511 CHECK_ERROR(result);
1514 if (!W_ERROR_IS_OK(result)) {
1515 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
1518 win_errstr(result)));
1522 /* Construct the Device Mode */
1523 status = dcerpc_winreg_query_binary(tmp_ctx,
1529 if (!NT_STATUS_IS_OK(status)) {
1530 result = ntstatus_to_werror(status);
1532 if (W_ERROR_IS_OK(result)) {
1533 info2->devmode = talloc_zero(info2, struct spoolss_DeviceMode);
1534 if (info2->devmode == NULL) {
1535 result = WERR_NOT_ENOUGH_MEMORY;
1538 ndr_err = ndr_pull_struct_blob(&blob,
1541 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
1542 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1543 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
1544 result = WERR_NOT_ENOUGH_MEMORY;
1549 if (info2->devmode == NULL && lp_default_devmode(snum)) {
1550 result = spoolss_create_default_devmode(info2,
1553 if (!W_ERROR_IS_OK(result)) {
1558 if (info2->devmode) {
1559 info2->devmode->size = ndr_size_spoolss_DeviceMode(info2->devmode, 0) - info2->devmode->driverextra_data.length;
1562 result = winreg_get_printer_secdesc(info2,
1566 if (!W_ERROR_IS_OK(result)) {
1570 /* Fix for OS/2 drivers. */
1571 if (get_remote_arch() == RA_OS2) {
1572 spoolss_map_to_os2_driver(info2, &info2->drivername);
1576 *pinfo2 = talloc_move(mem_ctx, &info2);
1581 if (is_valid_policy_hnd(&key_hnd)) {
1582 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1584 if (is_valid_policy_hnd(&hive_hnd)) {
1585 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1588 TALLOC_FREE(tmp_ctx);
1592 static WERROR winreg_get_secdesc(TALLOC_CTX *mem_ctx,
1593 struct dcerpc_binding_handle *winreg_handle,
1595 const char *attribute,
1596 struct spoolss_security_descriptor **psecdesc)
1598 struct spoolss_security_descriptor *secdesc;
1599 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1600 struct policy_handle hive_hnd, key_hnd;
1601 TALLOC_CTX *tmp_ctx;
1606 tmp_ctx = talloc_stackframe();
1607 if (tmp_ctx == NULL) {
1608 return WERR_NOT_ENOUGH_MEMORY;
1611 ZERO_STRUCT(hive_hnd);
1612 ZERO_STRUCT(key_hnd);
1614 result = winreg_printer_openkey(tmp_ctx,
1622 if (!W_ERROR_IS_OK(result)) {
1623 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
1624 goto create_default;
1629 status = dcerpc_winreg_query_sd(tmp_ctx,
1635 if (!NT_STATUS_IS_OK(status)) {
1636 result = ntstatus_to_werror(status);
1638 if (!W_ERROR_IS_OK(result)) {
1639 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
1641 if (is_valid_policy_hnd(&key_hnd)) {
1642 dcerpc_winreg_CloseKey(winreg_handle,
1648 if (is_valid_policy_hnd(&hive_hnd)) {
1649 dcerpc_winreg_CloseKey(winreg_handle,
1654 goto create_default;
1660 *psecdesc = talloc_move(mem_ctx, &secdesc);
1667 result = winreg_printer_openkey(tmp_ctx,
1675 if (!W_ERROR_IS_OK(result)) {
1679 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1680 if (!W_ERROR_IS_OK(result)) {
1684 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
1685 this security descriptor has been created when winbindd was
1686 down. Take ownership of security descriptor. */
1687 if (dom_sid_equal(secdesc->owner_sid, &global_sid_World)) {
1688 struct dom_sid owner_sid;
1690 /* Change sd owner to workgroup administrator */
1692 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid)) {
1693 struct spoolss_security_descriptor *new_secdesc;
1697 sid_append_rid(&owner_sid, DOMAIN_RID_ADMINISTRATOR);
1699 new_secdesc = make_sec_desc(tmp_ctx,
1708 if (new_secdesc == NULL) {
1709 result = WERR_NOT_ENOUGH_MEMORY;
1713 /* Swap with other one */
1714 secdesc = new_secdesc;
1718 status = dcerpc_winreg_set_sd(tmp_ctx,
1724 if (!NT_STATUS_IS_OK(status)) {
1725 result = ntstatus_to_werror(status);
1727 if (!W_ERROR_IS_OK(result)) {
1732 *psecdesc = talloc_move(mem_ctx, &secdesc);
1737 if (is_valid_policy_hnd(&key_hnd)) {
1738 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1740 if (is_valid_policy_hnd(&hive_hnd)) {
1741 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1744 talloc_free(tmp_ctx);
1748 WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
1749 struct dcerpc_binding_handle *winreg_handle,
1750 const char *sharename,
1751 struct spoolss_security_descriptor **psecdesc)
1756 path = winreg_printer_data_keyname(mem_ctx, sharename);
1758 return WERR_NOT_ENOUGH_MEMORY;
1761 result = winreg_get_secdesc(mem_ctx, winreg_handle,
1770 WERROR winreg_get_printserver_secdesc(TALLOC_CTX *mem_ctx,
1771 struct dcerpc_binding_handle *winreg_handle,
1772 struct spoolss_security_descriptor **psecdesc)
1774 return winreg_get_secdesc(mem_ctx, winreg_handle,
1775 TOP_LEVEL_CONTROL_KEY,
1776 "ServerSecurityDescriptor",
1780 static WERROR winreg_set_secdesc(TALLOC_CTX *mem_ctx,
1781 struct dcerpc_binding_handle *winreg_handle,
1783 const char *attribute,
1784 const struct spoolss_security_descriptor *secdesc)
1786 const struct spoolss_security_descriptor *new_secdesc = secdesc;
1787 struct spoolss_security_descriptor *old_secdesc;
1788 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1789 struct policy_handle hive_hnd, key_hnd;
1790 TALLOC_CTX *tmp_ctx;
1795 tmp_ctx = talloc_stackframe();
1796 if (tmp_ctx == NULL) {
1797 return WERR_NOT_ENOUGH_MEMORY;
1801 * The old owner and group sids of the security descriptor are not
1802 * present when new ACEs are added or removed by changing printer
1803 * permissions through NT. If they are NULL in the new security
1804 * descriptor then copy them over from the old one.
1806 if (!secdesc->owner_sid || !secdesc->group_sid) {
1807 struct dom_sid *owner_sid, *group_sid;
1808 struct security_acl *dacl, *sacl;
1811 result = winreg_get_secdesc(tmp_ctx,
1816 if (!W_ERROR_IS_OK(result)) {
1817 talloc_free(tmp_ctx);
1821 /* Pick out correct owner and group sids */
1822 owner_sid = secdesc->owner_sid ?
1823 secdesc->owner_sid :
1824 old_secdesc->owner_sid;
1826 group_sid = secdesc->group_sid ?
1827 secdesc->group_sid :
1828 old_secdesc->group_sid;
1830 dacl = secdesc->dacl ?
1834 sacl = secdesc->sacl ?
1838 /* Make a deep copy of the security descriptor */
1839 new_secdesc = make_sec_desc(tmp_ctx,
1847 if (new_secdesc == NULL) {
1848 talloc_free(tmp_ctx);
1849 return WERR_NOT_ENOUGH_MEMORY;
1853 ZERO_STRUCT(hive_hnd);
1854 ZERO_STRUCT(key_hnd);
1856 result = winreg_printer_openkey(tmp_ctx,
1864 if (!W_ERROR_IS_OK(result)) {
1868 status = dcerpc_winreg_set_sd(tmp_ctx,
1874 if (!NT_STATUS_IS_OK(status)) {
1875 result = ntstatus_to_werror(status);
1879 if (is_valid_policy_hnd(&key_hnd)) {
1880 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1882 if (is_valid_policy_hnd(&hive_hnd)) {
1883 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1886 talloc_free(tmp_ctx);
1890 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
1891 struct dcerpc_binding_handle *winreg_handle,
1892 const char *sharename,
1893 const struct spoolss_security_descriptor *secdesc)
1898 path = winreg_printer_data_keyname(mem_ctx, sharename);
1900 return WERR_NOT_ENOUGH_MEMORY;
1903 result = winreg_set_secdesc(mem_ctx, winreg_handle,
1905 "Security", secdesc);
1911 WERROR winreg_set_printserver_secdesc(TALLOC_CTX *mem_ctx,
1912 struct dcerpc_binding_handle *winreg_handle,
1913 const struct spoolss_security_descriptor *secdesc)
1915 return winreg_set_secdesc(mem_ctx, winreg_handle,
1916 TOP_LEVEL_CONTROL_KEY,
1917 "ServerSecurityDescriptor",
1921 /* Set printer data over the winreg pipe. */
1922 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
1923 struct dcerpc_binding_handle *winreg_handle,
1924 const char *printer,
1927 enum winreg_Type type,
1931 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1932 struct policy_handle hive_hnd, key_hnd;
1933 struct winreg_String wvalue = { 0, };
1935 WERROR result = WERR_OK;
1938 TALLOC_CTX *tmp_ctx;
1940 tmp_ctx = talloc_stackframe();
1941 if (tmp_ctx == NULL) {
1942 return WERR_NOT_ENOUGH_MEMORY;
1945 path = winreg_printer_data_keyname(tmp_ctx, printer);
1947 TALLOC_FREE(tmp_ctx);
1948 return WERR_NOT_ENOUGH_MEMORY;
1951 ZERO_STRUCT(hive_hnd);
1952 ZERO_STRUCT(key_hnd);
1954 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
1955 key, value, access_mask, printer));
1956 result = winreg_printer_openkey(tmp_ctx,
1964 if (!W_ERROR_IS_OK(result)) {
1965 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
1966 key, win_errstr(result)));
1970 wvalue.name = value;
1971 status = dcerpc_winreg_SetValue(winreg_handle,
1979 if (!NT_STATUS_IS_OK(status)) {
1980 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
1981 value, nt_errstr(status)));
1982 result = ntstatus_to_werror(status);
1986 if (is_valid_policy_hnd(&key_hnd)) {
1987 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1989 if (is_valid_policy_hnd(&hive_hnd)) {
1990 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1993 TALLOC_FREE(tmp_ctx);
1997 /* Get printer data over a winreg pipe. */
1998 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
1999 struct dcerpc_binding_handle *winreg_handle,
2000 const char *printer,
2003 enum winreg_Type *type,
2005 uint32_t *data_size)
2007 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2008 struct policy_handle hive_hnd, key_hnd;
2009 struct winreg_String wvalue;
2010 enum winreg_Type type_in = REG_NONE;
2012 uint8_t *data_in = NULL;
2013 uint32_t data_in_size = 0;
2014 uint32_t value_len = 0;
2015 WERROR result = WERR_OK;
2018 TALLOC_CTX *tmp_ctx;
2020 tmp_ctx = talloc_stackframe();
2021 if (tmp_ctx == NULL) {
2022 return WERR_NOT_ENOUGH_MEMORY;
2025 path = winreg_printer_data_keyname(tmp_ctx, printer);
2027 TALLOC_FREE(tmp_ctx);
2028 return WERR_NOT_ENOUGH_MEMORY;
2031 ZERO_STRUCT(hive_hnd);
2032 ZERO_STRUCT(key_hnd);
2034 result = winreg_printer_openkey(tmp_ctx,
2042 if (!W_ERROR_IS_OK(result)) {
2043 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2044 key, win_errstr(result)));
2048 wvalue.name = value;
2051 * call QueryValue once with data == NULL to get the
2052 * needed memory size to be allocated, then allocate
2053 * data buffer and call again.
2055 status = dcerpc_winreg_QueryValue(winreg_handle,
2064 if (!NT_STATUS_IS_OK(status)) {
2065 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2066 value, nt_errstr(status)));
2067 result = ntstatus_to_werror(status);
2070 if (!W_ERROR_IS_OK(result)) {
2071 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2072 value, win_errstr(result)));
2076 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2077 if (data_in == NULL) {
2078 result = WERR_NOT_ENOUGH_MEMORY;
2083 status = dcerpc_winreg_QueryValue(winreg_handle,
2092 if (!NT_STATUS_IS_OK(status)) {
2093 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2094 value, nt_errstr(status)));
2095 result = ntstatus_to_werror(status);
2098 if (!W_ERROR_IS_OK(result)) {
2099 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2100 value, win_errstr(result)));
2105 *data_size = data_in_size;
2107 *data = talloc_move(mem_ctx, &data_in);
2112 if (is_valid_policy_hnd(&key_hnd)) {
2113 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2115 if (is_valid_policy_hnd(&hive_hnd)) {
2116 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2119 TALLOC_FREE(tmp_ctx);
2123 /* Enumerate on the values of a given key and provide the data. */
2124 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2125 struct dcerpc_binding_handle *winreg_handle,
2126 const char *printer,
2128 uint32_t *pnum_values,
2129 struct spoolss_PrinterEnumValues **penum_values)
2132 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2133 struct policy_handle hive_hnd, key_hnd;
2135 struct spoolss_PrinterEnumValues *enum_values = NULL;
2136 uint32_t num_values = 0;
2138 WERROR result = WERR_OK;
2141 const char **enum_names = NULL;
2142 enum winreg_Type *enum_types = NULL;
2143 DATA_BLOB *enum_data_blobs = NULL;
2145 TALLOC_CTX *tmp_ctx;
2147 tmp_ctx = talloc_stackframe();
2148 if (tmp_ctx == NULL) {
2149 return WERR_NOT_ENOUGH_MEMORY;
2152 path = winreg_printer_data_keyname(tmp_ctx, printer);
2154 TALLOC_FREE(tmp_ctx);
2155 return WERR_NOT_ENOUGH_MEMORY;
2158 result = winreg_printer_openkey(tmp_ctx,
2166 if (!W_ERROR_IS_OK(result)) {
2167 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2168 key, win_errstr(result)));
2172 status = dcerpc_winreg_enumvals(tmp_ctx,
2180 if (!NT_STATUS_IS_OK(status)){
2181 result = ntstatus_to_werror(status);
2184 if (!W_ERROR_IS_OK(result)) {
2185 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2186 key, win_errstr(result)));
2190 enum_values = talloc_array(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
2191 if (enum_values == NULL){
2192 result = WERR_NOT_ENOUGH_MEMORY;
2193 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2194 key, win_errstr(result)));
2198 for (i = 0; i < num_values; i++){
2199 enum_values[i].value_name = enum_names[i];
2200 enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
2201 enum_values[i].type = enum_types[i];
2202 enum_values[i].data_length = enum_data_blobs[i].length;
2203 enum_values[i].data = NULL;
2205 if (enum_values[i].data_length != 0){
2206 enum_values[i].data = &enum_data_blobs[i];
2210 talloc_steal(enum_values, enum_names);
2211 talloc_steal(enum_values, enum_data_blobs);
2213 *pnum_values = num_values;
2215 *penum_values = talloc_move(mem_ctx, &enum_values);
2220 if (is_valid_policy_hnd(&key_hnd)) {
2221 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2223 if (is_valid_policy_hnd(&hive_hnd)) {
2224 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2227 TALLOC_FREE(tmp_ctx);
2231 /* Delete printer data over a winreg pipe. */
2232 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2233 struct dcerpc_binding_handle *winreg_handle,
2234 const char *printer,
2238 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2239 struct policy_handle hive_hnd, key_hnd;
2240 struct winreg_String wvalue = { 0, };
2242 WERROR result = WERR_OK;
2246 TALLOC_CTX *tmp_ctx;
2248 tmp_ctx = talloc_stackframe();
2249 if (tmp_ctx == NULL) {
2250 return WERR_NOT_ENOUGH_MEMORY;
2253 path = winreg_printer_data_keyname(tmp_ctx, printer);
2255 TALLOC_FREE(tmp_ctx);
2256 return WERR_NOT_ENOUGH_MEMORY;
2259 ZERO_STRUCT(hive_hnd);
2260 ZERO_STRUCT(key_hnd);
2262 result = winreg_printer_openkey(tmp_ctx,
2270 if (!W_ERROR_IS_OK(result)) {
2271 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2272 key, win_errstr(result)));
2276 wvalue.name = value;
2277 status = dcerpc_winreg_DeleteValue(winreg_handle,
2282 if (!NT_STATUS_IS_OK(status)) {
2283 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2284 value, nt_errstr(status)));
2285 result = ntstatus_to_werror(status);
2289 if (is_valid_policy_hnd(&key_hnd)) {
2290 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2292 if (is_valid_policy_hnd(&hive_hnd)) {
2293 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2296 TALLOC_FREE(tmp_ctx);
2300 /* Enumerate on the subkeys of a given key and provide the data. */
2301 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2302 struct dcerpc_binding_handle *winreg_handle,
2303 const char *printer,
2305 uint32_t *pnum_subkeys,
2306 const char ***psubkeys)
2308 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2309 struct policy_handle hive_hnd, key_hnd;
2311 const char **subkeys = NULL;
2312 uint32_t num_subkeys = -1;
2314 WERROR result = WERR_OK;
2318 TALLOC_CTX *tmp_ctx;
2320 tmp_ctx = talloc_stackframe();
2321 if (tmp_ctx == NULL) {
2322 return WERR_NOT_ENOUGH_MEMORY;
2325 path = winreg_printer_data_keyname(tmp_ctx, printer);
2327 TALLOC_FREE(tmp_ctx);
2328 return WERR_NOT_ENOUGH_MEMORY;
2331 ZERO_STRUCT(hive_hnd);
2332 ZERO_STRUCT(key_hnd);
2334 result = winreg_printer_openkey(tmp_ctx,
2342 if (!W_ERROR_IS_OK(result)) {
2343 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2344 key, win_errstr(result)));
2348 status = dcerpc_winreg_enum_keys(tmp_ctx,
2354 if (!NT_STATUS_IS_OK(status)) {
2355 result = ntstatus_to_werror(status);
2357 if (!W_ERROR_IS_OK(result)) {
2358 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2359 key, win_errstr(result)));
2363 *pnum_subkeys = num_subkeys;
2365 *psubkeys = talloc_move(mem_ctx, &subkeys);
2370 if (is_valid_policy_hnd(&key_hnd)) {
2371 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2373 if (is_valid_policy_hnd(&hive_hnd)) {
2374 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2377 TALLOC_FREE(tmp_ctx);
2381 /* Delete a key with subkeys of a given printer. */
2382 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
2383 struct dcerpc_binding_handle *winreg_handle,
2384 const char *printer,
2387 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2388 struct policy_handle hive_hnd, key_hnd;
2394 TALLOC_CTX *tmp_ctx;
2396 tmp_ctx = talloc_stackframe();
2397 if (tmp_ctx == NULL) {
2398 return WERR_NOT_ENOUGH_MEMORY;
2401 path = winreg_printer_data_keyname(tmp_ctx, printer);
2403 TALLOC_FREE(tmp_ctx);
2404 return WERR_NOT_ENOUGH_MEMORY;
2407 result = winreg_printer_openkey(tmp_ctx,
2415 if (!W_ERROR_IS_OK(result)) {
2416 /* key doesn't exist */
2417 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
2422 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2423 key, win_errstr(result)));
2427 if (is_valid_policy_hnd(&key_hnd)) {
2428 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
2431 if (key == NULL || key[0] == '\0') {
2434 keyname = talloc_asprintf(tmp_ctx,
2438 if (keyname == NULL) {
2439 result = WERR_NOT_ENOUGH_MEMORY;
2444 status = dcerpc_winreg_delete_subkeys_recursive(tmp_ctx,
2451 if (!NT_STATUS_IS_OK(status)) {
2452 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2453 key, nt_errstr(status)));
2454 result = ntstatus_to_werror(status);
2458 if (!W_ERROR_IS_OK(result)) {
2459 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2460 key, win_errstr(result)));
2465 if (is_valid_policy_hnd(&key_hnd)) {
2466 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2468 if (is_valid_policy_hnd(&hive_hnd)) {
2469 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2472 TALLOC_FREE(tmp_ctx);
2476 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
2477 struct dcerpc_binding_handle *winreg_handle,
2478 const char *printer)
2480 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2481 struct policy_handle hive_hnd, key_hnd;
2486 TALLOC_CTX *tmp_ctx;
2488 tmp_ctx = talloc_stackframe();
2489 if (tmp_ctx == NULL) {
2490 return WERR_NOT_ENOUGH_MEMORY;
2493 path = winreg_printer_data_keyname(tmp_ctx, printer);
2495 TALLOC_FREE(tmp_ctx);
2496 return WERR_NOT_ENOUGH_MEMORY;
2499 ZERO_STRUCT(hive_hnd);
2500 ZERO_STRUCT(key_hnd);
2502 result = winreg_printer_openkey(tmp_ctx,
2510 if (!W_ERROR_IS_OK(result)) {
2511 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2512 path, win_errstr(result)));
2516 status = dcerpc_winreg_set_dword(tmp_ctx,
2520 winreg_printer_rev_changeid(),
2522 if (!NT_STATUS_IS_OK(status)) {
2523 result = ntstatus_to_werror(status);
2525 if (!W_ERROR_IS_OK(result)) {
2531 if (is_valid_policy_hnd(&key_hnd)) {
2532 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2534 if (is_valid_policy_hnd(&hive_hnd)) {
2535 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2538 TALLOC_FREE(tmp_ctx);
2542 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
2543 struct dcerpc_binding_handle *winreg_handle,
2544 const char *printer,
2545 uint32_t *pchangeid)
2547 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2548 struct policy_handle hive_hnd, key_hnd;
2549 uint32_t changeid = 0;
2554 TALLOC_CTX *tmp_ctx;
2556 tmp_ctx = talloc_stackframe();
2557 if (tmp_ctx == NULL) {
2558 return WERR_NOT_ENOUGH_MEMORY;
2561 path = winreg_printer_data_keyname(tmp_ctx, printer);
2563 TALLOC_FREE(tmp_ctx);
2564 return WERR_NOT_ENOUGH_MEMORY;
2567 ZERO_STRUCT(hive_hnd);
2568 ZERO_STRUCT(key_hnd);
2570 result = winreg_printer_openkey(tmp_ctx,
2578 if (!W_ERROR_IS_OK(result)) {
2579 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2580 path, win_errstr(result)));
2584 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path));
2586 status = dcerpc_winreg_query_dword(tmp_ctx,
2592 if (!NT_STATUS_IS_OK(status)) {
2593 result = ntstatus_to_werror(status);
2595 if (!W_ERROR_IS_OK(result)) {
2600 *pchangeid = changeid;
2605 if (is_valid_policy_hnd(&key_hnd)) {
2606 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2608 if (is_valid_policy_hnd(&hive_hnd)) {
2609 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2612 TALLOC_FREE(tmp_ctx);
2617 * The special behaviour of the spoolss forms is documented at the website:
2619 * Managing Win32 Printserver Forms
2620 * http://unixwiz.net/techtips/winspooler-forms.html
2623 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
2624 struct dcerpc_binding_handle *winreg_handle,
2625 struct spoolss_AddFormInfo1 *form)
2627 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2628 struct policy_handle hive_hnd, key_hnd;
2629 struct winreg_String wvalue = { 0, };
2631 uint32_t num_info = 0;
2632 union spoolss_FormInfo *info = NULL;
2637 TALLOC_CTX *tmp_ctx;
2639 tmp_ctx = talloc_stackframe();
2640 if (tmp_ctx == NULL) {
2641 return WERR_NOT_ENOUGH_MEMORY;
2644 ZERO_STRUCT(hive_hnd);
2645 ZERO_STRUCT(key_hnd);
2647 result = winreg_printer_openkey(tmp_ctx,
2649 TOP_LEVEL_CONTROL_FORMS_KEY,
2655 if (!W_ERROR_IS_OK(result)) {
2656 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2657 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2661 result = winreg_printer_enumforms1(tmp_ctx, winreg_handle,
2663 if (!W_ERROR_IS_OK(result)) {
2664 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2665 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2669 /* If form name already exists or is builtin return ALREADY_EXISTS */
2670 for (i = 0; i < num_info; i++) {
2671 if (strequal(info[i].info1.form_name, form->form_name)) {
2672 result = WERR_FILE_EXISTS;
2677 wvalue.name = form->form_name;
2679 blob = data_blob_talloc(tmp_ctx, NULL, 32);
2680 SIVAL(blob.data, 0, form->size.width);
2681 SIVAL(blob.data, 4, form->size.height);
2682 SIVAL(blob.data, 8, form->area.left);
2683 SIVAL(blob.data, 12, form->area.top);
2684 SIVAL(blob.data, 16, form->area.right);
2685 SIVAL(blob.data, 20, form->area.bottom);
2686 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
2687 SIVAL(blob.data, 28, form->flags);
2689 status = dcerpc_winreg_SetValue(winreg_handle,
2697 if (!NT_STATUS_IS_OK(status)) {
2698 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2699 wvalue.name, nt_errstr(status)));
2700 result = ntstatus_to_werror(status);
2704 if (is_valid_policy_hnd(&key_hnd)) {
2705 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2707 if (is_valid_policy_hnd(&hive_hnd)) {
2708 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2712 TALLOC_FREE(tmp_ctx);
2716 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
2717 struct dcerpc_binding_handle *winreg_handle,
2718 uint32_t *pnum_info,
2719 union spoolss_FormInfo **pinfo)
2721 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2722 struct policy_handle hive_hnd, key_hnd;
2723 union spoolss_FormInfo *info;
2724 struct spoolss_PrinterEnumValues *enum_values = NULL;
2725 uint32_t num_values = 0;
2726 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
2731 const char **enum_names = NULL;
2732 enum winreg_Type *enum_types = NULL;
2733 DATA_BLOB *enum_data_blobs = NULL;
2734 TALLOC_CTX *tmp_ctx;
2736 tmp_ctx = talloc_stackframe();
2737 if (tmp_ctx == NULL) {
2738 return WERR_NOT_ENOUGH_MEMORY;
2741 ZERO_STRUCT(hive_hnd);
2742 ZERO_STRUCT(key_hnd);
2744 result = winreg_printer_openkey(tmp_ctx,
2746 TOP_LEVEL_CONTROL_FORMS_KEY,
2752 if (!W_ERROR_IS_OK(result)) {
2753 /* key doesn't exist */
2754 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
2759 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
2760 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2764 status = dcerpc_winreg_enumvals(tmp_ctx,
2772 if (!NT_STATUS_IS_OK(status)){
2773 result = ntstatus_to_werror(status);
2776 if (!W_ERROR_IS_OK(result)) {
2777 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2778 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2782 enum_values = talloc_zero_array(tmp_ctx,
2783 struct spoolss_PrinterEnumValues,
2785 if (enum_values == NULL){
2786 result = WERR_NOT_ENOUGH_MEMORY;
2790 for (i = 0; i < num_values; i++){
2791 enum_values[i].value_name = enum_names[i];
2792 enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
2793 enum_values[i].type = enum_types[i];
2794 enum_values[i].data_length = enum_data_blobs[i].length;
2795 enum_values[i].data = NULL;
2796 if (enum_values[i].data_length != 0){
2797 enum_values[i].data = &enum_data_blobs[i];
2801 if (!W_ERROR_IS_OK(result)) {
2802 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2803 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2807 info = talloc_array(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
2809 result = WERR_NOT_ENOUGH_MEMORY;
2813 /* Enumerate BUILTIN forms */
2814 for (i = 0; i < num_builtin; i++) {
2815 info[i].info1 = builtin_forms1[i];
2818 /* Enumerate registry forms */
2819 for (i = 0; i < num_values; i++) {
2820 union spoolss_FormInfo val;
2822 if (enum_values[i].type != REG_BINARY ||
2823 enum_values[i].data_length != 32) {
2827 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
2828 if (val.info1.form_name == NULL) {
2829 result = WERR_NOT_ENOUGH_MEMORY;
2833 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
2834 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
2835 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
2836 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
2837 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
2838 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
2839 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
2840 val.info1.flags = (enum spoolss_FormFlags) IVAL(enum_values[i].data->data, 28);
2842 info[i + num_builtin] = val;
2845 *pnum_info = num_builtin + num_values;
2847 *pinfo = talloc_move(mem_ctx, &info);
2851 if (is_valid_policy_hnd(&key_hnd)) {
2852 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2854 if (is_valid_policy_hnd(&hive_hnd)) {
2855 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2858 TALLOC_FREE(enum_values);
2859 TALLOC_FREE(tmp_ctx);
2863 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
2864 struct dcerpc_binding_handle *winreg_handle,
2865 const char *form_name)
2867 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2868 struct policy_handle hive_hnd, key_hnd;
2869 struct winreg_String wvalue = { 0, };
2870 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
2872 WERROR result = WERR_OK;
2875 TALLOC_CTX *tmp_ctx;
2877 for (i = 0; i < num_builtin; i++) {
2878 if (strequal(builtin_forms1[i].form_name, form_name)) {
2879 return WERR_INVALID_PARAMETER;
2883 tmp_ctx = talloc_stackframe();
2884 if (tmp_ctx == NULL) {
2885 return WERR_NOT_ENOUGH_MEMORY;
2888 ZERO_STRUCT(hive_hnd);
2889 ZERO_STRUCT(key_hnd);
2891 result = winreg_printer_openkey(tmp_ctx,
2893 TOP_LEVEL_CONTROL_FORMS_KEY,
2899 if (!W_ERROR_IS_OK(result)) {
2900 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
2901 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2902 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
2903 result = WERR_INVALID_FORM_NAME;
2908 wvalue.name = form_name;
2909 status = dcerpc_winreg_DeleteValue(winreg_handle,
2914 if (!NT_STATUS_IS_OK(status)) {
2915 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
2916 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
2917 wvalue.name, nt_errstr(status)));
2918 result = ntstatus_to_werror(status);
2922 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
2923 result = WERR_INVALID_FORM_NAME;
2927 if (is_valid_policy_hnd(&key_hnd)) {
2928 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2930 if (is_valid_policy_hnd(&hive_hnd)) {
2931 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2934 TALLOC_FREE(tmp_ctx);
2938 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
2939 struct dcerpc_binding_handle *winreg_handle,
2940 const char *form_name,
2941 struct spoolss_AddFormInfo1 *form)
2943 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2944 struct policy_handle hive_hnd = { 0, };
2945 struct policy_handle key_hnd = { 0, };
2946 struct winreg_String wvalue = { 0, };
2948 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
2952 TALLOC_CTX *tmp_ctx = NULL;
2954 for (i = 0; i < num_builtin; i++) {
2955 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
2956 result = WERR_INVALID_PARAMETER;
2961 tmp_ctx = talloc_stackframe();
2962 if (tmp_ctx == NULL) {
2963 return WERR_NOT_ENOUGH_MEMORY;
2966 ZERO_STRUCT(hive_hnd);
2967 ZERO_STRUCT(key_hnd);
2969 result = winreg_printer_openkey(tmp_ctx,
2971 TOP_LEVEL_CONTROL_FORMS_KEY,
2977 if (!W_ERROR_IS_OK(result)) {
2978 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
2979 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2983 /* If form_name != form->form_name then we renamed the form */
2984 if (strequal(form_name, form->form_name)) {
2985 result = winreg_printer_deleteform1(tmp_ctx, winreg_handle,
2987 if (!W_ERROR_IS_OK(result)) {
2988 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
2989 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2994 wvalue.name = form->form_name;
2996 blob = data_blob_talloc(tmp_ctx, NULL, 32);
2997 SIVAL(blob.data, 0, form->size.width);
2998 SIVAL(blob.data, 4, form->size.height);
2999 SIVAL(blob.data, 8, form->area.left);
3000 SIVAL(blob.data, 12, form->area.top);
3001 SIVAL(blob.data, 16, form->area.right);
3002 SIVAL(blob.data, 20, form->area.bottom);
3003 SIVAL(blob.data, 24, 42);
3004 SIVAL(blob.data, 28, form->flags);
3006 status = dcerpc_winreg_SetValue(winreg_handle,
3014 if (!NT_STATUS_IS_OK(status)) {
3015 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3016 wvalue.name, nt_errstr(status)));
3017 result = ntstatus_to_werror(status);
3021 if (winreg_handle != NULL) {
3024 if (is_valid_policy_hnd(&key_hnd)) {
3025 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3027 if (is_valid_policy_hnd(&hive_hnd)) {
3028 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3032 TALLOC_FREE(tmp_ctx);
3036 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3037 struct dcerpc_binding_handle *winreg_handle,
3038 const char *form_name,
3039 struct spoolss_FormInfo1 *r)
3041 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3042 struct policy_handle hive_hnd, key_hnd;
3043 struct winreg_String wvalue;
3044 enum winreg_Type type_in = REG_NONE;
3045 uint8_t *data_in = NULL;
3046 uint32_t data_in_size = 0;
3047 uint32_t value_len = 0;
3048 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3053 TALLOC_CTX *tmp_ctx;
3055 /* check builtin forms first */
3056 for (i = 0; i < num_builtin; i++) {
3057 if (strequal(builtin_forms1[i].form_name, form_name)) {
3058 *r = builtin_forms1[i];
3063 tmp_ctx = talloc_stackframe();
3064 if (tmp_ctx == NULL) {
3065 return WERR_NOT_ENOUGH_MEMORY;
3068 ZERO_STRUCT(hive_hnd);
3069 ZERO_STRUCT(key_hnd);
3071 result = winreg_printer_openkey(tmp_ctx,
3073 TOP_LEVEL_CONTROL_FORMS_KEY,
3079 if (!W_ERROR_IS_OK(result)) {
3080 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3081 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3085 wvalue.name = form_name;
3088 * call QueryValue once with data == NULL to get the
3089 * needed memory size to be allocated, then allocate
3090 * data buffer and call again.
3092 status = dcerpc_winreg_QueryValue(winreg_handle,
3101 if (!NT_STATUS_IS_OK(status)) {
3102 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3103 wvalue.name, nt_errstr(status)));
3104 result = ntstatus_to_werror(status);
3107 if (!W_ERROR_IS_OK(result)) {
3111 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3112 if (data_in == NULL) {
3113 result = WERR_NOT_ENOUGH_MEMORY;
3118 status = dcerpc_winreg_QueryValue(winreg_handle,
3127 if (!NT_STATUS_IS_OK(status)) {
3128 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3129 wvalue.name, nt_errstr(status)));
3130 result = ntstatus_to_werror(status);
3133 if (!W_ERROR_IS_OK(result)) {
3137 r->form_name = talloc_strdup(mem_ctx, form_name);
3138 if (r->form_name == NULL) {
3139 result = WERR_NOT_ENOUGH_MEMORY;
3143 r->size.width = IVAL(data_in, 0);
3144 r->size.height = IVAL(data_in, 4);
3145 r->area.left = IVAL(data_in, 8);
3146 r->area.top = IVAL(data_in, 12);
3147 r->area.right = IVAL(data_in, 16);
3148 r->area.bottom = IVAL(data_in, 20);
3149 /* skip index IVAL(data_in, 24)));*/
3150 r->flags = (enum spoolss_FormFlags) IVAL(data_in, 28);
3154 if (is_valid_policy_hnd(&key_hnd)) {
3155 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3157 if (is_valid_policy_hnd(&hive_hnd)) {
3158 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3161 TALLOC_FREE(tmp_ctx);
3165 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3166 struct dcerpc_binding_handle *winreg_handle,
3167 struct spoolss_AddDriverInfoCtr *r,
3168 const char **driver_name,
3169 uint32_t *driver_version)
3171 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3172 struct policy_handle hive_hnd, key_hnd;
3173 struct spoolss_DriverInfo8 info8;
3174 TALLOC_CTX *tmp_ctx = NULL;
3178 ZERO_STRUCT(hive_hnd);
3179 ZERO_STRUCT(key_hnd);
3182 if (!driver_info_ctr_to_info8(r, &info8)) {
3183 result = WERR_INVALID_PARAMETER;
3187 tmp_ctx = talloc_stackframe();
3188 if (tmp_ctx == NULL) {
3189 return WERR_NOT_ENOUGH_MEMORY;
3192 result = winreg_printer_opendriver(tmp_ctx,
3200 if (!W_ERROR_IS_OK(result)) {
3201 DEBUG(0, ("winreg_add_driver: "
3202 "Could not open driver key (%s,%s,%d): %s\n",
3203 info8.driver_name, info8.architecture,
3204 info8.version, win_errstr(result)));
3208 /* TODO: "Attributes" ? */
3210 status = dcerpc_winreg_set_dword(tmp_ctx,
3216 if (!NT_STATUS_IS_OK(status)) {
3217 result = ntstatus_to_werror(status);
3219 if (!W_ERROR_IS_OK(result)) {
3223 status = dcerpc_winreg_set_sz(tmp_ctx,
3229 if (!NT_STATUS_IS_OK(status)) {
3230 result = ntstatus_to_werror(status);
3232 if (!W_ERROR_IS_OK(result)) {
3236 status = dcerpc_winreg_set_sz(tmp_ctx,
3242 if (!NT_STATUS_IS_OK(status)) {
3243 result = ntstatus_to_werror(status);
3245 if (!W_ERROR_IS_OK(result)) {
3249 status = dcerpc_winreg_set_sz(tmp_ctx,
3252 "Configuration File",
3255 if (!NT_STATUS_IS_OK(status)) {
3256 result = ntstatus_to_werror(status);
3258 if (!W_ERROR_IS_OK(result)) {
3262 status = dcerpc_winreg_set_sz(tmp_ctx,
3268 if (!NT_STATUS_IS_OK(status)) {
3269 result = ntstatus_to_werror(status);
3271 if (!W_ERROR_IS_OK(result)) {
3275 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3279 info8.dependent_files,
3281 if (!NT_STATUS_IS_OK(status)) {
3282 result = ntstatus_to_werror(status);
3284 if (!W_ERROR_IS_OK(result)) {
3288 status = dcerpc_winreg_set_sz(tmp_ctx,
3294 if (!NT_STATUS_IS_OK(status)) {
3295 result = ntstatus_to_werror(status);
3297 if (!W_ERROR_IS_OK(result)) {
3301 status = dcerpc_winreg_set_sz(tmp_ctx,
3305 info8.default_datatype,
3307 if (!NT_STATUS_IS_OK(status)) {
3308 result = ntstatus_to_werror(status);
3310 if (!W_ERROR_IS_OK(result)) {
3314 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3316 &key_hnd, "Previous Names",
3317 info8.previous_names,
3319 if (!NT_STATUS_IS_OK(status)) {
3320 result = ntstatus_to_werror(status);
3322 if (!W_ERROR_IS_OK(result)) {
3326 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3327 &key_hnd, "DriverDate",
3329 if (!W_ERROR_IS_OK(result)) {
3333 result = winreg_printer_write_ver(tmp_ctx, winreg_handle,
3334 &key_hnd, "DriverVersion",
3335 info8.driver_version);
3336 if (!W_ERROR_IS_OK(result)) {
3340 status = dcerpc_winreg_set_sz(tmp_ctx,
3344 info8.manufacturer_name,
3346 if (!NT_STATUS_IS_OK(status)) {
3347 result = ntstatus_to_werror(status);
3349 if (!W_ERROR_IS_OK(result)) {
3353 status = dcerpc_winreg_set_sz(tmp_ctx,
3357 info8.manufacturer_url,
3359 if (!NT_STATUS_IS_OK(status)) {
3360 result = ntstatus_to_werror(status);
3362 if (!W_ERROR_IS_OK(result)) {
3366 status = dcerpc_winreg_set_sz(tmp_ctx,
3372 if (!NT_STATUS_IS_OK(status)) {
3373 result = ntstatus_to_werror(status);
3375 if (!W_ERROR_IS_OK(result)) {
3379 status = dcerpc_winreg_set_sz(tmp_ctx,
3385 if (!NT_STATUS_IS_OK(status)) {
3386 result = ntstatus_to_werror(status);
3388 if (!W_ERROR_IS_OK(result)) {
3392 status = dcerpc_winreg_set_sz(tmp_ctx,
3396 info8.print_processor,
3398 if (!NT_STATUS_IS_OK(status)) {
3399 result = ntstatus_to_werror(status);
3401 if (!W_ERROR_IS_OK(result)) {
3405 status = dcerpc_winreg_set_sz(tmp_ctx,
3411 if (!NT_STATUS_IS_OK(status)) {
3412 result = ntstatus_to_werror(status);
3414 if (!W_ERROR_IS_OK(result)) {
3418 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3422 info8.color_profiles,
3424 if (!NT_STATUS_IS_OK(status)) {
3425 result = ntstatus_to_werror(status);
3427 if (!W_ERROR_IS_OK(result)) {
3431 status = dcerpc_winreg_set_sz(tmp_ctx,
3437 if (!NT_STATUS_IS_OK(status)) {
3438 result = ntstatus_to_werror(status);
3440 if (!W_ERROR_IS_OK(result)) {
3444 status = dcerpc_winreg_set_dword(tmp_ctx,
3447 "PrinterDriverAttributes",
3448 info8.printer_driver_attributes,
3450 if (!NT_STATUS_IS_OK(status)) {
3451 result = ntstatus_to_werror(status);
3453 if (!W_ERROR_IS_OK(result)) {
3457 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3461 info8.core_driver_dependencies,
3463 if (!NT_STATUS_IS_OK(status)) {
3464 result = ntstatus_to_werror(status);
3466 if (!W_ERROR_IS_OK(result)) {
3470 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3471 &key_hnd, "MinInboxDriverVerDate",
3472 info8.min_inbox_driver_ver_date);
3473 if (!W_ERROR_IS_OK(result)) {
3477 result = winreg_printer_write_ver(tmp_ctx, winreg_handle, &key_hnd,
3478 "MinInboxDriverVerVersion",
3479 info8.min_inbox_driver_ver_version);
3480 if (!W_ERROR_IS_OK(result)) {
3484 *driver_name = info8.driver_name;
3485 *driver_version = info8.version;
3488 if (winreg_handle != NULL) {
3491 if (is_valid_policy_hnd(&key_hnd)) {
3492 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3494 if (is_valid_policy_hnd(&hive_hnd)) {
3495 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3499 TALLOC_FREE(tmp_ctx);
3503 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
3504 struct dcerpc_binding_handle *winreg_handle,
3505 const char *architecture,
3506 const char *driver_name,
3507 uint32_t driver_version,
3508 struct spoolss_DriverInfo8 **_info8)
3510 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3511 struct policy_handle hive_hnd, key_hnd;
3512 struct spoolss_DriverInfo8 i8, *info8;
3513 struct spoolss_PrinterEnumValues *enum_values = NULL;
3514 struct spoolss_PrinterEnumValues *v;
3515 uint32_t num_values = 0;
3516 TALLOC_CTX *tmp_ctx;
3520 const char **enum_names = NULL;
3521 enum winreg_Type *enum_types = NULL;
3522 DATA_BLOB *enum_data_blobs = NULL;
3524 ZERO_STRUCT(hive_hnd);
3525 ZERO_STRUCT(key_hnd);
3528 tmp_ctx = talloc_stackframe();
3529 if (tmp_ctx == NULL) {
3530 return WERR_NOT_ENOUGH_MEMORY;
3533 if (driver_version == DRIVER_ANY_VERSION) {
3534 /* look for Win2k first and then for NT4 */
3535 result = winreg_printer_opendriver(tmp_ctx,
3543 if (!W_ERROR_IS_OK(result)) {
3544 result = winreg_printer_opendriver(tmp_ctx,
3554 /* ok normal case */
3555 result = winreg_printer_opendriver(tmp_ctx,
3564 if (!W_ERROR_IS_OK(result)) {
3565 DEBUG(5, ("winreg_get_driver: "
3566 "Could not open driver key (%s,%s,%d): %s\n",
3567 driver_name, architecture,
3568 driver_version, win_errstr(result)));
3572 status = dcerpc_winreg_enumvals(tmp_ctx,
3580 if (!NT_STATUS_IS_OK(status)){
3581 result = ntstatus_to_werror(status);
3584 if (!W_ERROR_IS_OK(result)) {
3585 DEBUG(0, ("winreg_get_driver: "
3586 "Could not enumerate values for (%s,%s,%d): %s\n",
3587 driver_name, architecture,
3588 driver_version, win_errstr(result)));
3592 enum_values = talloc_zero_array(tmp_ctx,
3593 struct spoolss_PrinterEnumValues,
3595 if (enum_values == NULL){
3596 result = WERR_NOT_ENOUGH_MEMORY;
3600 for (i = 0; i < num_values; i++){
3601 enum_values[i].value_name = enum_names[i];
3602 enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
3603 enum_values[i].type = enum_types[i];
3604 enum_values[i].data_length = enum_data_blobs[i].length;
3605 enum_values[i].data = NULL;
3606 if (enum_values[i].data_length != 0){
3607 enum_values[i].data = &enum_data_blobs[i];
3611 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
3612 if (info8 == NULL) {
3613 result = WERR_NOT_ENOUGH_MEMORY;
3617 info8->driver_name = talloc_strdup(info8, driver_name);
3618 if (info8->driver_name == NULL) {
3619 result = WERR_NOT_ENOUGH_MEMORY;
3623 info8->architecture = talloc_strdup(info8, architecture);
3624 if (info8->architecture == NULL) {
3625 result = WERR_NOT_ENOUGH_MEMORY;
3631 for (i = 0; i < num_values; i++) {
3632 const char *tmp_str;
3635 v = &enum_values[i];
3637 result = winreg_enumval_to_dword(info8, v,
3640 if (W_ERROR_IS_OK(result)) {
3641 info8->version = (enum spoolss_DriverOSVersion) tmp;
3643 CHECK_ERROR(result);
3645 result = winreg_enumval_to_sz(info8, v,
3647 &info8->driver_path);
3648 CHECK_ERROR(result);
3650 result = winreg_enumval_to_sz(info8, v,
3653 CHECK_ERROR(result);
3655 result = winreg_enumval_to_sz(info8, v,
3656 "Configuration File",
3657 &info8->config_file);
3658 CHECK_ERROR(result);
3660 result = winreg_enumval_to_sz(info8, v,
3663 CHECK_ERROR(result);
3665 result = winreg_enumval_to_multi_sz(info8, v,
3667 &info8->dependent_files);
3668 CHECK_ERROR(result);
3670 result = winreg_enumval_to_sz(info8, v,
3672 &info8->monitor_name);
3673 CHECK_ERROR(result);
3675 result = winreg_enumval_to_sz(info8, v,
3677 &info8->default_datatype);
3678 CHECK_ERROR(result);
3680 result = winreg_enumval_to_multi_sz(info8, v,
3682 &info8->previous_names);
3683 CHECK_ERROR(result);
3685 result = winreg_enumval_to_sz(info8, v,
3688 if (W_ERROR_IS_OK(result)) {
3689 result = winreg_printer_date_to_NTTIME(tmp_str,
3690 &info8->driver_date);
3692 CHECK_ERROR(result);
3694 result = winreg_enumval_to_sz(info8, v,
3697 if (W_ERROR_IS_OK(result)) {
3698 result = winreg_printer_ver_to_qword(tmp_str,
3699 &info8->driver_version);
3701 CHECK_ERROR(result);
3703 result = winreg_enumval_to_sz(info8, v,
3705 &info8->manufacturer_name);
3706 CHECK_ERROR(result);
3708 result = winreg_enumval_to_sz(info8, v,
3710 &info8->manufacturer_url);
3711 CHECK_ERROR(result);
3713 result = winreg_enumval_to_sz(info8, v,
3715 &info8->hardware_id);
3716 CHECK_ERROR(result);
3718 result = winreg_enumval_to_sz(info8, v,
3721 CHECK_ERROR(result);
3723 result = winreg_enumval_to_sz(info8, v,
3725 &info8->print_processor);
3726 CHECK_ERROR(result);
3728 result = winreg_enumval_to_sz(info8, v,
3730 &info8->vendor_setup);
3731 CHECK_ERROR(result);
3733 result = winreg_enumval_to_multi_sz(info8, v,
3735 &info8->color_profiles);
3736 CHECK_ERROR(result);
3738 result = winreg_enumval_to_sz(info8, v,
3741 CHECK_ERROR(result);
3743 result = winreg_enumval_to_dword(info8, v,
3744 "PrinterDriverAttributes",
3745 &info8->printer_driver_attributes);
3746 CHECK_ERROR(result);
3748 result = winreg_enumval_to_multi_sz(info8, v,
3750 &info8->core_driver_dependencies);
3751 CHECK_ERROR(result);
3753 result = winreg_enumval_to_sz(info8, v,
3754 "MinInboxDriverVerDate",
3756 if (W_ERROR_IS_OK(result)) {
3757 result = winreg_printer_date_to_NTTIME(tmp_str,
3758 &info8->min_inbox_driver_ver_date);
3760 CHECK_ERROR(result);
3762 result = winreg_enumval_to_sz(info8, v,
3763 "MinInboxDriverVerVersion",
3765 if (W_ERROR_IS_OK(result)) {
3766 result = winreg_printer_ver_to_qword(tmp_str,
3767 &info8->min_inbox_driver_ver_version);
3769 CHECK_ERROR(result);
3772 if (!W_ERROR_IS_OK(result)) {
3773 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3774 "for %s: %s\n", v->value_name,
3775 win_errstr(result)));
3779 *_info8 = talloc_steal(mem_ctx, info8);
3782 if (winreg_handle != NULL) {
3785 if (is_valid_policy_hnd(&key_hnd)) {
3786 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3788 if (is_valid_policy_hnd(&hive_hnd)) {
3789 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3793 TALLOC_FREE(tmp_ctx);
3797 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
3798 struct dcerpc_binding_handle *winreg_handle,
3799 struct spoolss_DriverInfo8 *info8,
3802 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3803 struct policy_handle hive_hnd, key_hnd;
3804 TALLOC_CTX *tmp_ctx;
3809 ZERO_STRUCT(hive_hnd);
3810 ZERO_STRUCT(key_hnd);
3812 tmp_ctx = talloc_stackframe();
3813 if (tmp_ctx == NULL) {
3814 return WERR_NOT_ENOUGH_MEMORY;
3817 /* test that the key exists */
3818 result = winreg_printer_opendriver(tmp_ctx,
3821 info8->architecture,
3826 if (!W_ERROR_IS_OK(result)) {
3827 /* key doesn't exist */
3828 if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
3833 DEBUG(5, ("winreg_del_driver: "
3834 "Could not open driver (%s,%s,%u): %s\n",
3835 info8->driver_name, info8->architecture,
3836 version, win_errstr(result)));
3841 if (is_valid_policy_hnd(&key_hnd)) {
3842 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
3845 key_name = talloc_asprintf(tmp_ctx,
3846 "%s\\Environments\\%s\\Drivers\\Version-%u\\%s",
3847 TOP_LEVEL_CONTROL_KEY,
3848 info8->architecture, version,
3849 info8->driver_name);
3850 if (key_name == NULL) {
3851 result = WERR_NOT_ENOUGH_MEMORY;
3855 status = dcerpc_winreg_delete_subkeys_recursive(tmp_ctx,
3862 if (!NT_STATUS_IS_OK(status)){
3863 DEBUG(0, ("winreg_del_driver: "
3864 "Could not open driver (%s,%s,%u): %s\n",
3865 info8->driver_name, info8->architecture,
3866 version, nt_errstr(status)));
3870 if (!W_ERROR_IS_OK(result)) {
3871 DEBUG(0, ("winreg_del_driver: "
3872 "Could not open driver (%s,%s,%u): %s\n",
3873 info8->driver_name, info8->architecture,
3874 version, win_errstr(result)));
3880 if (winreg_handle != NULL) {
3883 if (is_valid_policy_hnd(&key_hnd)) {
3884 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3886 if (is_valid_policy_hnd(&hive_hnd)) {
3887 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3891 TALLOC_FREE(tmp_ctx);
3895 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
3896 struct dcerpc_binding_handle *winreg_handle,
3897 const char *architecture,
3899 uint32_t *num_drivers,
3900 const char ***drivers_p)
3902 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3903 struct policy_handle hive_hnd, key_hnd;
3904 const char **drivers;
3905 TALLOC_CTX *tmp_ctx;
3912 ZERO_STRUCT(hive_hnd);
3913 ZERO_STRUCT(key_hnd);
3915 tmp_ctx = talloc_stackframe();
3916 if (tmp_ctx == NULL) {
3917 return WERR_NOT_ENOUGH_MEMORY;
3920 /* use NULL for the driver name so we open the key that is
3921 * parent of all drivers for this architecture and version */
3922 result = winreg_printer_opendriver(tmp_ctx,
3930 if (!W_ERROR_IS_OK(result)) {
3931 DEBUG(5, ("winreg_get_driver_list: "
3932 "Could not open key (%s,%u): %s\n",
3933 architecture, version, win_errstr(result)));
3938 status = dcerpc_winreg_enum_keys(tmp_ctx,
3944 if (!NT_STATUS_IS_OK(status)) {
3945 result = ntstatus_to_werror(status);
3947 if (!W_ERROR_IS_OK(result)) {
3948 DEBUG(0, ("winreg_get_driver_list: "
3949 "Could not enumerate drivers for (%s,%u): %s\n",
3950 architecture, version, win_errstr(result)));
3954 *drivers_p = talloc_steal(mem_ctx, drivers);
3958 if (winreg_handle != NULL) {
3961 if (is_valid_policy_hnd(&key_hnd)) {
3962 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3964 if (is_valid_policy_hnd(&hive_hnd)) {
3965 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3969 TALLOC_FREE(tmp_ctx);
3973 WERROR winreg_get_core_driver(TALLOC_CTX *mem_ctx,
3974 struct dcerpc_binding_handle *winreg_handle,
3975 const char *architecture,
3976 const struct GUID *core_driver_guid,
3977 struct spoolss_CorePrinterDriver **_core_printer_driver)
3979 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3980 struct policy_handle hive_hnd, key_hnd;
3981 struct spoolss_CorePrinterDriver *c;
3982 struct spoolss_PrinterEnumValues *enum_values = NULL;
3983 struct spoolss_PrinterEnumValues *v;
3984 uint32_t num_values = 0;
3985 TALLOC_CTX *tmp_ctx;
3989 const char *guid_str;
3991 const char **enum_names = NULL;
3992 enum winreg_Type *enum_types = NULL;
3993 DATA_BLOB *enum_data_blobs = NULL;
3995 ZERO_STRUCT(hive_hnd);
3996 ZERO_STRUCT(key_hnd);
3998 tmp_ctx = talloc_stackframe();
3999 if (tmp_ctx == NULL) {
4000 return WERR_NOT_ENOUGH_MEMORY;
4003 path = talloc_asprintf(tmp_ctx, "%s\\%s\\CorePrinterDrivers",
4004 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
4007 result = WERR_NOT_ENOUGH_MEMORY;
4011 guid_str = GUID_string2(tmp_ctx, core_driver_guid);
4012 if (guid_str == NULL) {
4013 result = WERR_NOT_ENOUGH_MEMORY;
4017 result = winreg_printer_openkey(tmp_ctx,
4026 if (!W_ERROR_IS_OK(result)) {
4027 DEBUG(5, ("winreg_get_core_driver: "
4028 "Could not open core driver key (%s,%s): %s\n",
4029 guid_str, architecture, win_errstr(result)));
4033 status = dcerpc_winreg_enumvals(tmp_ctx,
4041 if (!NT_STATUS_IS_OK(status)){
4042 result = ntstatus_to_werror(status);
4045 if (!W_ERROR_IS_OK(result)) {
4046 DEBUG(0, ("winreg_get_core_driver: "
4047 "Could not enumerate values for (%s,%s): %s\n",
4048 guid_str, architecture, win_errstr(result)));
4052 enum_values = talloc_zero_array(tmp_ctx,
4053 struct spoolss_PrinterEnumValues,
4055 if (enum_values == NULL){
4056 result = WERR_NOT_ENOUGH_MEMORY;
4060 for (i = 0; i < num_values; i++){
4061 enum_values[i].value_name = enum_names[i];
4062 enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
4063 enum_values[i].type = enum_types[i];
4064 enum_values[i].data_length = enum_data_blobs[i].length;
4065 enum_values[i].data = NULL;
4066 if (enum_values[i].data_length != 0){
4067 enum_values[i].data = &enum_data_blobs[i];
4071 c = talloc_zero(tmp_ctx, struct spoolss_CorePrinterDriver);
4073 result = WERR_NOT_ENOUGH_MEMORY;
4077 c->core_driver_guid = *core_driver_guid;
4081 for (i = 0; i < num_values; i++) {
4082 const char *tmp_str;
4084 v = &enum_values[i];
4086 result = winreg_enumval_to_sz(c, v,
4089 CHECK_ERROR(result);
4091 result = winreg_enumval_to_sz(c, v,
4094 if (W_ERROR_IS_OK(result)) {
4095 result = winreg_printer_date_to_NTTIME(tmp_str,
4098 CHECK_ERROR(result);
4100 result = winreg_enumval_to_sz(c, v,
4103 if (W_ERROR_IS_OK(result)) {
4104 result = winreg_printer_ver_to_qword(tmp_str,
4105 &c->driver_version);
4107 CHECK_ERROR(result);
4110 if (!W_ERROR_IS_OK(result)) {
4111 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4112 "for %s: %s\n", v->value_name,
4113 win_errstr(result)));
4117 *_core_printer_driver = talloc_steal(mem_ctx, c);
4120 if (winreg_handle != NULL) {
4123 if (is_valid_policy_hnd(&key_hnd)) {
4124 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4126 if (is_valid_policy_hnd(&hive_hnd)) {
4127 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4131 TALLOC_FREE(tmp_ctx);