2 * Unix SMB/CIFS implementation.
4 * SPOOLSS RPC Pipe server / winreg client routines
6 * Copyright (c) 2010 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "nt_printing.h"
24 #include "srv_spoolss_util.h"
25 #include "../librpc/gen_ndr/ndr_spoolss.h"
26 #include "../librpc/gen_ndr/srv_winreg.h"
27 #include "../librpc/gen_ndr/cli_winreg.h"
28 #include "../librpc/gen_ndr/ndr_security.h"
30 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
31 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
32 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
33 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
35 #define EMPTY_STRING ""
37 #define FILL_STRING(mem_ctx, in, out) \
39 if (in && strlen(in)) { \
40 out = talloc_strdup(mem_ctx, in); \
42 out = talloc_strdup(mem_ctx, ""); \
44 W_ERROR_HAVE_NO_MEMORY(out); \
47 #define CHECK_ERROR(result) \
48 if (W_ERROR_IS_OK(result)) continue; \
49 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
50 if (!W_ERROR_IS_OK(result)) break
52 /* FLAGS, NAME, with, height, left, top, right, bottom */
53 static const struct spoolss_FormInfo1 builtin_forms1[] = {
54 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
55 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
56 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
57 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
58 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
59 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
60 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
61 { SPOOLSS_FORM_BUILTIN, "A0", {0xcd528,0x122488},{0x0,0x0,0xcd528,0x122488} },
62 { SPOOLSS_FORM_BUILTIN, "A1", {0x91050,0xcd528}, {0x0,0x0,0x91050,0xcd528} },
63 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
64 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
65 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
66 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
67 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
68 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
69 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
70 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
71 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
72 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
73 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
74 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
75 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
76 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
77 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
78 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
79 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
80 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
81 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
82 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
83 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
84 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
85 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
86 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
87 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
88 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
89 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
90 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
91 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
92 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
93 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
94 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
95 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
96 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
97 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
98 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
99 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
100 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
101 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
102 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
103 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
104 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
105 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
106 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
107 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
108 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
109 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
110 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
111 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
112 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
113 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
114 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
115 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
116 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
117 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
118 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
119 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
120 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
121 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
122 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
123 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
124 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
125 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
126 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
127 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
128 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
129 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
130 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
131 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
132 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
133 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
134 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
135 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
136 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
137 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
138 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
139 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
140 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
141 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
142 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
143 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
144 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
145 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
146 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
147 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} },
148 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
149 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
150 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
151 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
152 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
153 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
154 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
159 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
160 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
161 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
162 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
163 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
164 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
165 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
166 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
167 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
168 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
169 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
170 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
171 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
172 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
173 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} }
176 /********************************************************************
177 static helper functions
178 ********************************************************************/
180 /****************************************************************************
181 Update the changeid time.
182 ****************************************************************************/
186 * @brief Update the ChangeID time of a printer.
188 * This is SO NASTY as some drivers need this to change, others need it
189 * static. This value will change every second, and I must hope that this
190 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
193 * @return The ChangeID.
195 static uint32_t winreg_printer_rev_changeid(void)
199 get_process_uptime(&tv);
202 /* Return changeid as msec since spooler restart */
203 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
206 * This setting seems to work well but is too untested
207 * to replace the above calculation. Left in for experiementation
208 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
210 return tv.tv_sec * 10 + tv.tv_usec / 100000;
217 * @brief Connect to the interal winreg server and open the given printer key.
219 * The function will create the needed subkeys if they don't exist.
221 * @param[in] mem_ctx The memory context to use.
223 * @param[in] server_info The supplied server info.
225 * @param[out] winreg_pipe A pointer for the winreg rpc client pipe.
227 * @param[in] path The path to the key to open.
229 * @param[in] key The key to open.
231 * @param[in] create_key Set to true if the key should be created if it
234 * @param[in] access_mask The access mask to open the key.
236 * @param[out] hive_handle A policy handle for the opened hive.
238 * @param[out] key_handle A policy handle for the opened key.
240 * @return WERR_OK on success, the corresponding DOS error
241 * code if something gone wrong.
243 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
244 struct auth_serversupplied_info *server_info,
245 struct rpc_pipe_client **winreg_pipe,
249 uint32_t access_mask,
250 struct policy_handle *hive_handle,
251 struct policy_handle *key_handle)
253 struct rpc_pipe_client *pipe_handle;
254 struct winreg_String wkey, wkeyclass;
257 WERROR result = WERR_OK;
259 /* create winreg connection */
260 status = rpc_pipe_open_internal(mem_ctx,
261 &ndr_table_winreg.syntax_id,
264 if (!NT_STATUS_IS_OK(status)) {
265 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg_pipe: %s\n",
267 return ntstatus_to_werror(status);
270 status = rpccli_winreg_OpenHKLM(pipe_handle,
276 if (!NT_STATUS_IS_OK(status)) {
277 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
279 talloc_free(pipe_handle);
280 if (!W_ERROR_IS_OK(result)) {
283 return ntstatus_to_werror(status);
287 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
289 keyname = talloc_strdup(mem_ctx, path);
291 if (keyname == NULL) {
292 talloc_free(pipe_handle);
300 enum winreg_CreateAction action = REG_ACTION_NONE;
302 ZERO_STRUCT(wkeyclass);
305 status = rpccli_winreg_CreateKey(pipe_handle,
317 case REG_ACTION_NONE:
318 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
320 case REG_CREATED_NEW_KEY:
321 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
323 case REG_OPENED_EXISTING_KEY:
324 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
328 status = rpccli_winreg_OpenKey(pipe_handle,
337 if (!NT_STATUS_IS_OK(status)) {
338 talloc_free(pipe_handle);
339 if (!W_ERROR_IS_OK(result)) {
342 return ntstatus_to_werror(status);
345 *winreg_pipe = pipe_handle;
351 * @brief Create the registry keyname for the given printer.
353 * @param[in] mem_ctx The memory context to use.
355 * @param[in] printer The name of the printer to get the registry key.
357 * @return The registry key or NULL on error.
359 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
360 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
366 * @brief Enumerate values of an opened key handle and retrieve the data.
368 * @param[in] mem_ctx The memory context to use.
370 * @param[in] pipe_handle The pipe handle for the rpc connection.
372 * @param[in] key_hnd The opened key handle.
374 * @param[out] pnum_values A pointer to store he number of values found.
376 * @param[out] pnum_values A pointer to store the number of values we found.
378 * @return WERR_OK on success, the corresponding DOS error
379 * code if something gone wrong.
381 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
382 struct rpc_pipe_client *pipe_handle,
383 struct policy_handle *key_hnd,
384 uint32_t *pnum_values,
385 struct spoolss_PrinterEnumValues **penum_values)
388 uint32_t num_subkeys, max_subkeylen, max_classlen;
389 uint32_t num_values, max_valnamelen, max_valbufsize;
390 uint32_t secdescsize;
392 NTTIME last_changed_time;
393 struct winreg_String classname;
395 struct spoolss_PrinterEnumValues *enum_values;
397 WERROR result = WERR_OK;
400 tmp_ctx = talloc_stackframe();
401 if (tmp_ctx == NULL) {
405 ZERO_STRUCT(classname);
407 status = rpccli_winreg_QueryInfoKey(pipe_handle,
420 if (!NT_STATUS_IS_OK(status)) {
421 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
423 if (!W_ERROR_IS_OK(result)) {
426 result = ntstatus_to_werror(status);
430 if (num_values == 0) {
432 TALLOC_FREE(tmp_ctx);
436 enum_values = TALLOC_ARRAY(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
437 if (enum_values == NULL) {
442 for (i = 0; i < num_values; i++) {
443 struct spoolss_PrinterEnumValues val;
444 struct winreg_ValNameBuf name_buf;
445 enum winreg_Type type = REG_NONE;
446 uint8_t *data = NULL;
452 name_buf.size = max_valnamelen + 2;
455 data_size = max_valbufsize;
456 data = (uint8_t *) TALLOC(tmp_ctx, data_size);
459 status = rpccli_winreg_EnumValue(pipe_handle,
469 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
471 status = NT_STATUS_OK;
475 if (!NT_STATUS_IS_OK(status)) {
476 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
478 if (!W_ERROR_IS_OK(result)) {
481 result = ntstatus_to_werror(status);
485 if (name_buf.name == NULL) {
486 result = WERR_INVALID_PARAMETER;
490 val.value_name = talloc_strdup(enum_values, name_buf.name);
491 if (val.value_name == NULL) {
495 val.value_name_len = strlen_m_term(val.value_name) * 2;
498 val.data_length = data_size;
500 if (val.data_length) {
501 val.data = talloc(enum_values, DATA_BLOB);
502 if (val.data == NULL) {
506 *val.data = data_blob_talloc(enum_values, data, data_size);
509 enum_values[i] = val;
512 *pnum_values = num_values;
514 *penum_values = talloc_move(mem_ctx, &enum_values);
520 TALLOC_FREE(tmp_ctx);
527 * @brief Enumerate subkeys of an opened key handle and get the names.
529 * @param[in] mem_ctx The memory context to use.
531 * @param[in] pipe_handle The pipe handle for the rpc connection.
533 * @param[in] key_hnd The opened key handle.
535 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
537 * @param[in] psubkeys A pointer to an array to store the found names of
540 * @return WERR_OK on success, the corresponding DOS error
541 * code if something gone wrong.
543 static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
544 struct rpc_pipe_client *pipe_handle,
545 struct policy_handle *key_hnd,
546 uint32_t *pnum_subkeys,
547 const char ***psubkeys)
550 const char **subkeys;
551 uint32_t num_subkeys, max_subkeylen, max_classlen;
552 uint32_t num_values, max_valnamelen, max_valbufsize;
554 NTTIME last_changed_time;
555 uint32_t secdescsize;
556 struct winreg_String classname;
557 WERROR result = WERR_OK;
560 tmp_ctx = talloc_stackframe();
561 if (tmp_ctx == NULL) {
565 ZERO_STRUCT(classname);
567 status = rpccli_winreg_QueryInfoKey(pipe_handle,
580 if (!NT_STATUS_IS_OK(status)) {
581 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
583 if (!W_ERROR_IS_OK(result)) {
586 result = ntstatus_to_werror(status);
590 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
591 if (subkeys == NULL) {
596 if (num_subkeys == 0) {
597 subkeys[0] = talloc_strdup(subkeys, "");
598 if (subkeys[0] == NULL) {
604 *psubkeys = talloc_move(mem_ctx, &subkeys);
607 TALLOC_FREE(tmp_ctx);
611 for (i = 0; i < num_subkeys; i++) {
615 struct winreg_StringBuf class_buf;
616 struct winreg_StringBuf name_buf;
620 class_buf.size = max_classlen + 2;
621 class_buf.length = 0;
624 name_buf.size = max_subkeylen + 2;
627 ZERO_STRUCT(modtime);
629 status = rpccli_winreg_EnumKey(pipe_handle,
637 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
639 status = NT_STATUS_OK;
643 if (!NT_STATUS_IS_OK(status)) {
644 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
646 if (!W_ERROR_IS_OK(result)) {
649 result = ntstatus_to_werror(status);
653 if (name_buf.name == NULL) {
654 result = WERR_INVALID_PARAMETER;
658 name = talloc_strdup(subkeys, name_buf.name);
667 *pnum_subkeys = num_subkeys;
669 *psubkeys = talloc_move(mem_ctx, &subkeys);
673 TALLOC_FREE(tmp_ctx);
680 * @brief A function to delete a key and its subkeys recurively.
682 * @param[in] mem_ctx The memory context to use.
684 * @param[in] pipe_handle The pipe handle for the rpc connection.
686 * @param[in] hive_handle A opened hive handle to the key.
688 * @param[in] access_mask The access mask to access the key.
690 * @param[in] key The key to delete
692 * @return WERR_OK on success, the corresponding DOS error
693 * code if something gone wrong.
695 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
696 struct rpc_pipe_client *pipe_handle,
697 struct policy_handle *hive_handle,
698 uint32_t access_mask,
701 const char **subkeys = NULL;
702 uint32_t num_subkeys = 0;
703 struct policy_handle key_hnd;
704 struct winreg_String wkey;
705 WERROR result = WERR_OK;
709 ZERO_STRUCT(key_hnd);
712 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
714 status = rpccli_winreg_OpenKey(pipe_handle,
722 if (!NT_STATUS_IS_OK(status)) {
723 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
724 wkey.name, nt_errstr(status)));
725 if (!W_ERROR_IS_OK(result)) {
728 return ntstatus_to_werror(status);
731 result = winreg_printer_enumkeys(mem_ctx,
736 if (!W_ERROR_IS_OK(result)) {
740 for (i = 0; i < num_subkeys; i++) {
741 /* create key + subkey */
742 char *subkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkeys[i]);
743 if (subkey == NULL) {
747 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey));
748 result = winreg_printer_delete_subkeys(mem_ctx,
753 if (!W_ERROR_IS_OK(result)) {
758 if (is_valid_policy_hnd(&key_hnd)) {
759 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
764 status = rpccli_winreg_DeleteKey(pipe_handle,
771 if (is_valid_policy_hnd(&key_hnd)) {
772 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
778 static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
779 struct rpc_pipe_client *pipe_handle,
780 struct policy_handle *key_handle,
784 struct winreg_String wvalue;
786 WERROR result = WERR_OK;
791 blob = data_blob_string_const("");
793 if (!push_reg_sz(mem_ctx, &blob, data)) {
794 DEBUG(0, ("winreg_printer_write_sz: Could not marshall string %s for %s\n",
799 status = rpccli_winreg_SetValue(pipe_handle,
807 if (!NT_STATUS_IS_OK(status)) {
808 DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: %s\n",
809 wvalue.name, win_errstr(result)));
810 if (!W_ERROR_IS_OK(result)) {
811 result = ntstatus_to_werror(status);
818 static WERROR winreg_printer_write_dword(TALLOC_CTX *mem_ctx,
819 struct rpc_pipe_client *pipe_handle,
820 struct policy_handle *key_handle,
824 struct winreg_String wvalue;
826 WERROR result = WERR_OK;
830 blob = data_blob_talloc(mem_ctx, NULL, 4);
831 SIVAL(blob.data, 0, data);
833 status = rpccli_winreg_SetValue(pipe_handle,
841 if (!NT_STATUS_IS_OK(status)) {
842 DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: %s\n",
843 wvalue.name, win_errstr(result)));
844 if (!W_ERROR_IS_OK(result)) {
845 result = ntstatus_to_werror(status);
852 static WERROR winreg_printer_write_binary(TALLOC_CTX *mem_ctx,
853 struct rpc_pipe_client *pipe_handle,
854 struct policy_handle *key_handle,
858 struct winreg_String wvalue;
859 WERROR result = WERR_OK;
863 status = rpccli_winreg_SetValue(pipe_handle,
871 if (!NT_STATUS_IS_OK(status)) {
872 DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: %s\n",
873 wvalue.name, win_errstr(result)));
874 if (!W_ERROR_IS_OK(result)) {
875 result = ntstatus_to_werror(status);
882 static WERROR winreg_printer_query_binary(TALLOC_CTX *mem_ctx,
883 struct rpc_pipe_client *pipe_handle,
884 struct policy_handle *key_handle,
888 struct winreg_String wvalue;
889 enum winreg_Type type;
890 WERROR result = WERR_OK;
891 uint32_t value_len = 0;
892 uint32_t data_size = 0;
897 status = rpccli_winreg_QueryValue(pipe_handle,
906 if (!NT_STATUS_IS_OK(status)) {
907 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
908 wvalue.name, nt_errstr(status)));
909 if (!W_ERROR_IS_OK(result)) {
912 result = ntstatus_to_werror(status);
916 if (type != REG_BINARY) {
917 result = WERR_INVALID_DATATYPE;
920 blob = data_blob_talloc(mem_ctx, NULL, data_size);
921 if (blob.data == NULL) {
927 status = rpccli_winreg_QueryValue(pipe_handle,
936 if (!NT_STATUS_IS_OK(status)) {
937 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
938 wvalue.name, nt_errstr(status)));
939 if (!W_ERROR_IS_OK(result)) {
940 result = ntstatus_to_werror(status);
946 data->data = blob.data;
947 data->length = blob.length;
953 static WERROR winreg_printer_query_dword(TALLOC_CTX *mem_ctx,
954 struct rpc_pipe_client *pipe_handle,
955 struct policy_handle *key_handle,
959 struct winreg_String wvalue;
960 enum winreg_Type type;
961 WERROR result = WERR_OK;
962 uint32_t value_len = 0;
963 uint32_t data_size = 0;
968 status = rpccli_winreg_QueryValue(pipe_handle,
977 if (!NT_STATUS_IS_OK(status)) {
978 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
979 wvalue.name, nt_errstr(status)));
980 if (!W_ERROR_IS_OK(result)) {
983 result = ntstatus_to_werror(status);
987 if (type != REG_DWORD) {
988 result = WERR_INVALID_DATATYPE;
992 if (data_size != 4) {
993 result = WERR_INVALID_DATA;
997 blob = data_blob_talloc(mem_ctx, NULL, data_size);
998 if (blob.data == NULL) {
1004 status = rpccli_winreg_QueryValue(pipe_handle,
1013 if (!NT_STATUS_IS_OK(status)) {
1014 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1015 wvalue.name, nt_errstr(status)));
1016 if (!W_ERROR_IS_OK(result)) {
1017 result = ntstatus_to_werror(status);
1023 *data = IVAL(blob.data, 0);
1029 static WERROR winreg_printer_write_multi_sz(TALLOC_CTX *mem_ctx,
1030 struct rpc_pipe_client *pipe_handle,
1031 struct policy_handle *key_handle,
1035 struct winreg_String wvalue;
1037 WERROR result = WERR_OK;
1040 wvalue.name = value;
1041 if (!push_reg_multi_sz(mem_ctx, &blob, data)) {
1044 status = rpccli_winreg_SetValue(pipe_handle,
1052 if (!NT_STATUS_IS_OK(status)) {
1053 DEBUG(0, ("winreg_printer_write_multi_sz: Could not set value %s: %s\n",
1054 wvalue.name, win_errstr(result)));
1055 if (!W_ERROR_IS_OK(result)) {
1056 result = ntstatus_to_werror(status);
1063 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
1064 struct auth_serversupplied_info *server_info,
1065 const char *drivername,
1066 const char *architecture,
1068 uint32_t access_mask,
1070 struct rpc_pipe_client **winreg_pipe,
1071 struct policy_handle *hive_hnd,
1072 struct policy_handle *key_hnd)
1077 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
1078 TOP_LEVEL_CONTROL_KEY,
1079 architecture, version);
1084 result = winreg_printer_openkey(mem_ctx,
1096 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
1097 struct spoolss_PrinterEnumValues *v,
1098 const char *valuename, uint32_t *dw)
1100 /* just return if it is not the one we are looking for */
1101 if (strcmp(valuename, v->value_name) != 0) {
1102 return WERR_NOT_FOUND;
1105 if (v->type != REG_DWORD) {
1106 return WERR_INVALID_DATATYPE;
1109 if (v->data_length == 0) {
1114 *dw = IVAL(v->data->data, 0);
1118 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
1119 struct spoolss_PrinterEnumValues *v,
1120 const char *valuename, const char **_str)
1122 /* just return if it is not the one we are looking for */
1123 if (strcmp(valuename, v->value_name) != 0) {
1124 return WERR_NOT_FOUND;
1127 if (v->type != REG_SZ) {
1128 return WERR_INVALID_DATATYPE;
1131 if (v->data_length == 0) {
1132 *_str = talloc_strdup(mem_ctx, EMPTY_STRING);
1133 if (*_str == NULL) {
1139 if (!pull_reg_sz(mem_ctx, v->data, _str)) {
1146 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
1147 struct spoolss_PrinterEnumValues *v,
1148 const char *valuename,
1149 const char ***array)
1151 /* just return if it is not the one we are looking for */
1152 if (strcmp(valuename, v->value_name) != 0) {
1153 return WERR_NOT_FOUND;
1156 if (v->type != REG_MULTI_SZ) {
1157 return WERR_INVALID_DATATYPE;
1160 if (v->data_length == 0) {
1161 *array = talloc_array(mem_ctx, const char *, 1);
1162 if (*array == NULL) {
1169 if (!pull_reg_multi_sz(mem_ctx, v->data, array)) {
1176 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
1177 struct rpc_pipe_client *pipe_handle,
1178 struct policy_handle *key_handle,
1182 struct winreg_String wvalue;
1184 WERROR result = WERR_OK;
1190 t = nt_time_to_unix(data);
1192 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
1193 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
1198 wvalue.name = value;
1199 if (!push_reg_sz(mem_ctx, &blob, str)) {
1202 status = rpccli_winreg_SetValue(pipe_handle,
1210 if (!NT_STATUS_IS_OK(status)) {
1211 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1212 wvalue.name, win_errstr(result)));
1213 if (!W_ERROR_IS_OK(result)) {
1214 result = ntstatus_to_werror(status);
1221 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
1228 if (sscanf(str, "%d/%d/%d",
1229 &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3) {
1230 return WERR_INVALID_PARAMETER;
1237 unix_to_nt_time(data, t);
1242 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
1243 struct rpc_pipe_client *pipe_handle,
1244 struct policy_handle *key_handle,
1248 struct winreg_String wvalue;
1250 WERROR result = WERR_OK;
1254 /* FIXME: check format is right,
1255 * this needs to be something like: 6.1.7600.16385 */
1256 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
1257 (unsigned)((data >> 48) & 0xFFFF),
1258 (unsigned)((data >> 32) & 0xFFFF),
1259 (unsigned)((data >> 16) & 0xFFFF),
1260 (unsigned)(data & 0xFFFF));
1265 wvalue.name = value;
1266 if (!push_reg_sz(mem_ctx, &blob, str)) {
1269 status = rpccli_winreg_SetValue(pipe_handle,
1277 if (!NT_STATUS_IS_OK(status)) {
1278 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1279 wvalue.name, win_errstr(result)));
1280 if (!W_ERROR_IS_OK(result)) {
1281 result = ntstatus_to_werror(status);
1288 static WERROR winreg_printer_ver_to_dword(const char *str, uint64_t *data)
1290 unsigned int v1, v2, v3, v4;
1292 if (sscanf(str, "%u.%u.%u.%u", &v1, &v2, &v3, &v4) != 4) {
1293 return WERR_INVALID_PARAMETER;
1296 *data = ((uint64_t)(v1 & 0xFFFF) << 48) +
1297 ((uint64_t)(v2 & 0xFFFF) << 32) +
1298 ((uint64_t)(v3 & 0xFFFF) << 16) +
1299 (uint64_t)(v2 & 0xFFFF);
1304 /********************************************************************
1305 Public winreg function for spoolss
1306 ********************************************************************/
1308 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
1309 struct auth_serversupplied_info *server_info,
1310 const char *servername,
1311 const char *sharename)
1313 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1314 struct rpc_pipe_client *winreg_pipe = NULL;
1315 struct policy_handle hive_hnd, key_hnd;
1316 struct spoolss_SetPrinterInfo2 *info2;
1317 struct security_descriptor *secdesc;
1318 struct winreg_String wkey, wkeyclass;
1320 const char *subkeys[] = { SPOOL_DSDRIVER_KEY, SPOOL_DSSPOOLER_KEY, SPOOL_PRINTERDATA_KEY };
1321 uint32_t i, count = ARRAY_SIZE(subkeys);
1322 uint32_t info2_mask = 0;
1323 WERROR result = WERR_OK;
1324 TALLOC_CTX *tmp_ctx;
1326 tmp_ctx = talloc_stackframe();
1327 if (tmp_ctx == NULL) {
1331 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1333 TALLOC_FREE(tmp_ctx);
1337 ZERO_STRUCT(hive_hnd);
1338 ZERO_STRUCT(key_hnd);
1340 result = winreg_printer_openkey(tmp_ctx,
1349 if (W_ERROR_IS_OK(result)) {
1350 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
1352 } else if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1353 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
1354 } else if (!W_ERROR_IS_OK(result)) {
1355 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
1356 path, win_errstr(result)));
1360 /* Create the main key */
1361 result = winreg_printer_openkey(tmp_ctx,
1370 if (!W_ERROR_IS_OK(result)) {
1371 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1372 path, win_errstr(result)));
1376 if (is_valid_policy_hnd(&key_hnd)) {
1377 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1380 /* Create subkeys */
1381 for (i = 0; i < count; i++) {
1383 enum winreg_CreateAction action = REG_ACTION_NONE;
1385 ZERO_STRUCT(key_hnd);
1388 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
1389 if (wkey.name == NULL) {
1390 result = WERR_NOMEM;
1394 ZERO_STRUCT(wkeyclass);
1395 wkeyclass.name = "";
1397 status = rpccli_winreg_CreateKey(winreg_pipe,
1408 if (!NT_STATUS_IS_OK(status)) {
1409 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1410 wkey.name, win_errstr(result)));
1411 if (!W_ERROR_IS_OK(result)) {
1412 result = ntstatus_to_werror(status);
1419 const char *dnssuffix;
1420 const char *longname;
1421 const char *uncname;
1423 result = winreg_printer_write_sz(tmp_ctx,
1426 SPOOL_REG_PRINTERNAME,
1428 if (!W_ERROR_IS_OK(result)) {
1432 result = winreg_printer_write_sz(tmp_ctx,
1435 SPOOL_REG_SHORTSERVERNAME,
1437 if (!W_ERROR_IS_OK(result)) {
1441 /* We make the assumption that the netbios name
1442 * is the same as the DNS name since the former
1443 * will be what we used to join the domain
1445 dnssuffix = get_mydnsdomname(tmp_ctx);
1446 if (dnssuffix != NULL && dnssuffix[0] != '\0') {
1447 longname = talloc_asprintf(tmp_ctx, "%s.%s", global_myname(), dnssuffix);
1449 longname = talloc_strdup(tmp_ctx, global_myname());
1451 if (longname == NULL) {
1452 result = WERR_NOMEM;
1456 result = winreg_printer_write_sz(tmp_ctx,
1459 SPOOL_REG_SERVERNAME,
1461 if (!W_ERROR_IS_OK(result)) {
1465 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
1466 longname, sharename);
1467 if (uncname == NULL) {
1468 result = WERR_NOMEM;
1472 result = winreg_printer_write_sz(tmp_ctx,
1477 if (!W_ERROR_IS_OK(result)) {
1481 result = winreg_printer_write_dword(tmp_ctx,
1484 SPOOL_REG_VERSIONNUMBER,
1486 if (!W_ERROR_IS_OK(result)) {
1490 result = winreg_printer_write_dword(tmp_ctx,
1493 SPOOL_REG_PRINTSTARTTIME,
1495 if (!W_ERROR_IS_OK(result)) {
1499 result = winreg_printer_write_dword(tmp_ctx,
1502 SPOOL_REG_PRINTENDTIME,
1504 if (!W_ERROR_IS_OK(result)) {
1508 result = winreg_printer_write_dword(tmp_ctx,
1513 if (!W_ERROR_IS_OK(result)) {
1517 result = winreg_printer_write_dword(tmp_ctx,
1520 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
1522 if (!W_ERROR_IS_OK(result)) {
1530 if (is_valid_policy_hnd(&key_hnd)) {
1531 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1534 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
1535 if (info2 == NULL) {
1536 result = WERR_NOMEM;
1540 if (servername != NULL) {
1541 info2->printername = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
1542 servername, sharename);
1544 info2->printername = sharename;
1546 if (info2->printername == NULL) {
1547 result = WERR_NOMEM;
1550 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1552 info2->sharename = sharename;
1553 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1555 info2->portname = SAMBA_PRINTER_PORT_NAME;
1556 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1558 info2->printprocessor = "winprint";
1559 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1561 info2->datatype = "RAW";
1562 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1564 info2->comment = "";
1565 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1567 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1568 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1570 info2->starttime = 0; /* Minutes since 12:00am GMT */
1571 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1573 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1574 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1576 info2->priority = 1;
1577 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1579 info2->defaultpriority = 1;
1580 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1582 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1583 if (!W_ERROR_IS_OK(result)) {
1586 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1589 * Don't write a default Device Mode to the registry! The Device Mode is
1590 * only written to disk with a SetPrinter level 2 or 8.
1593 result = winreg_update_printer(tmp_ctx,
1602 if (winreg_pipe != NULL) {
1603 if (is_valid_policy_hnd(&key_hnd)) {
1604 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1606 if (is_valid_policy_hnd(&hive_hnd)) {
1607 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1611 talloc_free(tmp_ctx);
1615 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1616 struct auth_serversupplied_info *server_info,
1617 const char *sharename,
1618 uint32_t info2_mask,
1619 struct spoolss_SetPrinterInfo2 *info2,
1620 struct spoolss_DeviceMode *devmode,
1621 struct security_descriptor *secdesc)
1623 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1624 struct rpc_pipe_client *winreg_pipe = NULL;
1625 struct policy_handle hive_hnd, key_hnd;
1626 int snum = lp_servicenumber(sharename);
1627 enum ndr_err_code ndr_err;
1630 WERROR result = WERR_OK;
1631 TALLOC_CTX *tmp_ctx;
1633 tmp_ctx = talloc_stackframe();
1634 if (tmp_ctx == NULL) {
1638 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1640 TALLOC_FREE(tmp_ctx);
1644 ZERO_STRUCT(hive_hnd);
1645 ZERO_STRUCT(key_hnd);
1647 result = winreg_printer_openkey(tmp_ctx,
1656 if (!W_ERROR_IS_OK(result)) {
1657 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1658 path, win_errstr(result)));
1662 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1663 result = winreg_printer_write_dword(tmp_ctx,
1668 if (!W_ERROR_IS_OK(result)) {
1674 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1675 result = winreg_printer_write_dword(tmp_ctx,
1680 if (!W_ERROR_IS_OK(result)) {
1686 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1687 result = winreg_printer_write_sz(tmp_ctx,
1692 if (!W_ERROR_IS_OK(result)) {
1697 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1698 result = winreg_printer_write_sz(tmp_ctx,
1703 if (!W_ERROR_IS_OK(result)) {
1708 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1709 result = winreg_printer_write_dword(tmp_ctx,
1713 info2->defaultpriority);
1714 if (!W_ERROR_IS_OK(result)) {
1719 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1721 * Some client drivers freak out if there is a NULL devmode
1722 * (probably the driver is not checking before accessing
1723 * the devmode pointer) --jerry
1725 if (devmode == NULL && lp_default_devmode(snum) && info2 != NULL) {
1726 result = spoolss_create_default_devmode(tmp_ctx,
1729 if (!W_ERROR_IS_OK(result)) {
1733 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, devmode,
1734 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1735 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1736 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1737 result = WERR_NOMEM;
1741 result = winreg_printer_write_binary(tmp_ctx,
1746 if (!W_ERROR_IS_OK(result)) {
1751 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1752 result = winreg_printer_write_sz(tmp_ctx,
1757 if (!W_ERROR_IS_OK(result)) {
1762 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1763 result = winreg_printer_write_sz(tmp_ctx,
1768 if (!W_ERROR_IS_OK(result)) {
1773 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1774 result = winreg_printer_write_sz(tmp_ctx,
1779 if (!W_ERROR_IS_OK(result)) {
1784 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1785 result = winreg_printer_write_sz(tmp_ctx,
1790 if (!W_ERROR_IS_OK(result)) {
1795 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1797 * in addprinter: no servername and the printer is the name
1798 * in setprinter: servername is \\server
1799 * and printer is \\server\\printer
1801 * Samba manages only local printers.
1802 * we currently don't support things like i
1803 * path=\\other_server\printer
1805 * We only store the printername, not \\server\printername
1807 const char *p = strrchr(info2->printername, '\\');
1809 p = info2->printername;
1813 result = winreg_printer_write_sz(tmp_ctx,
1818 if (!W_ERROR_IS_OK(result)) {
1823 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1824 result = winreg_printer_write_sz(tmp_ctx,
1828 info2->printprocessor);
1829 if (!W_ERROR_IS_OK(result)) {
1834 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1835 result = winreg_printer_write_dword(tmp_ctx,
1840 if (!W_ERROR_IS_OK(result)) {
1845 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1847 * We need a security descriptor, if it isn't specified by
1848 * AddPrinter{Ex} then create a default descriptor.
1850 if (secdesc == NULL) {
1851 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1852 if (!W_ERROR_IS_OK(result)) {
1856 result = winreg_set_printer_secdesc(tmp_ctx,
1860 if (!W_ERROR_IS_OK(result)) {
1865 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1866 result = winreg_printer_write_sz(tmp_ctx,
1871 if (!W_ERROR_IS_OK(result)) {
1876 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1877 result = winreg_printer_write_sz(tmp_ctx,
1882 if (!W_ERROR_IS_OK(result)) {
1887 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1888 result = winreg_printer_write_dword(tmp_ctx,
1893 if (!W_ERROR_IS_OK(result)) {
1898 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1899 result = winreg_printer_write_dword(tmp_ctx,
1904 if (!W_ERROR_IS_OK(result)) {
1909 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1910 result = winreg_printer_write_dword(tmp_ctx,
1915 if (!W_ERROR_IS_OK(result)) {
1920 result = winreg_printer_write_dword(tmp_ctx,
1924 winreg_printer_rev_changeid());
1925 if (!W_ERROR_IS_OK(result)) {
1931 if (winreg_pipe != NULL) {
1932 if (is_valid_policy_hnd(&key_hnd)) {
1933 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1935 if (is_valid_policy_hnd(&hive_hnd)) {
1936 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1940 TALLOC_FREE(tmp_ctx);
1944 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1945 struct auth_serversupplied_info *server_info,
1946 const char *servername,
1947 const char *printer,
1948 struct spoolss_PrinterInfo2 **pinfo2)
1950 struct spoolss_PrinterInfo2 *info2;
1951 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1952 struct rpc_pipe_client *winreg_pipe = NULL;
1953 struct policy_handle hive_hnd, key_hnd;
1954 struct spoolss_PrinterEnumValues *enum_values = NULL;
1955 struct spoolss_PrinterEnumValues *v;
1956 enum ndr_err_code ndr_err;
1958 int snum = lp_servicenumber(printer);
1959 uint32_t num_values = 0;
1962 WERROR result = WERR_OK;
1963 TALLOC_CTX *tmp_ctx;
1965 tmp_ctx = talloc_stackframe();
1966 if (tmp_ctx == NULL) {
1970 path = winreg_printer_data_keyname(tmp_ctx, printer);
1972 TALLOC_FREE(tmp_ctx);
1976 result = winreg_printer_openkey(tmp_ctx,
1985 if (!W_ERROR_IS_OK(result)) {
1986 DEBUG(0, ("winreg_get_printer: Could not open key %s: %s\n",
1987 path, win_errstr(result)));
1991 result = winreg_printer_enumvalues(tmp_ctx,
1996 if (!W_ERROR_IS_OK(result)) {
1997 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1998 path, win_errstr(result)));
2002 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
2003 if (info2 == NULL) {
2004 result = WERR_NOMEM;
2008 FILL_STRING(info2, EMPTY_STRING, info2->servername);
2009 FILL_STRING(info2, EMPTY_STRING, info2->printername);
2010 FILL_STRING(info2, EMPTY_STRING, info2->sharename);
2011 FILL_STRING(info2, EMPTY_STRING, info2->portname);
2012 FILL_STRING(info2, EMPTY_STRING, info2->drivername);
2013 FILL_STRING(info2, EMPTY_STRING, info2->comment);
2014 FILL_STRING(info2, EMPTY_STRING, info2->location);
2015 FILL_STRING(info2, EMPTY_STRING, info2->sepfile);
2016 FILL_STRING(info2, EMPTY_STRING, info2->printprocessor);
2017 FILL_STRING(info2, EMPTY_STRING, info2->datatype);
2018 FILL_STRING(info2, EMPTY_STRING, info2->parameters);
2020 if (servername != NULL && servername[0] != '\0') {
2021 info2->servername = talloc_asprintf(info2, "\\\\%s", servername);
2022 if (info2->servername == NULL) {
2023 result = WERR_NOMEM;
2028 for (i = 0; i < num_values; i++) {
2029 v = &enum_values[i];
2031 result = winreg_enumval_to_sz(info2,
2034 &info2->printername);
2035 CHECK_ERROR(result);
2037 result = winreg_enumval_to_sz(info2,
2041 CHECK_ERROR(result);
2043 result = winreg_enumval_to_sz(info2,
2047 CHECK_ERROR(result);
2049 result = winreg_enumval_to_sz(info2,
2053 CHECK_ERROR(result);
2055 result = winreg_enumval_to_sz(info2,
2059 CHECK_ERROR(result);
2061 result = winreg_enumval_to_sz(info2,
2065 CHECK_ERROR(result);
2067 result = winreg_enumval_to_sz(info2,
2070 &info2->printprocessor);
2071 CHECK_ERROR(result);
2073 result = winreg_enumval_to_sz(info2,
2077 CHECK_ERROR(result);
2079 result = winreg_enumval_to_sz(info2,
2082 &info2->parameters);
2083 CHECK_ERROR(result);
2085 result = winreg_enumval_to_sz(info2,
2088 &info2->drivername);
2089 CHECK_ERROR(result);
2091 result = winreg_enumval_to_dword(info2,
2094 &info2->attributes);
2095 CHECK_ERROR(result);
2097 result = winreg_enumval_to_dword(info2,
2101 CHECK_ERROR(result);
2103 result = winreg_enumval_to_dword(info2,
2106 &info2->defaultpriority);
2107 CHECK_ERROR(result);
2109 result = winreg_enumval_to_dword(info2,
2113 CHECK_ERROR(result);
2115 result = winreg_enumval_to_dword(info2,
2119 CHECK_ERROR(result);
2121 result = winreg_enumval_to_dword(info2,
2125 CHECK_ERROR(result);
2127 result = winreg_enumval_to_dword(info2,
2131 CHECK_ERROR(result);
2134 if (!W_ERROR_IS_OK(result)) {
2135 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2138 win_errstr(result)));
2142 /* Create the printername */
2143 if (info2->servername != NULL && info2->servername[0] != '\0') {
2144 if (lp_force_printername(snum)) {
2145 const char *p = talloc_asprintf(info2, "%s\\%s",
2149 result = WERR_NOMEM;
2152 info2->printername = p;
2154 char *p = talloc_asprintf(info2, "%s\\%s",
2156 info2->printername);
2158 result = WERR_NOMEM;
2161 info2->printername = p;
2165 /* Construct the Device Mode */
2166 result = winreg_printer_query_binary(tmp_ctx,
2171 if (W_ERROR_IS_OK(result)) {
2172 info2->devmode = talloc_zero(info2, struct spoolss_DeviceMode);
2173 if (info2->devmode == NULL) {
2174 result = WERR_NOMEM;
2177 ndr_err = ndr_pull_struct_blob(&blob,
2180 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
2181 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2182 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2183 result = WERR_NOMEM;
2188 if (info2->devmode == NULL && lp_default_devmode(snum)) {
2189 result = spoolss_create_default_devmode(info2,
2192 if (!W_ERROR_IS_OK(result)) {
2197 if (info2->devmode != NULL) {
2198 info2->devmode->devicename = talloc_strdup(info2->devmode,
2199 info2->printername);
2200 if (info2->devmode->devicename == NULL) {
2201 DEBUG(0, ("winreg_get_printer: Failed to set devicename\n"));
2202 result = WERR_NOMEM;
2207 result = winreg_get_printer_secdesc(info2,
2211 if (!W_ERROR_IS_OK(result)) {
2215 /* Fix for OS/2 drivers. */
2216 if (get_remote_arch() == RA_OS2) {
2217 spoolss_map_to_os2_driver(info2, &info2->drivername);
2221 *pinfo2 = talloc_move(mem_ctx, &info2);
2226 if (winreg_pipe != NULL) {
2227 if (is_valid_policy_hnd(&key_hnd)) {
2228 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2230 if (is_valid_policy_hnd(&hive_hnd)) {
2231 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2235 TALLOC_FREE(tmp_ctx);
2239 WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
2240 struct auth_serversupplied_info *server_info,
2241 const char *sharename,
2242 struct spoolss_security_descriptor **psecdesc)
2244 struct spoolss_security_descriptor *secdesc;
2245 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2246 struct rpc_pipe_client *winreg_pipe = NULL;
2247 struct policy_handle hive_hnd, key_hnd;
2248 enum ndr_err_code ndr_err;
2251 TALLOC_CTX *tmp_ctx;
2254 tmp_ctx = talloc_stackframe();
2255 if (tmp_ctx == NULL) {
2259 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2261 talloc_free(tmp_ctx);
2265 ZERO_STRUCT(hive_hnd);
2266 ZERO_STRUCT(key_hnd);
2268 result = winreg_printer_openkey(tmp_ctx,
2277 if (!W_ERROR_IS_OK(result)) {
2278 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2279 goto create_default;
2284 result = winreg_printer_query_binary(tmp_ctx,
2289 if (!W_ERROR_IS_OK(result)) {
2290 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2291 goto create_default;
2296 secdesc = talloc_zero(tmp_ctx, struct spoolss_security_descriptor);
2297 if (secdesc == NULL) {
2298 result = WERR_NOMEM;
2301 ndr_err = ndr_pull_struct_blob(&blob,
2304 (ndr_pull_flags_fn_t) ndr_pull_security_descriptor);
2305 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2306 DEBUG(0, ("winreg_get_secdesc: Failed to unmarshall security descriptor\n"));
2307 result = WERR_NOMEM;
2312 *psecdesc = talloc_move(mem_ctx, &secdesc);
2319 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
2320 if (!W_ERROR_IS_OK(result)) {
2324 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
2325 this security descriptor has been created when winbindd was
2326 down. Take ownership of security descriptor. */
2327 if (sid_equal(secdesc->owner_sid, &global_sid_World)) {
2328 struct dom_sid owner_sid;
2330 /* Change sd owner to workgroup administrator */
2332 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid)) {
2333 struct spoolss_security_descriptor *new_secdesc;
2337 sid_append_rid(&owner_sid, DOMAIN_RID_ADMINISTRATOR);
2339 new_secdesc = make_sec_desc(tmp_ctx,
2348 if (new_secdesc == NULL) {
2349 result = WERR_NOMEM;
2353 /* Swap with other one */
2354 secdesc = new_secdesc;
2358 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, secdesc,
2359 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2360 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2361 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2362 result = WERR_NOMEM;
2366 result = winreg_printer_write_binary(tmp_ctx,
2371 if (!W_ERROR_IS_OK(result)) {
2376 *psecdesc = talloc_move(mem_ctx, &secdesc);
2381 if (winreg_pipe != NULL) {
2382 if (is_valid_policy_hnd(&key_hnd)) {
2383 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2385 if (is_valid_policy_hnd(&hive_hnd)) {
2386 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2390 talloc_free(tmp_ctx);
2394 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
2395 struct auth_serversupplied_info *server_info,
2396 const char *sharename,
2397 const struct spoolss_security_descriptor *secdesc)
2399 const struct spoolss_security_descriptor *new_secdesc = secdesc;
2400 struct spoolss_security_descriptor *old_secdesc;
2401 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2402 struct rpc_pipe_client *winreg_pipe = NULL;
2403 struct policy_handle hive_hnd, key_hnd;
2404 enum ndr_err_code ndr_err;
2407 TALLOC_CTX *tmp_ctx;
2410 tmp_ctx = talloc_stackframe();
2411 if (tmp_ctx == NULL) {
2415 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2417 talloc_free(tmp_ctx);
2422 * The old owner and group sids of the security descriptor are not
2423 * present when new ACEs are added or removed by changing printer
2424 * permissions through NT. If they are NULL in the new security
2425 * descriptor then copy them over from the old one.
2427 if (!secdesc->owner_sid || !secdesc->group_sid) {
2428 struct dom_sid *owner_sid, *group_sid;
2429 struct security_acl *dacl, *sacl;
2432 result = winreg_get_printer_secdesc(tmp_ctx,
2436 if (!W_ERROR_IS_OK(result)) {
2437 talloc_free(tmp_ctx);
2441 /* Pick out correct owner and group sids */
2442 owner_sid = secdesc->owner_sid ?
2443 secdesc->owner_sid :
2444 old_secdesc->owner_sid;
2446 group_sid = secdesc->group_sid ?
2447 secdesc->group_sid :
2448 old_secdesc->group_sid;
2450 dacl = secdesc->dacl ?
2454 sacl = secdesc->sacl ?
2458 /* Make a deep copy of the security descriptor */
2459 new_secdesc = make_sec_desc(tmp_ctx,
2467 if (new_secdesc == NULL) {
2468 talloc_free(tmp_ctx);
2473 ZERO_STRUCT(hive_hnd);
2474 ZERO_STRUCT(key_hnd);
2476 result = winreg_printer_openkey(tmp_ctx,
2485 if (!W_ERROR_IS_OK(result)) {
2489 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, new_secdesc,
2490 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2491 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2492 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2493 result = WERR_NOMEM;
2497 result = winreg_printer_write_binary(tmp_ctx,
2504 if (winreg_pipe != NULL) {
2505 if (is_valid_policy_hnd(&key_hnd)) {
2506 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2508 if (is_valid_policy_hnd(&hive_hnd)) {
2509 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2513 talloc_free(tmp_ctx);
2517 /* Set printer data over the winreg pipe. */
2518 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2519 struct auth_serversupplied_info *server_info,
2520 const char *printer,
2523 enum winreg_Type type,
2527 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2528 struct rpc_pipe_client *winreg_pipe = NULL;
2529 struct policy_handle hive_hnd, key_hnd;
2530 struct winreg_String wvalue;
2532 WERROR result = WERR_OK;
2534 TALLOC_CTX *tmp_ctx;
2536 tmp_ctx = talloc_stackframe();
2537 if (tmp_ctx == NULL) {
2541 path = winreg_printer_data_keyname(tmp_ctx, printer);
2543 TALLOC_FREE(tmp_ctx);
2547 ZERO_STRUCT(hive_hnd);
2548 ZERO_STRUCT(key_hnd);
2550 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2551 key, value, access_mask, printer));
2552 result = winreg_printer_openkey(tmp_ctx,
2561 if (!W_ERROR_IS_OK(result)) {
2562 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2563 key, win_errstr(result)));
2567 wvalue.name = value;
2568 status = rpccli_winreg_SetValue(winreg_pipe,
2576 if (!NT_STATUS_IS_OK(status)) {
2577 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2578 value, nt_errstr(status)));
2579 if (!W_ERROR_IS_OK(result)) {
2582 result = ntstatus_to_werror(status);
2588 if (winreg_pipe != NULL) {
2589 if (is_valid_policy_hnd(&key_hnd)) {
2590 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2592 if (is_valid_policy_hnd(&hive_hnd)) {
2593 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2597 TALLOC_FREE(tmp_ctx);
2601 /* Get printer data over a winreg pipe. */
2602 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2603 struct auth_serversupplied_info *server_info,
2604 const char *printer,
2607 enum winreg_Type *type,
2609 uint32_t *data_size)
2611 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2612 struct rpc_pipe_client *winreg_pipe = NULL;
2613 struct policy_handle hive_hnd, key_hnd;
2614 struct winreg_String wvalue;
2615 enum winreg_Type type_in;
2618 uint32_t data_in_size = 0;
2619 uint32_t value_len = 0;
2620 WERROR result = WERR_OK;
2622 TALLOC_CTX *tmp_ctx;
2624 tmp_ctx = talloc_stackframe();
2625 if (tmp_ctx == NULL) {
2629 path = winreg_printer_data_keyname(tmp_ctx, printer);
2631 TALLOC_FREE(tmp_ctx);
2635 ZERO_STRUCT(hive_hnd);
2636 ZERO_STRUCT(key_hnd);
2638 result = winreg_printer_openkey(tmp_ctx,
2647 if (!W_ERROR_IS_OK(result)) {
2648 DEBUG(0, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2649 key, win_errstr(result)));
2653 wvalue.name = value;
2656 * call QueryValue once with data == NULL to get the
2657 * needed memory size to be allocated, then allocate
2658 * data buffer and call again.
2660 status = rpccli_winreg_QueryValue(winreg_pipe,
2669 if (!NT_STATUS_IS_OK(status)) {
2670 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2671 value, nt_errstr(status)));
2672 if (!W_ERROR_IS_OK(result)) {
2675 result = ntstatus_to_werror(status);
2679 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2680 if (data_in == NULL) {
2681 result = WERR_NOMEM;
2686 status = rpccli_winreg_QueryValue(winreg_pipe,
2695 if (!NT_STATUS_IS_OK(status)) {
2696 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2697 value, nt_errstr(status)));
2698 if (!W_ERROR_IS_OK(result)) {
2699 result = ntstatus_to_werror(status);
2705 *data_size = data_in_size;
2707 *data = talloc_move(mem_ctx, &data_in);
2712 if (winreg_pipe != NULL) {
2713 if (is_valid_policy_hnd(&key_hnd)) {
2714 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2716 if (is_valid_policy_hnd(&hive_hnd)) {
2717 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2721 TALLOC_FREE(tmp_ctx);
2725 /* Enumerate on the values of a given key and provide the data. */
2726 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2727 struct auth_serversupplied_info *server_info,
2728 const char *printer,
2730 uint32_t *pnum_values,
2731 struct spoolss_PrinterEnumValues **penum_values)
2733 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2734 struct rpc_pipe_client *winreg_pipe = NULL;
2735 struct policy_handle hive_hnd, key_hnd;
2737 struct spoolss_PrinterEnumValues *enum_values = NULL;
2738 uint32_t num_values = 0;
2740 WERROR result = WERR_OK;
2742 TALLOC_CTX *tmp_ctx;
2744 tmp_ctx = talloc_stackframe();
2745 if (tmp_ctx == NULL) {
2749 path = winreg_printer_data_keyname(tmp_ctx, printer);
2751 TALLOC_FREE(tmp_ctx);
2755 result = winreg_printer_openkey(tmp_ctx,
2764 if (!W_ERROR_IS_OK(result)) {
2765 DEBUG(0, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2766 key, win_errstr(result)));
2770 result = winreg_printer_enumvalues(tmp_ctx,
2775 if (!W_ERROR_IS_OK(result)) {
2776 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2777 key, win_errstr(result)));
2781 *pnum_values = num_values;
2783 *penum_values = talloc_move(mem_ctx, &enum_values);
2788 if (winreg_pipe != NULL) {
2789 if (is_valid_policy_hnd(&key_hnd)) {
2790 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2792 if (is_valid_policy_hnd(&hive_hnd)) {
2793 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2797 TALLOC_FREE(tmp_ctx);
2801 /* Delete printer data over a winreg pipe. */
2802 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2803 struct auth_serversupplied_info *server_info,
2804 const char *printer,
2808 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2809 struct rpc_pipe_client *winreg_pipe = NULL;
2810 struct policy_handle hive_hnd, key_hnd;
2811 struct winreg_String wvalue;
2813 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 ZERO_STRUCT(hive_hnd);
2830 ZERO_STRUCT(key_hnd);
2832 result = winreg_printer_openkey(tmp_ctx,
2841 if (!W_ERROR_IS_OK(result)) {
2842 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2843 key, win_errstr(result)));
2847 wvalue.name = value;
2848 status = rpccli_winreg_DeleteValue(winreg_pipe,
2853 if (!NT_STATUS_IS_OK(status)) {
2854 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2855 value, nt_errstr(status)));
2856 if (!W_ERROR_IS_OK(result)) {
2859 result = ntstatus_to_werror(status);
2865 if (winreg_pipe != NULL) {
2866 if (is_valid_policy_hnd(&key_hnd)) {
2867 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2869 if (is_valid_policy_hnd(&hive_hnd)) {
2870 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2874 TALLOC_FREE(tmp_ctx);
2878 /* Enumerate on the subkeys of a given key and provide the data. */
2879 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2880 struct auth_serversupplied_info *server_info,
2881 const char *printer,
2883 uint32_t *pnum_subkeys,
2884 const char ***psubkeys)
2886 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2887 struct rpc_pipe_client *winreg_pipe = NULL;
2888 struct policy_handle hive_hnd, key_hnd;
2890 const char **subkeys = NULL;
2891 uint32_t num_subkeys = -1;
2893 WERROR result = WERR_OK;
2895 TALLOC_CTX *tmp_ctx;
2897 tmp_ctx = talloc_stackframe();
2898 if (tmp_ctx == NULL) {
2902 path = winreg_printer_data_keyname(tmp_ctx, printer);
2904 TALLOC_FREE(tmp_ctx);
2908 ZERO_STRUCT(hive_hnd);
2909 ZERO_STRUCT(key_hnd);
2911 result = winreg_printer_openkey(tmp_ctx,
2920 if (!W_ERROR_IS_OK(result)) {
2921 DEBUG(0, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2922 key, win_errstr(result)));
2926 result = winreg_printer_enumkeys(tmp_ctx,
2931 if (!W_ERROR_IS_OK(result)) {
2932 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2933 key, win_errstr(result)));
2937 *pnum_subkeys = num_subkeys;
2939 *psubkeys = talloc_move(mem_ctx, &subkeys);
2944 if (winreg_pipe != NULL) {
2945 if (is_valid_policy_hnd(&key_hnd)) {
2946 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2948 if (is_valid_policy_hnd(&hive_hnd)) {
2949 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2953 TALLOC_FREE(tmp_ctx);
2957 /* Delete a key with subkeys of a given printer. */
2958 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
2959 struct auth_serversupplied_info *server_info,
2960 const char *printer,
2963 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2964 struct rpc_pipe_client *winreg_pipe = NULL;
2965 struct policy_handle hive_hnd, key_hnd;
2969 TALLOC_CTX *tmp_ctx;
2971 tmp_ctx = talloc_stackframe();
2972 if (tmp_ctx == NULL) {
2976 path = winreg_printer_data_keyname(tmp_ctx, printer);
2978 TALLOC_FREE(tmp_ctx);
2982 result = winreg_printer_openkey(tmp_ctx,
2991 if (!W_ERROR_IS_OK(result)) {
2992 /* key doesn't exist */
2993 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2998 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2999 key, win_errstr(result)));
3003 if (is_valid_policy_hnd(&key_hnd)) {
3004 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3007 if (key == NULL || key[0] == '\0') {
3010 keyname = talloc_asprintf(tmp_ctx,
3014 if (keyname == NULL) {
3015 result = WERR_NOMEM;
3020 result = winreg_printer_delete_subkeys(tmp_ctx,
3025 if (!W_ERROR_IS_OK(result)) {
3026 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
3027 key, win_errstr(result)));
3032 if (winreg_pipe != NULL) {
3033 if (is_valid_policy_hnd(&key_hnd)) {
3034 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3036 if (is_valid_policy_hnd(&hive_hnd)) {
3037 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3041 TALLOC_FREE(tmp_ctx);
3045 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
3046 struct auth_serversupplied_info *server_info,
3047 const char *printer)
3049 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3050 struct rpc_pipe_client *winreg_pipe = NULL;
3051 struct policy_handle hive_hnd, key_hnd;
3054 TALLOC_CTX *tmp_ctx;
3056 tmp_ctx = talloc_stackframe();
3057 if (tmp_ctx == NULL) {
3061 path = winreg_printer_data_keyname(tmp_ctx, printer);
3063 TALLOC_FREE(tmp_ctx);
3067 ZERO_STRUCT(hive_hnd);
3068 ZERO_STRUCT(key_hnd);
3070 result = winreg_printer_openkey(tmp_ctx,
3079 if (!W_ERROR_IS_OK(result)) {
3080 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
3081 path, win_errstr(result)));
3085 result = winreg_printer_write_dword(tmp_ctx,
3089 winreg_printer_rev_changeid());
3090 if (!W_ERROR_IS_OK(result)) {
3096 if (winreg_pipe != NULL) {
3097 if (is_valid_policy_hnd(&key_hnd)) {
3098 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3100 if (is_valid_policy_hnd(&hive_hnd)) {
3101 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3105 TALLOC_FREE(tmp_ctx);
3109 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
3110 struct auth_serversupplied_info *server_info,
3111 const char *printer,
3112 uint32_t *pchangeid)
3114 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3115 struct rpc_pipe_client *winreg_pipe = NULL;
3116 struct policy_handle hive_hnd, key_hnd;
3117 uint32_t changeid = 0;
3120 TALLOC_CTX *tmp_ctx;
3122 tmp_ctx = talloc_stackframe();
3123 if (tmp_ctx == NULL) {
3127 path = winreg_printer_data_keyname(tmp_ctx, printer);
3129 TALLOC_FREE(tmp_ctx);
3133 ZERO_STRUCT(hive_hnd);
3134 ZERO_STRUCT(key_hnd);
3136 result = winreg_printer_openkey(tmp_ctx,
3145 if (!W_ERROR_IS_OK(result)) {
3146 DEBUG(0, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
3147 path, win_errstr(result)));
3151 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path));
3153 result = winreg_printer_query_dword(tmp_ctx,
3158 if (!W_ERROR_IS_OK(result)) {
3163 *pchangeid = changeid;
3168 if (winreg_pipe != NULL) {
3169 if (is_valid_policy_hnd(&key_hnd)) {
3170 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3172 if (is_valid_policy_hnd(&hive_hnd)) {
3173 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3177 TALLOC_FREE(tmp_ctx);
3182 * The special behaviour of the spoolss forms is documented at the website:
3184 * Managing Win32 Printserver Forms
3185 * http://unixwiz.net/techtips/winspooler-forms.html
3188 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
3189 struct auth_serversupplied_info *server_info,
3190 struct spoolss_AddFormInfo1 *form)
3192 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3193 struct rpc_pipe_client *winreg_pipe = NULL;
3194 struct policy_handle hive_hnd, key_hnd;
3195 struct winreg_String wvalue;
3197 uint32_t num_info = 0;
3198 union spoolss_FormInfo *info = NULL;
3202 TALLOC_CTX *tmp_ctx;
3204 tmp_ctx = talloc_stackframe();
3205 if (tmp_ctx == NULL) {
3209 ZERO_STRUCT(hive_hnd);
3210 ZERO_STRUCT(key_hnd);
3212 result = winreg_printer_openkey(tmp_ctx,
3215 TOP_LEVEL_CONTROL_FORMS_KEY,
3221 if (!W_ERROR_IS_OK(result)) {
3222 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
3223 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3227 result = winreg_printer_enumforms1(tmp_ctx, server_info, &num_info, &info);
3228 if (!W_ERROR_IS_OK(result)) {
3229 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
3230 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3234 /* If form name already exists or is builtin return ALREADY_EXISTS */
3235 for (i = 0; i < num_info; i++) {
3236 if (strequal(info[i].info1.form_name, form->form_name)) {
3237 result = WERR_FILE_EXISTS;
3242 wvalue.name = form->form_name;
3244 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3245 SIVAL(blob.data, 0, form->size.width);
3246 SIVAL(blob.data, 4, form->size.height);
3247 SIVAL(blob.data, 8, form->area.left);
3248 SIVAL(blob.data, 12, form->area.top);
3249 SIVAL(blob.data, 16, form->area.right);
3250 SIVAL(blob.data, 20, form->area.bottom);
3251 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
3252 SIVAL(blob.data, 28, form->flags);
3254 status = rpccli_winreg_SetValue(winreg_pipe,
3262 if (!NT_STATUS_IS_OK(status)) {
3263 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
3264 wvalue.name, nt_errstr(status)));
3265 if (!W_ERROR_IS_OK(result)) {
3268 result = ntstatus_to_werror(status);
3274 if (winreg_pipe != NULL) {
3275 if (is_valid_policy_hnd(&key_hnd)) {
3276 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3278 if (is_valid_policy_hnd(&hive_hnd)) {
3279 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3284 TALLOC_FREE(tmp_ctx);
3288 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
3289 struct auth_serversupplied_info *server_info,
3290 uint32_t *pnum_info,
3291 union spoolss_FormInfo **pinfo)
3293 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3294 struct rpc_pipe_client *winreg_pipe = NULL;
3295 struct policy_handle hive_hnd, key_hnd;
3296 union spoolss_FormInfo *info;
3297 struct spoolss_PrinterEnumValues *enum_values = NULL;
3298 uint32_t num_values = 0;
3299 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3302 TALLOC_CTX *tmp_ctx;
3304 tmp_ctx = talloc_stackframe();
3305 if (tmp_ctx == NULL) {
3309 ZERO_STRUCT(hive_hnd);
3310 ZERO_STRUCT(key_hnd);
3312 result = winreg_printer_openkey(tmp_ctx,
3315 TOP_LEVEL_CONTROL_FORMS_KEY,
3321 if (!W_ERROR_IS_OK(result)) {
3322 /* key doesn't exist */
3323 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3328 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3329 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3333 result = winreg_printer_enumvalues(tmp_ctx,
3338 if (!W_ERROR_IS_OK(result)) {
3339 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3340 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3344 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
3346 result = WERR_NOMEM;
3350 /* Enumerate BUILTIN forms */
3351 for (i = 0; i < num_builtin; i++) {
3352 info[i].info1 = builtin_forms1[i];
3355 /* Enumerate registry forms */
3356 for (i = 0; i < num_values; i++) {
3357 union spoolss_FormInfo val;
3359 if (enum_values[i].type != REG_BINARY ||
3360 enum_values[i].data_length != 32) {
3364 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
3365 if (val.info1.form_name == NULL) {
3366 result = WERR_NOMEM;
3370 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3371 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3372 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3373 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3374 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3375 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3376 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3377 val.info1.flags = (enum spoolss_FormFlags) IVAL(enum_values[i].data->data, 28);
3379 info[i + num_builtin] = val;
3382 *pnum_info = num_builtin + num_values;
3384 *pinfo = talloc_move(mem_ctx, &info);
3388 if (winreg_pipe != NULL) {
3389 if (is_valid_policy_hnd(&key_hnd)) {
3390 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3392 if (is_valid_policy_hnd(&hive_hnd)) {
3393 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3397 TALLOC_FREE(enum_values);
3398 TALLOC_FREE(tmp_ctx);
3402 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3403 struct auth_serversupplied_info *server_info,
3404 const char *form_name)
3406 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3407 struct rpc_pipe_client *winreg_pipe = NULL;
3408 struct policy_handle hive_hnd, key_hnd;
3409 struct winreg_String wvalue;
3410 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3412 WERROR result = WERR_OK;
3414 TALLOC_CTX *tmp_ctx;
3416 for (i = 0; i < num_builtin; i++) {
3417 if (strequal(builtin_forms1[i].form_name, form_name)) {
3418 return WERR_INVALID_PARAMETER;
3422 tmp_ctx = talloc_stackframe();
3423 if (tmp_ctx == NULL) {
3427 ZERO_STRUCT(hive_hnd);
3428 ZERO_STRUCT(key_hnd);
3430 result = winreg_printer_openkey(tmp_ctx,
3433 TOP_LEVEL_CONTROL_FORMS_KEY,
3439 if (!W_ERROR_IS_OK(result)) {
3440 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3441 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3442 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3443 result = WERR_INVALID_FORM_NAME;
3448 wvalue.name = form_name;
3449 status = rpccli_winreg_DeleteValue(winreg_pipe,
3454 if (!NT_STATUS_IS_OK(status)) {
3455 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3456 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3457 result = WERR_INVALID_FORM_NAME;
3460 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3461 wvalue.name, nt_errstr(status)));
3462 if (!W_ERROR_IS_OK(result)) {
3465 result = ntstatus_to_werror(status);
3471 if (winreg_pipe != NULL) {
3472 if (is_valid_policy_hnd(&key_hnd)) {
3473 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3475 if (is_valid_policy_hnd(&hive_hnd)) {
3476 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3480 TALLOC_FREE(tmp_ctx);
3484 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3485 struct auth_serversupplied_info *server_info,
3486 const char *form_name,
3487 struct spoolss_AddFormInfo1 *form)
3489 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3490 struct rpc_pipe_client *winreg_pipe = NULL;
3491 struct policy_handle hive_hnd, key_hnd;
3492 struct winreg_String wvalue;
3494 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3498 TALLOC_CTX *tmp_ctx = NULL;
3500 for (i = 0; i < num_builtin; i++) {
3501 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3502 result = WERR_INVALID_PARAM;
3507 tmp_ctx = talloc_stackframe();
3508 if (tmp_ctx == NULL) {
3512 ZERO_STRUCT(hive_hnd);
3513 ZERO_STRUCT(key_hnd);
3515 result = winreg_printer_openkey(tmp_ctx,
3518 TOP_LEVEL_CONTROL_FORMS_KEY,
3524 if (!W_ERROR_IS_OK(result)) {
3525 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3526 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3530 /* If form_name != form->form_name then we renamed the form */
3531 if (strequal(form_name, form->form_name)) {
3532 result = winreg_printer_deleteform1(tmp_ctx, server_info, form_name);
3533 if (!W_ERROR_IS_OK(result)) {
3534 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3535 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3540 wvalue.name = form->form_name;
3542 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3543 SIVAL(blob.data, 0, form->size.width);
3544 SIVAL(blob.data, 4, form->size.height);
3545 SIVAL(blob.data, 8, form->area.left);
3546 SIVAL(blob.data, 12, form->area.top);
3547 SIVAL(blob.data, 16, form->area.right);
3548 SIVAL(blob.data, 20, form->area.bottom);
3549 SIVAL(blob.data, 24, 42);
3550 SIVAL(blob.data, 28, form->flags);
3552 status = rpccli_winreg_SetValue(winreg_pipe,
3560 if (!NT_STATUS_IS_OK(status)) {
3561 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3562 wvalue.name, nt_errstr(status)));
3563 if (!W_ERROR_IS_OK(result)) {
3566 result = ntstatus_to_werror(status);
3572 if (winreg_pipe != NULL) {
3573 if (is_valid_policy_hnd(&key_hnd)) {
3574 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3576 if (is_valid_policy_hnd(&hive_hnd)) {
3577 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3581 TALLOC_FREE(tmp_ctx);
3585 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3586 struct auth_serversupplied_info *server_info,
3587 const char *form_name,
3588 struct spoolss_FormInfo1 *r)
3590 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3591 struct rpc_pipe_client *winreg_pipe = NULL;
3592 struct policy_handle hive_hnd, key_hnd;
3593 struct winreg_String wvalue;
3594 enum winreg_Type type_in;
3596 uint32_t data_in_size = 0;
3597 uint32_t value_len = 0;
3598 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3602 TALLOC_CTX *tmp_ctx;
3604 /* check builtin forms first */
3605 for (i = 0; i < num_builtin; i++) {
3606 if (strequal(builtin_forms1[i].form_name, form_name)) {
3607 *r = builtin_forms1[i];
3612 tmp_ctx = talloc_stackframe();
3613 if (tmp_ctx == NULL) {
3617 ZERO_STRUCT(hive_hnd);
3618 ZERO_STRUCT(key_hnd);
3620 result = winreg_printer_openkey(tmp_ctx,
3623 TOP_LEVEL_CONTROL_FORMS_KEY,
3629 if (!W_ERROR_IS_OK(result)) {
3630 DEBUG(0, ("winreg_printer_getform1: Could not open key %s: %s\n",
3631 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3635 wvalue.name = form_name;
3638 * call QueryValue once with data == NULL to get the
3639 * needed memory size to be allocated, then allocate
3640 * data buffer and call again.
3642 status = rpccli_winreg_QueryValue(winreg_pipe,
3651 if (!NT_STATUS_IS_OK(status)) {
3652 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3653 wvalue.name, nt_errstr(status)));
3654 if (!W_ERROR_IS_OK(result)) {
3657 result = ntstatus_to_werror(status);
3661 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3662 if (data_in == NULL) {
3663 result = WERR_NOMEM;
3668 status = rpccli_winreg_QueryValue(winreg_pipe,
3677 if (!NT_STATUS_IS_OK(status)) {
3678 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3679 wvalue.name, nt_errstr(status)));
3680 if (!W_ERROR_IS_OK(result)) {
3683 result = ntstatus_to_werror(status);
3687 r->form_name = talloc_strdup(mem_ctx, form_name);
3688 if (r->form_name == NULL) {
3689 result = WERR_NOMEM;
3693 r->size.width = IVAL(data_in, 0);
3694 r->size.height = IVAL(data_in, 4);
3695 r->area.left = IVAL(data_in, 8);
3696 r->area.top = IVAL(data_in, 12);
3697 r->area.right = IVAL(data_in, 16);
3698 r->area.bottom = IVAL(data_in, 20);
3699 /* skip index IVAL(data_in, 24)));*/
3700 r->flags = (enum spoolss_FormFlags) IVAL(data_in, 28);
3704 if (winreg_pipe != NULL) {
3705 if (is_valid_policy_hnd(&key_hnd)) {
3706 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3708 if (is_valid_policy_hnd(&hive_hnd)) {
3709 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3713 TALLOC_FREE(tmp_ctx);
3717 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3718 struct auth_serversupplied_info *server_info,
3719 struct spoolss_AddDriverInfoCtr *r,
3720 const char **driver_name,
3721 uint32_t *driver_version)
3723 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3724 struct rpc_pipe_client *winreg_pipe = NULL;
3725 struct policy_handle hive_hnd, key_hnd;
3726 struct spoolss_DriverInfo8 info8;
3727 TALLOC_CTX *tmp_ctx = NULL;
3730 ZERO_STRUCT(hive_hnd);
3731 ZERO_STRUCT(key_hnd);
3734 if (!driver_info_ctr_to_info8(r, &info8)) {
3735 result = WERR_INVALID_PARAMETER;
3739 tmp_ctx = talloc_stackframe();
3740 if (tmp_ctx == NULL) {
3744 result = winreg_printer_opendriver(tmp_ctx,
3753 if (!W_ERROR_IS_OK(result)) {
3754 DEBUG(0, ("winreg_add_driver: "
3755 "Could not open driver key (%s,%s,%d): %s\n",
3756 info8.driver_name, info8.architecture,
3757 info8.version, win_errstr(result)));
3761 /* TODO: "Attributes" ? */
3763 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe,
3764 &key_hnd, "Version",
3766 if (!W_ERROR_IS_OK(result)) {
3770 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3773 if (!W_ERROR_IS_OK(result)) {
3777 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3778 &key_hnd, "Data File",
3780 if (!W_ERROR_IS_OK(result)) {
3784 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3785 &key_hnd, "Configuration File",
3787 if (!W_ERROR_IS_OK(result)) {
3791 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3792 &key_hnd, "Help File",
3794 if (!W_ERROR_IS_OK(result)) {
3798 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3799 &key_hnd, "Dependent Files",
3800 info8.dependent_files);
3801 if (!W_ERROR_IS_OK(result)) {
3805 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3806 &key_hnd, "Monitor",
3807 info8.monitor_name);
3808 if (!W_ERROR_IS_OK(result)) {
3812 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3813 &key_hnd, "Datatype",
3814 info8.default_datatype);
3815 if (!W_ERROR_IS_OK(result)) {
3819 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3820 &key_hnd, "Previous Names",
3821 info8.previous_names);
3822 if (!W_ERROR_IS_OK(result)) {
3826 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3827 &key_hnd, "DriverDate",
3829 if (!W_ERROR_IS_OK(result)) {
3833 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe,
3834 &key_hnd, "DriverVersion",
3835 info8.driver_version);
3836 if (!W_ERROR_IS_OK(result)) {
3840 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3841 &key_hnd, "Manufacturer",
3842 info8.manufacturer_name);
3843 if (!W_ERROR_IS_OK(result)) {
3847 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3848 &key_hnd, "OEM URL",
3849 info8.manufacturer_url);
3850 if (!W_ERROR_IS_OK(result)) {
3854 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3855 &key_hnd, "HardwareID",
3857 if (!W_ERROR_IS_OK(result)) {
3861 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3862 &key_hnd, "Provider",
3864 if (!W_ERROR_IS_OK(result)) {
3868 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3869 &key_hnd, "Print Processor",
3870 info8.print_processor);
3871 if (!W_ERROR_IS_OK(result)) {
3875 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3876 &key_hnd, "VendorSetup",
3877 info8.vendor_setup);
3878 if (!W_ERROR_IS_OK(result)) {
3882 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3883 &key_hnd, "Color Profiles",
3884 info8.color_profiles);
3885 if (!W_ERROR_IS_OK(result)) {
3889 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3890 &key_hnd, "InfPath",
3892 if (!W_ERROR_IS_OK(result)) {
3896 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe, &key_hnd,
3897 "PrinterDriverAttributes",
3898 info8.printer_driver_attributes);
3899 if (!W_ERROR_IS_OK(result)) {
3903 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3904 &key_hnd, "CoreDependencies",
3905 info8.core_driver_dependencies);
3906 if (!W_ERROR_IS_OK(result)) {
3910 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3911 &key_hnd, "MinInboxDriverVerDate",
3912 info8.min_inbox_driver_ver_date);
3913 if (!W_ERROR_IS_OK(result)) {
3917 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe, &key_hnd,
3918 "MinInboxDriverVerVersion",
3919 info8.min_inbox_driver_ver_version);
3920 if (!W_ERROR_IS_OK(result)) {
3924 *driver_name = info8.driver_name;
3925 *driver_version = info8.version;
3928 if (winreg_pipe != NULL) {
3929 if (is_valid_policy_hnd(&key_hnd)) {
3930 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3932 if (is_valid_policy_hnd(&hive_hnd)) {
3933 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3937 TALLOC_FREE(tmp_ctx);
3941 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
3942 struct auth_serversupplied_info *server_info,
3943 const char *architecture,
3944 const char *driver_name,
3945 uint32_t driver_version,
3946 struct spoolss_DriverInfo8 **_info8)
3948 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3949 struct rpc_pipe_client *winreg_pipe = NULL;
3950 struct policy_handle hive_hnd, key_hnd;
3951 struct spoolss_DriverInfo8 i8, *info8;
3952 struct spoolss_PrinterEnumValues *enum_values = NULL;
3953 struct spoolss_PrinterEnumValues *v;
3954 uint32_t num_values = 0;
3955 TALLOC_CTX *tmp_ctx;
3959 ZERO_STRUCT(hive_hnd);
3960 ZERO_STRUCT(key_hnd);
3963 tmp_ctx = talloc_stackframe();
3964 if (tmp_ctx == NULL) {
3968 if (driver_version == DRIVER_ANY_VERSION) {
3969 /* look for Win2k first and then for NT4 */
3970 result = winreg_printer_opendriver(tmp_ctx,
3979 if (!W_ERROR_IS_OK(result)) {
3980 result = winreg_printer_opendriver(tmp_ctx,
3991 /* ok normal case */
3992 result = winreg_printer_opendriver(tmp_ctx,
4002 if (!W_ERROR_IS_OK(result)) {
4003 DEBUG(5, ("winreg_get_driver: "
4004 "Could not open driver key (%s,%s,%d): %s\n",
4005 driver_name, architecture,
4006 driver_version, win_errstr(result)));
4010 result = winreg_printer_enumvalues(tmp_ctx,
4015 if (!W_ERROR_IS_OK(result)) {
4016 DEBUG(0, ("winreg_get_driver: "
4017 "Could not enumerate values for (%s,%s,%d): %s\n",
4018 driver_name, architecture,
4019 driver_version, win_errstr(result)));
4023 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
4024 if (info8 == NULL) {
4025 result = WERR_NOMEM;
4029 info8->driver_name = talloc_strdup(info8, driver_name);
4030 if (info8->driver_name == NULL) {
4031 result = WERR_NOMEM;
4035 info8->architecture = talloc_strdup(info8, architecture);
4036 if (info8->architecture == NULL) {
4037 result = WERR_NOMEM;
4043 for (i = 0; i < num_values; i++) {
4044 const char *tmp_str;
4046 v = &enum_values[i];
4048 result = winreg_enumval_to_dword(info8, v,
4050 (uint32_t *) &info8->version);
4051 CHECK_ERROR(result);
4053 result = winreg_enumval_to_sz(info8, v,
4055 &info8->driver_path);
4056 CHECK_ERROR(result);
4058 result = winreg_enumval_to_sz(info8, v,
4061 CHECK_ERROR(result);
4063 result = winreg_enumval_to_sz(info8, v,
4064 "Configuration File",
4065 &info8->config_file);
4066 CHECK_ERROR(result);
4068 result = winreg_enumval_to_sz(info8, v,
4071 CHECK_ERROR(result);
4073 result = winreg_enumval_to_multi_sz(info8, v,
4075 &info8->dependent_files);
4076 CHECK_ERROR(result);
4078 result = winreg_enumval_to_sz(info8, v,
4080 &info8->monitor_name);
4081 CHECK_ERROR(result);
4083 result = winreg_enumval_to_sz(info8, v,
4085 &info8->default_datatype);
4086 CHECK_ERROR(result);
4088 result = winreg_enumval_to_multi_sz(info8, v,
4090 &info8->previous_names);
4091 CHECK_ERROR(result);
4093 result = winreg_enumval_to_sz(info8, v,
4096 if (W_ERROR_IS_OK(result)) {
4097 result = winreg_printer_date_to_NTTIME(tmp_str,
4098 &info8->driver_date);
4100 CHECK_ERROR(result);
4102 result = winreg_enumval_to_sz(info8, v,
4105 if (W_ERROR_IS_OK(result)) {
4106 result = winreg_printer_ver_to_dword(tmp_str,
4107 &info8->driver_version);
4109 CHECK_ERROR(result);
4111 result = winreg_enumval_to_sz(info8, v,
4113 &info8->manufacturer_name);
4114 CHECK_ERROR(result);
4116 result = winreg_enumval_to_sz(info8, v,
4118 &info8->manufacturer_url);
4119 CHECK_ERROR(result);
4121 result = winreg_enumval_to_sz(info8, v,
4123 &info8->hardware_id);
4124 CHECK_ERROR(result);
4126 result = winreg_enumval_to_sz(info8, v,
4129 CHECK_ERROR(result);
4131 result = winreg_enumval_to_sz(info8, v,
4133 &info8->print_processor);
4134 CHECK_ERROR(result);
4136 result = winreg_enumval_to_sz(info8, v,
4138 &info8->vendor_setup);
4139 CHECK_ERROR(result);
4141 result = winreg_enumval_to_multi_sz(info8, v,
4143 &info8->color_profiles);
4144 CHECK_ERROR(result);
4146 result = winreg_enumval_to_sz(info8, v,
4149 CHECK_ERROR(result);
4151 result = winreg_enumval_to_dword(info8, v,
4152 "PrinterDriverAttributes",
4153 &info8->printer_driver_attributes);
4154 CHECK_ERROR(result);
4156 result = winreg_enumval_to_multi_sz(info8, v,
4158 &info8->core_driver_dependencies);
4159 CHECK_ERROR(result);
4161 result = winreg_enumval_to_sz(info8, v,
4162 "MinInboxDriverVerDate",
4164 if (W_ERROR_IS_OK(result)) {
4165 result = winreg_printer_date_to_NTTIME(tmp_str,
4166 &info8->min_inbox_driver_ver_date);
4168 CHECK_ERROR(result);
4170 result = winreg_enumval_to_sz(info8, v,
4171 "MinInboxDriverVerVersion",
4173 if (W_ERROR_IS_OK(result)) {
4174 result = winreg_printer_ver_to_dword(tmp_str,
4175 &info8->min_inbox_driver_ver_version);
4177 CHECK_ERROR(result);
4180 if (!W_ERROR_IS_OK(result)) {
4181 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4182 "for %s: %s\n", v->value_name,
4183 win_errstr(result)));
4187 *_info8 = talloc_steal(mem_ctx, info8);
4190 if (winreg_pipe != NULL) {
4191 if (is_valid_policy_hnd(&key_hnd)) {
4192 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4194 if (is_valid_policy_hnd(&hive_hnd)) {
4195 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4199 TALLOC_FREE(tmp_ctx);
4203 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
4204 struct auth_serversupplied_info *server_info,
4205 struct spoolss_DriverInfo8 *info8,
4208 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4209 struct rpc_pipe_client *winreg_pipe = NULL;
4210 struct policy_handle hive_hnd, key_hnd;
4211 TALLOC_CTX *tmp_ctx;
4215 ZERO_STRUCT(hive_hnd);
4216 ZERO_STRUCT(key_hnd);
4218 tmp_ctx = talloc_stackframe();
4219 if (tmp_ctx == NULL) {
4223 /* test that the key exists */
4224 result = winreg_printer_opendriver(tmp_ctx,
4227 info8->architecture,
4233 if (!W_ERROR_IS_OK(result)) {
4234 /* key doesn't exist */
4235 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
4240 DEBUG(5, ("winreg_del_driver: "
4241 "Could not open driver (%s,%s,%u): %s\n",
4242 info8->driver_name, info8->architecture,
4243 version, win_errstr(result)));
4248 if (is_valid_policy_hnd(&key_hnd)) {
4249 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4252 key_name = talloc_asprintf(tmp_ctx,
4253 "%s\\Environments\\%s\\Drivers\\Version-%u",
4254 TOP_LEVEL_CONTROL_KEY,
4255 info8->architecture, version);
4256 if (key_name == NULL) {
4257 result = WERR_NOMEM;
4261 result = winreg_printer_delete_subkeys(tmp_ctx,
4266 if (!W_ERROR_IS_OK(result)) {
4267 DEBUG(0, ("winreg_del_driver: "
4268 "Could not open driver (%s,%s,%u): %s\n",
4269 info8->driver_name, info8->architecture,
4270 version, win_errstr(result)));
4276 if (winreg_pipe != NULL) {
4277 if (is_valid_policy_hnd(&key_hnd)) {
4278 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4280 if (is_valid_policy_hnd(&hive_hnd)) {
4281 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4285 TALLOC_FREE(tmp_ctx);
4289 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
4290 struct auth_serversupplied_info *server_info,
4291 const char *architecture,
4293 uint32_t *num_drivers,
4294 const char ***drivers_p)
4296 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4297 struct rpc_pipe_client *winreg_pipe = NULL;
4298 struct policy_handle hive_hnd, key_hnd;
4299 const char **drivers;
4300 TALLOC_CTX *tmp_ctx;
4306 ZERO_STRUCT(hive_hnd);
4307 ZERO_STRUCT(key_hnd);
4309 tmp_ctx = talloc_stackframe();
4310 if (tmp_ctx == NULL) {
4314 /* use NULL for the driver name so we open the key that is
4315 * parent of all drivers for this architecture and version */
4316 result = winreg_printer_opendriver(tmp_ctx,
4325 if (!W_ERROR_IS_OK(result)) {
4326 DEBUG(5, ("winreg_get_driver_list: "
4327 "Could not open key (%s,%u): %s\n",
4328 architecture, version, win_errstr(result)));
4333 result = winreg_printer_enumkeys(tmp_ctx,
4338 if (!W_ERROR_IS_OK(result)) {
4339 DEBUG(0, ("winreg_get_driver_list: "
4340 "Could not enumerate drivers for (%s,%u): %s\n",
4341 architecture, version, win_errstr(result)));
4345 *drivers_p = talloc_steal(mem_ctx, drivers);
4349 if (winreg_pipe != NULL) {
4350 if (is_valid_policy_hnd(&key_hnd)) {
4351 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4353 if (is_valid_policy_hnd(&hive_hnd)) {
4354 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4358 TALLOC_FREE(tmp_ctx);