2 * Unix SMB/CIFS implementation.
4 * SPOOLSS RPC Pipe server / winreg client routines
6 * Copyright (c) 2010 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "nt_printing.h"
24 #include "srv_spoolss_util.h"
25 #include "../librpc/gen_ndr/ndr_spoolss.h"
26 #include "../librpc/gen_ndr/srv_winreg.h"
27 #include "../librpc/gen_ndr/ndr_winreg_c.h"
28 #include "../librpc/gen_ndr/ndr_security.h"
30 #include "rpc_server/rpc_ncacn_np.h"
31 #include "../libcli/security/security.h"
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;
1223 str = talloc_strdup(mem_ctx, "01/01/1601");
1225 t = nt_time_to_unix(data);
1227 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
1228 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
1234 wvalue.name = value;
1235 if (!push_reg_sz(mem_ctx, &blob, str)) {
1238 status = dcerpc_winreg_SetValue(winreg_handle,
1246 if (!NT_STATUS_IS_OK(status)) {
1247 result = ntstatus_to_werror(status);
1249 if (!W_ERROR_IS_OK(result)) {
1250 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1251 wvalue.name, win_errstr(result)));
1257 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
1262 if (strequal(str, "01/01/1601")) {
1269 if (sscanf(str, "%d/%d/%d",
1270 &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3) {
1271 return WERR_INVALID_PARAMETER;
1278 unix_to_nt_time(data, t);
1283 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
1284 struct dcerpc_binding_handle *winreg_handle,
1285 struct policy_handle *key_handle,
1289 struct winreg_String wvalue;
1291 WERROR result = WERR_OK;
1295 /* FIXME: check format is right,
1296 * this needs to be something like: 6.1.7600.16385 */
1297 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
1298 (unsigned)((data >> 48) & 0xFFFF),
1299 (unsigned)((data >> 32) & 0xFFFF),
1300 (unsigned)((data >> 16) & 0xFFFF),
1301 (unsigned)(data & 0xFFFF));
1306 wvalue.name = value;
1307 if (!push_reg_sz(mem_ctx, &blob, str)) {
1310 status = dcerpc_winreg_SetValue(winreg_handle,
1318 if (!NT_STATUS_IS_OK(status)) {
1319 result = ntstatus_to_werror(status);
1321 if (!W_ERROR_IS_OK(result)) {
1322 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1323 wvalue.name, win_errstr(result)));
1329 static WERROR winreg_printer_ver_to_dword(const char *str, uint64_t *data)
1331 unsigned int v1, v2, v3, v4;
1333 if (sscanf(str, "%u.%u.%u.%u", &v1, &v2, &v3, &v4) != 4) {
1334 return WERR_INVALID_PARAMETER;
1337 *data = ((uint64_t)(v1 & 0xFFFF) << 48) +
1338 ((uint64_t)(v2 & 0xFFFF) << 32) +
1339 ((uint64_t)(v3 & 0xFFFF) << 16) +
1340 (uint64_t)(v2 & 0xFFFF);
1345 /********************************************************************
1346 Public winreg function for spoolss
1347 ********************************************************************/
1349 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
1350 const struct auth_serversupplied_info *server_info,
1351 struct messaging_context *msg_ctx,
1352 const char *sharename)
1354 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1355 struct dcerpc_binding_handle *winreg_handle = NULL;
1356 struct policy_handle hive_hnd, key_hnd;
1357 struct spoolss_SetPrinterInfo2 *info2;
1358 struct security_descriptor *secdesc;
1359 struct winreg_String wkey, wkeyclass;
1361 const char *subkeys[] = { SPOOL_DSDRIVER_KEY, SPOOL_DSSPOOLER_KEY, SPOOL_PRINTERDATA_KEY };
1362 uint32_t i, count = ARRAY_SIZE(subkeys);
1363 uint32_t info2_mask = 0;
1364 WERROR result = WERR_OK;
1365 TALLOC_CTX *tmp_ctx;
1367 tmp_ctx = talloc_stackframe();
1368 if (tmp_ctx == NULL) {
1372 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1374 TALLOC_FREE(tmp_ctx);
1378 ZERO_STRUCT(hive_hnd);
1379 ZERO_STRUCT(key_hnd);
1381 result = winreg_printer_openkey(tmp_ctx,
1391 if (W_ERROR_IS_OK(result)) {
1392 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
1394 } else if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1395 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
1396 } else if (!W_ERROR_IS_OK(result)) {
1397 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
1398 path, win_errstr(result)));
1402 /* Create the main key */
1403 result = winreg_printer_openkey(tmp_ctx,
1413 if (!W_ERROR_IS_OK(result)) {
1414 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1415 path, win_errstr(result)));
1419 if (is_valid_policy_hnd(&key_hnd)) {
1420 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
1423 /* Create subkeys */
1424 for (i = 0; i < count; i++) {
1426 enum winreg_CreateAction action = REG_ACTION_NONE;
1428 ZERO_STRUCT(key_hnd);
1431 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
1432 if (wkey.name == NULL) {
1433 result = WERR_NOMEM;
1437 ZERO_STRUCT(wkeyclass);
1438 wkeyclass.name = "";
1440 status = dcerpc_winreg_CreateKey(winreg_handle,
1451 if (!NT_STATUS_IS_OK(status)) {
1452 result = ntstatus_to_werror(status);
1454 if (!W_ERROR_IS_OK(result)) {
1455 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1456 wkey.name, win_errstr(result)));
1460 if (strequal(subkeys[i], SPOOL_DSSPOOLER_KEY)) {
1461 const char *dnssuffix;
1462 const char *longname;
1463 const char *uncname;
1465 result = winreg_printer_write_sz(tmp_ctx,
1468 SPOOL_REG_PRINTERNAME,
1470 if (!W_ERROR_IS_OK(result)) {
1474 result = winreg_printer_write_sz(tmp_ctx,
1477 SPOOL_REG_SHORTSERVERNAME,
1479 if (!W_ERROR_IS_OK(result)) {
1483 /* We make the assumption that the netbios name
1484 * is the same as the DNS name since the former
1485 * will be what we used to join the domain
1487 dnssuffix = get_mydnsdomname(tmp_ctx);
1488 if (dnssuffix != NULL && dnssuffix[0] != '\0') {
1489 longname = talloc_asprintf(tmp_ctx, "%s.%s", global_myname(), dnssuffix);
1491 longname = talloc_strdup(tmp_ctx, global_myname());
1493 if (longname == NULL) {
1494 result = WERR_NOMEM;
1498 result = winreg_printer_write_sz(tmp_ctx,
1501 SPOOL_REG_SERVERNAME,
1503 if (!W_ERROR_IS_OK(result)) {
1507 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
1508 longname, sharename);
1509 if (uncname == NULL) {
1510 result = WERR_NOMEM;
1514 result = winreg_printer_write_sz(tmp_ctx,
1519 if (!W_ERROR_IS_OK(result)) {
1523 result = winreg_printer_write_dword(tmp_ctx,
1526 SPOOL_REG_VERSIONNUMBER,
1528 if (!W_ERROR_IS_OK(result)) {
1532 result = winreg_printer_write_dword(tmp_ctx,
1535 SPOOL_REG_PRINTSTARTTIME,
1537 if (!W_ERROR_IS_OK(result)) {
1541 result = winreg_printer_write_dword(tmp_ctx,
1544 SPOOL_REG_PRINTENDTIME,
1546 if (!W_ERROR_IS_OK(result)) {
1550 result = winreg_printer_write_dword(tmp_ctx,
1555 if (!W_ERROR_IS_OK(result)) {
1559 result = winreg_printer_write_dword(tmp_ctx,
1562 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
1564 if (!W_ERROR_IS_OK(result)) {
1569 if (is_valid_policy_hnd(&key_hnd)) {
1570 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
1573 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
1574 if (info2 == NULL) {
1575 result = WERR_NOMEM;
1579 info2->printername = sharename;
1580 if (info2->printername == NULL) {
1581 result = WERR_NOMEM;
1584 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1586 info2->sharename = sharename;
1587 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1589 info2->portname = SAMBA_PRINTER_PORT_NAME;
1590 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1592 info2->printprocessor = "winprint";
1593 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1595 info2->datatype = "RAW";
1596 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1598 info2->comment = "";
1599 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1601 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1602 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1604 info2->starttime = 0; /* Minutes since 12:00am GMT */
1605 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1607 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1608 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1610 info2->priority = 1;
1611 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1613 info2->defaultpriority = 1;
1614 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1616 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1617 if (!W_ERROR_IS_OK(result)) {
1620 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1623 * Don't write a default Device Mode to the registry! The Device Mode is
1624 * only written to disk with a SetPrinter level 2 or 8.
1627 result = winreg_update_printer(tmp_ctx,
1637 if (winreg_handle != NULL) {
1640 if (is_valid_policy_hnd(&key_hnd)) {
1641 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1643 if (is_valid_policy_hnd(&hive_hnd)) {
1644 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1648 talloc_free(tmp_ctx);
1652 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1653 const struct auth_serversupplied_info *server_info,
1654 struct messaging_context *msg_ctx,
1655 const char *sharename,
1656 uint32_t info2_mask,
1657 struct spoolss_SetPrinterInfo2 *info2,
1658 struct spoolss_DeviceMode *devmode,
1659 struct security_descriptor *secdesc)
1661 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1662 struct dcerpc_binding_handle *winreg_handle = NULL;
1663 struct policy_handle hive_hnd, key_hnd;
1664 int snum = lp_servicenumber(sharename);
1665 enum ndr_err_code ndr_err;
1668 WERROR result = WERR_OK;
1669 TALLOC_CTX *tmp_ctx;
1671 tmp_ctx = talloc_stackframe();
1672 if (tmp_ctx == NULL) {
1676 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1678 TALLOC_FREE(tmp_ctx);
1682 ZERO_STRUCT(hive_hnd);
1683 ZERO_STRUCT(key_hnd);
1685 result = winreg_printer_openkey(tmp_ctx,
1695 if (!W_ERROR_IS_OK(result)) {
1696 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1697 path, win_errstr(result)));
1701 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1702 result = winreg_printer_write_dword(tmp_ctx,
1707 if (!W_ERROR_IS_OK(result)) {
1713 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1714 result = winreg_printer_write_dword(tmp_ctx,
1719 if (!W_ERROR_IS_OK(result)) {
1725 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1726 result = winreg_printer_write_sz(tmp_ctx,
1731 if (!W_ERROR_IS_OK(result)) {
1736 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1737 result = winreg_printer_write_sz(tmp_ctx,
1742 if (!W_ERROR_IS_OK(result)) {
1747 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1748 result = winreg_printer_write_dword(tmp_ctx,
1752 info2->defaultpriority);
1753 if (!W_ERROR_IS_OK(result)) {
1758 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1760 * Some client drivers freak out if there is a NULL devmode
1761 * (probably the driver is not checking before accessing
1762 * the devmode pointer) --jerry
1764 if (devmode == NULL && lp_default_devmode(snum) && info2 != NULL) {
1765 result = spoolss_create_default_devmode(tmp_ctx,
1768 if (!W_ERROR_IS_OK(result)) {
1773 if (devmode->size != (ndr_size_spoolss_DeviceMode(devmode, 0) - devmode->__driverextra_length)) {
1774 result = WERR_INVALID_PARAM;
1778 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, devmode,
1779 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1780 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1781 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1782 result = WERR_NOMEM;
1786 result = winreg_printer_write_binary(tmp_ctx,
1791 if (!W_ERROR_IS_OK(result)) {
1796 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1797 result = winreg_printer_write_sz(tmp_ctx,
1802 if (!W_ERROR_IS_OK(result)) {
1807 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1808 result = winreg_printer_write_sz(tmp_ctx,
1813 if (!W_ERROR_IS_OK(result)) {
1818 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1819 result = winreg_printer_write_sz(tmp_ctx,
1824 if (!W_ERROR_IS_OK(result)) {
1829 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1830 result = winreg_printer_write_sz(tmp_ctx,
1835 if (!W_ERROR_IS_OK(result)) {
1840 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1842 * in addprinter: no servername and the printer is the name
1843 * in setprinter: servername is \\server
1844 * and printer is \\server\\printer
1846 * Samba manages only local printers.
1847 * we currently don't support things like i
1848 * path=\\other_server\printer
1850 * We only store the printername, not \\server\printername
1852 const char *p = strrchr(info2->printername, '\\');
1854 p = info2->printername;
1858 result = winreg_printer_write_sz(tmp_ctx,
1863 if (!W_ERROR_IS_OK(result)) {
1868 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1869 result = winreg_printer_write_sz(tmp_ctx,
1873 info2->printprocessor);
1874 if (!W_ERROR_IS_OK(result)) {
1879 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1880 result = winreg_printer_write_dword(tmp_ctx,
1885 if (!W_ERROR_IS_OK(result)) {
1890 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1892 * We need a security descriptor, if it isn't specified by
1893 * AddPrinter{Ex} then create a default descriptor.
1895 if (secdesc == NULL) {
1896 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1897 if (!W_ERROR_IS_OK(result)) {
1901 result = winreg_set_printer_secdesc(tmp_ctx,
1906 if (!W_ERROR_IS_OK(result)) {
1911 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1912 result = winreg_printer_write_sz(tmp_ctx,
1917 if (!W_ERROR_IS_OK(result)) {
1922 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1923 result = winreg_printer_write_sz(tmp_ctx,
1928 if (!W_ERROR_IS_OK(result)) {
1933 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1934 result = winreg_printer_write_dword(tmp_ctx,
1939 if (!W_ERROR_IS_OK(result)) {
1944 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1945 result = winreg_printer_write_dword(tmp_ctx,
1950 if (!W_ERROR_IS_OK(result)) {
1955 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1956 result = winreg_printer_write_dword(tmp_ctx,
1961 if (!W_ERROR_IS_OK(result)) {
1966 result = winreg_printer_write_dword(tmp_ctx,
1970 winreg_printer_rev_changeid());
1971 if (!W_ERROR_IS_OK(result)) {
1977 if (winreg_handle != NULL) {
1980 if (is_valid_policy_hnd(&key_hnd)) {
1981 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1983 if (is_valid_policy_hnd(&hive_hnd)) {
1984 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1988 TALLOC_FREE(tmp_ctx);
1992 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1993 const struct auth_serversupplied_info *server_info,
1994 struct messaging_context *msg_ctx,
1995 const char *printer,
1996 struct spoolss_PrinterInfo2 **pinfo2)
1998 struct spoolss_PrinterInfo2 *info2;
1999 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2000 struct dcerpc_binding_handle *winreg_handle = NULL;
2001 struct policy_handle hive_hnd, key_hnd;
2002 struct spoolss_PrinterEnumValues *enum_values = NULL;
2003 struct spoolss_PrinterEnumValues *v;
2004 enum ndr_err_code ndr_err;
2006 int snum = lp_servicenumber(printer);
2007 uint32_t num_values = 0;
2010 WERROR result = WERR_OK;
2011 TALLOC_CTX *tmp_ctx;
2013 tmp_ctx = talloc_stackframe();
2014 if (tmp_ctx == NULL) {
2018 path = winreg_printer_data_keyname(tmp_ctx, printer);
2020 TALLOC_FREE(tmp_ctx);
2024 result = winreg_printer_openkey(tmp_ctx,
2034 if (!W_ERROR_IS_OK(result)) {
2035 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
2036 path, win_errstr(result)));
2040 result = winreg_printer_enumvalues(tmp_ctx,
2045 if (!W_ERROR_IS_OK(result)) {
2046 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
2047 path, win_errstr(result)));
2051 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
2052 if (info2 == NULL) {
2053 result = WERR_NOMEM;
2057 FILL_STRING(info2, EMPTY_STRING, info2->servername);
2058 FILL_STRING(info2, EMPTY_STRING, info2->printername);
2059 FILL_STRING(info2, EMPTY_STRING, info2->sharename);
2060 FILL_STRING(info2, EMPTY_STRING, info2->portname);
2061 FILL_STRING(info2, EMPTY_STRING, info2->drivername);
2062 FILL_STRING(info2, EMPTY_STRING, info2->comment);
2063 FILL_STRING(info2, EMPTY_STRING, info2->location);
2064 FILL_STRING(info2, EMPTY_STRING, info2->sepfile);
2065 FILL_STRING(info2, EMPTY_STRING, info2->printprocessor);
2066 FILL_STRING(info2, EMPTY_STRING, info2->datatype);
2067 FILL_STRING(info2, EMPTY_STRING, info2->parameters);
2069 for (i = 0; i < num_values; i++) {
2070 v = &enum_values[i];
2072 result = winreg_enumval_to_sz(info2,
2075 &info2->printername);
2076 CHECK_ERROR(result);
2078 result = winreg_enumval_to_sz(info2,
2082 CHECK_ERROR(result);
2084 result = winreg_enumval_to_sz(info2,
2088 CHECK_ERROR(result);
2090 result = winreg_enumval_to_sz(info2,
2094 CHECK_ERROR(result);
2096 result = winreg_enumval_to_sz(info2,
2100 CHECK_ERROR(result);
2102 result = winreg_enumval_to_sz(info2,
2106 CHECK_ERROR(result);
2108 result = winreg_enumval_to_sz(info2,
2111 &info2->printprocessor);
2112 CHECK_ERROR(result);
2114 result = winreg_enumval_to_sz(info2,
2118 CHECK_ERROR(result);
2120 result = winreg_enumval_to_sz(info2,
2123 &info2->parameters);
2124 CHECK_ERROR(result);
2126 result = winreg_enumval_to_sz(info2,
2129 &info2->drivername);
2130 CHECK_ERROR(result);
2132 result = winreg_enumval_to_dword(info2,
2135 &info2->attributes);
2136 CHECK_ERROR(result);
2138 result = winreg_enumval_to_dword(info2,
2142 CHECK_ERROR(result);
2144 result = winreg_enumval_to_dword(info2,
2147 &info2->defaultpriority);
2148 CHECK_ERROR(result);
2150 result = winreg_enumval_to_dword(info2,
2154 CHECK_ERROR(result);
2156 result = winreg_enumval_to_dword(info2,
2160 CHECK_ERROR(result);
2162 result = winreg_enumval_to_dword(info2,
2166 CHECK_ERROR(result);
2168 result = winreg_enumval_to_dword(info2,
2172 CHECK_ERROR(result);
2175 if (!W_ERROR_IS_OK(result)) {
2176 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2179 win_errstr(result)));
2183 /* Construct the Device Mode */
2184 result = winreg_printer_query_binary(tmp_ctx,
2189 if (W_ERROR_IS_OK(result)) {
2190 info2->devmode = talloc_zero(info2, struct spoolss_DeviceMode);
2191 if (info2->devmode == NULL) {
2192 result = WERR_NOMEM;
2195 ndr_err = ndr_pull_struct_blob(&blob,
2198 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
2199 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2200 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2201 result = WERR_NOMEM;
2206 if (info2->devmode == NULL && lp_default_devmode(snum)) {
2207 result = spoolss_create_default_devmode(info2,
2210 if (!W_ERROR_IS_OK(result)) {
2215 if (info2->devmode) {
2216 info2->devmode->size = ndr_size_spoolss_DeviceMode(info2->devmode, 0) - info2->devmode->driverextra_data.length;
2219 result = winreg_get_printer_secdesc(info2,
2224 if (!W_ERROR_IS_OK(result)) {
2228 /* Fix for OS/2 drivers. */
2229 if (get_remote_arch() == RA_OS2) {
2230 spoolss_map_to_os2_driver(info2, &info2->drivername);
2234 *pinfo2 = talloc_move(mem_ctx, &info2);
2239 if (winreg_handle != NULL) {
2242 if (is_valid_policy_hnd(&key_hnd)) {
2243 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2245 if (is_valid_policy_hnd(&hive_hnd)) {
2246 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2250 TALLOC_FREE(tmp_ctx);
2254 WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
2255 const struct auth_serversupplied_info *server_info,
2256 struct messaging_context *msg_ctx,
2257 const char *sharename,
2258 struct spoolss_security_descriptor **psecdesc)
2260 struct spoolss_security_descriptor *secdesc;
2261 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2262 struct dcerpc_binding_handle *winreg_handle = NULL;
2263 struct policy_handle hive_hnd, key_hnd;
2264 enum ndr_err_code ndr_err;
2267 TALLOC_CTX *tmp_ctx;
2270 tmp_ctx = talloc_stackframe();
2271 if (tmp_ctx == NULL) {
2275 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2277 talloc_free(tmp_ctx);
2281 ZERO_STRUCT(hive_hnd);
2282 ZERO_STRUCT(key_hnd);
2284 result = winreg_printer_openkey(tmp_ctx,
2294 if (!W_ERROR_IS_OK(result)) {
2295 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2296 goto create_default;
2301 result = winreg_printer_query_binary(tmp_ctx,
2306 if (!W_ERROR_IS_OK(result)) {
2307 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2308 goto create_default;
2313 secdesc = talloc_zero(tmp_ctx, struct spoolss_security_descriptor);
2314 if (secdesc == NULL) {
2315 result = WERR_NOMEM;
2318 ndr_err = ndr_pull_struct_blob(&blob,
2321 (ndr_pull_flags_fn_t) ndr_pull_security_descriptor);
2322 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2323 DEBUG(0, ("winreg_get_secdesc: Failed to unmarshall security descriptor\n"));
2324 result = WERR_NOMEM;
2329 *psecdesc = talloc_move(mem_ctx, &secdesc);
2336 result = winreg_printer_openkey(tmp_ctx,
2346 if (!W_ERROR_IS_OK(result)) {
2350 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
2351 if (!W_ERROR_IS_OK(result)) {
2355 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
2356 this security descriptor has been created when winbindd was
2357 down. Take ownership of security descriptor. */
2358 if (dom_sid_equal(secdesc->owner_sid, &global_sid_World)) {
2359 struct dom_sid owner_sid;
2361 /* Change sd owner to workgroup administrator */
2363 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid)) {
2364 struct spoolss_security_descriptor *new_secdesc;
2368 sid_append_rid(&owner_sid, DOMAIN_RID_ADMINISTRATOR);
2370 new_secdesc = make_sec_desc(tmp_ctx,
2379 if (new_secdesc == NULL) {
2380 result = WERR_NOMEM;
2384 /* Swap with other one */
2385 secdesc = new_secdesc;
2389 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, secdesc,
2390 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2391 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2392 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2393 result = WERR_NOMEM;
2397 result = winreg_printer_write_binary(tmp_ctx,
2402 if (!W_ERROR_IS_OK(result)) {
2407 *psecdesc = talloc_move(mem_ctx, &secdesc);
2412 if (winreg_handle != NULL) {
2415 if (is_valid_policy_hnd(&key_hnd)) {
2416 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2418 if (is_valid_policy_hnd(&hive_hnd)) {
2419 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2423 talloc_free(tmp_ctx);
2427 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
2428 const struct auth_serversupplied_info *server_info,
2429 struct messaging_context *msg_ctx,
2430 const char *sharename,
2431 const struct spoolss_security_descriptor *secdesc)
2433 const struct spoolss_security_descriptor *new_secdesc = secdesc;
2434 struct spoolss_security_descriptor *old_secdesc;
2435 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2436 struct dcerpc_binding_handle *winreg_handle = NULL;
2437 struct policy_handle hive_hnd, key_hnd;
2438 enum ndr_err_code ndr_err;
2441 TALLOC_CTX *tmp_ctx;
2444 tmp_ctx = talloc_stackframe();
2445 if (tmp_ctx == NULL) {
2449 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2451 talloc_free(tmp_ctx);
2456 * The old owner and group sids of the security descriptor are not
2457 * present when new ACEs are added or removed by changing printer
2458 * permissions through NT. If they are NULL in the new security
2459 * descriptor then copy them over from the old one.
2461 if (!secdesc->owner_sid || !secdesc->group_sid) {
2462 struct dom_sid *owner_sid, *group_sid;
2463 struct security_acl *dacl, *sacl;
2466 result = winreg_get_printer_secdesc(tmp_ctx,
2471 if (!W_ERROR_IS_OK(result)) {
2472 talloc_free(tmp_ctx);
2476 /* Pick out correct owner and group sids */
2477 owner_sid = secdesc->owner_sid ?
2478 secdesc->owner_sid :
2479 old_secdesc->owner_sid;
2481 group_sid = secdesc->group_sid ?
2482 secdesc->group_sid :
2483 old_secdesc->group_sid;
2485 dacl = secdesc->dacl ?
2489 sacl = secdesc->sacl ?
2493 /* Make a deep copy of the security descriptor */
2494 new_secdesc = make_sec_desc(tmp_ctx,
2502 if (new_secdesc == NULL) {
2503 talloc_free(tmp_ctx);
2508 ZERO_STRUCT(hive_hnd);
2509 ZERO_STRUCT(key_hnd);
2511 result = winreg_printer_openkey(tmp_ctx,
2521 if (!W_ERROR_IS_OK(result)) {
2525 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, new_secdesc,
2526 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2527 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2528 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2529 result = WERR_NOMEM;
2533 result = winreg_printer_write_binary(tmp_ctx,
2540 if (winreg_handle != NULL) {
2543 if (is_valid_policy_hnd(&key_hnd)) {
2544 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2546 if (is_valid_policy_hnd(&hive_hnd)) {
2547 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2551 talloc_free(tmp_ctx);
2555 /* Set printer data over the winreg pipe. */
2556 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2557 const struct auth_serversupplied_info *server_info,
2558 struct messaging_context *msg_ctx,
2559 const char *printer,
2562 enum winreg_Type type,
2566 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2567 struct dcerpc_binding_handle *winreg_handle = NULL;
2568 struct policy_handle hive_hnd, key_hnd;
2569 struct winreg_String wvalue;
2571 WERROR result = WERR_OK;
2573 TALLOC_CTX *tmp_ctx;
2575 tmp_ctx = talloc_stackframe();
2576 if (tmp_ctx == NULL) {
2580 path = winreg_printer_data_keyname(tmp_ctx, printer);
2582 TALLOC_FREE(tmp_ctx);
2586 ZERO_STRUCT(hive_hnd);
2587 ZERO_STRUCT(key_hnd);
2589 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2590 key, value, access_mask, printer));
2591 result = winreg_printer_openkey(tmp_ctx,
2601 if (!W_ERROR_IS_OK(result)) {
2602 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2603 key, win_errstr(result)));
2607 wvalue.name = value;
2608 status = dcerpc_winreg_SetValue(winreg_handle,
2616 if (!NT_STATUS_IS_OK(status)) {
2617 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2618 value, nt_errstr(status)));
2619 result = ntstatus_to_werror(status);
2623 if (winreg_handle != NULL) {
2626 if (is_valid_policy_hnd(&key_hnd)) {
2627 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2629 if (is_valid_policy_hnd(&hive_hnd)) {
2630 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2634 TALLOC_FREE(tmp_ctx);
2638 /* Get printer data over a winreg pipe. */
2639 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2640 const struct auth_serversupplied_info *server_info,
2641 struct messaging_context *msg_ctx,
2642 const char *printer,
2645 enum winreg_Type *type,
2647 uint32_t *data_size)
2649 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2650 struct dcerpc_binding_handle *winreg_handle = NULL;
2651 struct policy_handle hive_hnd, key_hnd;
2652 struct winreg_String wvalue;
2653 enum winreg_Type type_in;
2656 uint32_t data_in_size = 0;
2657 uint32_t value_len = 0;
2658 WERROR result = WERR_OK;
2660 TALLOC_CTX *tmp_ctx;
2662 tmp_ctx = talloc_stackframe();
2663 if (tmp_ctx == NULL) {
2667 path = winreg_printer_data_keyname(tmp_ctx, printer);
2669 TALLOC_FREE(tmp_ctx);
2673 ZERO_STRUCT(hive_hnd);
2674 ZERO_STRUCT(key_hnd);
2676 result = winreg_printer_openkey(tmp_ctx,
2686 if (!W_ERROR_IS_OK(result)) {
2687 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2688 key, win_errstr(result)));
2692 wvalue.name = value;
2695 * call QueryValue once with data == NULL to get the
2696 * needed memory size to be allocated, then allocate
2697 * data buffer and call again.
2699 status = dcerpc_winreg_QueryValue(winreg_handle,
2708 if (!NT_STATUS_IS_OK(status)) {
2709 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2710 value, nt_errstr(status)));
2711 result = ntstatus_to_werror(status);
2714 if (!W_ERROR_IS_OK(result)) {
2718 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2719 if (data_in == NULL) {
2720 result = WERR_NOMEM;
2725 status = dcerpc_winreg_QueryValue(winreg_handle,
2734 if (!NT_STATUS_IS_OK(status)) {
2735 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2736 value, nt_errstr(status)));
2737 result = ntstatus_to_werror(status);
2740 if (!W_ERROR_IS_OK(result)) {
2745 *data_size = data_in_size;
2747 *data = talloc_move(mem_ctx, &data_in);
2752 if (winreg_handle != NULL) {
2755 if (is_valid_policy_hnd(&key_hnd)) {
2756 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2758 if (is_valid_policy_hnd(&hive_hnd)) {
2759 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2763 TALLOC_FREE(tmp_ctx);
2767 /* Enumerate on the values of a given key and provide the data. */
2768 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2769 const struct auth_serversupplied_info *server_info,
2770 struct messaging_context *msg_ctx,
2771 const char *printer,
2773 uint32_t *pnum_values,
2774 struct spoolss_PrinterEnumValues **penum_values)
2776 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2777 struct dcerpc_binding_handle *winreg_handle = NULL;
2778 struct policy_handle hive_hnd, key_hnd;
2780 struct spoolss_PrinterEnumValues *enum_values = NULL;
2781 uint32_t num_values = 0;
2783 WERROR result = WERR_OK;
2785 TALLOC_CTX *tmp_ctx;
2787 tmp_ctx = talloc_stackframe();
2788 if (tmp_ctx == NULL) {
2792 path = winreg_printer_data_keyname(tmp_ctx, printer);
2794 TALLOC_FREE(tmp_ctx);
2798 result = winreg_printer_openkey(tmp_ctx,
2808 if (!W_ERROR_IS_OK(result)) {
2809 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2810 key, win_errstr(result)));
2814 result = winreg_printer_enumvalues(tmp_ctx,
2819 if (!W_ERROR_IS_OK(result)) {
2820 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2821 key, win_errstr(result)));
2825 *pnum_values = num_values;
2827 *penum_values = talloc_move(mem_ctx, &enum_values);
2832 if (winreg_handle != NULL) {
2835 if (is_valid_policy_hnd(&key_hnd)) {
2836 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2838 if (is_valid_policy_hnd(&hive_hnd)) {
2839 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2843 TALLOC_FREE(tmp_ctx);
2847 /* Delete printer data over a winreg pipe. */
2848 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2849 const struct auth_serversupplied_info *server_info,
2850 struct messaging_context *msg_ctx,
2851 const char *printer,
2855 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2856 struct dcerpc_binding_handle *winreg_handle = NULL;
2857 struct policy_handle hive_hnd, key_hnd;
2858 struct winreg_String wvalue;
2860 WERROR result = WERR_OK;
2863 TALLOC_CTX *tmp_ctx;
2865 tmp_ctx = talloc_stackframe();
2866 if (tmp_ctx == NULL) {
2870 path = winreg_printer_data_keyname(tmp_ctx, printer);
2872 TALLOC_FREE(tmp_ctx);
2876 ZERO_STRUCT(hive_hnd);
2877 ZERO_STRUCT(key_hnd);
2879 result = winreg_printer_openkey(tmp_ctx,
2889 if (!W_ERROR_IS_OK(result)) {
2890 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2891 key, win_errstr(result)));
2895 wvalue.name = value;
2896 status = dcerpc_winreg_DeleteValue(winreg_handle,
2901 if (!NT_STATUS_IS_OK(status)) {
2902 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2903 value, nt_errstr(status)));
2904 result = ntstatus_to_werror(status);
2908 if (winreg_handle != NULL) {
2911 if (is_valid_policy_hnd(&key_hnd)) {
2912 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2914 if (is_valid_policy_hnd(&hive_hnd)) {
2915 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2919 TALLOC_FREE(tmp_ctx);
2923 /* Enumerate on the subkeys of a given key and provide the data. */
2924 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2925 const struct auth_serversupplied_info *server_info,
2926 struct messaging_context *msg_ctx,
2927 const char *printer,
2929 uint32_t *pnum_subkeys,
2930 const char ***psubkeys)
2932 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2933 struct dcerpc_binding_handle *winreg_handle = NULL;
2934 struct policy_handle hive_hnd, key_hnd;
2936 const char **subkeys = NULL;
2937 uint32_t num_subkeys = -1;
2939 WERROR result = WERR_OK;
2941 TALLOC_CTX *tmp_ctx;
2943 tmp_ctx = talloc_stackframe();
2944 if (tmp_ctx == NULL) {
2948 path = winreg_printer_data_keyname(tmp_ctx, printer);
2950 TALLOC_FREE(tmp_ctx);
2954 ZERO_STRUCT(hive_hnd);
2955 ZERO_STRUCT(key_hnd);
2957 result = winreg_printer_openkey(tmp_ctx,
2967 if (!W_ERROR_IS_OK(result)) {
2968 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2969 key, win_errstr(result)));
2973 result = winreg_printer_enumkeys(tmp_ctx,
2978 if (!W_ERROR_IS_OK(result)) {
2979 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2980 key, win_errstr(result)));
2984 *pnum_subkeys = num_subkeys;
2986 *psubkeys = talloc_move(mem_ctx, &subkeys);
2991 if (winreg_handle != NULL) {
2994 if (is_valid_policy_hnd(&key_hnd)) {
2995 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2997 if (is_valid_policy_hnd(&hive_hnd)) {
2998 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3002 TALLOC_FREE(tmp_ctx);
3006 /* Delete a key with subkeys of a given printer. */
3007 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
3008 const struct auth_serversupplied_info *server_info,
3009 struct messaging_context *msg_ctx,
3010 const char *printer,
3013 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3014 struct dcerpc_binding_handle *winreg_handle = NULL;
3015 struct policy_handle hive_hnd, key_hnd;
3019 TALLOC_CTX *tmp_ctx;
3021 tmp_ctx = talloc_stackframe();
3022 if (tmp_ctx == NULL) {
3026 path = winreg_printer_data_keyname(tmp_ctx, printer);
3028 TALLOC_FREE(tmp_ctx);
3032 result = winreg_printer_openkey(tmp_ctx,
3042 if (!W_ERROR_IS_OK(result)) {
3043 /* key doesn't exist */
3044 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3049 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
3050 key, win_errstr(result)));
3054 if (is_valid_policy_hnd(&key_hnd)) {
3055 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
3058 if (key == NULL || key[0] == '\0') {
3061 keyname = talloc_asprintf(tmp_ctx,
3065 if (keyname == NULL) {
3066 result = WERR_NOMEM;
3071 result = winreg_printer_delete_subkeys(tmp_ctx,
3076 if (!W_ERROR_IS_OK(result)) {
3077 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
3078 key, win_errstr(result)));
3083 if (winreg_handle != NULL) {
3086 if (is_valid_policy_hnd(&key_hnd)) {
3087 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3089 if (is_valid_policy_hnd(&hive_hnd)) {
3090 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3094 TALLOC_FREE(tmp_ctx);
3098 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
3099 const struct auth_serversupplied_info *server_info,
3100 struct messaging_context *msg_ctx,
3101 const char *printer)
3103 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3104 struct dcerpc_binding_handle *winreg_handle = NULL;
3105 struct policy_handle hive_hnd, key_hnd;
3108 TALLOC_CTX *tmp_ctx;
3110 tmp_ctx = talloc_stackframe();
3111 if (tmp_ctx == NULL) {
3115 path = winreg_printer_data_keyname(tmp_ctx, printer);
3117 TALLOC_FREE(tmp_ctx);
3121 ZERO_STRUCT(hive_hnd);
3122 ZERO_STRUCT(key_hnd);
3124 result = winreg_printer_openkey(tmp_ctx,
3134 if (!W_ERROR_IS_OK(result)) {
3135 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
3136 path, win_errstr(result)));
3140 result = winreg_printer_write_dword(tmp_ctx,
3144 winreg_printer_rev_changeid());
3145 if (!W_ERROR_IS_OK(result)) {
3151 if (winreg_handle != NULL) {
3154 if (is_valid_policy_hnd(&key_hnd)) {
3155 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3157 if (is_valid_policy_hnd(&hive_hnd)) {
3158 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3162 TALLOC_FREE(tmp_ctx);
3166 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
3167 const struct auth_serversupplied_info *server_info,
3168 struct messaging_context *msg_ctx,
3169 const char *printer,
3170 uint32_t *pchangeid)
3172 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3173 struct dcerpc_binding_handle *winreg_handle = NULL;
3174 struct policy_handle hive_hnd, key_hnd;
3175 uint32_t changeid = 0;
3178 TALLOC_CTX *tmp_ctx;
3180 tmp_ctx = talloc_stackframe();
3181 if (tmp_ctx == NULL) {
3185 path = winreg_printer_data_keyname(tmp_ctx, printer);
3187 TALLOC_FREE(tmp_ctx);
3191 ZERO_STRUCT(hive_hnd);
3192 ZERO_STRUCT(key_hnd);
3194 result = winreg_printer_openkey(tmp_ctx,
3204 if (!W_ERROR_IS_OK(result)) {
3205 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
3206 path, win_errstr(result)));
3210 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path));
3212 result = winreg_printer_query_dword(tmp_ctx,
3217 if (!W_ERROR_IS_OK(result)) {
3222 *pchangeid = changeid;
3227 if (winreg_handle != NULL) {
3230 if (is_valid_policy_hnd(&key_hnd)) {
3231 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3233 if (is_valid_policy_hnd(&hive_hnd)) {
3234 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3238 TALLOC_FREE(tmp_ctx);
3243 * The special behaviour of the spoolss forms is documented at the website:
3245 * Managing Win32 Printserver Forms
3246 * http://unixwiz.net/techtips/winspooler-forms.html
3249 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
3250 const struct auth_serversupplied_info *server_info,
3251 struct messaging_context *msg_ctx,
3252 struct spoolss_AddFormInfo1 *form)
3254 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3255 struct dcerpc_binding_handle *winreg_handle = NULL;
3256 struct policy_handle hive_hnd, key_hnd;
3257 struct winreg_String wvalue;
3259 uint32_t num_info = 0;
3260 union spoolss_FormInfo *info = NULL;
3264 TALLOC_CTX *tmp_ctx;
3266 tmp_ctx = talloc_stackframe();
3267 if (tmp_ctx == NULL) {
3271 ZERO_STRUCT(hive_hnd);
3272 ZERO_STRUCT(key_hnd);
3274 result = winreg_printer_openkey(tmp_ctx,
3278 TOP_LEVEL_CONTROL_FORMS_KEY,
3284 if (!W_ERROR_IS_OK(result)) {
3285 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
3286 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3290 result = winreg_printer_enumforms1(tmp_ctx, server_info, msg_ctx,
3292 if (!W_ERROR_IS_OK(result)) {
3293 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
3294 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3298 /* If form name already exists or is builtin return ALREADY_EXISTS */
3299 for (i = 0; i < num_info; i++) {
3300 if (strequal(info[i].info1.form_name, form->form_name)) {
3301 result = WERR_FILE_EXISTS;
3306 wvalue.name = form->form_name;
3308 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3309 SIVAL(blob.data, 0, form->size.width);
3310 SIVAL(blob.data, 4, form->size.height);
3311 SIVAL(blob.data, 8, form->area.left);
3312 SIVAL(blob.data, 12, form->area.top);
3313 SIVAL(blob.data, 16, form->area.right);
3314 SIVAL(blob.data, 20, form->area.bottom);
3315 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
3316 SIVAL(blob.data, 28, form->flags);
3318 status = dcerpc_winreg_SetValue(winreg_handle,
3326 if (!NT_STATUS_IS_OK(status)) {
3327 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
3328 wvalue.name, nt_errstr(status)));
3329 result = ntstatus_to_werror(status);
3333 if (winreg_handle != NULL) {
3336 if (is_valid_policy_hnd(&key_hnd)) {
3337 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3339 if (is_valid_policy_hnd(&hive_hnd)) {
3340 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3345 TALLOC_FREE(tmp_ctx);
3349 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
3350 const struct auth_serversupplied_info *server_info,
3351 struct messaging_context *msg_ctx,
3352 uint32_t *pnum_info,
3353 union spoolss_FormInfo **pinfo)
3355 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3356 struct dcerpc_binding_handle *winreg_handle = NULL;
3357 struct policy_handle hive_hnd, key_hnd;
3358 union spoolss_FormInfo *info;
3359 struct spoolss_PrinterEnumValues *enum_values = NULL;
3360 uint32_t num_values = 0;
3361 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3364 TALLOC_CTX *tmp_ctx;
3366 tmp_ctx = talloc_stackframe();
3367 if (tmp_ctx == NULL) {
3371 ZERO_STRUCT(hive_hnd);
3372 ZERO_STRUCT(key_hnd);
3374 result = winreg_printer_openkey(tmp_ctx,
3378 TOP_LEVEL_CONTROL_FORMS_KEY,
3384 if (!W_ERROR_IS_OK(result)) {
3385 /* key doesn't exist */
3386 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3391 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3392 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3396 result = winreg_printer_enumvalues(tmp_ctx,
3401 if (!W_ERROR_IS_OK(result)) {
3402 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3403 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3407 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
3409 result = WERR_NOMEM;
3413 /* Enumerate BUILTIN forms */
3414 for (i = 0; i < num_builtin; i++) {
3415 info[i].info1 = builtin_forms1[i];
3418 /* Enumerate registry forms */
3419 for (i = 0; i < num_values; i++) {
3420 union spoolss_FormInfo val;
3422 if (enum_values[i].type != REG_BINARY ||
3423 enum_values[i].data_length != 32) {
3427 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
3428 if (val.info1.form_name == NULL) {
3429 result = WERR_NOMEM;
3433 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3434 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3435 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3436 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3437 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3438 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3439 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3440 val.info1.flags = (enum spoolss_FormFlags) IVAL(enum_values[i].data->data, 28);
3442 info[i + num_builtin] = val;
3445 *pnum_info = num_builtin + num_values;
3447 *pinfo = talloc_move(mem_ctx, &info);
3451 if (winreg_handle != NULL) {
3454 if (is_valid_policy_hnd(&key_hnd)) {
3455 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3457 if (is_valid_policy_hnd(&hive_hnd)) {
3458 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3462 TALLOC_FREE(enum_values);
3463 TALLOC_FREE(tmp_ctx);
3467 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3468 const struct auth_serversupplied_info *server_info,
3469 struct messaging_context *msg_ctx,
3470 const char *form_name)
3472 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3473 struct dcerpc_binding_handle *winreg_handle = NULL;
3474 struct policy_handle hive_hnd, key_hnd;
3475 struct winreg_String wvalue;
3476 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3478 WERROR result = WERR_OK;
3480 TALLOC_CTX *tmp_ctx;
3482 for (i = 0; i < num_builtin; i++) {
3483 if (strequal(builtin_forms1[i].form_name, form_name)) {
3484 return WERR_INVALID_PARAMETER;
3488 tmp_ctx = talloc_stackframe();
3489 if (tmp_ctx == NULL) {
3493 ZERO_STRUCT(hive_hnd);
3494 ZERO_STRUCT(key_hnd);
3496 result = winreg_printer_openkey(tmp_ctx,
3500 TOP_LEVEL_CONTROL_FORMS_KEY,
3506 if (!W_ERROR_IS_OK(result)) {
3507 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3508 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3509 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3510 result = WERR_INVALID_FORM_NAME;
3515 wvalue.name = form_name;
3516 status = dcerpc_winreg_DeleteValue(winreg_handle,
3521 if (!NT_STATUS_IS_OK(status)) {
3522 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3523 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3524 wvalue.name, nt_errstr(status)));
3525 result = ntstatus_to_werror(status);
3529 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3530 result = WERR_INVALID_FORM_NAME;
3534 if (winreg_handle != NULL) {
3537 if (is_valid_policy_hnd(&key_hnd)) {
3538 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3540 if (is_valid_policy_hnd(&hive_hnd)) {
3541 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3545 TALLOC_FREE(tmp_ctx);
3549 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3550 const struct auth_serversupplied_info *server_info,
3551 struct messaging_context *msg_ctx,
3552 const char *form_name,
3553 struct spoolss_AddFormInfo1 *form)
3555 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3556 struct dcerpc_binding_handle *winreg_handle = NULL;
3557 struct policy_handle hive_hnd, key_hnd;
3558 struct winreg_String wvalue;
3560 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3564 TALLOC_CTX *tmp_ctx = NULL;
3566 for (i = 0; i < num_builtin; i++) {
3567 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3568 result = WERR_INVALID_PARAM;
3573 tmp_ctx = talloc_stackframe();
3574 if (tmp_ctx == NULL) {
3578 ZERO_STRUCT(hive_hnd);
3579 ZERO_STRUCT(key_hnd);
3581 result = winreg_printer_openkey(tmp_ctx,
3585 TOP_LEVEL_CONTROL_FORMS_KEY,
3591 if (!W_ERROR_IS_OK(result)) {
3592 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3593 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3597 /* If form_name != form->form_name then we renamed the form */
3598 if (strequal(form_name, form->form_name)) {
3599 result = winreg_printer_deleteform1(tmp_ctx, server_info,
3600 msg_ctx, form_name);
3601 if (!W_ERROR_IS_OK(result)) {
3602 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3603 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3608 wvalue.name = form->form_name;
3610 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3611 SIVAL(blob.data, 0, form->size.width);
3612 SIVAL(blob.data, 4, form->size.height);
3613 SIVAL(blob.data, 8, form->area.left);
3614 SIVAL(blob.data, 12, form->area.top);
3615 SIVAL(blob.data, 16, form->area.right);
3616 SIVAL(blob.data, 20, form->area.bottom);
3617 SIVAL(blob.data, 24, 42);
3618 SIVAL(blob.data, 28, form->flags);
3620 status = dcerpc_winreg_SetValue(winreg_handle,
3628 if (!NT_STATUS_IS_OK(status)) {
3629 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3630 wvalue.name, nt_errstr(status)));
3631 result = ntstatus_to_werror(status);
3635 if (winreg_handle != NULL) {
3638 if (is_valid_policy_hnd(&key_hnd)) {
3639 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3641 if (is_valid_policy_hnd(&hive_hnd)) {
3642 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3646 TALLOC_FREE(tmp_ctx);
3650 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3651 const struct auth_serversupplied_info *server_info,
3652 struct messaging_context *msg_ctx,
3653 const char *form_name,
3654 struct spoolss_FormInfo1 *r)
3656 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3657 struct dcerpc_binding_handle *winreg_handle = NULL;
3658 struct policy_handle hive_hnd, key_hnd;
3659 struct winreg_String wvalue;
3660 enum winreg_Type type_in;
3662 uint32_t data_in_size = 0;
3663 uint32_t value_len = 0;
3664 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3668 TALLOC_CTX *tmp_ctx;
3670 /* check builtin forms first */
3671 for (i = 0; i < num_builtin; i++) {
3672 if (strequal(builtin_forms1[i].form_name, form_name)) {
3673 *r = builtin_forms1[i];
3678 tmp_ctx = talloc_stackframe();
3679 if (tmp_ctx == NULL) {
3683 ZERO_STRUCT(hive_hnd);
3684 ZERO_STRUCT(key_hnd);
3686 result = winreg_printer_openkey(tmp_ctx,
3690 TOP_LEVEL_CONTROL_FORMS_KEY,
3696 if (!W_ERROR_IS_OK(result)) {
3697 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3698 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3702 wvalue.name = form_name;
3705 * call QueryValue once with data == NULL to get the
3706 * needed memory size to be allocated, then allocate
3707 * data buffer and call again.
3709 status = dcerpc_winreg_QueryValue(winreg_handle,
3718 if (!NT_STATUS_IS_OK(status)) {
3719 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3720 wvalue.name, nt_errstr(status)));
3721 result = ntstatus_to_werror(status);
3724 if (!W_ERROR_IS_OK(result)) {
3728 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3729 if (data_in == NULL) {
3730 result = WERR_NOMEM;
3735 status = dcerpc_winreg_QueryValue(winreg_handle,
3744 if (!NT_STATUS_IS_OK(status)) {
3745 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3746 wvalue.name, nt_errstr(status)));
3747 result = ntstatus_to_werror(status);
3750 if (!W_ERROR_IS_OK(result)) {
3754 r->form_name = talloc_strdup(mem_ctx, form_name);
3755 if (r->form_name == NULL) {
3756 result = WERR_NOMEM;
3760 r->size.width = IVAL(data_in, 0);
3761 r->size.height = IVAL(data_in, 4);
3762 r->area.left = IVAL(data_in, 8);
3763 r->area.top = IVAL(data_in, 12);
3764 r->area.right = IVAL(data_in, 16);
3765 r->area.bottom = IVAL(data_in, 20);
3766 /* skip index IVAL(data_in, 24)));*/
3767 r->flags = (enum spoolss_FormFlags) IVAL(data_in, 28);
3771 if (winreg_handle != NULL) {
3774 if (is_valid_policy_hnd(&key_hnd)) {
3775 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3777 if (is_valid_policy_hnd(&hive_hnd)) {
3778 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3782 TALLOC_FREE(tmp_ctx);
3786 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3787 const struct auth_serversupplied_info *server_info,
3788 struct messaging_context *msg_ctx,
3789 struct spoolss_AddDriverInfoCtr *r,
3790 const char **driver_name,
3791 uint32_t *driver_version)
3793 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3794 struct dcerpc_binding_handle *winreg_handle = NULL;
3795 struct policy_handle hive_hnd, key_hnd;
3796 struct spoolss_DriverInfo8 info8;
3797 TALLOC_CTX *tmp_ctx = NULL;
3800 ZERO_STRUCT(hive_hnd);
3801 ZERO_STRUCT(key_hnd);
3804 if (!driver_info_ctr_to_info8(r, &info8)) {
3805 result = WERR_INVALID_PARAMETER;
3809 tmp_ctx = talloc_stackframe();
3810 if (tmp_ctx == NULL) {
3814 result = winreg_printer_opendriver(tmp_ctx,
3824 if (!W_ERROR_IS_OK(result)) {
3825 DEBUG(0, ("winreg_add_driver: "
3826 "Could not open driver key (%s,%s,%d): %s\n",
3827 info8.driver_name, info8.architecture,
3828 info8.version, win_errstr(result)));
3832 /* TODO: "Attributes" ? */
3834 result = winreg_printer_write_dword(tmp_ctx, winreg_handle,
3835 &key_hnd, "Version",
3837 if (!W_ERROR_IS_OK(result)) {
3841 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3844 if (!W_ERROR_IS_OK(result)) {
3848 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3849 &key_hnd, "Data File",
3851 if (!W_ERROR_IS_OK(result)) {
3855 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3856 &key_hnd, "Configuration File",
3858 if (!W_ERROR_IS_OK(result)) {
3862 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3863 &key_hnd, "Help File",
3865 if (!W_ERROR_IS_OK(result)) {
3869 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3870 &key_hnd, "Dependent Files",
3871 info8.dependent_files);
3872 if (!W_ERROR_IS_OK(result)) {
3876 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3877 &key_hnd, "Monitor",
3878 info8.monitor_name);
3879 if (!W_ERROR_IS_OK(result)) {
3883 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3884 &key_hnd, "Datatype",
3885 info8.default_datatype);
3886 if (!W_ERROR_IS_OK(result)) {
3890 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3891 &key_hnd, "Previous Names",
3892 info8.previous_names);
3893 if (!W_ERROR_IS_OK(result)) {
3897 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3898 &key_hnd, "DriverDate",
3900 if (!W_ERROR_IS_OK(result)) {
3904 result = winreg_printer_write_ver(tmp_ctx, winreg_handle,
3905 &key_hnd, "DriverVersion",
3906 info8.driver_version);
3907 if (!W_ERROR_IS_OK(result)) {
3911 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3912 &key_hnd, "Manufacturer",
3913 info8.manufacturer_name);
3914 if (!W_ERROR_IS_OK(result)) {
3918 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3919 &key_hnd, "OEM URL",
3920 info8.manufacturer_url);
3921 if (!W_ERROR_IS_OK(result)) {
3925 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3926 &key_hnd, "HardwareID",
3928 if (!W_ERROR_IS_OK(result)) {
3932 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3933 &key_hnd, "Provider",
3935 if (!W_ERROR_IS_OK(result)) {
3939 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3940 &key_hnd, "Print Processor",
3941 info8.print_processor);
3942 if (!W_ERROR_IS_OK(result)) {
3946 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3947 &key_hnd, "VendorSetup",
3948 info8.vendor_setup);
3949 if (!W_ERROR_IS_OK(result)) {
3953 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3954 &key_hnd, "Color Profiles",
3955 info8.color_profiles);
3956 if (!W_ERROR_IS_OK(result)) {
3960 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3961 &key_hnd, "InfPath",
3963 if (!W_ERROR_IS_OK(result)) {
3967 result = winreg_printer_write_dword(tmp_ctx, winreg_handle, &key_hnd,
3968 "PrinterDriverAttributes",
3969 info8.printer_driver_attributes);
3970 if (!W_ERROR_IS_OK(result)) {
3974 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3975 &key_hnd, "CoreDependencies",
3976 info8.core_driver_dependencies);
3977 if (!W_ERROR_IS_OK(result)) {
3981 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3982 &key_hnd, "MinInboxDriverVerDate",
3983 info8.min_inbox_driver_ver_date);
3984 if (!W_ERROR_IS_OK(result)) {
3988 result = winreg_printer_write_ver(tmp_ctx, winreg_handle, &key_hnd,
3989 "MinInboxDriverVerVersion",
3990 info8.min_inbox_driver_ver_version);
3991 if (!W_ERROR_IS_OK(result)) {
3995 *driver_name = info8.driver_name;
3996 *driver_version = info8.version;
3999 if (winreg_handle != NULL) {
4002 if (is_valid_policy_hnd(&key_hnd)) {
4003 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4005 if (is_valid_policy_hnd(&hive_hnd)) {
4006 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4010 TALLOC_FREE(tmp_ctx);
4014 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
4015 const struct auth_serversupplied_info *server_info,
4016 struct messaging_context *msg_ctx,
4017 const char *architecture,
4018 const char *driver_name,
4019 uint32_t driver_version,
4020 struct spoolss_DriverInfo8 **_info8)
4022 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4023 struct dcerpc_binding_handle *winreg_handle = NULL;
4024 struct policy_handle hive_hnd, key_hnd;
4025 struct spoolss_DriverInfo8 i8, *info8;
4026 struct spoolss_PrinterEnumValues *enum_values = NULL;
4027 struct spoolss_PrinterEnumValues *v;
4028 uint32_t num_values = 0;
4029 TALLOC_CTX *tmp_ctx;
4033 ZERO_STRUCT(hive_hnd);
4034 ZERO_STRUCT(key_hnd);
4037 tmp_ctx = talloc_stackframe();
4038 if (tmp_ctx == NULL) {
4042 if (driver_version == DRIVER_ANY_VERSION) {
4043 /* look for Win2k first and then for NT4 */
4044 result = winreg_printer_opendriver(tmp_ctx,
4054 if (!W_ERROR_IS_OK(result)) {
4055 result = winreg_printer_opendriver(tmp_ctx,
4067 /* ok normal case */
4068 result = winreg_printer_opendriver(tmp_ctx,
4079 if (!W_ERROR_IS_OK(result)) {
4080 DEBUG(5, ("winreg_get_driver: "
4081 "Could not open driver key (%s,%s,%d): %s\n",
4082 driver_name, architecture,
4083 driver_version, win_errstr(result)));
4087 result = winreg_printer_enumvalues(tmp_ctx,
4092 if (!W_ERROR_IS_OK(result)) {
4093 DEBUG(0, ("winreg_get_driver: "
4094 "Could not enumerate values for (%s,%s,%d): %s\n",
4095 driver_name, architecture,
4096 driver_version, win_errstr(result)));
4100 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
4101 if (info8 == NULL) {
4102 result = WERR_NOMEM;
4106 info8->driver_name = talloc_strdup(info8, driver_name);
4107 if (info8->driver_name == NULL) {
4108 result = WERR_NOMEM;
4112 info8->architecture = talloc_strdup(info8, architecture);
4113 if (info8->architecture == NULL) {
4114 result = WERR_NOMEM;
4120 for (i = 0; i < num_values; i++) {
4121 const char *tmp_str;
4124 v = &enum_values[i];
4126 result = winreg_enumval_to_dword(info8, v,
4129 if (NT_STATUS_IS_OK(result)) {
4130 info8->version = (enum spoolss_DriverOSVersion) tmp;
4132 CHECK_ERROR(result);
4134 result = winreg_enumval_to_sz(info8, v,
4136 &info8->driver_path);
4137 CHECK_ERROR(result);
4139 result = winreg_enumval_to_sz(info8, v,
4142 CHECK_ERROR(result);
4144 result = winreg_enumval_to_sz(info8, v,
4145 "Configuration File",
4146 &info8->config_file);
4147 CHECK_ERROR(result);
4149 result = winreg_enumval_to_sz(info8, v,
4152 CHECK_ERROR(result);
4154 result = winreg_enumval_to_multi_sz(info8, v,
4156 &info8->dependent_files);
4157 CHECK_ERROR(result);
4159 result = winreg_enumval_to_sz(info8, v,
4161 &info8->monitor_name);
4162 CHECK_ERROR(result);
4164 result = winreg_enumval_to_sz(info8, v,
4166 &info8->default_datatype);
4167 CHECK_ERROR(result);
4169 result = winreg_enumval_to_multi_sz(info8, v,
4171 &info8->previous_names);
4172 CHECK_ERROR(result);
4174 result = winreg_enumval_to_sz(info8, v,
4177 if (W_ERROR_IS_OK(result)) {
4178 result = winreg_printer_date_to_NTTIME(tmp_str,
4179 &info8->driver_date);
4181 CHECK_ERROR(result);
4183 result = winreg_enumval_to_sz(info8, v,
4186 if (W_ERROR_IS_OK(result)) {
4187 result = winreg_printer_ver_to_dword(tmp_str,
4188 &info8->driver_version);
4190 CHECK_ERROR(result);
4192 result = winreg_enumval_to_sz(info8, v,
4194 &info8->manufacturer_name);
4195 CHECK_ERROR(result);
4197 result = winreg_enumval_to_sz(info8, v,
4199 &info8->manufacturer_url);
4200 CHECK_ERROR(result);
4202 result = winreg_enumval_to_sz(info8, v,
4204 &info8->hardware_id);
4205 CHECK_ERROR(result);
4207 result = winreg_enumval_to_sz(info8, v,
4210 CHECK_ERROR(result);
4212 result = winreg_enumval_to_sz(info8, v,
4214 &info8->print_processor);
4215 CHECK_ERROR(result);
4217 result = winreg_enumval_to_sz(info8, v,
4219 &info8->vendor_setup);
4220 CHECK_ERROR(result);
4222 result = winreg_enumval_to_multi_sz(info8, v,
4224 &info8->color_profiles);
4225 CHECK_ERROR(result);
4227 result = winreg_enumval_to_sz(info8, v,
4230 CHECK_ERROR(result);
4232 result = winreg_enumval_to_dword(info8, v,
4233 "PrinterDriverAttributes",
4234 &info8->printer_driver_attributes);
4235 CHECK_ERROR(result);
4237 result = winreg_enumval_to_multi_sz(info8, v,
4239 &info8->core_driver_dependencies);
4240 CHECK_ERROR(result);
4242 result = winreg_enumval_to_sz(info8, v,
4243 "MinInboxDriverVerDate",
4245 if (W_ERROR_IS_OK(result)) {
4246 result = winreg_printer_date_to_NTTIME(tmp_str,
4247 &info8->min_inbox_driver_ver_date);
4249 CHECK_ERROR(result);
4251 result = winreg_enumval_to_sz(info8, v,
4252 "MinInboxDriverVerVersion",
4254 if (W_ERROR_IS_OK(result)) {
4255 result = winreg_printer_ver_to_dword(tmp_str,
4256 &info8->min_inbox_driver_ver_version);
4258 CHECK_ERROR(result);
4261 if (!W_ERROR_IS_OK(result)) {
4262 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4263 "for %s: %s\n", v->value_name,
4264 win_errstr(result)));
4268 *_info8 = talloc_steal(mem_ctx, info8);
4271 if (winreg_handle != NULL) {
4274 if (is_valid_policy_hnd(&key_hnd)) {
4275 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4277 if (is_valid_policy_hnd(&hive_hnd)) {
4278 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4282 TALLOC_FREE(tmp_ctx);
4286 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
4287 const struct auth_serversupplied_info *server_info,
4288 struct messaging_context *msg_ctx,
4289 struct spoolss_DriverInfo8 *info8,
4292 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4293 struct dcerpc_binding_handle *winreg_handle = NULL;
4294 struct policy_handle hive_hnd, key_hnd;
4295 TALLOC_CTX *tmp_ctx;
4299 ZERO_STRUCT(hive_hnd);
4300 ZERO_STRUCT(key_hnd);
4302 tmp_ctx = talloc_stackframe();
4303 if (tmp_ctx == NULL) {
4307 /* test that the key exists */
4308 result = winreg_printer_opendriver(tmp_ctx,
4312 info8->architecture,
4318 if (!W_ERROR_IS_OK(result)) {
4319 /* key doesn't exist */
4320 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
4325 DEBUG(5, ("winreg_del_driver: "
4326 "Could not open driver (%s,%s,%u): %s\n",
4327 info8->driver_name, info8->architecture,
4328 version, win_errstr(result)));
4333 if (is_valid_policy_hnd(&key_hnd)) {
4334 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
4337 key_name = talloc_asprintf(tmp_ctx,
4338 "%s\\Environments\\%s\\Drivers\\Version-%u",
4339 TOP_LEVEL_CONTROL_KEY,
4340 info8->architecture, version);
4341 if (key_name == NULL) {
4342 result = WERR_NOMEM;
4346 result = winreg_printer_delete_subkeys(tmp_ctx,
4351 if (!W_ERROR_IS_OK(result)) {
4352 DEBUG(0, ("winreg_del_driver: "
4353 "Could not open driver (%s,%s,%u): %s\n",
4354 info8->driver_name, info8->architecture,
4355 version, win_errstr(result)));
4361 if (winreg_handle != NULL) {
4364 if (is_valid_policy_hnd(&key_hnd)) {
4365 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4367 if (is_valid_policy_hnd(&hive_hnd)) {
4368 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4372 TALLOC_FREE(tmp_ctx);
4376 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
4377 const struct auth_serversupplied_info *server_info,
4378 struct messaging_context *msg_ctx,
4379 const char *architecture,
4381 uint32_t *num_drivers,
4382 const char ***drivers_p)
4384 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4385 struct dcerpc_binding_handle *winreg_handle = NULL;
4386 struct policy_handle hive_hnd, key_hnd;
4387 const char **drivers;
4388 TALLOC_CTX *tmp_ctx;
4394 ZERO_STRUCT(hive_hnd);
4395 ZERO_STRUCT(key_hnd);
4397 tmp_ctx = talloc_stackframe();
4398 if (tmp_ctx == NULL) {
4402 /* use NULL for the driver name so we open the key that is
4403 * parent of all drivers for this architecture and version */
4404 result = winreg_printer_opendriver(tmp_ctx,
4414 if (!W_ERROR_IS_OK(result)) {
4415 DEBUG(5, ("winreg_get_driver_list: "
4416 "Could not open key (%s,%u): %s\n",
4417 architecture, version, win_errstr(result)));
4422 result = winreg_printer_enumkeys(tmp_ctx,
4427 if (!W_ERROR_IS_OK(result)) {
4428 DEBUG(0, ("winreg_get_driver_list: "
4429 "Could not enumerate drivers for (%s,%u): %s\n",
4430 architecture, version, win_errstr(result)));
4434 *drivers_p = talloc_steal(mem_ctx, drivers);
4438 if (winreg_handle != NULL) {
4441 if (is_valid_policy_hnd(&key_hnd)) {
4442 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4444 if (is_valid_policy_hnd(&hive_hnd)) {
4445 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4449 TALLOC_FREE(tmp_ctx);