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 "srv_spoolss_util.h"
24 #include "../librpc/gen_ndr/srv_winreg.h"
25 #include "../librpc/gen_ndr/cli_winreg.h"
27 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
28 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
29 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
30 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
32 #define EMPTY_STRING ""
33 static const char *empty_string_array[1] = { NULL };
34 #define EMPTY_STRING_ARRAY empty_string_array
36 #define CHECK_ERROR(result) \
37 if (W_ERROR_IS_OK(result)) continue; \
38 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
39 if (!W_ERROR_IS_OK(result)) break
41 /* FLAGS, NAME, with, height, left, top, right, bottom */
42 static const struct spoolss_FormInfo1 builtin_forms1[] = {
43 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
44 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
45 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
46 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
47 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
48 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
49 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
50 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
51 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
52 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
53 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
54 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
55 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
56 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
57 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
58 { SPOOLSS_FORM_BUILTIN, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
59 { SPOOLSS_FORM_BUILTIN, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
60 { SPOOLSS_FORM_BUILTIN, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
61 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
62 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
63 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
64 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
65 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
66 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
67 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
68 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
69 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
70 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
71 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
72 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
73 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
74 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
75 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
76 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
77 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
78 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
79 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
80 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
81 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} },
82 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
83 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
84 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
85 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
86 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
87 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
88 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
89 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
90 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
91 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
92 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
93 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
94 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
95 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
96 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
97 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
98 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
99 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
100 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
101 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
102 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
103 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
104 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
105 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
106 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
107 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
108 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
109 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
110 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
111 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
112 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
113 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
114 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
115 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
116 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
117 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
118 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
119 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
120 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
121 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
122 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
123 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
124 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
125 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
126 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
127 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
128 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
129 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
130 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
131 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
132 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
133 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
134 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
135 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
136 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
137 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
138 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
139 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
140 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
141 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
142 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
143 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
144 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
145 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
146 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
147 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
148 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
149 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
150 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
151 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
152 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
153 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
154 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
159 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
160 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} }
163 /********************************************************************
164 static helper functions
165 ********************************************************************/
167 /****************************************************************************
168 Update the changeid time.
169 ****************************************************************************/
173 * @brief Update the ChangeID time of a printer.
175 * This is SO NASTY as some drivers need this to change, others need it
176 * static. This value will change every second, and I must hope that this
177 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
180 * @return The ChangeID.
182 static uint32_t winreg_printer_rev_changeid(void)
186 get_process_uptime(&tv);
189 /* Return changeid as msec since spooler restart */
190 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
193 * This setting seems to work well but is too untested
194 * to replace the above calculation. Left in for experiementation
195 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
197 return tv.tv_sec * 10 + tv.tv_usec / 100000;
201 static struct spoolss_security_descriptor *winreg_printer_create_default_secdesc(TALLOC_CTX *ctx)
203 SEC_ACE ace[5]; /* max number of ace entries */
207 SEC_DESC *psd = NULL;
211 /* Create an ACE where Everyone is allowed to print */
213 sa = PRINTER_ACE_PRINT;
214 init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
215 sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
217 /* Add the domain admins group if we are a DC */
220 DOM_SID domadmins_sid;
222 sid_compose(&domadmins_sid, get_global_sam_sid(),
223 DOMAIN_GROUP_RID_ADMINS);
225 sa = PRINTER_ACE_FULL_CONTROL;
226 init_sec_ace(&ace[i++], &domadmins_sid,
227 SEC_ACE_TYPE_ACCESS_ALLOWED, sa,
228 SEC_ACE_FLAG_OBJECT_INHERIT | SEC_ACE_FLAG_INHERIT_ONLY);
229 init_sec_ace(&ace[i++], &domadmins_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
230 sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
232 else if (secrets_fetch_domain_sid(lp_workgroup(), &adm_sid)) {
233 sid_append_rid(&adm_sid, DOMAIN_USER_RID_ADMIN);
235 sa = PRINTER_ACE_FULL_CONTROL;
236 init_sec_ace(&ace[i++], &adm_sid,
237 SEC_ACE_TYPE_ACCESS_ALLOWED, sa,
238 SEC_ACE_FLAG_OBJECT_INHERIT | SEC_ACE_FLAG_INHERIT_ONLY);
239 init_sec_ace(&ace[i++], &adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
240 sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
243 /* add BUILTIN\Administrators as FULL CONTROL */
245 sa = PRINTER_ACE_FULL_CONTROL;
246 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
247 SEC_ACE_TYPE_ACCESS_ALLOWED, sa,
248 SEC_ACE_FLAG_OBJECT_INHERIT | SEC_ACE_FLAG_INHERIT_ONLY);
249 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
250 SEC_ACE_TYPE_ACCESS_ALLOWED,
251 sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
253 /* Make the security descriptor owned by the BUILTIN\Administrators */
255 /* The ACL revision number in rpc_secdesc.h differs from the one
256 created by NT when setting ACE entries in printer
257 descriptors. NT4 complains about the property being edited by a
260 if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) != NULL) {
261 psd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE,
262 &global_sid_Builtin_Administrators,
263 &global_sid_Builtin_Administrators,
264 NULL, psa, &sd_size);
268 DEBUG(0,("construct_default_printer_sd: Failed to make SEC_DESC.\n"));
272 DEBUG(4,("construct_default_printer_sdb: size = %u.\n",
273 (unsigned int)sd_size));
278 static struct spoolss_DeviceMode *winreg_printer_create_default_devmode(TALLOC_CTX *mem_ctx,
279 const char *default_devicename)
281 char adevice[MAXDEVICENAME];
282 struct spoolss_DeviceMode *devmode;
284 devmode = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
285 if (devmode == NULL) {
289 slprintf(adevice, sizeof(adevice), "%s", default_devicename);
290 devmode->devicename = talloc_strdup(mem_ctx, adevice);
291 if (devmode->devicename == NULL) {
295 devmode->formname = "Letter";
297 devmode->specversion = DMSPEC_NT4_AND_ABOVE;
298 devmode->driverversion = 0x0400;
299 devmode->size = 0x00DC;
300 devmode->__driverextra_length = 0;
301 devmode->fields = DEVMODE_FORMNAME |
303 DEVMODE_PRINTQUALITY |
304 DEVMODE_DEFAULTSOURCE |
309 devmode->orientation = DMORIENT_PORTRAIT;
310 devmode->papersize = DMPAPER_LETTER;
311 devmode->paperlength = 0;
312 devmode->paperwidth = 0;
313 devmode->scale = 0x64;
315 devmode->defaultsource = DMBIN_FORMSOURCE;
316 devmode->printquality = DMRES_HIGH; /* 0x0258 */
317 devmode->color = DMRES_MONOCHROME;
318 devmode->duplex = DMDUP_SIMPLEX;
319 devmode->yresolution = 0;
320 devmode->ttoption = DMTT_SUBDEV;
321 devmode->collate = DMCOLLATE_FALSE;
322 devmode->icmmethod = 0;
323 devmode->icmintent = 0;
324 devmode->mediatype = 0;
325 devmode->dithertype = 0;
327 devmode->logpixels = 0;
328 devmode->bitsperpel = 0;
329 devmode->pelswidth = 0;
330 devmode->pelsheight = 0;
331 devmode->displayflags = 0;
332 devmode->displayfrequency = 0;
333 devmode->reserved1 = 0;
334 devmode->reserved2 = 0;
335 devmode->panningwidth = 0;
336 devmode->panningheight = 0;
338 devmode->driverextra_data.data = NULL;
339 devmode->driverextra_data.length = 0;
347 * @brief Connect to the interal winreg server and open the given printer key.
349 * The function will create the needed subkeys if they don't exist.
351 * @param[in] mem_ctx The memory context to use.
353 * @param[in] server_info The supplied server info.
355 * @param[out] winreg_pipe A pointer for the winreg rpc client pipe.
357 * @param[in] path The path to the key to open.
359 * @param[in] key The key to open.
361 * @param[in] create_key Set to true if the key should be created if it
364 * @param[in] access_mask The access mask to open the key.
366 * @param[out] hive_handle A policy handle for the opened hive.
368 * @param[out] key_handle A policy handle for the opened key.
370 * @return WERR_OK on success, the corresponding DOS error
371 * code if something gone wrong.
373 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
374 struct auth_serversupplied_info *server_info,
375 struct rpc_pipe_client **winreg_pipe,
379 uint32_t access_mask,
380 struct policy_handle *hive_handle,
381 struct policy_handle *key_handle)
383 struct rpc_pipe_client *pipe_handle;
384 struct winreg_String wkey, wkeyclass;
387 WERROR result = WERR_OK;
389 /* create winreg connection */
390 status = rpc_pipe_open_internal(mem_ctx,
391 &ndr_table_winreg.syntax_id,
395 if (!NT_STATUS_IS_OK(status)) {
396 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg_pipe: %s\n",
398 return ntstatus_to_werror(status);
401 status = rpccli_winreg_OpenHKLM(pipe_handle,
407 if (!NT_STATUS_IS_OK(status)) {
408 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
410 talloc_free(pipe_handle);
411 if (!W_ERROR_IS_OK(result)) {
414 return ntstatus_to_werror(status);
418 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
420 keyname = talloc_strdup(mem_ctx, path);
422 if (keyname == NULL) {
423 talloc_free(pipe_handle);
431 enum winreg_CreateAction action = REG_ACTION_NONE;
433 ZERO_STRUCT(wkeyclass);
436 status = rpccli_winreg_CreateKey(pipe_handle,
448 case REG_ACTION_NONE:
449 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
451 case REG_CREATED_NEW_KEY:
452 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
454 case REG_OPENED_EXISTING_KEY:
455 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
459 status = rpccli_winreg_OpenKey(pipe_handle,
468 if (!NT_STATUS_IS_OK(status)) {
469 talloc_free(pipe_handle);
470 if (!W_ERROR_IS_OK(result)) {
473 return ntstatus_to_werror(status);
476 *winreg_pipe = pipe_handle;
482 * @brief Create the registry keyname for the given printer.
484 * @param[in] mem_ctx The memory context to use.
486 * @param[in] printer The name of the printer to get the registry key.
488 * @return The registry key or NULL on error.
490 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
491 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
497 * @brief Enumerate values of an opened key handle and retrieve the data.
499 * @param[in] mem_ctx The memory context to use.
501 * @param[in] pipe_handle The pipe handle for the rpc connection.
503 * @param[in] key_hnd The opened key handle.
505 * @param[out] pnum_values A pointer to store he number of values found.
507 * @param[out] pnum_values A pointer to store the number of values we found.
509 * @return WERR_OK on success, the corresponding DOS error
510 * code if something gone wrong.
512 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
513 struct rpc_pipe_client *pipe_handle,
514 struct policy_handle *key_hnd,
515 uint32_t *pnum_values,
516 struct spoolss_PrinterEnumValues **penum_values)
519 uint32_t num_subkeys, max_subkeylen, max_classlen;
520 uint32_t num_values, max_valnamelen, max_valbufsize;
521 uint32_t secdescsize;
523 NTTIME last_changed_time;
524 struct winreg_String classname;
526 struct spoolss_PrinterEnumValues *enum_values;
528 WERROR result = WERR_OK;
531 tmp_ctx = talloc_new(mem_ctx);
532 if (tmp_ctx == NULL) {
536 ZERO_STRUCT(classname);
538 status = rpccli_winreg_QueryInfoKey(pipe_handle,
551 if (!NT_STATUS_IS_OK(status)) {
552 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
554 if (!W_ERROR_IS_OK(result)) {
557 result = ntstatus_to_werror(status);
561 if (num_values == 0) {
563 TALLOC_FREE(tmp_ctx);
567 enum_values = TALLOC_ARRAY(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
568 if (enum_values == NULL) {
573 for (i = 0; i < num_values; i++) {
574 struct spoolss_PrinterEnumValues val;
575 struct winreg_ValNameBuf name_buf;
576 enum winreg_Type type = REG_NONE;
577 uint8_t *data = NULL;
583 name_buf.size = max_valnamelen + 2;
586 data_size = max_valbufsize;
587 data = (uint8_t *) TALLOC(tmp_ctx, data_size);
590 status = rpccli_winreg_EnumValue(pipe_handle,
600 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
602 status = NT_STATUS_OK;
606 if (!NT_STATUS_IS_OK(status)) {
607 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
609 if (!W_ERROR_IS_OK(result)) {
612 result = ntstatus_to_werror(status);
616 if (name_buf.name == NULL) {
617 result = WERR_INVALID_PARAMETER;
621 val.value_name = talloc_strdup(enum_values, name_buf.name);
622 if (val.value_name == NULL) {
626 val.value_name_len = strlen_m_term(val.value_name) * 2;
629 val.data_length = data_size;
631 if (val.data_length) {
632 val.data = talloc(enum_values, DATA_BLOB);
633 if (val.data == NULL) {
637 *val.data = data_blob_talloc(enum_values, data, data_size);
640 enum_values[i] = val;
643 *pnum_values = num_values;
645 *penum_values = talloc_move(mem_ctx, &enum_values);
651 TALLOC_FREE(tmp_ctx);
658 * @brief Enumerate subkeys of an opened key handle and get the names.
660 * @param[in] mem_ctx The memory context to use.
662 * @param[in] pipe_handle The pipe handle for the rpc connection.
664 * @param[in] key_hnd The opened key handle.
666 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
668 * @param[in] psubkeys A pointer to an array to store the found names of
671 * @return WERR_OK on success, the corresponding DOS error
672 * code if something gone wrong.
674 static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
675 struct rpc_pipe_client *pipe_handle,
676 struct policy_handle *key_hnd,
677 uint32_t *pnum_subkeys,
678 const char ***psubkeys)
681 const char **subkeys;
682 uint32_t num_subkeys, max_subkeylen, max_classlen;
683 uint32_t num_values, max_valnamelen, max_valbufsize;
685 NTTIME last_changed_time;
686 uint32_t secdescsize;
687 struct winreg_String classname;
688 WERROR result = WERR_OK;
691 tmp_ctx = talloc_new(mem_ctx);
692 if (tmp_ctx == NULL) {
696 ZERO_STRUCT(classname);
698 status = rpccli_winreg_QueryInfoKey(pipe_handle,
711 if (!NT_STATUS_IS_OK(status)) {
712 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
714 if (!W_ERROR_IS_OK(result)) {
717 result = ntstatus_to_werror(status);
721 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
722 if (subkeys == NULL) {
727 if (num_subkeys == 0) {
728 subkeys[0] = talloc_strdup(subkeys, "");
729 if (subkeys[0] == NULL) {
735 *psubkeys = talloc_move(mem_ctx, &subkeys);
738 TALLOC_FREE(tmp_ctx);
742 for (i = 0; i < num_subkeys; i++) {
746 struct winreg_StringBuf class_buf;
747 struct winreg_StringBuf name_buf;
751 class_buf.size = max_classlen + 2;
752 class_buf.length = 0;
755 name_buf.size = max_subkeylen + 2;
758 ZERO_STRUCT(modtime);
760 status = rpccli_winreg_EnumKey(pipe_handle,
768 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
770 status = NT_STATUS_OK;
774 if (!NT_STATUS_IS_OK(status)) {
775 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
777 if (!W_ERROR_IS_OK(result)) {
780 result = ntstatus_to_werror(status);
784 if (name_buf.name == NULL) {
785 result = WERR_INVALID_PARAMETER;
789 name = talloc_strdup(subkeys, name_buf.name);
798 *pnum_subkeys = num_subkeys;
800 *psubkeys = talloc_move(mem_ctx, &subkeys);
804 TALLOC_FREE(tmp_ctx);
811 * @brief A function to delete a key and its subkeys recurively.
813 * @param[in] mem_ctx The memory context to use.
815 * @param[in] pipe_handle The pipe handle for the rpc connection.
817 * @param[in] hive_handle A opened hive handle to the key.
819 * @param[in] access_mask The access mask to access the key.
821 * @param[in] key The key to delete
823 * @return WERR_OK on success, the corresponding DOS error
824 * code if something gone wrong.
826 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
827 struct rpc_pipe_client *pipe_handle,
828 struct policy_handle *hive_handle,
829 uint32_t access_mask,
832 const char **subkeys = NULL;
833 uint32_t num_subkeys = 0;
834 struct policy_handle key_hnd;
835 struct winreg_String wkey;
836 WERROR result = WERR_OK;
840 ZERO_STRUCT(key_hnd);
843 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
845 status = rpccli_winreg_OpenKey(pipe_handle,
853 if (!NT_STATUS_IS_OK(status)) {
854 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
855 wkey.name, nt_errstr(status)));
856 if (!W_ERROR_IS_OK(result)) {
859 return ntstatus_to_werror(status);
862 result = winreg_printer_enumkeys(mem_ctx,
867 if (!W_ERROR_IS_OK(result)) {
871 for (i = 0; i < num_subkeys; i++) {
872 /* create key + subkey */
873 char *subkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkeys[i]);
874 if (subkey == NULL) {
878 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey));
879 result = winreg_printer_delete_subkeys(mem_ctx,
884 if (!W_ERROR_IS_OK(result)) {
889 if (is_valid_policy_hnd(&key_hnd)) {
890 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
895 status = rpccli_winreg_DeleteKey(pipe_handle,
902 if (is_valid_policy_hnd(&key_hnd)) {
903 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
909 static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
910 struct rpc_pipe_client *pipe_handle,
911 struct policy_handle *key_handle,
915 struct winreg_String wvalue;
917 WERROR result = WERR_OK;
922 blob = data_blob_string_const("");
924 if (!push_reg_sz(mem_ctx, NULL, &blob, data)) {
925 DEBUG(0, ("winreg_printer_write_sz: Could not marshall string %s for %s\n",
930 status = rpccli_winreg_SetValue(pipe_handle,
938 if (!NT_STATUS_IS_OK(status)) {
939 DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: %s\n",
940 wvalue.name, win_errstr(result)));
941 if (!W_ERROR_IS_OK(result)) {
942 result = ntstatus_to_werror(status);
949 static WERROR winreg_printer_write_dword(TALLOC_CTX *mem_ctx,
950 struct rpc_pipe_client *pipe_handle,
951 struct policy_handle *key_handle,
955 struct winreg_String wvalue;
957 WERROR result = WERR_OK;
961 blob = data_blob_talloc(mem_ctx, NULL, 4);
962 SIVAL(blob.data, 0, data);
964 status = rpccli_winreg_SetValue(pipe_handle,
972 if (!NT_STATUS_IS_OK(status)) {
973 DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: %s\n",
974 wvalue.name, win_errstr(result)));
975 if (!W_ERROR_IS_OK(result)) {
976 result = ntstatus_to_werror(status);
983 static WERROR winreg_printer_write_binary(TALLOC_CTX *mem_ctx,
984 struct rpc_pipe_client *pipe_handle,
985 struct policy_handle *key_handle,
989 struct winreg_String wvalue;
990 WERROR result = WERR_OK;
994 status = rpccli_winreg_SetValue(pipe_handle,
1002 if (!NT_STATUS_IS_OK(status)) {
1003 DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: %s\n",
1004 wvalue.name, win_errstr(result)));
1005 if (!W_ERROR_IS_OK(result)) {
1006 result = ntstatus_to_werror(status);
1013 static WERROR winreg_printer_query_binary(TALLOC_CTX *mem_ctx,
1014 struct rpc_pipe_client *pipe_handle,
1015 struct policy_handle *key_handle,
1019 struct winreg_String wvalue;
1020 enum winreg_Type type;
1021 WERROR result = WERR_OK;
1022 uint32_t value_len = 0;
1023 uint32_t data_size = 0;
1027 wvalue.name = value;
1028 status = rpccli_winreg_QueryValue(pipe_handle,
1037 if (!NT_STATUS_IS_OK(status)) {
1038 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1039 wvalue.name, nt_errstr(status)));
1040 if (!W_ERROR_IS_OK(result)) {
1043 result = ntstatus_to_werror(status);
1047 if (type != REG_BINARY) {
1048 result = WERR_INVALID_DATATYPE;
1051 blob = data_blob_talloc(mem_ctx, NULL, data_size);
1052 if (blob.data == NULL) {
1053 result = WERR_NOMEM;
1058 status = rpccli_winreg_QueryValue(pipe_handle,
1067 if (!NT_STATUS_IS_OK(status)) {
1068 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1069 wvalue.name, nt_errstr(status)));
1070 if (!W_ERROR_IS_OK(result)) {
1071 result = ntstatus_to_werror(status);
1077 data->data = blob.data;
1078 data->length = blob.length;
1084 static WERROR winreg_printer_query_dword(TALLOC_CTX *mem_ctx,
1085 struct rpc_pipe_client *pipe_handle,
1086 struct policy_handle *key_handle,
1090 struct winreg_String wvalue;
1091 enum winreg_Type type;
1092 WERROR result = WERR_OK;
1093 uint32_t value_len = 0;
1094 uint32_t data_size = 0;
1098 wvalue.name = value;
1099 status = rpccli_winreg_QueryValue(pipe_handle,
1108 if (!NT_STATUS_IS_OK(status)) {
1109 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1110 wvalue.name, nt_errstr(status)));
1111 if (!W_ERROR_IS_OK(result)) {
1114 result = ntstatus_to_werror(status);
1118 if (type != REG_DWORD) {
1119 result = WERR_INVALID_DATATYPE;
1123 if (data_size != 4) {
1124 result = WERR_INVALID_DATA;
1128 blob = data_blob_talloc(mem_ctx, NULL, data_size);
1129 if (blob.data == NULL) {
1130 result = WERR_NOMEM;
1135 status = rpccli_winreg_QueryValue(pipe_handle,
1144 if (!NT_STATUS_IS_OK(status)) {
1145 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1146 wvalue.name, nt_errstr(status)));
1147 if (!W_ERROR_IS_OK(result)) {
1148 result = ntstatus_to_werror(status);
1154 *data = IVAL(blob.data, 0);
1160 static WERROR winreg_printer_write_multi_sz(TALLOC_CTX *mem_ctx,
1161 struct rpc_pipe_client *pipe_handle,
1162 struct policy_handle *key_handle,
1166 struct winreg_String wvalue;
1168 WERROR result = WERR_OK;
1171 wvalue.name = value;
1172 if (!push_reg_multi_sz(mem_ctx, NULL, &blob, data)) {
1175 status = rpccli_winreg_SetValue(pipe_handle,
1183 if (!NT_STATUS_IS_OK(status)) {
1184 DEBUG(0, ("winreg_printer_write_multi_sz: Could not set value %s: %s\n",
1185 wvalue.name, win_errstr(result)));
1186 if (!W_ERROR_IS_OK(result)) {
1187 result = ntstatus_to_werror(status);
1194 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
1195 struct auth_serversupplied_info *server_info,
1196 const char *drivername,
1197 const char *architecture,
1199 uint32_t access_mask,
1201 struct rpc_pipe_client **winreg_pipe,
1202 struct policy_handle *hive_hnd,
1203 struct policy_handle *key_hnd)
1208 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
1209 TOP_LEVEL_CONTROL_KEY,
1210 architecture, version);
1215 result = winreg_printer_openkey(mem_ctx,
1227 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
1228 struct spoolss_PrinterEnumValues *v,
1229 const char *valuename, uint32_t *dw)
1231 /* just return if it is not the one we are looking for */
1232 if (strcmp(valuename, v->value_name) != 0) {
1233 return WERR_NOT_FOUND;
1236 if (v->type != REG_DWORD) {
1237 return WERR_INVALID_DATATYPE;
1240 *dw = IVAL(v->data->data, 0);
1244 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
1245 struct spoolss_PrinterEnumValues *v,
1246 const char *valuename, const char **_str)
1248 /* just return if it is not the one we are looking for */
1249 if (strcmp(valuename, v->value_name) != 0) {
1250 return WERR_NOT_FOUND;
1253 if (v->type != REG_SZ) {
1254 return WERR_INVALID_DATATYPE;
1257 if (!pull_reg_sz(mem_ctx, NULL, v->data, _str)) {
1264 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
1265 struct spoolss_PrinterEnumValues *v,
1266 const char *valuename,
1267 const char ***array)
1269 /* just return if it is not the one we are looking for */
1270 if (strcmp(valuename, v->value_name) != 0) {
1271 return WERR_NOT_FOUND;
1274 if (v->type != REG_MULTI_SZ) {
1275 return WERR_INVALID_DATATYPE;
1278 if (!pull_reg_multi_sz(mem_ctx, NULL, v->data, array)) {
1285 static WERROR winreg_enumval_to_blob(TALLOC_CTX *mem_ctx,
1286 struct spoolss_PrinterEnumValues *v,
1287 const char *valuename,
1290 /* just return if it is not the one we are looking for */
1291 if (strcmp(valuename, v->value_name) != 0) {
1292 return WERR_NOT_FOUND;
1295 if (v->type != REG_BINARY) {
1296 return WERR_INVALID_DATATYPE;
1299 blob->data = v->data->data;
1300 blob->length = v->data_length;
1305 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
1306 struct rpc_pipe_client *pipe_handle,
1307 struct policy_handle *key_handle,
1311 struct winreg_String wvalue;
1313 WERROR result = WERR_OK;
1319 t = nt_time_to_unix(data);
1321 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
1322 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
1327 wvalue.name = value;
1328 if (!push_reg_sz(mem_ctx, NULL, &blob, str)) {
1331 status = rpccli_winreg_SetValue(pipe_handle,
1339 if (!NT_STATUS_IS_OK(status)) {
1340 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1341 wvalue.name, win_errstr(result)));
1342 if (!W_ERROR_IS_OK(result)) {
1343 result = ntstatus_to_werror(status);
1350 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
1357 if (sscanf(str, "%d/%d/%d",
1358 &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3) {
1359 return WERR_INVALID_PARAMETER;
1366 unix_to_nt_time(data, t);
1371 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
1372 struct rpc_pipe_client *pipe_handle,
1373 struct policy_handle *key_handle,
1377 struct winreg_String wvalue;
1379 WERROR result = WERR_OK;
1383 /* FIXME: check format is right,
1384 * this needs to be something like: 6.1.7600.16385 */
1385 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
1386 (unsigned)((data >> 48) & 0xFFFF),
1387 (unsigned)((data >> 32) & 0xFFFF),
1388 (unsigned)((data >> 16) & 0xFFFF),
1389 (unsigned)(data & 0xFFFF));
1394 wvalue.name = value;
1395 if (!push_reg_sz(mem_ctx, NULL, &blob, str)) {
1398 status = rpccli_winreg_SetValue(pipe_handle,
1406 if (!NT_STATUS_IS_OK(status)) {
1407 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1408 wvalue.name, win_errstr(result)));
1409 if (!W_ERROR_IS_OK(result)) {
1410 result = ntstatus_to_werror(status);
1417 static WERROR winreg_printer_ver_to_dword(const char *str, uint64_t *data)
1419 unsigned int v1, v2, v3, v4;
1421 if (sscanf(str, "%u.%u.%u.%u", &v1, &v2, &v3, &v4) != 4) {
1422 return WERR_INVALID_PARAMETER;
1425 *data = ((uint64_t)(v1 & 0xFFFF) << 48) +
1426 ((uint64_t)(v2 & 0xFFFF) << 32) +
1427 ((uint64_t)(v3 & 0xFFFF) << 16) +
1428 (uint64_t)(v2 & 0xFFFF);
1433 /********************************************************************
1434 Public winreg function for spoolss
1435 ********************************************************************/
1437 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
1438 struct auth_serversupplied_info *server_info,
1439 const char *servername,
1440 const char *sharename)
1442 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1443 struct rpc_pipe_client *winreg_pipe = NULL;
1444 struct policy_handle hive_hnd, key_hnd;
1445 struct spoolss_SetPrinterInfo2 *info2;
1446 struct spoolss_DeviceMode *devmode = NULL;
1447 struct security_descriptor *secdesc;
1448 struct winreg_String wkey, wkeyclass;
1450 const char *subkeys[] = { "DsDriver", "DsSpooler", "PrinterDriverData" };
1451 uint32_t i, count = ARRAY_SIZE(subkeys);
1452 int snum = lp_servicenumber(sharename);
1453 uint32_t info2_mask = 0;
1454 WERROR result = WERR_OK;
1455 TALLOC_CTX *tmp_ctx;
1457 tmp_ctx = talloc_new(mem_ctx);
1458 if (tmp_ctx == NULL) {
1462 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1464 TALLOC_FREE(tmp_ctx);
1468 ZERO_STRUCT(hive_hnd);
1469 ZERO_STRUCT(key_hnd);
1471 result = winreg_printer_openkey(tmp_ctx,
1480 if (W_ERROR_IS_OK(result)) {
1481 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
1483 } else if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1484 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
1485 } else if (!W_ERROR_IS_OK(result)) {
1486 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
1487 path, win_errstr(result)));
1491 /* Create the main key */
1492 result = winreg_printer_openkey(tmp_ctx,
1501 if (!W_ERROR_IS_OK(result)) {
1502 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1503 path, win_errstr(result)));
1507 if (is_valid_policy_hnd(&key_hnd)) {
1508 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1511 /* Create subkeys */
1512 for (i = 0; i < count; i++) {
1514 enum winreg_CreateAction action = REG_ACTION_NONE;
1516 ZERO_STRUCT(key_hnd);
1519 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
1520 if (wkey.name == NULL) {
1521 result = WERR_NOMEM;
1525 ZERO_STRUCT(wkeyclass);
1526 wkeyclass.name = "";
1528 status = rpccli_winreg_CreateKey(winreg_pipe,
1539 if (!NT_STATUS_IS_OK(status)) {
1540 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1541 wkey.name, win_errstr(result)));
1542 if (!W_ERROR_IS_OK(result)) {
1543 result = ntstatus_to_werror(status);
1548 if (is_valid_policy_hnd(&key_hnd)) {
1549 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1552 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
1553 if (info2 == NULL) {
1554 result = WERR_NOMEM;
1558 info2->printername = sharename;
1559 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1561 info2->sharename = sharename;
1562 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1564 info2->portname = SAMBA_PRINTER_PORT_NAME;
1565 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1567 info2->printprocessor = "winprint";
1568 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1570 info2->datatype = "RAW";
1571 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1573 info2->comment = "";
1574 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1576 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1577 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1579 info2->starttime = 0; /* Minutes since 12:00am GMT */
1580 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1582 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1583 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1585 info2->priority = 1;
1586 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1588 info2->defaultpriority = 1;
1589 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1591 /* info2->setuptime = (uint32_t) time(NULL); */
1593 if (lp_default_devmode(snum)) {
1594 devmode = winreg_printer_create_default_devmode(tmp_ctx,
1595 info2->printername);
1596 if (devmode == NULL) {
1597 result = WERR_NOMEM;
1601 info2_mask |= SPOOLSS_PRINTER_INFO_DEVMODE;
1604 secdesc = winreg_printer_create_default_secdesc(tmp_ctx);
1605 if (secdesc == NULL) {
1606 result = WERR_NOMEM;
1609 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1611 result = winreg_update_printer(tmp_ctx,
1620 if (winreg_pipe != NULL) {
1621 if (is_valid_policy_hnd(&key_hnd)) {
1622 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1624 if (is_valid_policy_hnd(&hive_hnd)) {
1625 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1629 talloc_free(tmp_ctx);
1633 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1634 struct auth_serversupplied_info *server_info,
1635 const char *sharename,
1636 uint32_t info2_mask,
1637 struct spoolss_SetPrinterInfo2 *info2,
1638 struct spoolss_DeviceMode *devmode,
1639 struct security_descriptor *secdesc)
1641 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1642 struct rpc_pipe_client *winreg_pipe = NULL;
1643 struct policy_handle hive_hnd, key_hnd;
1644 enum ndr_err_code ndr_err;
1647 WERROR result = WERR_OK;
1648 TALLOC_CTX *tmp_ctx;
1650 tmp_ctx = talloc_new(mem_ctx);
1651 if (tmp_ctx == NULL) {
1655 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1657 TALLOC_FREE(tmp_ctx);
1661 ZERO_STRUCT(hive_hnd);
1662 ZERO_STRUCT(key_hnd);
1664 result = winreg_printer_openkey(tmp_ctx,
1673 if (!W_ERROR_IS_OK(result)) {
1674 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1675 path, win_errstr(result)));
1679 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1680 result = winreg_printer_write_dword(tmp_ctx,
1685 if (!W_ERROR_IS_OK(result)) {
1691 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1692 result = winreg_printer_write_dword(tmp_ctx,
1697 if (!W_ERROR_IS_OK(result)) {
1703 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1704 result = winreg_printer_write_sz(tmp_ctx,
1709 if (!W_ERROR_IS_OK(result)) {
1714 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1715 result = winreg_printer_write_sz(tmp_ctx,
1720 if (!W_ERROR_IS_OK(result)) {
1725 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1726 result = winreg_printer_write_dword(tmp_ctx,
1730 info2->defaultpriority);
1731 if (!W_ERROR_IS_OK(result)) {
1736 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1737 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, NULL, 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 secdesc = winreg_printer_create_default_secdesc(tmp_ctx);
1857 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, NULL, secdesc,
1858 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
1859 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1860 DEBUG(0, ("winreg_update_printer: Failed to marshall security descriptor\n"));
1861 result = WERR_NOMEM;
1865 result = winreg_printer_write_binary(tmp_ctx,
1870 if (!W_ERROR_IS_OK(result)) {
1875 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1876 result = winreg_printer_write_sz(tmp_ctx,
1881 if (!W_ERROR_IS_OK(result)) {
1886 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1887 result = winreg_printer_write_sz(tmp_ctx,
1892 if (!W_ERROR_IS_OK(result)) {
1897 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1898 result = winreg_printer_write_dword(tmp_ctx,
1903 if (!W_ERROR_IS_OK(result)) {
1908 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1909 result = winreg_printer_write_dword(tmp_ctx,
1914 if (!W_ERROR_IS_OK(result)) {
1919 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1920 result = winreg_printer_write_dword(tmp_ctx,
1925 if (!W_ERROR_IS_OK(result)) {
1930 result = winreg_printer_write_dword(tmp_ctx,
1934 winreg_printer_rev_changeid());
1935 if (!W_ERROR_IS_OK(result)) {
1941 if (winreg_pipe != NULL) {
1942 if (is_valid_policy_hnd(&key_hnd)) {
1943 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1945 if (is_valid_policy_hnd(&hive_hnd)) {
1946 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1950 TALLOC_FREE(tmp_ctx);
1954 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1955 struct auth_serversupplied_info *server_info,
1956 const char *servername,
1957 const char *printer,
1958 struct spoolss_PrinterInfo2 **pinfo2)
1960 struct spoolss_PrinterInfo2 *info2;
1961 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1962 struct rpc_pipe_client *winreg_pipe = NULL;
1963 struct policy_handle hive_hnd, key_hnd;
1964 struct spoolss_PrinterEnumValues *enum_values = NULL;
1965 struct spoolss_PrinterEnumValues *v;
1966 enum ndr_err_code ndr_err;
1968 uint32_t num_values = 0;
1971 WERROR result = WERR_OK;
1972 TALLOC_CTX *tmp_ctx;
1974 tmp_ctx = talloc_new(mem_ctx);
1975 if (tmp_ctx == NULL) {
1979 path = winreg_printer_data_keyname(tmp_ctx, printer);
1981 TALLOC_FREE(tmp_ctx);
1985 result = winreg_printer_openkey(tmp_ctx,
1994 if (!W_ERROR_IS_OK(result)) {
1995 DEBUG(0, ("winreg_get_printer: Could not open key %s: %s\n",
1996 path, win_errstr(result)));
2000 result = winreg_printer_enumvalues(tmp_ctx,
2005 if (!W_ERROR_IS_OK(result)) {
2006 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
2007 path, win_errstr(result)));
2011 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
2012 if (info2 == NULL) {
2013 result = WERR_NOMEM;
2017 info2->servername = EMPTY_STRING;
2018 info2->printername = EMPTY_STRING;
2019 info2->sharename = EMPTY_STRING;
2020 info2->portname = EMPTY_STRING;
2021 info2->drivername = EMPTY_STRING;
2022 info2->comment = EMPTY_STRING;
2023 info2->location = EMPTY_STRING;
2024 info2->sepfile = EMPTY_STRING;
2025 info2->printprocessor = EMPTY_STRING;
2026 info2->datatype = EMPTY_STRING;
2027 info2->parameters = EMPTY_STRING;
2029 if (servername != NULL && servername[0] != '\0') {
2030 info2->servername = talloc_asprintf(info2, "\\\\%s", servername);
2031 if (info2->servername == NULL) {
2032 result = WERR_NOMEM;
2037 for (i = 0; i < num_values; i++) {
2038 v = &enum_values[i];
2040 result = winreg_enumval_to_sz(info2,
2043 &info2->printername);
2044 if (W_ERROR_IS_OK(result) && info2->servername[0] != '\0') {
2045 char *p = talloc_asprintf(info2, "%s\\%s",
2047 info2->printername);
2049 result = WERR_NOMEM;
2051 info2->printername = p;
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,
2071 CHECK_ERROR(result);
2073 result = winreg_enumval_to_sz(info2,
2077 CHECK_ERROR(result);
2079 result = winreg_enumval_to_sz(info2,
2083 CHECK_ERROR(result);
2085 result = winreg_enumval_to_sz(info2,
2088 &info2->printprocessor);
2089 CHECK_ERROR(result);
2091 result = winreg_enumval_to_sz(info2,
2095 CHECK_ERROR(result);
2097 result = winreg_enumval_to_sz(info2,
2100 &info2->parameters);
2101 CHECK_ERROR(result);
2103 result = winreg_enumval_to_sz(info2,
2106 &info2->drivername);
2107 CHECK_ERROR(result);
2109 result = winreg_enumval_to_dword(info2,
2112 &info2->attributes);
2113 CHECK_ERROR(result);
2115 result = winreg_enumval_to_dword(info2,
2119 CHECK_ERROR(result);
2121 result = winreg_enumval_to_dword(info2,
2124 &info2->defaultpriority);
2125 CHECK_ERROR(result);
2127 result = winreg_enumval_to_dword(info2,
2131 CHECK_ERROR(result);
2133 result = winreg_enumval_to_dword(info2,
2137 CHECK_ERROR(result);
2139 result = winreg_enumval_to_dword(info2,
2143 CHECK_ERROR(result);
2145 result = winreg_enumval_to_dword(info2,
2149 CHECK_ERROR(result);
2151 result = winreg_enumval_to_blob(info2,
2155 if (W_ERROR_IS_OK(result)) {
2156 info2->devmode = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
2157 if (info2->devmode == NULL) {
2158 result = WERR_NOMEM;
2161 ndr_err = ndr_pull_struct_blob(&blob,
2165 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
2166 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2167 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2168 result = WERR_NOMEM;
2172 CHECK_ERROR(result);
2174 result = winreg_enumval_to_blob(info2,
2178 if (W_ERROR_IS_OK(result)) {
2179 info2->secdesc = talloc_zero(mem_ctx, struct spoolss_security_descriptor);
2180 if (info2->secdesc == NULL) {
2181 result = WERR_NOMEM;
2184 ndr_err = ndr_pull_struct_blob(&blob,
2188 (ndr_pull_flags_fn_t) ndr_pull_security_descriptor);
2189 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2190 DEBUG(0, ("winreg_get_printer: Failed to unmarshall security descriptor\n"));
2191 result = WERR_NOMEM;
2195 CHECK_ERROR(result);
2198 if (!W_ERROR_IS_OK(result)) {
2199 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2202 win_errstr(result)));
2207 *pinfo2 = talloc_move(mem_ctx, &info2);
2212 if (winreg_pipe != NULL) {
2213 if (is_valid_policy_hnd(&key_hnd)) {
2214 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2216 if (is_valid_policy_hnd(&hive_hnd)) {
2217 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2221 TALLOC_FREE(tmp_ctx);
2225 /* Set printer data over the winreg pipe. */
2226 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2227 struct auth_serversupplied_info *server_info,
2228 const char *printer,
2231 enum winreg_Type type,
2235 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2236 struct rpc_pipe_client *winreg_pipe = NULL;
2237 struct policy_handle hive_hnd, key_hnd;
2238 struct winreg_String wvalue;
2240 WERROR result = WERR_OK;
2242 TALLOC_CTX *tmp_ctx;
2244 tmp_ctx = talloc_new(mem_ctx);
2245 if (tmp_ctx == NULL) {
2249 path = winreg_printer_data_keyname(tmp_ctx, printer);
2251 TALLOC_FREE(tmp_ctx);
2255 ZERO_STRUCT(hive_hnd);
2256 ZERO_STRUCT(key_hnd);
2258 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2259 key, value, access_mask, printer));
2260 result = winreg_printer_openkey(tmp_ctx,
2269 if (!W_ERROR_IS_OK(result)) {
2270 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2271 key, win_errstr(result)));
2275 wvalue.name = value;
2276 status = rpccli_winreg_SetValue(winreg_pipe,
2284 if (!NT_STATUS_IS_OK(status)) {
2285 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2286 value, nt_errstr(status)));
2287 if (!W_ERROR_IS_OK(result)) {
2290 result = ntstatus_to_werror(status);
2296 if (winreg_pipe != NULL) {
2297 if (is_valid_policy_hnd(&key_hnd)) {
2298 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2300 if (is_valid_policy_hnd(&hive_hnd)) {
2301 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2305 TALLOC_FREE(tmp_ctx);
2309 /* Get printer data over a winreg pipe. */
2310 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2311 struct auth_serversupplied_info *server_info,
2312 const char *printer,
2315 enum winreg_Type *type,
2317 uint32_t *data_size)
2319 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2320 struct rpc_pipe_client *winreg_pipe = NULL;
2321 struct policy_handle hive_hnd, key_hnd;
2322 struct winreg_String wvalue;
2323 enum winreg_Type type_in;
2326 uint32_t data_in_size = 0;
2327 uint32_t value_len = 0;
2328 WERROR result = WERR_OK;
2330 TALLOC_CTX *tmp_ctx;
2332 tmp_ctx = talloc_new(mem_ctx);
2333 if (tmp_ctx == NULL) {
2337 path = winreg_printer_data_keyname(tmp_ctx, printer);
2339 TALLOC_FREE(tmp_ctx);
2343 ZERO_STRUCT(hive_hnd);
2344 ZERO_STRUCT(key_hnd);
2346 result = winreg_printer_openkey(tmp_ctx,
2355 if (!W_ERROR_IS_OK(result)) {
2356 DEBUG(0, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2357 key, win_errstr(result)));
2361 wvalue.name = value;
2364 * call QueryValue once with data == NULL to get the
2365 * needed memory size to be allocated, then allocate
2366 * data buffer and call again.
2368 status = rpccli_winreg_QueryValue(winreg_pipe,
2377 if (!NT_STATUS_IS_OK(status)) {
2378 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2379 value, nt_errstr(status)));
2380 if (!W_ERROR_IS_OK(result)) {
2383 result = ntstatus_to_werror(status);
2387 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2388 if (data_in == NULL) {
2389 result = WERR_NOMEM;
2394 status = rpccli_winreg_QueryValue(winreg_pipe,
2403 if (!NT_STATUS_IS_OK(status)) {
2404 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2405 value, nt_errstr(status)));
2406 if (!W_ERROR_IS_OK(result)) {
2407 result = ntstatus_to_werror(status);
2413 *data_size = data_in_size;
2415 *data = talloc_move(mem_ctx, &data_in);
2420 if (winreg_pipe != NULL) {
2421 if (is_valid_policy_hnd(&key_hnd)) {
2422 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2424 if (is_valid_policy_hnd(&hive_hnd)) {
2425 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2429 TALLOC_FREE(tmp_ctx);
2433 /* Enumerate on the values of a given key and provide the data. */
2434 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2435 struct auth_serversupplied_info *server_info,
2436 const char *printer,
2438 uint32_t *pnum_values,
2439 struct spoolss_PrinterEnumValues **penum_values)
2441 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2442 struct rpc_pipe_client *winreg_pipe = NULL;
2443 struct policy_handle hive_hnd, key_hnd;
2445 struct spoolss_PrinterEnumValues *enum_values = NULL;
2446 uint32_t num_values = 0;
2448 WERROR result = WERR_OK;
2450 TALLOC_CTX *tmp_ctx;
2452 tmp_ctx = talloc_new(mem_ctx);
2453 if (tmp_ctx == NULL) {
2457 path = winreg_printer_data_keyname(tmp_ctx, printer);
2459 TALLOC_FREE(tmp_ctx);
2463 result = winreg_printer_openkey(tmp_ctx,
2472 if (!W_ERROR_IS_OK(result)) {
2473 DEBUG(0, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2474 key, win_errstr(result)));
2478 result = winreg_printer_enumvalues(tmp_ctx,
2483 if (!W_ERROR_IS_OK(result)) {
2484 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2485 key, win_errstr(result)));
2489 *pnum_values = num_values;
2491 *penum_values = talloc_move(mem_ctx, &enum_values);
2496 if (winreg_pipe != NULL) {
2497 if (is_valid_policy_hnd(&key_hnd)) {
2498 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2500 if (is_valid_policy_hnd(&hive_hnd)) {
2501 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2505 TALLOC_FREE(tmp_ctx);
2509 /* Delete printer data over a winreg pipe. */
2510 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2511 struct auth_serversupplied_info *server_info,
2512 const char *printer,
2516 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2517 struct rpc_pipe_client *winreg_pipe = NULL;
2518 struct policy_handle hive_hnd, key_hnd;
2519 struct winreg_String wvalue;
2521 WERROR result = WERR_OK;
2524 TALLOC_CTX *tmp_ctx;
2526 tmp_ctx = talloc_new(mem_ctx);
2527 if (tmp_ctx == NULL) {
2531 path = winreg_printer_data_keyname(tmp_ctx, printer);
2533 TALLOC_FREE(tmp_ctx);
2537 ZERO_STRUCT(hive_hnd);
2538 ZERO_STRUCT(key_hnd);
2540 result = winreg_printer_openkey(tmp_ctx,
2549 if (!W_ERROR_IS_OK(result)) {
2550 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2551 key, win_errstr(result)));
2555 wvalue.name = value;
2556 status = rpccli_winreg_DeleteValue(winreg_pipe,
2561 if (!NT_STATUS_IS_OK(status)) {
2562 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2563 value, nt_errstr(status)));
2564 if (!W_ERROR_IS_OK(result)) {
2567 result = ntstatus_to_werror(status);
2573 if (winreg_pipe != NULL) {
2574 if (is_valid_policy_hnd(&key_hnd)) {
2575 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2577 if (is_valid_policy_hnd(&hive_hnd)) {
2578 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2582 TALLOC_FREE(tmp_ctx);
2586 /* Enumerate on the subkeys of a given key and provide the data. */
2587 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2588 struct auth_serversupplied_info *server_info,
2589 const char *printer,
2591 uint32_t *pnum_subkeys,
2592 const char ***psubkeys)
2594 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2595 struct rpc_pipe_client *winreg_pipe = NULL;
2596 struct policy_handle hive_hnd, key_hnd;
2598 const char **subkeys = NULL;
2599 uint32_t num_subkeys = -1;
2601 WERROR result = WERR_OK;
2603 TALLOC_CTX *tmp_ctx;
2605 tmp_ctx = talloc_new(mem_ctx);
2606 if (tmp_ctx == NULL) {
2610 path = winreg_printer_data_keyname(tmp_ctx, printer);
2612 TALLOC_FREE(tmp_ctx);
2616 ZERO_STRUCT(hive_hnd);
2617 ZERO_STRUCT(key_hnd);
2619 result = winreg_printer_openkey(tmp_ctx,
2628 if (!W_ERROR_IS_OK(result)) {
2629 DEBUG(0, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2630 key, win_errstr(result)));
2634 result = winreg_printer_enumkeys(tmp_ctx,
2639 if (!W_ERROR_IS_OK(result)) {
2640 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2641 key, win_errstr(result)));
2645 *pnum_subkeys = num_subkeys;
2647 *psubkeys = talloc_move(mem_ctx, &subkeys);
2652 if (winreg_pipe != NULL) {
2653 if (is_valid_policy_hnd(&key_hnd)) {
2654 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2656 if (is_valid_policy_hnd(&hive_hnd)) {
2657 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2661 TALLOC_FREE(tmp_ctx);
2665 /* Delete a key with subkeys of a given printer. */
2666 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
2667 struct auth_serversupplied_info *server_info,
2668 const char *printer,
2671 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2672 struct rpc_pipe_client *winreg_pipe = NULL;
2673 struct policy_handle hive_hnd, key_hnd;
2677 TALLOC_CTX *tmp_ctx;
2679 tmp_ctx = talloc_new(mem_ctx);
2680 if (tmp_ctx == NULL) {
2684 path = winreg_printer_data_keyname(tmp_ctx, printer);
2686 TALLOC_FREE(tmp_ctx);
2690 result = winreg_printer_openkey(tmp_ctx,
2699 if (!W_ERROR_IS_OK(result)) {
2700 /* key doesn't exist */
2701 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2706 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2707 key, win_errstr(result)));
2711 if (is_valid_policy_hnd(&key_hnd)) {
2712 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2715 if (key == NULL || key[0] == '\0') {
2718 keyname = talloc_asprintf(tmp_ctx,
2722 if (keyname == NULL) {
2723 result = WERR_NOMEM;
2728 result = winreg_printer_delete_subkeys(tmp_ctx,
2733 if (!W_ERROR_IS_OK(result)) {
2734 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2735 key, win_errstr(result)));
2740 if (winreg_pipe != NULL) {
2741 if (is_valid_policy_hnd(&key_hnd)) {
2742 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2744 if (is_valid_policy_hnd(&hive_hnd)) {
2745 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2749 TALLOC_FREE(tmp_ctx);
2753 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
2754 struct auth_serversupplied_info *server_info,
2755 const char *printer)
2757 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2758 struct rpc_pipe_client *winreg_pipe = NULL;
2759 struct policy_handle hive_hnd, key_hnd;
2762 TALLOC_CTX *tmp_ctx;
2764 tmp_ctx = talloc_new(mem_ctx);
2765 if (tmp_ctx == NULL) {
2769 path = winreg_printer_data_keyname(tmp_ctx, printer);
2771 TALLOC_FREE(tmp_ctx);
2775 ZERO_STRUCT(hive_hnd);
2776 ZERO_STRUCT(key_hnd);
2778 result = winreg_printer_openkey(tmp_ctx,
2787 if (!W_ERROR_IS_OK(result)) {
2788 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2789 path, win_errstr(result)));
2793 result = winreg_printer_write_dword(tmp_ctx,
2797 winreg_printer_rev_changeid());
2798 if (!W_ERROR_IS_OK(result)) {
2804 if (winreg_pipe != NULL) {
2805 if (is_valid_policy_hnd(&key_hnd)) {
2806 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2808 if (is_valid_policy_hnd(&hive_hnd)) {
2809 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2813 TALLOC_FREE(tmp_ctx);
2817 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
2818 struct auth_serversupplied_info *server_info,
2819 const char *printer,
2820 uint32_t *pchangeid)
2822 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2823 struct rpc_pipe_client *winreg_pipe = NULL;
2824 struct policy_handle hive_hnd, key_hnd;
2825 uint32_t changeid = 0;
2828 TALLOC_CTX *tmp_ctx;
2830 tmp_ctx = talloc_new(mem_ctx);
2831 if (tmp_ctx == NULL) {
2835 path = winreg_printer_data_keyname(tmp_ctx, printer);
2837 TALLOC_FREE(tmp_ctx);
2841 ZERO_STRUCT(hive_hnd);
2842 ZERO_STRUCT(key_hnd);
2844 result = winreg_printer_openkey(tmp_ctx,
2853 if (!W_ERROR_IS_OK(result)) {
2854 DEBUG(0, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2855 path, win_errstr(result)));
2859 DEBUG(0, ("winreg_printer_get_changeid: get changeid from %s\n", path));
2860 result = winreg_printer_query_dword(tmp_ctx,
2865 if (!W_ERROR_IS_OK(result)) {
2870 *pchangeid = changeid;
2875 if (winreg_pipe != NULL) {
2876 if (is_valid_policy_hnd(&key_hnd)) {
2877 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2879 if (is_valid_policy_hnd(&hive_hnd)) {
2880 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2884 TALLOC_FREE(tmp_ctx);
2889 * The special behaviour of the spoolss forms is documented at the website:
2891 * Managing Win32 Printserver Forms
2892 * http://unixwiz.net/techtips/winspooler-forms.html
2895 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
2896 struct auth_serversupplied_info *server_info,
2897 struct spoolss_AddFormInfo1 *form)
2899 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2900 struct rpc_pipe_client *winreg_pipe = NULL;
2901 struct policy_handle hive_hnd, key_hnd;
2902 struct winreg_String wvalue;
2904 uint32_t num_info = 0;
2905 union spoolss_FormInfo *info = NULL;
2909 TALLOC_CTX *tmp_ctx;
2911 tmp_ctx = talloc_new(mem_ctx);
2912 if (tmp_ctx == NULL) {
2916 ZERO_STRUCT(hive_hnd);
2917 ZERO_STRUCT(key_hnd);
2919 result = winreg_printer_openkey(tmp_ctx,
2922 TOP_LEVEL_CONTROL_FORMS_KEY,
2928 if (!W_ERROR_IS_OK(result)) {
2929 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2930 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2934 result = winreg_printer_enumforms1(tmp_ctx, server_info, &num_info, &info);
2935 if (!W_ERROR_IS_OK(result)) {
2936 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2937 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2941 /* If form name already exists or is builtin return ALREADY_EXISTS */
2942 for (i = 0; i < num_info; i++) {
2943 if (strequal(info[i].info1.form_name, form->form_name)) {
2944 result = WERR_FILE_EXISTS;
2949 wvalue.name = form->form_name;
2951 blob = data_blob_talloc(tmp_ctx, NULL, 32);
2952 SIVAL(blob.data, 0, form->size.width);
2953 SIVAL(blob.data, 4, form->size.height);
2954 SIVAL(blob.data, 8, form->area.left);
2955 SIVAL(blob.data, 12, form->area.top);
2956 SIVAL(blob.data, 16, form->area.right);
2957 SIVAL(blob.data, 20, form->area.bottom);
2958 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
2959 SIVAL(blob.data, 28, form->flags);
2961 status = rpccli_winreg_SetValue(winreg_pipe,
2969 if (!NT_STATUS_IS_OK(status)) {
2970 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2971 wvalue.name, nt_errstr(status)));
2972 if (!W_ERROR_IS_OK(result)) {
2975 result = ntstatus_to_werror(status);
2981 if (winreg_pipe != NULL) {
2982 if (is_valid_policy_hnd(&key_hnd)) {
2983 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2985 if (is_valid_policy_hnd(&hive_hnd)) {
2986 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2991 TALLOC_FREE(tmp_ctx);
2995 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
2996 struct auth_serversupplied_info *server_info,
2997 uint32_t *pnum_info,
2998 union spoolss_FormInfo **pinfo)
3000 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3001 struct rpc_pipe_client *winreg_pipe = NULL;
3002 struct policy_handle hive_hnd, key_hnd;
3003 union spoolss_FormInfo *info;
3004 struct spoolss_PrinterEnumValues *enum_values = NULL;
3005 uint32_t num_values = 0;
3006 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3009 TALLOC_CTX *tmp_ctx;
3011 tmp_ctx = talloc_new(mem_ctx);
3012 if (tmp_ctx == NULL) {
3016 ZERO_STRUCT(hive_hnd);
3017 ZERO_STRUCT(key_hnd);
3019 result = winreg_printer_openkey(tmp_ctx,
3022 TOP_LEVEL_CONTROL_FORMS_KEY,
3028 if (!W_ERROR_IS_OK(result)) {
3029 /* key doesn't exist */
3030 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3035 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3036 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3040 result = winreg_printer_enumvalues(tmp_ctx,
3045 if (!W_ERROR_IS_OK(result)) {
3046 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3047 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3051 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
3053 result = WERR_NOMEM;
3057 /* Enumerate BUILTIN forms */
3058 for (i = 0; i < num_builtin; i++) {
3059 info[i].info1 = builtin_forms1[i];
3062 /* Enumerate registry forms */
3063 for (i = 0; i < num_values; i++) {
3064 union spoolss_FormInfo val;
3066 if (enum_values[i].type != REG_BINARY ||
3067 enum_values[i].data_length != 32) {
3071 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
3072 if (val.info1.form_name == NULL) {
3073 result = WERR_NOMEM;
3077 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
3078 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
3079 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
3080 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
3081 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
3082 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
3083 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3084 val.info1.flags = IVAL(enum_values[i].data->data, 28);
3086 info[i + num_builtin] = val;
3089 *pnum_info = num_builtin + num_values;
3091 *pinfo = talloc_move(mem_ctx, &info);
3095 if (winreg_pipe != NULL) {
3096 if (is_valid_policy_hnd(&key_hnd)) {
3097 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3099 if (is_valid_policy_hnd(&hive_hnd)) {
3100 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3104 TALLOC_FREE(enum_values);
3105 TALLOC_FREE(tmp_ctx);
3109 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3110 struct auth_serversupplied_info *server_info,
3111 const char *form_name)
3113 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3114 struct rpc_pipe_client *winreg_pipe = NULL;
3115 struct policy_handle hive_hnd, key_hnd;
3116 struct winreg_String wvalue;
3117 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3119 WERROR result = WERR_OK;
3121 TALLOC_CTX *tmp_ctx;
3123 for (i = 0; i < num_builtin; i++) {
3124 if (strequal(builtin_forms1[i].form_name, form_name)) {
3125 return WERR_INVALID_PARAMETER;
3129 tmp_ctx = talloc_new(mem_ctx);
3130 if (tmp_ctx == NULL) {
3134 ZERO_STRUCT(hive_hnd);
3135 ZERO_STRUCT(key_hnd);
3137 result = winreg_printer_openkey(tmp_ctx,
3140 TOP_LEVEL_CONTROL_FORMS_KEY,
3146 if (!W_ERROR_IS_OK(result)) {
3147 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3148 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3149 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3150 result = WERR_INVALID_FORM_NAME;
3155 wvalue.name = form_name;
3156 status = rpccli_winreg_DeleteValue(winreg_pipe,
3161 if (!NT_STATUS_IS_OK(status)) {
3162 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3163 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3164 result = WERR_INVALID_FORM_NAME;
3167 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3168 wvalue.name, nt_errstr(status)));
3169 if (!W_ERROR_IS_OK(result)) {
3172 result = ntstatus_to_werror(status);
3178 if (winreg_pipe != NULL) {
3179 if (is_valid_policy_hnd(&key_hnd)) {
3180 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3182 if (is_valid_policy_hnd(&hive_hnd)) {
3183 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3187 TALLOC_FREE(tmp_ctx);
3191 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3192 struct auth_serversupplied_info *server_info,
3193 const char *form_name,
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_builtin = ARRAY_SIZE(builtin_forms1);
3205 TALLOC_CTX *tmp_ctx = NULL;
3207 for (i = 0; i < num_builtin; i++) {
3208 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3209 result = WERR_INVALID_PARAM;
3214 tmp_ctx = talloc_new(mem_ctx);
3215 if (tmp_ctx == NULL) {
3219 ZERO_STRUCT(hive_hnd);
3220 ZERO_STRUCT(key_hnd);
3222 result = winreg_printer_openkey(tmp_ctx,
3225 TOP_LEVEL_CONTROL_FORMS_KEY,
3231 if (!W_ERROR_IS_OK(result)) {
3232 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3233 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3237 /* If form_name != form->form_name then we renamed the form */
3238 if (strequal(form_name, form->form_name)) {
3239 result = winreg_printer_deleteform1(tmp_ctx, server_info, form_name);
3240 if (!W_ERROR_IS_OK(result)) {
3241 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3242 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3247 wvalue.name = form->form_name;
3249 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3250 SIVAL(blob.data, 0, form->size.width);
3251 SIVAL(blob.data, 4, form->size.height);
3252 SIVAL(blob.data, 8, form->area.left);
3253 SIVAL(blob.data, 12, form->area.top);
3254 SIVAL(blob.data, 16, form->area.right);
3255 SIVAL(blob.data, 20, form->area.bottom);
3256 SIVAL(blob.data, 24, 42);
3257 SIVAL(blob.data, 28, form->flags);
3259 status = rpccli_winreg_SetValue(winreg_pipe,
3267 if (!NT_STATUS_IS_OK(status)) {
3268 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3269 wvalue.name, nt_errstr(status)));
3270 if (!W_ERROR_IS_OK(result)) {
3273 result = ntstatus_to_werror(status);
3279 if (winreg_pipe != NULL) {
3280 if (is_valid_policy_hnd(&key_hnd)) {
3281 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3283 if (is_valid_policy_hnd(&hive_hnd)) {
3284 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3288 TALLOC_FREE(tmp_ctx);
3292 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3293 struct auth_serversupplied_info *server_info,
3294 const char *form_name,
3295 struct spoolss_FormInfo1 *r)
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 struct winreg_String wvalue;
3301 enum winreg_Type type_in;
3303 uint32_t data_in_size = 0;
3304 uint32_t value_len = 0;
3305 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3309 TALLOC_CTX *tmp_ctx;
3311 /* check builtin forms first */
3312 for (i = 0; i < num_builtin; i++) {
3313 if (strequal(builtin_forms1[i].form_name, form_name)) {
3314 *r = builtin_forms1[i];
3319 tmp_ctx = talloc_new(mem_ctx);
3320 if (tmp_ctx == NULL) {
3324 ZERO_STRUCT(hive_hnd);
3325 ZERO_STRUCT(key_hnd);
3327 result = winreg_printer_openkey(tmp_ctx,
3330 TOP_LEVEL_CONTROL_FORMS_KEY,
3336 if (!W_ERROR_IS_OK(result)) {
3337 DEBUG(0, ("winreg_printer_getform1: Could not open key %s: %s\n",
3338 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3342 wvalue.name = form_name;
3345 * call QueryValue once with data == NULL to get the
3346 * needed memory size to be allocated, then allocate
3347 * data buffer and call again.
3349 status = rpccli_winreg_QueryValue(winreg_pipe,
3358 if (!NT_STATUS_IS_OK(status)) {
3359 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3360 wvalue.name, nt_errstr(status)));
3361 if (!W_ERROR_IS_OK(result)) {
3364 result = ntstatus_to_werror(status);
3368 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3369 if (data_in == NULL) {
3370 result = WERR_NOMEM;
3375 status = rpccli_winreg_QueryValue(winreg_pipe,
3384 if (!NT_STATUS_IS_OK(status)) {
3385 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3386 wvalue.name, nt_errstr(status)));
3387 if (!W_ERROR_IS_OK(result)) {
3390 result = ntstatus_to_werror(status);
3394 r->form_name = talloc_strdup(mem_ctx, form_name);
3395 if (r->form_name == NULL) {
3396 result = WERR_NOMEM;
3400 r->size.width = IVAL(data_in, 0);
3401 r->size.height = IVAL(data_in, 4);
3402 r->area.left = IVAL(data_in, 8);
3403 r->area.top = IVAL(data_in, 12);
3404 r->area.right = IVAL(data_in, 16);
3405 r->area.bottom = IVAL(data_in, 20);
3406 /* skip index IVAL(data_in, 24)));*/
3407 r->flags = IVAL(data_in, 28);
3411 if (winreg_pipe != NULL) {
3412 if (is_valid_policy_hnd(&key_hnd)) {
3413 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3415 if (is_valid_policy_hnd(&hive_hnd)) {
3416 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3420 TALLOC_FREE(tmp_ctx);
3424 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3425 struct auth_serversupplied_info *server_info,
3426 struct spoolss_AddDriverInfoCtr *r,
3427 const char **driver_name,
3428 uint32_t *driver_version)
3430 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3431 struct rpc_pipe_client *winreg_pipe = NULL;
3432 struct policy_handle hive_hnd, key_hnd;
3433 struct spoolss_DriverInfo8 info8;
3434 TALLOC_CTX *tmp_ctx = NULL;
3437 ZERO_STRUCT(hive_hnd);
3438 ZERO_STRUCT(key_hnd);
3441 if (!driver_info_ctr_to_info8(r, &info8)) {
3442 result = WERR_INVALID_PARAMETER;
3446 tmp_ctx = talloc_new(mem_ctx);
3447 if (tmp_ctx == NULL) {
3451 result = winreg_printer_opendriver(tmp_ctx,
3460 if (!W_ERROR_IS_OK(result)) {
3461 DEBUG(0, ("winreg_add_driver: "
3462 "Could not open driver key (%s,%s,%d): %s\n",
3463 info8.driver_name, info8.architecture,
3464 info8.version, win_errstr(result)));
3468 /* TODO: "Attributes" ? */
3470 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe,
3471 &key_hnd, "Version",
3473 if (!W_ERROR_IS_OK(result)) {
3477 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3480 if (!W_ERROR_IS_OK(result)) {
3484 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3485 &key_hnd, "Data File",
3487 if (!W_ERROR_IS_OK(result)) {
3491 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3492 &key_hnd, "Configuration File",
3494 if (!W_ERROR_IS_OK(result)) {
3498 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3499 &key_hnd, "Help File",
3501 if (!W_ERROR_IS_OK(result)) {
3505 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3506 &key_hnd, "Dependent Files",
3507 info8.dependent_files);
3508 if (!W_ERROR_IS_OK(result)) {
3512 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3513 &key_hnd, "Monitor",
3514 info8.monitor_name);
3515 if (!W_ERROR_IS_OK(result)) {
3519 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3520 &key_hnd, "Datatype",
3521 info8.default_datatype);
3522 if (!W_ERROR_IS_OK(result)) {
3526 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3527 &key_hnd, "Previous Names",
3528 info8.previous_names);
3529 if (!W_ERROR_IS_OK(result)) {
3533 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3534 &key_hnd, "DriverDate",
3536 if (!W_ERROR_IS_OK(result)) {
3540 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe,
3541 &key_hnd, "DriverVersion",
3542 info8.driver_version);
3543 if (!W_ERROR_IS_OK(result)) {
3547 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3548 &key_hnd, "Manufacturer",
3549 info8.manufacturer_name);
3550 if (!W_ERROR_IS_OK(result)) {
3554 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3555 &key_hnd, "OEM URL",
3556 info8.manufacturer_url);
3557 if (!W_ERROR_IS_OK(result)) {
3561 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3562 &key_hnd, "HardwareID",
3564 if (!W_ERROR_IS_OK(result)) {
3568 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3569 &key_hnd, "Provider",
3571 if (!W_ERROR_IS_OK(result)) {
3575 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3576 &key_hnd, "Print Processor",
3577 info8.print_processor);
3578 if (!W_ERROR_IS_OK(result)) {
3582 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3583 &key_hnd, "VendorSetup",
3584 info8.vendor_setup);
3585 if (!W_ERROR_IS_OK(result)) {
3589 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3590 &key_hnd, "Color Profiles",
3591 info8.color_profiles);
3592 if (!W_ERROR_IS_OK(result)) {
3596 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3597 &key_hnd, "InfPath",
3599 if (!W_ERROR_IS_OK(result)) {
3603 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe, &key_hnd,
3604 "PrinterDriverAttributes",
3605 info8.printer_driver_attributes);
3606 if (!W_ERROR_IS_OK(result)) {
3610 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3611 &key_hnd, "CoreDependencies",
3612 info8.core_driver_dependencies);
3613 if (!W_ERROR_IS_OK(result)) {
3617 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3618 &key_hnd, "MinInboxDriverVerDate",
3619 info8.min_inbox_driver_ver_date);
3620 if (!W_ERROR_IS_OK(result)) {
3624 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe, &key_hnd,
3625 "MinInboxDriverVerVersion",
3626 info8.min_inbox_driver_ver_version);
3627 if (!W_ERROR_IS_OK(result)) {
3631 *driver_name = info8.driver_name;
3632 *driver_version = info8.version;
3635 if (winreg_pipe != NULL) {
3636 if (is_valid_policy_hnd(&key_hnd)) {
3637 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3639 if (is_valid_policy_hnd(&hive_hnd)) {
3640 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3644 TALLOC_FREE(tmp_ctx);
3648 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
3649 struct auth_serversupplied_info *server_info,
3650 const char *architecture,
3651 const char *driver_name,
3652 uint32_t driver_version,
3653 struct spoolss_DriverInfo8 **_info8)
3655 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3656 struct rpc_pipe_client *winreg_pipe = NULL;
3657 struct policy_handle hive_hnd, key_hnd;
3658 struct spoolss_DriverInfo8 i8, *info8;
3659 struct spoolss_PrinterEnumValues *enum_values = NULL;
3660 struct spoolss_PrinterEnumValues *v;
3661 uint32_t num_values = 0;
3662 TALLOC_CTX *tmp_ctx;
3666 ZERO_STRUCT(hive_hnd);
3667 ZERO_STRUCT(key_hnd);
3670 tmp_ctx = talloc_new(mem_ctx);
3671 if (tmp_ctx == NULL) {
3675 if (driver_version == DRIVER_ANY_VERSION) {
3676 /* look for Win2k first and then for NT4 */
3677 result = winreg_printer_opendriver(tmp_ctx,
3686 if (!W_ERROR_IS_OK(result)) {
3687 result = winreg_printer_opendriver(tmp_ctx,
3698 /* ok normal case */
3699 result = winreg_printer_opendriver(tmp_ctx,
3709 if (!W_ERROR_IS_OK(result)) {
3710 DEBUG(5, ("winreg_get_driver: "
3711 "Could not open driver key (%s,%s,%d): %s\n",
3712 driver_name, architecture,
3713 driver_version, win_errstr(result)));
3717 result = winreg_printer_enumvalues(tmp_ctx,
3722 if (!W_ERROR_IS_OK(result)) {
3723 DEBUG(0, ("winreg_get_driver: "
3724 "Could not enumerate values for (%s,%s,%d): %s\n",
3725 driver_name, architecture,
3726 driver_version, win_errstr(result)));
3730 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
3731 if (info8 == NULL) {
3732 result = WERR_NOMEM;
3736 info8->driver_name = talloc_strdup(info8, driver_name);
3737 if (info8->driver_name == NULL) {
3738 result = WERR_NOMEM;
3742 info8->architecture = talloc_strdup(info8, architecture);
3743 if (info8->architecture == NULL) {
3744 result = WERR_NOMEM;
3748 info8->config_file = EMPTY_STRING;
3749 info8->data_file = EMPTY_STRING;
3750 info8->default_datatype = EMPTY_STRING;
3751 info8->driver_path = EMPTY_STRING;
3752 info8->hardware_id = EMPTY_STRING;
3753 info8->help_file = EMPTY_STRING;
3754 info8->inf_path = EMPTY_STRING;
3755 info8->manufacturer_name = EMPTY_STRING;
3756 info8->manufacturer_url = EMPTY_STRING;
3757 info8->monitor_name = EMPTY_STRING;
3758 info8->print_processor = EMPTY_STRING;
3759 info8->provider = EMPTY_STRING;
3760 info8->vendor_setup = EMPTY_STRING;
3762 info8->color_profiles = empty_string_array;
3763 info8->core_driver_dependencies = EMPTY_STRING_ARRAY;
3764 info8->dependent_files = EMPTY_STRING_ARRAY;
3765 info8->previous_names = EMPTY_STRING_ARRAY;
3769 for (i = 0; i < num_values; i++) {
3770 const char *tmp_str;
3772 v = &enum_values[i];
3774 result = winreg_enumval_to_dword(info8, v,
3777 CHECK_ERROR(result);
3779 result = winreg_enumval_to_sz(info8, v,
3781 &info8->driver_path);
3782 CHECK_ERROR(result);
3784 result = winreg_enumval_to_sz(info8, v,
3787 CHECK_ERROR(result);
3789 result = winreg_enumval_to_sz(info8, v,
3790 "Configuration File",
3791 &info8->config_file);
3792 CHECK_ERROR(result);
3794 result = winreg_enumval_to_sz(info8, v,
3797 CHECK_ERROR(result);
3799 result = winreg_enumval_to_multi_sz(info8, v,
3801 &info8->dependent_files);
3802 CHECK_ERROR(result);
3804 result = winreg_enumval_to_sz(info8, v,
3806 &info8->monitor_name);
3807 CHECK_ERROR(result);
3809 result = winreg_enumval_to_sz(info8, v,
3811 &info8->default_datatype);
3812 CHECK_ERROR(result);
3814 result = winreg_enumval_to_multi_sz(info8, v,
3816 &info8->previous_names);
3817 CHECK_ERROR(result);
3819 result = winreg_enumval_to_sz(info8, v,
3822 if (W_ERROR_IS_OK(result)) {
3823 result = winreg_printer_date_to_NTTIME(tmp_str,
3824 &info8->driver_date);
3826 CHECK_ERROR(result);
3828 result = winreg_enumval_to_sz(info8, v,
3831 if (W_ERROR_IS_OK(result)) {
3832 result = winreg_printer_ver_to_dword(tmp_str,
3833 &info8->driver_version);
3835 CHECK_ERROR(result);
3837 result = winreg_enumval_to_sz(info8, v,
3839 &info8->manufacturer_name);
3840 CHECK_ERROR(result);
3842 result = winreg_enumval_to_sz(info8, v,
3844 &info8->manufacturer_url);
3845 CHECK_ERROR(result);
3847 result = winreg_enumval_to_sz(info8, v,
3849 &info8->hardware_id);
3850 CHECK_ERROR(result);
3852 result = winreg_enumval_to_sz(info8, v,
3855 CHECK_ERROR(result);
3857 result = winreg_enumval_to_sz(info8, v,
3859 &info8->print_processor);
3860 CHECK_ERROR(result);
3862 result = winreg_enumval_to_sz(info8, v,
3864 &info8->vendor_setup);
3865 CHECK_ERROR(result);
3867 result = winreg_enumval_to_multi_sz(info8, v,
3869 &info8->color_profiles);
3870 CHECK_ERROR(result);
3872 result = winreg_enumval_to_sz(info8, v,
3875 CHECK_ERROR(result);
3877 result = winreg_enumval_to_dword(info8, v,
3878 "PrinterDriverAttributes",
3879 &info8->printer_driver_attributes);
3880 CHECK_ERROR(result);
3882 result = winreg_enumval_to_multi_sz(info8, v,
3884 &info8->core_driver_dependencies);
3885 CHECK_ERROR(result);
3887 result = winreg_enumval_to_sz(info8, v,
3888 "MinInboxDriverVerDate",
3890 if (W_ERROR_IS_OK(result)) {
3891 result = winreg_printer_date_to_NTTIME(tmp_str,
3892 &info8->min_inbox_driver_ver_date);
3894 CHECK_ERROR(result);
3896 result = winreg_enumval_to_sz(info8, v,
3897 "MinInboxDriverVerVersion",
3899 if (W_ERROR_IS_OK(result)) {
3900 result = winreg_printer_ver_to_dword(tmp_str,
3901 &info8->min_inbox_driver_ver_version);
3903 CHECK_ERROR(result);
3906 if (!W_ERROR_IS_OK(result)) {
3907 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3908 "for %s: %s\n", v->value_name,
3909 win_errstr(result)));
3913 *_info8 = talloc_steal(mem_ctx, info8);
3916 if (winreg_pipe != NULL) {
3917 if (is_valid_policy_hnd(&key_hnd)) {
3918 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3920 if (is_valid_policy_hnd(&hive_hnd)) {
3921 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3925 TALLOC_FREE(tmp_ctx);
3929 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
3930 struct auth_serversupplied_info *server_info,
3931 struct spoolss_DriverInfo8 *info8,
3934 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3935 struct rpc_pipe_client *winreg_pipe = NULL;
3936 struct policy_handle hive_hnd, key_hnd;
3937 TALLOC_CTX *tmp_ctx;
3941 ZERO_STRUCT(hive_hnd);
3942 ZERO_STRUCT(key_hnd);
3944 tmp_ctx = talloc_new(mem_ctx);
3945 if (tmp_ctx == NULL) {
3949 /* test that the key exists */
3950 result = winreg_printer_opendriver(tmp_ctx,
3953 info8->architecture,
3959 if (!W_ERROR_IS_OK(result)) {
3960 /* key doesn't exist */
3961 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3966 DEBUG(5, ("winreg_del_driver: "
3967 "Could not open driver (%s,%s,%u): %s\n",
3968 info8->driver_name, info8->architecture,
3969 version, win_errstr(result)));
3974 if (is_valid_policy_hnd(&key_hnd)) {
3975 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3978 key_name = talloc_asprintf(tmp_ctx,
3979 "%s\\Environments\\%s\\Drivers\\Version-%u",
3980 TOP_LEVEL_CONTROL_KEY,
3981 info8->architecture, version);
3982 if (key_name == NULL) {
3983 result = WERR_NOMEM;
3987 result = winreg_printer_delete_subkeys(tmp_ctx,
3992 if (!W_ERROR_IS_OK(result)) {
3993 DEBUG(0, ("winreg_del_driver: "
3994 "Could not open driver (%s,%s,%u): %s\n",
3995 info8->driver_name, info8->architecture,
3996 version, win_errstr(result)));
4002 if (winreg_pipe != NULL) {
4003 if (is_valid_policy_hnd(&key_hnd)) {
4004 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4006 if (is_valid_policy_hnd(&hive_hnd)) {
4007 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4011 TALLOC_FREE(tmp_ctx);
4015 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
4016 struct auth_serversupplied_info *server_info,
4017 const char *architecture,
4019 uint32_t *num_drivers,
4020 const char ***drivers_p)
4022 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
4023 struct rpc_pipe_client *winreg_pipe = NULL;
4024 struct policy_handle hive_hnd, key_hnd;
4025 const char **drivers;
4026 TALLOC_CTX *tmp_ctx;
4029 ZERO_STRUCT(hive_hnd);
4030 ZERO_STRUCT(key_hnd);
4032 tmp_ctx = talloc_new(mem_ctx);
4033 if (tmp_ctx == NULL) {
4037 /* use NULL for the driver name so we open the key that is
4038 * parent of all drivers for this architecture and version */
4039 result = winreg_printer_opendriver(tmp_ctx,
4048 if (!W_ERROR_IS_OK(result)) {
4049 DEBUG(5, ("winreg_get_driver_list: "
4050 "Could not open key (%s,%u): %s\n",
4051 architecture, version, win_errstr(result)));
4055 result = winreg_printer_enumkeys(tmp_ctx,
4060 if (!W_ERROR_IS_OK(result)) {
4061 DEBUG(0, ("winreg_get_driver_list: "
4062 "Could not enumerate drivers for (%s,%u): %s\n",
4063 architecture, version, win_errstr(result)));
4067 *drivers_p = talloc_steal(mem_ctx, drivers);
4071 if (winreg_pipe != NULL) {
4072 if (is_valid_policy_hnd(&key_hnd)) {
4073 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
4075 if (is_valid_policy_hnd(&hive_hnd)) {
4076 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
4080 TALLOC_FREE(tmp_ctx);