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_new(mem_ctx);
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_new(mem_ctx);
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(0, ("winreg_printer_query_dword: 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(0, ("winreg_printer_query_dword: 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(0, ("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(0, ("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_new(mem_ctx);
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_new(mem_ctx);
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_new(mem_ctx);
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[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_new(mem_ctx);
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_new(mem_ctx);
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_new(mem_ctx);
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_new(mem_ctx);
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_new(mem_ctx);
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_new(mem_ctx);
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_new(mem_ctx);
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_new(mem_ctx);
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_new(mem_ctx);
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_new(mem_ctx);
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(0, ("winreg_printer_get_changeid: get changeid from %s\n", path));
3152 result = winreg_printer_query_dword(tmp_ctx,
3157 if (!W_ERROR_IS_OK(result)) {
3162 *pchangeid = changeid;
3167 if (winreg_pipe != NULL) {
3168 if (is_valid_policy_hnd(&key_hnd)) {
3169 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3171 if (is_valid_policy_hnd(&hive_hnd)) {
3172 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3176 TALLOC_FREE(tmp_ctx);
3181 * The special behaviour of the spoolss forms is documented at the website:
3183 * Managing Win32 Printserver Forms
3184 * http://unixwiz.net/techtips/winspooler-forms.html
3187 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
3188 struct auth_serversupplied_info *server_info,
3189 struct spoolss_AddFormInfo1 *form)
3191 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3192 struct rpc_pipe_client *winreg_pipe = NULL;
3193 struct policy_handle hive_hnd, key_hnd;
3194 struct winreg_String wvalue;
3196 uint32_t num_info = 0;
3197 union spoolss_FormInfo *info = NULL;
3201 TALLOC_CTX *tmp_ctx;
3203 tmp_ctx = talloc_new(mem_ctx);
3204 if (tmp_ctx == NULL) {
3208 ZERO_STRUCT(hive_hnd);
3209 ZERO_STRUCT(key_hnd);
3211 result = winreg_printer_openkey(tmp_ctx,
3214 TOP_LEVEL_CONTROL_FORMS_KEY,
3220 if (!W_ERROR_IS_OK(result)) {
3221 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
3222 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3226 result = winreg_printer_enumforms1(tmp_ctx, server_info, &num_info, &info);
3227 if (!W_ERROR_IS_OK(result)) {
3228 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
3229 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3233 /* If form name already exists or is builtin return ALREADY_EXISTS */
3234 for (i = 0; i < num_info; i++) {
3235 if (strequal(info[i].info1.form_name, form->form_name)) {
3236 result = WERR_FILE_EXISTS;
3241 wvalue.name = form->form_name;
3243 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3244 SIVAL(blob.data, 0, form->size.width);
3245 SIVAL(blob.data, 4, form->size.height);
3246 SIVAL(blob.data, 8, form->area.left);
3247 SIVAL(blob.data, 12, form->area.top);
3248 SIVAL(blob.data, 16, form->area.right);
3249 SIVAL(blob.data, 20, form->area.bottom);
3250 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
3251 SIVAL(blob.data, 28, form->flags);
3253 status = rpccli_winreg_SetValue(winreg_pipe,
3261 if (!NT_STATUS_IS_OK(status)) {
3262 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
3263 wvalue.name, nt_errstr(status)));
3264 if (!W_ERROR_IS_OK(result)) {
3267 result = ntstatus_to_werror(status);
3273 if (winreg_pipe != NULL) {
3274 if (is_valid_policy_hnd(&key_hnd)) {
3275 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3277 if (is_valid_policy_hnd(&hive_hnd)) {
3278 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3283 TALLOC_FREE(tmp_ctx);
3287 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
3288 struct auth_serversupplied_info *server_info,
3289 uint32_t *pnum_info,
3290 union spoolss_FormInfo **pinfo)
3292 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3293 struct rpc_pipe_client *winreg_pipe = NULL;
3294 struct policy_handle hive_hnd, key_hnd;
3295 union spoolss_FormInfo *info;
3296 struct spoolss_PrinterEnumValues *enum_values = NULL;
3297 uint32_t num_values = 0;
3298 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3301 TALLOC_CTX *tmp_ctx;
3303 tmp_ctx = talloc_new(mem_ctx);
3304 if (tmp_ctx == NULL) {
3308 ZERO_STRUCT(hive_hnd);
3309 ZERO_STRUCT(key_hnd);
3311 result = winreg_printer_openkey(tmp_ctx,
3314 TOP_LEVEL_CONTROL_FORMS_KEY,
3320 if (!W_ERROR_IS_OK(result)) {
3321 /* key doesn't exist */
3322 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3327 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3328 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3332 result = winreg_printer_enumvalues(tmp_ctx,
3337 if (!W_ERROR_IS_OK(result)) {
3338 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3339 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3343 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
3345 result = WERR_NOMEM;
3349 /* Enumerate BUILTIN forms */
3350 for (i = 0; i < num_builtin; i++) {
3351 info[i].info1 = builtin_forms1[i];
3354 /* Enumerate registry forms */
3355 for (i = 0; i < num_values; i++) {
3356 union spoolss_FormInfo val;
3358 if (enum_values[i].type != REG_BINARY ||
3359 enum_values[i].data_length != 32) {
3363 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
3364 if (val.info1.form_name == NULL) {
3365 result = WERR_NOMEM;
3369 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3370 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3371 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3372 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3373 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3374 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3375 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3376 val.info1.flags = IVAL(enum_values[i].data->data, 28);
3378 info[i + num_builtin] = val;
3381 *pnum_info = num_builtin + num_values;
3383 *pinfo = talloc_move(mem_ctx, &info);
3387 if (winreg_pipe != NULL) {
3388 if (is_valid_policy_hnd(&key_hnd)) {
3389 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3391 if (is_valid_policy_hnd(&hive_hnd)) {
3392 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3396 TALLOC_FREE(enum_values);
3397 TALLOC_FREE(tmp_ctx);
3401 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3402 struct auth_serversupplied_info *server_info,
3403 const char *form_name)
3405 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3406 struct rpc_pipe_client *winreg_pipe = NULL;
3407 struct policy_handle hive_hnd, key_hnd;
3408 struct winreg_String wvalue;
3409 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3411 WERROR result = WERR_OK;
3413 TALLOC_CTX *tmp_ctx;
3415 for (i = 0; i < num_builtin; i++) {
3416 if (strequal(builtin_forms1[i].form_name, form_name)) {
3417 return WERR_INVALID_PARAMETER;
3421 tmp_ctx = talloc_new(mem_ctx);
3422 if (tmp_ctx == NULL) {
3426 ZERO_STRUCT(hive_hnd);
3427 ZERO_STRUCT(key_hnd);
3429 result = winreg_printer_openkey(tmp_ctx,
3432 TOP_LEVEL_CONTROL_FORMS_KEY,
3438 if (!W_ERROR_IS_OK(result)) {
3439 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3440 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3441 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3442 result = WERR_INVALID_FORM_NAME;
3447 wvalue.name = form_name;
3448 status = rpccli_winreg_DeleteValue(winreg_pipe,
3453 if (!NT_STATUS_IS_OK(status)) {
3454 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3455 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3456 result = WERR_INVALID_FORM_NAME;
3459 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3460 wvalue.name, nt_errstr(status)));
3461 if (!W_ERROR_IS_OK(result)) {
3464 result = ntstatus_to_werror(status);
3470 if (winreg_pipe != NULL) {
3471 if (is_valid_policy_hnd(&key_hnd)) {
3472 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3474 if (is_valid_policy_hnd(&hive_hnd)) {
3475 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3479 TALLOC_FREE(tmp_ctx);
3483 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3484 struct auth_serversupplied_info *server_info,
3485 const char *form_name,
3486 struct spoolss_AddFormInfo1 *form)
3488 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3489 struct rpc_pipe_client *winreg_pipe = NULL;
3490 struct policy_handle hive_hnd, key_hnd;
3491 struct winreg_String wvalue;
3493 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3497 TALLOC_CTX *tmp_ctx = NULL;
3499 for (i = 0; i < num_builtin; i++) {
3500 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3501 result = WERR_INVALID_PARAM;
3506 tmp_ctx = talloc_new(mem_ctx);
3507 if (tmp_ctx == NULL) {
3511 ZERO_STRUCT(hive_hnd);
3512 ZERO_STRUCT(key_hnd);
3514 result = winreg_printer_openkey(tmp_ctx,
3517 TOP_LEVEL_CONTROL_FORMS_KEY,
3523 if (!W_ERROR_IS_OK(result)) {
3524 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3525 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3529 /* If form_name != form->form_name then we renamed the form */
3530 if (strequal(form_name, form->form_name)) {
3531 result = winreg_printer_deleteform1(tmp_ctx, server_info, form_name);
3532 if (!W_ERROR_IS_OK(result)) {
3533 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3534 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3539 wvalue.name = form->form_name;
3541 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3542 SIVAL(blob.data, 0, form->size.width);
3543 SIVAL(blob.data, 4, form->size.height);
3544 SIVAL(blob.data, 8, form->area.left);
3545 SIVAL(blob.data, 12, form->area.top);
3546 SIVAL(blob.data, 16, form->area.right);
3547 SIVAL(blob.data, 20, form->area.bottom);
3548 SIVAL(blob.data, 24, 42);
3549 SIVAL(blob.data, 28, form->flags);
3551 status = rpccli_winreg_SetValue(winreg_pipe,
3559 if (!NT_STATUS_IS_OK(status)) {
3560 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3561 wvalue.name, nt_errstr(status)));
3562 if (!W_ERROR_IS_OK(result)) {
3565 result = ntstatus_to_werror(status);
3571 if (winreg_pipe != NULL) {
3572 if (is_valid_policy_hnd(&key_hnd)) {
3573 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3575 if (is_valid_policy_hnd(&hive_hnd)) {
3576 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3580 TALLOC_FREE(tmp_ctx);
3584 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3585 struct auth_serversupplied_info *server_info,
3586 const char *form_name,
3587 struct spoolss_FormInfo1 *r)
3589 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3590 struct rpc_pipe_client *winreg_pipe = NULL;
3591 struct policy_handle hive_hnd, key_hnd;
3592 struct winreg_String wvalue;
3593 enum winreg_Type type_in;
3595 uint32_t data_in_size = 0;
3596 uint32_t value_len = 0;
3597 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3601 TALLOC_CTX *tmp_ctx;
3603 /* check builtin forms first */
3604 for (i = 0; i < num_builtin; i++) {
3605 if (strequal(builtin_forms1[i].form_name, form_name)) {
3606 *r = builtin_forms1[i];
3611 tmp_ctx = talloc_new(mem_ctx);
3612 if (tmp_ctx == NULL) {
3616 ZERO_STRUCT(hive_hnd);
3617 ZERO_STRUCT(key_hnd);
3619 result = winreg_printer_openkey(tmp_ctx,
3622 TOP_LEVEL_CONTROL_FORMS_KEY,
3628 if (!W_ERROR_IS_OK(result)) {
3629 DEBUG(0, ("winreg_printer_getform1: Could not open key %s: %s\n",
3630 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3634 wvalue.name = form_name;
3637 * call QueryValue once with data == NULL to get the
3638 * needed memory size to be allocated, then allocate
3639 * data buffer and call again.
3641 status = rpccli_winreg_QueryValue(winreg_pipe,
3650 if (!NT_STATUS_IS_OK(status)) {
3651 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3652 wvalue.name, nt_errstr(status)));
3653 if (!W_ERROR_IS_OK(result)) {
3656 result = ntstatus_to_werror(status);
3660 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3661 if (data_in == NULL) {
3662 result = WERR_NOMEM;
3667 status = rpccli_winreg_QueryValue(winreg_pipe,
3676 if (!NT_STATUS_IS_OK(status)) {
3677 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3678 wvalue.name, nt_errstr(status)));
3679 if (!W_ERROR_IS_OK(result)) {
3682 result = ntstatus_to_werror(status);
3686 r->form_name = talloc_strdup(mem_ctx, form_name);
3687 if (r->form_name == NULL) {
3688 result = WERR_NOMEM;
3692 r->size.width = IVAL(data_in, 0);
3693 r->size.height = IVAL(data_in, 4);
3694 r->area.left = IVAL(data_in, 8);
3695 r->area.top = IVAL(data_in, 12);
3696 r->area.right = IVAL(data_in, 16);
3697 r->area.bottom = IVAL(data_in, 20);
3698 /* skip index IVAL(data_in, 24)));*/
3699 r->flags = IVAL(data_in, 28);
3703 if (winreg_pipe != NULL) {
3704 if (is_valid_policy_hnd(&key_hnd)) {
3705 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3707 if (is_valid_policy_hnd(&hive_hnd)) {
3708 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3712 TALLOC_FREE(tmp_ctx);
3716 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3717 struct auth_serversupplied_info *server_info,
3718 struct spoolss_AddDriverInfoCtr *r,
3719 const char **driver_name,
3720 uint32_t *driver_version)
3722 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3723 struct rpc_pipe_client *winreg_pipe = NULL;
3724 struct policy_handle hive_hnd, key_hnd;
3725 struct spoolss_DriverInfo8 info8;
3726 TALLOC_CTX *tmp_ctx = NULL;
3729 ZERO_STRUCT(hive_hnd);
3730 ZERO_STRUCT(key_hnd);
3733 if (!driver_info_ctr_to_info8(r, &info8)) {
3734 result = WERR_INVALID_PARAMETER;
3738 tmp_ctx = talloc_new(mem_ctx);
3739 if (tmp_ctx == NULL) {
3743 result = winreg_printer_opendriver(tmp_ctx,
3752 if (!W_ERROR_IS_OK(result)) {
3753 DEBUG(0, ("winreg_add_driver: "
3754 "Could not open driver key (%s,%s,%d): %s\n",
3755 info8.driver_name, info8.architecture,
3756 info8.version, win_errstr(result)));
3760 /* TODO: "Attributes" ? */
3762 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe,
3763 &key_hnd, "Version",
3765 if (!W_ERROR_IS_OK(result)) {
3769 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3772 if (!W_ERROR_IS_OK(result)) {
3776 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3777 &key_hnd, "Data File",
3779 if (!W_ERROR_IS_OK(result)) {
3783 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3784 &key_hnd, "Configuration File",
3786 if (!W_ERROR_IS_OK(result)) {
3790 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3791 &key_hnd, "Help File",
3793 if (!W_ERROR_IS_OK(result)) {
3797 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3798 &key_hnd, "Dependent Files",
3799 info8.dependent_files);
3800 if (!W_ERROR_IS_OK(result)) {
3804 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3805 &key_hnd, "Monitor",
3806 info8.monitor_name);
3807 if (!W_ERROR_IS_OK(result)) {
3811 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3812 &key_hnd, "Datatype",
3813 info8.default_datatype);
3814 if (!W_ERROR_IS_OK(result)) {
3818 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3819 &key_hnd, "Previous Names",
3820 info8.previous_names);
3821 if (!W_ERROR_IS_OK(result)) {
3825 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3826 &key_hnd, "DriverDate",
3828 if (!W_ERROR_IS_OK(result)) {
3832 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe,
3833 &key_hnd, "DriverVersion",
3834 info8.driver_version);
3835 if (!W_ERROR_IS_OK(result)) {
3839 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3840 &key_hnd, "Manufacturer",
3841 info8.manufacturer_name);
3842 if (!W_ERROR_IS_OK(result)) {
3846 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3847 &key_hnd, "OEM URL",
3848 info8.manufacturer_url);
3849 if (!W_ERROR_IS_OK(result)) {
3853 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3854 &key_hnd, "HardwareID",
3856 if (!W_ERROR_IS_OK(result)) {
3860 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3861 &key_hnd, "Provider",
3863 if (!W_ERROR_IS_OK(result)) {
3867 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3868 &key_hnd, "Print Processor",
3869 info8.print_processor);
3870 if (!W_ERROR_IS_OK(result)) {
3874 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3875 &key_hnd, "VendorSetup",
3876 info8.vendor_setup);
3877 if (!W_ERROR_IS_OK(result)) {
3881 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3882 &key_hnd, "Color Profiles",
3883 info8.color_profiles);
3884 if (!W_ERROR_IS_OK(result)) {
3888 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3889 &key_hnd, "InfPath",
3891 if (!W_ERROR_IS_OK(result)) {
3895 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe, &key_hnd,
3896 "PrinterDriverAttributes",
3897 info8.printer_driver_attributes);
3898 if (!W_ERROR_IS_OK(result)) {
3902 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3903 &key_hnd, "CoreDependencies",
3904 info8.core_driver_dependencies);
3905 if (!W_ERROR_IS_OK(result)) {
3909 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3910 &key_hnd, "MinInboxDriverVerDate",
3911 info8.min_inbox_driver_ver_date);
3912 if (!W_ERROR_IS_OK(result)) {
3916 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe, &key_hnd,
3917 "MinInboxDriverVerVersion",
3918 info8.min_inbox_driver_ver_version);
3919 if (!W_ERROR_IS_OK(result)) {
3923 *driver_name = info8.driver_name;
3924 *driver_version = info8.version;
3927 if (winreg_pipe != NULL) {
3928 if (is_valid_policy_hnd(&key_hnd)) {
3929 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3931 if (is_valid_policy_hnd(&hive_hnd)) {
3932 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3936 TALLOC_FREE(tmp_ctx);
3940 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
3941 struct auth_serversupplied_info *server_info,
3942 const char *architecture,
3943 const char *driver_name,
3944 uint32_t driver_version,
3945 struct spoolss_DriverInfo8 **_info8)
3947 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3948 struct rpc_pipe_client *winreg_pipe = NULL;
3949 struct policy_handle hive_hnd, key_hnd;
3950 struct spoolss_DriverInfo8 i8, *info8;
3951 struct spoolss_PrinterEnumValues *enum_values = NULL;
3952 struct spoolss_PrinterEnumValues *v;
3953 uint32_t num_values = 0;
3954 TALLOC_CTX *tmp_ctx;
3958 ZERO_STRUCT(hive_hnd);
3959 ZERO_STRUCT(key_hnd);
3962 tmp_ctx = talloc_new(mem_ctx);
3963 if (tmp_ctx == NULL) {
3967 if (driver_version == DRIVER_ANY_VERSION) {
3968 /* look for Win2k first and then for NT4 */
3969 result = winreg_printer_opendriver(tmp_ctx,
3978 if (!W_ERROR_IS_OK(result)) {
3979 result = winreg_printer_opendriver(tmp_ctx,
3990 /* ok normal case */
3991 result = winreg_printer_opendriver(tmp_ctx,
4001 if (!W_ERROR_IS_OK(result)) {
4002 DEBUG(5, ("winreg_get_driver: "
4003 "Could not open driver key (%s,%s,%d): %s\n",
4004 driver_name, architecture,
4005 driver_version, win_errstr(result)));
4009 result = winreg_printer_enumvalues(tmp_ctx,
4014 if (!W_ERROR_IS_OK(result)) {
4015 DEBUG(0, ("winreg_get_driver: "
4016 "Could not enumerate values for (%s,%s,%d): %s\n",
4017 driver_name, architecture,
4018 driver_version, win_errstr(result)));
4022 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
4023 if (info8 == NULL) {
4024 result = WERR_NOMEM;
4028 info8->driver_name = talloc_strdup(info8, driver_name);
4029 if (info8->driver_name == NULL) {
4030 result = WERR_NOMEM;
4034 info8->architecture = talloc_strdup(info8, architecture);
4035 if (info8->architecture == NULL) {
4036 result = WERR_NOMEM;
4042 for (i = 0; i < num_values; i++) {
4043 const char *tmp_str;
4045 v = &enum_values[i];
4047 result = winreg_enumval_to_dword(info8, v,
4050 CHECK_ERROR(result);
4052 result = winreg_enumval_to_sz(info8, v,
4054 &info8->driver_path);
4055 CHECK_ERROR(result);
4057 result = winreg_enumval_to_sz(info8, v,
4060 CHECK_ERROR(result);
4062 result = winreg_enumval_to_sz(info8, v,
4063 "Configuration File",
4064 &info8->config_file);
4065 CHECK_ERROR(result);
4067 result = winreg_enumval_to_sz(info8, v,
4070 CHECK_ERROR(result);
4072 result = winreg_enumval_to_multi_sz(info8, v,
4074 &info8->dependent_files);
4075 CHECK_ERROR(result);
4077 result = winreg_enumval_to_sz(info8, v,
4079 &info8->monitor_name);
4080 CHECK_ERROR(result);
4082 result = winreg_enumval_to_sz(info8, v,
4084 &info8->default_datatype);
4085 CHECK_ERROR(result);
4087 result = winreg_enumval_to_multi_sz(info8, v,
4089 &info8->previous_names);
4090 CHECK_ERROR(result);
4092 result = winreg_enumval_to_sz(info8, v,
4095 if (W_ERROR_IS_OK(result)) {
4096 result = winreg_printer_date_to_NTTIME(tmp_str,
4097 &info8->driver_date);
4099 CHECK_ERROR(result);
4101 result = winreg_enumval_to_sz(info8, v,
4104 if (W_ERROR_IS_OK(result)) {
4105 result = winreg_printer_ver_to_dword(tmp_str,
4106 &info8->driver_version);
4108 CHECK_ERROR(result);
4110 result = winreg_enumval_to_sz(info8, v,
4112 &info8->manufacturer_name);
4113 CHECK_ERROR(result);
4115 result = winreg_enumval_to_sz(info8, v,
4117 &info8->manufacturer_url);
4118 CHECK_ERROR(result);
4120 result = winreg_enumval_to_sz(info8, v,
4122 &info8->hardware_id);
4123 CHECK_ERROR(result);
4125 result = winreg_enumval_to_sz(info8, v,
4128 CHECK_ERROR(result);
4130 result = winreg_enumval_to_sz(info8, v,
4132 &info8->print_processor);
4133 CHECK_ERROR(result);
4135 result = winreg_enumval_to_sz(info8, v,
4137 &info8->vendor_setup);
4138 CHECK_ERROR(result);
4140 result = winreg_enumval_to_multi_sz(info8, v,
4142 &info8->color_profiles);
4143 CHECK_ERROR(result);
4145 result = winreg_enumval_to_sz(info8, v,
4148 CHECK_ERROR(result);
4150 result = winreg_enumval_to_dword(info8, v,
4151 "PrinterDriverAttributes",
4152 &info8->printer_driver_attributes);
4153 CHECK_ERROR(result);
4155 result = winreg_enumval_to_multi_sz(info8, v,
4157 &info8->core_driver_dependencies);
4158 CHECK_ERROR(result);
4160 result = winreg_enumval_to_sz(info8, v,
4161 "MinInboxDriverVerDate",
4163 if (W_ERROR_IS_OK(result)) {
4164 result = winreg_printer_date_to_NTTIME(tmp_str,
4165 &info8->min_inbox_driver_ver_date);
4167 CHECK_ERROR(result);
4169 result = winreg_enumval_to_sz(info8, v,
4170 "MinInboxDriverVerVersion",
4172 if (W_ERROR_IS_OK(result)) {
4173 result = winreg_printer_ver_to_dword(tmp_str,
4174 &info8->min_inbox_driver_ver_version);
4176 CHECK_ERROR(result);
4179 if (!W_ERROR_IS_OK(result)) {
4180 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4181 "for %s: %s\n", v->value_name,
4182 win_errstr(result)));
4186 *_info8 = talloc_steal(mem_ctx, info8);
4189 if (winreg_pipe != NULL) {
4190 if (is_valid_policy_hnd(&key_hnd)) {
4191 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4193 if (is_valid_policy_hnd(&hive_hnd)) {
4194 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4198 TALLOC_FREE(tmp_ctx);
4202 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
4203 struct auth_serversupplied_info *server_info,
4204 struct spoolss_DriverInfo8 *info8,
4207 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4208 struct rpc_pipe_client *winreg_pipe = NULL;
4209 struct policy_handle hive_hnd, key_hnd;
4210 TALLOC_CTX *tmp_ctx;
4214 ZERO_STRUCT(hive_hnd);
4215 ZERO_STRUCT(key_hnd);
4217 tmp_ctx = talloc_new(mem_ctx);
4218 if (tmp_ctx == NULL) {
4222 /* test that the key exists */
4223 result = winreg_printer_opendriver(tmp_ctx,
4226 info8->architecture,
4232 if (!W_ERROR_IS_OK(result)) {
4233 /* key doesn't exist */
4234 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
4239 DEBUG(5, ("winreg_del_driver: "
4240 "Could not open driver (%s,%s,%u): %s\n",
4241 info8->driver_name, info8->architecture,
4242 version, win_errstr(result)));
4247 if (is_valid_policy_hnd(&key_hnd)) {
4248 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4251 key_name = talloc_asprintf(tmp_ctx,
4252 "%s\\Environments\\%s\\Drivers\\Version-%u",
4253 TOP_LEVEL_CONTROL_KEY,
4254 info8->architecture, version);
4255 if (key_name == NULL) {
4256 result = WERR_NOMEM;
4260 result = winreg_printer_delete_subkeys(tmp_ctx,
4265 if (!W_ERROR_IS_OK(result)) {
4266 DEBUG(0, ("winreg_del_driver: "
4267 "Could not open driver (%s,%s,%u): %s\n",
4268 info8->driver_name, info8->architecture,
4269 version, win_errstr(result)));
4275 if (winreg_pipe != NULL) {
4276 if (is_valid_policy_hnd(&key_hnd)) {
4277 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4279 if (is_valid_policy_hnd(&hive_hnd)) {
4280 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4284 TALLOC_FREE(tmp_ctx);
4288 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
4289 struct auth_serversupplied_info *server_info,
4290 const char *architecture,
4292 uint32_t *num_drivers,
4293 const char ***drivers_p)
4295 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4296 struct rpc_pipe_client *winreg_pipe = NULL;
4297 struct policy_handle hive_hnd, key_hnd;
4298 const char **drivers;
4299 TALLOC_CTX *tmp_ctx;
4305 ZERO_STRUCT(hive_hnd);
4306 ZERO_STRUCT(key_hnd);
4308 tmp_ctx = talloc_new(mem_ctx);
4309 if (tmp_ctx == NULL) {
4313 /* use NULL for the driver name so we open the key that is
4314 * parent of all drivers for this architecture and version */
4315 result = winreg_printer_opendriver(tmp_ctx,
4324 if (!W_ERROR_IS_OK(result)) {
4325 DEBUG(5, ("winreg_get_driver_list: "
4326 "Could not open key (%s,%u): %s\n",
4327 architecture, version, win_errstr(result)));
4332 result = winreg_printer_enumkeys(tmp_ctx,
4337 if (!W_ERROR_IS_OK(result)) {
4338 DEBUG(0, ("winreg_get_driver_list: "
4339 "Could not enumerate drivers for (%s,%u): %s\n",
4340 architecture, version, win_errstr(result)));
4344 *drivers_p = talloc_steal(mem_ctx, drivers);
4348 if (winreg_pipe != NULL) {
4349 if (is_valid_policy_hnd(&key_hnd)) {
4350 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4352 if (is_valid_policy_hnd(&hive_hnd)) {
4353 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4357 TALLOC_FREE(tmp_ctx);