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/cli_winreg.h"
28 #include "../librpc/gen_ndr/ndr_security.h"
30 #include "rpc_server/rpc_ncacn_np.h"
32 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
33 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
34 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
35 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
37 #define EMPTY_STRING ""
39 #define FILL_STRING(mem_ctx, in, out) \
41 if (in && strlen(in)) { \
42 out = talloc_strdup(mem_ctx, in); \
44 out = talloc_strdup(mem_ctx, ""); \
46 W_ERROR_HAVE_NO_MEMORY(out); \
49 #define CHECK_ERROR(result) \
50 if (W_ERROR_IS_OK(result)) continue; \
51 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
52 if (!W_ERROR_IS_OK(result)) break
54 /* FLAGS, NAME, with, height, left, top, right, bottom */
55 static const struct spoolss_FormInfo1 builtin_forms1[] = {
56 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
57 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
58 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
59 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
60 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
61 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
62 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
63 { SPOOLSS_FORM_BUILTIN, "A0", {0xcd528,0x122488},{0x0,0x0,0xcd528,0x122488} },
64 { SPOOLSS_FORM_BUILTIN, "A1", {0x91050,0xcd528}, {0x0,0x0,0x91050,0xcd528} },
65 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
66 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
67 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
68 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
69 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
70 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
71 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
72 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
73 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
74 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
75 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
76 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
77 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
78 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
79 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
80 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
81 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
82 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
83 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
84 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
85 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
86 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
87 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
88 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
89 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
90 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
91 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
92 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
93 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
94 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
95 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
96 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
97 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
98 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
99 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
100 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
101 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
102 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
103 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
104 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
105 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
106 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
107 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
108 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
109 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
110 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
111 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
112 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
113 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
114 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
115 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
116 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
117 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
118 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
119 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
120 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
121 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
122 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
123 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
124 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
125 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
126 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
127 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
128 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
129 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
130 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
131 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
132 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
133 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
134 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
135 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
136 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
137 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
138 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
139 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
140 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
141 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
142 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
143 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
144 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
145 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
146 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
147 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
148 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
149 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} },
150 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
151 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
152 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
153 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
154 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
159 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
160 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
161 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
162 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
163 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
164 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
165 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
166 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
167 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
168 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
169 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
170 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
171 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
172 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
173 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
174 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
175 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} }
178 /********************************************************************
179 static helper functions
180 ********************************************************************/
182 /****************************************************************************
183 Update the changeid time.
184 ****************************************************************************/
188 * @brief Update the ChangeID time of a printer.
190 * This is SO NASTY as some drivers need this to change, others need it
191 * static. This value will change every second, and I must hope that this
192 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
195 * @return The ChangeID.
197 static uint32_t winreg_printer_rev_changeid(void)
201 get_process_uptime(&tv);
204 /* Return changeid as msec since spooler restart */
205 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
208 * This setting seems to work well but is too untested
209 * to replace the above calculation. Left in for experiementation
210 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
212 return tv.tv_sec * 10 + tv.tv_usec / 100000;
219 * @brief Connect to the interal winreg server and open the given printer key.
221 * The function will create the needed subkeys if they don't exist.
223 * @param[in] mem_ctx The memory context to use.
225 * @param[in] server_info The supplied server info.
227 * @param[out] binding_handle A pointer for the winreg dcerpc binding handle.
229 * @param[in] path The path to the key to open.
231 * @param[in] key The key to open.
233 * @param[in] create_key Set to true if the key should be created if it
236 * @param[in] access_mask The access mask to open the key.
238 * @param[out] hive_handle A policy handle for the opened hive.
240 * @param[out] key_handle A policy handle for the opened key.
242 * @return WERR_OK on success, the corresponding DOS error
243 * code if something gone wrong.
245 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
246 const struct auth_serversupplied_info *server_info,
247 struct messaging_context *msg_ctx,
248 struct dcerpc_binding_handle **winreg_binding_handle,
252 uint32_t access_mask,
253 struct policy_handle *hive_handle,
254 struct policy_handle *key_handle)
256 static struct client_address client_id;
257 struct dcerpc_binding_handle *binding_handle;
258 struct winreg_String wkey, wkeyclass;
261 WERROR result = WERR_OK;
263 strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
264 client_id.name = "127.0.0.1";
266 status = rpcint_binding_handle(mem_ctx,
272 if (!NT_STATUS_IS_OK(status)) {
273 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg pipe: %s\n",
275 return ntstatus_to_werror(status);
278 status = dcerpc_winreg_OpenHKLM(binding_handle,
284 if (!NT_STATUS_IS_OK(status)) {
285 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
287 talloc_free(binding_handle);
288 return ntstatus_to_werror(status);
290 if (!W_ERROR_IS_OK(result)) {
291 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
292 win_errstr(result)));
293 talloc_free(binding_handle);
298 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
300 keyname = talloc_strdup(mem_ctx, path);
302 if (keyname == NULL) {
303 talloc_free(binding_handle);
311 enum winreg_CreateAction action = REG_ACTION_NONE;
313 ZERO_STRUCT(wkeyclass);
316 status = dcerpc_winreg_CreateKey(binding_handle,
328 case REG_ACTION_NONE:
329 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
331 case REG_CREATED_NEW_KEY:
332 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
334 case REG_OPENED_EXISTING_KEY:
335 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
339 status = dcerpc_winreg_OpenKey(binding_handle,
348 if (!NT_STATUS_IS_OK(status)) {
349 talloc_free(binding_handle);
350 return ntstatus_to_werror(status);
352 if (!W_ERROR_IS_OK(result)) {
353 talloc_free(binding_handle);
357 *winreg_binding_handle = binding_handle;
363 * @brief Create the registry keyname for the given printer.
365 * @param[in] mem_ctx The memory context to use.
367 * @param[in] printer The name of the printer to get the registry key.
369 * @return The registry key or NULL on error.
371 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
372 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
378 * @brief Enumerate values of an opened key handle and retrieve the data.
380 * @param[in] mem_ctx The memory context to use.
382 * @param[in] winreg_handle The binding handle for the rpc connection.
384 * @param[in] key_hnd The opened key handle.
386 * @param[out] pnum_values A pointer to store he number of values found.
388 * @param[out] pnum_values A pointer to store the number of values we found.
390 * @return WERR_OK on success, the corresponding DOS error
391 * code if something gone wrong.
393 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
394 struct dcerpc_binding_handle *winreg_handle,
395 struct policy_handle *key_hnd,
396 uint32_t *pnum_values,
397 struct spoolss_PrinterEnumValues **penum_values)
400 uint32_t num_subkeys, max_subkeylen, max_classlen;
401 uint32_t num_values, max_valnamelen, max_valbufsize;
402 uint32_t secdescsize;
404 NTTIME last_changed_time;
405 struct winreg_String classname;
407 struct spoolss_PrinterEnumValues *enum_values;
409 WERROR result = WERR_OK;
412 tmp_ctx = talloc_stackframe();
413 if (tmp_ctx == NULL) {
417 ZERO_STRUCT(classname);
419 status = dcerpc_winreg_QueryInfoKey(winreg_handle,
432 if (!NT_STATUS_IS_OK(status)) {
433 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
435 result = ntstatus_to_werror(status);
438 if (!W_ERROR_IS_OK(result)) {
439 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
440 win_errstr(result)));
444 if (num_values == 0) {
446 TALLOC_FREE(tmp_ctx);
450 enum_values = TALLOC_ARRAY(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
451 if (enum_values == NULL) {
456 for (i = 0; i < num_values; i++) {
457 struct spoolss_PrinterEnumValues val;
458 struct winreg_ValNameBuf name_buf;
459 enum winreg_Type type = REG_NONE;
466 name_buf.size = max_valnamelen + 2;
469 data_size = max_valbufsize;
472 data = (uint8_t *) TALLOC(tmp_ctx, data_size);
476 status = dcerpc_winreg_EnumValue(winreg_handle,
483 data_size ? &data_size : NULL,
486 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
488 status = NT_STATUS_OK;
492 if (!NT_STATUS_IS_OK(status)) {
493 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
495 result = ntstatus_to_werror(status);
498 if (!W_ERROR_IS_OK(result)) {
499 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
500 win_errstr(result)));
504 if (name_buf.name == NULL) {
505 result = WERR_INVALID_PARAMETER;
509 val.value_name = talloc_strdup(enum_values, name_buf.name);
510 if (val.value_name == NULL) {
514 val.value_name_len = strlen_m_term(val.value_name) * 2;
517 val.data_length = length;
519 if (val.data_length) {
520 val.data = talloc(enum_values, DATA_BLOB);
521 if (val.data == NULL) {
525 *val.data = data_blob_talloc(val.data, data, val.data_length);
528 enum_values[i] = val;
531 *pnum_values = num_values;
533 *penum_values = talloc_move(mem_ctx, &enum_values);
539 TALLOC_FREE(tmp_ctx);
546 * @brief Enumerate subkeys of an opened key handle and get the names.
548 * @param[in] mem_ctx The memory context to use.
550 * @param[in] winreg_handle The binding handle for the rpc connection.
552 * @param[in] key_hnd The opened key handle.
554 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
556 * @param[in] psubkeys A pointer to an array to store the found names of
559 * @return WERR_OK on success, the corresponding DOS error
560 * code if something gone wrong.
562 static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
563 struct dcerpc_binding_handle *winreg_handle,
564 struct policy_handle *key_hnd,
565 uint32_t *pnum_subkeys,
566 const char ***psubkeys)
569 const char **subkeys;
570 uint32_t num_subkeys, max_subkeylen, max_classlen;
571 uint32_t num_values, max_valnamelen, max_valbufsize;
573 NTTIME last_changed_time;
574 uint32_t secdescsize;
575 struct winreg_String classname;
576 WERROR result = WERR_OK;
579 tmp_ctx = talloc_stackframe();
580 if (tmp_ctx == NULL) {
584 ZERO_STRUCT(classname);
586 status = dcerpc_winreg_QueryInfoKey(winreg_handle,
599 if (!NT_STATUS_IS_OK(status)) {
600 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
602 result = ntstatus_to_werror(status);
605 if (!W_ERROR_IS_OK(result)) {
606 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
607 win_errstr(result)));
611 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
612 if (subkeys == NULL) {
617 if (num_subkeys == 0) {
618 subkeys[0] = talloc_strdup(subkeys, "");
619 if (subkeys[0] == NULL) {
625 *psubkeys = talloc_move(mem_ctx, &subkeys);
628 TALLOC_FREE(tmp_ctx);
632 for (i = 0; i < num_subkeys; i++) {
636 struct winreg_StringBuf class_buf;
637 struct winreg_StringBuf name_buf;
641 class_buf.size = max_classlen + 2;
642 class_buf.length = 0;
645 name_buf.size = max_subkeylen + 2;
648 ZERO_STRUCT(modtime);
650 status = dcerpc_winreg_EnumKey(winreg_handle,
658 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
660 status = NT_STATUS_OK;
664 if (!NT_STATUS_IS_OK(status)) {
665 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
667 result = ntstatus_to_werror(status);
670 if (!W_ERROR_IS_OK(result)) {
671 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
672 win_errstr(result)));
676 if (name_buf.name == NULL) {
677 result = WERR_INVALID_PARAMETER;
681 name = talloc_strdup(subkeys, name_buf.name);
690 *pnum_subkeys = num_subkeys;
692 *psubkeys = talloc_move(mem_ctx, &subkeys);
696 TALLOC_FREE(tmp_ctx);
703 * @brief A function to delete a key and its subkeys recurively.
705 * @param[in] mem_ctx The memory context to use.
707 * @param[in] winreg_handle The binding handle for the rpc connection.
709 * @param[in] hive_handle A opened hive handle to the key.
711 * @param[in] access_mask The access mask to access the key.
713 * @param[in] key The key to delete
715 * @return WERR_OK on success, the corresponding DOS error
716 * code if something gone wrong.
718 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
719 struct dcerpc_binding_handle *winreg_handle,
720 struct policy_handle *hive_handle,
721 uint32_t access_mask,
724 const char **subkeys = NULL;
725 uint32_t num_subkeys = 0;
726 struct policy_handle key_hnd;
727 struct winreg_String wkey;
728 WERROR result = WERR_OK;
732 ZERO_STRUCT(key_hnd);
735 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
737 status = dcerpc_winreg_OpenKey(winreg_handle,
745 if (!NT_STATUS_IS_OK(status)) {
746 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
747 wkey.name, nt_errstr(status)));
748 return ntstatus_to_werror(status);
750 if (!W_ERROR_IS_OK(result)) {
751 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
752 wkey.name, win_errstr(result)));
756 result = winreg_printer_enumkeys(mem_ctx,
761 if (!W_ERROR_IS_OK(result)) {
765 for (i = 0; i < num_subkeys; i++) {
766 /* create key + subkey */
767 char *subkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkeys[i]);
768 if (subkey == NULL) {
772 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey));
773 result = winreg_printer_delete_subkeys(mem_ctx,
778 if (!W_ERROR_IS_OK(result)) {
783 if (is_valid_policy_hnd(&key_hnd)) {
785 dcerpc_winreg_CloseKey(winreg_handle, mem_ctx, &key_hnd, &ignore);
790 status = dcerpc_winreg_DeleteKey(winreg_handle,
795 if (!NT_STATUS_IS_OK(status)) {
796 result = ntstatus_to_werror(status);
800 if (is_valid_policy_hnd(&key_hnd)) {
803 dcerpc_winreg_CloseKey(winreg_handle, mem_ctx, &key_hnd, &ignore);
809 static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
810 struct dcerpc_binding_handle *winreg_handle,
811 struct policy_handle *key_handle,
815 struct winreg_String wvalue;
817 WERROR result = WERR_OK;
822 blob = data_blob_string_const("");
824 if (!push_reg_sz(mem_ctx, &blob, data)) {
825 DEBUG(0, ("winreg_printer_write_sz: Could not marshall string %s for %s\n",
830 status = dcerpc_winreg_SetValue(winreg_handle,
838 if (!NT_STATUS_IS_OK(status)) {
839 result = ntstatus_to_werror(status);
841 if (!W_ERROR_IS_OK(result)) {
842 DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: %s\n",
843 wvalue.name, win_errstr(result)));
849 static WERROR winreg_printer_write_dword(TALLOC_CTX *mem_ctx,
850 struct dcerpc_binding_handle *winreg_handle,
851 struct policy_handle *key_handle,
855 struct winreg_String wvalue;
857 WERROR result = WERR_OK;
861 blob = data_blob_talloc(mem_ctx, NULL, 4);
862 SIVAL(blob.data, 0, data);
864 status = dcerpc_winreg_SetValue(winreg_handle,
872 if (!NT_STATUS_IS_OK(status)) {
873 result = ntstatus_to_werror(status);
875 if (!W_ERROR_IS_OK(result)) {
876 DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: %s\n",
877 wvalue.name, win_errstr(result)));
883 static WERROR winreg_printer_write_binary(TALLOC_CTX *mem_ctx,
884 struct dcerpc_binding_handle *winreg_handle,
885 struct policy_handle *key_handle,
889 struct winreg_String wvalue;
890 WERROR result = WERR_OK;
894 status = dcerpc_winreg_SetValue(winreg_handle,
902 if (!NT_STATUS_IS_OK(status)) {
903 result = ntstatus_to_werror(status);
905 if (!W_ERROR_IS_OK(result)) {
906 DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: %s\n",
907 wvalue.name, win_errstr(result)));
913 static WERROR winreg_printer_query_binary(TALLOC_CTX *mem_ctx,
914 struct dcerpc_binding_handle *winreg_handle,
915 struct policy_handle *key_handle,
919 struct winreg_String wvalue;
920 enum winreg_Type type;
921 WERROR result = WERR_OK;
922 uint32_t value_len = 0;
923 uint32_t data_size = 0;
928 status = dcerpc_winreg_QueryValue(winreg_handle,
937 if (!NT_STATUS_IS_OK(status)) {
938 result = ntstatus_to_werror(status);
940 if (!W_ERROR_IS_OK(result)) {
941 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
942 wvalue.name, win_errstr(result)));
946 if (type != REG_BINARY) {
947 result = WERR_INVALID_DATATYPE;
950 blob = data_blob_talloc(mem_ctx, NULL, data_size);
951 if (blob.data == NULL) {
957 status = dcerpc_winreg_QueryValue(winreg_handle,
966 if (!NT_STATUS_IS_OK(status)) {
967 result = ntstatus_to_werror(status);
969 if (!W_ERROR_IS_OK(result)) {
970 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
971 wvalue.name, win_errstr(result)));
976 data->data = blob.data;
977 data->length = blob.length;
983 static WERROR winreg_printer_query_dword(TALLOC_CTX *mem_ctx,
984 struct dcerpc_binding_handle *winreg_handle,
985 struct policy_handle *key_handle,
989 struct winreg_String wvalue;
990 enum winreg_Type type;
991 WERROR result = WERR_OK;
992 uint32_t value_len = 0;
993 uint32_t data_size = 0;
998 status = dcerpc_winreg_QueryValue(winreg_handle,
1007 if (!NT_STATUS_IS_OK(status)) {
1008 result = ntstatus_to_werror(status);
1010 if (!W_ERROR_IS_OK(result)) {
1011 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1012 wvalue.name, win_errstr(result)));
1016 if (type != REG_DWORD) {
1017 result = WERR_INVALID_DATATYPE;
1021 if (data_size != 4) {
1022 result = WERR_INVALID_DATA;
1026 blob = data_blob_talloc(mem_ctx, NULL, data_size);
1027 if (blob.data == NULL) {
1028 result = WERR_NOMEM;
1033 status = dcerpc_winreg_QueryValue(winreg_handle,
1042 if (!NT_STATUS_IS_OK(status)) {
1043 result = ntstatus_to_werror(status);
1045 if (!W_ERROR_IS_OK(result)) {
1046 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1047 wvalue.name, win_errstr(result)));
1052 *data = IVAL(blob.data, 0);
1058 static WERROR winreg_printer_write_multi_sz(TALLOC_CTX *mem_ctx,
1059 struct dcerpc_binding_handle *winreg_handle,
1060 struct policy_handle *key_handle,
1064 struct winreg_String wvalue;
1066 WERROR result = WERR_OK;
1069 wvalue.name = value;
1070 if (!push_reg_multi_sz(mem_ctx, &blob, data)) {
1073 status = dcerpc_winreg_SetValue(winreg_handle,
1081 if (!NT_STATUS_IS_OK(status)) {
1082 result = ntstatus_to_werror(status);
1084 if (!W_ERROR_IS_OK(result)) {
1085 DEBUG(0, ("winreg_printer_write_multi_sz: Could not set value %s: %s\n",
1086 wvalue.name, win_errstr(result)));
1092 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
1093 const struct auth_serversupplied_info *server_info,
1094 struct messaging_context *msg_ctx,
1095 const char *drivername,
1096 const char *architecture,
1098 uint32_t access_mask,
1100 struct dcerpc_binding_handle **winreg_binding_handle,
1101 struct policy_handle *hive_hnd,
1102 struct policy_handle *key_hnd)
1107 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
1108 TOP_LEVEL_CONTROL_KEY,
1109 architecture, version);
1114 result = winreg_printer_openkey(mem_ctx,
1117 winreg_binding_handle,
1127 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
1128 struct spoolss_PrinterEnumValues *v,
1129 const char *valuename, uint32_t *dw)
1131 /* just return if it is not the one we are looking for */
1132 if (strcmp(valuename, v->value_name) != 0) {
1133 return WERR_NOT_FOUND;
1136 if (v->type != REG_DWORD) {
1137 return WERR_INVALID_DATATYPE;
1140 if (v->data_length != 4) {
1145 *dw = IVAL(v->data->data, 0);
1149 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
1150 struct spoolss_PrinterEnumValues *v,
1151 const char *valuename, const char **_str)
1153 /* just return if it is not the one we are looking for */
1154 if (strcmp(valuename, v->value_name) != 0) {
1155 return WERR_NOT_FOUND;
1158 if (v->type != REG_SZ) {
1159 return WERR_INVALID_DATATYPE;
1162 if (v->data_length == 0) {
1163 *_str = talloc_strdup(mem_ctx, EMPTY_STRING);
1164 if (*_str == NULL) {
1170 if (!pull_reg_sz(mem_ctx, v->data, _str)) {
1177 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
1178 struct spoolss_PrinterEnumValues *v,
1179 const char *valuename,
1180 const char ***array)
1182 /* just return if it is not the one we are looking for */
1183 if (strcmp(valuename, v->value_name) != 0) {
1184 return WERR_NOT_FOUND;
1187 if (v->type != REG_MULTI_SZ) {
1188 return WERR_INVALID_DATATYPE;
1191 if (v->data_length == 0) {
1192 *array = talloc_array(mem_ctx, const char *, 1);
1193 if (*array == NULL) {
1200 if (!pull_reg_multi_sz(mem_ctx, v->data, array)) {
1207 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
1208 struct dcerpc_binding_handle *winreg_handle,
1209 struct policy_handle *key_handle,
1213 struct winreg_String wvalue;
1215 WERROR result = WERR_OK;
1221 t = nt_time_to_unix(data);
1223 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
1224 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
1229 wvalue.name = value;
1230 if (!push_reg_sz(mem_ctx, &blob, str)) {
1233 status = dcerpc_winreg_SetValue(winreg_handle,
1241 if (!NT_STATUS_IS_OK(status)) {
1242 result = ntstatus_to_werror(status);
1244 if (!W_ERROR_IS_OK(result)) {
1245 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1246 wvalue.name, win_errstr(result)));
1252 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
1259 if (sscanf(str, "%d/%d/%d",
1260 &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3) {
1261 return WERR_INVALID_PARAMETER;
1268 unix_to_nt_time(data, t);
1273 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
1274 struct dcerpc_binding_handle *winreg_handle,
1275 struct policy_handle *key_handle,
1279 struct winreg_String wvalue;
1281 WERROR result = WERR_OK;
1285 /* FIXME: check format is right,
1286 * this needs to be something like: 6.1.7600.16385 */
1287 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
1288 (unsigned)((data >> 48) & 0xFFFF),
1289 (unsigned)((data >> 32) & 0xFFFF),
1290 (unsigned)((data >> 16) & 0xFFFF),
1291 (unsigned)(data & 0xFFFF));
1296 wvalue.name = value;
1297 if (!push_reg_sz(mem_ctx, &blob, str)) {
1300 status = dcerpc_winreg_SetValue(winreg_handle,
1308 if (!NT_STATUS_IS_OK(status)) {
1309 result = ntstatus_to_werror(status);
1311 if (!W_ERROR_IS_OK(result)) {
1312 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1313 wvalue.name, win_errstr(result)));
1319 static WERROR winreg_printer_ver_to_dword(const char *str, uint64_t *data)
1321 unsigned int v1, v2, v3, v4;
1323 if (sscanf(str, "%u.%u.%u.%u", &v1, &v2, &v3, &v4) != 4) {
1324 return WERR_INVALID_PARAMETER;
1327 *data = ((uint64_t)(v1 & 0xFFFF) << 48) +
1328 ((uint64_t)(v2 & 0xFFFF) << 32) +
1329 ((uint64_t)(v3 & 0xFFFF) << 16) +
1330 (uint64_t)(v2 & 0xFFFF);
1335 /********************************************************************
1336 Public winreg function for spoolss
1337 ********************************************************************/
1339 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
1340 const struct auth_serversupplied_info *server_info,
1341 struct messaging_context *msg_ctx,
1342 const char *servername,
1343 const char *sharename)
1345 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1346 struct dcerpc_binding_handle *winreg_handle = NULL;
1347 struct policy_handle hive_hnd, key_hnd;
1348 struct spoolss_SetPrinterInfo2 *info2;
1349 struct security_descriptor *secdesc;
1350 struct winreg_String wkey, wkeyclass;
1352 const char *subkeys[] = { SPOOL_DSDRIVER_KEY, SPOOL_DSSPOOLER_KEY, SPOOL_PRINTERDATA_KEY };
1353 uint32_t i, count = ARRAY_SIZE(subkeys);
1354 uint32_t info2_mask = 0;
1355 WERROR result = WERR_OK;
1356 TALLOC_CTX *tmp_ctx;
1358 tmp_ctx = talloc_stackframe();
1359 if (tmp_ctx == NULL) {
1363 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1365 TALLOC_FREE(tmp_ctx);
1369 ZERO_STRUCT(hive_hnd);
1370 ZERO_STRUCT(key_hnd);
1372 result = winreg_printer_openkey(tmp_ctx,
1382 if (W_ERROR_IS_OK(result)) {
1383 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
1385 } else if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1386 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
1387 } else if (!W_ERROR_IS_OK(result)) {
1388 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
1389 path, win_errstr(result)));
1393 /* Create the main key */
1394 result = winreg_printer_openkey(tmp_ctx,
1404 if (!W_ERROR_IS_OK(result)) {
1405 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1406 path, win_errstr(result)));
1410 if (is_valid_policy_hnd(&key_hnd)) {
1411 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
1414 /* Create subkeys */
1415 for (i = 0; i < count; i++) {
1417 enum winreg_CreateAction action = REG_ACTION_NONE;
1419 ZERO_STRUCT(key_hnd);
1422 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
1423 if (wkey.name == NULL) {
1424 result = WERR_NOMEM;
1428 ZERO_STRUCT(wkeyclass);
1429 wkeyclass.name = "";
1431 status = dcerpc_winreg_CreateKey(winreg_handle,
1442 if (!NT_STATUS_IS_OK(status)) {
1443 result = ntstatus_to_werror(status);
1445 if (!W_ERROR_IS_OK(result)) {
1446 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1447 wkey.name, win_errstr(result)));
1453 const char *dnssuffix;
1454 const char *longname;
1455 const char *uncname;
1457 result = winreg_printer_write_sz(tmp_ctx,
1460 SPOOL_REG_PRINTERNAME,
1462 if (!W_ERROR_IS_OK(result)) {
1466 result = winreg_printer_write_sz(tmp_ctx,
1469 SPOOL_REG_SHORTSERVERNAME,
1471 if (!W_ERROR_IS_OK(result)) {
1475 /* We make the assumption that the netbios name
1476 * is the same as the DNS name since the former
1477 * will be what we used to join the domain
1479 dnssuffix = get_mydnsdomname(tmp_ctx);
1480 if (dnssuffix != NULL && dnssuffix[0] != '\0') {
1481 longname = talloc_asprintf(tmp_ctx, "%s.%s", global_myname(), dnssuffix);
1483 longname = talloc_strdup(tmp_ctx, global_myname());
1485 if (longname == NULL) {
1486 result = WERR_NOMEM;
1490 result = winreg_printer_write_sz(tmp_ctx,
1493 SPOOL_REG_SERVERNAME,
1495 if (!W_ERROR_IS_OK(result)) {
1499 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
1500 longname, sharename);
1501 if (uncname == NULL) {
1502 result = WERR_NOMEM;
1506 result = winreg_printer_write_sz(tmp_ctx,
1511 if (!W_ERROR_IS_OK(result)) {
1515 result = winreg_printer_write_dword(tmp_ctx,
1518 SPOOL_REG_VERSIONNUMBER,
1520 if (!W_ERROR_IS_OK(result)) {
1524 result = winreg_printer_write_dword(tmp_ctx,
1527 SPOOL_REG_PRINTSTARTTIME,
1529 if (!W_ERROR_IS_OK(result)) {
1533 result = winreg_printer_write_dword(tmp_ctx,
1536 SPOOL_REG_PRINTENDTIME,
1538 if (!W_ERROR_IS_OK(result)) {
1542 result = winreg_printer_write_dword(tmp_ctx,
1547 if (!W_ERROR_IS_OK(result)) {
1551 result = winreg_printer_write_dword(tmp_ctx,
1554 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
1556 if (!W_ERROR_IS_OK(result)) {
1564 if (is_valid_policy_hnd(&key_hnd)) {
1565 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
1568 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
1569 if (info2 == NULL) {
1570 result = WERR_NOMEM;
1574 if (servername != NULL) {
1575 info2->printername = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
1576 servername, sharename);
1578 info2->printername = sharename;
1580 if (info2->printername == NULL) {
1581 result = WERR_NOMEM;
1584 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1586 info2->sharename = sharename;
1587 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1589 info2->portname = SAMBA_PRINTER_PORT_NAME;
1590 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1592 info2->printprocessor = "winprint";
1593 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1595 info2->datatype = "RAW";
1596 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1598 info2->comment = "";
1599 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1601 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1602 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1604 info2->starttime = 0; /* Minutes since 12:00am GMT */
1605 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1607 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1608 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1610 info2->priority = 1;
1611 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1613 info2->defaultpriority = 1;
1614 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1616 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1617 if (!W_ERROR_IS_OK(result)) {
1620 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1623 * Don't write a default Device Mode to the registry! The Device Mode is
1624 * only written to disk with a SetPrinter level 2 or 8.
1627 result = winreg_update_printer(tmp_ctx,
1637 if (winreg_handle != NULL) {
1640 if (is_valid_policy_hnd(&key_hnd)) {
1641 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1643 if (is_valid_policy_hnd(&hive_hnd)) {
1644 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1648 talloc_free(tmp_ctx);
1652 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1653 const struct auth_serversupplied_info *server_info,
1654 struct messaging_context *msg_ctx,
1655 const char *sharename,
1656 uint32_t info2_mask,
1657 struct spoolss_SetPrinterInfo2 *info2,
1658 struct spoolss_DeviceMode *devmode,
1659 struct security_descriptor *secdesc)
1661 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1662 struct dcerpc_binding_handle *winreg_handle = NULL;
1663 struct policy_handle hive_hnd, key_hnd;
1664 int snum = lp_servicenumber(sharename);
1665 enum ndr_err_code ndr_err;
1668 WERROR result = WERR_OK;
1669 TALLOC_CTX *tmp_ctx;
1671 tmp_ctx = talloc_stackframe();
1672 if (tmp_ctx == NULL) {
1676 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1678 TALLOC_FREE(tmp_ctx);
1682 ZERO_STRUCT(hive_hnd);
1683 ZERO_STRUCT(key_hnd);
1685 result = winreg_printer_openkey(tmp_ctx,
1695 if (!W_ERROR_IS_OK(result)) {
1696 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1697 path, win_errstr(result)));
1701 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1702 result = winreg_printer_write_dword(tmp_ctx,
1707 if (!W_ERROR_IS_OK(result)) {
1713 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1714 result = winreg_printer_write_dword(tmp_ctx,
1719 if (!W_ERROR_IS_OK(result)) {
1725 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1726 result = winreg_printer_write_sz(tmp_ctx,
1731 if (!W_ERROR_IS_OK(result)) {
1736 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1737 result = winreg_printer_write_sz(tmp_ctx,
1742 if (!W_ERROR_IS_OK(result)) {
1747 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1748 result = winreg_printer_write_dword(tmp_ctx,
1752 info2->defaultpriority);
1753 if (!W_ERROR_IS_OK(result)) {
1758 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1760 * Some client drivers freak out if there is a NULL devmode
1761 * (probably the driver is not checking before accessing
1762 * the devmode pointer) --jerry
1764 if (devmode == NULL && lp_default_devmode(snum) && info2 != NULL) {
1765 result = spoolss_create_default_devmode(tmp_ctx,
1768 if (!W_ERROR_IS_OK(result)) {
1772 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, devmode,
1773 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1774 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1775 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1776 result = WERR_NOMEM;
1780 result = winreg_printer_write_binary(tmp_ctx,
1785 if (!W_ERROR_IS_OK(result)) {
1790 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1791 result = winreg_printer_write_sz(tmp_ctx,
1796 if (!W_ERROR_IS_OK(result)) {
1801 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1802 result = winreg_printer_write_sz(tmp_ctx,
1807 if (!W_ERROR_IS_OK(result)) {
1812 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1813 result = winreg_printer_write_sz(tmp_ctx,
1818 if (!W_ERROR_IS_OK(result)) {
1823 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1824 result = winreg_printer_write_sz(tmp_ctx,
1829 if (!W_ERROR_IS_OK(result)) {
1834 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1836 * in addprinter: no servername and the printer is the name
1837 * in setprinter: servername is \\server
1838 * and printer is \\server\\printer
1840 * Samba manages only local printers.
1841 * we currently don't support things like i
1842 * path=\\other_server\printer
1844 * We only store the printername, not \\server\printername
1846 const char *p = strrchr(info2->printername, '\\');
1848 p = info2->printername;
1852 result = winreg_printer_write_sz(tmp_ctx,
1857 if (!W_ERROR_IS_OK(result)) {
1862 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1863 result = winreg_printer_write_sz(tmp_ctx,
1867 info2->printprocessor);
1868 if (!W_ERROR_IS_OK(result)) {
1873 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1874 result = winreg_printer_write_dword(tmp_ctx,
1879 if (!W_ERROR_IS_OK(result)) {
1884 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1886 * We need a security descriptor, if it isn't specified by
1887 * AddPrinter{Ex} then create a default descriptor.
1889 if (secdesc == NULL) {
1890 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1891 if (!W_ERROR_IS_OK(result)) {
1895 result = winreg_set_printer_secdesc(tmp_ctx,
1900 if (!W_ERROR_IS_OK(result)) {
1905 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1906 result = winreg_printer_write_sz(tmp_ctx,
1911 if (!W_ERROR_IS_OK(result)) {
1916 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1917 result = winreg_printer_write_sz(tmp_ctx,
1922 if (!W_ERROR_IS_OK(result)) {
1927 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1928 result = winreg_printer_write_dword(tmp_ctx,
1933 if (!W_ERROR_IS_OK(result)) {
1938 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1939 result = winreg_printer_write_dword(tmp_ctx,
1944 if (!W_ERROR_IS_OK(result)) {
1949 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1950 result = winreg_printer_write_dword(tmp_ctx,
1955 if (!W_ERROR_IS_OK(result)) {
1960 result = winreg_printer_write_dword(tmp_ctx,
1964 winreg_printer_rev_changeid());
1965 if (!W_ERROR_IS_OK(result)) {
1971 if (winreg_handle != NULL) {
1974 if (is_valid_policy_hnd(&key_hnd)) {
1975 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1977 if (is_valid_policy_hnd(&hive_hnd)) {
1978 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1982 TALLOC_FREE(tmp_ctx);
1986 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1987 const struct auth_serversupplied_info *server_info,
1988 struct messaging_context *msg_ctx,
1989 const char *servername,
1990 const char *printer,
1991 struct spoolss_PrinterInfo2 **pinfo2)
1993 struct spoolss_PrinterInfo2 *info2;
1994 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1995 struct dcerpc_binding_handle *winreg_handle = NULL;
1996 struct policy_handle hive_hnd, key_hnd;
1997 struct spoolss_PrinterEnumValues *enum_values = NULL;
1998 struct spoolss_PrinterEnumValues *v;
1999 enum ndr_err_code ndr_err;
2001 int snum = lp_servicenumber(printer);
2002 uint32_t num_values = 0;
2005 WERROR result = WERR_OK;
2006 TALLOC_CTX *tmp_ctx;
2008 tmp_ctx = talloc_stackframe();
2009 if (tmp_ctx == NULL) {
2013 path = winreg_printer_data_keyname(tmp_ctx, printer);
2015 TALLOC_FREE(tmp_ctx);
2019 result = winreg_printer_openkey(tmp_ctx,
2029 if (!W_ERROR_IS_OK(result)) {
2030 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
2031 path, win_errstr(result)));
2035 result = winreg_printer_enumvalues(tmp_ctx,
2040 if (!W_ERROR_IS_OK(result)) {
2041 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
2042 path, win_errstr(result)));
2046 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
2047 if (info2 == NULL) {
2048 result = WERR_NOMEM;
2052 FILL_STRING(info2, EMPTY_STRING, info2->servername);
2053 FILL_STRING(info2, EMPTY_STRING, info2->printername);
2054 FILL_STRING(info2, EMPTY_STRING, info2->sharename);
2055 FILL_STRING(info2, EMPTY_STRING, info2->portname);
2056 FILL_STRING(info2, EMPTY_STRING, info2->drivername);
2057 FILL_STRING(info2, EMPTY_STRING, info2->comment);
2058 FILL_STRING(info2, EMPTY_STRING, info2->location);
2059 FILL_STRING(info2, EMPTY_STRING, info2->sepfile);
2060 FILL_STRING(info2, EMPTY_STRING, info2->printprocessor);
2061 FILL_STRING(info2, EMPTY_STRING, info2->datatype);
2062 FILL_STRING(info2, EMPTY_STRING, info2->parameters);
2064 if (servername != NULL && servername[0] != '\0') {
2065 info2->servername = talloc_asprintf(info2, "\\\\%s", servername);
2066 if (info2->servername == NULL) {
2067 result = WERR_NOMEM;
2072 for (i = 0; i < num_values; i++) {
2073 v = &enum_values[i];
2075 result = winreg_enumval_to_sz(info2,
2078 &info2->printername);
2079 CHECK_ERROR(result);
2081 result = winreg_enumval_to_sz(info2,
2085 CHECK_ERROR(result);
2087 result = winreg_enumval_to_sz(info2,
2091 CHECK_ERROR(result);
2093 result = winreg_enumval_to_sz(info2,
2097 CHECK_ERROR(result);
2099 result = winreg_enumval_to_sz(info2,
2103 CHECK_ERROR(result);
2105 result = winreg_enumval_to_sz(info2,
2109 CHECK_ERROR(result);
2111 result = winreg_enumval_to_sz(info2,
2114 &info2->printprocessor);
2115 CHECK_ERROR(result);
2117 result = winreg_enumval_to_sz(info2,
2121 CHECK_ERROR(result);
2123 result = winreg_enumval_to_sz(info2,
2126 &info2->parameters);
2127 CHECK_ERROR(result);
2129 result = winreg_enumval_to_sz(info2,
2132 &info2->drivername);
2133 CHECK_ERROR(result);
2135 result = winreg_enumval_to_dword(info2,
2138 &info2->attributes);
2139 CHECK_ERROR(result);
2141 result = winreg_enumval_to_dword(info2,
2145 CHECK_ERROR(result);
2147 result = winreg_enumval_to_dword(info2,
2150 &info2->defaultpriority);
2151 CHECK_ERROR(result);
2153 result = winreg_enumval_to_dword(info2,
2157 CHECK_ERROR(result);
2159 result = winreg_enumval_to_dword(info2,
2163 CHECK_ERROR(result);
2165 result = winreg_enumval_to_dword(info2,
2169 CHECK_ERROR(result);
2171 result = winreg_enumval_to_dword(info2,
2175 CHECK_ERROR(result);
2178 if (!W_ERROR_IS_OK(result)) {
2179 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2182 win_errstr(result)));
2186 /* Create the printername */
2187 if (info2->servername != NULL && info2->servername[0] != '\0') {
2188 if (lp_force_printername(snum)) {
2189 const char *p = talloc_asprintf(info2, "%s\\%s",
2193 result = WERR_NOMEM;
2196 info2->printername = p;
2198 char *p = talloc_asprintf(info2, "%s\\%s",
2200 info2->printername);
2202 result = WERR_NOMEM;
2205 info2->printername = p;
2209 /* Construct the Device Mode */
2210 result = winreg_printer_query_binary(tmp_ctx,
2215 if (W_ERROR_IS_OK(result)) {
2216 info2->devmode = talloc_zero(info2, struct spoolss_DeviceMode);
2217 if (info2->devmode == NULL) {
2218 result = WERR_NOMEM;
2221 ndr_err = ndr_pull_struct_blob(&blob,
2224 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
2225 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2226 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2227 result = WERR_NOMEM;
2232 if (info2->devmode == NULL && lp_default_devmode(snum)) {
2233 result = spoolss_create_default_devmode(info2,
2236 if (!W_ERROR_IS_OK(result)) {
2241 if (info2->devmode != NULL) {
2242 info2->devmode->devicename = talloc_strdup(info2->devmode,
2243 info2->printername);
2244 if (info2->devmode->devicename == NULL) {
2245 DEBUG(0, ("winreg_get_printer: Failed to set devicename\n"));
2246 result = WERR_NOMEM;
2251 result = winreg_get_printer_secdesc(info2,
2256 if (!W_ERROR_IS_OK(result)) {
2260 /* Fix for OS/2 drivers. */
2261 if (get_remote_arch() == RA_OS2) {
2262 spoolss_map_to_os2_driver(info2, &info2->drivername);
2266 *pinfo2 = talloc_move(mem_ctx, &info2);
2271 if (winreg_handle != NULL) {
2274 if (is_valid_policy_hnd(&key_hnd)) {
2275 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2277 if (is_valid_policy_hnd(&hive_hnd)) {
2278 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2282 TALLOC_FREE(tmp_ctx);
2286 WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
2287 const struct auth_serversupplied_info *server_info,
2288 struct messaging_context *msg_ctx,
2289 const char *sharename,
2290 struct spoolss_security_descriptor **psecdesc)
2292 struct spoolss_security_descriptor *secdesc;
2293 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2294 struct dcerpc_binding_handle *winreg_handle = NULL;
2295 struct policy_handle hive_hnd, key_hnd;
2296 enum ndr_err_code ndr_err;
2299 TALLOC_CTX *tmp_ctx;
2302 tmp_ctx = talloc_stackframe();
2303 if (tmp_ctx == NULL) {
2307 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2309 talloc_free(tmp_ctx);
2313 ZERO_STRUCT(hive_hnd);
2314 ZERO_STRUCT(key_hnd);
2316 result = winreg_printer_openkey(tmp_ctx,
2326 if (!W_ERROR_IS_OK(result)) {
2327 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2328 goto create_default;
2333 result = winreg_printer_query_binary(tmp_ctx,
2338 if (!W_ERROR_IS_OK(result)) {
2339 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2340 goto create_default;
2345 secdesc = talloc_zero(tmp_ctx, struct spoolss_security_descriptor);
2346 if (secdesc == NULL) {
2347 result = WERR_NOMEM;
2350 ndr_err = ndr_pull_struct_blob(&blob,
2353 (ndr_pull_flags_fn_t) ndr_pull_security_descriptor);
2354 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2355 DEBUG(0, ("winreg_get_secdesc: Failed to unmarshall security descriptor\n"));
2356 result = WERR_NOMEM;
2361 *psecdesc = talloc_move(mem_ctx, &secdesc);
2368 result = winreg_printer_openkey(tmp_ctx,
2378 if (!W_ERROR_IS_OK(result)) {
2382 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
2383 if (!W_ERROR_IS_OK(result)) {
2387 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
2388 this security descriptor has been created when winbindd was
2389 down. Take ownership of security descriptor. */
2390 if (sid_equal(secdesc->owner_sid, &global_sid_World)) {
2391 struct dom_sid owner_sid;
2393 /* Change sd owner to workgroup administrator */
2395 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid)) {
2396 struct spoolss_security_descriptor *new_secdesc;
2400 sid_append_rid(&owner_sid, DOMAIN_RID_ADMINISTRATOR);
2402 new_secdesc = make_sec_desc(tmp_ctx,
2411 if (new_secdesc == NULL) {
2412 result = WERR_NOMEM;
2416 /* Swap with other one */
2417 secdesc = new_secdesc;
2421 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, secdesc,
2422 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2423 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2424 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2425 result = WERR_NOMEM;
2429 result = winreg_printer_write_binary(tmp_ctx,
2434 if (!W_ERROR_IS_OK(result)) {
2439 *psecdesc = talloc_move(mem_ctx, &secdesc);
2444 if (winreg_handle != NULL) {
2447 if (is_valid_policy_hnd(&key_hnd)) {
2448 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2450 if (is_valid_policy_hnd(&hive_hnd)) {
2451 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2455 talloc_free(tmp_ctx);
2459 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
2460 const struct auth_serversupplied_info *server_info,
2461 struct messaging_context *msg_ctx,
2462 const char *sharename,
2463 const struct spoolss_security_descriptor *secdesc)
2465 const struct spoolss_security_descriptor *new_secdesc = secdesc;
2466 struct spoolss_security_descriptor *old_secdesc;
2467 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2468 struct dcerpc_binding_handle *winreg_handle = NULL;
2469 struct policy_handle hive_hnd, key_hnd;
2470 enum ndr_err_code ndr_err;
2473 TALLOC_CTX *tmp_ctx;
2476 tmp_ctx = talloc_stackframe();
2477 if (tmp_ctx == NULL) {
2481 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2483 talloc_free(tmp_ctx);
2488 * The old owner and group sids of the security descriptor are not
2489 * present when new ACEs are added or removed by changing printer
2490 * permissions through NT. If they are NULL in the new security
2491 * descriptor then copy them over from the old one.
2493 if (!secdesc->owner_sid || !secdesc->group_sid) {
2494 struct dom_sid *owner_sid, *group_sid;
2495 struct security_acl *dacl, *sacl;
2498 result = winreg_get_printer_secdesc(tmp_ctx,
2503 if (!W_ERROR_IS_OK(result)) {
2504 talloc_free(tmp_ctx);
2508 /* Pick out correct owner and group sids */
2509 owner_sid = secdesc->owner_sid ?
2510 secdesc->owner_sid :
2511 old_secdesc->owner_sid;
2513 group_sid = secdesc->group_sid ?
2514 secdesc->group_sid :
2515 old_secdesc->group_sid;
2517 dacl = secdesc->dacl ?
2521 sacl = secdesc->sacl ?
2525 /* Make a deep copy of the security descriptor */
2526 new_secdesc = make_sec_desc(tmp_ctx,
2534 if (new_secdesc == NULL) {
2535 talloc_free(tmp_ctx);
2540 ZERO_STRUCT(hive_hnd);
2541 ZERO_STRUCT(key_hnd);
2543 result = winreg_printer_openkey(tmp_ctx,
2553 if (!W_ERROR_IS_OK(result)) {
2557 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, new_secdesc,
2558 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2559 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2560 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2561 result = WERR_NOMEM;
2565 result = winreg_printer_write_binary(tmp_ctx,
2572 if (winreg_handle != NULL) {
2575 if (is_valid_policy_hnd(&key_hnd)) {
2576 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2578 if (is_valid_policy_hnd(&hive_hnd)) {
2579 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2583 talloc_free(tmp_ctx);
2587 /* Set printer data over the winreg pipe. */
2588 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2589 const struct auth_serversupplied_info *server_info,
2590 struct messaging_context *msg_ctx,
2591 const char *printer,
2594 enum winreg_Type type,
2598 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2599 struct dcerpc_binding_handle *winreg_handle = NULL;
2600 struct policy_handle hive_hnd, key_hnd;
2601 struct winreg_String wvalue;
2603 WERROR result = WERR_OK;
2605 TALLOC_CTX *tmp_ctx;
2607 tmp_ctx = talloc_stackframe();
2608 if (tmp_ctx == NULL) {
2612 path = winreg_printer_data_keyname(tmp_ctx, printer);
2614 TALLOC_FREE(tmp_ctx);
2618 ZERO_STRUCT(hive_hnd);
2619 ZERO_STRUCT(key_hnd);
2621 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2622 key, value, access_mask, printer));
2623 result = winreg_printer_openkey(tmp_ctx,
2633 if (!W_ERROR_IS_OK(result)) {
2634 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2635 key, win_errstr(result)));
2639 wvalue.name = value;
2640 status = dcerpc_winreg_SetValue(winreg_handle,
2648 if (!NT_STATUS_IS_OK(status)) {
2649 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2650 value, nt_errstr(status)));
2651 result = ntstatus_to_werror(status);
2655 if (winreg_handle != NULL) {
2658 if (is_valid_policy_hnd(&key_hnd)) {
2659 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2661 if (is_valid_policy_hnd(&hive_hnd)) {
2662 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2666 TALLOC_FREE(tmp_ctx);
2670 /* Get printer data over a winreg pipe. */
2671 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2672 const struct auth_serversupplied_info *server_info,
2673 struct messaging_context *msg_ctx,
2674 const char *printer,
2677 enum winreg_Type *type,
2679 uint32_t *data_size)
2681 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2682 struct dcerpc_binding_handle *winreg_handle = NULL;
2683 struct policy_handle hive_hnd, key_hnd;
2684 struct winreg_String wvalue;
2685 enum winreg_Type type_in;
2688 uint32_t data_in_size = 0;
2689 uint32_t value_len = 0;
2690 WERROR result = WERR_OK;
2692 TALLOC_CTX *tmp_ctx;
2694 tmp_ctx = talloc_stackframe();
2695 if (tmp_ctx == NULL) {
2699 path = winreg_printer_data_keyname(tmp_ctx, printer);
2701 TALLOC_FREE(tmp_ctx);
2705 ZERO_STRUCT(hive_hnd);
2706 ZERO_STRUCT(key_hnd);
2708 result = winreg_printer_openkey(tmp_ctx,
2718 if (!W_ERROR_IS_OK(result)) {
2719 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2720 key, win_errstr(result)));
2724 wvalue.name = value;
2727 * call QueryValue once with data == NULL to get the
2728 * needed memory size to be allocated, then allocate
2729 * data buffer and call again.
2731 status = dcerpc_winreg_QueryValue(winreg_handle,
2740 if (!NT_STATUS_IS_OK(status)) {
2741 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2742 value, nt_errstr(status)));
2743 result = ntstatus_to_werror(status);
2746 if (!W_ERROR_IS_OK(result)) {
2750 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2751 if (data_in == NULL) {
2752 result = WERR_NOMEM;
2757 status = dcerpc_winreg_QueryValue(winreg_handle,
2766 if (!NT_STATUS_IS_OK(status)) {
2767 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2768 value, nt_errstr(status)));
2769 result = ntstatus_to_werror(status);
2772 if (!W_ERROR_IS_OK(result)) {
2777 *data_size = data_in_size;
2779 *data = talloc_move(mem_ctx, &data_in);
2784 if (winreg_handle != NULL) {
2787 if (is_valid_policy_hnd(&key_hnd)) {
2788 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2790 if (is_valid_policy_hnd(&hive_hnd)) {
2791 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2795 TALLOC_FREE(tmp_ctx);
2799 /* Enumerate on the values of a given key and provide the data. */
2800 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2801 const struct auth_serversupplied_info *server_info,
2802 struct messaging_context *msg_ctx,
2803 const char *printer,
2805 uint32_t *pnum_values,
2806 struct spoolss_PrinterEnumValues **penum_values)
2808 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2809 struct dcerpc_binding_handle *winreg_handle = NULL;
2810 struct policy_handle hive_hnd, key_hnd;
2812 struct spoolss_PrinterEnumValues *enum_values = NULL;
2813 uint32_t num_values = 0;
2815 WERROR result = WERR_OK;
2817 TALLOC_CTX *tmp_ctx;
2819 tmp_ctx = talloc_stackframe();
2820 if (tmp_ctx == NULL) {
2824 path = winreg_printer_data_keyname(tmp_ctx, printer);
2826 TALLOC_FREE(tmp_ctx);
2830 result = winreg_printer_openkey(tmp_ctx,
2840 if (!W_ERROR_IS_OK(result)) {
2841 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2842 key, win_errstr(result)));
2846 result = winreg_printer_enumvalues(tmp_ctx,
2851 if (!W_ERROR_IS_OK(result)) {
2852 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2853 key, win_errstr(result)));
2857 *pnum_values = num_values;
2859 *penum_values = talloc_move(mem_ctx, &enum_values);
2864 if (winreg_handle != NULL) {
2867 if (is_valid_policy_hnd(&key_hnd)) {
2868 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2870 if (is_valid_policy_hnd(&hive_hnd)) {
2871 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2875 TALLOC_FREE(tmp_ctx);
2879 /* Delete printer data over a winreg pipe. */
2880 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2881 const struct auth_serversupplied_info *server_info,
2882 struct messaging_context *msg_ctx,
2883 const char *printer,
2887 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2888 struct dcerpc_binding_handle *winreg_handle = NULL;
2889 struct policy_handle hive_hnd, key_hnd;
2890 struct winreg_String wvalue;
2892 WERROR result = WERR_OK;
2895 TALLOC_CTX *tmp_ctx;
2897 tmp_ctx = talloc_stackframe();
2898 if (tmp_ctx == NULL) {
2902 path = winreg_printer_data_keyname(tmp_ctx, printer);
2904 TALLOC_FREE(tmp_ctx);
2908 ZERO_STRUCT(hive_hnd);
2909 ZERO_STRUCT(key_hnd);
2911 result = winreg_printer_openkey(tmp_ctx,
2921 if (!W_ERROR_IS_OK(result)) {
2922 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2923 key, win_errstr(result)));
2927 wvalue.name = value;
2928 status = dcerpc_winreg_DeleteValue(winreg_handle,
2933 if (!NT_STATUS_IS_OK(status)) {
2934 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2935 value, nt_errstr(status)));
2936 result = ntstatus_to_werror(status);
2940 if (winreg_handle != NULL) {
2943 if (is_valid_policy_hnd(&key_hnd)) {
2944 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2946 if (is_valid_policy_hnd(&hive_hnd)) {
2947 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2951 TALLOC_FREE(tmp_ctx);
2955 /* Enumerate on the subkeys of a given key and provide the data. */
2956 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2957 const struct auth_serversupplied_info *server_info,
2958 struct messaging_context *msg_ctx,
2959 const char *printer,
2961 uint32_t *pnum_subkeys,
2962 const char ***psubkeys)
2964 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2965 struct dcerpc_binding_handle *winreg_handle = NULL;
2966 struct policy_handle hive_hnd, key_hnd;
2968 const char **subkeys = NULL;
2969 uint32_t num_subkeys = -1;
2971 WERROR result = WERR_OK;
2973 TALLOC_CTX *tmp_ctx;
2975 tmp_ctx = talloc_stackframe();
2976 if (tmp_ctx == NULL) {
2980 path = winreg_printer_data_keyname(tmp_ctx, printer);
2982 TALLOC_FREE(tmp_ctx);
2986 ZERO_STRUCT(hive_hnd);
2987 ZERO_STRUCT(key_hnd);
2989 result = winreg_printer_openkey(tmp_ctx,
2999 if (!W_ERROR_IS_OK(result)) {
3000 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
3001 key, win_errstr(result)));
3005 result = winreg_printer_enumkeys(tmp_ctx,
3010 if (!W_ERROR_IS_OK(result)) {
3011 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
3012 key, win_errstr(result)));
3016 *pnum_subkeys = num_subkeys;
3018 *psubkeys = talloc_move(mem_ctx, &subkeys);
3023 if (winreg_handle != NULL) {
3026 if (is_valid_policy_hnd(&key_hnd)) {
3027 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3029 if (is_valid_policy_hnd(&hive_hnd)) {
3030 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3034 TALLOC_FREE(tmp_ctx);
3038 /* Delete a key with subkeys of a given printer. */
3039 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
3040 const struct auth_serversupplied_info *server_info,
3041 struct messaging_context *msg_ctx,
3042 const char *printer,
3045 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3046 struct dcerpc_binding_handle *winreg_handle = NULL;
3047 struct policy_handle hive_hnd, key_hnd;
3051 TALLOC_CTX *tmp_ctx;
3053 tmp_ctx = talloc_stackframe();
3054 if (tmp_ctx == NULL) {
3058 path = winreg_printer_data_keyname(tmp_ctx, printer);
3060 TALLOC_FREE(tmp_ctx);
3064 result = winreg_printer_openkey(tmp_ctx,
3074 if (!W_ERROR_IS_OK(result)) {
3075 /* key doesn't exist */
3076 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3081 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
3082 key, win_errstr(result)));
3086 if (is_valid_policy_hnd(&key_hnd)) {
3087 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
3090 if (key == NULL || key[0] == '\0') {
3093 keyname = talloc_asprintf(tmp_ctx,
3097 if (keyname == NULL) {
3098 result = WERR_NOMEM;
3103 result = winreg_printer_delete_subkeys(tmp_ctx,
3108 if (!W_ERROR_IS_OK(result)) {
3109 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
3110 key, win_errstr(result)));
3115 if (winreg_handle != NULL) {
3118 if (is_valid_policy_hnd(&key_hnd)) {
3119 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3121 if (is_valid_policy_hnd(&hive_hnd)) {
3122 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3126 TALLOC_FREE(tmp_ctx);
3130 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
3131 const struct auth_serversupplied_info *server_info,
3132 struct messaging_context *msg_ctx,
3133 const char *printer)
3135 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3136 struct dcerpc_binding_handle *winreg_handle = NULL;
3137 struct policy_handle hive_hnd, key_hnd;
3140 TALLOC_CTX *tmp_ctx;
3142 tmp_ctx = talloc_stackframe();
3143 if (tmp_ctx == NULL) {
3147 path = winreg_printer_data_keyname(tmp_ctx, printer);
3149 TALLOC_FREE(tmp_ctx);
3153 ZERO_STRUCT(hive_hnd);
3154 ZERO_STRUCT(key_hnd);
3156 result = winreg_printer_openkey(tmp_ctx,
3166 if (!W_ERROR_IS_OK(result)) {
3167 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
3168 path, win_errstr(result)));
3172 result = winreg_printer_write_dword(tmp_ctx,
3176 winreg_printer_rev_changeid());
3177 if (!W_ERROR_IS_OK(result)) {
3183 if (winreg_handle != NULL) {
3186 if (is_valid_policy_hnd(&key_hnd)) {
3187 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3189 if (is_valid_policy_hnd(&hive_hnd)) {
3190 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3194 TALLOC_FREE(tmp_ctx);
3198 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
3199 const struct auth_serversupplied_info *server_info,
3200 struct messaging_context *msg_ctx,
3201 const char *printer,
3202 uint32_t *pchangeid)
3204 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3205 struct dcerpc_binding_handle *winreg_handle = NULL;
3206 struct policy_handle hive_hnd, key_hnd;
3207 uint32_t changeid = 0;
3210 TALLOC_CTX *tmp_ctx;
3212 tmp_ctx = talloc_stackframe();
3213 if (tmp_ctx == NULL) {
3217 path = winreg_printer_data_keyname(tmp_ctx, printer);
3219 TALLOC_FREE(tmp_ctx);
3223 ZERO_STRUCT(hive_hnd);
3224 ZERO_STRUCT(key_hnd);
3226 result = winreg_printer_openkey(tmp_ctx,
3236 if (!W_ERROR_IS_OK(result)) {
3237 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
3238 path, win_errstr(result)));
3242 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path));
3244 result = winreg_printer_query_dword(tmp_ctx,
3249 if (!W_ERROR_IS_OK(result)) {
3254 *pchangeid = changeid;
3259 if (winreg_handle != NULL) {
3262 if (is_valid_policy_hnd(&key_hnd)) {
3263 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3265 if (is_valid_policy_hnd(&hive_hnd)) {
3266 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3270 TALLOC_FREE(tmp_ctx);
3275 * The special behaviour of the spoolss forms is documented at the website:
3277 * Managing Win32 Printserver Forms
3278 * http://unixwiz.net/techtips/winspooler-forms.html
3281 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
3282 const struct auth_serversupplied_info *server_info,
3283 struct messaging_context *msg_ctx,
3284 struct spoolss_AddFormInfo1 *form)
3286 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3287 struct dcerpc_binding_handle *winreg_handle = NULL;
3288 struct policy_handle hive_hnd, key_hnd;
3289 struct winreg_String wvalue;
3291 uint32_t num_info = 0;
3292 union spoolss_FormInfo *info = NULL;
3296 TALLOC_CTX *tmp_ctx;
3298 tmp_ctx = talloc_stackframe();
3299 if (tmp_ctx == NULL) {
3303 ZERO_STRUCT(hive_hnd);
3304 ZERO_STRUCT(key_hnd);
3306 result = winreg_printer_openkey(tmp_ctx,
3310 TOP_LEVEL_CONTROL_FORMS_KEY,
3316 if (!W_ERROR_IS_OK(result)) {
3317 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
3318 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3322 result = winreg_printer_enumforms1(tmp_ctx, server_info, msg_ctx,
3324 if (!W_ERROR_IS_OK(result)) {
3325 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
3326 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3330 /* If form name already exists or is builtin return ALREADY_EXISTS */
3331 for (i = 0; i < num_info; i++) {
3332 if (strequal(info[i].info1.form_name, form->form_name)) {
3333 result = WERR_FILE_EXISTS;
3338 wvalue.name = form->form_name;
3340 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3341 SIVAL(blob.data, 0, form->size.width);
3342 SIVAL(blob.data, 4, form->size.height);
3343 SIVAL(blob.data, 8, form->area.left);
3344 SIVAL(blob.data, 12, form->area.top);
3345 SIVAL(blob.data, 16, form->area.right);
3346 SIVAL(blob.data, 20, form->area.bottom);
3347 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
3348 SIVAL(blob.data, 28, form->flags);
3350 status = dcerpc_winreg_SetValue(winreg_handle,
3358 if (!NT_STATUS_IS_OK(status)) {
3359 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
3360 wvalue.name, nt_errstr(status)));
3361 result = ntstatus_to_werror(status);
3365 if (winreg_handle != NULL) {
3368 if (is_valid_policy_hnd(&key_hnd)) {
3369 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3371 if (is_valid_policy_hnd(&hive_hnd)) {
3372 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3377 TALLOC_FREE(tmp_ctx);
3381 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
3382 const struct auth_serversupplied_info *server_info,
3383 struct messaging_context *msg_ctx,
3384 uint32_t *pnum_info,
3385 union spoolss_FormInfo **pinfo)
3387 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3388 struct dcerpc_binding_handle *winreg_handle = NULL;
3389 struct policy_handle hive_hnd, key_hnd;
3390 union spoolss_FormInfo *info;
3391 struct spoolss_PrinterEnumValues *enum_values = NULL;
3392 uint32_t num_values = 0;
3393 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3396 TALLOC_CTX *tmp_ctx;
3398 tmp_ctx = talloc_stackframe();
3399 if (tmp_ctx == NULL) {
3403 ZERO_STRUCT(hive_hnd);
3404 ZERO_STRUCT(key_hnd);
3406 result = winreg_printer_openkey(tmp_ctx,
3410 TOP_LEVEL_CONTROL_FORMS_KEY,
3416 if (!W_ERROR_IS_OK(result)) {
3417 /* key doesn't exist */
3418 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3423 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3424 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3428 result = winreg_printer_enumvalues(tmp_ctx,
3433 if (!W_ERROR_IS_OK(result)) {
3434 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3435 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3439 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
3441 result = WERR_NOMEM;
3445 /* Enumerate BUILTIN forms */
3446 for (i = 0; i < num_builtin; i++) {
3447 info[i].info1 = builtin_forms1[i];
3450 /* Enumerate registry forms */
3451 for (i = 0; i < num_values; i++) {
3452 union spoolss_FormInfo val;
3454 if (enum_values[i].type != REG_BINARY ||
3455 enum_values[i].data_length != 32) {
3459 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
3460 if (val.info1.form_name == NULL) {
3461 result = WERR_NOMEM;
3465 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3466 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3467 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3468 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3469 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3470 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3471 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3472 val.info1.flags = (enum spoolss_FormFlags) IVAL(enum_values[i].data->data, 28);
3474 info[i + num_builtin] = val;
3477 *pnum_info = num_builtin + num_values;
3479 *pinfo = talloc_move(mem_ctx, &info);
3483 if (winreg_handle != NULL) {
3486 if (is_valid_policy_hnd(&key_hnd)) {
3487 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3489 if (is_valid_policy_hnd(&hive_hnd)) {
3490 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3494 TALLOC_FREE(enum_values);
3495 TALLOC_FREE(tmp_ctx);
3499 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3500 const struct auth_serversupplied_info *server_info,
3501 struct messaging_context *msg_ctx,
3502 const char *form_name)
3504 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3505 struct dcerpc_binding_handle *winreg_handle = NULL;
3506 struct policy_handle hive_hnd, key_hnd;
3507 struct winreg_String wvalue;
3508 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3510 WERROR result = WERR_OK;
3512 TALLOC_CTX *tmp_ctx;
3514 for (i = 0; i < num_builtin; i++) {
3515 if (strequal(builtin_forms1[i].form_name, form_name)) {
3516 return WERR_INVALID_PARAMETER;
3520 tmp_ctx = talloc_stackframe();
3521 if (tmp_ctx == NULL) {
3525 ZERO_STRUCT(hive_hnd);
3526 ZERO_STRUCT(key_hnd);
3528 result = winreg_printer_openkey(tmp_ctx,
3532 TOP_LEVEL_CONTROL_FORMS_KEY,
3538 if (!W_ERROR_IS_OK(result)) {
3539 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3540 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3541 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3542 result = WERR_INVALID_FORM_NAME;
3547 wvalue.name = form_name;
3548 status = dcerpc_winreg_DeleteValue(winreg_handle,
3553 if (!NT_STATUS_IS_OK(status)) {
3554 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3555 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3556 wvalue.name, nt_errstr(status)));
3557 result = ntstatus_to_werror(status);
3561 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3562 result = WERR_INVALID_FORM_NAME;
3566 if (winreg_handle != NULL) {
3569 if (is_valid_policy_hnd(&key_hnd)) {
3570 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3572 if (is_valid_policy_hnd(&hive_hnd)) {
3573 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3577 TALLOC_FREE(tmp_ctx);
3581 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3582 const struct auth_serversupplied_info *server_info,
3583 struct messaging_context *msg_ctx,
3584 const char *form_name,
3585 struct spoolss_AddFormInfo1 *form)
3587 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3588 struct dcerpc_binding_handle *winreg_handle = NULL;
3589 struct policy_handle hive_hnd, key_hnd;
3590 struct winreg_String wvalue;
3592 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3596 TALLOC_CTX *tmp_ctx = NULL;
3598 for (i = 0; i < num_builtin; i++) {
3599 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3600 result = WERR_INVALID_PARAM;
3605 tmp_ctx = talloc_stackframe();
3606 if (tmp_ctx == NULL) {
3610 ZERO_STRUCT(hive_hnd);
3611 ZERO_STRUCT(key_hnd);
3613 result = winreg_printer_openkey(tmp_ctx,
3617 TOP_LEVEL_CONTROL_FORMS_KEY,
3623 if (!W_ERROR_IS_OK(result)) {
3624 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3625 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3629 /* If form_name != form->form_name then we renamed the form */
3630 if (strequal(form_name, form->form_name)) {
3631 result = winreg_printer_deleteform1(tmp_ctx, server_info,
3632 msg_ctx, form_name);
3633 if (!W_ERROR_IS_OK(result)) {
3634 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3635 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3640 wvalue.name = form->form_name;
3642 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3643 SIVAL(blob.data, 0, form->size.width);
3644 SIVAL(blob.data, 4, form->size.height);
3645 SIVAL(blob.data, 8, form->area.left);
3646 SIVAL(blob.data, 12, form->area.top);
3647 SIVAL(blob.data, 16, form->area.right);
3648 SIVAL(blob.data, 20, form->area.bottom);
3649 SIVAL(blob.data, 24, 42);
3650 SIVAL(blob.data, 28, form->flags);
3652 status = dcerpc_winreg_SetValue(winreg_handle,
3660 if (!NT_STATUS_IS_OK(status)) {
3661 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3662 wvalue.name, nt_errstr(status)));
3663 result = ntstatus_to_werror(status);
3667 if (winreg_handle != NULL) {
3670 if (is_valid_policy_hnd(&key_hnd)) {
3671 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3673 if (is_valid_policy_hnd(&hive_hnd)) {
3674 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3678 TALLOC_FREE(tmp_ctx);
3682 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3683 const struct auth_serversupplied_info *server_info,
3684 struct messaging_context *msg_ctx,
3685 const char *form_name,
3686 struct spoolss_FormInfo1 *r)
3688 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3689 struct dcerpc_binding_handle *winreg_handle = NULL;
3690 struct policy_handle hive_hnd, key_hnd;
3691 struct winreg_String wvalue;
3692 enum winreg_Type type_in;
3694 uint32_t data_in_size = 0;
3695 uint32_t value_len = 0;
3696 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3700 TALLOC_CTX *tmp_ctx;
3702 /* check builtin forms first */
3703 for (i = 0; i < num_builtin; i++) {
3704 if (strequal(builtin_forms1[i].form_name, form_name)) {
3705 *r = builtin_forms1[i];
3710 tmp_ctx = talloc_stackframe();
3711 if (tmp_ctx == NULL) {
3715 ZERO_STRUCT(hive_hnd);
3716 ZERO_STRUCT(key_hnd);
3718 result = winreg_printer_openkey(tmp_ctx,
3722 TOP_LEVEL_CONTROL_FORMS_KEY,
3728 if (!W_ERROR_IS_OK(result)) {
3729 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3730 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3734 wvalue.name = form_name;
3737 * call QueryValue once with data == NULL to get the
3738 * needed memory size to be allocated, then allocate
3739 * data buffer and call again.
3741 status = dcerpc_winreg_QueryValue(winreg_handle,
3750 if (!NT_STATUS_IS_OK(status)) {
3751 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3752 wvalue.name, nt_errstr(status)));
3753 result = ntstatus_to_werror(status);
3756 if (!W_ERROR_IS_OK(result)) {
3760 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3761 if (data_in == NULL) {
3762 result = WERR_NOMEM;
3767 status = dcerpc_winreg_QueryValue(winreg_handle,
3776 if (!NT_STATUS_IS_OK(status)) {
3777 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3778 wvalue.name, nt_errstr(status)));
3779 result = ntstatus_to_werror(status);
3782 if (!W_ERROR_IS_OK(result)) {
3786 r->form_name = talloc_strdup(mem_ctx, form_name);
3787 if (r->form_name == NULL) {
3788 result = WERR_NOMEM;
3792 r->size.width = IVAL(data_in, 0);
3793 r->size.height = IVAL(data_in, 4);
3794 r->area.left = IVAL(data_in, 8);
3795 r->area.top = IVAL(data_in, 12);
3796 r->area.right = IVAL(data_in, 16);
3797 r->area.bottom = IVAL(data_in, 20);
3798 /* skip index IVAL(data_in, 24)));*/
3799 r->flags = (enum spoolss_FormFlags) IVAL(data_in, 28);
3803 if (winreg_handle != NULL) {
3806 if (is_valid_policy_hnd(&key_hnd)) {
3807 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3809 if (is_valid_policy_hnd(&hive_hnd)) {
3810 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3814 TALLOC_FREE(tmp_ctx);
3818 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3819 const struct auth_serversupplied_info *server_info,
3820 struct messaging_context *msg_ctx,
3821 struct spoolss_AddDriverInfoCtr *r,
3822 const char **driver_name,
3823 uint32_t *driver_version)
3825 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3826 struct dcerpc_binding_handle *winreg_handle = NULL;
3827 struct policy_handle hive_hnd, key_hnd;
3828 struct spoolss_DriverInfo8 info8;
3829 TALLOC_CTX *tmp_ctx = NULL;
3832 ZERO_STRUCT(hive_hnd);
3833 ZERO_STRUCT(key_hnd);
3836 if (!driver_info_ctr_to_info8(r, &info8)) {
3837 result = WERR_INVALID_PARAMETER;
3841 tmp_ctx = talloc_stackframe();
3842 if (tmp_ctx == NULL) {
3846 result = winreg_printer_opendriver(tmp_ctx,
3856 if (!W_ERROR_IS_OK(result)) {
3857 DEBUG(0, ("winreg_add_driver: "
3858 "Could not open driver key (%s,%s,%d): %s\n",
3859 info8.driver_name, info8.architecture,
3860 info8.version, win_errstr(result)));
3864 /* TODO: "Attributes" ? */
3866 result = winreg_printer_write_dword(tmp_ctx, winreg_handle,
3867 &key_hnd, "Version",
3869 if (!W_ERROR_IS_OK(result)) {
3873 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3876 if (!W_ERROR_IS_OK(result)) {
3880 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3881 &key_hnd, "Data File",
3883 if (!W_ERROR_IS_OK(result)) {
3887 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3888 &key_hnd, "Configuration File",
3890 if (!W_ERROR_IS_OK(result)) {
3894 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3895 &key_hnd, "Help File",
3897 if (!W_ERROR_IS_OK(result)) {
3901 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3902 &key_hnd, "Dependent Files",
3903 info8.dependent_files);
3904 if (!W_ERROR_IS_OK(result)) {
3908 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3909 &key_hnd, "Monitor",
3910 info8.monitor_name);
3911 if (!W_ERROR_IS_OK(result)) {
3915 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3916 &key_hnd, "Datatype",
3917 info8.default_datatype);
3918 if (!W_ERROR_IS_OK(result)) {
3922 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3923 &key_hnd, "Previous Names",
3924 info8.previous_names);
3925 if (!W_ERROR_IS_OK(result)) {
3929 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3930 &key_hnd, "DriverDate",
3932 if (!W_ERROR_IS_OK(result)) {
3936 result = winreg_printer_write_ver(tmp_ctx, winreg_handle,
3937 &key_hnd, "DriverVersion",
3938 info8.driver_version);
3939 if (!W_ERROR_IS_OK(result)) {
3943 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3944 &key_hnd, "Manufacturer",
3945 info8.manufacturer_name);
3946 if (!W_ERROR_IS_OK(result)) {
3950 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3951 &key_hnd, "OEM URL",
3952 info8.manufacturer_url);
3953 if (!W_ERROR_IS_OK(result)) {
3957 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3958 &key_hnd, "HardwareID",
3960 if (!W_ERROR_IS_OK(result)) {
3964 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3965 &key_hnd, "Provider",
3967 if (!W_ERROR_IS_OK(result)) {
3971 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3972 &key_hnd, "Print Processor",
3973 info8.print_processor);
3974 if (!W_ERROR_IS_OK(result)) {
3978 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3979 &key_hnd, "VendorSetup",
3980 info8.vendor_setup);
3981 if (!W_ERROR_IS_OK(result)) {
3985 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3986 &key_hnd, "Color Profiles",
3987 info8.color_profiles);
3988 if (!W_ERROR_IS_OK(result)) {
3992 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3993 &key_hnd, "InfPath",
3995 if (!W_ERROR_IS_OK(result)) {
3999 result = winreg_printer_write_dword(tmp_ctx, winreg_handle, &key_hnd,
4000 "PrinterDriverAttributes",
4001 info8.printer_driver_attributes);
4002 if (!W_ERROR_IS_OK(result)) {
4006 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
4007 &key_hnd, "CoreDependencies",
4008 info8.core_driver_dependencies);
4009 if (!W_ERROR_IS_OK(result)) {
4013 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
4014 &key_hnd, "MinInboxDriverVerDate",
4015 info8.min_inbox_driver_ver_date);
4016 if (!W_ERROR_IS_OK(result)) {
4020 result = winreg_printer_write_ver(tmp_ctx, winreg_handle, &key_hnd,
4021 "MinInboxDriverVerVersion",
4022 info8.min_inbox_driver_ver_version);
4023 if (!W_ERROR_IS_OK(result)) {
4027 *driver_name = info8.driver_name;
4028 *driver_version = info8.version;
4031 if (winreg_handle != NULL) {
4034 if (is_valid_policy_hnd(&key_hnd)) {
4035 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4037 if (is_valid_policy_hnd(&hive_hnd)) {
4038 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4042 TALLOC_FREE(tmp_ctx);
4046 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
4047 const struct auth_serversupplied_info *server_info,
4048 struct messaging_context *msg_ctx,
4049 const char *architecture,
4050 const char *driver_name,
4051 uint32_t driver_version,
4052 struct spoolss_DriverInfo8 **_info8)
4054 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4055 struct dcerpc_binding_handle *winreg_handle = NULL;
4056 struct policy_handle hive_hnd, key_hnd;
4057 struct spoolss_DriverInfo8 i8, *info8;
4058 struct spoolss_PrinterEnumValues *enum_values = NULL;
4059 struct spoolss_PrinterEnumValues *v;
4060 uint32_t num_values = 0;
4061 TALLOC_CTX *tmp_ctx;
4065 ZERO_STRUCT(hive_hnd);
4066 ZERO_STRUCT(key_hnd);
4069 tmp_ctx = talloc_stackframe();
4070 if (tmp_ctx == NULL) {
4074 if (driver_version == DRIVER_ANY_VERSION) {
4075 /* look for Win2k first and then for NT4 */
4076 result = winreg_printer_opendriver(tmp_ctx,
4086 if (!W_ERROR_IS_OK(result)) {
4087 result = winreg_printer_opendriver(tmp_ctx,
4099 /* ok normal case */
4100 result = winreg_printer_opendriver(tmp_ctx,
4111 if (!W_ERROR_IS_OK(result)) {
4112 DEBUG(5, ("winreg_get_driver: "
4113 "Could not open driver key (%s,%s,%d): %s\n",
4114 driver_name, architecture,
4115 driver_version, win_errstr(result)));
4119 result = winreg_printer_enumvalues(tmp_ctx,
4124 if (!W_ERROR_IS_OK(result)) {
4125 DEBUG(0, ("winreg_get_driver: "
4126 "Could not enumerate values for (%s,%s,%d): %s\n",
4127 driver_name, architecture,
4128 driver_version, win_errstr(result)));
4132 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
4133 if (info8 == NULL) {
4134 result = WERR_NOMEM;
4138 info8->driver_name = talloc_strdup(info8, driver_name);
4139 if (info8->driver_name == NULL) {
4140 result = WERR_NOMEM;
4144 info8->architecture = talloc_strdup(info8, architecture);
4145 if (info8->architecture == NULL) {
4146 result = WERR_NOMEM;
4152 for (i = 0; i < num_values; i++) {
4153 const char *tmp_str;
4156 v = &enum_values[i];
4158 result = winreg_enumval_to_dword(info8, v,
4161 if (NT_STATUS_IS_OK(result)) {
4162 info8->version = (enum spoolss_DriverOSVersion) tmp;
4164 CHECK_ERROR(result);
4166 result = winreg_enumval_to_sz(info8, v,
4168 &info8->driver_path);
4169 CHECK_ERROR(result);
4171 result = winreg_enumval_to_sz(info8, v,
4174 CHECK_ERROR(result);
4176 result = winreg_enumval_to_sz(info8, v,
4177 "Configuration File",
4178 &info8->config_file);
4179 CHECK_ERROR(result);
4181 result = winreg_enumval_to_sz(info8, v,
4184 CHECK_ERROR(result);
4186 result = winreg_enumval_to_multi_sz(info8, v,
4188 &info8->dependent_files);
4189 CHECK_ERROR(result);
4191 result = winreg_enumval_to_sz(info8, v,
4193 &info8->monitor_name);
4194 CHECK_ERROR(result);
4196 result = winreg_enumval_to_sz(info8, v,
4198 &info8->default_datatype);
4199 CHECK_ERROR(result);
4201 result = winreg_enumval_to_multi_sz(info8, v,
4203 &info8->previous_names);
4204 CHECK_ERROR(result);
4206 result = winreg_enumval_to_sz(info8, v,
4209 if (W_ERROR_IS_OK(result)) {
4210 result = winreg_printer_date_to_NTTIME(tmp_str,
4211 &info8->driver_date);
4213 CHECK_ERROR(result);
4215 result = winreg_enumval_to_sz(info8, v,
4218 if (W_ERROR_IS_OK(result)) {
4219 result = winreg_printer_ver_to_dword(tmp_str,
4220 &info8->driver_version);
4222 CHECK_ERROR(result);
4224 result = winreg_enumval_to_sz(info8, v,
4226 &info8->manufacturer_name);
4227 CHECK_ERROR(result);
4229 result = winreg_enumval_to_sz(info8, v,
4231 &info8->manufacturer_url);
4232 CHECK_ERROR(result);
4234 result = winreg_enumval_to_sz(info8, v,
4236 &info8->hardware_id);
4237 CHECK_ERROR(result);
4239 result = winreg_enumval_to_sz(info8, v,
4242 CHECK_ERROR(result);
4244 result = winreg_enumval_to_sz(info8, v,
4246 &info8->print_processor);
4247 CHECK_ERROR(result);
4249 result = winreg_enumval_to_sz(info8, v,
4251 &info8->vendor_setup);
4252 CHECK_ERROR(result);
4254 result = winreg_enumval_to_multi_sz(info8, v,
4256 &info8->color_profiles);
4257 CHECK_ERROR(result);
4259 result = winreg_enumval_to_sz(info8, v,
4262 CHECK_ERROR(result);
4264 result = winreg_enumval_to_dword(info8, v,
4265 "PrinterDriverAttributes",
4266 &info8->printer_driver_attributes);
4267 CHECK_ERROR(result);
4269 result = winreg_enumval_to_multi_sz(info8, v,
4271 &info8->core_driver_dependencies);
4272 CHECK_ERROR(result);
4274 result = winreg_enumval_to_sz(info8, v,
4275 "MinInboxDriverVerDate",
4277 if (W_ERROR_IS_OK(result)) {
4278 result = winreg_printer_date_to_NTTIME(tmp_str,
4279 &info8->min_inbox_driver_ver_date);
4281 CHECK_ERROR(result);
4283 result = winreg_enumval_to_sz(info8, v,
4284 "MinInboxDriverVerVersion",
4286 if (W_ERROR_IS_OK(result)) {
4287 result = winreg_printer_ver_to_dword(tmp_str,
4288 &info8->min_inbox_driver_ver_version);
4290 CHECK_ERROR(result);
4293 if (!W_ERROR_IS_OK(result)) {
4294 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4295 "for %s: %s\n", v->value_name,
4296 win_errstr(result)));
4300 *_info8 = talloc_steal(mem_ctx, info8);
4303 if (winreg_handle != NULL) {
4306 if (is_valid_policy_hnd(&key_hnd)) {
4307 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4309 if (is_valid_policy_hnd(&hive_hnd)) {
4310 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4314 TALLOC_FREE(tmp_ctx);
4318 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
4319 const struct auth_serversupplied_info *server_info,
4320 struct messaging_context *msg_ctx,
4321 struct spoolss_DriverInfo8 *info8,
4324 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4325 struct dcerpc_binding_handle *winreg_handle = NULL;
4326 struct policy_handle hive_hnd, key_hnd;
4327 TALLOC_CTX *tmp_ctx;
4331 ZERO_STRUCT(hive_hnd);
4332 ZERO_STRUCT(key_hnd);
4334 tmp_ctx = talloc_stackframe();
4335 if (tmp_ctx == NULL) {
4339 /* test that the key exists */
4340 result = winreg_printer_opendriver(tmp_ctx,
4344 info8->architecture,
4350 if (!W_ERROR_IS_OK(result)) {
4351 /* key doesn't exist */
4352 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
4357 DEBUG(5, ("winreg_del_driver: "
4358 "Could not open driver (%s,%s,%u): %s\n",
4359 info8->driver_name, info8->architecture,
4360 version, win_errstr(result)));
4365 if (is_valid_policy_hnd(&key_hnd)) {
4366 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
4369 key_name = talloc_asprintf(tmp_ctx,
4370 "%s\\Environments\\%s\\Drivers\\Version-%u",
4371 TOP_LEVEL_CONTROL_KEY,
4372 info8->architecture, version);
4373 if (key_name == NULL) {
4374 result = WERR_NOMEM;
4378 result = winreg_printer_delete_subkeys(tmp_ctx,
4383 if (!W_ERROR_IS_OK(result)) {
4384 DEBUG(0, ("winreg_del_driver: "
4385 "Could not open driver (%s,%s,%u): %s\n",
4386 info8->driver_name, info8->architecture,
4387 version, win_errstr(result)));
4393 if (winreg_handle != NULL) {
4396 if (is_valid_policy_hnd(&key_hnd)) {
4397 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4399 if (is_valid_policy_hnd(&hive_hnd)) {
4400 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4404 TALLOC_FREE(tmp_ctx);
4408 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
4409 const struct auth_serversupplied_info *server_info,
4410 struct messaging_context *msg_ctx,
4411 const char *architecture,
4413 uint32_t *num_drivers,
4414 const char ***drivers_p)
4416 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4417 struct dcerpc_binding_handle *winreg_handle = NULL;
4418 struct policy_handle hive_hnd, key_hnd;
4419 const char **drivers;
4420 TALLOC_CTX *tmp_ctx;
4426 ZERO_STRUCT(hive_hnd);
4427 ZERO_STRUCT(key_hnd);
4429 tmp_ctx = talloc_stackframe();
4430 if (tmp_ctx == NULL) {
4434 /* use NULL for the driver name so we open the key that is
4435 * parent of all drivers for this architecture and version */
4436 result = winreg_printer_opendriver(tmp_ctx,
4446 if (!W_ERROR_IS_OK(result)) {
4447 DEBUG(5, ("winreg_get_driver_list: "
4448 "Could not open key (%s,%u): %s\n",
4449 architecture, version, win_errstr(result)));
4454 result = winreg_printer_enumkeys(tmp_ctx,
4459 if (!W_ERROR_IS_OK(result)) {
4460 DEBUG(0, ("winreg_get_driver_list: "
4461 "Could not enumerate drivers for (%s,%u): %s\n",
4462 architecture, version, win_errstr(result)));
4466 *drivers_p = talloc_steal(mem_ctx, drivers);
4470 if (winreg_handle != NULL) {
4473 if (is_valid_policy_hnd(&key_hnd)) {
4474 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4476 if (is_valid_policy_hnd(&hive_hnd)) {
4477 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4481 TALLOC_FREE(tmp_ctx);