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"
31 #include "../libcli/security/dom_sid.h"
33 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
34 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
35 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
36 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
38 #define EMPTY_STRING ""
40 #define FILL_STRING(mem_ctx, in, out) \
42 if (in && strlen(in)) { \
43 out = talloc_strdup(mem_ctx, in); \
45 out = talloc_strdup(mem_ctx, ""); \
47 W_ERROR_HAVE_NO_MEMORY(out); \
50 #define CHECK_ERROR(result) \
51 if (W_ERROR_IS_OK(result)) continue; \
52 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
53 if (!W_ERROR_IS_OK(result)) break
55 /* FLAGS, NAME, with, height, left, top, right, bottom */
56 static const struct spoolss_FormInfo1 builtin_forms1[] = {
57 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
58 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
59 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
60 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
61 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
62 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
63 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
64 { SPOOLSS_FORM_BUILTIN, "A0", {0xcd528,0x122488},{0x0,0x0,0xcd528,0x122488} },
65 { SPOOLSS_FORM_BUILTIN, "A1", {0x91050,0xcd528}, {0x0,0x0,0x91050,0xcd528} },
66 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
67 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
68 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
69 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
70 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
71 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
72 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
73 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
74 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
75 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
76 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
77 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
78 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
79 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
80 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
81 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
82 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
83 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
84 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
85 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
86 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
87 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
88 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
89 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
90 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
91 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
92 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
93 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
94 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
95 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
96 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
97 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
98 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
99 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
100 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
101 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
102 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
103 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
104 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
105 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
106 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
107 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
108 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
109 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
110 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
111 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
112 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
113 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
114 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
115 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
116 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
117 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
118 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
119 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
120 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
121 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
122 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
123 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
124 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
125 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
126 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
127 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
128 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
129 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
130 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
131 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
132 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
133 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
134 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
135 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
136 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
137 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
138 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
139 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
140 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
141 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
142 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
143 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
144 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
145 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
146 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
147 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
148 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
149 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
150 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} },
151 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
152 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
153 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
154 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
159 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
160 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
161 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
162 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
163 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
164 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
165 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
166 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
167 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
168 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
169 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
170 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
171 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
172 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
173 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
174 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
175 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
176 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} }
179 /********************************************************************
180 static helper functions
181 ********************************************************************/
183 /****************************************************************************
184 Update the changeid time.
185 ****************************************************************************/
189 * @brief Update the ChangeID time of a printer.
191 * This is SO NASTY as some drivers need this to change, others need it
192 * static. This value will change every second, and I must hope that this
193 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
196 * @return The ChangeID.
198 static uint32_t winreg_printer_rev_changeid(void)
202 get_process_uptime(&tv);
205 /* Return changeid as msec since spooler restart */
206 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
209 * This setting seems to work well but is too untested
210 * to replace the above calculation. Left in for experiementation
211 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
213 return tv.tv_sec * 10 + tv.tv_usec / 100000;
220 * @brief Connect to the interal winreg server and open the given printer key.
222 * The function will create the needed subkeys if they don't exist.
224 * @param[in] mem_ctx The memory context to use.
226 * @param[in] server_info The supplied server info.
228 * @param[out] binding_handle A pointer for the winreg dcerpc binding handle.
230 * @param[in] path The path to the key to open.
232 * @param[in] key The key to open.
234 * @param[in] create_key Set to true if the key should be created if it
237 * @param[in] access_mask The access mask to open the key.
239 * @param[out] hive_handle A policy handle for the opened hive.
241 * @param[out] key_handle A policy handle for the opened key.
243 * @return WERR_OK on success, the corresponding DOS error
244 * code if something gone wrong.
246 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
247 const struct auth_serversupplied_info *server_info,
248 struct messaging_context *msg_ctx,
249 struct dcerpc_binding_handle **winreg_binding_handle,
253 uint32_t access_mask,
254 struct policy_handle *hive_handle,
255 struct policy_handle *key_handle)
257 static struct client_address client_id;
258 struct dcerpc_binding_handle *binding_handle;
259 struct winreg_String wkey, wkeyclass;
262 WERROR result = WERR_OK;
264 strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
265 client_id.name = "127.0.0.1";
267 status = rpcint_binding_handle(mem_ctx,
273 if (!NT_STATUS_IS_OK(status)) {
274 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg pipe: %s\n",
276 return ntstatus_to_werror(status);
279 status = dcerpc_winreg_OpenHKLM(binding_handle,
285 if (!NT_STATUS_IS_OK(status)) {
286 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
288 talloc_free(binding_handle);
289 return ntstatus_to_werror(status);
291 if (!W_ERROR_IS_OK(result)) {
292 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
293 win_errstr(result)));
294 talloc_free(binding_handle);
299 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
301 keyname = talloc_strdup(mem_ctx, path);
303 if (keyname == NULL) {
304 talloc_free(binding_handle);
312 enum winreg_CreateAction action = REG_ACTION_NONE;
314 ZERO_STRUCT(wkeyclass);
317 status = dcerpc_winreg_CreateKey(binding_handle,
329 case REG_ACTION_NONE:
330 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
332 case REG_CREATED_NEW_KEY:
333 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
335 case REG_OPENED_EXISTING_KEY:
336 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
340 status = dcerpc_winreg_OpenKey(binding_handle,
349 if (!NT_STATUS_IS_OK(status)) {
350 talloc_free(binding_handle);
351 return ntstatus_to_werror(status);
353 if (!W_ERROR_IS_OK(result)) {
354 talloc_free(binding_handle);
358 *winreg_binding_handle = binding_handle;
364 * @brief Create the registry keyname for the given printer.
366 * @param[in] mem_ctx The memory context to use.
368 * @param[in] printer The name of the printer to get the registry key.
370 * @return The registry key or NULL on error.
372 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
373 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
379 * @brief Enumerate values of an opened key handle and retrieve the data.
381 * @param[in] mem_ctx The memory context to use.
383 * @param[in] winreg_handle The binding handle for the rpc connection.
385 * @param[in] key_hnd The opened key handle.
387 * @param[out] pnum_values A pointer to store he number of values found.
389 * @param[out] pnum_values A pointer to store the number of values we found.
391 * @return WERR_OK on success, the corresponding DOS error
392 * code if something gone wrong.
394 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
395 struct dcerpc_binding_handle *winreg_handle,
396 struct policy_handle *key_hnd,
397 uint32_t *pnum_values,
398 struct spoolss_PrinterEnumValues **penum_values)
401 uint32_t num_subkeys, max_subkeylen, max_classlen;
402 uint32_t num_values, max_valnamelen, max_valbufsize;
403 uint32_t secdescsize;
405 NTTIME last_changed_time;
406 struct winreg_String classname;
408 struct spoolss_PrinterEnumValues *enum_values;
410 WERROR result = WERR_OK;
413 tmp_ctx = talloc_stackframe();
414 if (tmp_ctx == NULL) {
418 ZERO_STRUCT(classname);
420 status = dcerpc_winreg_QueryInfoKey(winreg_handle,
433 if (!NT_STATUS_IS_OK(status)) {
434 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
436 result = ntstatus_to_werror(status);
439 if (!W_ERROR_IS_OK(result)) {
440 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
441 win_errstr(result)));
445 if (num_values == 0) {
447 TALLOC_FREE(tmp_ctx);
451 enum_values = TALLOC_ARRAY(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
452 if (enum_values == NULL) {
457 for (i = 0; i < num_values; i++) {
458 struct spoolss_PrinterEnumValues val;
459 struct winreg_ValNameBuf name_buf;
460 enum winreg_Type type = REG_NONE;
467 name_buf.size = max_valnamelen + 2;
470 data_size = max_valbufsize;
473 data = (uint8_t *) TALLOC(tmp_ctx, data_size);
477 status = dcerpc_winreg_EnumValue(winreg_handle,
484 data_size ? &data_size : NULL,
487 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
489 status = NT_STATUS_OK;
493 if (!NT_STATUS_IS_OK(status)) {
494 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
496 result = ntstatus_to_werror(status);
499 if (!W_ERROR_IS_OK(result)) {
500 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
501 win_errstr(result)));
505 if (name_buf.name == NULL) {
506 result = WERR_INVALID_PARAMETER;
510 val.value_name = talloc_strdup(enum_values, name_buf.name);
511 if (val.value_name == NULL) {
515 val.value_name_len = strlen_m_term(val.value_name) * 2;
518 val.data_length = length;
520 if (val.data_length) {
521 val.data = talloc(enum_values, DATA_BLOB);
522 if (val.data == NULL) {
526 *val.data = data_blob_talloc(val.data, data, val.data_length);
529 enum_values[i] = val;
532 *pnum_values = num_values;
534 *penum_values = talloc_move(mem_ctx, &enum_values);
540 TALLOC_FREE(tmp_ctx);
547 * @brief Enumerate subkeys of an opened key handle and get the names.
549 * @param[in] mem_ctx The memory context to use.
551 * @param[in] winreg_handle The binding handle for the rpc connection.
553 * @param[in] key_hnd The opened key handle.
555 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
557 * @param[in] psubkeys A pointer to an array to store the found names of
560 * @return WERR_OK on success, the corresponding DOS error
561 * code if something gone wrong.
563 static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
564 struct dcerpc_binding_handle *winreg_handle,
565 struct policy_handle *key_hnd,
566 uint32_t *pnum_subkeys,
567 const char ***psubkeys)
570 const char **subkeys;
571 uint32_t num_subkeys, max_subkeylen, max_classlen;
572 uint32_t num_values, max_valnamelen, max_valbufsize;
574 NTTIME last_changed_time;
575 uint32_t secdescsize;
576 struct winreg_String classname;
577 WERROR result = WERR_OK;
580 tmp_ctx = talloc_stackframe();
581 if (tmp_ctx == NULL) {
585 ZERO_STRUCT(classname);
587 status = dcerpc_winreg_QueryInfoKey(winreg_handle,
600 if (!NT_STATUS_IS_OK(status)) {
601 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
603 result = ntstatus_to_werror(status);
606 if (!W_ERROR_IS_OK(result)) {
607 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
608 win_errstr(result)));
612 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
613 if (subkeys == NULL) {
618 if (num_subkeys == 0) {
619 subkeys[0] = talloc_strdup(subkeys, "");
620 if (subkeys[0] == NULL) {
626 *psubkeys = talloc_move(mem_ctx, &subkeys);
629 TALLOC_FREE(tmp_ctx);
633 for (i = 0; i < num_subkeys; i++) {
637 struct winreg_StringBuf class_buf;
638 struct winreg_StringBuf name_buf;
642 class_buf.size = max_classlen + 2;
643 class_buf.length = 0;
646 name_buf.size = max_subkeylen + 2;
649 ZERO_STRUCT(modtime);
651 status = dcerpc_winreg_EnumKey(winreg_handle,
659 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
661 status = NT_STATUS_OK;
665 if (!NT_STATUS_IS_OK(status)) {
666 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
668 result = ntstatus_to_werror(status);
671 if (!W_ERROR_IS_OK(result)) {
672 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
673 win_errstr(result)));
677 if (name_buf.name == NULL) {
678 result = WERR_INVALID_PARAMETER;
682 name = talloc_strdup(subkeys, name_buf.name);
691 *pnum_subkeys = num_subkeys;
693 *psubkeys = talloc_move(mem_ctx, &subkeys);
697 TALLOC_FREE(tmp_ctx);
704 * @brief A function to delete a key and its subkeys recurively.
706 * @param[in] mem_ctx The memory context to use.
708 * @param[in] winreg_handle The binding handle for the rpc connection.
710 * @param[in] hive_handle A opened hive handle to the key.
712 * @param[in] access_mask The access mask to access the key.
714 * @param[in] key The key to delete
716 * @return WERR_OK on success, the corresponding DOS error
717 * code if something gone wrong.
719 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
720 struct dcerpc_binding_handle *winreg_handle,
721 struct policy_handle *hive_handle,
722 uint32_t access_mask,
725 const char **subkeys = NULL;
726 uint32_t num_subkeys = 0;
727 struct policy_handle key_hnd;
728 struct winreg_String wkey;
729 WERROR result = WERR_OK;
733 ZERO_STRUCT(key_hnd);
736 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
738 status = dcerpc_winreg_OpenKey(winreg_handle,
746 if (!NT_STATUS_IS_OK(status)) {
747 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
748 wkey.name, nt_errstr(status)));
749 return ntstatus_to_werror(status);
751 if (!W_ERROR_IS_OK(result)) {
752 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
753 wkey.name, win_errstr(result)));
757 result = winreg_printer_enumkeys(mem_ctx,
762 if (!W_ERROR_IS_OK(result)) {
766 for (i = 0; i < num_subkeys; i++) {
767 /* create key + subkey */
768 char *subkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkeys[i]);
769 if (subkey == NULL) {
773 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey));
774 result = winreg_printer_delete_subkeys(mem_ctx,
779 if (!W_ERROR_IS_OK(result)) {
784 if (is_valid_policy_hnd(&key_hnd)) {
786 dcerpc_winreg_CloseKey(winreg_handle, mem_ctx, &key_hnd, &ignore);
791 status = dcerpc_winreg_DeleteKey(winreg_handle,
796 if (!NT_STATUS_IS_OK(status)) {
797 result = ntstatus_to_werror(status);
801 if (is_valid_policy_hnd(&key_hnd)) {
804 dcerpc_winreg_CloseKey(winreg_handle, mem_ctx, &key_hnd, &ignore);
810 static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
811 struct dcerpc_binding_handle *winreg_handle,
812 struct policy_handle *key_handle,
816 struct winreg_String wvalue;
818 WERROR result = WERR_OK;
823 blob = data_blob_string_const("");
825 if (!push_reg_sz(mem_ctx, &blob, data)) {
826 DEBUG(0, ("winreg_printer_write_sz: Could not marshall string %s for %s\n",
831 status = dcerpc_winreg_SetValue(winreg_handle,
839 if (!NT_STATUS_IS_OK(status)) {
840 result = ntstatus_to_werror(status);
842 if (!W_ERROR_IS_OK(result)) {
843 DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: %s\n",
844 wvalue.name, win_errstr(result)));
850 static WERROR winreg_printer_write_dword(TALLOC_CTX *mem_ctx,
851 struct dcerpc_binding_handle *winreg_handle,
852 struct policy_handle *key_handle,
856 struct winreg_String wvalue;
858 WERROR result = WERR_OK;
862 blob = data_blob_talloc(mem_ctx, NULL, 4);
863 SIVAL(blob.data, 0, data);
865 status = dcerpc_winreg_SetValue(winreg_handle,
873 if (!NT_STATUS_IS_OK(status)) {
874 result = ntstatus_to_werror(status);
876 if (!W_ERROR_IS_OK(result)) {
877 DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: %s\n",
878 wvalue.name, win_errstr(result)));
884 static WERROR winreg_printer_write_binary(TALLOC_CTX *mem_ctx,
885 struct dcerpc_binding_handle *winreg_handle,
886 struct policy_handle *key_handle,
890 struct winreg_String wvalue;
891 WERROR result = WERR_OK;
895 status = dcerpc_winreg_SetValue(winreg_handle,
903 if (!NT_STATUS_IS_OK(status)) {
904 result = ntstatus_to_werror(status);
906 if (!W_ERROR_IS_OK(result)) {
907 DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: %s\n",
908 wvalue.name, win_errstr(result)));
914 static WERROR winreg_printer_query_binary(TALLOC_CTX *mem_ctx,
915 struct dcerpc_binding_handle *winreg_handle,
916 struct policy_handle *key_handle,
920 struct winreg_String wvalue;
921 enum winreg_Type type;
922 WERROR result = WERR_OK;
923 uint32_t value_len = 0;
924 uint32_t data_size = 0;
929 status = dcerpc_winreg_QueryValue(winreg_handle,
938 if (!NT_STATUS_IS_OK(status)) {
939 result = ntstatus_to_werror(status);
941 if (!W_ERROR_IS_OK(result)) {
942 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
943 wvalue.name, win_errstr(result)));
947 if (type != REG_BINARY) {
948 result = WERR_INVALID_DATATYPE;
951 blob = data_blob_talloc(mem_ctx, NULL, data_size);
952 if (blob.data == NULL) {
958 status = dcerpc_winreg_QueryValue(winreg_handle,
967 if (!NT_STATUS_IS_OK(status)) {
968 result = ntstatus_to_werror(status);
970 if (!W_ERROR_IS_OK(result)) {
971 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
972 wvalue.name, win_errstr(result)));
977 data->data = blob.data;
978 data->length = blob.length;
984 static WERROR winreg_printer_query_dword(TALLOC_CTX *mem_ctx,
985 struct dcerpc_binding_handle *winreg_handle,
986 struct policy_handle *key_handle,
990 struct winreg_String wvalue;
991 enum winreg_Type type;
992 WERROR result = WERR_OK;
993 uint32_t value_len = 0;
994 uint32_t data_size = 0;
999 status = dcerpc_winreg_QueryValue(winreg_handle,
1008 if (!NT_STATUS_IS_OK(status)) {
1009 result = ntstatus_to_werror(status);
1011 if (!W_ERROR_IS_OK(result)) {
1012 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1013 wvalue.name, win_errstr(result)));
1017 if (type != REG_DWORD) {
1018 result = WERR_INVALID_DATATYPE;
1022 if (data_size != 4) {
1023 result = WERR_INVALID_DATA;
1027 blob = data_blob_talloc(mem_ctx, NULL, data_size);
1028 if (blob.data == NULL) {
1029 result = WERR_NOMEM;
1034 status = dcerpc_winreg_QueryValue(winreg_handle,
1043 if (!NT_STATUS_IS_OK(status)) {
1044 result = ntstatus_to_werror(status);
1046 if (!W_ERROR_IS_OK(result)) {
1047 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1048 wvalue.name, win_errstr(result)));
1053 *data = IVAL(blob.data, 0);
1059 static WERROR winreg_printer_write_multi_sz(TALLOC_CTX *mem_ctx,
1060 struct dcerpc_binding_handle *winreg_handle,
1061 struct policy_handle *key_handle,
1065 struct winreg_String wvalue;
1067 WERROR result = WERR_OK;
1070 wvalue.name = value;
1071 if (!push_reg_multi_sz(mem_ctx, &blob, data)) {
1074 status = dcerpc_winreg_SetValue(winreg_handle,
1082 if (!NT_STATUS_IS_OK(status)) {
1083 result = ntstatus_to_werror(status);
1085 if (!W_ERROR_IS_OK(result)) {
1086 DEBUG(0, ("winreg_printer_write_multi_sz: Could not set value %s: %s\n",
1087 wvalue.name, win_errstr(result)));
1093 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
1094 const struct auth_serversupplied_info *server_info,
1095 struct messaging_context *msg_ctx,
1096 const char *drivername,
1097 const char *architecture,
1099 uint32_t access_mask,
1101 struct dcerpc_binding_handle **winreg_binding_handle,
1102 struct policy_handle *hive_hnd,
1103 struct policy_handle *key_hnd)
1108 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
1109 TOP_LEVEL_CONTROL_KEY,
1110 architecture, version);
1115 result = winreg_printer_openkey(mem_ctx,
1118 winreg_binding_handle,
1128 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
1129 struct spoolss_PrinterEnumValues *v,
1130 const char *valuename, uint32_t *dw)
1132 /* just return if it is not the one we are looking for */
1133 if (strcmp(valuename, v->value_name) != 0) {
1134 return WERR_NOT_FOUND;
1137 if (v->type != REG_DWORD) {
1138 return WERR_INVALID_DATATYPE;
1141 if (v->data_length != 4) {
1146 *dw = IVAL(v->data->data, 0);
1150 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
1151 struct spoolss_PrinterEnumValues *v,
1152 const char *valuename, const char **_str)
1154 /* just return if it is not the one we are looking for */
1155 if (strcmp(valuename, v->value_name) != 0) {
1156 return WERR_NOT_FOUND;
1159 if (v->type != REG_SZ) {
1160 return WERR_INVALID_DATATYPE;
1163 if (v->data_length == 0) {
1164 *_str = talloc_strdup(mem_ctx, EMPTY_STRING);
1165 if (*_str == NULL) {
1171 if (!pull_reg_sz(mem_ctx, v->data, _str)) {
1178 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
1179 struct spoolss_PrinterEnumValues *v,
1180 const char *valuename,
1181 const char ***array)
1183 /* just return if it is not the one we are looking for */
1184 if (strcmp(valuename, v->value_name) != 0) {
1185 return WERR_NOT_FOUND;
1188 if (v->type != REG_MULTI_SZ) {
1189 return WERR_INVALID_DATATYPE;
1192 if (v->data_length == 0) {
1193 *array = talloc_array(mem_ctx, const char *, 1);
1194 if (*array == NULL) {
1201 if (!pull_reg_multi_sz(mem_ctx, v->data, array)) {
1208 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
1209 struct dcerpc_binding_handle *winreg_handle,
1210 struct policy_handle *key_handle,
1214 struct winreg_String wvalue;
1216 WERROR result = WERR_OK;
1222 t = nt_time_to_unix(data);
1224 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
1225 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
1230 wvalue.name = value;
1231 if (!push_reg_sz(mem_ctx, &blob, str)) {
1234 status = dcerpc_winreg_SetValue(winreg_handle,
1242 if (!NT_STATUS_IS_OK(status)) {
1243 result = ntstatus_to_werror(status);
1245 if (!W_ERROR_IS_OK(result)) {
1246 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1247 wvalue.name, win_errstr(result)));
1253 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
1260 if (sscanf(str, "%d/%d/%d",
1261 &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3) {
1262 return WERR_INVALID_PARAMETER;
1269 unix_to_nt_time(data, t);
1274 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
1275 struct dcerpc_binding_handle *winreg_handle,
1276 struct policy_handle *key_handle,
1280 struct winreg_String wvalue;
1282 WERROR result = WERR_OK;
1286 /* FIXME: check format is right,
1287 * this needs to be something like: 6.1.7600.16385 */
1288 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
1289 (unsigned)((data >> 48) & 0xFFFF),
1290 (unsigned)((data >> 32) & 0xFFFF),
1291 (unsigned)((data >> 16) & 0xFFFF),
1292 (unsigned)(data & 0xFFFF));
1297 wvalue.name = value;
1298 if (!push_reg_sz(mem_ctx, &blob, str)) {
1301 status = dcerpc_winreg_SetValue(winreg_handle,
1309 if (!NT_STATUS_IS_OK(status)) {
1310 result = ntstatus_to_werror(status);
1312 if (!W_ERROR_IS_OK(result)) {
1313 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1314 wvalue.name, win_errstr(result)));
1320 static WERROR winreg_printer_ver_to_dword(const char *str, uint64_t *data)
1322 unsigned int v1, v2, v3, v4;
1324 if (sscanf(str, "%u.%u.%u.%u", &v1, &v2, &v3, &v4) != 4) {
1325 return WERR_INVALID_PARAMETER;
1328 *data = ((uint64_t)(v1 & 0xFFFF) << 48) +
1329 ((uint64_t)(v2 & 0xFFFF) << 32) +
1330 ((uint64_t)(v3 & 0xFFFF) << 16) +
1331 (uint64_t)(v2 & 0xFFFF);
1336 /********************************************************************
1337 Public winreg function for spoolss
1338 ********************************************************************/
1340 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
1341 const struct auth_serversupplied_info *server_info,
1342 struct messaging_context *msg_ctx,
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 info2->printername = sharename;
1575 if (info2->printername == NULL) {
1576 result = WERR_NOMEM;
1579 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1581 info2->sharename = sharename;
1582 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1584 info2->portname = SAMBA_PRINTER_PORT_NAME;
1585 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1587 info2->printprocessor = "winprint";
1588 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1590 info2->datatype = "RAW";
1591 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1593 info2->comment = "";
1594 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1596 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1597 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1599 info2->starttime = 0; /* Minutes since 12:00am GMT */
1600 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1602 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1603 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1605 info2->priority = 1;
1606 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1608 info2->defaultpriority = 1;
1609 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1611 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1612 if (!W_ERROR_IS_OK(result)) {
1615 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1618 * Don't write a default Device Mode to the registry! The Device Mode is
1619 * only written to disk with a SetPrinter level 2 or 8.
1622 result = winreg_update_printer(tmp_ctx,
1632 if (winreg_handle != NULL) {
1635 if (is_valid_policy_hnd(&key_hnd)) {
1636 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1638 if (is_valid_policy_hnd(&hive_hnd)) {
1639 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1643 talloc_free(tmp_ctx);
1647 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1648 const struct auth_serversupplied_info *server_info,
1649 struct messaging_context *msg_ctx,
1650 const char *sharename,
1651 uint32_t info2_mask,
1652 struct spoolss_SetPrinterInfo2 *info2,
1653 struct spoolss_DeviceMode *devmode,
1654 struct security_descriptor *secdesc)
1656 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1657 struct dcerpc_binding_handle *winreg_handle = NULL;
1658 struct policy_handle hive_hnd, key_hnd;
1659 int snum = lp_servicenumber(sharename);
1660 enum ndr_err_code ndr_err;
1663 WERROR result = WERR_OK;
1664 TALLOC_CTX *tmp_ctx;
1666 tmp_ctx = talloc_stackframe();
1667 if (tmp_ctx == NULL) {
1671 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1673 TALLOC_FREE(tmp_ctx);
1677 ZERO_STRUCT(hive_hnd);
1678 ZERO_STRUCT(key_hnd);
1680 result = winreg_printer_openkey(tmp_ctx,
1690 if (!W_ERROR_IS_OK(result)) {
1691 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1692 path, win_errstr(result)));
1696 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1697 result = winreg_printer_write_dword(tmp_ctx,
1702 if (!W_ERROR_IS_OK(result)) {
1708 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1709 result = winreg_printer_write_dword(tmp_ctx,
1714 if (!W_ERROR_IS_OK(result)) {
1720 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1721 result = winreg_printer_write_sz(tmp_ctx,
1726 if (!W_ERROR_IS_OK(result)) {
1731 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1732 result = winreg_printer_write_sz(tmp_ctx,
1737 if (!W_ERROR_IS_OK(result)) {
1742 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1743 result = winreg_printer_write_dword(tmp_ctx,
1747 info2->defaultpriority);
1748 if (!W_ERROR_IS_OK(result)) {
1753 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1755 * Some client drivers freak out if there is a NULL devmode
1756 * (probably the driver is not checking before accessing
1757 * the devmode pointer) --jerry
1759 if (devmode == NULL && lp_default_devmode(snum) && info2 != NULL) {
1760 result = spoolss_create_default_devmode(tmp_ctx,
1763 if (!W_ERROR_IS_OK(result)) {
1767 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, devmode,
1768 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1769 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1770 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1771 result = WERR_NOMEM;
1775 result = winreg_printer_write_binary(tmp_ctx,
1780 if (!W_ERROR_IS_OK(result)) {
1785 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1786 result = winreg_printer_write_sz(tmp_ctx,
1791 if (!W_ERROR_IS_OK(result)) {
1796 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1797 result = winreg_printer_write_sz(tmp_ctx,
1802 if (!W_ERROR_IS_OK(result)) {
1807 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1808 result = winreg_printer_write_sz(tmp_ctx,
1813 if (!W_ERROR_IS_OK(result)) {
1818 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1819 result = winreg_printer_write_sz(tmp_ctx,
1824 if (!W_ERROR_IS_OK(result)) {
1829 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1831 * in addprinter: no servername and the printer is the name
1832 * in setprinter: servername is \\server
1833 * and printer is \\server\\printer
1835 * Samba manages only local printers.
1836 * we currently don't support things like i
1837 * path=\\other_server\printer
1839 * We only store the printername, not \\server\printername
1841 const char *p = strrchr(info2->printername, '\\');
1843 p = info2->printername;
1847 result = winreg_printer_write_sz(tmp_ctx,
1852 if (!W_ERROR_IS_OK(result)) {
1857 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1858 result = winreg_printer_write_sz(tmp_ctx,
1862 info2->printprocessor);
1863 if (!W_ERROR_IS_OK(result)) {
1868 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1869 result = winreg_printer_write_dword(tmp_ctx,
1874 if (!W_ERROR_IS_OK(result)) {
1879 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1881 * We need a security descriptor, if it isn't specified by
1882 * AddPrinter{Ex} then create a default descriptor.
1884 if (secdesc == NULL) {
1885 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1886 if (!W_ERROR_IS_OK(result)) {
1890 result = winreg_set_printer_secdesc(tmp_ctx,
1895 if (!W_ERROR_IS_OK(result)) {
1900 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1901 result = winreg_printer_write_sz(tmp_ctx,
1906 if (!W_ERROR_IS_OK(result)) {
1911 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1912 result = winreg_printer_write_sz(tmp_ctx,
1917 if (!W_ERROR_IS_OK(result)) {
1922 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1923 result = winreg_printer_write_dword(tmp_ctx,
1928 if (!W_ERROR_IS_OK(result)) {
1933 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1934 result = winreg_printer_write_dword(tmp_ctx,
1939 if (!W_ERROR_IS_OK(result)) {
1944 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1945 result = winreg_printer_write_dword(tmp_ctx,
1950 if (!W_ERROR_IS_OK(result)) {
1955 result = winreg_printer_write_dword(tmp_ctx,
1959 winreg_printer_rev_changeid());
1960 if (!W_ERROR_IS_OK(result)) {
1966 if (winreg_handle != NULL) {
1969 if (is_valid_policy_hnd(&key_hnd)) {
1970 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1972 if (is_valid_policy_hnd(&hive_hnd)) {
1973 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1977 TALLOC_FREE(tmp_ctx);
1981 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1982 const struct auth_serversupplied_info *server_info,
1983 struct messaging_context *msg_ctx,
1984 const char *printer,
1985 struct spoolss_PrinterInfo2 **pinfo2)
1987 struct spoolss_PrinterInfo2 *info2;
1988 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1989 struct dcerpc_binding_handle *winreg_handle = NULL;
1990 struct policy_handle hive_hnd, key_hnd;
1991 struct spoolss_PrinterEnumValues *enum_values = NULL;
1992 struct spoolss_PrinterEnumValues *v;
1993 enum ndr_err_code ndr_err;
1995 int snum = lp_servicenumber(printer);
1996 uint32_t num_values = 0;
1999 WERROR result = WERR_OK;
2000 TALLOC_CTX *tmp_ctx;
2002 tmp_ctx = talloc_stackframe();
2003 if (tmp_ctx == NULL) {
2007 path = winreg_printer_data_keyname(tmp_ctx, printer);
2009 TALLOC_FREE(tmp_ctx);
2013 result = winreg_printer_openkey(tmp_ctx,
2023 if (!W_ERROR_IS_OK(result)) {
2024 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
2025 path, win_errstr(result)));
2029 result = winreg_printer_enumvalues(tmp_ctx,
2034 if (!W_ERROR_IS_OK(result)) {
2035 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
2036 path, win_errstr(result)));
2040 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
2041 if (info2 == NULL) {
2042 result = WERR_NOMEM;
2046 FILL_STRING(info2, EMPTY_STRING, info2->servername);
2047 FILL_STRING(info2, EMPTY_STRING, info2->printername);
2048 FILL_STRING(info2, EMPTY_STRING, info2->sharename);
2049 FILL_STRING(info2, EMPTY_STRING, info2->portname);
2050 FILL_STRING(info2, EMPTY_STRING, info2->drivername);
2051 FILL_STRING(info2, EMPTY_STRING, info2->comment);
2052 FILL_STRING(info2, EMPTY_STRING, info2->location);
2053 FILL_STRING(info2, EMPTY_STRING, info2->sepfile);
2054 FILL_STRING(info2, EMPTY_STRING, info2->printprocessor);
2055 FILL_STRING(info2, EMPTY_STRING, info2->datatype);
2056 FILL_STRING(info2, EMPTY_STRING, info2->parameters);
2058 for (i = 0; i < num_values; i++) {
2059 v = &enum_values[i];
2061 result = winreg_enumval_to_sz(info2,
2064 &info2->printername);
2065 CHECK_ERROR(result);
2067 result = winreg_enumval_to_sz(info2,
2071 CHECK_ERROR(result);
2073 result = winreg_enumval_to_sz(info2,
2077 CHECK_ERROR(result);
2079 result = winreg_enumval_to_sz(info2,
2083 CHECK_ERROR(result);
2085 result = winreg_enumval_to_sz(info2,
2089 CHECK_ERROR(result);
2091 result = winreg_enumval_to_sz(info2,
2095 CHECK_ERROR(result);
2097 result = winreg_enumval_to_sz(info2,
2100 &info2->printprocessor);
2101 CHECK_ERROR(result);
2103 result = winreg_enumval_to_sz(info2,
2107 CHECK_ERROR(result);
2109 result = winreg_enumval_to_sz(info2,
2112 &info2->parameters);
2113 CHECK_ERROR(result);
2115 result = winreg_enumval_to_sz(info2,
2118 &info2->drivername);
2119 CHECK_ERROR(result);
2121 result = winreg_enumval_to_dword(info2,
2124 &info2->attributes);
2125 CHECK_ERROR(result);
2127 result = winreg_enumval_to_dword(info2,
2131 CHECK_ERROR(result);
2133 result = winreg_enumval_to_dword(info2,
2136 &info2->defaultpriority);
2137 CHECK_ERROR(result);
2139 result = winreg_enumval_to_dword(info2,
2143 CHECK_ERROR(result);
2145 result = winreg_enumval_to_dword(info2,
2149 CHECK_ERROR(result);
2151 result = winreg_enumval_to_dword(info2,
2155 CHECK_ERROR(result);
2157 result = winreg_enumval_to_dword(info2,
2161 CHECK_ERROR(result);
2164 if (!W_ERROR_IS_OK(result)) {
2165 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2168 win_errstr(result)));
2172 /* Construct the Device Mode */
2173 result = winreg_printer_query_binary(tmp_ctx,
2178 if (W_ERROR_IS_OK(result)) {
2179 info2->devmode = talloc_zero(info2, struct spoolss_DeviceMode);
2180 if (info2->devmode == NULL) {
2181 result = WERR_NOMEM;
2184 ndr_err = ndr_pull_struct_blob(&blob,
2187 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
2188 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2189 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2190 result = WERR_NOMEM;
2195 if (info2->devmode == NULL && lp_default_devmode(snum)) {
2196 result = spoolss_create_default_devmode(info2,
2199 if (!W_ERROR_IS_OK(result)) {
2204 result = winreg_get_printer_secdesc(info2,
2209 if (!W_ERROR_IS_OK(result)) {
2213 /* Fix for OS/2 drivers. */
2214 if (get_remote_arch() == RA_OS2) {
2215 spoolss_map_to_os2_driver(info2, &info2->drivername);
2219 *pinfo2 = talloc_move(mem_ctx, &info2);
2224 if (winreg_handle != NULL) {
2227 if (is_valid_policy_hnd(&key_hnd)) {
2228 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2230 if (is_valid_policy_hnd(&hive_hnd)) {
2231 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2235 TALLOC_FREE(tmp_ctx);
2239 WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
2240 const struct auth_serversupplied_info *server_info,
2241 struct messaging_context *msg_ctx,
2242 const char *sharename,
2243 struct spoolss_security_descriptor **psecdesc)
2245 struct spoolss_security_descriptor *secdesc;
2246 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2247 struct dcerpc_binding_handle *winreg_handle = NULL;
2248 struct policy_handle hive_hnd, key_hnd;
2249 enum ndr_err_code ndr_err;
2252 TALLOC_CTX *tmp_ctx;
2255 tmp_ctx = talloc_stackframe();
2256 if (tmp_ctx == NULL) {
2260 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2262 talloc_free(tmp_ctx);
2266 ZERO_STRUCT(hive_hnd);
2267 ZERO_STRUCT(key_hnd);
2269 result = winreg_printer_openkey(tmp_ctx,
2279 if (!W_ERROR_IS_OK(result)) {
2280 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2281 goto create_default;
2286 result = winreg_printer_query_binary(tmp_ctx,
2291 if (!W_ERROR_IS_OK(result)) {
2292 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2293 goto create_default;
2298 secdesc = talloc_zero(tmp_ctx, struct spoolss_security_descriptor);
2299 if (secdesc == NULL) {
2300 result = WERR_NOMEM;
2303 ndr_err = ndr_pull_struct_blob(&blob,
2306 (ndr_pull_flags_fn_t) ndr_pull_security_descriptor);
2307 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2308 DEBUG(0, ("winreg_get_secdesc: Failed to unmarshall security descriptor\n"));
2309 result = WERR_NOMEM;
2314 *psecdesc = talloc_move(mem_ctx, &secdesc);
2321 result = winreg_printer_openkey(tmp_ctx,
2331 if (!W_ERROR_IS_OK(result)) {
2335 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
2336 if (!W_ERROR_IS_OK(result)) {
2340 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
2341 this security descriptor has been created when winbindd was
2342 down. Take ownership of security descriptor. */
2343 if (dom_sid_equal(secdesc->owner_sid, &global_sid_World)) {
2344 struct dom_sid owner_sid;
2346 /* Change sd owner to workgroup administrator */
2348 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid)) {
2349 struct spoolss_security_descriptor *new_secdesc;
2353 sid_append_rid(&owner_sid, DOMAIN_RID_ADMINISTRATOR);
2355 new_secdesc = make_sec_desc(tmp_ctx,
2364 if (new_secdesc == NULL) {
2365 result = WERR_NOMEM;
2369 /* Swap with other one */
2370 secdesc = new_secdesc;
2374 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, secdesc,
2375 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2376 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2377 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2378 result = WERR_NOMEM;
2382 result = winreg_printer_write_binary(tmp_ctx,
2387 if (!W_ERROR_IS_OK(result)) {
2392 *psecdesc = talloc_move(mem_ctx, &secdesc);
2397 if (winreg_handle != NULL) {
2400 if (is_valid_policy_hnd(&key_hnd)) {
2401 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2403 if (is_valid_policy_hnd(&hive_hnd)) {
2404 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2408 talloc_free(tmp_ctx);
2412 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
2413 const struct auth_serversupplied_info *server_info,
2414 struct messaging_context *msg_ctx,
2415 const char *sharename,
2416 const struct spoolss_security_descriptor *secdesc)
2418 const struct spoolss_security_descriptor *new_secdesc = secdesc;
2419 struct spoolss_security_descriptor *old_secdesc;
2420 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2421 struct dcerpc_binding_handle *winreg_handle = NULL;
2422 struct policy_handle hive_hnd, key_hnd;
2423 enum ndr_err_code ndr_err;
2426 TALLOC_CTX *tmp_ctx;
2429 tmp_ctx = talloc_stackframe();
2430 if (tmp_ctx == NULL) {
2434 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2436 talloc_free(tmp_ctx);
2441 * The old owner and group sids of the security descriptor are not
2442 * present when new ACEs are added or removed by changing printer
2443 * permissions through NT. If they are NULL in the new security
2444 * descriptor then copy them over from the old one.
2446 if (!secdesc->owner_sid || !secdesc->group_sid) {
2447 struct dom_sid *owner_sid, *group_sid;
2448 struct security_acl *dacl, *sacl;
2451 result = winreg_get_printer_secdesc(tmp_ctx,
2456 if (!W_ERROR_IS_OK(result)) {
2457 talloc_free(tmp_ctx);
2461 /* Pick out correct owner and group sids */
2462 owner_sid = secdesc->owner_sid ?
2463 secdesc->owner_sid :
2464 old_secdesc->owner_sid;
2466 group_sid = secdesc->group_sid ?
2467 secdesc->group_sid :
2468 old_secdesc->group_sid;
2470 dacl = secdesc->dacl ?
2474 sacl = secdesc->sacl ?
2478 /* Make a deep copy of the security descriptor */
2479 new_secdesc = make_sec_desc(tmp_ctx,
2487 if (new_secdesc == NULL) {
2488 talloc_free(tmp_ctx);
2493 ZERO_STRUCT(hive_hnd);
2494 ZERO_STRUCT(key_hnd);
2496 result = winreg_printer_openkey(tmp_ctx,
2506 if (!W_ERROR_IS_OK(result)) {
2510 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, new_secdesc,
2511 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2512 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2513 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2514 result = WERR_NOMEM;
2518 result = winreg_printer_write_binary(tmp_ctx,
2525 if (winreg_handle != NULL) {
2528 if (is_valid_policy_hnd(&key_hnd)) {
2529 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2531 if (is_valid_policy_hnd(&hive_hnd)) {
2532 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2536 talloc_free(tmp_ctx);
2540 /* Set printer data over the winreg pipe. */
2541 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2542 const struct auth_serversupplied_info *server_info,
2543 struct messaging_context *msg_ctx,
2544 const char *printer,
2547 enum winreg_Type type,
2551 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2552 struct dcerpc_binding_handle *winreg_handle = NULL;
2553 struct policy_handle hive_hnd, key_hnd;
2554 struct winreg_String wvalue;
2556 WERROR result = WERR_OK;
2558 TALLOC_CTX *tmp_ctx;
2560 tmp_ctx = talloc_stackframe();
2561 if (tmp_ctx == NULL) {
2565 path = winreg_printer_data_keyname(tmp_ctx, printer);
2567 TALLOC_FREE(tmp_ctx);
2571 ZERO_STRUCT(hive_hnd);
2572 ZERO_STRUCT(key_hnd);
2574 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2575 key, value, access_mask, printer));
2576 result = winreg_printer_openkey(tmp_ctx,
2586 if (!W_ERROR_IS_OK(result)) {
2587 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2588 key, win_errstr(result)));
2592 wvalue.name = value;
2593 status = dcerpc_winreg_SetValue(winreg_handle,
2601 if (!NT_STATUS_IS_OK(status)) {
2602 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2603 value, nt_errstr(status)));
2604 result = ntstatus_to_werror(status);
2608 if (winreg_handle != NULL) {
2611 if (is_valid_policy_hnd(&key_hnd)) {
2612 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2614 if (is_valid_policy_hnd(&hive_hnd)) {
2615 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2619 TALLOC_FREE(tmp_ctx);
2623 /* Get printer data over a winreg pipe. */
2624 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2625 const struct auth_serversupplied_info *server_info,
2626 struct messaging_context *msg_ctx,
2627 const char *printer,
2630 enum winreg_Type *type,
2632 uint32_t *data_size)
2634 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2635 struct dcerpc_binding_handle *winreg_handle = NULL;
2636 struct policy_handle hive_hnd, key_hnd;
2637 struct winreg_String wvalue;
2638 enum winreg_Type type_in;
2641 uint32_t data_in_size = 0;
2642 uint32_t value_len = 0;
2643 WERROR result = WERR_OK;
2645 TALLOC_CTX *tmp_ctx;
2647 tmp_ctx = talloc_stackframe();
2648 if (tmp_ctx == NULL) {
2652 path = winreg_printer_data_keyname(tmp_ctx, printer);
2654 TALLOC_FREE(tmp_ctx);
2658 ZERO_STRUCT(hive_hnd);
2659 ZERO_STRUCT(key_hnd);
2661 result = winreg_printer_openkey(tmp_ctx,
2671 if (!W_ERROR_IS_OK(result)) {
2672 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2673 key, win_errstr(result)));
2677 wvalue.name = value;
2680 * call QueryValue once with data == NULL to get the
2681 * needed memory size to be allocated, then allocate
2682 * data buffer and call again.
2684 status = dcerpc_winreg_QueryValue(winreg_handle,
2693 if (!NT_STATUS_IS_OK(status)) {
2694 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2695 value, nt_errstr(status)));
2696 result = ntstatus_to_werror(status);
2699 if (!W_ERROR_IS_OK(result)) {
2703 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2704 if (data_in == NULL) {
2705 result = WERR_NOMEM;
2710 status = dcerpc_winreg_QueryValue(winreg_handle,
2719 if (!NT_STATUS_IS_OK(status)) {
2720 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2721 value, nt_errstr(status)));
2722 result = ntstatus_to_werror(status);
2725 if (!W_ERROR_IS_OK(result)) {
2730 *data_size = data_in_size;
2732 *data = talloc_move(mem_ctx, &data_in);
2737 if (winreg_handle != NULL) {
2740 if (is_valid_policy_hnd(&key_hnd)) {
2741 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2743 if (is_valid_policy_hnd(&hive_hnd)) {
2744 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2748 TALLOC_FREE(tmp_ctx);
2752 /* Enumerate on the values of a given key and provide the data. */
2753 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2754 const struct auth_serversupplied_info *server_info,
2755 struct messaging_context *msg_ctx,
2756 const char *printer,
2758 uint32_t *pnum_values,
2759 struct spoolss_PrinterEnumValues **penum_values)
2761 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2762 struct dcerpc_binding_handle *winreg_handle = NULL;
2763 struct policy_handle hive_hnd, key_hnd;
2765 struct spoolss_PrinterEnumValues *enum_values = NULL;
2766 uint32_t num_values = 0;
2768 WERROR result = WERR_OK;
2770 TALLOC_CTX *tmp_ctx;
2772 tmp_ctx = talloc_stackframe();
2773 if (tmp_ctx == NULL) {
2777 path = winreg_printer_data_keyname(tmp_ctx, printer);
2779 TALLOC_FREE(tmp_ctx);
2783 result = winreg_printer_openkey(tmp_ctx,
2793 if (!W_ERROR_IS_OK(result)) {
2794 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2795 key, win_errstr(result)));
2799 result = winreg_printer_enumvalues(tmp_ctx,
2804 if (!W_ERROR_IS_OK(result)) {
2805 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2806 key, win_errstr(result)));
2810 *pnum_values = num_values;
2812 *penum_values = talloc_move(mem_ctx, &enum_values);
2817 if (winreg_handle != NULL) {
2820 if (is_valid_policy_hnd(&key_hnd)) {
2821 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2823 if (is_valid_policy_hnd(&hive_hnd)) {
2824 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2828 TALLOC_FREE(tmp_ctx);
2832 /* Delete printer data over a winreg pipe. */
2833 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2834 const struct auth_serversupplied_info *server_info,
2835 struct messaging_context *msg_ctx,
2836 const char *printer,
2840 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2841 struct dcerpc_binding_handle *winreg_handle = NULL;
2842 struct policy_handle hive_hnd, key_hnd;
2843 struct winreg_String wvalue;
2845 WERROR result = WERR_OK;
2848 TALLOC_CTX *tmp_ctx;
2850 tmp_ctx = talloc_stackframe();
2851 if (tmp_ctx == NULL) {
2855 path = winreg_printer_data_keyname(tmp_ctx, printer);
2857 TALLOC_FREE(tmp_ctx);
2861 ZERO_STRUCT(hive_hnd);
2862 ZERO_STRUCT(key_hnd);
2864 result = winreg_printer_openkey(tmp_ctx,
2874 if (!W_ERROR_IS_OK(result)) {
2875 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2876 key, win_errstr(result)));
2880 wvalue.name = value;
2881 status = dcerpc_winreg_DeleteValue(winreg_handle,
2886 if (!NT_STATUS_IS_OK(status)) {
2887 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2888 value, nt_errstr(status)));
2889 result = ntstatus_to_werror(status);
2893 if (winreg_handle != NULL) {
2896 if (is_valid_policy_hnd(&key_hnd)) {
2897 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2899 if (is_valid_policy_hnd(&hive_hnd)) {
2900 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2904 TALLOC_FREE(tmp_ctx);
2908 /* Enumerate on the subkeys of a given key and provide the data. */
2909 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2910 const struct auth_serversupplied_info *server_info,
2911 struct messaging_context *msg_ctx,
2912 const char *printer,
2914 uint32_t *pnum_subkeys,
2915 const char ***psubkeys)
2917 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2918 struct dcerpc_binding_handle *winreg_handle = NULL;
2919 struct policy_handle hive_hnd, key_hnd;
2921 const char **subkeys = NULL;
2922 uint32_t num_subkeys = -1;
2924 WERROR result = WERR_OK;
2926 TALLOC_CTX *tmp_ctx;
2928 tmp_ctx = talloc_stackframe();
2929 if (tmp_ctx == NULL) {
2933 path = winreg_printer_data_keyname(tmp_ctx, printer);
2935 TALLOC_FREE(tmp_ctx);
2939 ZERO_STRUCT(hive_hnd);
2940 ZERO_STRUCT(key_hnd);
2942 result = winreg_printer_openkey(tmp_ctx,
2952 if (!W_ERROR_IS_OK(result)) {
2953 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2954 key, win_errstr(result)));
2958 result = winreg_printer_enumkeys(tmp_ctx,
2963 if (!W_ERROR_IS_OK(result)) {
2964 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2965 key, win_errstr(result)));
2969 *pnum_subkeys = num_subkeys;
2971 *psubkeys = talloc_move(mem_ctx, &subkeys);
2976 if (winreg_handle != NULL) {
2979 if (is_valid_policy_hnd(&key_hnd)) {
2980 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2982 if (is_valid_policy_hnd(&hive_hnd)) {
2983 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2987 TALLOC_FREE(tmp_ctx);
2991 /* Delete a key with subkeys of a given printer. */
2992 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
2993 const struct auth_serversupplied_info *server_info,
2994 struct messaging_context *msg_ctx,
2995 const char *printer,
2998 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2999 struct dcerpc_binding_handle *winreg_handle = NULL;
3000 struct policy_handle hive_hnd, key_hnd;
3004 TALLOC_CTX *tmp_ctx;
3006 tmp_ctx = talloc_stackframe();
3007 if (tmp_ctx == NULL) {
3011 path = winreg_printer_data_keyname(tmp_ctx, printer);
3013 TALLOC_FREE(tmp_ctx);
3017 result = winreg_printer_openkey(tmp_ctx,
3027 if (!W_ERROR_IS_OK(result)) {
3028 /* key doesn't exist */
3029 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3034 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
3035 key, win_errstr(result)));
3039 if (is_valid_policy_hnd(&key_hnd)) {
3040 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
3043 if (key == NULL || key[0] == '\0') {
3046 keyname = talloc_asprintf(tmp_ctx,
3050 if (keyname == NULL) {
3051 result = WERR_NOMEM;
3056 result = winreg_printer_delete_subkeys(tmp_ctx,
3061 if (!W_ERROR_IS_OK(result)) {
3062 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
3063 key, win_errstr(result)));
3068 if (winreg_handle != NULL) {
3071 if (is_valid_policy_hnd(&key_hnd)) {
3072 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3074 if (is_valid_policy_hnd(&hive_hnd)) {
3075 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3079 TALLOC_FREE(tmp_ctx);
3083 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
3084 const struct auth_serversupplied_info *server_info,
3085 struct messaging_context *msg_ctx,
3086 const char *printer)
3088 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3089 struct dcerpc_binding_handle *winreg_handle = NULL;
3090 struct policy_handle hive_hnd, key_hnd;
3093 TALLOC_CTX *tmp_ctx;
3095 tmp_ctx = talloc_stackframe();
3096 if (tmp_ctx == NULL) {
3100 path = winreg_printer_data_keyname(tmp_ctx, printer);
3102 TALLOC_FREE(tmp_ctx);
3106 ZERO_STRUCT(hive_hnd);
3107 ZERO_STRUCT(key_hnd);
3109 result = winreg_printer_openkey(tmp_ctx,
3119 if (!W_ERROR_IS_OK(result)) {
3120 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
3121 path, win_errstr(result)));
3125 result = winreg_printer_write_dword(tmp_ctx,
3129 winreg_printer_rev_changeid());
3130 if (!W_ERROR_IS_OK(result)) {
3136 if (winreg_handle != NULL) {
3139 if (is_valid_policy_hnd(&key_hnd)) {
3140 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3142 if (is_valid_policy_hnd(&hive_hnd)) {
3143 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3147 TALLOC_FREE(tmp_ctx);
3151 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
3152 const struct auth_serversupplied_info *server_info,
3153 struct messaging_context *msg_ctx,
3154 const char *printer,
3155 uint32_t *pchangeid)
3157 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3158 struct dcerpc_binding_handle *winreg_handle = NULL;
3159 struct policy_handle hive_hnd, key_hnd;
3160 uint32_t changeid = 0;
3163 TALLOC_CTX *tmp_ctx;
3165 tmp_ctx = talloc_stackframe();
3166 if (tmp_ctx == NULL) {
3170 path = winreg_printer_data_keyname(tmp_ctx, printer);
3172 TALLOC_FREE(tmp_ctx);
3176 ZERO_STRUCT(hive_hnd);
3177 ZERO_STRUCT(key_hnd);
3179 result = winreg_printer_openkey(tmp_ctx,
3189 if (!W_ERROR_IS_OK(result)) {
3190 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
3191 path, win_errstr(result)));
3195 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path));
3197 result = winreg_printer_query_dword(tmp_ctx,
3202 if (!W_ERROR_IS_OK(result)) {
3207 *pchangeid = changeid;
3212 if (winreg_handle != NULL) {
3215 if (is_valid_policy_hnd(&key_hnd)) {
3216 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3218 if (is_valid_policy_hnd(&hive_hnd)) {
3219 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3223 TALLOC_FREE(tmp_ctx);
3228 * The special behaviour of the spoolss forms is documented at the website:
3230 * Managing Win32 Printserver Forms
3231 * http://unixwiz.net/techtips/winspooler-forms.html
3234 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
3235 const struct auth_serversupplied_info *server_info,
3236 struct messaging_context *msg_ctx,
3237 struct spoolss_AddFormInfo1 *form)
3239 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3240 struct dcerpc_binding_handle *winreg_handle = NULL;
3241 struct policy_handle hive_hnd, key_hnd;
3242 struct winreg_String wvalue;
3244 uint32_t num_info = 0;
3245 union spoolss_FormInfo *info = NULL;
3249 TALLOC_CTX *tmp_ctx;
3251 tmp_ctx = talloc_stackframe();
3252 if (tmp_ctx == NULL) {
3256 ZERO_STRUCT(hive_hnd);
3257 ZERO_STRUCT(key_hnd);
3259 result = winreg_printer_openkey(tmp_ctx,
3263 TOP_LEVEL_CONTROL_FORMS_KEY,
3269 if (!W_ERROR_IS_OK(result)) {
3270 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
3271 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3275 result = winreg_printer_enumforms1(tmp_ctx, server_info, msg_ctx,
3277 if (!W_ERROR_IS_OK(result)) {
3278 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
3279 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3283 /* If form name already exists or is builtin return ALREADY_EXISTS */
3284 for (i = 0; i < num_info; i++) {
3285 if (strequal(info[i].info1.form_name, form->form_name)) {
3286 result = WERR_FILE_EXISTS;
3291 wvalue.name = form->form_name;
3293 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3294 SIVAL(blob.data, 0, form->size.width);
3295 SIVAL(blob.data, 4, form->size.height);
3296 SIVAL(blob.data, 8, form->area.left);
3297 SIVAL(blob.data, 12, form->area.top);
3298 SIVAL(blob.data, 16, form->area.right);
3299 SIVAL(blob.data, 20, form->area.bottom);
3300 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
3301 SIVAL(blob.data, 28, form->flags);
3303 status = dcerpc_winreg_SetValue(winreg_handle,
3311 if (!NT_STATUS_IS_OK(status)) {
3312 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
3313 wvalue.name, nt_errstr(status)));
3314 result = ntstatus_to_werror(status);
3318 if (winreg_handle != NULL) {
3321 if (is_valid_policy_hnd(&key_hnd)) {
3322 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3324 if (is_valid_policy_hnd(&hive_hnd)) {
3325 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3330 TALLOC_FREE(tmp_ctx);
3334 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
3335 const struct auth_serversupplied_info *server_info,
3336 struct messaging_context *msg_ctx,
3337 uint32_t *pnum_info,
3338 union spoolss_FormInfo **pinfo)
3340 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3341 struct dcerpc_binding_handle *winreg_handle = NULL;
3342 struct policy_handle hive_hnd, key_hnd;
3343 union spoolss_FormInfo *info;
3344 struct spoolss_PrinterEnumValues *enum_values = NULL;
3345 uint32_t num_values = 0;
3346 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3349 TALLOC_CTX *tmp_ctx;
3351 tmp_ctx = talloc_stackframe();
3352 if (tmp_ctx == NULL) {
3356 ZERO_STRUCT(hive_hnd);
3357 ZERO_STRUCT(key_hnd);
3359 result = winreg_printer_openkey(tmp_ctx,
3363 TOP_LEVEL_CONTROL_FORMS_KEY,
3369 if (!W_ERROR_IS_OK(result)) {
3370 /* key doesn't exist */
3371 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3376 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3377 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3381 result = winreg_printer_enumvalues(tmp_ctx,
3386 if (!W_ERROR_IS_OK(result)) {
3387 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3388 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3392 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
3394 result = WERR_NOMEM;
3398 /* Enumerate BUILTIN forms */
3399 for (i = 0; i < num_builtin; i++) {
3400 info[i].info1 = builtin_forms1[i];
3403 /* Enumerate registry forms */
3404 for (i = 0; i < num_values; i++) {
3405 union spoolss_FormInfo val;
3407 if (enum_values[i].type != REG_BINARY ||
3408 enum_values[i].data_length != 32) {
3412 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
3413 if (val.info1.form_name == NULL) {
3414 result = WERR_NOMEM;
3418 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3419 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3420 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3421 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3422 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3423 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3424 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3425 val.info1.flags = (enum spoolss_FormFlags) IVAL(enum_values[i].data->data, 28);
3427 info[i + num_builtin] = val;
3430 *pnum_info = num_builtin + num_values;
3432 *pinfo = talloc_move(mem_ctx, &info);
3436 if (winreg_handle != NULL) {
3439 if (is_valid_policy_hnd(&key_hnd)) {
3440 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3442 if (is_valid_policy_hnd(&hive_hnd)) {
3443 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3447 TALLOC_FREE(enum_values);
3448 TALLOC_FREE(tmp_ctx);
3452 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3453 const struct auth_serversupplied_info *server_info,
3454 struct messaging_context *msg_ctx,
3455 const char *form_name)
3457 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3458 struct dcerpc_binding_handle *winreg_handle = NULL;
3459 struct policy_handle hive_hnd, key_hnd;
3460 struct winreg_String wvalue;
3461 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3463 WERROR result = WERR_OK;
3465 TALLOC_CTX *tmp_ctx;
3467 for (i = 0; i < num_builtin; i++) {
3468 if (strequal(builtin_forms1[i].form_name, form_name)) {
3469 return WERR_INVALID_PARAMETER;
3473 tmp_ctx = talloc_stackframe();
3474 if (tmp_ctx == NULL) {
3478 ZERO_STRUCT(hive_hnd);
3479 ZERO_STRUCT(key_hnd);
3481 result = winreg_printer_openkey(tmp_ctx,
3485 TOP_LEVEL_CONTROL_FORMS_KEY,
3491 if (!W_ERROR_IS_OK(result)) {
3492 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3493 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3494 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3495 result = WERR_INVALID_FORM_NAME;
3500 wvalue.name = form_name;
3501 status = dcerpc_winreg_DeleteValue(winreg_handle,
3506 if (!NT_STATUS_IS_OK(status)) {
3507 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3508 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3509 wvalue.name, nt_errstr(status)));
3510 result = ntstatus_to_werror(status);
3514 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3515 result = WERR_INVALID_FORM_NAME;
3519 if (winreg_handle != NULL) {
3522 if (is_valid_policy_hnd(&key_hnd)) {
3523 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3525 if (is_valid_policy_hnd(&hive_hnd)) {
3526 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3530 TALLOC_FREE(tmp_ctx);
3534 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3535 const struct auth_serversupplied_info *server_info,
3536 struct messaging_context *msg_ctx,
3537 const char *form_name,
3538 struct spoolss_AddFormInfo1 *form)
3540 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3541 struct dcerpc_binding_handle *winreg_handle = NULL;
3542 struct policy_handle hive_hnd, key_hnd;
3543 struct winreg_String wvalue;
3545 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3549 TALLOC_CTX *tmp_ctx = NULL;
3551 for (i = 0; i < num_builtin; i++) {
3552 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3553 result = WERR_INVALID_PARAM;
3558 tmp_ctx = talloc_stackframe();
3559 if (tmp_ctx == NULL) {
3563 ZERO_STRUCT(hive_hnd);
3564 ZERO_STRUCT(key_hnd);
3566 result = winreg_printer_openkey(tmp_ctx,
3570 TOP_LEVEL_CONTROL_FORMS_KEY,
3576 if (!W_ERROR_IS_OK(result)) {
3577 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3578 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3582 /* If form_name != form->form_name then we renamed the form */
3583 if (strequal(form_name, form->form_name)) {
3584 result = winreg_printer_deleteform1(tmp_ctx, server_info,
3585 msg_ctx, form_name);
3586 if (!W_ERROR_IS_OK(result)) {
3587 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3588 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3593 wvalue.name = form->form_name;
3595 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3596 SIVAL(blob.data, 0, form->size.width);
3597 SIVAL(blob.data, 4, form->size.height);
3598 SIVAL(blob.data, 8, form->area.left);
3599 SIVAL(blob.data, 12, form->area.top);
3600 SIVAL(blob.data, 16, form->area.right);
3601 SIVAL(blob.data, 20, form->area.bottom);
3602 SIVAL(blob.data, 24, 42);
3603 SIVAL(blob.data, 28, form->flags);
3605 status = dcerpc_winreg_SetValue(winreg_handle,
3613 if (!NT_STATUS_IS_OK(status)) {
3614 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3615 wvalue.name, nt_errstr(status)));
3616 result = ntstatus_to_werror(status);
3620 if (winreg_handle != NULL) {
3623 if (is_valid_policy_hnd(&key_hnd)) {
3624 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3626 if (is_valid_policy_hnd(&hive_hnd)) {
3627 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3631 TALLOC_FREE(tmp_ctx);
3635 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3636 const struct auth_serversupplied_info *server_info,
3637 struct messaging_context *msg_ctx,
3638 const char *form_name,
3639 struct spoolss_FormInfo1 *r)
3641 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3642 struct dcerpc_binding_handle *winreg_handle = NULL;
3643 struct policy_handle hive_hnd, key_hnd;
3644 struct winreg_String wvalue;
3645 enum winreg_Type type_in;
3647 uint32_t data_in_size = 0;
3648 uint32_t value_len = 0;
3649 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3653 TALLOC_CTX *tmp_ctx;
3655 /* check builtin forms first */
3656 for (i = 0; i < num_builtin; i++) {
3657 if (strequal(builtin_forms1[i].form_name, form_name)) {
3658 *r = builtin_forms1[i];
3663 tmp_ctx = talloc_stackframe();
3664 if (tmp_ctx == NULL) {
3668 ZERO_STRUCT(hive_hnd);
3669 ZERO_STRUCT(key_hnd);
3671 result = winreg_printer_openkey(tmp_ctx,
3675 TOP_LEVEL_CONTROL_FORMS_KEY,
3681 if (!W_ERROR_IS_OK(result)) {
3682 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3683 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3687 wvalue.name = form_name;
3690 * call QueryValue once with data == NULL to get the
3691 * needed memory size to be allocated, then allocate
3692 * data buffer and call again.
3694 status = dcerpc_winreg_QueryValue(winreg_handle,
3703 if (!NT_STATUS_IS_OK(status)) {
3704 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3705 wvalue.name, nt_errstr(status)));
3706 result = ntstatus_to_werror(status);
3709 if (!W_ERROR_IS_OK(result)) {
3713 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3714 if (data_in == NULL) {
3715 result = WERR_NOMEM;
3720 status = dcerpc_winreg_QueryValue(winreg_handle,
3729 if (!NT_STATUS_IS_OK(status)) {
3730 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3731 wvalue.name, nt_errstr(status)));
3732 result = ntstatus_to_werror(status);
3735 if (!W_ERROR_IS_OK(result)) {
3739 r->form_name = talloc_strdup(mem_ctx, form_name);
3740 if (r->form_name == NULL) {
3741 result = WERR_NOMEM;
3745 r->size.width = IVAL(data_in, 0);
3746 r->size.height = IVAL(data_in, 4);
3747 r->area.left = IVAL(data_in, 8);
3748 r->area.top = IVAL(data_in, 12);
3749 r->area.right = IVAL(data_in, 16);
3750 r->area.bottom = IVAL(data_in, 20);
3751 /* skip index IVAL(data_in, 24)));*/
3752 r->flags = (enum spoolss_FormFlags) IVAL(data_in, 28);
3756 if (winreg_handle != NULL) {
3759 if (is_valid_policy_hnd(&key_hnd)) {
3760 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3762 if (is_valid_policy_hnd(&hive_hnd)) {
3763 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3767 TALLOC_FREE(tmp_ctx);
3771 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3772 const struct auth_serversupplied_info *server_info,
3773 struct messaging_context *msg_ctx,
3774 struct spoolss_AddDriverInfoCtr *r,
3775 const char **driver_name,
3776 uint32_t *driver_version)
3778 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3779 struct dcerpc_binding_handle *winreg_handle = NULL;
3780 struct policy_handle hive_hnd, key_hnd;
3781 struct spoolss_DriverInfo8 info8;
3782 TALLOC_CTX *tmp_ctx = NULL;
3785 ZERO_STRUCT(hive_hnd);
3786 ZERO_STRUCT(key_hnd);
3789 if (!driver_info_ctr_to_info8(r, &info8)) {
3790 result = WERR_INVALID_PARAMETER;
3794 tmp_ctx = talloc_stackframe();
3795 if (tmp_ctx == NULL) {
3799 result = winreg_printer_opendriver(tmp_ctx,
3809 if (!W_ERROR_IS_OK(result)) {
3810 DEBUG(0, ("winreg_add_driver: "
3811 "Could not open driver key (%s,%s,%d): %s\n",
3812 info8.driver_name, info8.architecture,
3813 info8.version, win_errstr(result)));
3817 /* TODO: "Attributes" ? */
3819 result = winreg_printer_write_dword(tmp_ctx, winreg_handle,
3820 &key_hnd, "Version",
3822 if (!W_ERROR_IS_OK(result)) {
3826 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3829 if (!W_ERROR_IS_OK(result)) {
3833 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3834 &key_hnd, "Data File",
3836 if (!W_ERROR_IS_OK(result)) {
3840 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3841 &key_hnd, "Configuration File",
3843 if (!W_ERROR_IS_OK(result)) {
3847 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3848 &key_hnd, "Help File",
3850 if (!W_ERROR_IS_OK(result)) {
3854 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3855 &key_hnd, "Dependent Files",
3856 info8.dependent_files);
3857 if (!W_ERROR_IS_OK(result)) {
3861 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3862 &key_hnd, "Monitor",
3863 info8.monitor_name);
3864 if (!W_ERROR_IS_OK(result)) {
3868 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3869 &key_hnd, "Datatype",
3870 info8.default_datatype);
3871 if (!W_ERROR_IS_OK(result)) {
3875 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3876 &key_hnd, "Previous Names",
3877 info8.previous_names);
3878 if (!W_ERROR_IS_OK(result)) {
3882 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3883 &key_hnd, "DriverDate",
3885 if (!W_ERROR_IS_OK(result)) {
3889 result = winreg_printer_write_ver(tmp_ctx, winreg_handle,
3890 &key_hnd, "DriverVersion",
3891 info8.driver_version);
3892 if (!W_ERROR_IS_OK(result)) {
3896 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3897 &key_hnd, "Manufacturer",
3898 info8.manufacturer_name);
3899 if (!W_ERROR_IS_OK(result)) {
3903 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3904 &key_hnd, "OEM URL",
3905 info8.manufacturer_url);
3906 if (!W_ERROR_IS_OK(result)) {
3910 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3911 &key_hnd, "HardwareID",
3913 if (!W_ERROR_IS_OK(result)) {
3917 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3918 &key_hnd, "Provider",
3920 if (!W_ERROR_IS_OK(result)) {
3924 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3925 &key_hnd, "Print Processor",
3926 info8.print_processor);
3927 if (!W_ERROR_IS_OK(result)) {
3931 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3932 &key_hnd, "VendorSetup",
3933 info8.vendor_setup);
3934 if (!W_ERROR_IS_OK(result)) {
3938 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3939 &key_hnd, "Color Profiles",
3940 info8.color_profiles);
3941 if (!W_ERROR_IS_OK(result)) {
3945 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3946 &key_hnd, "InfPath",
3948 if (!W_ERROR_IS_OK(result)) {
3952 result = winreg_printer_write_dword(tmp_ctx, winreg_handle, &key_hnd,
3953 "PrinterDriverAttributes",
3954 info8.printer_driver_attributes);
3955 if (!W_ERROR_IS_OK(result)) {
3959 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3960 &key_hnd, "CoreDependencies",
3961 info8.core_driver_dependencies);
3962 if (!W_ERROR_IS_OK(result)) {
3966 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3967 &key_hnd, "MinInboxDriverVerDate",
3968 info8.min_inbox_driver_ver_date);
3969 if (!W_ERROR_IS_OK(result)) {
3973 result = winreg_printer_write_ver(tmp_ctx, winreg_handle, &key_hnd,
3974 "MinInboxDriverVerVersion",
3975 info8.min_inbox_driver_ver_version);
3976 if (!W_ERROR_IS_OK(result)) {
3980 *driver_name = info8.driver_name;
3981 *driver_version = info8.version;
3984 if (winreg_handle != NULL) {
3987 if (is_valid_policy_hnd(&key_hnd)) {
3988 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3990 if (is_valid_policy_hnd(&hive_hnd)) {
3991 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3995 TALLOC_FREE(tmp_ctx);
3999 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
4000 const struct auth_serversupplied_info *server_info,
4001 struct messaging_context *msg_ctx,
4002 const char *architecture,
4003 const char *driver_name,
4004 uint32_t driver_version,
4005 struct spoolss_DriverInfo8 **_info8)
4007 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4008 struct dcerpc_binding_handle *winreg_handle = NULL;
4009 struct policy_handle hive_hnd, key_hnd;
4010 struct spoolss_DriverInfo8 i8, *info8;
4011 struct spoolss_PrinterEnumValues *enum_values = NULL;
4012 struct spoolss_PrinterEnumValues *v;
4013 uint32_t num_values = 0;
4014 TALLOC_CTX *tmp_ctx;
4018 ZERO_STRUCT(hive_hnd);
4019 ZERO_STRUCT(key_hnd);
4022 tmp_ctx = talloc_stackframe();
4023 if (tmp_ctx == NULL) {
4027 if (driver_version == DRIVER_ANY_VERSION) {
4028 /* look for Win2k first and then for NT4 */
4029 result = winreg_printer_opendriver(tmp_ctx,
4039 if (!W_ERROR_IS_OK(result)) {
4040 result = winreg_printer_opendriver(tmp_ctx,
4052 /* ok normal case */
4053 result = winreg_printer_opendriver(tmp_ctx,
4064 if (!W_ERROR_IS_OK(result)) {
4065 DEBUG(5, ("winreg_get_driver: "
4066 "Could not open driver key (%s,%s,%d): %s\n",
4067 driver_name, architecture,
4068 driver_version, win_errstr(result)));
4072 result = winreg_printer_enumvalues(tmp_ctx,
4077 if (!W_ERROR_IS_OK(result)) {
4078 DEBUG(0, ("winreg_get_driver: "
4079 "Could not enumerate values for (%s,%s,%d): %s\n",
4080 driver_name, architecture,
4081 driver_version, win_errstr(result)));
4085 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
4086 if (info8 == NULL) {
4087 result = WERR_NOMEM;
4091 info8->driver_name = talloc_strdup(info8, driver_name);
4092 if (info8->driver_name == NULL) {
4093 result = WERR_NOMEM;
4097 info8->architecture = talloc_strdup(info8, architecture);
4098 if (info8->architecture == NULL) {
4099 result = WERR_NOMEM;
4105 for (i = 0; i < num_values; i++) {
4106 const char *tmp_str;
4109 v = &enum_values[i];
4111 result = winreg_enumval_to_dword(info8, v,
4114 if (NT_STATUS_IS_OK(result)) {
4115 info8->version = (enum spoolss_DriverOSVersion) tmp;
4117 CHECK_ERROR(result);
4119 result = winreg_enumval_to_sz(info8, v,
4121 &info8->driver_path);
4122 CHECK_ERROR(result);
4124 result = winreg_enumval_to_sz(info8, v,
4127 CHECK_ERROR(result);
4129 result = winreg_enumval_to_sz(info8, v,
4130 "Configuration File",
4131 &info8->config_file);
4132 CHECK_ERROR(result);
4134 result = winreg_enumval_to_sz(info8, v,
4137 CHECK_ERROR(result);
4139 result = winreg_enumval_to_multi_sz(info8, v,
4141 &info8->dependent_files);
4142 CHECK_ERROR(result);
4144 result = winreg_enumval_to_sz(info8, v,
4146 &info8->monitor_name);
4147 CHECK_ERROR(result);
4149 result = winreg_enumval_to_sz(info8, v,
4151 &info8->default_datatype);
4152 CHECK_ERROR(result);
4154 result = winreg_enumval_to_multi_sz(info8, v,
4156 &info8->previous_names);
4157 CHECK_ERROR(result);
4159 result = winreg_enumval_to_sz(info8, v,
4162 if (W_ERROR_IS_OK(result)) {
4163 result = winreg_printer_date_to_NTTIME(tmp_str,
4164 &info8->driver_date);
4166 CHECK_ERROR(result);
4168 result = winreg_enumval_to_sz(info8, v,
4171 if (W_ERROR_IS_OK(result)) {
4172 result = winreg_printer_ver_to_dword(tmp_str,
4173 &info8->driver_version);
4175 CHECK_ERROR(result);
4177 result = winreg_enumval_to_sz(info8, v,
4179 &info8->manufacturer_name);
4180 CHECK_ERROR(result);
4182 result = winreg_enumval_to_sz(info8, v,
4184 &info8->manufacturer_url);
4185 CHECK_ERROR(result);
4187 result = winreg_enumval_to_sz(info8, v,
4189 &info8->hardware_id);
4190 CHECK_ERROR(result);
4192 result = winreg_enumval_to_sz(info8, v,
4195 CHECK_ERROR(result);
4197 result = winreg_enumval_to_sz(info8, v,
4199 &info8->print_processor);
4200 CHECK_ERROR(result);
4202 result = winreg_enumval_to_sz(info8, v,
4204 &info8->vendor_setup);
4205 CHECK_ERROR(result);
4207 result = winreg_enumval_to_multi_sz(info8, v,
4209 &info8->color_profiles);
4210 CHECK_ERROR(result);
4212 result = winreg_enumval_to_sz(info8, v,
4215 CHECK_ERROR(result);
4217 result = winreg_enumval_to_dword(info8, v,
4218 "PrinterDriverAttributes",
4219 &info8->printer_driver_attributes);
4220 CHECK_ERROR(result);
4222 result = winreg_enumval_to_multi_sz(info8, v,
4224 &info8->core_driver_dependencies);
4225 CHECK_ERROR(result);
4227 result = winreg_enumval_to_sz(info8, v,
4228 "MinInboxDriverVerDate",
4230 if (W_ERROR_IS_OK(result)) {
4231 result = winreg_printer_date_to_NTTIME(tmp_str,
4232 &info8->min_inbox_driver_ver_date);
4234 CHECK_ERROR(result);
4236 result = winreg_enumval_to_sz(info8, v,
4237 "MinInboxDriverVerVersion",
4239 if (W_ERROR_IS_OK(result)) {
4240 result = winreg_printer_ver_to_dword(tmp_str,
4241 &info8->min_inbox_driver_ver_version);
4243 CHECK_ERROR(result);
4246 if (!W_ERROR_IS_OK(result)) {
4247 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4248 "for %s: %s\n", v->value_name,
4249 win_errstr(result)));
4253 *_info8 = talloc_steal(mem_ctx, info8);
4256 if (winreg_handle != NULL) {
4259 if (is_valid_policy_hnd(&key_hnd)) {
4260 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4262 if (is_valid_policy_hnd(&hive_hnd)) {
4263 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4267 TALLOC_FREE(tmp_ctx);
4271 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
4272 const struct auth_serversupplied_info *server_info,
4273 struct messaging_context *msg_ctx,
4274 struct spoolss_DriverInfo8 *info8,
4277 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4278 struct dcerpc_binding_handle *winreg_handle = NULL;
4279 struct policy_handle hive_hnd, key_hnd;
4280 TALLOC_CTX *tmp_ctx;
4284 ZERO_STRUCT(hive_hnd);
4285 ZERO_STRUCT(key_hnd);
4287 tmp_ctx = talloc_stackframe();
4288 if (tmp_ctx == NULL) {
4292 /* test that the key exists */
4293 result = winreg_printer_opendriver(tmp_ctx,
4297 info8->architecture,
4303 if (!W_ERROR_IS_OK(result)) {
4304 /* key doesn't exist */
4305 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
4310 DEBUG(5, ("winreg_del_driver: "
4311 "Could not open driver (%s,%s,%u): %s\n",
4312 info8->driver_name, info8->architecture,
4313 version, win_errstr(result)));
4318 if (is_valid_policy_hnd(&key_hnd)) {
4319 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
4322 key_name = talloc_asprintf(tmp_ctx,
4323 "%s\\Environments\\%s\\Drivers\\Version-%u",
4324 TOP_LEVEL_CONTROL_KEY,
4325 info8->architecture, version);
4326 if (key_name == NULL) {
4327 result = WERR_NOMEM;
4331 result = winreg_printer_delete_subkeys(tmp_ctx,
4336 if (!W_ERROR_IS_OK(result)) {
4337 DEBUG(0, ("winreg_del_driver: "
4338 "Could not open driver (%s,%s,%u): %s\n",
4339 info8->driver_name, info8->architecture,
4340 version, win_errstr(result)));
4346 if (winreg_handle != NULL) {
4349 if (is_valid_policy_hnd(&key_hnd)) {
4350 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4352 if (is_valid_policy_hnd(&hive_hnd)) {
4353 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4357 TALLOC_FREE(tmp_ctx);
4361 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
4362 const struct auth_serversupplied_info *server_info,
4363 struct messaging_context *msg_ctx,
4364 const char *architecture,
4366 uint32_t *num_drivers,
4367 const char ***drivers_p)
4369 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4370 struct dcerpc_binding_handle *winreg_handle = NULL;
4371 struct policy_handle hive_hnd, key_hnd;
4372 const char **drivers;
4373 TALLOC_CTX *tmp_ctx;
4379 ZERO_STRUCT(hive_hnd);
4380 ZERO_STRUCT(key_hnd);
4382 tmp_ctx = talloc_stackframe();
4383 if (tmp_ctx == NULL) {
4387 /* use NULL for the driver name so we open the key that is
4388 * parent of all drivers for this architecture and version */
4389 result = winreg_printer_opendriver(tmp_ctx,
4399 if (!W_ERROR_IS_OK(result)) {
4400 DEBUG(5, ("winreg_get_driver_list: "
4401 "Could not open key (%s,%u): %s\n",
4402 architecture, version, win_errstr(result)));
4407 result = winreg_printer_enumkeys(tmp_ctx,
4412 if (!W_ERROR_IS_OK(result)) {
4413 DEBUG(0, ("winreg_get_driver_list: "
4414 "Could not enumerate drivers for (%s,%u): %s\n",
4415 architecture, version, win_errstr(result)));
4419 *drivers_p = talloc_steal(mem_ctx, drivers);
4423 if (winreg_handle != NULL) {
4426 if (is_valid_policy_hnd(&key_hnd)) {
4427 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4429 if (is_valid_policy_hnd(&hive_hnd)) {
4430 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4434 TALLOC_FREE(tmp_ctx);