2 * Unix SMB/CIFS implementation.
4 * SPOOLSS RPC Pipe server / winreg client routines
6 * Copyright (c) 2010 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "nt_printing.h"
24 #include "srv_spoolss_util.h"
25 #include "../librpc/gen_ndr/ndr_spoolss.h"
26 #include "../librpc/gen_ndr/srv_winreg.h"
27 #include "../librpc/gen_ndr/cli_winreg.h"
28 #include "../librpc/gen_ndr/ndr_security.h"
31 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
32 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
33 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
34 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
36 #define EMPTY_STRING ""
38 #define FILL_STRING(mem_ctx, in, out) \
40 if (in && strlen(in)) { \
41 out = talloc_strdup(mem_ctx, in); \
43 out = talloc_strdup(mem_ctx, ""); \
45 W_ERROR_HAVE_NO_MEMORY(out); \
48 #define CHECK_ERROR(result) \
49 if (W_ERROR_IS_OK(result)) continue; \
50 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
51 if (!W_ERROR_IS_OK(result)) break
53 /* FLAGS, NAME, with, height, left, top, right, bottom */
54 static const struct spoolss_FormInfo1 builtin_forms1[] = {
55 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
56 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
57 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
58 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
59 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
60 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
61 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
62 { SPOOLSS_FORM_BUILTIN, "A0", {0xcd528,0x122488},{0x0,0x0,0xcd528,0x122488} },
63 { SPOOLSS_FORM_BUILTIN, "A1", {0x91050,0xcd528}, {0x0,0x0,0x91050,0xcd528} },
64 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
65 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
66 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
67 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
68 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
69 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
70 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
71 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
72 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
73 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
74 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
75 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
76 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
77 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
78 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
79 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
80 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
81 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
82 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
83 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
84 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
85 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
86 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
87 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
88 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
89 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
90 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
91 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
92 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
93 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
94 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
95 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
96 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
97 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
98 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
99 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
100 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
101 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
102 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
103 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
104 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
105 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
106 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
107 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
108 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
109 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
110 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
111 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
112 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
113 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
114 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
115 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
116 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
117 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
118 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
119 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
120 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
121 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
122 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
123 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
124 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
125 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
126 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
127 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
128 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
129 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
130 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
131 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
132 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
133 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
134 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
135 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
136 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
137 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
138 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
139 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
140 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
141 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
142 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
143 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
144 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
145 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
146 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
147 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
148 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} },
149 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
150 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
151 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
152 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
153 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
154 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
159 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
160 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
161 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
162 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
163 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
164 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
165 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
166 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
167 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
168 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
169 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
170 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
171 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
172 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
173 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
174 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} }
177 /********************************************************************
178 static helper functions
179 ********************************************************************/
181 /****************************************************************************
182 Update the changeid time.
183 ****************************************************************************/
187 * @brief Update the ChangeID time of a printer.
189 * This is SO NASTY as some drivers need this to change, others need it
190 * static. This value will change every second, and I must hope that this
191 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
194 * @return The ChangeID.
196 static uint32_t winreg_printer_rev_changeid(void)
200 get_process_uptime(&tv);
203 /* Return changeid as msec since spooler restart */
204 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
207 * This setting seems to work well but is too untested
208 * to replace the above calculation. Left in for experiementation
209 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
211 return tv.tv_sec * 10 + tv.tv_usec / 100000;
218 * @brief Connect to the interal winreg server and open the given printer key.
220 * The function will create the needed subkeys if they don't exist.
222 * @param[in] mem_ctx The memory context to use.
224 * @param[in] server_info The supplied server info.
226 * @param[out] binding_handle A pointer for the winreg dcerpc binding handle.
228 * @param[in] path The path to the key to open.
230 * @param[in] key The key to open.
232 * @param[in] create_key Set to true if the key should be created if it
235 * @param[in] access_mask The access mask to open the key.
237 * @param[out] hive_handle A policy handle for the opened hive.
239 * @param[out] key_handle A policy handle for the opened key.
241 * @return WERR_OK on success, the corresponding DOS error
242 * code if something gone wrong.
244 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
245 struct auth_serversupplied_info *server_info,
246 struct messaging_context *msg_ctx,
247 struct dcerpc_binding_handle **winreg_binding_handle,
251 uint32_t access_mask,
252 struct policy_handle *hive_handle,
253 struct policy_handle *key_handle)
255 static struct client_address client_id;
256 struct dcerpc_binding_handle *binding_handle;
257 struct winreg_String wkey, wkeyclass;
260 WERROR result = WERR_OK;
262 strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
263 client_id.name = "127.0.0.1";
265 status = rpcint_binding_handle(mem_ctx,
271 if (!NT_STATUS_IS_OK(status)) {
272 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg pipe: %s\n",
274 return ntstatus_to_werror(status);
277 status = dcerpc_winreg_OpenHKLM(binding_handle,
283 if (!NT_STATUS_IS_OK(status)) {
284 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
286 talloc_free(binding_handle);
287 return ntstatus_to_werror(status);
289 if (!W_ERROR_IS_OK(result)) {
290 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
291 win_errstr(result)));
292 talloc_free(binding_handle);
297 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
299 keyname = talloc_strdup(mem_ctx, path);
301 if (keyname == NULL) {
302 talloc_free(binding_handle);
310 enum winreg_CreateAction action = REG_ACTION_NONE;
312 ZERO_STRUCT(wkeyclass);
315 status = dcerpc_winreg_CreateKey(binding_handle,
327 case REG_ACTION_NONE:
328 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
330 case REG_CREATED_NEW_KEY:
331 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
333 case REG_OPENED_EXISTING_KEY:
334 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
338 status = dcerpc_winreg_OpenKey(binding_handle,
347 if (!NT_STATUS_IS_OK(status)) {
348 talloc_free(binding_handle);
349 return ntstatus_to_werror(status);
351 if (!W_ERROR_IS_OK(result)) {
352 talloc_free(binding_handle);
356 *winreg_binding_handle = binding_handle;
362 * @brief Create the registry keyname for the given printer.
364 * @param[in] mem_ctx The memory context to use.
366 * @param[in] printer The name of the printer to get the registry key.
368 * @return The registry key or NULL on error.
370 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
371 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
377 * @brief Enumerate values of an opened key handle and retrieve the data.
379 * @param[in] mem_ctx The memory context to use.
381 * @param[in] winreg_handle The binding handle for the rpc connection.
383 * @param[in] key_hnd The opened key handle.
385 * @param[out] pnum_values A pointer to store he number of values found.
387 * @param[out] pnum_values A pointer to store the number of values we found.
389 * @return WERR_OK on success, the corresponding DOS error
390 * code if something gone wrong.
392 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
393 struct dcerpc_binding_handle *winreg_handle,
394 struct policy_handle *key_hnd,
395 uint32_t *pnum_values,
396 struct spoolss_PrinterEnumValues **penum_values)
399 uint32_t num_subkeys, max_subkeylen, max_classlen;
400 uint32_t num_values, max_valnamelen, max_valbufsize;
401 uint32_t secdescsize;
403 NTTIME last_changed_time;
404 struct winreg_String classname;
406 struct spoolss_PrinterEnumValues *enum_values;
408 WERROR result = WERR_OK;
411 tmp_ctx = talloc_stackframe();
412 if (tmp_ctx == NULL) {
416 ZERO_STRUCT(classname);
418 status = dcerpc_winreg_QueryInfoKey(winreg_handle,
431 if (!NT_STATUS_IS_OK(status)) {
432 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
434 result = ntstatus_to_werror(status);
437 if (!W_ERROR_IS_OK(result)) {
438 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
439 win_errstr(result)));
443 if (num_values == 0) {
445 TALLOC_FREE(tmp_ctx);
449 enum_values = TALLOC_ARRAY(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
450 if (enum_values == NULL) {
455 for (i = 0; i < num_values; i++) {
456 struct spoolss_PrinterEnumValues val;
457 struct winreg_ValNameBuf name_buf;
458 enum winreg_Type type = REG_NONE;
465 name_buf.size = max_valnamelen + 2;
468 data_size = max_valbufsize;
471 data = (uint8_t *) TALLOC(tmp_ctx, data_size);
475 status = dcerpc_winreg_EnumValue(winreg_handle,
482 data_size ? &data_size : NULL,
485 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
487 status = NT_STATUS_OK;
491 if (!NT_STATUS_IS_OK(status)) {
492 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
494 result = ntstatus_to_werror(status);
497 if (!W_ERROR_IS_OK(result)) {
498 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
499 win_errstr(result)));
503 if (name_buf.name == NULL) {
504 result = WERR_INVALID_PARAMETER;
508 val.value_name = talloc_strdup(enum_values, name_buf.name);
509 if (val.value_name == NULL) {
513 val.value_name_len = strlen_m_term(val.value_name) * 2;
516 val.data_length = length;
518 if (val.data_length) {
519 val.data = talloc(enum_values, DATA_BLOB);
520 if (val.data == NULL) {
524 *val.data = data_blob_talloc(val.data, data, val.data_length);
527 enum_values[i] = val;
530 *pnum_values = num_values;
532 *penum_values = talloc_move(mem_ctx, &enum_values);
538 TALLOC_FREE(tmp_ctx);
545 * @brief Enumerate subkeys of an opened key handle and get the names.
547 * @param[in] mem_ctx The memory context to use.
549 * @param[in] winreg_handle The binding handle for the rpc connection.
551 * @param[in] key_hnd The opened key handle.
553 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
555 * @param[in] psubkeys A pointer to an array to store the found names of
558 * @return WERR_OK on success, the corresponding DOS error
559 * code if something gone wrong.
561 static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
562 struct dcerpc_binding_handle *winreg_handle,
563 struct policy_handle *key_hnd,
564 uint32_t *pnum_subkeys,
565 const char ***psubkeys)
568 const char **subkeys;
569 uint32_t num_subkeys, max_subkeylen, max_classlen;
570 uint32_t num_values, max_valnamelen, max_valbufsize;
572 NTTIME last_changed_time;
573 uint32_t secdescsize;
574 struct winreg_String classname;
575 WERROR result = WERR_OK;
578 tmp_ctx = talloc_stackframe();
579 if (tmp_ctx == NULL) {
583 ZERO_STRUCT(classname);
585 status = dcerpc_winreg_QueryInfoKey(winreg_handle,
598 if (!NT_STATUS_IS_OK(status)) {
599 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
601 result = ntstatus_to_werror(status);
604 if (!W_ERROR_IS_OK(result)) {
605 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
606 win_errstr(result)));
610 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
611 if (subkeys == NULL) {
616 if (num_subkeys == 0) {
617 subkeys[0] = talloc_strdup(subkeys, "");
618 if (subkeys[0] == NULL) {
624 *psubkeys = talloc_move(mem_ctx, &subkeys);
627 TALLOC_FREE(tmp_ctx);
631 for (i = 0; i < num_subkeys; i++) {
635 struct winreg_StringBuf class_buf;
636 struct winreg_StringBuf name_buf;
640 class_buf.size = max_classlen + 2;
641 class_buf.length = 0;
644 name_buf.size = max_subkeylen + 2;
647 ZERO_STRUCT(modtime);
649 status = dcerpc_winreg_EnumKey(winreg_handle,
657 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
659 status = NT_STATUS_OK;
663 if (!NT_STATUS_IS_OK(status)) {
664 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
666 result = ntstatus_to_werror(status);
669 if (!W_ERROR_IS_OK(result)) {
670 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
671 win_errstr(result)));
675 if (name_buf.name == NULL) {
676 result = WERR_INVALID_PARAMETER;
680 name = talloc_strdup(subkeys, name_buf.name);
689 *pnum_subkeys = num_subkeys;
691 *psubkeys = talloc_move(mem_ctx, &subkeys);
695 TALLOC_FREE(tmp_ctx);
702 * @brief A function to delete a key and its subkeys recurively.
704 * @param[in] mem_ctx The memory context to use.
706 * @param[in] winreg_handle The binding handle for the rpc connection.
708 * @param[in] hive_handle A opened hive handle to the key.
710 * @param[in] access_mask The access mask to access the key.
712 * @param[in] key The key to delete
714 * @return WERR_OK on success, the corresponding DOS error
715 * code if something gone wrong.
717 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
718 struct dcerpc_binding_handle *winreg_handle,
719 struct policy_handle *hive_handle,
720 uint32_t access_mask,
723 const char **subkeys = NULL;
724 uint32_t num_subkeys = 0;
725 struct policy_handle key_hnd;
726 struct winreg_String wkey;
727 WERROR result = WERR_OK;
731 ZERO_STRUCT(key_hnd);
734 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
736 status = dcerpc_winreg_OpenKey(winreg_handle,
744 if (!NT_STATUS_IS_OK(status)) {
745 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
746 wkey.name, nt_errstr(status)));
747 return ntstatus_to_werror(status);
749 if (!W_ERROR_IS_OK(result)) {
750 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
751 wkey.name, win_errstr(result)));
755 result = winreg_printer_enumkeys(mem_ctx,
760 if (!W_ERROR_IS_OK(result)) {
764 for (i = 0; i < num_subkeys; i++) {
765 /* create key + subkey */
766 char *subkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkeys[i]);
767 if (subkey == NULL) {
771 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey));
772 result = winreg_printer_delete_subkeys(mem_ctx,
777 if (!W_ERROR_IS_OK(result)) {
782 if (is_valid_policy_hnd(&key_hnd)) {
784 dcerpc_winreg_CloseKey(winreg_handle, mem_ctx, &key_hnd, &ignore);
789 status = dcerpc_winreg_DeleteKey(winreg_handle,
794 if (!NT_STATUS_IS_OK(status)) {
795 result = ntstatus_to_werror(status);
799 if (is_valid_policy_hnd(&key_hnd)) {
802 dcerpc_winreg_CloseKey(winreg_handle, mem_ctx, &key_hnd, &ignore);
808 static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
809 struct dcerpc_binding_handle *winreg_handle,
810 struct policy_handle *key_handle,
814 struct winreg_String wvalue;
816 WERROR result = WERR_OK;
821 blob = data_blob_string_const("");
823 if (!push_reg_sz(mem_ctx, &blob, data)) {
824 DEBUG(0, ("winreg_printer_write_sz: Could not marshall string %s for %s\n",
829 status = dcerpc_winreg_SetValue(winreg_handle,
837 if (!NT_STATUS_IS_OK(status)) {
838 result = ntstatus_to_werror(status);
840 if (!W_ERROR_IS_OK(result)) {
841 DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: %s\n",
842 wvalue.name, win_errstr(result)));
848 static WERROR winreg_printer_write_dword(TALLOC_CTX *mem_ctx,
849 struct dcerpc_binding_handle *winreg_handle,
850 struct policy_handle *key_handle,
854 struct winreg_String wvalue;
856 WERROR result = WERR_OK;
860 blob = data_blob_talloc(mem_ctx, NULL, 4);
861 SIVAL(blob.data, 0, data);
863 status = dcerpc_winreg_SetValue(winreg_handle,
871 if (!NT_STATUS_IS_OK(status)) {
872 result = ntstatus_to_werror(status);
874 if (!W_ERROR_IS_OK(result)) {
875 DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: %s\n",
876 wvalue.name, win_errstr(result)));
882 static WERROR winreg_printer_write_binary(TALLOC_CTX *mem_ctx,
883 struct dcerpc_binding_handle *winreg_handle,
884 struct policy_handle *key_handle,
888 struct winreg_String wvalue;
889 WERROR result = WERR_OK;
893 status = dcerpc_winreg_SetValue(winreg_handle,
901 if (!NT_STATUS_IS_OK(status)) {
902 result = ntstatus_to_werror(status);
904 if (!W_ERROR_IS_OK(result)) {
905 DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: %s\n",
906 wvalue.name, win_errstr(result)));
912 static WERROR winreg_printer_query_binary(TALLOC_CTX *mem_ctx,
913 struct dcerpc_binding_handle *winreg_handle,
914 struct policy_handle *key_handle,
918 struct winreg_String wvalue;
919 enum winreg_Type type;
920 WERROR result = WERR_OK;
921 uint32_t value_len = 0;
922 uint32_t data_size = 0;
927 status = dcerpc_winreg_QueryValue(winreg_handle,
936 if (!NT_STATUS_IS_OK(status)) {
937 result = ntstatus_to_werror(status);
939 if (!W_ERROR_IS_OK(result)) {
940 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
941 wvalue.name, win_errstr(result)));
945 if (type != REG_BINARY) {
946 result = WERR_INVALID_DATATYPE;
949 blob = data_blob_talloc(mem_ctx, NULL, data_size);
950 if (blob.data == NULL) {
956 status = dcerpc_winreg_QueryValue(winreg_handle,
965 if (!NT_STATUS_IS_OK(status)) {
966 result = ntstatus_to_werror(status);
968 if (!W_ERROR_IS_OK(result)) {
969 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
970 wvalue.name, win_errstr(result)));
975 data->data = blob.data;
976 data->length = blob.length;
982 static WERROR winreg_printer_query_dword(TALLOC_CTX *mem_ctx,
983 struct dcerpc_binding_handle *winreg_handle,
984 struct policy_handle *key_handle,
988 struct winreg_String wvalue;
989 enum winreg_Type type;
990 WERROR result = WERR_OK;
991 uint32_t value_len = 0;
992 uint32_t data_size = 0;
997 status = dcerpc_winreg_QueryValue(winreg_handle,
1006 if (!NT_STATUS_IS_OK(status)) {
1007 result = ntstatus_to_werror(status);
1009 if (!W_ERROR_IS_OK(result)) {
1010 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1011 wvalue.name, win_errstr(result)));
1015 if (type != REG_DWORD) {
1016 result = WERR_INVALID_DATATYPE;
1020 if (data_size != 4) {
1021 result = WERR_INVALID_DATA;
1025 blob = data_blob_talloc(mem_ctx, NULL, data_size);
1026 if (blob.data == NULL) {
1027 result = WERR_NOMEM;
1032 status = dcerpc_winreg_QueryValue(winreg_handle,
1041 if (!NT_STATUS_IS_OK(status)) {
1042 result = ntstatus_to_werror(status);
1044 if (!W_ERROR_IS_OK(result)) {
1045 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1046 wvalue.name, win_errstr(result)));
1051 *data = IVAL(blob.data, 0);
1057 static WERROR winreg_printer_write_multi_sz(TALLOC_CTX *mem_ctx,
1058 struct dcerpc_binding_handle *winreg_handle,
1059 struct policy_handle *key_handle,
1063 struct winreg_String wvalue;
1065 WERROR result = WERR_OK;
1068 wvalue.name = value;
1069 if (!push_reg_multi_sz(mem_ctx, &blob, data)) {
1072 status = dcerpc_winreg_SetValue(winreg_handle,
1080 if (!NT_STATUS_IS_OK(status)) {
1081 result = ntstatus_to_werror(status);
1083 if (!W_ERROR_IS_OK(result)) {
1084 DEBUG(0, ("winreg_printer_write_multi_sz: Could not set value %s: %s\n",
1085 wvalue.name, win_errstr(result)));
1091 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
1092 struct auth_serversupplied_info *server_info,
1093 struct messaging_context *msg_ctx,
1094 const char *drivername,
1095 const char *architecture,
1097 uint32_t access_mask,
1099 struct dcerpc_binding_handle **winreg_binding_handle,
1100 struct policy_handle *hive_hnd,
1101 struct policy_handle *key_hnd)
1106 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
1107 TOP_LEVEL_CONTROL_KEY,
1108 architecture, version);
1113 result = winreg_printer_openkey(mem_ctx,
1116 winreg_binding_handle,
1126 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
1127 struct spoolss_PrinterEnumValues *v,
1128 const char *valuename, uint32_t *dw)
1130 /* just return if it is not the one we are looking for */
1131 if (strcmp(valuename, v->value_name) != 0) {
1132 return WERR_NOT_FOUND;
1135 if (v->type != REG_DWORD) {
1136 return WERR_INVALID_DATATYPE;
1139 if (v->data_length != 4) {
1144 *dw = IVAL(v->data->data, 0);
1148 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
1149 struct spoolss_PrinterEnumValues *v,
1150 const char *valuename, const char **_str)
1152 /* just return if it is not the one we are looking for */
1153 if (strcmp(valuename, v->value_name) != 0) {
1154 return WERR_NOT_FOUND;
1157 if (v->type != REG_SZ) {
1158 return WERR_INVALID_DATATYPE;
1161 if (v->data_length == 0) {
1162 *_str = talloc_strdup(mem_ctx, EMPTY_STRING);
1163 if (*_str == NULL) {
1169 if (!pull_reg_sz(mem_ctx, v->data, _str)) {
1176 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
1177 struct spoolss_PrinterEnumValues *v,
1178 const char *valuename,
1179 const char ***array)
1181 /* just return if it is not the one we are looking for */
1182 if (strcmp(valuename, v->value_name) != 0) {
1183 return WERR_NOT_FOUND;
1186 if (v->type != REG_MULTI_SZ) {
1187 return WERR_INVALID_DATATYPE;
1190 if (v->data_length == 0) {
1191 *array = talloc_array(mem_ctx, const char *, 1);
1192 if (*array == NULL) {
1199 if (!pull_reg_multi_sz(mem_ctx, v->data, array)) {
1206 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
1207 struct dcerpc_binding_handle *winreg_handle,
1208 struct policy_handle *key_handle,
1212 struct winreg_String wvalue;
1214 WERROR result = WERR_OK;
1220 t = nt_time_to_unix(data);
1222 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
1223 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
1228 wvalue.name = value;
1229 if (!push_reg_sz(mem_ctx, &blob, str)) {
1232 status = dcerpc_winreg_SetValue(winreg_handle,
1240 if (!NT_STATUS_IS_OK(status)) {
1241 result = ntstatus_to_werror(status);
1243 if (!W_ERROR_IS_OK(result)) {
1244 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1245 wvalue.name, win_errstr(result)));
1251 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
1258 if (sscanf(str, "%d/%d/%d",
1259 &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3) {
1260 return WERR_INVALID_PARAMETER;
1267 unix_to_nt_time(data, t);
1272 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
1273 struct dcerpc_binding_handle *winreg_handle,
1274 struct policy_handle *key_handle,
1278 struct winreg_String wvalue;
1280 WERROR result = WERR_OK;
1284 /* FIXME: check format is right,
1285 * this needs to be something like: 6.1.7600.16385 */
1286 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
1287 (unsigned)((data >> 48) & 0xFFFF),
1288 (unsigned)((data >> 32) & 0xFFFF),
1289 (unsigned)((data >> 16) & 0xFFFF),
1290 (unsigned)(data & 0xFFFF));
1295 wvalue.name = value;
1296 if (!push_reg_sz(mem_ctx, &blob, str)) {
1299 status = dcerpc_winreg_SetValue(winreg_handle,
1307 if (!NT_STATUS_IS_OK(status)) {
1308 result = ntstatus_to_werror(status);
1310 if (!W_ERROR_IS_OK(result)) {
1311 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1312 wvalue.name, win_errstr(result)));
1318 static WERROR winreg_printer_ver_to_dword(const char *str, uint64_t *data)
1320 unsigned int v1, v2, v3, v4;
1322 if (sscanf(str, "%u.%u.%u.%u", &v1, &v2, &v3, &v4) != 4) {
1323 return WERR_INVALID_PARAMETER;
1326 *data = ((uint64_t)(v1 & 0xFFFF) << 48) +
1327 ((uint64_t)(v2 & 0xFFFF) << 32) +
1328 ((uint64_t)(v3 & 0xFFFF) << 16) +
1329 (uint64_t)(v2 & 0xFFFF);
1334 /********************************************************************
1335 Public winreg function for spoolss
1336 ********************************************************************/
1338 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
1339 struct auth_serversupplied_info *server_info,
1340 struct messaging_context *msg_ctx,
1341 const char *servername,
1342 const char *sharename)
1344 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1345 struct dcerpc_binding_handle *winreg_handle = NULL;
1346 struct policy_handle hive_hnd, key_hnd;
1347 struct spoolss_SetPrinterInfo2 *info2;
1348 struct security_descriptor *secdesc;
1349 struct winreg_String wkey, wkeyclass;
1351 const char *subkeys[] = { SPOOL_DSDRIVER_KEY, SPOOL_DSSPOOLER_KEY, SPOOL_PRINTERDATA_KEY };
1352 uint32_t i, count = ARRAY_SIZE(subkeys);
1353 uint32_t info2_mask = 0;
1354 WERROR result = WERR_OK;
1355 TALLOC_CTX *tmp_ctx;
1357 tmp_ctx = talloc_stackframe();
1358 if (tmp_ctx == NULL) {
1362 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1364 TALLOC_FREE(tmp_ctx);
1368 ZERO_STRUCT(hive_hnd);
1369 ZERO_STRUCT(key_hnd);
1371 result = winreg_printer_openkey(tmp_ctx,
1381 if (W_ERROR_IS_OK(result)) {
1382 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
1384 } else if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1385 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
1386 } else if (!W_ERROR_IS_OK(result)) {
1387 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
1388 path, win_errstr(result)));
1392 /* Create the main key */
1393 result = winreg_printer_openkey(tmp_ctx,
1403 if (!W_ERROR_IS_OK(result)) {
1404 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1405 path, win_errstr(result)));
1409 if (is_valid_policy_hnd(&key_hnd)) {
1410 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
1413 /* Create subkeys */
1414 for (i = 0; i < count; i++) {
1416 enum winreg_CreateAction action = REG_ACTION_NONE;
1418 ZERO_STRUCT(key_hnd);
1421 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
1422 if (wkey.name == NULL) {
1423 result = WERR_NOMEM;
1427 ZERO_STRUCT(wkeyclass);
1428 wkeyclass.name = "";
1430 status = dcerpc_winreg_CreateKey(winreg_handle,
1441 if (!NT_STATUS_IS_OK(status)) {
1442 result = ntstatus_to_werror(status);
1444 if (!W_ERROR_IS_OK(result)) {
1445 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1446 wkey.name, win_errstr(result)));
1452 const char *dnssuffix;
1453 const char *longname;
1454 const char *uncname;
1456 result = winreg_printer_write_sz(tmp_ctx,
1459 SPOOL_REG_PRINTERNAME,
1461 if (!W_ERROR_IS_OK(result)) {
1465 result = winreg_printer_write_sz(tmp_ctx,
1468 SPOOL_REG_SHORTSERVERNAME,
1470 if (!W_ERROR_IS_OK(result)) {
1474 /* We make the assumption that the netbios name
1475 * is the same as the DNS name since the former
1476 * will be what we used to join the domain
1478 dnssuffix = get_mydnsdomname(tmp_ctx);
1479 if (dnssuffix != NULL && dnssuffix[0] != '\0') {
1480 longname = talloc_asprintf(tmp_ctx, "%s.%s", global_myname(), dnssuffix);
1482 longname = talloc_strdup(tmp_ctx, global_myname());
1484 if (longname == NULL) {
1485 result = WERR_NOMEM;
1489 result = winreg_printer_write_sz(tmp_ctx,
1492 SPOOL_REG_SERVERNAME,
1494 if (!W_ERROR_IS_OK(result)) {
1498 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
1499 longname, sharename);
1500 if (uncname == NULL) {
1501 result = WERR_NOMEM;
1505 result = winreg_printer_write_sz(tmp_ctx,
1510 if (!W_ERROR_IS_OK(result)) {
1514 result = winreg_printer_write_dword(tmp_ctx,
1517 SPOOL_REG_VERSIONNUMBER,
1519 if (!W_ERROR_IS_OK(result)) {
1523 result = winreg_printer_write_dword(tmp_ctx,
1526 SPOOL_REG_PRINTSTARTTIME,
1528 if (!W_ERROR_IS_OK(result)) {
1532 result = winreg_printer_write_dword(tmp_ctx,
1535 SPOOL_REG_PRINTENDTIME,
1537 if (!W_ERROR_IS_OK(result)) {
1541 result = winreg_printer_write_dword(tmp_ctx,
1546 if (!W_ERROR_IS_OK(result)) {
1550 result = winreg_printer_write_dword(tmp_ctx,
1553 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
1555 if (!W_ERROR_IS_OK(result)) {
1563 if (is_valid_policy_hnd(&key_hnd)) {
1564 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
1567 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
1568 if (info2 == NULL) {
1569 result = WERR_NOMEM;
1573 if (servername != NULL) {
1574 info2->printername = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
1575 servername, sharename);
1577 info2->printername = sharename;
1579 if (info2->printername == NULL) {
1580 result = WERR_NOMEM;
1583 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1585 info2->sharename = sharename;
1586 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1588 info2->portname = SAMBA_PRINTER_PORT_NAME;
1589 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1591 info2->printprocessor = "winprint";
1592 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1594 info2->datatype = "RAW";
1595 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1597 info2->comment = "";
1598 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1600 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1601 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1603 info2->starttime = 0; /* Minutes since 12:00am GMT */
1604 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1606 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1607 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1609 info2->priority = 1;
1610 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1612 info2->defaultpriority = 1;
1613 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1615 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1616 if (!W_ERROR_IS_OK(result)) {
1619 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1622 * Don't write a default Device Mode to the registry! The Device Mode is
1623 * only written to disk with a SetPrinter level 2 or 8.
1626 result = winreg_update_printer(tmp_ctx,
1636 if (winreg_handle != NULL) {
1639 if (is_valid_policy_hnd(&key_hnd)) {
1640 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1642 if (is_valid_policy_hnd(&hive_hnd)) {
1643 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1647 talloc_free(tmp_ctx);
1651 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1652 struct auth_serversupplied_info *server_info,
1653 struct messaging_context *msg_ctx,
1654 const char *sharename,
1655 uint32_t info2_mask,
1656 struct spoolss_SetPrinterInfo2 *info2,
1657 struct spoolss_DeviceMode *devmode,
1658 struct security_descriptor *secdesc)
1660 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1661 struct dcerpc_binding_handle *winreg_handle = NULL;
1662 struct policy_handle hive_hnd, key_hnd;
1663 int snum = lp_servicenumber(sharename);
1664 enum ndr_err_code ndr_err;
1667 WERROR result = WERR_OK;
1668 TALLOC_CTX *tmp_ctx;
1670 tmp_ctx = talloc_stackframe();
1671 if (tmp_ctx == NULL) {
1675 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1677 TALLOC_FREE(tmp_ctx);
1681 ZERO_STRUCT(hive_hnd);
1682 ZERO_STRUCT(key_hnd);
1684 result = winreg_printer_openkey(tmp_ctx,
1694 if (!W_ERROR_IS_OK(result)) {
1695 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1696 path, win_errstr(result)));
1700 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1701 result = winreg_printer_write_dword(tmp_ctx,
1706 if (!W_ERROR_IS_OK(result)) {
1712 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1713 result = winreg_printer_write_dword(tmp_ctx,
1718 if (!W_ERROR_IS_OK(result)) {
1724 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1725 result = winreg_printer_write_sz(tmp_ctx,
1730 if (!W_ERROR_IS_OK(result)) {
1735 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1736 result = winreg_printer_write_sz(tmp_ctx,
1741 if (!W_ERROR_IS_OK(result)) {
1746 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1747 result = winreg_printer_write_dword(tmp_ctx,
1751 info2->defaultpriority);
1752 if (!W_ERROR_IS_OK(result)) {
1757 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1759 * Some client drivers freak out if there is a NULL devmode
1760 * (probably the driver is not checking before accessing
1761 * the devmode pointer) --jerry
1763 if (devmode == NULL && lp_default_devmode(snum) && info2 != NULL) {
1764 result = spoolss_create_default_devmode(tmp_ctx,
1767 if (!W_ERROR_IS_OK(result)) {
1771 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, devmode,
1772 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1773 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1774 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1775 result = WERR_NOMEM;
1779 result = winreg_printer_write_binary(tmp_ctx,
1784 if (!W_ERROR_IS_OK(result)) {
1789 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1790 result = winreg_printer_write_sz(tmp_ctx,
1795 if (!W_ERROR_IS_OK(result)) {
1800 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1801 result = winreg_printer_write_sz(tmp_ctx,
1806 if (!W_ERROR_IS_OK(result)) {
1811 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1812 result = winreg_printer_write_sz(tmp_ctx,
1817 if (!W_ERROR_IS_OK(result)) {
1822 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1823 result = winreg_printer_write_sz(tmp_ctx,
1828 if (!W_ERROR_IS_OK(result)) {
1833 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1835 * in addprinter: no servername and the printer is the name
1836 * in setprinter: servername is \\server
1837 * and printer is \\server\\printer
1839 * Samba manages only local printers.
1840 * we currently don't support things like i
1841 * path=\\other_server\printer
1843 * We only store the printername, not \\server\printername
1845 const char *p = strrchr(info2->printername, '\\');
1847 p = info2->printername;
1851 result = winreg_printer_write_sz(tmp_ctx,
1856 if (!W_ERROR_IS_OK(result)) {
1861 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1862 result = winreg_printer_write_sz(tmp_ctx,
1866 info2->printprocessor);
1867 if (!W_ERROR_IS_OK(result)) {
1872 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1873 result = winreg_printer_write_dword(tmp_ctx,
1878 if (!W_ERROR_IS_OK(result)) {
1883 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1885 * We need a security descriptor, if it isn't specified by
1886 * AddPrinter{Ex} then create a default descriptor.
1888 if (secdesc == NULL) {
1889 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1890 if (!W_ERROR_IS_OK(result)) {
1894 result = winreg_set_printer_secdesc(tmp_ctx,
1899 if (!W_ERROR_IS_OK(result)) {
1904 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1905 result = winreg_printer_write_sz(tmp_ctx,
1910 if (!W_ERROR_IS_OK(result)) {
1915 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1916 result = winreg_printer_write_sz(tmp_ctx,
1921 if (!W_ERROR_IS_OK(result)) {
1926 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1927 result = winreg_printer_write_dword(tmp_ctx,
1932 if (!W_ERROR_IS_OK(result)) {
1937 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1938 result = winreg_printer_write_dword(tmp_ctx,
1943 if (!W_ERROR_IS_OK(result)) {
1948 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1949 result = winreg_printer_write_dword(tmp_ctx,
1954 if (!W_ERROR_IS_OK(result)) {
1959 result = winreg_printer_write_dword(tmp_ctx,
1963 winreg_printer_rev_changeid());
1964 if (!W_ERROR_IS_OK(result)) {
1970 if (winreg_handle != NULL) {
1973 if (is_valid_policy_hnd(&key_hnd)) {
1974 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
1976 if (is_valid_policy_hnd(&hive_hnd)) {
1977 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
1981 TALLOC_FREE(tmp_ctx);
1985 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1986 struct auth_serversupplied_info *server_info,
1987 struct messaging_context *msg_ctx,
1988 const char *servername,
1989 const char *printer,
1990 struct spoolss_PrinterInfo2 **pinfo2)
1992 struct spoolss_PrinterInfo2 *info2;
1993 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1994 struct dcerpc_binding_handle *winreg_handle = NULL;
1995 struct policy_handle hive_hnd, key_hnd;
1996 struct spoolss_PrinterEnumValues *enum_values = NULL;
1997 struct spoolss_PrinterEnumValues *v;
1998 enum ndr_err_code ndr_err;
2000 int snum = lp_servicenumber(printer);
2001 uint32_t num_values = 0;
2004 WERROR result = WERR_OK;
2005 TALLOC_CTX *tmp_ctx;
2007 tmp_ctx = talloc_stackframe();
2008 if (tmp_ctx == NULL) {
2012 path = winreg_printer_data_keyname(tmp_ctx, printer);
2014 TALLOC_FREE(tmp_ctx);
2018 result = winreg_printer_openkey(tmp_ctx,
2028 if (!W_ERROR_IS_OK(result)) {
2029 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
2030 path, win_errstr(result)));
2034 result = winreg_printer_enumvalues(tmp_ctx,
2039 if (!W_ERROR_IS_OK(result)) {
2040 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
2041 path, win_errstr(result)));
2045 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
2046 if (info2 == NULL) {
2047 result = WERR_NOMEM;
2051 FILL_STRING(info2, EMPTY_STRING, info2->servername);
2052 FILL_STRING(info2, EMPTY_STRING, info2->printername);
2053 FILL_STRING(info2, EMPTY_STRING, info2->sharename);
2054 FILL_STRING(info2, EMPTY_STRING, info2->portname);
2055 FILL_STRING(info2, EMPTY_STRING, info2->drivername);
2056 FILL_STRING(info2, EMPTY_STRING, info2->comment);
2057 FILL_STRING(info2, EMPTY_STRING, info2->location);
2058 FILL_STRING(info2, EMPTY_STRING, info2->sepfile);
2059 FILL_STRING(info2, EMPTY_STRING, info2->printprocessor);
2060 FILL_STRING(info2, EMPTY_STRING, info2->datatype);
2061 FILL_STRING(info2, EMPTY_STRING, info2->parameters);
2063 if (servername != NULL && servername[0] != '\0') {
2064 info2->servername = talloc_asprintf(info2, "\\\\%s", servername);
2065 if (info2->servername == NULL) {
2066 result = WERR_NOMEM;
2071 for (i = 0; i < num_values; i++) {
2072 v = &enum_values[i];
2074 result = winreg_enumval_to_sz(info2,
2077 &info2->printername);
2078 CHECK_ERROR(result);
2080 result = winreg_enumval_to_sz(info2,
2084 CHECK_ERROR(result);
2086 result = winreg_enumval_to_sz(info2,
2090 CHECK_ERROR(result);
2092 result = winreg_enumval_to_sz(info2,
2096 CHECK_ERROR(result);
2098 result = winreg_enumval_to_sz(info2,
2102 CHECK_ERROR(result);
2104 result = winreg_enumval_to_sz(info2,
2108 CHECK_ERROR(result);
2110 result = winreg_enumval_to_sz(info2,
2113 &info2->printprocessor);
2114 CHECK_ERROR(result);
2116 result = winreg_enumval_to_sz(info2,
2120 CHECK_ERROR(result);
2122 result = winreg_enumval_to_sz(info2,
2125 &info2->parameters);
2126 CHECK_ERROR(result);
2128 result = winreg_enumval_to_sz(info2,
2131 &info2->drivername);
2132 CHECK_ERROR(result);
2134 result = winreg_enumval_to_dword(info2,
2137 &info2->attributes);
2138 CHECK_ERROR(result);
2140 result = winreg_enumval_to_dword(info2,
2144 CHECK_ERROR(result);
2146 result = winreg_enumval_to_dword(info2,
2149 &info2->defaultpriority);
2150 CHECK_ERROR(result);
2152 result = winreg_enumval_to_dword(info2,
2156 CHECK_ERROR(result);
2158 result = winreg_enumval_to_dword(info2,
2162 CHECK_ERROR(result);
2164 result = winreg_enumval_to_dword(info2,
2168 CHECK_ERROR(result);
2170 result = winreg_enumval_to_dword(info2,
2174 CHECK_ERROR(result);
2177 if (!W_ERROR_IS_OK(result)) {
2178 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2181 win_errstr(result)));
2185 /* Create the printername */
2186 if (info2->servername != NULL && info2->servername[0] != '\0') {
2187 if (lp_force_printername(snum)) {
2188 const char *p = talloc_asprintf(info2, "%s\\%s",
2192 result = WERR_NOMEM;
2195 info2->printername = p;
2197 char *p = talloc_asprintf(info2, "%s\\%s",
2199 info2->printername);
2201 result = WERR_NOMEM;
2204 info2->printername = p;
2208 /* Construct the Device Mode */
2209 result = winreg_printer_query_binary(tmp_ctx,
2214 if (W_ERROR_IS_OK(result)) {
2215 info2->devmode = talloc_zero(info2, struct spoolss_DeviceMode);
2216 if (info2->devmode == NULL) {
2217 result = WERR_NOMEM;
2220 ndr_err = ndr_pull_struct_blob(&blob,
2223 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
2224 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2225 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2226 result = WERR_NOMEM;
2231 if (info2->devmode == NULL && lp_default_devmode(snum)) {
2232 result = spoolss_create_default_devmode(info2,
2235 if (!W_ERROR_IS_OK(result)) {
2240 if (info2->devmode != NULL) {
2241 info2->devmode->devicename = talloc_strdup(info2->devmode,
2242 info2->printername);
2243 if (info2->devmode->devicename == NULL) {
2244 DEBUG(0, ("winreg_get_printer: Failed to set devicename\n"));
2245 result = WERR_NOMEM;
2250 result = winreg_get_printer_secdesc(info2,
2255 if (!W_ERROR_IS_OK(result)) {
2259 /* Fix for OS/2 drivers. */
2260 if (get_remote_arch() == RA_OS2) {
2261 spoolss_map_to_os2_driver(info2, &info2->drivername);
2265 *pinfo2 = talloc_move(mem_ctx, &info2);
2270 if (winreg_handle != NULL) {
2273 if (is_valid_policy_hnd(&key_hnd)) {
2274 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2276 if (is_valid_policy_hnd(&hive_hnd)) {
2277 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2281 TALLOC_FREE(tmp_ctx);
2285 WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
2286 struct auth_serversupplied_info *server_info,
2287 struct messaging_context *msg_ctx,
2288 const char *sharename,
2289 struct spoolss_security_descriptor **psecdesc)
2291 struct spoolss_security_descriptor *secdesc;
2292 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2293 struct dcerpc_binding_handle *winreg_handle = NULL;
2294 struct policy_handle hive_hnd, key_hnd;
2295 enum ndr_err_code ndr_err;
2298 TALLOC_CTX *tmp_ctx;
2301 tmp_ctx = talloc_stackframe();
2302 if (tmp_ctx == NULL) {
2306 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2308 talloc_free(tmp_ctx);
2312 ZERO_STRUCT(hive_hnd);
2313 ZERO_STRUCT(key_hnd);
2315 result = winreg_printer_openkey(tmp_ctx,
2325 if (!W_ERROR_IS_OK(result)) {
2326 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2327 goto create_default;
2332 result = winreg_printer_query_binary(tmp_ctx,
2337 if (!W_ERROR_IS_OK(result)) {
2338 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2339 goto create_default;
2344 secdesc = talloc_zero(tmp_ctx, struct spoolss_security_descriptor);
2345 if (secdesc == NULL) {
2346 result = WERR_NOMEM;
2349 ndr_err = ndr_pull_struct_blob(&blob,
2352 (ndr_pull_flags_fn_t) ndr_pull_security_descriptor);
2353 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2354 DEBUG(0, ("winreg_get_secdesc: Failed to unmarshall security descriptor\n"));
2355 result = WERR_NOMEM;
2360 *psecdesc = talloc_move(mem_ctx, &secdesc);
2367 result = winreg_printer_openkey(tmp_ctx,
2377 if (!W_ERROR_IS_OK(result)) {
2381 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
2382 if (!W_ERROR_IS_OK(result)) {
2386 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
2387 this security descriptor has been created when winbindd was
2388 down. Take ownership of security descriptor. */
2389 if (sid_equal(secdesc->owner_sid, &global_sid_World)) {
2390 struct dom_sid owner_sid;
2392 /* Change sd owner to workgroup administrator */
2394 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid)) {
2395 struct spoolss_security_descriptor *new_secdesc;
2399 sid_append_rid(&owner_sid, DOMAIN_RID_ADMINISTRATOR);
2401 new_secdesc = make_sec_desc(tmp_ctx,
2410 if (new_secdesc == NULL) {
2411 result = WERR_NOMEM;
2415 /* Swap with other one */
2416 secdesc = new_secdesc;
2420 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, secdesc,
2421 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2422 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2423 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2424 result = WERR_NOMEM;
2428 result = winreg_printer_write_binary(tmp_ctx,
2433 if (!W_ERROR_IS_OK(result)) {
2438 *psecdesc = talloc_move(mem_ctx, &secdesc);
2443 if (winreg_handle != NULL) {
2446 if (is_valid_policy_hnd(&key_hnd)) {
2447 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2449 if (is_valid_policy_hnd(&hive_hnd)) {
2450 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2454 talloc_free(tmp_ctx);
2458 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
2459 struct auth_serversupplied_info *server_info,
2460 struct messaging_context *msg_ctx,
2461 const char *sharename,
2462 const struct spoolss_security_descriptor *secdesc)
2464 const struct spoolss_security_descriptor *new_secdesc = secdesc;
2465 struct spoolss_security_descriptor *old_secdesc;
2466 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2467 struct dcerpc_binding_handle *winreg_handle = NULL;
2468 struct policy_handle hive_hnd, key_hnd;
2469 enum ndr_err_code ndr_err;
2472 TALLOC_CTX *tmp_ctx;
2475 tmp_ctx = talloc_stackframe();
2476 if (tmp_ctx == NULL) {
2480 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2482 talloc_free(tmp_ctx);
2487 * The old owner and group sids of the security descriptor are not
2488 * present when new ACEs are added or removed by changing printer
2489 * permissions through NT. If they are NULL in the new security
2490 * descriptor then copy them over from the old one.
2492 if (!secdesc->owner_sid || !secdesc->group_sid) {
2493 struct dom_sid *owner_sid, *group_sid;
2494 struct security_acl *dacl, *sacl;
2497 result = winreg_get_printer_secdesc(tmp_ctx,
2502 if (!W_ERROR_IS_OK(result)) {
2503 talloc_free(tmp_ctx);
2507 /* Pick out correct owner and group sids */
2508 owner_sid = secdesc->owner_sid ?
2509 secdesc->owner_sid :
2510 old_secdesc->owner_sid;
2512 group_sid = secdesc->group_sid ?
2513 secdesc->group_sid :
2514 old_secdesc->group_sid;
2516 dacl = secdesc->dacl ?
2520 sacl = secdesc->sacl ?
2524 /* Make a deep copy of the security descriptor */
2525 new_secdesc = make_sec_desc(tmp_ctx,
2533 if (new_secdesc == NULL) {
2534 talloc_free(tmp_ctx);
2539 ZERO_STRUCT(hive_hnd);
2540 ZERO_STRUCT(key_hnd);
2542 result = winreg_printer_openkey(tmp_ctx,
2552 if (!W_ERROR_IS_OK(result)) {
2556 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, new_secdesc,
2557 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2558 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2559 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2560 result = WERR_NOMEM;
2564 result = winreg_printer_write_binary(tmp_ctx,
2571 if (winreg_handle != NULL) {
2574 if (is_valid_policy_hnd(&key_hnd)) {
2575 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2577 if (is_valid_policy_hnd(&hive_hnd)) {
2578 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2582 talloc_free(tmp_ctx);
2586 /* Set printer data over the winreg pipe. */
2587 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2588 struct auth_serversupplied_info *server_info,
2589 struct messaging_context *msg_ctx,
2590 const char *printer,
2593 enum winreg_Type type,
2597 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2598 struct dcerpc_binding_handle *winreg_handle = NULL;
2599 struct policy_handle hive_hnd, key_hnd;
2600 struct winreg_String wvalue;
2602 WERROR result = WERR_OK;
2604 TALLOC_CTX *tmp_ctx;
2606 tmp_ctx = talloc_stackframe();
2607 if (tmp_ctx == NULL) {
2611 path = winreg_printer_data_keyname(tmp_ctx, printer);
2613 TALLOC_FREE(tmp_ctx);
2617 ZERO_STRUCT(hive_hnd);
2618 ZERO_STRUCT(key_hnd);
2620 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2621 key, value, access_mask, printer));
2622 result = winreg_printer_openkey(tmp_ctx,
2632 if (!W_ERROR_IS_OK(result)) {
2633 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2634 key, win_errstr(result)));
2638 wvalue.name = value;
2639 status = dcerpc_winreg_SetValue(winreg_handle,
2647 if (!NT_STATUS_IS_OK(status)) {
2648 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2649 value, nt_errstr(status)));
2650 result = ntstatus_to_werror(status);
2654 if (winreg_handle != NULL) {
2657 if (is_valid_policy_hnd(&key_hnd)) {
2658 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2660 if (is_valid_policy_hnd(&hive_hnd)) {
2661 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2665 TALLOC_FREE(tmp_ctx);
2669 /* Get printer data over a winreg pipe. */
2670 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2671 struct auth_serversupplied_info *server_info,
2672 struct messaging_context *msg_ctx,
2673 const char *printer,
2676 enum winreg_Type *type,
2678 uint32_t *data_size)
2680 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2681 struct dcerpc_binding_handle *winreg_handle = NULL;
2682 struct policy_handle hive_hnd, key_hnd;
2683 struct winreg_String wvalue;
2684 enum winreg_Type type_in;
2687 uint32_t data_in_size = 0;
2688 uint32_t value_len = 0;
2689 WERROR result = WERR_OK;
2691 TALLOC_CTX *tmp_ctx;
2693 tmp_ctx = talloc_stackframe();
2694 if (tmp_ctx == NULL) {
2698 path = winreg_printer_data_keyname(tmp_ctx, printer);
2700 TALLOC_FREE(tmp_ctx);
2704 ZERO_STRUCT(hive_hnd);
2705 ZERO_STRUCT(key_hnd);
2707 result = winreg_printer_openkey(tmp_ctx,
2717 if (!W_ERROR_IS_OK(result)) {
2718 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2719 key, win_errstr(result)));
2723 wvalue.name = value;
2726 * call QueryValue once with data == NULL to get the
2727 * needed memory size to be allocated, then allocate
2728 * data buffer and call again.
2730 status = dcerpc_winreg_QueryValue(winreg_handle,
2739 if (!NT_STATUS_IS_OK(status)) {
2740 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2741 value, nt_errstr(status)));
2742 result = ntstatus_to_werror(status);
2745 if (!W_ERROR_IS_OK(result)) {
2749 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2750 if (data_in == NULL) {
2751 result = WERR_NOMEM;
2756 status = dcerpc_winreg_QueryValue(winreg_handle,
2765 if (!NT_STATUS_IS_OK(status)) {
2766 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2767 value, nt_errstr(status)));
2768 result = ntstatus_to_werror(status);
2771 if (!W_ERROR_IS_OK(result)) {
2776 *data_size = data_in_size;
2778 *data = talloc_move(mem_ctx, &data_in);
2783 if (winreg_handle != NULL) {
2786 if (is_valid_policy_hnd(&key_hnd)) {
2787 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2789 if (is_valid_policy_hnd(&hive_hnd)) {
2790 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2794 TALLOC_FREE(tmp_ctx);
2798 /* Enumerate on the values of a given key and provide the data. */
2799 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2800 struct auth_serversupplied_info *server_info,
2801 struct messaging_context *msg_ctx,
2802 const char *printer,
2804 uint32_t *pnum_values,
2805 struct spoolss_PrinterEnumValues **penum_values)
2807 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2808 struct dcerpc_binding_handle *winreg_handle = NULL;
2809 struct policy_handle hive_hnd, key_hnd;
2811 struct spoolss_PrinterEnumValues *enum_values = NULL;
2812 uint32_t num_values = 0;
2814 WERROR result = WERR_OK;
2816 TALLOC_CTX *tmp_ctx;
2818 tmp_ctx = talloc_stackframe();
2819 if (tmp_ctx == NULL) {
2823 path = winreg_printer_data_keyname(tmp_ctx, printer);
2825 TALLOC_FREE(tmp_ctx);
2829 result = winreg_printer_openkey(tmp_ctx,
2839 if (!W_ERROR_IS_OK(result)) {
2840 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2841 key, win_errstr(result)));
2845 result = winreg_printer_enumvalues(tmp_ctx,
2850 if (!W_ERROR_IS_OK(result)) {
2851 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2852 key, win_errstr(result)));
2856 *pnum_values = num_values;
2858 *penum_values = talloc_move(mem_ctx, &enum_values);
2863 if (winreg_handle != NULL) {
2866 if (is_valid_policy_hnd(&key_hnd)) {
2867 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2869 if (is_valid_policy_hnd(&hive_hnd)) {
2870 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2874 TALLOC_FREE(tmp_ctx);
2878 /* Delete printer data over a winreg pipe. */
2879 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2880 struct auth_serversupplied_info *server_info,
2881 struct messaging_context *msg_ctx,
2882 const char *printer,
2886 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2887 struct dcerpc_binding_handle *winreg_handle = NULL;
2888 struct policy_handle hive_hnd, key_hnd;
2889 struct winreg_String wvalue;
2891 WERROR result = WERR_OK;
2894 TALLOC_CTX *tmp_ctx;
2896 tmp_ctx = talloc_stackframe();
2897 if (tmp_ctx == NULL) {
2901 path = winreg_printer_data_keyname(tmp_ctx, printer);
2903 TALLOC_FREE(tmp_ctx);
2907 ZERO_STRUCT(hive_hnd);
2908 ZERO_STRUCT(key_hnd);
2910 result = winreg_printer_openkey(tmp_ctx,
2920 if (!W_ERROR_IS_OK(result)) {
2921 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2922 key, win_errstr(result)));
2926 wvalue.name = value;
2927 status = dcerpc_winreg_DeleteValue(winreg_handle,
2932 if (!NT_STATUS_IS_OK(status)) {
2933 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2934 value, nt_errstr(status)));
2935 result = ntstatus_to_werror(status);
2939 if (winreg_handle != NULL) {
2942 if (is_valid_policy_hnd(&key_hnd)) {
2943 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
2945 if (is_valid_policy_hnd(&hive_hnd)) {
2946 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
2950 TALLOC_FREE(tmp_ctx);
2954 /* Enumerate on the subkeys of a given key and provide the data. */
2955 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2956 struct auth_serversupplied_info *server_info,
2957 struct messaging_context *msg_ctx,
2958 const char *printer,
2960 uint32_t *pnum_subkeys,
2961 const char ***psubkeys)
2963 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2964 struct dcerpc_binding_handle *winreg_handle = NULL;
2965 struct policy_handle hive_hnd, key_hnd;
2967 const char **subkeys = NULL;
2968 uint32_t num_subkeys = -1;
2970 WERROR result = WERR_OK;
2972 TALLOC_CTX *tmp_ctx;
2974 tmp_ctx = talloc_stackframe();
2975 if (tmp_ctx == NULL) {
2979 path = winreg_printer_data_keyname(tmp_ctx, printer);
2981 TALLOC_FREE(tmp_ctx);
2985 ZERO_STRUCT(hive_hnd);
2986 ZERO_STRUCT(key_hnd);
2988 result = winreg_printer_openkey(tmp_ctx,
2998 if (!W_ERROR_IS_OK(result)) {
2999 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
3000 key, win_errstr(result)));
3004 result = winreg_printer_enumkeys(tmp_ctx,
3009 if (!W_ERROR_IS_OK(result)) {
3010 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
3011 key, win_errstr(result)));
3015 *pnum_subkeys = num_subkeys;
3017 *psubkeys = talloc_move(mem_ctx, &subkeys);
3022 if (winreg_handle != NULL) {
3025 if (is_valid_policy_hnd(&key_hnd)) {
3026 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3028 if (is_valid_policy_hnd(&hive_hnd)) {
3029 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3033 TALLOC_FREE(tmp_ctx);
3037 /* Delete a key with subkeys of a given printer. */
3038 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
3039 struct auth_serversupplied_info *server_info,
3040 struct messaging_context *msg_ctx,
3041 const char *printer,
3044 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3045 struct dcerpc_binding_handle *winreg_handle = NULL;
3046 struct policy_handle hive_hnd, key_hnd;
3050 TALLOC_CTX *tmp_ctx;
3052 tmp_ctx = talloc_stackframe();
3053 if (tmp_ctx == NULL) {
3057 path = winreg_printer_data_keyname(tmp_ctx, printer);
3059 TALLOC_FREE(tmp_ctx);
3063 result = winreg_printer_openkey(tmp_ctx,
3073 if (!W_ERROR_IS_OK(result)) {
3074 /* key doesn't exist */
3075 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3080 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
3081 key, win_errstr(result)));
3085 if (is_valid_policy_hnd(&key_hnd)) {
3086 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
3089 if (key == NULL || key[0] == '\0') {
3092 keyname = talloc_asprintf(tmp_ctx,
3096 if (keyname == NULL) {
3097 result = WERR_NOMEM;
3102 result = winreg_printer_delete_subkeys(tmp_ctx,
3107 if (!W_ERROR_IS_OK(result)) {
3108 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
3109 key, win_errstr(result)));
3114 if (winreg_handle != NULL) {
3117 if (is_valid_policy_hnd(&key_hnd)) {
3118 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3120 if (is_valid_policy_hnd(&hive_hnd)) {
3121 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3125 TALLOC_FREE(tmp_ctx);
3129 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
3130 struct auth_serversupplied_info *server_info,
3131 struct messaging_context *msg_ctx,
3132 const char *printer)
3134 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3135 struct dcerpc_binding_handle *winreg_handle = NULL;
3136 struct policy_handle hive_hnd, key_hnd;
3139 TALLOC_CTX *tmp_ctx;
3141 tmp_ctx = talloc_stackframe();
3142 if (tmp_ctx == NULL) {
3146 path = winreg_printer_data_keyname(tmp_ctx, printer);
3148 TALLOC_FREE(tmp_ctx);
3152 ZERO_STRUCT(hive_hnd);
3153 ZERO_STRUCT(key_hnd);
3155 result = winreg_printer_openkey(tmp_ctx,
3165 if (!W_ERROR_IS_OK(result)) {
3166 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
3167 path, win_errstr(result)));
3171 result = winreg_printer_write_dword(tmp_ctx,
3175 winreg_printer_rev_changeid());
3176 if (!W_ERROR_IS_OK(result)) {
3182 if (winreg_handle != NULL) {
3185 if (is_valid_policy_hnd(&key_hnd)) {
3186 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3188 if (is_valid_policy_hnd(&hive_hnd)) {
3189 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3193 TALLOC_FREE(tmp_ctx);
3197 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
3198 struct auth_serversupplied_info *server_info,
3199 struct messaging_context *msg_ctx,
3200 const char *printer,
3201 uint32_t *pchangeid)
3203 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3204 struct dcerpc_binding_handle *winreg_handle = NULL;
3205 struct policy_handle hive_hnd, key_hnd;
3206 uint32_t changeid = 0;
3209 TALLOC_CTX *tmp_ctx;
3211 tmp_ctx = talloc_stackframe();
3212 if (tmp_ctx == NULL) {
3216 path = winreg_printer_data_keyname(tmp_ctx, printer);
3218 TALLOC_FREE(tmp_ctx);
3222 ZERO_STRUCT(hive_hnd);
3223 ZERO_STRUCT(key_hnd);
3225 result = winreg_printer_openkey(tmp_ctx,
3235 if (!W_ERROR_IS_OK(result)) {
3236 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
3237 path, win_errstr(result)));
3241 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path));
3243 result = winreg_printer_query_dword(tmp_ctx,
3248 if (!W_ERROR_IS_OK(result)) {
3253 *pchangeid = changeid;
3258 if (winreg_handle != NULL) {
3261 if (is_valid_policy_hnd(&key_hnd)) {
3262 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3264 if (is_valid_policy_hnd(&hive_hnd)) {
3265 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3269 TALLOC_FREE(tmp_ctx);
3274 * The special behaviour of the spoolss forms is documented at the website:
3276 * Managing Win32 Printserver Forms
3277 * http://unixwiz.net/techtips/winspooler-forms.html
3280 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
3281 struct auth_serversupplied_info *server_info,
3282 struct messaging_context *msg_ctx,
3283 struct spoolss_AddFormInfo1 *form)
3285 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3286 struct dcerpc_binding_handle *winreg_handle = NULL;
3287 struct policy_handle hive_hnd, key_hnd;
3288 struct winreg_String wvalue;
3290 uint32_t num_info = 0;
3291 union spoolss_FormInfo *info = NULL;
3295 TALLOC_CTX *tmp_ctx;
3297 tmp_ctx = talloc_stackframe();
3298 if (tmp_ctx == NULL) {
3302 ZERO_STRUCT(hive_hnd);
3303 ZERO_STRUCT(key_hnd);
3305 result = winreg_printer_openkey(tmp_ctx,
3309 TOP_LEVEL_CONTROL_FORMS_KEY,
3315 if (!W_ERROR_IS_OK(result)) {
3316 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
3317 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3321 result = winreg_printer_enumforms1(tmp_ctx, server_info, msg_ctx,
3323 if (!W_ERROR_IS_OK(result)) {
3324 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
3325 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3329 /* If form name already exists or is builtin return ALREADY_EXISTS */
3330 for (i = 0; i < num_info; i++) {
3331 if (strequal(info[i].info1.form_name, form->form_name)) {
3332 result = WERR_FILE_EXISTS;
3337 wvalue.name = form->form_name;
3339 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3340 SIVAL(blob.data, 0, form->size.width);
3341 SIVAL(blob.data, 4, form->size.height);
3342 SIVAL(blob.data, 8, form->area.left);
3343 SIVAL(blob.data, 12, form->area.top);
3344 SIVAL(blob.data, 16, form->area.right);
3345 SIVAL(blob.data, 20, form->area.bottom);
3346 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
3347 SIVAL(blob.data, 28, form->flags);
3349 status = dcerpc_winreg_SetValue(winreg_handle,
3357 if (!NT_STATUS_IS_OK(status)) {
3358 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
3359 wvalue.name, nt_errstr(status)));
3360 result = ntstatus_to_werror(status);
3364 if (winreg_handle != NULL) {
3367 if (is_valid_policy_hnd(&key_hnd)) {
3368 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3370 if (is_valid_policy_hnd(&hive_hnd)) {
3371 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3376 TALLOC_FREE(tmp_ctx);
3380 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
3381 struct auth_serversupplied_info *server_info,
3382 struct messaging_context *msg_ctx,
3383 uint32_t *pnum_info,
3384 union spoolss_FormInfo **pinfo)
3386 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3387 struct dcerpc_binding_handle *winreg_handle = NULL;
3388 struct policy_handle hive_hnd, key_hnd;
3389 union spoolss_FormInfo *info;
3390 struct spoolss_PrinterEnumValues *enum_values = NULL;
3391 uint32_t num_values = 0;
3392 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3395 TALLOC_CTX *tmp_ctx;
3397 tmp_ctx = talloc_stackframe();
3398 if (tmp_ctx == NULL) {
3402 ZERO_STRUCT(hive_hnd);
3403 ZERO_STRUCT(key_hnd);
3405 result = winreg_printer_openkey(tmp_ctx,
3409 TOP_LEVEL_CONTROL_FORMS_KEY,
3415 if (!W_ERROR_IS_OK(result)) {
3416 /* key doesn't exist */
3417 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3422 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3423 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3427 result = winreg_printer_enumvalues(tmp_ctx,
3432 if (!W_ERROR_IS_OK(result)) {
3433 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3434 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3438 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
3440 result = WERR_NOMEM;
3444 /* Enumerate BUILTIN forms */
3445 for (i = 0; i < num_builtin; i++) {
3446 info[i].info1 = builtin_forms1[i];
3449 /* Enumerate registry forms */
3450 for (i = 0; i < num_values; i++) {
3451 union spoolss_FormInfo val;
3453 if (enum_values[i].type != REG_BINARY ||
3454 enum_values[i].data_length != 32) {
3458 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
3459 if (val.info1.form_name == NULL) {
3460 result = WERR_NOMEM;
3464 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3465 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3466 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3467 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3468 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3469 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3470 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3471 val.info1.flags = (enum spoolss_FormFlags) IVAL(enum_values[i].data->data, 28);
3473 info[i + num_builtin] = val;
3476 *pnum_info = num_builtin + num_values;
3478 *pinfo = talloc_move(mem_ctx, &info);
3482 if (winreg_handle != NULL) {
3485 if (is_valid_policy_hnd(&key_hnd)) {
3486 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3488 if (is_valid_policy_hnd(&hive_hnd)) {
3489 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3493 TALLOC_FREE(enum_values);
3494 TALLOC_FREE(tmp_ctx);
3498 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3499 struct auth_serversupplied_info *server_info,
3500 struct messaging_context *msg_ctx,
3501 const char *form_name)
3503 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3504 struct dcerpc_binding_handle *winreg_handle = NULL;
3505 struct policy_handle hive_hnd, key_hnd;
3506 struct winreg_String wvalue;
3507 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3509 WERROR result = WERR_OK;
3511 TALLOC_CTX *tmp_ctx;
3513 for (i = 0; i < num_builtin; i++) {
3514 if (strequal(builtin_forms1[i].form_name, form_name)) {
3515 return WERR_INVALID_PARAMETER;
3519 tmp_ctx = talloc_stackframe();
3520 if (tmp_ctx == NULL) {
3524 ZERO_STRUCT(hive_hnd);
3525 ZERO_STRUCT(key_hnd);
3527 result = winreg_printer_openkey(tmp_ctx,
3531 TOP_LEVEL_CONTROL_FORMS_KEY,
3537 if (!W_ERROR_IS_OK(result)) {
3538 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3539 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3540 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3541 result = WERR_INVALID_FORM_NAME;
3546 wvalue.name = form_name;
3547 status = dcerpc_winreg_DeleteValue(winreg_handle,
3552 if (!NT_STATUS_IS_OK(status)) {
3553 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3554 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3555 wvalue.name, nt_errstr(status)));
3556 result = ntstatus_to_werror(status);
3560 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3561 result = WERR_INVALID_FORM_NAME;
3565 if (winreg_handle != NULL) {
3568 if (is_valid_policy_hnd(&key_hnd)) {
3569 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3571 if (is_valid_policy_hnd(&hive_hnd)) {
3572 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3576 TALLOC_FREE(tmp_ctx);
3580 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3581 struct auth_serversupplied_info *server_info,
3582 struct messaging_context *msg_ctx,
3583 const char *form_name,
3584 struct spoolss_AddFormInfo1 *form)
3586 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3587 struct dcerpc_binding_handle *winreg_handle = NULL;
3588 struct policy_handle hive_hnd, key_hnd;
3589 struct winreg_String wvalue;
3591 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3595 TALLOC_CTX *tmp_ctx = NULL;
3597 for (i = 0; i < num_builtin; i++) {
3598 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3599 result = WERR_INVALID_PARAM;
3604 tmp_ctx = talloc_stackframe();
3605 if (tmp_ctx == NULL) {
3609 ZERO_STRUCT(hive_hnd);
3610 ZERO_STRUCT(key_hnd);
3612 result = winreg_printer_openkey(tmp_ctx,
3616 TOP_LEVEL_CONTROL_FORMS_KEY,
3622 if (!W_ERROR_IS_OK(result)) {
3623 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3624 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3628 /* If form_name != form->form_name then we renamed the form */
3629 if (strequal(form_name, form->form_name)) {
3630 result = winreg_printer_deleteform1(tmp_ctx, server_info,
3631 msg_ctx, form_name);
3632 if (!W_ERROR_IS_OK(result)) {
3633 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3634 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3639 wvalue.name = form->form_name;
3641 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3642 SIVAL(blob.data, 0, form->size.width);
3643 SIVAL(blob.data, 4, form->size.height);
3644 SIVAL(blob.data, 8, form->area.left);
3645 SIVAL(blob.data, 12, form->area.top);
3646 SIVAL(blob.data, 16, form->area.right);
3647 SIVAL(blob.data, 20, form->area.bottom);
3648 SIVAL(blob.data, 24, 42);
3649 SIVAL(blob.data, 28, form->flags);
3651 status = dcerpc_winreg_SetValue(winreg_handle,
3659 if (!NT_STATUS_IS_OK(status)) {
3660 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3661 wvalue.name, nt_errstr(status)));
3662 result = ntstatus_to_werror(status);
3666 if (winreg_handle != NULL) {
3669 if (is_valid_policy_hnd(&key_hnd)) {
3670 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3672 if (is_valid_policy_hnd(&hive_hnd)) {
3673 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3677 TALLOC_FREE(tmp_ctx);
3681 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3682 struct auth_serversupplied_info *server_info,
3683 struct messaging_context *msg_ctx,
3684 const char *form_name,
3685 struct spoolss_FormInfo1 *r)
3687 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3688 struct dcerpc_binding_handle *winreg_handle = NULL;
3689 struct policy_handle hive_hnd, key_hnd;
3690 struct winreg_String wvalue;
3691 enum winreg_Type type_in;
3693 uint32_t data_in_size = 0;
3694 uint32_t value_len = 0;
3695 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3699 TALLOC_CTX *tmp_ctx;
3701 /* check builtin forms first */
3702 for (i = 0; i < num_builtin; i++) {
3703 if (strequal(builtin_forms1[i].form_name, form_name)) {
3704 *r = builtin_forms1[i];
3709 tmp_ctx = talloc_stackframe();
3710 if (tmp_ctx == NULL) {
3714 ZERO_STRUCT(hive_hnd);
3715 ZERO_STRUCT(key_hnd);
3717 result = winreg_printer_openkey(tmp_ctx,
3721 TOP_LEVEL_CONTROL_FORMS_KEY,
3727 if (!W_ERROR_IS_OK(result)) {
3728 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3729 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3733 wvalue.name = form_name;
3736 * call QueryValue once with data == NULL to get the
3737 * needed memory size to be allocated, then allocate
3738 * data buffer and call again.
3740 status = dcerpc_winreg_QueryValue(winreg_handle,
3749 if (!NT_STATUS_IS_OK(status)) {
3750 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3751 wvalue.name, nt_errstr(status)));
3752 result = ntstatus_to_werror(status);
3755 if (!W_ERROR_IS_OK(result)) {
3759 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3760 if (data_in == NULL) {
3761 result = WERR_NOMEM;
3766 status = dcerpc_winreg_QueryValue(winreg_handle,
3775 if (!NT_STATUS_IS_OK(status)) {
3776 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3777 wvalue.name, nt_errstr(status)));
3778 result = ntstatus_to_werror(status);
3781 if (!W_ERROR_IS_OK(result)) {
3785 r->form_name = talloc_strdup(mem_ctx, form_name);
3786 if (r->form_name == NULL) {
3787 result = WERR_NOMEM;
3791 r->size.width = IVAL(data_in, 0);
3792 r->size.height = IVAL(data_in, 4);
3793 r->area.left = IVAL(data_in, 8);
3794 r->area.top = IVAL(data_in, 12);
3795 r->area.right = IVAL(data_in, 16);
3796 r->area.bottom = IVAL(data_in, 20);
3797 /* skip index IVAL(data_in, 24)));*/
3798 r->flags = (enum spoolss_FormFlags) IVAL(data_in, 28);
3802 if (winreg_handle != NULL) {
3805 if (is_valid_policy_hnd(&key_hnd)) {
3806 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
3808 if (is_valid_policy_hnd(&hive_hnd)) {
3809 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
3813 TALLOC_FREE(tmp_ctx);
3817 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3818 struct auth_serversupplied_info *server_info,
3819 struct messaging_context *msg_ctx,
3820 struct spoolss_AddDriverInfoCtr *r,
3821 const char **driver_name,
3822 uint32_t *driver_version)
3824 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3825 struct dcerpc_binding_handle *winreg_handle = NULL;
3826 struct policy_handle hive_hnd, key_hnd;
3827 struct spoolss_DriverInfo8 info8;
3828 TALLOC_CTX *tmp_ctx = NULL;
3831 ZERO_STRUCT(hive_hnd);
3832 ZERO_STRUCT(key_hnd);
3835 if (!driver_info_ctr_to_info8(r, &info8)) {
3836 result = WERR_INVALID_PARAMETER;
3840 tmp_ctx = talloc_stackframe();
3841 if (tmp_ctx == NULL) {
3845 result = winreg_printer_opendriver(tmp_ctx,
3855 if (!W_ERROR_IS_OK(result)) {
3856 DEBUG(0, ("winreg_add_driver: "
3857 "Could not open driver key (%s,%s,%d): %s\n",
3858 info8.driver_name, info8.architecture,
3859 info8.version, win_errstr(result)));
3863 /* TODO: "Attributes" ? */
3865 result = winreg_printer_write_dword(tmp_ctx, winreg_handle,
3866 &key_hnd, "Version",
3868 if (!W_ERROR_IS_OK(result)) {
3872 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3875 if (!W_ERROR_IS_OK(result)) {
3879 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3880 &key_hnd, "Data File",
3882 if (!W_ERROR_IS_OK(result)) {
3886 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3887 &key_hnd, "Configuration File",
3889 if (!W_ERROR_IS_OK(result)) {
3893 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3894 &key_hnd, "Help File",
3896 if (!W_ERROR_IS_OK(result)) {
3900 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3901 &key_hnd, "Dependent Files",
3902 info8.dependent_files);
3903 if (!W_ERROR_IS_OK(result)) {
3907 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3908 &key_hnd, "Monitor",
3909 info8.monitor_name);
3910 if (!W_ERROR_IS_OK(result)) {
3914 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3915 &key_hnd, "Datatype",
3916 info8.default_datatype);
3917 if (!W_ERROR_IS_OK(result)) {
3921 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3922 &key_hnd, "Previous Names",
3923 info8.previous_names);
3924 if (!W_ERROR_IS_OK(result)) {
3928 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
3929 &key_hnd, "DriverDate",
3931 if (!W_ERROR_IS_OK(result)) {
3935 result = winreg_printer_write_ver(tmp_ctx, winreg_handle,
3936 &key_hnd, "DriverVersion",
3937 info8.driver_version);
3938 if (!W_ERROR_IS_OK(result)) {
3942 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3943 &key_hnd, "Manufacturer",
3944 info8.manufacturer_name);
3945 if (!W_ERROR_IS_OK(result)) {
3949 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3950 &key_hnd, "OEM URL",
3951 info8.manufacturer_url);
3952 if (!W_ERROR_IS_OK(result)) {
3956 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3957 &key_hnd, "HardwareID",
3959 if (!W_ERROR_IS_OK(result)) {
3963 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3964 &key_hnd, "Provider",
3966 if (!W_ERROR_IS_OK(result)) {
3970 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3971 &key_hnd, "Print Processor",
3972 info8.print_processor);
3973 if (!W_ERROR_IS_OK(result)) {
3977 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3978 &key_hnd, "VendorSetup",
3979 info8.vendor_setup);
3980 if (!W_ERROR_IS_OK(result)) {
3984 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
3985 &key_hnd, "Color Profiles",
3986 info8.color_profiles);
3987 if (!W_ERROR_IS_OK(result)) {
3991 result = winreg_printer_write_sz(tmp_ctx, winreg_handle,
3992 &key_hnd, "InfPath",
3994 if (!W_ERROR_IS_OK(result)) {
3998 result = winreg_printer_write_dword(tmp_ctx, winreg_handle, &key_hnd,
3999 "PrinterDriverAttributes",
4000 info8.printer_driver_attributes);
4001 if (!W_ERROR_IS_OK(result)) {
4005 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_handle,
4006 &key_hnd, "CoreDependencies",
4007 info8.core_driver_dependencies);
4008 if (!W_ERROR_IS_OK(result)) {
4012 result = winreg_printer_write_date(tmp_ctx, winreg_handle,
4013 &key_hnd, "MinInboxDriverVerDate",
4014 info8.min_inbox_driver_ver_date);
4015 if (!W_ERROR_IS_OK(result)) {
4019 result = winreg_printer_write_ver(tmp_ctx, winreg_handle, &key_hnd,
4020 "MinInboxDriverVerVersion",
4021 info8.min_inbox_driver_ver_version);
4022 if (!W_ERROR_IS_OK(result)) {
4026 *driver_name = info8.driver_name;
4027 *driver_version = info8.version;
4030 if (winreg_handle != NULL) {
4033 if (is_valid_policy_hnd(&key_hnd)) {
4034 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4036 if (is_valid_policy_hnd(&hive_hnd)) {
4037 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4041 TALLOC_FREE(tmp_ctx);
4045 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
4046 struct auth_serversupplied_info *server_info,
4047 struct messaging_context *msg_ctx,
4048 const char *architecture,
4049 const char *driver_name,
4050 uint32_t driver_version,
4051 struct spoolss_DriverInfo8 **_info8)
4053 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4054 struct dcerpc_binding_handle *winreg_handle = NULL;
4055 struct policy_handle hive_hnd, key_hnd;
4056 struct spoolss_DriverInfo8 i8, *info8;
4057 struct spoolss_PrinterEnumValues *enum_values = NULL;
4058 struct spoolss_PrinterEnumValues *v;
4059 uint32_t num_values = 0;
4060 TALLOC_CTX *tmp_ctx;
4064 ZERO_STRUCT(hive_hnd);
4065 ZERO_STRUCT(key_hnd);
4068 tmp_ctx = talloc_stackframe();
4069 if (tmp_ctx == NULL) {
4073 if (driver_version == DRIVER_ANY_VERSION) {
4074 /* look for Win2k first and then for NT4 */
4075 result = winreg_printer_opendriver(tmp_ctx,
4085 if (!W_ERROR_IS_OK(result)) {
4086 result = winreg_printer_opendriver(tmp_ctx,
4098 /* ok normal case */
4099 result = winreg_printer_opendriver(tmp_ctx,
4110 if (!W_ERROR_IS_OK(result)) {
4111 DEBUG(5, ("winreg_get_driver: "
4112 "Could not open driver key (%s,%s,%d): %s\n",
4113 driver_name, architecture,
4114 driver_version, win_errstr(result)));
4118 result = winreg_printer_enumvalues(tmp_ctx,
4123 if (!W_ERROR_IS_OK(result)) {
4124 DEBUG(0, ("winreg_get_driver: "
4125 "Could not enumerate values for (%s,%s,%d): %s\n",
4126 driver_name, architecture,
4127 driver_version, win_errstr(result)));
4131 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
4132 if (info8 == NULL) {
4133 result = WERR_NOMEM;
4137 info8->driver_name = talloc_strdup(info8, driver_name);
4138 if (info8->driver_name == NULL) {
4139 result = WERR_NOMEM;
4143 info8->architecture = talloc_strdup(info8, architecture);
4144 if (info8->architecture == NULL) {
4145 result = WERR_NOMEM;
4151 for (i = 0; i < num_values; i++) {
4152 const char *tmp_str;
4155 v = &enum_values[i];
4157 result = winreg_enumval_to_dword(info8, v,
4160 if (NT_STATUS_IS_OK(result)) {
4161 info8->version = (enum spoolss_DriverOSVersion) tmp;
4163 CHECK_ERROR(result);
4165 result = winreg_enumval_to_sz(info8, v,
4167 &info8->driver_path);
4168 CHECK_ERROR(result);
4170 result = winreg_enumval_to_sz(info8, v,
4173 CHECK_ERROR(result);
4175 result = winreg_enumval_to_sz(info8, v,
4176 "Configuration File",
4177 &info8->config_file);
4178 CHECK_ERROR(result);
4180 result = winreg_enumval_to_sz(info8, v,
4183 CHECK_ERROR(result);
4185 result = winreg_enumval_to_multi_sz(info8, v,
4187 &info8->dependent_files);
4188 CHECK_ERROR(result);
4190 result = winreg_enumval_to_sz(info8, v,
4192 &info8->monitor_name);
4193 CHECK_ERROR(result);
4195 result = winreg_enumval_to_sz(info8, v,
4197 &info8->default_datatype);
4198 CHECK_ERROR(result);
4200 result = winreg_enumval_to_multi_sz(info8, v,
4202 &info8->previous_names);
4203 CHECK_ERROR(result);
4205 result = winreg_enumval_to_sz(info8, v,
4208 if (W_ERROR_IS_OK(result)) {
4209 result = winreg_printer_date_to_NTTIME(tmp_str,
4210 &info8->driver_date);
4212 CHECK_ERROR(result);
4214 result = winreg_enumval_to_sz(info8, v,
4217 if (W_ERROR_IS_OK(result)) {
4218 result = winreg_printer_ver_to_dword(tmp_str,
4219 &info8->driver_version);
4221 CHECK_ERROR(result);
4223 result = winreg_enumval_to_sz(info8, v,
4225 &info8->manufacturer_name);
4226 CHECK_ERROR(result);
4228 result = winreg_enumval_to_sz(info8, v,
4230 &info8->manufacturer_url);
4231 CHECK_ERROR(result);
4233 result = winreg_enumval_to_sz(info8, v,
4235 &info8->hardware_id);
4236 CHECK_ERROR(result);
4238 result = winreg_enumval_to_sz(info8, v,
4241 CHECK_ERROR(result);
4243 result = winreg_enumval_to_sz(info8, v,
4245 &info8->print_processor);
4246 CHECK_ERROR(result);
4248 result = winreg_enumval_to_sz(info8, v,
4250 &info8->vendor_setup);
4251 CHECK_ERROR(result);
4253 result = winreg_enumval_to_multi_sz(info8, v,
4255 &info8->color_profiles);
4256 CHECK_ERROR(result);
4258 result = winreg_enumval_to_sz(info8, v,
4261 CHECK_ERROR(result);
4263 result = winreg_enumval_to_dword(info8, v,
4264 "PrinterDriverAttributes",
4265 &info8->printer_driver_attributes);
4266 CHECK_ERROR(result);
4268 result = winreg_enumval_to_multi_sz(info8, v,
4270 &info8->core_driver_dependencies);
4271 CHECK_ERROR(result);
4273 result = winreg_enumval_to_sz(info8, v,
4274 "MinInboxDriverVerDate",
4276 if (W_ERROR_IS_OK(result)) {
4277 result = winreg_printer_date_to_NTTIME(tmp_str,
4278 &info8->min_inbox_driver_ver_date);
4280 CHECK_ERROR(result);
4282 result = winreg_enumval_to_sz(info8, v,
4283 "MinInboxDriverVerVersion",
4285 if (W_ERROR_IS_OK(result)) {
4286 result = winreg_printer_ver_to_dword(tmp_str,
4287 &info8->min_inbox_driver_ver_version);
4289 CHECK_ERROR(result);
4292 if (!W_ERROR_IS_OK(result)) {
4293 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4294 "for %s: %s\n", v->value_name,
4295 win_errstr(result)));
4299 *_info8 = talloc_steal(mem_ctx, info8);
4302 if (winreg_handle != NULL) {
4305 if (is_valid_policy_hnd(&key_hnd)) {
4306 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4308 if (is_valid_policy_hnd(&hive_hnd)) {
4309 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4313 TALLOC_FREE(tmp_ctx);
4317 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
4318 struct auth_serversupplied_info *server_info,
4319 struct messaging_context *msg_ctx,
4320 struct spoolss_DriverInfo8 *info8,
4323 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4324 struct dcerpc_binding_handle *winreg_handle = NULL;
4325 struct policy_handle hive_hnd, key_hnd;
4326 TALLOC_CTX *tmp_ctx;
4330 ZERO_STRUCT(hive_hnd);
4331 ZERO_STRUCT(key_hnd);
4333 tmp_ctx = talloc_stackframe();
4334 if (tmp_ctx == NULL) {
4338 /* test that the key exists */
4339 result = winreg_printer_opendriver(tmp_ctx,
4343 info8->architecture,
4349 if (!W_ERROR_IS_OK(result)) {
4350 /* key doesn't exist */
4351 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
4356 DEBUG(5, ("winreg_del_driver: "
4357 "Could not open driver (%s,%s,%u): %s\n",
4358 info8->driver_name, info8->architecture,
4359 version, win_errstr(result)));
4364 if (is_valid_policy_hnd(&key_hnd)) {
4365 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
4368 key_name = talloc_asprintf(tmp_ctx,
4369 "%s\\Environments\\%s\\Drivers\\Version-%u",
4370 TOP_LEVEL_CONTROL_KEY,
4371 info8->architecture, version);
4372 if (key_name == NULL) {
4373 result = WERR_NOMEM;
4377 result = winreg_printer_delete_subkeys(tmp_ctx,
4382 if (!W_ERROR_IS_OK(result)) {
4383 DEBUG(0, ("winreg_del_driver: "
4384 "Could not open driver (%s,%s,%u): %s\n",
4385 info8->driver_name, info8->architecture,
4386 version, win_errstr(result)));
4392 if (winreg_handle != NULL) {
4395 if (is_valid_policy_hnd(&key_hnd)) {
4396 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4398 if (is_valid_policy_hnd(&hive_hnd)) {
4399 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4403 TALLOC_FREE(tmp_ctx);
4407 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
4408 struct auth_serversupplied_info *server_info,
4409 struct messaging_context *msg_ctx,
4410 const char *architecture,
4412 uint32_t *num_drivers,
4413 const char ***drivers_p)
4415 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4416 struct dcerpc_binding_handle *winreg_handle = NULL;
4417 struct policy_handle hive_hnd, key_hnd;
4418 const char **drivers;
4419 TALLOC_CTX *tmp_ctx;
4425 ZERO_STRUCT(hive_hnd);
4426 ZERO_STRUCT(key_hnd);
4428 tmp_ctx = talloc_stackframe();
4429 if (tmp_ctx == NULL) {
4433 /* use NULL for the driver name so we open the key that is
4434 * parent of all drivers for this architecture and version */
4435 result = winreg_printer_opendriver(tmp_ctx,
4445 if (!W_ERROR_IS_OK(result)) {
4446 DEBUG(5, ("winreg_get_driver_list: "
4447 "Could not open key (%s,%u): %s\n",
4448 architecture, version, win_errstr(result)));
4453 result = winreg_printer_enumkeys(tmp_ctx,
4458 if (!W_ERROR_IS_OK(result)) {
4459 DEBUG(0, ("winreg_get_driver_list: "
4460 "Could not enumerate drivers for (%s,%u): %s\n",
4461 architecture, version, win_errstr(result)));
4465 *drivers_p = talloc_steal(mem_ctx, drivers);
4469 if (winreg_handle != NULL) {
4472 if (is_valid_policy_hnd(&key_hnd)) {
4473 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
4475 if (is_valid_policy_hnd(&hive_hnd)) {
4476 dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
4480 TALLOC_FREE(tmp_ctx);