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 "srv_spoolss_util.h"
25 #include "../librpc/gen_ndr/ndr_spoolss.h"
26 #include "../librpc/gen_ndr/srv_winreg.h"
27 #include "../librpc/gen_ndr/ndr_winreg_c.h"
28 #include "../librpc/gen_ndr/ndr_security.h"
30 #include "rpc_server/rpc_ncacn_np.h"
31 #include "../libcli/security/security.h"
32 #include "rpc_client/cli_winreg.h"
34 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
35 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
36 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
37 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
39 #define EMPTY_STRING ""
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, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
59 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
60 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
61 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
62 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
63 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
64 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
65 { SPOOLSS_FORM_BUILTIN, "A0", {0xcd528,0x122488},{0x0,0x0,0xcd528,0x122488} },
66 { SPOOLSS_FORM_BUILTIN, "A1", {0x91050,0xcd528}, {0x0,0x0,0x91050,0xcd528} },
67 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
68 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
69 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
70 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
71 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
72 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
73 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
74 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
75 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
76 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
77 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
78 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
79 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
80 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
81 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
82 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
83 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
84 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
85 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
86 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
87 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
88 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
89 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
90 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
91 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
92 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
93 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
94 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
95 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
96 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
97 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
98 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
99 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
100 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
101 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
102 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
103 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
104 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
105 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
106 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
107 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
108 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
109 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
110 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
111 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
112 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
113 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
114 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
115 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
116 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
117 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
118 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
119 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
120 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
121 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
122 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
123 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
124 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
125 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
126 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
127 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
128 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
129 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
130 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
131 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
132 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
133 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
134 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
135 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
136 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
137 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
138 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
139 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
140 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
141 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
142 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
143 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
144 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
145 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
146 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
147 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
148 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
149 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
150 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
151 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} },
152 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
153 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
154 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
159 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
160 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
161 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
162 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
163 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
164 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
165 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
166 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
167 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
168 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
169 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
170 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
171 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
172 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
173 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
174 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
175 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
176 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
177 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} }
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;
221 * @brief Connect to the interal winreg server and open the given printer key.
223 * The function will create the needed subkeys if they don't exist.
225 * @param[in] mem_ctx The memory context to use.
227 * @param[in] session_info The supplied server info.
229 * @param[out] binding_handle A pointer for the winreg dcerpc binding handle.
231 * @param[in] path The path to the key to open.
233 * @param[in] key The key to open.
235 * @param[in] create_key Set to true if the key should be created if it
238 * @param[in] access_mask The access mask to open the key.
240 * @param[out] hive_handle A policy handle for the opened hive.
242 * @param[out] key_handle A policy handle for the opened key.
244 * @return WERR_OK on success, the corresponding DOS error
245 * code if something gone wrong.
247 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
248 const struct auth_serversupplied_info *session_info,
249 struct messaging_context *msg_ctx,
250 struct dcerpc_binding_handle **winreg_binding_handle,
254 uint32_t access_mask,
255 struct policy_handle *hive_handle,
256 struct policy_handle *key_handle)
258 static struct client_address client_id;
259 struct dcerpc_binding_handle *binding_handle;
260 struct winreg_String wkey, wkeyclass;
263 WERROR result = WERR_OK;
265 strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
266 client_id.name = "127.0.0.1";
268 status = rpcint_binding_handle(mem_ctx,
274 if (!NT_STATUS_IS_OK(status)) {
275 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg pipe: %s\n",
277 return ntstatus_to_werror(status);
280 status = dcerpc_winreg_OpenHKLM(binding_handle,
286 if (!NT_STATUS_IS_OK(status)) {
287 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
289 talloc_free(binding_handle);
290 return ntstatus_to_werror(status);
292 if (!W_ERROR_IS_OK(result)) {
293 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
294 win_errstr(result)));
295 talloc_free(binding_handle);
300 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
302 keyname = talloc_strdup(mem_ctx, path);
304 if (keyname == NULL) {
305 talloc_free(binding_handle);
313 enum winreg_CreateAction action = REG_ACTION_NONE;
315 ZERO_STRUCT(wkeyclass);
318 status = dcerpc_winreg_CreateKey(binding_handle,
330 case REG_ACTION_NONE:
331 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
333 case REG_CREATED_NEW_KEY:
334 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
336 case REG_OPENED_EXISTING_KEY:
337 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
341 status = dcerpc_winreg_OpenKey(binding_handle,
350 if (!NT_STATUS_IS_OK(status)) {
351 talloc_free(binding_handle);
352 return ntstatus_to_werror(status);
354 if (!W_ERROR_IS_OK(result)) {
355 talloc_free(binding_handle);
359 *winreg_binding_handle = binding_handle;
365 * @brief Create the registry keyname for the given printer.
367 * @param[in] mem_ctx The memory context to use.
369 * @param[in] printer The name of the printer to get the registry key.
371 * @return The registry key or NULL on error.
373 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
374 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
380 * @brief Enumerate values of an opened key handle and retrieve the data.
382 * @param[in] mem_ctx The memory context to use.
384 * @param[in] winreg_handle The binding handle for the rpc connection.
386 * @param[in] key_hnd The opened key handle.
388 * @param[out] pnum_values A pointer to store he number of values found.
390 * @param[out] pnum_values A pointer to store the number of values we found.
392 * @return WERR_OK on success, the corresponding DOS error
393 * code if something gone wrong.
395 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
396 struct dcerpc_binding_handle *winreg_handle,
397 struct policy_handle *key_hnd,
398 uint32_t *pnum_values,
399 struct spoolss_PrinterEnumValues **penum_values)
402 uint32_t num_subkeys, max_subkeylen, max_classlen;
403 uint32_t num_values, max_valnamelen, max_valbufsize;
404 uint32_t secdescsize;
406 NTTIME last_changed_time;
407 struct winreg_String classname;
409 struct spoolss_PrinterEnumValues *enum_values;
411 WERROR result = WERR_OK;
414 tmp_ctx = talloc_stackframe();
415 if (tmp_ctx == NULL) {
419 ZERO_STRUCT(classname);
421 status = dcerpc_winreg_QueryInfoKey(winreg_handle,
434 if (!NT_STATUS_IS_OK(status)) {
435 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
437 result = ntstatus_to_werror(status);
440 if (!W_ERROR_IS_OK(result)) {
441 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
442 win_errstr(result)));
446 if (num_values == 0) {
448 TALLOC_FREE(tmp_ctx);
452 enum_values = TALLOC_ARRAY(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
453 if (enum_values == NULL) {
458 for (i = 0; i < num_values; i++) {
459 struct spoolss_PrinterEnumValues val;
460 struct winreg_ValNameBuf name_buf;
461 enum winreg_Type type = REG_NONE;
468 name_buf.size = max_valnamelen + 2;
471 data_size = max_valbufsize;
474 data = (uint8_t *) TALLOC(tmp_ctx, data_size);
478 status = dcerpc_winreg_EnumValue(winreg_handle,
485 data_size ? &data_size : NULL,
488 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
490 status = NT_STATUS_OK;
494 if (!NT_STATUS_IS_OK(status)) {
495 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
497 result = ntstatus_to_werror(status);
500 if (!W_ERROR_IS_OK(result)) {
501 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
502 win_errstr(result)));
506 if (name_buf.name == NULL) {
507 result = WERR_INVALID_PARAMETER;
511 val.value_name = talloc_strdup(enum_values, name_buf.name);
512 if (val.value_name == NULL) {
516 val.value_name_len = strlen_m_term(val.value_name) * 2;
519 val.data_length = length;
521 if (val.data_length) {
522 val.data = talloc(enum_values, DATA_BLOB);
523 if (val.data == NULL) {
527 *val.data = data_blob_talloc(val.data, data, val.data_length);
530 enum_values[i] = val;
533 *pnum_values = num_values;
535 *penum_values = talloc_move(mem_ctx, &enum_values);
541 TALLOC_FREE(tmp_ctx);
548 * @brief A function to delete a key and its subkeys recurively.
550 * @param[in] mem_ctx The memory context to use.
552 * @param[in] winreg_handle The binding handle for the rpc connection.
554 * @param[in] hive_handle A opened hive handle to the key.
556 * @param[in] access_mask The access mask to access the key.
558 * @param[in] key The key to delete
560 * @return WERR_OK on success, the corresponding DOS error
561 * code if something gone wrong.
563 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
564 struct dcerpc_binding_handle *winreg_handle,
565 struct policy_handle *hive_handle,
566 uint32_t access_mask,
569 const char **subkeys = NULL;
570 uint32_t num_subkeys = 0;
571 struct policy_handle key_hnd;
572 struct winreg_String wkey = { 0, };
573 WERROR result = WERR_OK;
577 ZERO_STRUCT(key_hnd);
580 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
582 status = dcerpc_winreg_OpenKey(winreg_handle,
590 if (!NT_STATUS_IS_OK(status)) {
591 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
592 wkey.name, nt_errstr(status)));
593 return ntstatus_to_werror(status);
595 if (!W_ERROR_IS_OK(result)) {
596 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
597 wkey.name, win_errstr(result)));
601 status = dcerpc_winreg_enum_keys(mem_ctx,
607 if (!NT_STATUS_IS_OK(status)) {
608 result = ntstatus_to_werror(status);
610 if (!W_ERROR_IS_OK(result)) {
614 for (i = 0; i < num_subkeys; i++) {
615 /* create key + subkey */
616 char *subkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkeys[i]);
617 if (subkey == NULL) {
621 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey));
622 result = winreg_printer_delete_subkeys(mem_ctx,
627 if (!W_ERROR_IS_OK(result)) {
632 if (is_valid_policy_hnd(&key_hnd)) {
634 dcerpc_winreg_CloseKey(winreg_handle, mem_ctx, &key_hnd, &ignore);
639 status = dcerpc_winreg_DeleteKey(winreg_handle,
644 if (!NT_STATUS_IS_OK(status)) {
645 result = ntstatus_to_werror(status);
649 if (is_valid_policy_hnd(&key_hnd)) {
652 dcerpc_winreg_CloseKey(winreg_handle, mem_ctx, &key_hnd, &ignore);
658 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
659 const struct auth_serversupplied_info *session_info,
660 struct messaging_context *msg_ctx,
661 const char *drivername,
662 const char *architecture,
664 uint32_t access_mask,
666 struct dcerpc_binding_handle **winreg_binding_handle,
667 struct policy_handle *hive_hnd,
668 struct policy_handle *key_hnd)
673 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
674 TOP_LEVEL_CONTROL_KEY,
675 architecture, version);
680 result = winreg_printer_openkey(mem_ctx,
683 winreg_binding_handle,
693 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
694 struct spoolss_PrinterEnumValues *v,
695 const char *valuename, uint32_t *dw)
697 /* just return if it is not the one we are looking for */
698 if (strcmp(valuename, v->value_name) != 0) {
699 return WERR_NOT_FOUND;
702 if (v->type != REG_DWORD) {
703 return WERR_INVALID_DATATYPE;
706 if (v->data_length != 4) {
711 *dw = IVAL(v->data->data, 0);
715 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
716 struct spoolss_PrinterEnumValues *v,
717 const char *valuename, const char **_str)
719 /* just return if it is not the one we are looking for */
720 if (strcmp(valuename, v->value_name) != 0) {
721 return WERR_NOT_FOUND;
724 if (v->type != REG_SZ) {
725 return WERR_INVALID_DATATYPE;
728 if (v->data_length == 0) {
729 *_str = talloc_strdup(mem_ctx, EMPTY_STRING);
736 if (!pull_reg_sz(mem_ctx, v->data, _str)) {
743 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
744 struct spoolss_PrinterEnumValues *v,
745 const char *valuename,
748 /* just return if it is not the one we are looking for */
749 if (strcmp(valuename, v->value_name) != 0) {
750 return WERR_NOT_FOUND;
753 if (v->type != REG_MULTI_SZ) {
754 return WERR_INVALID_DATATYPE;
757 if (v->data_length == 0) {
758 *array = talloc_array(mem_ctx, const char *, 1);
759 if (*array == NULL) {
766 if (!pull_reg_multi_sz(mem_ctx, v->data, array)) {
773 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
774 struct dcerpc_binding_handle *winreg_handle,
775 struct policy_handle *key_handle,
779 struct winreg_String wvalue;
781 WERROR result = WERR_OK;
788 str = talloc_strdup(mem_ctx, "01/01/1601");
790 t = nt_time_to_unix(data);
792 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
793 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
800 if (!push_reg_sz(mem_ctx, &blob, str)) {
803 status = dcerpc_winreg_SetValue(winreg_handle,
811 if (!NT_STATUS_IS_OK(status)) {
812 result = ntstatus_to_werror(status);
814 if (!W_ERROR_IS_OK(result)) {
815 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
816 wvalue.name, win_errstr(result)));
822 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
827 if (strequal(str, "01/01/1601")) {
834 if (sscanf(str, "%d/%d/%d",
835 &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3) {
836 return WERR_INVALID_PARAMETER;
843 unix_to_nt_time(data, t);
848 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
849 struct dcerpc_binding_handle *winreg_handle,
850 struct policy_handle *key_handle,
854 struct winreg_String wvalue = { 0, };
856 WERROR result = WERR_OK;
860 /* FIXME: check format is right,
861 * this needs to be something like: 6.1.7600.16385 */
862 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
863 (unsigned)((data >> 48) & 0xFFFF),
864 (unsigned)((data >> 32) & 0xFFFF),
865 (unsigned)((data >> 16) & 0xFFFF),
866 (unsigned)(data & 0xFFFF));
872 if (!push_reg_sz(mem_ctx, &blob, str)) {
875 status = dcerpc_winreg_SetValue(winreg_handle,
883 if (!NT_STATUS_IS_OK(status)) {
884 result = ntstatus_to_werror(status);
886 if (!W_ERROR_IS_OK(result)) {
887 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
888 wvalue.name, win_errstr(result)));
894 static WERROR winreg_printer_ver_to_dword(const char *str, uint64_t *data)
896 unsigned int v1, v2, v3, v4;
898 if (sscanf(str, "%u.%u.%u.%u", &v1, &v2, &v3, &v4) != 4) {
899 return WERR_INVALID_PARAMETER;
902 *data = ((uint64_t)(v1 & 0xFFFF) << 48) +
903 ((uint64_t)(v2 & 0xFFFF) << 32) +
904 ((uint64_t)(v3 & 0xFFFF) << 16) +
905 (uint64_t)(v2 & 0xFFFF);
910 /********************************************************************
911 Public winreg function for spoolss
912 ********************************************************************/
914 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
915 const struct auth_serversupplied_info *session_info,
916 struct messaging_context *msg_ctx,
917 const char *sharename)
919 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
920 struct dcerpc_binding_handle *winreg_handle = NULL;
921 struct policy_handle hive_hnd, key_hnd;
922 struct spoolss_SetPrinterInfo2 *info2;
923 struct security_descriptor *secdesc;
924 struct winreg_String wkey, wkeyclass;
926 const char *subkeys[] = { SPOOL_DSDRIVER_KEY, SPOOL_DSSPOOLER_KEY, SPOOL_PRINTERDATA_KEY };
927 uint32_t i, count = ARRAY_SIZE(subkeys);
928 uint32_t info2_mask = 0;
929 WERROR result = WERR_OK;
932 tmp_ctx = talloc_stackframe();
933 if (tmp_ctx == NULL) {
937 path = winreg_printer_data_keyname(tmp_ctx, sharename);
939 TALLOC_FREE(tmp_ctx);
943 ZERO_STRUCT(hive_hnd);
944 ZERO_STRUCT(key_hnd);
946 result = winreg_printer_openkey(tmp_ctx,
956 if (W_ERROR_IS_OK(result)) {
957 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
959 } else if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
960 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
961 } else if (!W_ERROR_IS_OK(result)) {
962 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
963 path, win_errstr(result)));
967 /* Create the main key */
968 result = winreg_printer_openkey(tmp_ctx,
978 if (!W_ERROR_IS_OK(result)) {
979 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
980 path, win_errstr(result)));
984 if (is_valid_policy_hnd(&key_hnd)) {
985 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
989 for (i = 0; i < count; i++) {
991 enum winreg_CreateAction action = REG_ACTION_NONE;
993 ZERO_STRUCT(key_hnd);
996 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
997 if (wkey.name == NULL) {
1002 ZERO_STRUCT(wkeyclass);
1003 wkeyclass.name = "";
1005 status = dcerpc_winreg_CreateKey(winreg_handle,
1016 if (!NT_STATUS_IS_OK(status)) {
1017 result = ntstatus_to_werror(status);
1019 if (!W_ERROR_IS_OK(result)) {
1020 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1021 wkey.name, win_errstr(result)));
1025 if (strequal(subkeys[i], SPOOL_DSSPOOLER_KEY)) {
1026 const char *dnssuffix;
1027 const char *longname;
1028 const char *uncname;
1030 status = dcerpc_winreg_set_sz(tmp_ctx,
1033 SPOOL_REG_PRINTERNAME,
1036 if (!NT_STATUS_IS_OK(status)) {
1037 result = ntstatus_to_werror(status);
1039 if (!W_ERROR_IS_OK(result)) {
1043 status = dcerpc_winreg_set_sz(tmp_ctx,
1046 SPOOL_REG_SHORTSERVERNAME,
1049 if (!NT_STATUS_IS_OK(status)) {
1050 result = ntstatus_to_werror(status);
1052 if (!W_ERROR_IS_OK(result)) {
1056 /* We make the assumption that the netbios name
1057 * is the same as the DNS name since the former
1058 * will be what we used to join the domain
1060 dnssuffix = get_mydnsdomname(tmp_ctx);
1061 if (dnssuffix != NULL && dnssuffix[0] != '\0') {
1062 longname = talloc_asprintf(tmp_ctx, "%s.%s", global_myname(), dnssuffix);
1064 longname = talloc_strdup(tmp_ctx, global_myname());
1066 if (longname == NULL) {
1067 result = WERR_NOMEM;
1071 status = dcerpc_winreg_set_sz(tmp_ctx,
1074 SPOOL_REG_SERVERNAME,
1077 if (!NT_STATUS_IS_OK(status)) {
1078 result = ntstatus_to_werror(status);
1080 if (!W_ERROR_IS_OK(result)) {
1084 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
1085 longname, sharename);
1086 if (uncname == NULL) {
1087 result = WERR_NOMEM;
1091 status = dcerpc_winreg_set_sz(tmp_ctx,
1097 if (!NT_STATUS_IS_OK(status)) {
1098 result = ntstatus_to_werror(status);
1100 if (!W_ERROR_IS_OK(result)) {
1104 status = dcerpc_winreg_set_dword(tmp_ctx,
1107 SPOOL_REG_VERSIONNUMBER,
1110 if (!NT_STATUS_IS_OK(status)) {
1111 result = ntstatus_to_werror(status);
1113 if (!W_ERROR_IS_OK(result)) {
1117 status = dcerpc_winreg_set_dword(tmp_ctx,
1120 SPOOL_REG_PRINTSTARTTIME,
1123 if (!NT_STATUS_IS_OK(status)) {
1124 result = ntstatus_to_werror(status);
1126 if (!W_ERROR_IS_OK(result)) {
1130 status = dcerpc_winreg_set_dword(tmp_ctx,
1133 SPOOL_REG_PRINTENDTIME,
1136 if (!NT_STATUS_IS_OK(status)) {
1137 result = ntstatus_to_werror(status);
1139 if (!W_ERROR_IS_OK(result)) {
1143 status = dcerpc_winreg_set_dword(tmp_ctx,
1149 if (!NT_STATUS_IS_OK(status)) {
1150 result = ntstatus_to_werror(status);
1152 if (!W_ERROR_IS_OK(result)) {
1156 status = dcerpc_winreg_set_dword(tmp_ctx,
1159 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
1162 if (!NT_STATUS_IS_OK(status)) {
1163 result = ntstatus_to_werror(status);
1165 if (!W_ERROR_IS_OK(result)) {
1170 if (is_valid_policy_hnd(&key_hnd)) {
1171 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
1174 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
1175 if (info2 == NULL) {
1176 result = WERR_NOMEM;
1180 info2->printername = sharename;
1181 if (info2->printername == NULL) {
1182 result = WERR_NOMEM;
1185 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1187 info2->sharename = sharename;
1188 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1190 info2->portname = SAMBA_PRINTER_PORT_NAME;
1191 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1193 info2->printprocessor = "winprint";
1194 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1196 info2->datatype = "RAW";
1197 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1199 info2->comment = "";
1200 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1202 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1203 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1205 info2->starttime = 0; /* Minutes since 12:00am GMT */
1206 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1208 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1209 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1211 info2->priority = 1;
1212 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1214 info2->defaultpriority = 1;
1215 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1217 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1218 if (!W_ERROR_IS_OK(result)) {
1221 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1224 * Don't write a default Device Mode to the registry! The Device Mode is
1225 * only written to disk with a SetPrinter level 2 or 8.
1228 result = winreg_update_printer(tmp_ctx,
1238 if (winreg_handle != NULL) {
1241 if (is_valid_policy_hnd(&key_hnd)) {
1242 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1244 if (is_valid_policy_hnd(&hive_hnd)) {
1245 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1249 talloc_free(tmp_ctx);
1253 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1254 const struct auth_serversupplied_info *session_info,
1255 struct messaging_context *msg_ctx,
1256 const char *sharename,
1257 uint32_t info2_mask,
1258 struct spoolss_SetPrinterInfo2 *info2,
1259 struct spoolss_DeviceMode *devmode,
1260 struct security_descriptor *secdesc)
1262 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1263 struct dcerpc_binding_handle *winreg_handle = NULL;
1264 struct policy_handle hive_hnd, key_hnd;
1265 int snum = lp_servicenumber(sharename);
1266 enum ndr_err_code ndr_err;
1269 WERROR result = WERR_OK;
1271 TALLOC_CTX *tmp_ctx;
1273 tmp_ctx = talloc_stackframe();
1274 if (tmp_ctx == NULL) {
1278 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1280 TALLOC_FREE(tmp_ctx);
1284 ZERO_STRUCT(hive_hnd);
1285 ZERO_STRUCT(key_hnd);
1287 result = winreg_printer_openkey(tmp_ctx,
1297 if (!W_ERROR_IS_OK(result)) {
1298 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1299 path, win_errstr(result)));
1303 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1304 status = dcerpc_winreg_set_dword(tmp_ctx,
1310 if (!NT_STATUS_IS_OK(status)) {
1311 result = ntstatus_to_werror(status);
1313 if (!W_ERROR_IS_OK(result)) {
1319 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1320 status = dcerpc_winreg_set_dword(tmp_ctx,
1326 if (!NT_STATUS_IS_OK(status)) {
1327 result = ntstatus_to_werror(status);
1329 if (!W_ERROR_IS_OK(result)) {
1335 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1336 status = dcerpc_winreg_set_sz(tmp_ctx,
1342 if (!NT_STATUS_IS_OK(status)) {
1343 result = ntstatus_to_werror(status);
1345 if (!W_ERROR_IS_OK(result)) {
1350 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1351 status = dcerpc_winreg_set_sz(tmp_ctx,
1357 if (!NT_STATUS_IS_OK(status)) {
1358 result = ntstatus_to_werror(status);
1360 if (!W_ERROR_IS_OK(result)) {
1365 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1366 status = dcerpc_winreg_set_dword(tmp_ctx,
1370 info2->defaultpriority,
1372 if (!NT_STATUS_IS_OK(status)) {
1373 result = ntstatus_to_werror(status);
1375 if (!W_ERROR_IS_OK(result)) {
1380 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1382 * Some client drivers freak out if there is a NULL devmode
1383 * (probably the driver is not checking before accessing
1384 * the devmode pointer) --jerry
1386 if (devmode == NULL && lp_default_devmode(snum) && info2 != NULL) {
1387 result = spoolss_create_default_devmode(tmp_ctx,
1390 if (!W_ERROR_IS_OK(result)) {
1395 if (devmode->size != (ndr_size_spoolss_DeviceMode(devmode, 0) - devmode->__driverextra_length)) {
1396 result = WERR_INVALID_PARAM;
1400 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, devmode,
1401 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1402 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1403 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1404 result = WERR_NOMEM;
1408 status = dcerpc_winreg_set_binary(tmp_ctx,
1414 if (!NT_STATUS_IS_OK(status)) {
1415 result = ntstatus_to_werror(status);
1417 if (!W_ERROR_IS_OK(result)) {
1422 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1423 status = dcerpc_winreg_set_sz(tmp_ctx,
1429 if (!NT_STATUS_IS_OK(status)) {
1430 result = ntstatus_to_werror(status);
1432 if (!W_ERROR_IS_OK(result)) {
1437 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1438 status = dcerpc_winreg_set_sz(tmp_ctx,
1444 if (!NT_STATUS_IS_OK(status)) {
1445 result = ntstatus_to_werror(status);
1447 if (!W_ERROR_IS_OK(result)) {
1452 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1453 status = dcerpc_winreg_set_sz(tmp_ctx,
1459 if (!NT_STATUS_IS_OK(status)) {
1460 result = ntstatus_to_werror(status);
1462 if (!W_ERROR_IS_OK(result)) {
1467 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1468 status = dcerpc_winreg_set_sz(tmp_ctx,
1474 if (!NT_STATUS_IS_OK(status)) {
1475 result = ntstatus_to_werror(status);
1477 if (!W_ERROR_IS_OK(result)) {
1482 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1484 * in addprinter: no servername and the printer is the name
1485 * in setprinter: servername is \\server
1486 * and printer is \\server\\printer
1488 * Samba manages only local printers.
1489 * we currently don't support things like i
1490 * path=\\other_server\printer
1492 * We only store the printername, not \\server\printername
1494 const char *p = strrchr(info2->printername, '\\');
1496 p = info2->printername;
1500 status = dcerpc_winreg_set_sz(tmp_ctx,
1506 if (!NT_STATUS_IS_OK(status)) {
1507 result = ntstatus_to_werror(status);
1509 if (!W_ERROR_IS_OK(result)) {
1514 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1515 status = dcerpc_winreg_set_sz(tmp_ctx,
1519 info2->printprocessor,
1521 if (!NT_STATUS_IS_OK(status)) {
1522 result = ntstatus_to_werror(status);
1524 if (!W_ERROR_IS_OK(result)) {
1529 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1530 status = dcerpc_winreg_set_dword(tmp_ctx,
1536 if (!NT_STATUS_IS_OK(status)) {
1537 result = ntstatus_to_werror(status);
1539 if (!W_ERROR_IS_OK(result)) {
1544 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1546 * We need a security descriptor, if it isn't specified by
1547 * AddPrinter{Ex} then create a default descriptor.
1549 if (secdesc == NULL) {
1550 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1551 if (!W_ERROR_IS_OK(result)) {
1555 result = winreg_set_printer_secdesc(tmp_ctx,
1560 if (!W_ERROR_IS_OK(result)) {
1565 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1566 status = dcerpc_winreg_set_sz(tmp_ctx,
1572 if (!NT_STATUS_IS_OK(status)) {
1573 result = ntstatus_to_werror(status);
1575 if (!W_ERROR_IS_OK(result)) {
1580 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1581 status = dcerpc_winreg_set_sz(tmp_ctx,
1587 if (!NT_STATUS_IS_OK(status)) {
1588 result = ntstatus_to_werror(status);
1590 if (!W_ERROR_IS_OK(result)) {
1595 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1596 status = dcerpc_winreg_set_dword(tmp_ctx,
1602 if (!NT_STATUS_IS_OK(status)) {
1603 result = ntstatus_to_werror(status);
1605 if (!W_ERROR_IS_OK(result)) {
1610 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1611 status = dcerpc_winreg_set_dword(tmp_ctx,
1617 if (!NT_STATUS_IS_OK(status)) {
1618 result = ntstatus_to_werror(status);
1620 if (!W_ERROR_IS_OK(result)) {
1625 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1626 status = dcerpc_winreg_set_dword(tmp_ctx,
1632 if (!NT_STATUS_IS_OK(status)) {
1633 result = ntstatus_to_werror(status);
1635 if (!W_ERROR_IS_OK(result)) {
1640 status = dcerpc_winreg_set_dword(tmp_ctx,
1644 winreg_printer_rev_changeid(),
1646 if (!NT_STATUS_IS_OK(status)) {
1647 result = ntstatus_to_werror(status);
1649 if (!W_ERROR_IS_OK(result)) {
1655 if (winreg_handle != NULL) {
1658 if (is_valid_policy_hnd(&key_hnd)) {
1659 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1661 if (is_valid_policy_hnd(&hive_hnd)) {
1662 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1666 TALLOC_FREE(tmp_ctx);
1670 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1671 const struct auth_serversupplied_info *session_info,
1672 struct messaging_context *msg_ctx,
1673 const char *printer,
1674 struct spoolss_PrinterInfo2 **pinfo2)
1676 struct spoolss_PrinterInfo2 *info2;
1677 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1678 struct dcerpc_binding_handle *winreg_handle = NULL;
1679 struct policy_handle hive_hnd, key_hnd;
1680 struct spoolss_PrinterEnumValues *enum_values = NULL;
1681 struct spoolss_PrinterEnumValues *v = NULL;
1682 enum ndr_err_code ndr_err;
1684 int snum = lp_servicenumber(printer);
1685 uint32_t num_values = 0;
1689 WERROR result = WERR_OK;
1690 TALLOC_CTX *tmp_ctx;
1692 tmp_ctx = talloc_stackframe();
1693 if (tmp_ctx == NULL) {
1697 path = winreg_printer_data_keyname(tmp_ctx, printer);
1699 TALLOC_FREE(tmp_ctx);
1703 result = winreg_printer_openkey(tmp_ctx,
1713 if (!W_ERROR_IS_OK(result)) {
1714 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
1715 path, win_errstr(result)));
1719 result = winreg_printer_enumvalues(tmp_ctx,
1724 if (!W_ERROR_IS_OK(result)) {
1725 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1726 path, win_errstr(result)));
1730 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
1731 if (info2 == NULL) {
1732 result = WERR_NOMEM;
1736 FILL_STRING(info2, EMPTY_STRING, info2->servername);
1737 FILL_STRING(info2, EMPTY_STRING, info2->printername);
1738 FILL_STRING(info2, EMPTY_STRING, info2->sharename);
1739 FILL_STRING(info2, EMPTY_STRING, info2->portname);
1740 FILL_STRING(info2, EMPTY_STRING, info2->drivername);
1741 FILL_STRING(info2, EMPTY_STRING, info2->comment);
1742 FILL_STRING(info2, EMPTY_STRING, info2->location);
1743 FILL_STRING(info2, EMPTY_STRING, info2->sepfile);
1744 FILL_STRING(info2, EMPTY_STRING, info2->printprocessor);
1745 FILL_STRING(info2, EMPTY_STRING, info2->datatype);
1746 FILL_STRING(info2, EMPTY_STRING, info2->parameters);
1748 for (i = 0; i < num_values; i++) {
1749 v = &enum_values[i];
1751 result = winreg_enumval_to_sz(info2,
1754 &info2->printername);
1755 CHECK_ERROR(result);
1757 result = winreg_enumval_to_sz(info2,
1761 CHECK_ERROR(result);
1763 result = winreg_enumval_to_sz(info2,
1767 CHECK_ERROR(result);
1769 result = winreg_enumval_to_sz(info2,
1773 CHECK_ERROR(result);
1775 result = winreg_enumval_to_sz(info2,
1779 CHECK_ERROR(result);
1781 result = winreg_enumval_to_sz(info2,
1785 CHECK_ERROR(result);
1787 result = winreg_enumval_to_sz(info2,
1790 &info2->printprocessor);
1791 CHECK_ERROR(result);
1793 result = winreg_enumval_to_sz(info2,
1797 CHECK_ERROR(result);
1799 result = winreg_enumval_to_sz(info2,
1802 &info2->parameters);
1803 CHECK_ERROR(result);
1805 result = winreg_enumval_to_sz(info2,
1808 &info2->drivername);
1809 CHECK_ERROR(result);
1811 result = winreg_enumval_to_dword(info2,
1814 &info2->attributes);
1815 CHECK_ERROR(result);
1817 result = winreg_enumval_to_dword(info2,
1821 CHECK_ERROR(result);
1823 result = winreg_enumval_to_dword(info2,
1826 &info2->defaultpriority);
1827 CHECK_ERROR(result);
1829 result = winreg_enumval_to_dword(info2,
1833 CHECK_ERROR(result);
1835 result = winreg_enumval_to_dword(info2,
1839 CHECK_ERROR(result);
1841 result = winreg_enumval_to_dword(info2,
1845 CHECK_ERROR(result);
1847 result = winreg_enumval_to_dword(info2,
1851 CHECK_ERROR(result);
1854 if (!W_ERROR_IS_OK(result)) {
1855 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
1858 win_errstr(result)));
1862 /* Construct the Device Mode */
1863 status = dcerpc_winreg_query_binary(tmp_ctx,
1869 if (!NT_STATUS_IS_OK(status)) {
1870 result = ntstatus_to_werror(status);
1872 if (W_ERROR_IS_OK(result)) {
1873 info2->devmode = talloc_zero(info2, struct spoolss_DeviceMode);
1874 if (info2->devmode == NULL) {
1875 result = WERR_NOMEM;
1878 ndr_err = ndr_pull_struct_blob(&blob,
1881 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
1882 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1883 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
1884 result = WERR_NOMEM;
1889 if (info2->devmode == NULL && lp_default_devmode(snum)) {
1890 result = spoolss_create_default_devmode(info2,
1893 if (!W_ERROR_IS_OK(result)) {
1898 if (info2->devmode) {
1899 info2->devmode->size = ndr_size_spoolss_DeviceMode(info2->devmode, 0) - info2->devmode->driverextra_data.length;
1902 result = winreg_get_printer_secdesc(info2,
1907 if (!W_ERROR_IS_OK(result)) {
1911 /* Fix for OS/2 drivers. */
1912 if (get_remote_arch() == RA_OS2) {
1913 spoolss_map_to_os2_driver(info2, &info2->drivername);
1917 *pinfo2 = talloc_move(mem_ctx, &info2);
1922 if (winreg_handle != NULL) {
1925 if (is_valid_policy_hnd(&key_hnd)) {
1926 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1928 if (is_valid_policy_hnd(&hive_hnd)) {
1929 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1933 TALLOC_FREE(tmp_ctx);
1937 WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
1938 const struct auth_serversupplied_info *session_info,
1939 struct messaging_context *msg_ctx,
1940 const char *sharename,
1941 struct spoolss_security_descriptor **psecdesc)
1943 struct spoolss_security_descriptor *secdesc;
1944 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1945 struct dcerpc_binding_handle *winreg_handle = NULL;
1946 struct policy_handle hive_hnd, key_hnd;
1948 TALLOC_CTX *tmp_ctx;
1952 tmp_ctx = talloc_stackframe();
1953 if (tmp_ctx == NULL) {
1957 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1959 talloc_free(tmp_ctx);
1963 ZERO_STRUCT(hive_hnd);
1964 ZERO_STRUCT(key_hnd);
1966 result = winreg_printer_openkey(tmp_ctx,
1976 if (!W_ERROR_IS_OK(result)) {
1977 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1978 goto create_default;
1983 status = dcerpc_winreg_query_sd(tmp_ctx,
1989 if (!NT_STATUS_IS_OK(status)) {
1990 result = ntstatus_to_werror(status);
1992 if (!W_ERROR_IS_OK(result)) {
1993 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1994 goto create_default;
2000 *psecdesc = talloc_move(mem_ctx, &secdesc);
2007 result = winreg_printer_openkey(tmp_ctx,
2017 if (!W_ERROR_IS_OK(result)) {
2021 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
2022 if (!W_ERROR_IS_OK(result)) {
2026 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
2027 this security descriptor has been created when winbindd was
2028 down. Take ownership of security descriptor. */
2029 if (dom_sid_equal(secdesc->owner_sid, &global_sid_World)) {
2030 struct dom_sid owner_sid;
2032 /* Change sd owner to workgroup administrator */
2034 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid)) {
2035 struct spoolss_security_descriptor *new_secdesc;
2039 sid_append_rid(&owner_sid, DOMAIN_RID_ADMINISTRATOR);
2041 new_secdesc = make_sec_desc(tmp_ctx,
2050 if (new_secdesc == NULL) {
2051 result = WERR_NOMEM;
2055 /* Swap with other one */
2056 secdesc = new_secdesc;
2060 status = dcerpc_winreg_set_sd(tmp_ctx,
2066 if (!NT_STATUS_IS_OK(status)) {
2067 result = ntstatus_to_werror(status);
2069 if (!W_ERROR_IS_OK(result)) {
2074 *psecdesc = talloc_move(mem_ctx, &secdesc);
2079 if (winreg_handle != NULL) {
2082 if (is_valid_policy_hnd(&key_hnd)) {
2083 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2085 if (is_valid_policy_hnd(&hive_hnd)) {
2086 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2090 talloc_free(tmp_ctx);
2094 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
2095 const struct auth_serversupplied_info *session_info,
2096 struct messaging_context *msg_ctx,
2097 const char *sharename,
2098 const struct spoolss_security_descriptor *secdesc)
2100 const struct spoolss_security_descriptor *new_secdesc = secdesc;
2101 struct spoolss_security_descriptor *old_secdesc;
2102 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2103 struct dcerpc_binding_handle *winreg_handle = NULL;
2104 struct policy_handle hive_hnd, key_hnd;
2106 TALLOC_CTX *tmp_ctx;
2110 tmp_ctx = talloc_stackframe();
2111 if (tmp_ctx == NULL) {
2115 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2117 talloc_free(tmp_ctx);
2122 * The old owner and group sids of the security descriptor are not
2123 * present when new ACEs are added or removed by changing printer
2124 * permissions through NT. If they are NULL in the new security
2125 * descriptor then copy them over from the old one.
2127 if (!secdesc->owner_sid || !secdesc->group_sid) {
2128 struct dom_sid *owner_sid, *group_sid;
2129 struct security_acl *dacl, *sacl;
2132 result = winreg_get_printer_secdesc(tmp_ctx,
2137 if (!W_ERROR_IS_OK(result)) {
2138 talloc_free(tmp_ctx);
2142 /* Pick out correct owner and group sids */
2143 owner_sid = secdesc->owner_sid ?
2144 secdesc->owner_sid :
2145 old_secdesc->owner_sid;
2147 group_sid = secdesc->group_sid ?
2148 secdesc->group_sid :
2149 old_secdesc->group_sid;
2151 dacl = secdesc->dacl ?
2155 sacl = secdesc->sacl ?
2159 /* Make a deep copy of the security descriptor */
2160 new_secdesc = make_sec_desc(tmp_ctx,
2168 if (new_secdesc == NULL) {
2169 talloc_free(tmp_ctx);
2174 ZERO_STRUCT(hive_hnd);
2175 ZERO_STRUCT(key_hnd);
2177 result = winreg_printer_openkey(tmp_ctx,
2187 if (!W_ERROR_IS_OK(result)) {
2191 status = dcerpc_winreg_set_sd(tmp_ctx,
2197 if (!NT_STATUS_IS_OK(status)) {
2198 result = ntstatus_to_werror(status);
2202 if (winreg_handle != NULL) {
2205 if (is_valid_policy_hnd(&key_hnd)) {
2206 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2208 if (is_valid_policy_hnd(&hive_hnd)) {
2209 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2213 talloc_free(tmp_ctx);
2217 /* Set printer data over the winreg pipe. */
2218 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2219 const struct auth_serversupplied_info *session_info,
2220 struct messaging_context *msg_ctx,
2221 const char *printer,
2224 enum winreg_Type type,
2228 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2229 struct dcerpc_binding_handle *winreg_handle = NULL;
2230 struct policy_handle hive_hnd, key_hnd;
2231 struct winreg_String wvalue = { 0, };
2233 WERROR result = WERR_OK;
2235 TALLOC_CTX *tmp_ctx;
2237 tmp_ctx = talloc_stackframe();
2238 if (tmp_ctx == NULL) {
2242 path = winreg_printer_data_keyname(tmp_ctx, printer);
2244 TALLOC_FREE(tmp_ctx);
2248 ZERO_STRUCT(hive_hnd);
2249 ZERO_STRUCT(key_hnd);
2251 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2252 key, value, access_mask, printer));
2253 result = winreg_printer_openkey(tmp_ctx,
2263 if (!W_ERROR_IS_OK(result)) {
2264 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2265 key, win_errstr(result)));
2269 wvalue.name = value;
2270 status = dcerpc_winreg_SetValue(winreg_handle,
2278 if (!NT_STATUS_IS_OK(status)) {
2279 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2280 value, nt_errstr(status)));
2281 result = ntstatus_to_werror(status);
2285 if (winreg_handle != NULL) {
2288 if (is_valid_policy_hnd(&key_hnd)) {
2289 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2291 if (is_valid_policy_hnd(&hive_hnd)) {
2292 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2296 TALLOC_FREE(tmp_ctx);
2300 /* Get printer data over a winreg pipe. */
2301 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2302 const struct auth_serversupplied_info *session_info,
2303 struct messaging_context *msg_ctx,
2304 const char *printer,
2307 enum winreg_Type *type,
2309 uint32_t *data_size)
2311 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2312 struct dcerpc_binding_handle *winreg_handle = NULL;
2313 struct policy_handle hive_hnd, key_hnd;
2314 struct winreg_String wvalue;
2315 enum winreg_Type type_in;
2318 uint32_t data_in_size = 0;
2319 uint32_t value_len = 0;
2320 WERROR result = WERR_OK;
2322 TALLOC_CTX *tmp_ctx;
2324 tmp_ctx = talloc_stackframe();
2325 if (tmp_ctx == NULL) {
2329 path = winreg_printer_data_keyname(tmp_ctx, printer);
2331 TALLOC_FREE(tmp_ctx);
2335 ZERO_STRUCT(hive_hnd);
2336 ZERO_STRUCT(key_hnd);
2338 result = winreg_printer_openkey(tmp_ctx,
2348 if (!W_ERROR_IS_OK(result)) {
2349 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2350 key, win_errstr(result)));
2354 wvalue.name = value;
2357 * call QueryValue once with data == NULL to get the
2358 * needed memory size to be allocated, then allocate
2359 * data buffer and call again.
2361 status = dcerpc_winreg_QueryValue(winreg_handle,
2370 if (!NT_STATUS_IS_OK(status)) {
2371 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2372 value, nt_errstr(status)));
2373 result = ntstatus_to_werror(status);
2376 if (!W_ERROR_IS_OK(result)) {
2380 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2381 if (data_in == NULL) {
2382 result = WERR_NOMEM;
2387 status = dcerpc_winreg_QueryValue(winreg_handle,
2396 if (!NT_STATUS_IS_OK(status)) {
2397 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2398 value, nt_errstr(status)));
2399 result = ntstatus_to_werror(status);
2402 if (!W_ERROR_IS_OK(result)) {
2407 *data_size = data_in_size;
2409 *data = talloc_move(mem_ctx, &data_in);
2414 if (winreg_handle != NULL) {
2417 if (is_valid_policy_hnd(&key_hnd)) {
2418 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2420 if (is_valid_policy_hnd(&hive_hnd)) {
2421 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2425 TALLOC_FREE(tmp_ctx);
2429 /* Enumerate on the values of a given key and provide the data. */
2430 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2431 const struct auth_serversupplied_info *session_info,
2432 struct messaging_context *msg_ctx,
2433 const char *printer,
2435 uint32_t *pnum_values,
2436 struct spoolss_PrinterEnumValues **penum_values)
2438 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2439 struct dcerpc_binding_handle *winreg_handle = NULL;
2440 struct policy_handle hive_hnd, key_hnd;
2442 struct spoolss_PrinterEnumValues *enum_values = NULL;
2443 uint32_t num_values = 0;
2445 WERROR result = WERR_OK;
2447 TALLOC_CTX *tmp_ctx;
2449 tmp_ctx = talloc_stackframe();
2450 if (tmp_ctx == NULL) {
2454 path = winreg_printer_data_keyname(tmp_ctx, printer);
2456 TALLOC_FREE(tmp_ctx);
2460 result = winreg_printer_openkey(tmp_ctx,
2470 if (!W_ERROR_IS_OK(result)) {
2471 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2472 key, win_errstr(result)));
2476 result = winreg_printer_enumvalues(tmp_ctx,
2481 if (!W_ERROR_IS_OK(result)) {
2482 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2483 key, win_errstr(result)));
2487 *pnum_values = num_values;
2489 *penum_values = talloc_move(mem_ctx, &enum_values);
2494 if (winreg_handle != NULL) {
2497 if (is_valid_policy_hnd(&key_hnd)) {
2498 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2500 if (is_valid_policy_hnd(&hive_hnd)) {
2501 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2505 TALLOC_FREE(tmp_ctx);
2509 /* Delete printer data over a winreg pipe. */
2510 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2511 const struct auth_serversupplied_info *session_info,
2512 struct messaging_context *msg_ctx,
2513 const char *printer,
2517 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2518 struct dcerpc_binding_handle *winreg_handle = NULL;
2519 struct policy_handle hive_hnd, key_hnd;
2520 struct winreg_String wvalue = { 0, };
2522 WERROR result = WERR_OK;
2525 TALLOC_CTX *tmp_ctx;
2527 tmp_ctx = talloc_stackframe();
2528 if (tmp_ctx == NULL) {
2532 path = winreg_printer_data_keyname(tmp_ctx, printer);
2534 TALLOC_FREE(tmp_ctx);
2538 ZERO_STRUCT(hive_hnd);
2539 ZERO_STRUCT(key_hnd);
2541 result = winreg_printer_openkey(tmp_ctx,
2551 if (!W_ERROR_IS_OK(result)) {
2552 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2553 key, win_errstr(result)));
2557 wvalue.name = value;
2558 status = dcerpc_winreg_DeleteValue(winreg_handle,
2563 if (!NT_STATUS_IS_OK(status)) {
2564 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2565 value, nt_errstr(status)));
2566 result = ntstatus_to_werror(status);
2570 if (winreg_handle != NULL) {
2573 if (is_valid_policy_hnd(&key_hnd)) {
2574 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2576 if (is_valid_policy_hnd(&hive_hnd)) {
2577 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2581 TALLOC_FREE(tmp_ctx);
2585 /* Enumerate on the subkeys of a given key and provide the data. */
2586 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2587 const struct auth_serversupplied_info *session_info,
2588 struct messaging_context *msg_ctx,
2589 const char *printer,
2591 uint32_t *pnum_subkeys,
2592 const char ***psubkeys)
2594 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2595 struct dcerpc_binding_handle *winreg_handle = NULL;
2596 struct policy_handle hive_hnd, key_hnd;
2598 const char **subkeys = NULL;
2599 uint32_t num_subkeys = -1;
2601 WERROR result = WERR_OK;
2604 TALLOC_CTX *tmp_ctx;
2606 tmp_ctx = talloc_stackframe();
2607 if (tmp_ctx == NULL) {
2611 path = winreg_printer_data_keyname(tmp_ctx, printer);
2613 TALLOC_FREE(tmp_ctx);
2617 ZERO_STRUCT(hive_hnd);
2618 ZERO_STRUCT(key_hnd);
2620 result = winreg_printer_openkey(tmp_ctx,
2630 if (!W_ERROR_IS_OK(result)) {
2631 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2632 key, win_errstr(result)));
2636 status = dcerpc_winreg_enum_keys(tmp_ctx,
2642 if (!NT_STATUS_IS_OK(status)) {
2643 result = ntstatus_to_werror(status);
2645 if (!W_ERROR_IS_OK(result)) {
2646 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2647 key, win_errstr(result)));
2651 *pnum_subkeys = num_subkeys;
2653 *psubkeys = talloc_move(mem_ctx, &subkeys);
2658 if (winreg_handle != NULL) {
2661 if (is_valid_policy_hnd(&key_hnd)) {
2662 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2664 if (is_valid_policy_hnd(&hive_hnd)) {
2665 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2669 TALLOC_FREE(tmp_ctx);
2673 /* Delete a key with subkeys of a given printer. */
2674 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
2675 const struct auth_serversupplied_info *session_info,
2676 struct messaging_context *msg_ctx,
2677 const char *printer,
2680 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2681 struct dcerpc_binding_handle *winreg_handle = NULL;
2682 struct policy_handle hive_hnd, key_hnd;
2686 TALLOC_CTX *tmp_ctx;
2688 tmp_ctx = talloc_stackframe();
2689 if (tmp_ctx == NULL) {
2693 path = winreg_printer_data_keyname(tmp_ctx, printer);
2695 TALLOC_FREE(tmp_ctx);
2699 result = winreg_printer_openkey(tmp_ctx,
2709 if (!W_ERROR_IS_OK(result)) {
2710 /* key doesn't exist */
2711 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2716 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2717 key, win_errstr(result)));
2721 if (is_valid_policy_hnd(&key_hnd)) {
2722 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
2725 if (key == NULL || key[0] == '\0') {
2728 keyname = talloc_asprintf(tmp_ctx,
2732 if (keyname == NULL) {
2733 result = WERR_NOMEM;
2738 result = winreg_printer_delete_subkeys(tmp_ctx,
2743 if (!W_ERROR_IS_OK(result)) {
2744 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2745 key, win_errstr(result)));
2750 if (winreg_handle != NULL) {
2753 if (is_valid_policy_hnd(&key_hnd)) {
2754 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2756 if (is_valid_policy_hnd(&hive_hnd)) {
2757 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2761 TALLOC_FREE(tmp_ctx);
2765 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
2766 const struct auth_serversupplied_info *session_info,
2767 struct messaging_context *msg_ctx,
2768 const char *printer)
2770 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2771 struct dcerpc_binding_handle *winreg_handle = NULL;
2772 struct policy_handle hive_hnd, key_hnd;
2776 TALLOC_CTX *tmp_ctx;
2778 tmp_ctx = talloc_stackframe();
2779 if (tmp_ctx == NULL) {
2783 path = winreg_printer_data_keyname(tmp_ctx, printer);
2785 TALLOC_FREE(tmp_ctx);
2789 ZERO_STRUCT(hive_hnd);
2790 ZERO_STRUCT(key_hnd);
2792 result = winreg_printer_openkey(tmp_ctx,
2802 if (!W_ERROR_IS_OK(result)) {
2803 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2804 path, win_errstr(result)));
2808 status = dcerpc_winreg_set_dword(tmp_ctx,
2812 winreg_printer_rev_changeid(),
2814 if (!NT_STATUS_IS_OK(status)) {
2815 result = ntstatus_to_werror(status);
2817 if (!W_ERROR_IS_OK(result)) {
2823 if (winreg_handle != NULL) {
2826 if (is_valid_policy_hnd(&key_hnd)) {
2827 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2829 if (is_valid_policy_hnd(&hive_hnd)) {
2830 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2834 TALLOC_FREE(tmp_ctx);
2838 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
2839 const struct auth_serversupplied_info *session_info,
2840 struct messaging_context *msg_ctx,
2841 const char *printer,
2842 uint32_t *pchangeid)
2844 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2845 struct dcerpc_binding_handle *winreg_handle = NULL;
2846 struct policy_handle hive_hnd, key_hnd;
2847 uint32_t changeid = 0;
2851 TALLOC_CTX *tmp_ctx;
2853 tmp_ctx = talloc_stackframe();
2854 if (tmp_ctx == NULL) {
2858 path = winreg_printer_data_keyname(tmp_ctx, printer);
2860 TALLOC_FREE(tmp_ctx);
2864 ZERO_STRUCT(hive_hnd);
2865 ZERO_STRUCT(key_hnd);
2867 result = winreg_printer_openkey(tmp_ctx,
2877 if (!W_ERROR_IS_OK(result)) {
2878 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2879 path, win_errstr(result)));
2883 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path));
2885 status = dcerpc_winreg_query_dword(tmp_ctx,
2891 if (!NT_STATUS_IS_OK(status)) {
2892 result = ntstatus_to_werror(status);
2894 if (!W_ERROR_IS_OK(result)) {
2899 *pchangeid = changeid;
2904 if (winreg_handle != NULL) {
2907 if (is_valid_policy_hnd(&key_hnd)) {
2908 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2910 if (is_valid_policy_hnd(&hive_hnd)) {
2911 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2915 TALLOC_FREE(tmp_ctx);
2920 * The special behaviour of the spoolss forms is documented at the website:
2922 * Managing Win32 Printserver Forms
2923 * http://unixwiz.net/techtips/winspooler-forms.html
2926 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
2927 const struct auth_serversupplied_info *session_info,
2928 struct messaging_context *msg_ctx,
2929 struct spoolss_AddFormInfo1 *form)
2931 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2932 struct dcerpc_binding_handle *winreg_handle = NULL;
2933 struct policy_handle hive_hnd, key_hnd;
2934 struct winreg_String wvalue = { 0, };
2936 uint32_t num_info = 0;
2937 union spoolss_FormInfo *info = NULL;
2941 TALLOC_CTX *tmp_ctx;
2943 tmp_ctx = talloc_stackframe();
2944 if (tmp_ctx == NULL) {
2948 ZERO_STRUCT(hive_hnd);
2949 ZERO_STRUCT(key_hnd);
2951 result = winreg_printer_openkey(tmp_ctx,
2955 TOP_LEVEL_CONTROL_FORMS_KEY,
2961 if (!W_ERROR_IS_OK(result)) {
2962 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2963 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2967 result = winreg_printer_enumforms1(tmp_ctx, session_info, msg_ctx,
2969 if (!W_ERROR_IS_OK(result)) {
2970 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2971 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2975 /* If form name already exists or is builtin return ALREADY_EXISTS */
2976 for (i = 0; i < num_info; i++) {
2977 if (strequal(info[i].info1.form_name, form->form_name)) {
2978 result = WERR_FILE_EXISTS;
2983 wvalue.name = form->form_name;
2985 blob = data_blob_talloc(tmp_ctx, NULL, 32);
2986 SIVAL(blob.data, 0, form->size.width);
2987 SIVAL(blob.data, 4, form->size.height);
2988 SIVAL(blob.data, 8, form->area.left);
2989 SIVAL(blob.data, 12, form->area.top);
2990 SIVAL(blob.data, 16, form->area.right);
2991 SIVAL(blob.data, 20, form->area.bottom);
2992 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
2993 SIVAL(blob.data, 28, form->flags);
2995 status = dcerpc_winreg_SetValue(winreg_handle,
3003 if (!NT_STATUS_IS_OK(status)) {
3004 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
3005 wvalue.name, nt_errstr(status)));
3006 result = ntstatus_to_werror(status);
3010 if (winreg_handle != NULL) {
3013 if (is_valid_policy_hnd(&key_hnd)) {
3014 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3016 if (is_valid_policy_hnd(&hive_hnd)) {
3017 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3022 TALLOC_FREE(tmp_ctx);
3026 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
3027 const struct auth_serversupplied_info *session_info,
3028 struct messaging_context *msg_ctx,
3029 uint32_t *pnum_info,
3030 union spoolss_FormInfo **pinfo)
3032 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3033 struct dcerpc_binding_handle *winreg_handle = NULL;
3034 struct policy_handle hive_hnd, key_hnd;
3035 union spoolss_FormInfo *info;
3036 struct spoolss_PrinterEnumValues *enum_values = NULL;
3037 uint32_t num_values = 0;
3038 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3041 TALLOC_CTX *tmp_ctx;
3043 tmp_ctx = talloc_stackframe();
3044 if (tmp_ctx == NULL) {
3048 ZERO_STRUCT(hive_hnd);
3049 ZERO_STRUCT(key_hnd);
3051 result = winreg_printer_openkey(tmp_ctx,
3055 TOP_LEVEL_CONTROL_FORMS_KEY,
3061 if (!W_ERROR_IS_OK(result)) {
3062 /* key doesn't exist */
3063 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3068 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3069 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3073 result = winreg_printer_enumvalues(tmp_ctx,
3078 if (!W_ERROR_IS_OK(result)) {
3079 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3080 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3084 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
3086 result = WERR_NOMEM;
3090 /* Enumerate BUILTIN forms */
3091 for (i = 0; i < num_builtin; i++) {
3092 info[i].info1 = builtin_forms1[i];
3095 /* Enumerate registry forms */
3096 for (i = 0; i < num_values; i++) {
3097 union spoolss_FormInfo val;
3099 if (enum_values[i].type != REG_BINARY ||
3100 enum_values[i].data_length != 32) {
3104 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
3105 if (val.info1.form_name == NULL) {
3106 result = WERR_NOMEM;
3110 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3111 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3112 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3113 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3114 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3115 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3116 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3117 val.info1.flags = (enum spoolss_FormFlags) IVAL(enum_values[i].data->data, 28);
3119 info[i + num_builtin] = val;
3122 *pnum_info = num_builtin + num_values;
3124 *pinfo = talloc_move(mem_ctx, &info);
3128 if (winreg_handle != NULL) {
3131 if (is_valid_policy_hnd(&key_hnd)) {
3132 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3134 if (is_valid_policy_hnd(&hive_hnd)) {
3135 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3139 TALLOC_FREE(enum_values);
3140 TALLOC_FREE(tmp_ctx);
3144 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3145 const struct auth_serversupplied_info *session_info,
3146 struct messaging_context *msg_ctx,
3147 const char *form_name)
3149 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3150 struct dcerpc_binding_handle *winreg_handle = NULL;
3151 struct policy_handle hive_hnd, key_hnd;
3152 struct winreg_String wvalue = { 0, };
3153 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3155 WERROR result = WERR_OK;
3157 TALLOC_CTX *tmp_ctx;
3159 for (i = 0; i < num_builtin; i++) {
3160 if (strequal(builtin_forms1[i].form_name, form_name)) {
3161 return WERR_INVALID_PARAMETER;
3165 tmp_ctx = talloc_stackframe();
3166 if (tmp_ctx == NULL) {
3170 ZERO_STRUCT(hive_hnd);
3171 ZERO_STRUCT(key_hnd);
3173 result = winreg_printer_openkey(tmp_ctx,
3177 TOP_LEVEL_CONTROL_FORMS_KEY,
3183 if (!W_ERROR_IS_OK(result)) {
3184 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3185 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3186 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3187 result = WERR_INVALID_FORM_NAME;
3192 wvalue.name = form_name;
3193 status = dcerpc_winreg_DeleteValue(winreg_handle,
3198 if (!NT_STATUS_IS_OK(status)) {
3199 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3200 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3201 wvalue.name, nt_errstr(status)));
3202 result = ntstatus_to_werror(status);
3206 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3207 result = WERR_INVALID_FORM_NAME;
3211 if (winreg_handle != NULL) {
3214 if (is_valid_policy_hnd(&key_hnd)) {
3215 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3217 if (is_valid_policy_hnd(&hive_hnd)) {
3218 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3222 TALLOC_FREE(tmp_ctx);
3226 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3227 const struct auth_serversupplied_info *session_info,
3228 struct messaging_context *msg_ctx,
3229 const char *form_name,
3230 struct spoolss_AddFormInfo1 *form)
3232 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3233 struct dcerpc_binding_handle *winreg_handle = NULL;
3234 struct policy_handle hive_hnd, key_hnd;
3235 struct winreg_String wvalue = { 0, };
3237 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3241 TALLOC_CTX *tmp_ctx = NULL;
3243 for (i = 0; i < num_builtin; i++) {
3244 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3245 result = WERR_INVALID_PARAM;
3250 tmp_ctx = talloc_stackframe();
3251 if (tmp_ctx == NULL) {
3255 ZERO_STRUCT(hive_hnd);
3256 ZERO_STRUCT(key_hnd);
3258 result = winreg_printer_openkey(tmp_ctx,
3262 TOP_LEVEL_CONTROL_FORMS_KEY,
3268 if (!W_ERROR_IS_OK(result)) {
3269 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3270 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3274 /* If form_name != form->form_name then we renamed the form */
3275 if (strequal(form_name, form->form_name)) {
3276 result = winreg_printer_deleteform1(tmp_ctx, session_info,
3277 msg_ctx, form_name);
3278 if (!W_ERROR_IS_OK(result)) {
3279 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3280 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3285 wvalue.name = form->form_name;
3287 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3288 SIVAL(blob.data, 0, form->size.width);
3289 SIVAL(blob.data, 4, form->size.height);
3290 SIVAL(blob.data, 8, form->area.left);
3291 SIVAL(blob.data, 12, form->area.top);
3292 SIVAL(blob.data, 16, form->area.right);
3293 SIVAL(blob.data, 20, form->area.bottom);
3294 SIVAL(blob.data, 24, 42);
3295 SIVAL(blob.data, 28, form->flags);
3297 status = dcerpc_winreg_SetValue(winreg_handle,
3305 if (!NT_STATUS_IS_OK(status)) {
3306 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3307 wvalue.name, nt_errstr(status)));
3308 result = ntstatus_to_werror(status);
3312 if (winreg_handle != NULL) {
3315 if (is_valid_policy_hnd(&key_hnd)) {
3316 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3318 if (is_valid_policy_hnd(&hive_hnd)) {
3319 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3323 TALLOC_FREE(tmp_ctx);
3327 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3328 const struct auth_serversupplied_info *session_info,
3329 struct messaging_context *msg_ctx,
3330 const char *form_name,
3331 struct spoolss_FormInfo1 *r)
3333 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3334 struct dcerpc_binding_handle *winreg_handle = NULL;
3335 struct policy_handle hive_hnd, key_hnd;
3336 struct winreg_String wvalue;
3337 enum winreg_Type type_in;
3339 uint32_t data_in_size = 0;
3340 uint32_t value_len = 0;
3341 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3345 TALLOC_CTX *tmp_ctx;
3347 /* check builtin forms first */
3348 for (i = 0; i < num_builtin; i++) {
3349 if (strequal(builtin_forms1[i].form_name, form_name)) {
3350 *r = builtin_forms1[i];
3355 tmp_ctx = talloc_stackframe();
3356 if (tmp_ctx == NULL) {
3360 ZERO_STRUCT(hive_hnd);
3361 ZERO_STRUCT(key_hnd);
3363 result = winreg_printer_openkey(tmp_ctx,
3367 TOP_LEVEL_CONTROL_FORMS_KEY,
3373 if (!W_ERROR_IS_OK(result)) {
3374 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3375 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3379 wvalue.name = form_name;
3382 * call QueryValue once with data == NULL to get the
3383 * needed memory size to be allocated, then allocate
3384 * data buffer and call again.
3386 status = dcerpc_winreg_QueryValue(winreg_handle,
3395 if (!NT_STATUS_IS_OK(status)) {
3396 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3397 wvalue.name, nt_errstr(status)));
3398 result = ntstatus_to_werror(status);
3401 if (!W_ERROR_IS_OK(result)) {
3405 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3406 if (data_in == NULL) {
3407 result = WERR_NOMEM;
3412 status = dcerpc_winreg_QueryValue(winreg_handle,
3421 if (!NT_STATUS_IS_OK(status)) {
3422 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3423 wvalue.name, nt_errstr(status)));
3424 result = ntstatus_to_werror(status);
3427 if (!W_ERROR_IS_OK(result)) {
3431 r->form_name = talloc_strdup(mem_ctx, form_name);
3432 if (r->form_name == NULL) {
3433 result = WERR_NOMEM;
3437 r->size.width = IVAL(data_in, 0);
3438 r->size.height = IVAL(data_in, 4);
3439 r->area.left = IVAL(data_in, 8);
3440 r->area.top = IVAL(data_in, 12);
3441 r->area.right = IVAL(data_in, 16);
3442 r->area.bottom = IVAL(data_in, 20);
3443 /* skip index IVAL(data_in, 24)));*/
3444 r->flags = (enum spoolss_FormFlags) IVAL(data_in, 28);
3448 if (winreg_handle != NULL) {
3451 if (is_valid_policy_hnd(&key_hnd)) {
3452 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3454 if (is_valid_policy_hnd(&hive_hnd)) {
3455 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3459 TALLOC_FREE(tmp_ctx);
3463 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3464 const struct auth_serversupplied_info *session_info,
3465 struct messaging_context *msg_ctx,
3466 struct spoolss_AddDriverInfoCtr *r,
3467 const char **driver_name,
3468 uint32_t *driver_version)
3470 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3471 struct dcerpc_binding_handle *winreg_handle = NULL;
3472 struct policy_handle hive_hnd, key_hnd;
3473 struct spoolss_DriverInfo8 info8;
3474 TALLOC_CTX *tmp_ctx = NULL;
3478 ZERO_STRUCT(hive_hnd);
3479 ZERO_STRUCT(key_hnd);
3482 if (!driver_info_ctr_to_info8(r, &info8)) {
3483 result = WERR_INVALID_PARAMETER;
3487 tmp_ctx = talloc_stackframe();
3488 if (tmp_ctx == NULL) {
3492 result = winreg_printer_opendriver(tmp_ctx,
3502 if (!W_ERROR_IS_OK(result)) {
3503 DEBUG(0, ("winreg_add_driver: "
3504 "Could not open driver key (%s,%s,%d): %s\n",
3505 info8.driver_name, info8.architecture,
3506 info8.version, win_errstr(result)));
3510 /* TODO: "Attributes" ? */
3512 status = dcerpc_winreg_set_dword(tmp_ctx,
3518 if (!NT_STATUS_IS_OK(status)) {
3519 result = ntstatus_to_werror(status);
3521 if (!W_ERROR_IS_OK(result)) {
3525 status = dcerpc_winreg_set_sz(tmp_ctx,
3531 if (!NT_STATUS_IS_OK(status)) {
3532 result = ntstatus_to_werror(status);
3534 if (!W_ERROR_IS_OK(result)) {
3538 status = dcerpc_winreg_set_sz(tmp_ctx,
3544 if (!NT_STATUS_IS_OK(status)) {
3545 result = ntstatus_to_werror(status);
3547 if (!W_ERROR_IS_OK(result)) {
3551 status = dcerpc_winreg_set_sz(tmp_ctx,
3554 "Configuration File",
3557 if (!NT_STATUS_IS_OK(status)) {
3558 result = ntstatus_to_werror(status);
3560 if (!W_ERROR_IS_OK(result)) {
3564 status = dcerpc_winreg_set_sz(tmp_ctx,
3570 if (!NT_STATUS_IS_OK(status)) {
3571 result = ntstatus_to_werror(status);
3573 if (!W_ERROR_IS_OK(result)) {
3577 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3581 info8.dependent_files,
3583 if (!NT_STATUS_IS_OK(status)) {
3584 result = ntstatus_to_werror(status);
3586 if (!W_ERROR_IS_OK(result)) {
3590 status = dcerpc_winreg_set_sz(tmp_ctx,
3596 if (!NT_STATUS_IS_OK(status)) {
3597 result = ntstatus_to_werror(status);
3599 if (!W_ERROR_IS_OK(result)) {
3603 status = dcerpc_winreg_set_sz(tmp_ctx,
3607 info8.default_datatype,
3609 if (!NT_STATUS_IS_OK(status)) {
3610 result = ntstatus_to_werror(status);
3612 if (!W_ERROR_IS_OK(result)) {
3616 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3618 &key_hnd, "Previous Names",
3619 info8.previous_names,
3621 if (!NT_STATUS_IS_OK(status)) {
3622 result = ntstatus_to_werror(status);
3624 if (!W_ERROR_IS_OK(result)) {
3628 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3629 &key_hnd, "DriverDate",
3631 if (!W_ERROR_IS_OK(result)) {
3635 result = winreg_printer_write_ver(tmp_ctx, winreg_handle,
3636 &key_hnd, "DriverVersion",
3637 info8.driver_version);
3638 if (!W_ERROR_IS_OK(result)) {
3642 status = dcerpc_winreg_set_sz(tmp_ctx,
3646 info8.manufacturer_name,
3648 if (!NT_STATUS_IS_OK(status)) {
3649 result = ntstatus_to_werror(status);
3651 if (!W_ERROR_IS_OK(result)) {
3655 status = dcerpc_winreg_set_sz(tmp_ctx,
3659 info8.manufacturer_url,
3661 if (!NT_STATUS_IS_OK(status)) {
3662 result = ntstatus_to_werror(status);
3664 if (!W_ERROR_IS_OK(result)) {
3668 status = dcerpc_winreg_set_sz(tmp_ctx,
3674 if (!NT_STATUS_IS_OK(status)) {
3675 result = ntstatus_to_werror(status);
3677 if (!W_ERROR_IS_OK(result)) {
3681 status = dcerpc_winreg_set_sz(tmp_ctx,
3687 if (!NT_STATUS_IS_OK(status)) {
3688 result = ntstatus_to_werror(status);
3690 if (!W_ERROR_IS_OK(result)) {
3694 status = dcerpc_winreg_set_sz(tmp_ctx,
3698 info8.print_processor,
3700 if (!NT_STATUS_IS_OK(status)) {
3701 result = ntstatus_to_werror(status);
3703 if (!W_ERROR_IS_OK(result)) {
3707 status = dcerpc_winreg_set_sz(tmp_ctx,
3713 if (!NT_STATUS_IS_OK(status)) {
3714 result = ntstatus_to_werror(status);
3716 if (!W_ERROR_IS_OK(result)) {
3720 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3724 info8.color_profiles,
3726 if (!NT_STATUS_IS_OK(status)) {
3727 result = ntstatus_to_werror(status);
3729 if (!W_ERROR_IS_OK(result)) {
3733 status = dcerpc_winreg_set_sz(tmp_ctx,
3739 if (!NT_STATUS_IS_OK(status)) {
3740 result = ntstatus_to_werror(status);
3742 if (!W_ERROR_IS_OK(result)) {
3746 status = dcerpc_winreg_set_dword(tmp_ctx,
3749 "PrinterDriverAttributes",
3750 info8.printer_driver_attributes,
3752 if (!NT_STATUS_IS_OK(status)) {
3753 result = ntstatus_to_werror(status);
3755 if (!W_ERROR_IS_OK(result)) {
3759 status = dcerpc_winreg_set_multi_sz(tmp_ctx,
3763 info8.core_driver_dependencies,
3765 if (!NT_STATUS_IS_OK(status)) {
3766 result = ntstatus_to_werror(status);
3768 if (!W_ERROR_IS_OK(result)) {
3772 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3773 &key_hnd, "MinInboxDriverVerDate",
3774 info8.min_inbox_driver_ver_date);
3775 if (!W_ERROR_IS_OK(result)) {
3779 result = winreg_printer_write_ver(tmp_ctx, winreg_handle, &key_hnd,
3780 "MinInboxDriverVerVersion",
3781 info8.min_inbox_driver_ver_version);
3782 if (!W_ERROR_IS_OK(result)) {
3786 *driver_name = info8.driver_name;
3787 *driver_version = info8.version;
3790 if (winreg_handle != NULL) {
3793 if (is_valid_policy_hnd(&key_hnd)) {
3794 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3796 if (is_valid_policy_hnd(&hive_hnd)) {
3797 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3801 TALLOC_FREE(tmp_ctx);
3805 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
3806 const struct auth_serversupplied_info *session_info,
3807 struct messaging_context *msg_ctx,
3808 const char *architecture,
3809 const char *driver_name,
3810 uint32_t driver_version,
3811 struct spoolss_DriverInfo8 **_info8)
3813 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3814 struct dcerpc_binding_handle *winreg_handle = NULL;
3815 struct policy_handle hive_hnd, key_hnd;
3816 struct spoolss_DriverInfo8 i8, *info8;
3817 struct spoolss_PrinterEnumValues *enum_values = NULL;
3818 struct spoolss_PrinterEnumValues *v;
3819 uint32_t num_values = 0;
3820 TALLOC_CTX *tmp_ctx;
3824 ZERO_STRUCT(hive_hnd);
3825 ZERO_STRUCT(key_hnd);
3828 tmp_ctx = talloc_stackframe();
3829 if (tmp_ctx == NULL) {
3833 if (driver_version == DRIVER_ANY_VERSION) {
3834 /* look for Win2k first and then for NT4 */
3835 result = winreg_printer_opendriver(tmp_ctx,
3845 if (!W_ERROR_IS_OK(result)) {
3846 result = winreg_printer_opendriver(tmp_ctx,
3858 /* ok normal case */
3859 result = winreg_printer_opendriver(tmp_ctx,
3870 if (!W_ERROR_IS_OK(result)) {
3871 DEBUG(5, ("winreg_get_driver: "
3872 "Could not open driver key (%s,%s,%d): %s\n",
3873 driver_name, architecture,
3874 driver_version, win_errstr(result)));
3878 result = winreg_printer_enumvalues(tmp_ctx,
3883 if (!W_ERROR_IS_OK(result)) {
3884 DEBUG(0, ("winreg_get_driver: "
3885 "Could not enumerate values for (%s,%s,%d): %s\n",
3886 driver_name, architecture,
3887 driver_version, win_errstr(result)));
3891 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
3892 if (info8 == NULL) {
3893 result = WERR_NOMEM;
3897 info8->driver_name = talloc_strdup(info8, driver_name);
3898 if (info8->driver_name == NULL) {
3899 result = WERR_NOMEM;
3903 info8->architecture = talloc_strdup(info8, architecture);
3904 if (info8->architecture == NULL) {
3905 result = WERR_NOMEM;
3911 for (i = 0; i < num_values; i++) {
3912 const char *tmp_str;
3915 v = &enum_values[i];
3917 result = winreg_enumval_to_dword(info8, v,
3920 if (NT_STATUS_IS_OK(result)) {
3921 info8->version = (enum spoolss_DriverOSVersion) tmp;
3923 CHECK_ERROR(result);
3925 result = winreg_enumval_to_sz(info8, v,
3927 &info8->driver_path);
3928 CHECK_ERROR(result);
3930 result = winreg_enumval_to_sz(info8, v,
3933 CHECK_ERROR(result);
3935 result = winreg_enumval_to_sz(info8, v,
3936 "Configuration File",
3937 &info8->config_file);
3938 CHECK_ERROR(result);
3940 result = winreg_enumval_to_sz(info8, v,
3943 CHECK_ERROR(result);
3945 result = winreg_enumval_to_multi_sz(info8, v,
3947 &info8->dependent_files);
3948 CHECK_ERROR(result);
3950 result = winreg_enumval_to_sz(info8, v,
3952 &info8->monitor_name);
3953 CHECK_ERROR(result);
3955 result = winreg_enumval_to_sz(info8, v,
3957 &info8->default_datatype);
3958 CHECK_ERROR(result);
3960 result = winreg_enumval_to_multi_sz(info8, v,
3962 &info8->previous_names);
3963 CHECK_ERROR(result);
3965 result = winreg_enumval_to_sz(info8, v,
3968 if (W_ERROR_IS_OK(result)) {
3969 result = winreg_printer_date_to_NTTIME(tmp_str,
3970 &info8->driver_date);
3972 CHECK_ERROR(result);
3974 result = winreg_enumval_to_sz(info8, v,
3977 if (W_ERROR_IS_OK(result)) {
3978 result = winreg_printer_ver_to_dword(tmp_str,
3979 &info8->driver_version);
3981 CHECK_ERROR(result);
3983 result = winreg_enumval_to_sz(info8, v,
3985 &info8->manufacturer_name);
3986 CHECK_ERROR(result);
3988 result = winreg_enumval_to_sz(info8, v,
3990 &info8->manufacturer_url);
3991 CHECK_ERROR(result);
3993 result = winreg_enumval_to_sz(info8, v,
3995 &info8->hardware_id);
3996 CHECK_ERROR(result);
3998 result = winreg_enumval_to_sz(info8, v,
4001 CHECK_ERROR(result);
4003 result = winreg_enumval_to_sz(info8, v,
4005 &info8->print_processor);
4006 CHECK_ERROR(result);
4008 result = winreg_enumval_to_sz(info8, v,
4010 &info8->vendor_setup);
4011 CHECK_ERROR(result);
4013 result = winreg_enumval_to_multi_sz(info8, v,
4015 &info8->color_profiles);
4016 CHECK_ERROR(result);
4018 result = winreg_enumval_to_sz(info8, v,
4021 CHECK_ERROR(result);
4023 result = winreg_enumval_to_dword(info8, v,
4024 "PrinterDriverAttributes",
4025 &info8->printer_driver_attributes);
4026 CHECK_ERROR(result);
4028 result = winreg_enumval_to_multi_sz(info8, v,
4030 &info8->core_driver_dependencies);
4031 CHECK_ERROR(result);
4033 result = winreg_enumval_to_sz(info8, v,
4034 "MinInboxDriverVerDate",
4036 if (W_ERROR_IS_OK(result)) {
4037 result = winreg_printer_date_to_NTTIME(tmp_str,
4038 &info8->min_inbox_driver_ver_date);
4040 CHECK_ERROR(result);
4042 result = winreg_enumval_to_sz(info8, v,
4043 "MinInboxDriverVerVersion",
4045 if (W_ERROR_IS_OK(result)) {
4046 result = winreg_printer_ver_to_dword(tmp_str,
4047 &info8->min_inbox_driver_ver_version);
4049 CHECK_ERROR(result);
4052 if (!W_ERROR_IS_OK(result)) {
4053 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4054 "for %s: %s\n", v->value_name,
4055 win_errstr(result)));
4059 *_info8 = talloc_steal(mem_ctx, info8);
4062 if (winreg_handle != NULL) {
4065 if (is_valid_policy_hnd(&key_hnd)) {
4066 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4068 if (is_valid_policy_hnd(&hive_hnd)) {
4069 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4073 TALLOC_FREE(tmp_ctx);
4077 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
4078 const struct auth_serversupplied_info *session_info,
4079 struct messaging_context *msg_ctx,
4080 struct spoolss_DriverInfo8 *info8,
4083 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4084 struct dcerpc_binding_handle *winreg_handle = NULL;
4085 struct policy_handle hive_hnd, key_hnd;
4086 TALLOC_CTX *tmp_ctx;
4090 ZERO_STRUCT(hive_hnd);
4091 ZERO_STRUCT(key_hnd);
4093 tmp_ctx = talloc_stackframe();
4094 if (tmp_ctx == NULL) {
4098 /* test that the key exists */
4099 result = winreg_printer_opendriver(tmp_ctx,
4103 info8->architecture,
4109 if (!W_ERROR_IS_OK(result)) {
4110 /* key doesn't exist */
4111 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
4116 DEBUG(5, ("winreg_del_driver: "
4117 "Could not open driver (%s,%s,%u): %s\n",
4118 info8->driver_name, info8->architecture,
4119 version, win_errstr(result)));
4124 if (is_valid_policy_hnd(&key_hnd)) {
4125 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
4128 key_name = talloc_asprintf(tmp_ctx,
4129 "%s\\Environments\\%s\\Drivers\\Version-%u\\%s",
4130 TOP_LEVEL_CONTROL_KEY,
4131 info8->architecture, version,
4132 info8->driver_name);
4133 if (key_name == NULL) {
4134 result = WERR_NOMEM;
4138 result = winreg_printer_delete_subkeys(tmp_ctx,
4143 if (!W_ERROR_IS_OK(result)) {
4144 DEBUG(0, ("winreg_del_driver: "
4145 "Could not open driver (%s,%s,%u): %s\n",
4146 info8->driver_name, info8->architecture,
4147 version, win_errstr(result)));
4153 if (winreg_handle != NULL) {
4156 if (is_valid_policy_hnd(&key_hnd)) {
4157 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4159 if (is_valid_policy_hnd(&hive_hnd)) {
4160 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4164 TALLOC_FREE(tmp_ctx);
4168 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
4169 const struct auth_serversupplied_info *session_info,
4170 struct messaging_context *msg_ctx,
4171 const char *architecture,
4173 uint32_t *num_drivers,
4174 const char ***drivers_p)
4176 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4177 struct dcerpc_binding_handle *winreg_handle = NULL;
4178 struct policy_handle hive_hnd, key_hnd;
4179 const char **drivers;
4180 TALLOC_CTX *tmp_ctx;
4187 ZERO_STRUCT(hive_hnd);
4188 ZERO_STRUCT(key_hnd);
4190 tmp_ctx = talloc_stackframe();
4191 if (tmp_ctx == NULL) {
4195 /* use NULL for the driver name so we open the key that is
4196 * parent of all drivers for this architecture and version */
4197 result = winreg_printer_opendriver(tmp_ctx,
4207 if (!W_ERROR_IS_OK(result)) {
4208 DEBUG(5, ("winreg_get_driver_list: "
4209 "Could not open key (%s,%u): %s\n",
4210 architecture, version, win_errstr(result)));
4215 status = dcerpc_winreg_enum_keys(tmp_ctx,
4221 if (!NT_STATUS_IS_OK(status)) {
4222 result = ntstatus_to_werror(status);
4224 if (!W_ERROR_IS_OK(result)) {
4225 DEBUG(0, ("winreg_get_driver_list: "
4226 "Could not enumerate drivers for (%s,%u): %s\n",
4227 architecture, version, win_errstr(result)));
4231 *drivers_p = talloc_steal(mem_ctx, drivers);
4235 if (winreg_handle != NULL) {
4238 if (is_valid_policy_hnd(&key_hnd)) {
4239 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4241 if (is_valid_policy_hnd(&hive_hnd)) {
4242 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4246 TALLOC_FREE(tmp_ctx);