2 * Unix SMB/CIFS implementation.
4 * SPOOLSS RPC Pipe server / winreg client routines
6 * Copyright (c) 2010 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "nt_printing.h"
24 #include "srv_spoolss_util.h"
25 #include "../librpc/gen_ndr/ndr_spoolss.h"
26 #include "../librpc/gen_ndr/srv_winreg.h"
27 #include "../librpc/gen_ndr/cli_winreg.h"
28 #include "../librpc/gen_ndr/ndr_security.h"
31 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
32 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
33 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
34 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
36 #define EMPTY_STRING ""
38 #define FILL_STRING(mem_ctx, in, out) \
40 if (in && strlen(in)) { \
41 out = talloc_strdup(mem_ctx, in); \
43 out = talloc_strdup(mem_ctx, ""); \
45 W_ERROR_HAVE_NO_MEMORY(out); \
48 #define CHECK_ERROR(result) \
49 if (W_ERROR_IS_OK(result)) continue; \
50 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
51 if (!W_ERROR_IS_OK(result)) break
53 /* FLAGS, NAME, with, height, left, top, right, bottom */
54 static const struct spoolss_FormInfo1 builtin_forms1[] = {
55 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
56 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
57 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
58 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
59 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
60 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
61 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
62 { SPOOLSS_FORM_BUILTIN, "A0", {0xcd528,0x122488},{0x0,0x0,0xcd528,0x122488} },
63 { SPOOLSS_FORM_BUILTIN, "A1", {0x91050,0xcd528}, {0x0,0x0,0x91050,0xcd528} },
64 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
65 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
66 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
67 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
68 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
69 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
70 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
71 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
72 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
73 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
74 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
75 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
76 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
77 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
78 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
79 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
80 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
81 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
82 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
83 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
84 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
85 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
86 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
87 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
88 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
89 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
90 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
91 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
92 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
93 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
94 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
95 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
96 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
97 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
98 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
99 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
100 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
101 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
102 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
103 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
104 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
105 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
106 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
107 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
108 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
109 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
110 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
111 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
112 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
113 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
114 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
115 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
116 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
117 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
118 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
119 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
120 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
121 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
122 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
123 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
124 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
125 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
126 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
127 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
128 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
129 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
130 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
131 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
132 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
133 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
134 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
135 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
136 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
137 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
138 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
139 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
140 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
141 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
142 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
143 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
144 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
145 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
146 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
147 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
148 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} },
149 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
150 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
151 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
152 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
153 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
154 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
159 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
160 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
161 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
162 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
163 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
164 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
165 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
166 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
167 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
168 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
169 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
170 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
171 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
172 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
173 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
174 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} }
177 /********************************************************************
178 static helper functions
179 ********************************************************************/
181 /****************************************************************************
182 Update the changeid time.
183 ****************************************************************************/
187 * @brief Update the ChangeID time of a printer.
189 * This is SO NASTY as some drivers need this to change, others need it
190 * static. This value will change every second, and I must hope that this
191 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
194 * @return The ChangeID.
196 static uint32_t winreg_printer_rev_changeid(void)
200 get_process_uptime(&tv);
203 /* Return changeid as msec since spooler restart */
204 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
207 * This setting seems to work well but is too untested
208 * to replace the above calculation. Left in for experiementation
209 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
211 return tv.tv_sec * 10 + tv.tv_usec / 100000;
218 * @brief Connect to the interal winreg server and open the given printer key.
220 * The function will create the needed subkeys if they don't exist.
222 * @param[in] mem_ctx The memory context to use.
224 * @param[in] server_info The supplied server info.
226 * @param[out] winreg_pipe A pointer for the winreg rpc client pipe.
228 * @param[in] path The path to the key to open.
230 * @param[in] key The key to open.
232 * @param[in] create_key Set to true if the key should be created if it
235 * @param[in] access_mask The access mask to open the key.
237 * @param[out] hive_handle A policy handle for the opened hive.
239 * @param[out] key_handle A policy handle for the opened key.
241 * @return WERR_OK on success, the corresponding DOS error
242 * code if something gone wrong.
244 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
245 struct auth_serversupplied_info *server_info,
246 struct rpc_pipe_client **winreg_pipe,
250 uint32_t access_mask,
251 struct policy_handle *hive_handle,
252 struct policy_handle *key_handle)
254 struct rpc_pipe_client *pipe_handle;
255 struct winreg_String wkey, wkeyclass;
258 WERROR result = WERR_OK;
260 /* create winreg connection */
261 status = rpc_pipe_open_internal(mem_ctx,
262 &ndr_table_winreg.syntax_id,
265 if (!NT_STATUS_IS_OK(status)) {
266 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg_pipe: %s\n",
268 return ntstatus_to_werror(status);
271 status = rpccli_winreg_OpenHKLM(pipe_handle,
277 if (!NT_STATUS_IS_OK(status)) {
278 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
280 talloc_free(pipe_handle);
281 if (!W_ERROR_IS_OK(result)) {
284 return ntstatus_to_werror(status);
288 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
290 keyname = talloc_strdup(mem_ctx, path);
292 if (keyname == NULL) {
293 talloc_free(pipe_handle);
301 enum winreg_CreateAction action = REG_ACTION_NONE;
303 ZERO_STRUCT(wkeyclass);
306 status = rpccli_winreg_CreateKey(pipe_handle,
318 case REG_ACTION_NONE:
319 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
321 case REG_CREATED_NEW_KEY:
322 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
324 case REG_OPENED_EXISTING_KEY:
325 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
329 status = rpccli_winreg_OpenKey(pipe_handle,
338 if (!NT_STATUS_IS_OK(status)) {
339 talloc_free(pipe_handle);
340 if (!W_ERROR_IS_OK(result)) {
343 return ntstatus_to_werror(status);
346 *winreg_pipe = pipe_handle;
352 * @brief Create the registry keyname for the given printer.
354 * @param[in] mem_ctx The memory context to use.
356 * @param[in] printer The name of the printer to get the registry key.
358 * @return The registry key or NULL on error.
360 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
361 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
367 * @brief Enumerate values of an opened key handle and retrieve the data.
369 * @param[in] mem_ctx The memory context to use.
371 * @param[in] pipe_handle The pipe handle for the rpc connection.
373 * @param[in] key_hnd The opened key handle.
375 * @param[out] pnum_values A pointer to store he number of values found.
377 * @param[out] pnum_values A pointer to store the number of values we found.
379 * @return WERR_OK on success, the corresponding DOS error
380 * code if something gone wrong.
382 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
383 struct rpc_pipe_client *pipe_handle,
384 struct policy_handle *key_hnd,
385 uint32_t *pnum_values,
386 struct spoolss_PrinterEnumValues **penum_values)
389 uint32_t num_subkeys, max_subkeylen, max_classlen;
390 uint32_t num_values, max_valnamelen, max_valbufsize;
391 uint32_t secdescsize;
393 NTTIME last_changed_time;
394 struct winreg_String classname;
396 struct spoolss_PrinterEnumValues *enum_values;
398 WERROR result = WERR_OK;
401 tmp_ctx = talloc_stackframe();
402 if (tmp_ctx == NULL) {
406 ZERO_STRUCT(classname);
408 status = rpccli_winreg_QueryInfoKey(pipe_handle,
421 if (!NT_STATUS_IS_OK(status)) {
422 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
424 if (!W_ERROR_IS_OK(result)) {
427 result = ntstatus_to_werror(status);
431 if (num_values == 0) {
433 TALLOC_FREE(tmp_ctx);
437 enum_values = TALLOC_ARRAY(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
438 if (enum_values == NULL) {
443 for (i = 0; i < num_values; i++) {
444 struct spoolss_PrinterEnumValues val;
445 struct winreg_ValNameBuf name_buf;
446 enum winreg_Type type = REG_NONE;
453 name_buf.size = max_valnamelen + 2;
456 data_size = max_valbufsize;
459 data = (uint8_t *) TALLOC(tmp_ctx, data_size);
463 status = rpccli_winreg_EnumValue(pipe_handle,
470 data_size ? &data_size : NULL,
473 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
475 status = NT_STATUS_OK;
479 if (!NT_STATUS_IS_OK(status)) {
480 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
482 if (!W_ERROR_IS_OK(result)) {
485 result = ntstatus_to_werror(status);
489 if (name_buf.name == NULL) {
490 result = WERR_INVALID_PARAMETER;
494 val.value_name = talloc_strdup(enum_values, name_buf.name);
495 if (val.value_name == NULL) {
499 val.value_name_len = strlen_m_term(val.value_name) * 2;
502 val.data_length = length;
504 if (val.data_length) {
505 val.data = talloc(enum_values, DATA_BLOB);
506 if (val.data == NULL) {
510 *val.data = data_blob_talloc(val.data, data, val.data_length);
513 enum_values[i] = val;
516 *pnum_values = num_values;
518 *penum_values = talloc_move(mem_ctx, &enum_values);
524 TALLOC_FREE(tmp_ctx);
531 * @brief Enumerate subkeys of an opened key handle and get the names.
533 * @param[in] mem_ctx The memory context to use.
535 * @param[in] pipe_handle The pipe handle for the rpc connection.
537 * @param[in] key_hnd The opened key handle.
539 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
541 * @param[in] psubkeys A pointer to an array to store the found names of
544 * @return WERR_OK on success, the corresponding DOS error
545 * code if something gone wrong.
547 static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
548 struct rpc_pipe_client *pipe_handle,
549 struct policy_handle *key_hnd,
550 uint32_t *pnum_subkeys,
551 const char ***psubkeys)
554 const char **subkeys;
555 uint32_t num_subkeys, max_subkeylen, max_classlen;
556 uint32_t num_values, max_valnamelen, max_valbufsize;
558 NTTIME last_changed_time;
559 uint32_t secdescsize;
560 struct winreg_String classname;
561 WERROR result = WERR_OK;
564 tmp_ctx = talloc_stackframe();
565 if (tmp_ctx == NULL) {
569 ZERO_STRUCT(classname);
571 status = rpccli_winreg_QueryInfoKey(pipe_handle,
584 if (!NT_STATUS_IS_OK(status)) {
585 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
587 if (!W_ERROR_IS_OK(result)) {
590 result = ntstatus_to_werror(status);
594 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
595 if (subkeys == NULL) {
600 if (num_subkeys == 0) {
601 subkeys[0] = talloc_strdup(subkeys, "");
602 if (subkeys[0] == NULL) {
608 *psubkeys = talloc_move(mem_ctx, &subkeys);
611 TALLOC_FREE(tmp_ctx);
615 for (i = 0; i < num_subkeys; i++) {
619 struct winreg_StringBuf class_buf;
620 struct winreg_StringBuf name_buf;
624 class_buf.size = max_classlen + 2;
625 class_buf.length = 0;
628 name_buf.size = max_subkeylen + 2;
631 ZERO_STRUCT(modtime);
633 status = rpccli_winreg_EnumKey(pipe_handle,
641 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
643 status = NT_STATUS_OK;
647 if (!NT_STATUS_IS_OK(status)) {
648 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
650 if (!W_ERROR_IS_OK(result)) {
653 result = ntstatus_to_werror(status);
657 if (name_buf.name == NULL) {
658 result = WERR_INVALID_PARAMETER;
662 name = talloc_strdup(subkeys, name_buf.name);
671 *pnum_subkeys = num_subkeys;
673 *psubkeys = talloc_move(mem_ctx, &subkeys);
677 TALLOC_FREE(tmp_ctx);
684 * @brief A function to delete a key and its subkeys recurively.
686 * @param[in] mem_ctx The memory context to use.
688 * @param[in] pipe_handle The pipe handle for the rpc connection.
690 * @param[in] hive_handle A opened hive handle to the key.
692 * @param[in] access_mask The access mask to access the key.
694 * @param[in] key The key to delete
696 * @return WERR_OK on success, the corresponding DOS error
697 * code if something gone wrong.
699 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
700 struct rpc_pipe_client *pipe_handle,
701 struct policy_handle *hive_handle,
702 uint32_t access_mask,
705 const char **subkeys = NULL;
706 uint32_t num_subkeys = 0;
707 struct policy_handle key_hnd;
708 struct winreg_String wkey;
709 WERROR result = WERR_OK;
713 ZERO_STRUCT(key_hnd);
716 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
718 status = rpccli_winreg_OpenKey(pipe_handle,
726 if (!NT_STATUS_IS_OK(status)) {
727 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
728 wkey.name, nt_errstr(status)));
729 if (!W_ERROR_IS_OK(result)) {
732 return ntstatus_to_werror(status);
735 result = winreg_printer_enumkeys(mem_ctx,
740 if (!W_ERROR_IS_OK(result)) {
744 for (i = 0; i < num_subkeys; i++) {
745 /* create key + subkey */
746 char *subkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkeys[i]);
747 if (subkey == NULL) {
751 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey));
752 result = winreg_printer_delete_subkeys(mem_ctx,
757 if (!W_ERROR_IS_OK(result)) {
762 if (is_valid_policy_hnd(&key_hnd)) {
763 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
768 status = rpccli_winreg_DeleteKey(pipe_handle,
775 if (is_valid_policy_hnd(&key_hnd)) {
776 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
782 static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
783 struct rpc_pipe_client *pipe_handle,
784 struct policy_handle *key_handle,
788 struct winreg_String wvalue;
790 WERROR result = WERR_OK;
795 blob = data_blob_string_const("");
797 if (!push_reg_sz(mem_ctx, &blob, data)) {
798 DEBUG(0, ("winreg_printer_write_sz: Could not marshall string %s for %s\n",
803 status = rpccli_winreg_SetValue(pipe_handle,
811 if (!NT_STATUS_IS_OK(status)) {
812 DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: %s\n",
813 wvalue.name, win_errstr(result)));
814 if (!W_ERROR_IS_OK(result)) {
815 result = ntstatus_to_werror(status);
822 static WERROR winreg_printer_write_dword(TALLOC_CTX *mem_ctx,
823 struct rpc_pipe_client *pipe_handle,
824 struct policy_handle *key_handle,
828 struct winreg_String wvalue;
830 WERROR result = WERR_OK;
834 blob = data_blob_talloc(mem_ctx, NULL, 4);
835 SIVAL(blob.data, 0, data);
837 status = rpccli_winreg_SetValue(pipe_handle,
845 if (!NT_STATUS_IS_OK(status)) {
846 DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: %s\n",
847 wvalue.name, win_errstr(result)));
848 if (!W_ERROR_IS_OK(result)) {
849 result = ntstatus_to_werror(status);
856 static WERROR winreg_printer_write_binary(TALLOC_CTX *mem_ctx,
857 struct rpc_pipe_client *pipe_handle,
858 struct policy_handle *key_handle,
862 struct winreg_String wvalue;
863 WERROR result = WERR_OK;
867 status = rpccli_winreg_SetValue(pipe_handle,
875 if (!NT_STATUS_IS_OK(status)) {
876 DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: %s\n",
877 wvalue.name, win_errstr(result)));
878 if (!W_ERROR_IS_OK(result)) {
879 result = ntstatus_to_werror(status);
886 static WERROR winreg_printer_query_binary(TALLOC_CTX *mem_ctx,
887 struct rpc_pipe_client *pipe_handle,
888 struct policy_handle *key_handle,
892 struct winreg_String wvalue;
893 enum winreg_Type type;
894 WERROR result = WERR_OK;
895 uint32_t value_len = 0;
896 uint32_t data_size = 0;
901 status = rpccli_winreg_QueryValue(pipe_handle,
910 if (!NT_STATUS_IS_OK(status)) {
911 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
912 wvalue.name, nt_errstr(status)));
913 if (!W_ERROR_IS_OK(result)) {
916 result = ntstatus_to_werror(status);
920 if (type != REG_BINARY) {
921 result = WERR_INVALID_DATATYPE;
924 blob = data_blob_talloc(mem_ctx, NULL, data_size);
925 if (blob.data == NULL) {
931 status = rpccli_winreg_QueryValue(pipe_handle,
940 if (!NT_STATUS_IS_OK(status)) {
941 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
942 wvalue.name, nt_errstr(status)));
943 if (!W_ERROR_IS_OK(result)) {
944 result = ntstatus_to_werror(status);
950 data->data = blob.data;
951 data->length = blob.length;
957 static WERROR winreg_printer_query_dword(TALLOC_CTX *mem_ctx,
958 struct rpc_pipe_client *pipe_handle,
959 struct policy_handle *key_handle,
963 struct winreg_String wvalue;
964 enum winreg_Type type;
965 WERROR result = WERR_OK;
966 uint32_t value_len = 0;
967 uint32_t data_size = 0;
972 status = rpccli_winreg_QueryValue(pipe_handle,
981 if (!NT_STATUS_IS_OK(status)) {
982 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
983 wvalue.name, nt_errstr(status)));
984 if (!W_ERROR_IS_OK(result)) {
987 result = ntstatus_to_werror(status);
991 if (type != REG_DWORD) {
992 result = WERR_INVALID_DATATYPE;
996 if (data_size != 4) {
997 result = WERR_INVALID_DATA;
1001 blob = data_blob_talloc(mem_ctx, NULL, data_size);
1002 if (blob.data == NULL) {
1003 result = WERR_NOMEM;
1008 status = rpccli_winreg_QueryValue(pipe_handle,
1017 if (!NT_STATUS_IS_OK(status)) {
1018 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1019 wvalue.name, nt_errstr(status)));
1020 if (!W_ERROR_IS_OK(result)) {
1021 result = ntstatus_to_werror(status);
1027 *data = IVAL(blob.data, 0);
1033 static WERROR winreg_printer_write_multi_sz(TALLOC_CTX *mem_ctx,
1034 struct rpc_pipe_client *pipe_handle,
1035 struct policy_handle *key_handle,
1039 struct winreg_String wvalue;
1041 WERROR result = WERR_OK;
1044 wvalue.name = value;
1045 if (!push_reg_multi_sz(mem_ctx, &blob, data)) {
1048 status = rpccli_winreg_SetValue(pipe_handle,
1056 if (!NT_STATUS_IS_OK(status)) {
1057 DEBUG(0, ("winreg_printer_write_multi_sz: Could not set value %s: %s\n",
1058 wvalue.name, win_errstr(result)));
1059 if (!W_ERROR_IS_OK(result)) {
1060 result = ntstatus_to_werror(status);
1067 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
1068 struct auth_serversupplied_info *server_info,
1069 const char *drivername,
1070 const char *architecture,
1072 uint32_t access_mask,
1074 struct rpc_pipe_client **winreg_pipe,
1075 struct policy_handle *hive_hnd,
1076 struct policy_handle *key_hnd)
1081 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
1082 TOP_LEVEL_CONTROL_KEY,
1083 architecture, version);
1088 result = winreg_printer_openkey(mem_ctx,
1100 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
1101 struct spoolss_PrinterEnumValues *v,
1102 const char *valuename, uint32_t *dw)
1104 /* just return if it is not the one we are looking for */
1105 if (strcmp(valuename, v->value_name) != 0) {
1106 return WERR_NOT_FOUND;
1109 if (v->type != REG_DWORD) {
1110 return WERR_INVALID_DATATYPE;
1113 if (v->data_length != 4) {
1118 *dw = IVAL(v->data->data, 0);
1122 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
1123 struct spoolss_PrinterEnumValues *v,
1124 const char *valuename, const char **_str)
1126 /* just return if it is not the one we are looking for */
1127 if (strcmp(valuename, v->value_name) != 0) {
1128 return WERR_NOT_FOUND;
1131 if (v->type != REG_SZ) {
1132 return WERR_INVALID_DATATYPE;
1135 if (v->data_length == 0) {
1136 *_str = talloc_strdup(mem_ctx, EMPTY_STRING);
1137 if (*_str == NULL) {
1143 if (!pull_reg_sz(mem_ctx, v->data, _str)) {
1150 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
1151 struct spoolss_PrinterEnumValues *v,
1152 const char *valuename,
1153 const char ***array)
1155 /* just return if it is not the one we are looking for */
1156 if (strcmp(valuename, v->value_name) != 0) {
1157 return WERR_NOT_FOUND;
1160 if (v->type != REG_MULTI_SZ) {
1161 return WERR_INVALID_DATATYPE;
1164 if (v->data_length == 0) {
1165 *array = talloc_array(mem_ctx, const char *, 1);
1166 if (*array == NULL) {
1173 if (!pull_reg_multi_sz(mem_ctx, v->data, array)) {
1180 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
1181 struct rpc_pipe_client *pipe_handle,
1182 struct policy_handle *key_handle,
1186 struct winreg_String wvalue;
1188 WERROR result = WERR_OK;
1194 t = nt_time_to_unix(data);
1196 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
1197 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
1202 wvalue.name = value;
1203 if (!push_reg_sz(mem_ctx, &blob, str)) {
1206 status = rpccli_winreg_SetValue(pipe_handle,
1214 if (!NT_STATUS_IS_OK(status)) {
1215 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1216 wvalue.name, win_errstr(result)));
1217 if (!W_ERROR_IS_OK(result)) {
1218 result = ntstatus_to_werror(status);
1225 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
1232 if (sscanf(str, "%d/%d/%d",
1233 &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3) {
1234 return WERR_INVALID_PARAMETER;
1241 unix_to_nt_time(data, t);
1246 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
1247 struct rpc_pipe_client *pipe_handle,
1248 struct policy_handle *key_handle,
1252 struct winreg_String wvalue;
1254 WERROR result = WERR_OK;
1258 /* FIXME: check format is right,
1259 * this needs to be something like: 6.1.7600.16385 */
1260 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
1261 (unsigned)((data >> 48) & 0xFFFF),
1262 (unsigned)((data >> 32) & 0xFFFF),
1263 (unsigned)((data >> 16) & 0xFFFF),
1264 (unsigned)(data & 0xFFFF));
1269 wvalue.name = value;
1270 if (!push_reg_sz(mem_ctx, &blob, str)) {
1273 status = rpccli_winreg_SetValue(pipe_handle,
1281 if (!NT_STATUS_IS_OK(status)) {
1282 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1283 wvalue.name, win_errstr(result)));
1284 if (!W_ERROR_IS_OK(result)) {
1285 result = ntstatus_to_werror(status);
1292 static WERROR winreg_printer_ver_to_dword(const char *str, uint64_t *data)
1294 unsigned int v1, v2, v3, v4;
1296 if (sscanf(str, "%u.%u.%u.%u", &v1, &v2, &v3, &v4) != 4) {
1297 return WERR_INVALID_PARAMETER;
1300 *data = ((uint64_t)(v1 & 0xFFFF) << 48) +
1301 ((uint64_t)(v2 & 0xFFFF) << 32) +
1302 ((uint64_t)(v3 & 0xFFFF) << 16) +
1303 (uint64_t)(v2 & 0xFFFF);
1308 /********************************************************************
1309 Public winreg function for spoolss
1310 ********************************************************************/
1312 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
1313 struct auth_serversupplied_info *server_info,
1314 const char *servername,
1315 const char *sharename)
1317 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1318 struct rpc_pipe_client *winreg_pipe = NULL;
1319 struct policy_handle hive_hnd, key_hnd;
1320 struct spoolss_SetPrinterInfo2 *info2;
1321 struct security_descriptor *secdesc;
1322 struct winreg_String wkey, wkeyclass;
1324 const char *subkeys[] = { SPOOL_DSDRIVER_KEY, SPOOL_DSSPOOLER_KEY, SPOOL_PRINTERDATA_KEY };
1325 uint32_t i, count = ARRAY_SIZE(subkeys);
1326 uint32_t info2_mask = 0;
1327 WERROR result = WERR_OK;
1328 TALLOC_CTX *tmp_ctx;
1330 tmp_ctx = talloc_stackframe();
1331 if (tmp_ctx == NULL) {
1335 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1337 TALLOC_FREE(tmp_ctx);
1341 ZERO_STRUCT(hive_hnd);
1342 ZERO_STRUCT(key_hnd);
1344 result = winreg_printer_openkey(tmp_ctx,
1353 if (W_ERROR_IS_OK(result)) {
1354 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
1356 } else if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1357 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
1358 } else if (!W_ERROR_IS_OK(result)) {
1359 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
1360 path, win_errstr(result)));
1364 /* Create the main key */
1365 result = winreg_printer_openkey(tmp_ctx,
1374 if (!W_ERROR_IS_OK(result)) {
1375 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1376 path, win_errstr(result)));
1380 if (is_valid_policy_hnd(&key_hnd)) {
1381 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1384 /* Create subkeys */
1385 for (i = 0; i < count; i++) {
1387 enum winreg_CreateAction action = REG_ACTION_NONE;
1389 ZERO_STRUCT(key_hnd);
1392 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
1393 if (wkey.name == NULL) {
1394 result = WERR_NOMEM;
1398 ZERO_STRUCT(wkeyclass);
1399 wkeyclass.name = "";
1401 status = rpccli_winreg_CreateKey(winreg_pipe,
1412 if (!NT_STATUS_IS_OK(status)) {
1413 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1414 wkey.name, win_errstr(result)));
1415 if (!W_ERROR_IS_OK(result)) {
1416 result = ntstatus_to_werror(status);
1423 const char *dnssuffix;
1424 const char *longname;
1425 const char *uncname;
1427 result = winreg_printer_write_sz(tmp_ctx,
1430 SPOOL_REG_PRINTERNAME,
1432 if (!W_ERROR_IS_OK(result)) {
1436 result = winreg_printer_write_sz(tmp_ctx,
1439 SPOOL_REG_SHORTSERVERNAME,
1441 if (!W_ERROR_IS_OK(result)) {
1445 /* We make the assumption that the netbios name
1446 * is the same as the DNS name since the former
1447 * will be what we used to join the domain
1449 dnssuffix = get_mydnsdomname(tmp_ctx);
1450 if (dnssuffix != NULL && dnssuffix[0] != '\0') {
1451 longname = talloc_asprintf(tmp_ctx, "%s.%s", global_myname(), dnssuffix);
1453 longname = talloc_strdup(tmp_ctx, global_myname());
1455 if (longname == NULL) {
1456 result = WERR_NOMEM;
1460 result = winreg_printer_write_sz(tmp_ctx,
1463 SPOOL_REG_SERVERNAME,
1465 if (!W_ERROR_IS_OK(result)) {
1469 uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
1470 longname, sharename);
1471 if (uncname == NULL) {
1472 result = WERR_NOMEM;
1476 result = winreg_printer_write_sz(tmp_ctx,
1481 if (!W_ERROR_IS_OK(result)) {
1485 result = winreg_printer_write_dword(tmp_ctx,
1488 SPOOL_REG_VERSIONNUMBER,
1490 if (!W_ERROR_IS_OK(result)) {
1494 result = winreg_printer_write_dword(tmp_ctx,
1497 SPOOL_REG_PRINTSTARTTIME,
1499 if (!W_ERROR_IS_OK(result)) {
1503 result = winreg_printer_write_dword(tmp_ctx,
1506 SPOOL_REG_PRINTENDTIME,
1508 if (!W_ERROR_IS_OK(result)) {
1512 result = winreg_printer_write_dword(tmp_ctx,
1517 if (!W_ERROR_IS_OK(result)) {
1521 result = winreg_printer_write_dword(tmp_ctx,
1524 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
1526 if (!W_ERROR_IS_OK(result)) {
1534 if (is_valid_policy_hnd(&key_hnd)) {
1535 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1538 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
1539 if (info2 == NULL) {
1540 result = WERR_NOMEM;
1544 if (servername != NULL) {
1545 info2->printername = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
1546 servername, sharename);
1548 info2->printername = sharename;
1550 if (info2->printername == NULL) {
1551 result = WERR_NOMEM;
1554 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1556 info2->sharename = sharename;
1557 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1559 info2->portname = SAMBA_PRINTER_PORT_NAME;
1560 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1562 info2->printprocessor = "winprint";
1563 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1565 info2->datatype = "RAW";
1566 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1568 info2->comment = "";
1569 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1571 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1572 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1574 info2->starttime = 0; /* Minutes since 12:00am GMT */
1575 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1577 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1578 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1580 info2->priority = 1;
1581 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1583 info2->defaultpriority = 1;
1584 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1586 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1587 if (!W_ERROR_IS_OK(result)) {
1590 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1593 * Don't write a default Device Mode to the registry! The Device Mode is
1594 * only written to disk with a SetPrinter level 2 or 8.
1597 result = winreg_update_printer(tmp_ctx,
1606 if (winreg_pipe != NULL) {
1607 if (is_valid_policy_hnd(&key_hnd)) {
1608 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1610 if (is_valid_policy_hnd(&hive_hnd)) {
1611 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1615 talloc_free(tmp_ctx);
1619 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1620 struct auth_serversupplied_info *server_info,
1621 const char *sharename,
1622 uint32_t info2_mask,
1623 struct spoolss_SetPrinterInfo2 *info2,
1624 struct spoolss_DeviceMode *devmode,
1625 struct security_descriptor *secdesc)
1627 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1628 struct rpc_pipe_client *winreg_pipe = NULL;
1629 struct policy_handle hive_hnd, key_hnd;
1630 int snum = lp_servicenumber(sharename);
1631 enum ndr_err_code ndr_err;
1634 WERROR result = WERR_OK;
1635 TALLOC_CTX *tmp_ctx;
1637 tmp_ctx = talloc_stackframe();
1638 if (tmp_ctx == NULL) {
1642 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1644 TALLOC_FREE(tmp_ctx);
1648 ZERO_STRUCT(hive_hnd);
1649 ZERO_STRUCT(key_hnd);
1651 result = winreg_printer_openkey(tmp_ctx,
1660 if (!W_ERROR_IS_OK(result)) {
1661 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1662 path, win_errstr(result)));
1666 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1667 result = winreg_printer_write_dword(tmp_ctx,
1672 if (!W_ERROR_IS_OK(result)) {
1678 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1679 result = winreg_printer_write_dword(tmp_ctx,
1684 if (!W_ERROR_IS_OK(result)) {
1690 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1691 result = winreg_printer_write_sz(tmp_ctx,
1696 if (!W_ERROR_IS_OK(result)) {
1701 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1702 result = winreg_printer_write_sz(tmp_ctx,
1707 if (!W_ERROR_IS_OK(result)) {
1712 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1713 result = winreg_printer_write_dword(tmp_ctx,
1717 info2->defaultpriority);
1718 if (!W_ERROR_IS_OK(result)) {
1723 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1725 * Some client drivers freak out if there is a NULL devmode
1726 * (probably the driver is not checking before accessing
1727 * the devmode pointer) --jerry
1729 if (devmode == NULL && lp_default_devmode(snum) && info2 != NULL) {
1730 result = spoolss_create_default_devmode(tmp_ctx,
1733 if (!W_ERROR_IS_OK(result)) {
1737 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, devmode,
1738 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1739 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1740 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1741 result = WERR_NOMEM;
1745 result = winreg_printer_write_binary(tmp_ctx,
1750 if (!W_ERROR_IS_OK(result)) {
1755 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1756 result = winreg_printer_write_sz(tmp_ctx,
1761 if (!W_ERROR_IS_OK(result)) {
1766 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1767 result = winreg_printer_write_sz(tmp_ctx,
1772 if (!W_ERROR_IS_OK(result)) {
1777 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1778 result = winreg_printer_write_sz(tmp_ctx,
1783 if (!W_ERROR_IS_OK(result)) {
1788 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1789 result = winreg_printer_write_sz(tmp_ctx,
1794 if (!W_ERROR_IS_OK(result)) {
1799 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1801 * in addprinter: no servername and the printer is the name
1802 * in setprinter: servername is \\server
1803 * and printer is \\server\\printer
1805 * Samba manages only local printers.
1806 * we currently don't support things like i
1807 * path=\\other_server\printer
1809 * We only store the printername, not \\server\printername
1811 const char *p = strrchr(info2->printername, '\\');
1813 p = info2->printername;
1817 result = winreg_printer_write_sz(tmp_ctx,
1822 if (!W_ERROR_IS_OK(result)) {
1827 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1828 result = winreg_printer_write_sz(tmp_ctx,
1832 info2->printprocessor);
1833 if (!W_ERROR_IS_OK(result)) {
1838 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1839 result = winreg_printer_write_dword(tmp_ctx,
1844 if (!W_ERROR_IS_OK(result)) {
1849 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1851 * We need a security descriptor, if it isn't specified by
1852 * AddPrinter{Ex} then create a default descriptor.
1854 if (secdesc == NULL) {
1855 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
1856 if (!W_ERROR_IS_OK(result)) {
1860 result = winreg_set_printer_secdesc(tmp_ctx,
1864 if (!W_ERROR_IS_OK(result)) {
1869 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1870 result = winreg_printer_write_sz(tmp_ctx,
1875 if (!W_ERROR_IS_OK(result)) {
1880 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1881 result = winreg_printer_write_sz(tmp_ctx,
1886 if (!W_ERROR_IS_OK(result)) {
1891 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1892 result = winreg_printer_write_dword(tmp_ctx,
1897 if (!W_ERROR_IS_OK(result)) {
1902 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1903 result = winreg_printer_write_dword(tmp_ctx,
1908 if (!W_ERROR_IS_OK(result)) {
1913 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1914 result = winreg_printer_write_dword(tmp_ctx,
1919 if (!W_ERROR_IS_OK(result)) {
1924 result = winreg_printer_write_dword(tmp_ctx,
1928 winreg_printer_rev_changeid());
1929 if (!W_ERROR_IS_OK(result)) {
1935 if (winreg_pipe != NULL) {
1936 if (is_valid_policy_hnd(&key_hnd)) {
1937 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1939 if (is_valid_policy_hnd(&hive_hnd)) {
1940 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1944 TALLOC_FREE(tmp_ctx);
1948 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1949 struct auth_serversupplied_info *server_info,
1950 const char *servername,
1951 const char *printer,
1952 struct spoolss_PrinterInfo2 **pinfo2)
1954 struct spoolss_PrinterInfo2 *info2;
1955 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1956 struct rpc_pipe_client *winreg_pipe = NULL;
1957 struct policy_handle hive_hnd, key_hnd;
1958 struct spoolss_PrinterEnumValues *enum_values = NULL;
1959 struct spoolss_PrinterEnumValues *v;
1960 enum ndr_err_code ndr_err;
1962 int snum = lp_servicenumber(printer);
1963 uint32_t num_values = 0;
1966 WERROR result = WERR_OK;
1967 TALLOC_CTX *tmp_ctx;
1969 tmp_ctx = talloc_stackframe();
1970 if (tmp_ctx == NULL) {
1974 path = winreg_printer_data_keyname(tmp_ctx, printer);
1976 TALLOC_FREE(tmp_ctx);
1980 result = winreg_printer_openkey(tmp_ctx,
1989 if (!W_ERROR_IS_OK(result)) {
1990 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
1991 path, win_errstr(result)));
1995 result = winreg_printer_enumvalues(tmp_ctx,
2000 if (!W_ERROR_IS_OK(result)) {
2001 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
2002 path, win_errstr(result)));
2006 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
2007 if (info2 == NULL) {
2008 result = WERR_NOMEM;
2012 FILL_STRING(info2, EMPTY_STRING, info2->servername);
2013 FILL_STRING(info2, EMPTY_STRING, info2->printername);
2014 FILL_STRING(info2, EMPTY_STRING, info2->sharename);
2015 FILL_STRING(info2, EMPTY_STRING, info2->portname);
2016 FILL_STRING(info2, EMPTY_STRING, info2->drivername);
2017 FILL_STRING(info2, EMPTY_STRING, info2->comment);
2018 FILL_STRING(info2, EMPTY_STRING, info2->location);
2019 FILL_STRING(info2, EMPTY_STRING, info2->sepfile);
2020 FILL_STRING(info2, EMPTY_STRING, info2->printprocessor);
2021 FILL_STRING(info2, EMPTY_STRING, info2->datatype);
2022 FILL_STRING(info2, EMPTY_STRING, info2->parameters);
2024 if (servername != NULL && servername[0] != '\0') {
2025 info2->servername = talloc_asprintf(info2, "\\\\%s", servername);
2026 if (info2->servername == NULL) {
2027 result = WERR_NOMEM;
2032 for (i = 0; i < num_values; i++) {
2033 v = &enum_values[i];
2035 result = winreg_enumval_to_sz(info2,
2038 &info2->printername);
2039 CHECK_ERROR(result);
2041 result = winreg_enumval_to_sz(info2,
2045 CHECK_ERROR(result);
2047 result = winreg_enumval_to_sz(info2,
2051 CHECK_ERROR(result);
2053 result = winreg_enumval_to_sz(info2,
2057 CHECK_ERROR(result);
2059 result = winreg_enumval_to_sz(info2,
2063 CHECK_ERROR(result);
2065 result = winreg_enumval_to_sz(info2,
2069 CHECK_ERROR(result);
2071 result = winreg_enumval_to_sz(info2,
2074 &info2->printprocessor);
2075 CHECK_ERROR(result);
2077 result = winreg_enumval_to_sz(info2,
2081 CHECK_ERROR(result);
2083 result = winreg_enumval_to_sz(info2,
2086 &info2->parameters);
2087 CHECK_ERROR(result);
2089 result = winreg_enumval_to_sz(info2,
2092 &info2->drivername);
2093 CHECK_ERROR(result);
2095 result = winreg_enumval_to_dword(info2,
2098 &info2->attributes);
2099 CHECK_ERROR(result);
2101 result = winreg_enumval_to_dword(info2,
2105 CHECK_ERROR(result);
2107 result = winreg_enumval_to_dword(info2,
2110 &info2->defaultpriority);
2111 CHECK_ERROR(result);
2113 result = winreg_enumval_to_dword(info2,
2117 CHECK_ERROR(result);
2119 result = winreg_enumval_to_dword(info2,
2123 CHECK_ERROR(result);
2125 result = winreg_enumval_to_dword(info2,
2129 CHECK_ERROR(result);
2131 result = winreg_enumval_to_dword(info2,
2135 CHECK_ERROR(result);
2138 if (!W_ERROR_IS_OK(result)) {
2139 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2142 win_errstr(result)));
2146 /* Create the printername */
2147 if (info2->servername != NULL && info2->servername[0] != '\0') {
2148 if (lp_force_printername(snum)) {
2149 const char *p = talloc_asprintf(info2, "%s\\%s",
2153 result = WERR_NOMEM;
2156 info2->printername = p;
2158 char *p = talloc_asprintf(info2, "%s\\%s",
2160 info2->printername);
2162 result = WERR_NOMEM;
2165 info2->printername = p;
2169 /* Construct the Device Mode */
2170 result = winreg_printer_query_binary(tmp_ctx,
2175 if (W_ERROR_IS_OK(result)) {
2176 info2->devmode = talloc_zero(info2, struct spoolss_DeviceMode);
2177 if (info2->devmode == NULL) {
2178 result = WERR_NOMEM;
2181 ndr_err = ndr_pull_struct_blob(&blob,
2184 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
2185 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2186 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2187 result = WERR_NOMEM;
2192 if (info2->devmode == NULL && lp_default_devmode(snum)) {
2193 result = spoolss_create_default_devmode(info2,
2196 if (!W_ERROR_IS_OK(result)) {
2201 if (info2->devmode != NULL) {
2202 info2->devmode->devicename = talloc_strdup(info2->devmode,
2203 info2->printername);
2204 if (info2->devmode->devicename == NULL) {
2205 DEBUG(0, ("winreg_get_printer: Failed to set devicename\n"));
2206 result = WERR_NOMEM;
2211 result = winreg_get_printer_secdesc(info2,
2215 if (!W_ERROR_IS_OK(result)) {
2219 /* Fix for OS/2 drivers. */
2220 if (get_remote_arch() == RA_OS2) {
2221 spoolss_map_to_os2_driver(info2, &info2->drivername);
2225 *pinfo2 = talloc_move(mem_ctx, &info2);
2230 if (winreg_pipe != NULL) {
2231 if (is_valid_policy_hnd(&key_hnd)) {
2232 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2234 if (is_valid_policy_hnd(&hive_hnd)) {
2235 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2239 TALLOC_FREE(tmp_ctx);
2243 WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
2244 struct auth_serversupplied_info *server_info,
2245 const char *sharename,
2246 struct spoolss_security_descriptor **psecdesc)
2248 struct spoolss_security_descriptor *secdesc;
2249 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2250 struct rpc_pipe_client *winreg_pipe = NULL;
2251 struct policy_handle hive_hnd, key_hnd;
2252 enum ndr_err_code ndr_err;
2255 TALLOC_CTX *tmp_ctx;
2258 tmp_ctx = talloc_stackframe();
2259 if (tmp_ctx == NULL) {
2263 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2265 talloc_free(tmp_ctx);
2269 ZERO_STRUCT(hive_hnd);
2270 ZERO_STRUCT(key_hnd);
2272 result = winreg_printer_openkey(tmp_ctx,
2281 if (!W_ERROR_IS_OK(result)) {
2282 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2283 goto create_default;
2288 result = winreg_printer_query_binary(tmp_ctx,
2293 if (!W_ERROR_IS_OK(result)) {
2294 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2295 goto create_default;
2300 secdesc = talloc_zero(tmp_ctx, struct spoolss_security_descriptor);
2301 if (secdesc == NULL) {
2302 result = WERR_NOMEM;
2305 ndr_err = ndr_pull_struct_blob(&blob,
2308 (ndr_pull_flags_fn_t) ndr_pull_security_descriptor);
2309 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2310 DEBUG(0, ("winreg_get_secdesc: Failed to unmarshall security descriptor\n"));
2311 result = WERR_NOMEM;
2316 *psecdesc = talloc_move(mem_ctx, &secdesc);
2323 result = spoolss_create_default_secdesc(tmp_ctx, &secdesc);
2324 if (!W_ERROR_IS_OK(result)) {
2328 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
2329 this security descriptor has been created when winbindd was
2330 down. Take ownership of security descriptor. */
2331 if (sid_equal(secdesc->owner_sid, &global_sid_World)) {
2332 struct dom_sid owner_sid;
2334 /* Change sd owner to workgroup administrator */
2336 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid)) {
2337 struct spoolss_security_descriptor *new_secdesc;
2341 sid_append_rid(&owner_sid, DOMAIN_RID_ADMINISTRATOR);
2343 new_secdesc = make_sec_desc(tmp_ctx,
2352 if (new_secdesc == NULL) {
2353 result = WERR_NOMEM;
2357 /* Swap with other one */
2358 secdesc = new_secdesc;
2362 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, secdesc,
2363 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2364 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2365 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2366 result = WERR_NOMEM;
2370 result = winreg_printer_write_binary(tmp_ctx,
2375 if (!W_ERROR_IS_OK(result)) {
2380 *psecdesc = talloc_move(mem_ctx, &secdesc);
2385 if (winreg_pipe != NULL) {
2386 if (is_valid_policy_hnd(&key_hnd)) {
2387 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2389 if (is_valid_policy_hnd(&hive_hnd)) {
2390 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2394 talloc_free(tmp_ctx);
2398 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
2399 struct auth_serversupplied_info *server_info,
2400 const char *sharename,
2401 const struct spoolss_security_descriptor *secdesc)
2403 const struct spoolss_security_descriptor *new_secdesc = secdesc;
2404 struct spoolss_security_descriptor *old_secdesc;
2405 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2406 struct rpc_pipe_client *winreg_pipe = NULL;
2407 struct policy_handle hive_hnd, key_hnd;
2408 enum ndr_err_code ndr_err;
2411 TALLOC_CTX *tmp_ctx;
2414 tmp_ctx = talloc_stackframe();
2415 if (tmp_ctx == NULL) {
2419 path = winreg_printer_data_keyname(tmp_ctx, sharename);
2421 talloc_free(tmp_ctx);
2426 * The old owner and group sids of the security descriptor are not
2427 * present when new ACEs are added or removed by changing printer
2428 * permissions through NT. If they are NULL in the new security
2429 * descriptor then copy them over from the old one.
2431 if (!secdesc->owner_sid || !secdesc->group_sid) {
2432 struct dom_sid *owner_sid, *group_sid;
2433 struct security_acl *dacl, *sacl;
2436 result = winreg_get_printer_secdesc(tmp_ctx,
2440 if (!W_ERROR_IS_OK(result)) {
2441 talloc_free(tmp_ctx);
2445 /* Pick out correct owner and group sids */
2446 owner_sid = secdesc->owner_sid ?
2447 secdesc->owner_sid :
2448 old_secdesc->owner_sid;
2450 group_sid = secdesc->group_sid ?
2451 secdesc->group_sid :
2452 old_secdesc->group_sid;
2454 dacl = secdesc->dacl ?
2458 sacl = secdesc->sacl ?
2462 /* Make a deep copy of the security descriptor */
2463 new_secdesc = make_sec_desc(tmp_ctx,
2471 if (new_secdesc == NULL) {
2472 talloc_free(tmp_ctx);
2477 ZERO_STRUCT(hive_hnd);
2478 ZERO_STRUCT(key_hnd);
2480 result = winreg_printer_openkey(tmp_ctx,
2489 if (!W_ERROR_IS_OK(result)) {
2493 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, new_secdesc,
2494 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
2495 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2496 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2497 result = WERR_NOMEM;
2501 result = winreg_printer_write_binary(tmp_ctx,
2508 if (winreg_pipe != NULL) {
2509 if (is_valid_policy_hnd(&key_hnd)) {
2510 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2512 if (is_valid_policy_hnd(&hive_hnd)) {
2513 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2517 talloc_free(tmp_ctx);
2521 /* Set printer data over the winreg pipe. */
2522 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2523 struct auth_serversupplied_info *server_info,
2524 const char *printer,
2527 enum winreg_Type type,
2531 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2532 struct rpc_pipe_client *winreg_pipe = NULL;
2533 struct policy_handle hive_hnd, key_hnd;
2534 struct winreg_String wvalue;
2536 WERROR result = WERR_OK;
2538 TALLOC_CTX *tmp_ctx;
2540 tmp_ctx = talloc_stackframe();
2541 if (tmp_ctx == NULL) {
2545 path = winreg_printer_data_keyname(tmp_ctx, printer);
2547 TALLOC_FREE(tmp_ctx);
2551 ZERO_STRUCT(hive_hnd);
2552 ZERO_STRUCT(key_hnd);
2554 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2555 key, value, access_mask, printer));
2556 result = winreg_printer_openkey(tmp_ctx,
2565 if (!W_ERROR_IS_OK(result)) {
2566 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2567 key, win_errstr(result)));
2571 wvalue.name = value;
2572 status = rpccli_winreg_SetValue(winreg_pipe,
2580 if (!NT_STATUS_IS_OK(status)) {
2581 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2582 value, nt_errstr(status)));
2583 if (!W_ERROR_IS_OK(result)) {
2586 result = ntstatus_to_werror(status);
2592 if (winreg_pipe != NULL) {
2593 if (is_valid_policy_hnd(&key_hnd)) {
2594 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2596 if (is_valid_policy_hnd(&hive_hnd)) {
2597 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2601 TALLOC_FREE(tmp_ctx);
2605 /* Get printer data over a winreg pipe. */
2606 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2607 struct auth_serversupplied_info *server_info,
2608 const char *printer,
2611 enum winreg_Type *type,
2613 uint32_t *data_size)
2615 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2616 struct rpc_pipe_client *winreg_pipe = NULL;
2617 struct policy_handle hive_hnd, key_hnd;
2618 struct winreg_String wvalue;
2619 enum winreg_Type type_in;
2622 uint32_t data_in_size = 0;
2623 uint32_t value_len = 0;
2624 WERROR result = WERR_OK;
2626 TALLOC_CTX *tmp_ctx;
2628 tmp_ctx = talloc_stackframe();
2629 if (tmp_ctx == NULL) {
2633 path = winreg_printer_data_keyname(tmp_ctx, printer);
2635 TALLOC_FREE(tmp_ctx);
2639 ZERO_STRUCT(hive_hnd);
2640 ZERO_STRUCT(key_hnd);
2642 result = winreg_printer_openkey(tmp_ctx,
2651 if (!W_ERROR_IS_OK(result)) {
2652 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2653 key, win_errstr(result)));
2657 wvalue.name = value;
2660 * call QueryValue once with data == NULL to get the
2661 * needed memory size to be allocated, then allocate
2662 * data buffer and call again.
2664 status = rpccli_winreg_QueryValue(winreg_pipe,
2673 if (!NT_STATUS_IS_OK(status)) {
2674 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2675 value, nt_errstr(status)));
2676 if (!W_ERROR_IS_OK(result)) {
2679 result = ntstatus_to_werror(status);
2683 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2684 if (data_in == NULL) {
2685 result = WERR_NOMEM;
2690 status = rpccli_winreg_QueryValue(winreg_pipe,
2699 if (!NT_STATUS_IS_OK(status)) {
2700 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2701 value, nt_errstr(status)));
2702 if (!W_ERROR_IS_OK(result)) {
2703 result = ntstatus_to_werror(status);
2709 *data_size = data_in_size;
2711 *data = talloc_move(mem_ctx, &data_in);
2716 if (winreg_pipe != NULL) {
2717 if (is_valid_policy_hnd(&key_hnd)) {
2718 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2720 if (is_valid_policy_hnd(&hive_hnd)) {
2721 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2725 TALLOC_FREE(tmp_ctx);
2729 /* Enumerate on the values of a given key and provide the data. */
2730 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2731 struct auth_serversupplied_info *server_info,
2732 const char *printer,
2734 uint32_t *pnum_values,
2735 struct spoolss_PrinterEnumValues **penum_values)
2737 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2738 struct rpc_pipe_client *winreg_pipe = NULL;
2739 struct policy_handle hive_hnd, key_hnd;
2741 struct spoolss_PrinterEnumValues *enum_values = NULL;
2742 uint32_t num_values = 0;
2744 WERROR result = WERR_OK;
2746 TALLOC_CTX *tmp_ctx;
2748 tmp_ctx = talloc_stackframe();
2749 if (tmp_ctx == NULL) {
2753 path = winreg_printer_data_keyname(tmp_ctx, printer);
2755 TALLOC_FREE(tmp_ctx);
2759 result = winreg_printer_openkey(tmp_ctx,
2768 if (!W_ERROR_IS_OK(result)) {
2769 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2770 key, win_errstr(result)));
2774 result = winreg_printer_enumvalues(tmp_ctx,
2779 if (!W_ERROR_IS_OK(result)) {
2780 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2781 key, win_errstr(result)));
2785 *pnum_values = num_values;
2787 *penum_values = talloc_move(mem_ctx, &enum_values);
2792 if (winreg_pipe != NULL) {
2793 if (is_valid_policy_hnd(&key_hnd)) {
2794 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2796 if (is_valid_policy_hnd(&hive_hnd)) {
2797 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2801 TALLOC_FREE(tmp_ctx);
2805 /* Delete printer data over a winreg pipe. */
2806 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2807 struct auth_serversupplied_info *server_info,
2808 const char *printer,
2812 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2813 struct rpc_pipe_client *winreg_pipe = NULL;
2814 struct policy_handle hive_hnd, key_hnd;
2815 struct winreg_String wvalue;
2817 WERROR result = WERR_OK;
2820 TALLOC_CTX *tmp_ctx;
2822 tmp_ctx = talloc_stackframe();
2823 if (tmp_ctx == NULL) {
2827 path = winreg_printer_data_keyname(tmp_ctx, printer);
2829 TALLOC_FREE(tmp_ctx);
2833 ZERO_STRUCT(hive_hnd);
2834 ZERO_STRUCT(key_hnd);
2836 result = winreg_printer_openkey(tmp_ctx,
2845 if (!W_ERROR_IS_OK(result)) {
2846 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2847 key, win_errstr(result)));
2851 wvalue.name = value;
2852 status = rpccli_winreg_DeleteValue(winreg_pipe,
2857 if (!NT_STATUS_IS_OK(status)) {
2858 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2859 value, nt_errstr(status)));
2860 if (!W_ERROR_IS_OK(result)) {
2863 result = ntstatus_to_werror(status);
2869 if (winreg_pipe != NULL) {
2870 if (is_valid_policy_hnd(&key_hnd)) {
2871 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2873 if (is_valid_policy_hnd(&hive_hnd)) {
2874 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2878 TALLOC_FREE(tmp_ctx);
2882 /* Enumerate on the subkeys of a given key and provide the data. */
2883 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2884 struct auth_serversupplied_info *server_info,
2885 const char *printer,
2887 uint32_t *pnum_subkeys,
2888 const char ***psubkeys)
2890 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2891 struct rpc_pipe_client *winreg_pipe = NULL;
2892 struct policy_handle hive_hnd, key_hnd;
2894 const char **subkeys = NULL;
2895 uint32_t num_subkeys = -1;
2897 WERROR result = WERR_OK;
2899 TALLOC_CTX *tmp_ctx;
2901 tmp_ctx = talloc_stackframe();
2902 if (tmp_ctx == NULL) {
2906 path = winreg_printer_data_keyname(tmp_ctx, printer);
2908 TALLOC_FREE(tmp_ctx);
2912 ZERO_STRUCT(hive_hnd);
2913 ZERO_STRUCT(key_hnd);
2915 result = winreg_printer_openkey(tmp_ctx,
2924 if (!W_ERROR_IS_OK(result)) {
2925 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2926 key, win_errstr(result)));
2930 result = winreg_printer_enumkeys(tmp_ctx,
2935 if (!W_ERROR_IS_OK(result)) {
2936 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2937 key, win_errstr(result)));
2941 *pnum_subkeys = num_subkeys;
2943 *psubkeys = talloc_move(mem_ctx, &subkeys);
2948 if (winreg_pipe != NULL) {
2949 if (is_valid_policy_hnd(&key_hnd)) {
2950 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2952 if (is_valid_policy_hnd(&hive_hnd)) {
2953 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2957 TALLOC_FREE(tmp_ctx);
2961 /* Delete a key with subkeys of a given printer. */
2962 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
2963 struct auth_serversupplied_info *server_info,
2964 const char *printer,
2967 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2968 struct rpc_pipe_client *winreg_pipe = NULL;
2969 struct policy_handle hive_hnd, key_hnd;
2973 TALLOC_CTX *tmp_ctx;
2975 tmp_ctx = talloc_stackframe();
2976 if (tmp_ctx == NULL) {
2980 path = winreg_printer_data_keyname(tmp_ctx, printer);
2982 TALLOC_FREE(tmp_ctx);
2986 result = winreg_printer_openkey(tmp_ctx,
2995 if (!W_ERROR_IS_OK(result)) {
2996 /* key doesn't exist */
2997 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3002 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
3003 key, win_errstr(result)));
3007 if (is_valid_policy_hnd(&key_hnd)) {
3008 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3011 if (key == NULL || key[0] == '\0') {
3014 keyname = talloc_asprintf(tmp_ctx,
3018 if (keyname == NULL) {
3019 result = WERR_NOMEM;
3024 result = winreg_printer_delete_subkeys(tmp_ctx,
3029 if (!W_ERROR_IS_OK(result)) {
3030 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
3031 key, win_errstr(result)));
3036 if (winreg_pipe != NULL) {
3037 if (is_valid_policy_hnd(&key_hnd)) {
3038 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3040 if (is_valid_policy_hnd(&hive_hnd)) {
3041 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3045 TALLOC_FREE(tmp_ctx);
3049 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
3050 struct auth_serversupplied_info *server_info,
3051 const char *printer)
3053 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3054 struct rpc_pipe_client *winreg_pipe = NULL;
3055 struct policy_handle hive_hnd, key_hnd;
3058 TALLOC_CTX *tmp_ctx;
3060 tmp_ctx = talloc_stackframe();
3061 if (tmp_ctx == NULL) {
3065 path = winreg_printer_data_keyname(tmp_ctx, printer);
3067 TALLOC_FREE(tmp_ctx);
3071 ZERO_STRUCT(hive_hnd);
3072 ZERO_STRUCT(key_hnd);
3074 result = winreg_printer_openkey(tmp_ctx,
3083 if (!W_ERROR_IS_OK(result)) {
3084 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
3085 path, win_errstr(result)));
3089 result = winreg_printer_write_dword(tmp_ctx,
3093 winreg_printer_rev_changeid());
3094 if (!W_ERROR_IS_OK(result)) {
3100 if (winreg_pipe != NULL) {
3101 if (is_valid_policy_hnd(&key_hnd)) {
3102 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3104 if (is_valid_policy_hnd(&hive_hnd)) {
3105 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3109 TALLOC_FREE(tmp_ctx);
3113 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
3114 struct auth_serversupplied_info *server_info,
3115 const char *printer,
3116 uint32_t *pchangeid)
3118 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3119 struct rpc_pipe_client *winreg_pipe = NULL;
3120 struct policy_handle hive_hnd, key_hnd;
3121 uint32_t changeid = 0;
3124 TALLOC_CTX *tmp_ctx;
3126 tmp_ctx = talloc_stackframe();
3127 if (tmp_ctx == NULL) {
3131 path = winreg_printer_data_keyname(tmp_ctx, printer);
3133 TALLOC_FREE(tmp_ctx);
3137 ZERO_STRUCT(hive_hnd);
3138 ZERO_STRUCT(key_hnd);
3140 result = winreg_printer_openkey(tmp_ctx,
3149 if (!W_ERROR_IS_OK(result)) {
3150 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
3151 path, win_errstr(result)));
3155 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path));
3157 result = winreg_printer_query_dword(tmp_ctx,
3162 if (!W_ERROR_IS_OK(result)) {
3167 *pchangeid = changeid;
3172 if (winreg_pipe != NULL) {
3173 if (is_valid_policy_hnd(&key_hnd)) {
3174 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3176 if (is_valid_policy_hnd(&hive_hnd)) {
3177 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3181 TALLOC_FREE(tmp_ctx);
3186 * The special behaviour of the spoolss forms is documented at the website:
3188 * Managing Win32 Printserver Forms
3189 * http://unixwiz.net/techtips/winspooler-forms.html
3192 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
3193 struct auth_serversupplied_info *server_info,
3194 struct spoolss_AddFormInfo1 *form)
3196 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3197 struct rpc_pipe_client *winreg_pipe = NULL;
3198 struct policy_handle hive_hnd, key_hnd;
3199 struct winreg_String wvalue;
3201 uint32_t num_info = 0;
3202 union spoolss_FormInfo *info = NULL;
3206 TALLOC_CTX *tmp_ctx;
3208 tmp_ctx = talloc_stackframe();
3209 if (tmp_ctx == NULL) {
3213 ZERO_STRUCT(hive_hnd);
3214 ZERO_STRUCT(key_hnd);
3216 result = winreg_printer_openkey(tmp_ctx,
3219 TOP_LEVEL_CONTROL_FORMS_KEY,
3225 if (!W_ERROR_IS_OK(result)) {
3226 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
3227 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3231 result = winreg_printer_enumforms1(tmp_ctx, server_info, &num_info, &info);
3232 if (!W_ERROR_IS_OK(result)) {
3233 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
3234 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3238 /* If form name already exists or is builtin return ALREADY_EXISTS */
3239 for (i = 0; i < num_info; i++) {
3240 if (strequal(info[i].info1.form_name, form->form_name)) {
3241 result = WERR_FILE_EXISTS;
3246 wvalue.name = form->form_name;
3248 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3249 SIVAL(blob.data, 0, form->size.width);
3250 SIVAL(blob.data, 4, form->size.height);
3251 SIVAL(blob.data, 8, form->area.left);
3252 SIVAL(blob.data, 12, form->area.top);
3253 SIVAL(blob.data, 16, form->area.right);
3254 SIVAL(blob.data, 20, form->area.bottom);
3255 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
3256 SIVAL(blob.data, 28, form->flags);
3258 status = rpccli_winreg_SetValue(winreg_pipe,
3266 if (!NT_STATUS_IS_OK(status)) {
3267 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
3268 wvalue.name, nt_errstr(status)));
3269 if (!W_ERROR_IS_OK(result)) {
3272 result = ntstatus_to_werror(status);
3278 if (winreg_pipe != NULL) {
3279 if (is_valid_policy_hnd(&key_hnd)) {
3280 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3282 if (is_valid_policy_hnd(&hive_hnd)) {
3283 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3288 TALLOC_FREE(tmp_ctx);
3292 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
3293 struct auth_serversupplied_info *server_info,
3294 uint32_t *pnum_info,
3295 union spoolss_FormInfo **pinfo)
3297 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3298 struct rpc_pipe_client *winreg_pipe = NULL;
3299 struct policy_handle hive_hnd, key_hnd;
3300 union spoolss_FormInfo *info;
3301 struct spoolss_PrinterEnumValues *enum_values = NULL;
3302 uint32_t num_values = 0;
3303 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3306 TALLOC_CTX *tmp_ctx;
3308 tmp_ctx = talloc_stackframe();
3309 if (tmp_ctx == NULL) {
3313 ZERO_STRUCT(hive_hnd);
3314 ZERO_STRUCT(key_hnd);
3316 result = winreg_printer_openkey(tmp_ctx,
3319 TOP_LEVEL_CONTROL_FORMS_KEY,
3325 if (!W_ERROR_IS_OK(result)) {
3326 /* key doesn't exist */
3327 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3332 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3333 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3337 result = winreg_printer_enumvalues(tmp_ctx,
3342 if (!W_ERROR_IS_OK(result)) {
3343 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3344 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3348 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
3350 result = WERR_NOMEM;
3354 /* Enumerate BUILTIN forms */
3355 for (i = 0; i < num_builtin; i++) {
3356 info[i].info1 = builtin_forms1[i];
3359 /* Enumerate registry forms */
3360 for (i = 0; i < num_values; i++) {
3361 union spoolss_FormInfo val;
3363 if (enum_values[i].type != REG_BINARY ||
3364 enum_values[i].data_length != 32) {
3368 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
3369 if (val.info1.form_name == NULL) {
3370 result = WERR_NOMEM;
3374 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3375 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3376 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3377 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3378 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3379 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3380 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3381 val.info1.flags = (enum spoolss_FormFlags) IVAL(enum_values[i].data->data, 28);
3383 info[i + num_builtin] = val;
3386 *pnum_info = num_builtin + num_values;
3388 *pinfo = talloc_move(mem_ctx, &info);
3392 if (winreg_pipe != NULL) {
3393 if (is_valid_policy_hnd(&key_hnd)) {
3394 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3396 if (is_valid_policy_hnd(&hive_hnd)) {
3397 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3401 TALLOC_FREE(enum_values);
3402 TALLOC_FREE(tmp_ctx);
3406 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3407 struct auth_serversupplied_info *server_info,
3408 const char *form_name)
3410 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3411 struct rpc_pipe_client *winreg_pipe = NULL;
3412 struct policy_handle hive_hnd, key_hnd;
3413 struct winreg_String wvalue;
3414 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3416 WERROR result = WERR_OK;
3418 TALLOC_CTX *tmp_ctx;
3420 for (i = 0; i < num_builtin; i++) {
3421 if (strequal(builtin_forms1[i].form_name, form_name)) {
3422 return WERR_INVALID_PARAMETER;
3426 tmp_ctx = talloc_stackframe();
3427 if (tmp_ctx == NULL) {
3431 ZERO_STRUCT(hive_hnd);
3432 ZERO_STRUCT(key_hnd);
3434 result = winreg_printer_openkey(tmp_ctx,
3437 TOP_LEVEL_CONTROL_FORMS_KEY,
3443 if (!W_ERROR_IS_OK(result)) {
3444 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3445 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3446 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3447 result = WERR_INVALID_FORM_NAME;
3452 wvalue.name = form_name;
3453 status = rpccli_winreg_DeleteValue(winreg_pipe,
3458 if (!NT_STATUS_IS_OK(status)) {
3459 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3460 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3461 result = WERR_INVALID_FORM_NAME;
3464 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3465 wvalue.name, nt_errstr(status)));
3466 if (!W_ERROR_IS_OK(result)) {
3469 result = ntstatus_to_werror(status);
3475 if (winreg_pipe != NULL) {
3476 if (is_valid_policy_hnd(&key_hnd)) {
3477 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3479 if (is_valid_policy_hnd(&hive_hnd)) {
3480 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3484 TALLOC_FREE(tmp_ctx);
3488 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3489 struct auth_serversupplied_info *server_info,
3490 const char *form_name,
3491 struct spoolss_AddFormInfo1 *form)
3493 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3494 struct rpc_pipe_client *winreg_pipe = NULL;
3495 struct policy_handle hive_hnd, key_hnd;
3496 struct winreg_String wvalue;
3498 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3502 TALLOC_CTX *tmp_ctx = NULL;
3504 for (i = 0; i < num_builtin; i++) {
3505 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3506 result = WERR_INVALID_PARAM;
3511 tmp_ctx = talloc_stackframe();
3512 if (tmp_ctx == NULL) {
3516 ZERO_STRUCT(hive_hnd);
3517 ZERO_STRUCT(key_hnd);
3519 result = winreg_printer_openkey(tmp_ctx,
3522 TOP_LEVEL_CONTROL_FORMS_KEY,
3528 if (!W_ERROR_IS_OK(result)) {
3529 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3530 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3534 /* If form_name != form->form_name then we renamed the form */
3535 if (strequal(form_name, form->form_name)) {
3536 result = winreg_printer_deleteform1(tmp_ctx, server_info, form_name);
3537 if (!W_ERROR_IS_OK(result)) {
3538 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3539 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3544 wvalue.name = form->form_name;
3546 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3547 SIVAL(blob.data, 0, form->size.width);
3548 SIVAL(blob.data, 4, form->size.height);
3549 SIVAL(blob.data, 8, form->area.left);
3550 SIVAL(blob.data, 12, form->area.top);
3551 SIVAL(blob.data, 16, form->area.right);
3552 SIVAL(blob.data, 20, form->area.bottom);
3553 SIVAL(blob.data, 24, 42);
3554 SIVAL(blob.data, 28, form->flags);
3556 status = rpccli_winreg_SetValue(winreg_pipe,
3564 if (!NT_STATUS_IS_OK(status)) {
3565 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3566 wvalue.name, nt_errstr(status)));
3567 if (!W_ERROR_IS_OK(result)) {
3570 result = ntstatus_to_werror(status);
3576 if (winreg_pipe != NULL) {
3577 if (is_valid_policy_hnd(&key_hnd)) {
3578 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3580 if (is_valid_policy_hnd(&hive_hnd)) {
3581 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3585 TALLOC_FREE(tmp_ctx);
3589 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3590 struct auth_serversupplied_info *server_info,
3591 const char *form_name,
3592 struct spoolss_FormInfo1 *r)
3594 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3595 struct rpc_pipe_client *winreg_pipe = NULL;
3596 struct policy_handle hive_hnd, key_hnd;
3597 struct winreg_String wvalue;
3598 enum winreg_Type type_in;
3600 uint32_t data_in_size = 0;
3601 uint32_t value_len = 0;
3602 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3606 TALLOC_CTX *tmp_ctx;
3608 /* check builtin forms first */
3609 for (i = 0; i < num_builtin; i++) {
3610 if (strequal(builtin_forms1[i].form_name, form_name)) {
3611 *r = builtin_forms1[i];
3616 tmp_ctx = talloc_stackframe();
3617 if (tmp_ctx == NULL) {
3621 ZERO_STRUCT(hive_hnd);
3622 ZERO_STRUCT(key_hnd);
3624 result = winreg_printer_openkey(tmp_ctx,
3627 TOP_LEVEL_CONTROL_FORMS_KEY,
3633 if (!W_ERROR_IS_OK(result)) {
3634 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3635 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3639 wvalue.name = form_name;
3642 * call QueryValue once with data == NULL to get the
3643 * needed memory size to be allocated, then allocate
3644 * data buffer and call again.
3646 status = rpccli_winreg_QueryValue(winreg_pipe,
3655 if (!NT_STATUS_IS_OK(status)) {
3656 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3657 wvalue.name, nt_errstr(status)));
3658 if (!W_ERROR_IS_OK(result)) {
3661 result = ntstatus_to_werror(status);
3665 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3666 if (data_in == NULL) {
3667 result = WERR_NOMEM;
3672 status = rpccli_winreg_QueryValue(winreg_pipe,
3681 if (!NT_STATUS_IS_OK(status)) {
3682 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3683 wvalue.name, nt_errstr(status)));
3684 if (!W_ERROR_IS_OK(result)) {
3687 result = ntstatus_to_werror(status);
3691 r->form_name = talloc_strdup(mem_ctx, form_name);
3692 if (r->form_name == NULL) {
3693 result = WERR_NOMEM;
3697 r->size.width = IVAL(data_in, 0);
3698 r->size.height = IVAL(data_in, 4);
3699 r->area.left = IVAL(data_in, 8);
3700 r->area.top = IVAL(data_in, 12);
3701 r->area.right = IVAL(data_in, 16);
3702 r->area.bottom = IVAL(data_in, 20);
3703 /* skip index IVAL(data_in, 24)));*/
3704 r->flags = (enum spoolss_FormFlags) IVAL(data_in, 28);
3708 if (winreg_pipe != NULL) {
3709 if (is_valid_policy_hnd(&key_hnd)) {
3710 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3712 if (is_valid_policy_hnd(&hive_hnd)) {
3713 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3717 TALLOC_FREE(tmp_ctx);
3721 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3722 struct auth_serversupplied_info *server_info,
3723 struct spoolss_AddDriverInfoCtr *r,
3724 const char **driver_name,
3725 uint32_t *driver_version)
3727 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3728 struct rpc_pipe_client *winreg_pipe = NULL;
3729 struct policy_handle hive_hnd, key_hnd;
3730 struct spoolss_DriverInfo8 info8;
3731 TALLOC_CTX *tmp_ctx = NULL;
3734 ZERO_STRUCT(hive_hnd);
3735 ZERO_STRUCT(key_hnd);
3738 if (!driver_info_ctr_to_info8(r, &info8)) {
3739 result = WERR_INVALID_PARAMETER;
3743 tmp_ctx = talloc_stackframe();
3744 if (tmp_ctx == NULL) {
3748 result = winreg_printer_opendriver(tmp_ctx,
3757 if (!W_ERROR_IS_OK(result)) {
3758 DEBUG(0, ("winreg_add_driver: "
3759 "Could not open driver key (%s,%s,%d): %s\n",
3760 info8.driver_name, info8.architecture,
3761 info8.version, win_errstr(result)));
3765 /* TODO: "Attributes" ? */
3767 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe,
3768 &key_hnd, "Version",
3770 if (!W_ERROR_IS_OK(result)) {
3774 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3777 if (!W_ERROR_IS_OK(result)) {
3781 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3782 &key_hnd, "Data File",
3784 if (!W_ERROR_IS_OK(result)) {
3788 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3789 &key_hnd, "Configuration File",
3791 if (!W_ERROR_IS_OK(result)) {
3795 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3796 &key_hnd, "Help File",
3798 if (!W_ERROR_IS_OK(result)) {
3802 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3803 &key_hnd, "Dependent Files",
3804 info8.dependent_files);
3805 if (!W_ERROR_IS_OK(result)) {
3809 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3810 &key_hnd, "Monitor",
3811 info8.monitor_name);
3812 if (!W_ERROR_IS_OK(result)) {
3816 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3817 &key_hnd, "Datatype",
3818 info8.default_datatype);
3819 if (!W_ERROR_IS_OK(result)) {
3823 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3824 &key_hnd, "Previous Names",
3825 info8.previous_names);
3826 if (!W_ERROR_IS_OK(result)) {
3830 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3831 &key_hnd, "DriverDate",
3833 if (!W_ERROR_IS_OK(result)) {
3837 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe,
3838 &key_hnd, "DriverVersion",
3839 info8.driver_version);
3840 if (!W_ERROR_IS_OK(result)) {
3844 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3845 &key_hnd, "Manufacturer",
3846 info8.manufacturer_name);
3847 if (!W_ERROR_IS_OK(result)) {
3851 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3852 &key_hnd, "OEM URL",
3853 info8.manufacturer_url);
3854 if (!W_ERROR_IS_OK(result)) {
3858 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3859 &key_hnd, "HardwareID",
3861 if (!W_ERROR_IS_OK(result)) {
3865 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3866 &key_hnd, "Provider",
3868 if (!W_ERROR_IS_OK(result)) {
3872 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3873 &key_hnd, "Print Processor",
3874 info8.print_processor);
3875 if (!W_ERROR_IS_OK(result)) {
3879 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3880 &key_hnd, "VendorSetup",
3881 info8.vendor_setup);
3882 if (!W_ERROR_IS_OK(result)) {
3886 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3887 &key_hnd, "Color Profiles",
3888 info8.color_profiles);
3889 if (!W_ERROR_IS_OK(result)) {
3893 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3894 &key_hnd, "InfPath",
3896 if (!W_ERROR_IS_OK(result)) {
3900 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe, &key_hnd,
3901 "PrinterDriverAttributes",
3902 info8.printer_driver_attributes);
3903 if (!W_ERROR_IS_OK(result)) {
3907 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3908 &key_hnd, "CoreDependencies",
3909 info8.core_driver_dependencies);
3910 if (!W_ERROR_IS_OK(result)) {
3914 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3915 &key_hnd, "MinInboxDriverVerDate",
3916 info8.min_inbox_driver_ver_date);
3917 if (!W_ERROR_IS_OK(result)) {
3921 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe, &key_hnd,
3922 "MinInboxDriverVerVersion",
3923 info8.min_inbox_driver_ver_version);
3924 if (!W_ERROR_IS_OK(result)) {
3928 *driver_name = info8.driver_name;
3929 *driver_version = info8.version;
3932 if (winreg_pipe != NULL) {
3933 if (is_valid_policy_hnd(&key_hnd)) {
3934 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3936 if (is_valid_policy_hnd(&hive_hnd)) {
3937 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3941 TALLOC_FREE(tmp_ctx);
3945 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
3946 struct auth_serversupplied_info *server_info,
3947 const char *architecture,
3948 const char *driver_name,
3949 uint32_t driver_version,
3950 struct spoolss_DriverInfo8 **_info8)
3952 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3953 struct rpc_pipe_client *winreg_pipe = NULL;
3954 struct policy_handle hive_hnd, key_hnd;
3955 struct spoolss_DriverInfo8 i8, *info8;
3956 struct spoolss_PrinterEnumValues *enum_values = NULL;
3957 struct spoolss_PrinterEnumValues *v;
3958 uint32_t num_values = 0;
3959 TALLOC_CTX *tmp_ctx;
3963 ZERO_STRUCT(hive_hnd);
3964 ZERO_STRUCT(key_hnd);
3967 tmp_ctx = talloc_stackframe();
3968 if (tmp_ctx == NULL) {
3972 if (driver_version == DRIVER_ANY_VERSION) {
3973 /* look for Win2k first and then for NT4 */
3974 result = winreg_printer_opendriver(tmp_ctx,
3983 if (!W_ERROR_IS_OK(result)) {
3984 result = winreg_printer_opendriver(tmp_ctx,
3995 /* ok normal case */
3996 result = winreg_printer_opendriver(tmp_ctx,
4006 if (!W_ERROR_IS_OK(result)) {
4007 DEBUG(5, ("winreg_get_driver: "
4008 "Could not open driver key (%s,%s,%d): %s\n",
4009 driver_name, architecture,
4010 driver_version, win_errstr(result)));
4014 result = winreg_printer_enumvalues(tmp_ctx,
4019 if (!W_ERROR_IS_OK(result)) {
4020 DEBUG(0, ("winreg_get_driver: "
4021 "Could not enumerate values for (%s,%s,%d): %s\n",
4022 driver_name, architecture,
4023 driver_version, win_errstr(result)));
4027 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
4028 if (info8 == NULL) {
4029 result = WERR_NOMEM;
4033 info8->driver_name = talloc_strdup(info8, driver_name);
4034 if (info8->driver_name == NULL) {
4035 result = WERR_NOMEM;
4039 info8->architecture = talloc_strdup(info8, architecture);
4040 if (info8->architecture == NULL) {
4041 result = WERR_NOMEM;
4047 for (i = 0; i < num_values; i++) {
4048 const char *tmp_str;
4051 v = &enum_values[i];
4053 result = winreg_enumval_to_dword(info8, v,
4056 if (NT_STATUS_IS_OK(result)) {
4057 info8->version = (enum spoolss_DriverOSVersion) tmp;
4059 CHECK_ERROR(result);
4061 result = winreg_enumval_to_sz(info8, v,
4063 &info8->driver_path);
4064 CHECK_ERROR(result);
4066 result = winreg_enumval_to_sz(info8, v,
4069 CHECK_ERROR(result);
4071 result = winreg_enumval_to_sz(info8, v,
4072 "Configuration File",
4073 &info8->config_file);
4074 CHECK_ERROR(result);
4076 result = winreg_enumval_to_sz(info8, v,
4079 CHECK_ERROR(result);
4081 result = winreg_enumval_to_multi_sz(info8, v,
4083 &info8->dependent_files);
4084 CHECK_ERROR(result);
4086 result = winreg_enumval_to_sz(info8, v,
4088 &info8->monitor_name);
4089 CHECK_ERROR(result);
4091 result = winreg_enumval_to_sz(info8, v,
4093 &info8->default_datatype);
4094 CHECK_ERROR(result);
4096 result = winreg_enumval_to_multi_sz(info8, v,
4098 &info8->previous_names);
4099 CHECK_ERROR(result);
4101 result = winreg_enumval_to_sz(info8, v,
4104 if (W_ERROR_IS_OK(result)) {
4105 result = winreg_printer_date_to_NTTIME(tmp_str,
4106 &info8->driver_date);
4108 CHECK_ERROR(result);
4110 result = winreg_enumval_to_sz(info8, v,
4113 if (W_ERROR_IS_OK(result)) {
4114 result = winreg_printer_ver_to_dword(tmp_str,
4115 &info8->driver_version);
4117 CHECK_ERROR(result);
4119 result = winreg_enumval_to_sz(info8, v,
4121 &info8->manufacturer_name);
4122 CHECK_ERROR(result);
4124 result = winreg_enumval_to_sz(info8, v,
4126 &info8->manufacturer_url);
4127 CHECK_ERROR(result);
4129 result = winreg_enumval_to_sz(info8, v,
4131 &info8->hardware_id);
4132 CHECK_ERROR(result);
4134 result = winreg_enumval_to_sz(info8, v,
4137 CHECK_ERROR(result);
4139 result = winreg_enumval_to_sz(info8, v,
4141 &info8->print_processor);
4142 CHECK_ERROR(result);
4144 result = winreg_enumval_to_sz(info8, v,
4146 &info8->vendor_setup);
4147 CHECK_ERROR(result);
4149 result = winreg_enumval_to_multi_sz(info8, v,
4151 &info8->color_profiles);
4152 CHECK_ERROR(result);
4154 result = winreg_enumval_to_sz(info8, v,
4157 CHECK_ERROR(result);
4159 result = winreg_enumval_to_dword(info8, v,
4160 "PrinterDriverAttributes",
4161 &info8->printer_driver_attributes);
4162 CHECK_ERROR(result);
4164 result = winreg_enumval_to_multi_sz(info8, v,
4166 &info8->core_driver_dependencies);
4167 CHECK_ERROR(result);
4169 result = winreg_enumval_to_sz(info8, v,
4170 "MinInboxDriverVerDate",
4172 if (W_ERROR_IS_OK(result)) {
4173 result = winreg_printer_date_to_NTTIME(tmp_str,
4174 &info8->min_inbox_driver_ver_date);
4176 CHECK_ERROR(result);
4178 result = winreg_enumval_to_sz(info8, v,
4179 "MinInboxDriverVerVersion",
4181 if (W_ERROR_IS_OK(result)) {
4182 result = winreg_printer_ver_to_dword(tmp_str,
4183 &info8->min_inbox_driver_ver_version);
4185 CHECK_ERROR(result);
4188 if (!W_ERROR_IS_OK(result)) {
4189 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4190 "for %s: %s\n", v->value_name,
4191 win_errstr(result)));
4195 *_info8 = talloc_steal(mem_ctx, info8);
4198 if (winreg_pipe != NULL) {
4199 if (is_valid_policy_hnd(&key_hnd)) {
4200 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4202 if (is_valid_policy_hnd(&hive_hnd)) {
4203 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4207 TALLOC_FREE(tmp_ctx);
4211 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
4212 struct auth_serversupplied_info *server_info,
4213 struct spoolss_DriverInfo8 *info8,
4216 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4217 struct rpc_pipe_client *winreg_pipe = NULL;
4218 struct policy_handle hive_hnd, key_hnd;
4219 TALLOC_CTX *tmp_ctx;
4223 ZERO_STRUCT(hive_hnd);
4224 ZERO_STRUCT(key_hnd);
4226 tmp_ctx = talloc_stackframe();
4227 if (tmp_ctx == NULL) {
4231 /* test that the key exists */
4232 result = winreg_printer_opendriver(tmp_ctx,
4235 info8->architecture,
4241 if (!W_ERROR_IS_OK(result)) {
4242 /* key doesn't exist */
4243 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
4248 DEBUG(5, ("winreg_del_driver: "
4249 "Could not open driver (%s,%s,%u): %s\n",
4250 info8->driver_name, info8->architecture,
4251 version, win_errstr(result)));
4256 if (is_valid_policy_hnd(&key_hnd)) {
4257 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4260 key_name = talloc_asprintf(tmp_ctx,
4261 "%s\\Environments\\%s\\Drivers\\Version-%u",
4262 TOP_LEVEL_CONTROL_KEY,
4263 info8->architecture, version);
4264 if (key_name == NULL) {
4265 result = WERR_NOMEM;
4269 result = winreg_printer_delete_subkeys(tmp_ctx,
4274 if (!W_ERROR_IS_OK(result)) {
4275 DEBUG(0, ("winreg_del_driver: "
4276 "Could not open driver (%s,%s,%u): %s\n",
4277 info8->driver_name, info8->architecture,
4278 version, win_errstr(result)));
4284 if (winreg_pipe != NULL) {
4285 if (is_valid_policy_hnd(&key_hnd)) {
4286 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4288 if (is_valid_policy_hnd(&hive_hnd)) {
4289 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4293 TALLOC_FREE(tmp_ctx);
4297 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
4298 struct auth_serversupplied_info *server_info,
4299 const char *architecture,
4301 uint32_t *num_drivers,
4302 const char ***drivers_p)
4304 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4305 struct rpc_pipe_client *winreg_pipe = NULL;
4306 struct policy_handle hive_hnd, key_hnd;
4307 const char **drivers;
4308 TALLOC_CTX *tmp_ctx;
4314 ZERO_STRUCT(hive_hnd);
4315 ZERO_STRUCT(key_hnd);
4317 tmp_ctx = talloc_stackframe();
4318 if (tmp_ctx == NULL) {
4322 /* use NULL for the driver name so we open the key that is
4323 * parent of all drivers for this architecture and version */
4324 result = winreg_printer_opendriver(tmp_ctx,
4333 if (!W_ERROR_IS_OK(result)) {
4334 DEBUG(5, ("winreg_get_driver_list: "
4335 "Could not open key (%s,%u): %s\n",
4336 architecture, version, win_errstr(result)));
4341 result = winreg_printer_enumkeys(tmp_ctx,
4346 if (!W_ERROR_IS_OK(result)) {
4347 DEBUG(0, ("winreg_get_driver_list: "
4348 "Could not enumerate drivers for (%s,%u): %s\n",
4349 architecture, version, win_errstr(result)));
4353 *drivers_p = talloc_steal(mem_ctx, drivers);
4357 if (winreg_pipe != NULL) {
4358 if (is_valid_policy_hnd(&key_hnd)) {
4359 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4361 if (is_valid_policy_hnd(&hive_hnd)) {
4362 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4366 TALLOC_FREE(tmp_ctx);