s3-spoolss: Added missing Printer Driver in winreg_{update,get}_printer.
[Samba/ekacnet.git] / source3 / rpc_server / srv_spoolss_util.c
blobb70090f44b34659bda4350b808134b199bc062df
1 /*
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/>.
22 #include "includes.h"
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 ""
34 #define CHECK_ERROR(result) \
35 if (W_ERROR_IS_OK(result)) continue; \
36 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
37 if (!W_ERROR_IS_OK(result)) break
39 /* FLAGS, NAME, with, height, left, top, right, bottom */
40 static const struct spoolss_FormInfo1 builtin_forms1[] = {
41 { SPOOLSS_FORM_BUILTIN, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
42 { SPOOLSS_FORM_BUILTIN, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
43 { SPOOLSS_FORM_BUILTIN, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
44 { SPOOLSS_FORM_BUILTIN, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
45 { SPOOLSS_FORM_BUILTIN, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
46 { SPOOLSS_FORM_BUILTIN, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
47 { SPOOLSS_FORM_BUILTIN, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
48 { SPOOLSS_FORM_BUILTIN, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
49 { SPOOLSS_FORM_BUILTIN, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
50 { SPOOLSS_FORM_BUILTIN, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
51 { SPOOLSS_FORM_BUILTIN, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
52 { SPOOLSS_FORM_BUILTIN, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
53 { SPOOLSS_FORM_BUILTIN, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
54 { SPOOLSS_FORM_BUILTIN, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
55 { SPOOLSS_FORM_BUILTIN, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
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, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
59 { SPOOLSS_FORM_BUILTIN, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
60 { SPOOLSS_FORM_BUILTIN, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
61 { SPOOLSS_FORM_BUILTIN, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
62 { SPOOLSS_FORM_BUILTIN, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
63 { SPOOLSS_FORM_BUILTIN, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
64 { SPOOLSS_FORM_BUILTIN, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
65 { SPOOLSS_FORM_BUILTIN, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
66 { SPOOLSS_FORM_BUILTIN, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
67 { SPOOLSS_FORM_BUILTIN, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
68 { SPOOLSS_FORM_BUILTIN, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
69 { SPOOLSS_FORM_BUILTIN, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
70 { SPOOLSS_FORM_BUILTIN, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
71 { SPOOLSS_FORM_BUILTIN, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
72 { SPOOLSS_FORM_BUILTIN, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
73 { SPOOLSS_FORM_BUILTIN, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
74 { SPOOLSS_FORM_BUILTIN, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
75 { SPOOLSS_FORM_BUILTIN, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
76 { SPOOLSS_FORM_BUILTIN, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
77 { SPOOLSS_FORM_BUILTIN, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
78 { SPOOLSS_FORM_BUILTIN, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
79 { SPOOLSS_FORM_BUILTIN, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} },
80 { SPOOLSS_FORM_BUILTIN, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
81 { SPOOLSS_FORM_BUILTIN, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
82 { SPOOLSS_FORM_BUILTIN, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
83 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
84 { SPOOLSS_FORM_BUILTIN, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
85 { SPOOLSS_FORM_BUILTIN, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
86 { SPOOLSS_FORM_BUILTIN, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
87 { SPOOLSS_FORM_BUILTIN, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
88 { SPOOLSS_FORM_BUILTIN, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
89 { SPOOLSS_FORM_BUILTIN, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
90 { SPOOLSS_FORM_BUILTIN, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
91 { SPOOLSS_FORM_BUILTIN, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
92 { SPOOLSS_FORM_BUILTIN, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
93 { SPOOLSS_FORM_BUILTIN, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
94 { SPOOLSS_FORM_BUILTIN, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
95 { SPOOLSS_FORM_BUILTIN, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
96 { SPOOLSS_FORM_BUILTIN, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
97 { SPOOLSS_FORM_BUILTIN, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
98 { SPOOLSS_FORM_BUILTIN, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
99 { SPOOLSS_FORM_BUILTIN, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
100 { SPOOLSS_FORM_BUILTIN, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
101 { SPOOLSS_FORM_BUILTIN, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
102 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
103 { SPOOLSS_FORM_BUILTIN, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
104 { SPOOLSS_FORM_BUILTIN, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
105 { SPOOLSS_FORM_BUILTIN, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
106 { SPOOLSS_FORM_BUILTIN, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
107 { SPOOLSS_FORM_BUILTIN, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
108 { SPOOLSS_FORM_BUILTIN, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
109 { SPOOLSS_FORM_BUILTIN, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
110 { SPOOLSS_FORM_BUILTIN, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
111 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
112 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
113 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
114 { SPOOLSS_FORM_BUILTIN, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
115 { SPOOLSS_FORM_BUILTIN, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
116 { SPOOLSS_FORM_BUILTIN, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
117 { SPOOLSS_FORM_BUILTIN, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
118 { SPOOLSS_FORM_BUILTIN, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
119 { SPOOLSS_FORM_BUILTIN, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
120 { SPOOLSS_FORM_BUILTIN, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
121 { SPOOLSS_FORM_BUILTIN, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
122 { SPOOLSS_FORM_BUILTIN, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
123 { SPOOLSS_FORM_BUILTIN, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
124 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
125 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
126 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
127 { SPOOLSS_FORM_BUILTIN, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
128 { SPOOLSS_FORM_BUILTIN, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
129 { SPOOLSS_FORM_BUILTIN, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
130 { SPOOLSS_FORM_BUILTIN, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
131 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
132 { SPOOLSS_FORM_BUILTIN, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
133 { SPOOLSS_FORM_BUILTIN, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
134 { SPOOLSS_FORM_BUILTIN, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
135 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
136 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
137 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
138 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
139 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
140 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
141 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
142 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
143 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
144 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
145 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
146 { SPOOLSS_FORM_BUILTIN, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
147 { SPOOLSS_FORM_BUILTIN, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
148 { SPOOLSS_FORM_BUILTIN, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
149 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
150 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
151 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
152 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
153 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
154 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
155 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
156 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
157 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
158 { SPOOLSS_FORM_BUILTIN, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} }
161 /********************************************************************
162 static helper functions
163 ********************************************************************/
165 /****************************************************************************
166 Update the changeid time.
167 ****************************************************************************/
169 * @internal
171 * @brief Update the ChangeID time of a printer.
173 * This is SO NASTY as some drivers need this to change, others need it
174 * static. This value will change every second, and I must hope that this
175 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
176 * UTAH ! JRA.
178 * @return The ChangeID.
180 static uint32_t winreg_printer_rev_changeid(void)
182 struct timeval tv;
184 get_process_uptime(&tv);
186 #if 1 /* JERRY */
187 /* Return changeid as msec since spooler restart */
188 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
189 #else
191 * This setting seems to work well but is too untested
192 * to replace the above calculation. Left in for experiementation
193 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
195 return tv.tv_sec * 10 + tv.tv_usec / 100000;
196 #endif
199 static struct spoolss_security_descriptor *winreg_printer_create_default_secdesc(TALLOC_CTX *ctx)
201 SEC_ACE ace[5]; /* max number of ace entries */
202 int i = 0;
203 uint32_t sa;
204 SEC_ACL *psa = NULL;
205 SEC_DESC *psd = NULL;
206 DOM_SID adm_sid;
207 size_t sd_size;
209 /* Create an ACE where Everyone is allowed to print */
211 sa = PRINTER_ACE_PRINT;
212 init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
213 sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
215 /* Add the domain admins group if we are a DC */
217 if ( IS_DC ) {
218 DOM_SID domadmins_sid;
220 sid_compose(&domadmins_sid, get_global_sam_sid(),
221 DOMAIN_GROUP_RID_ADMINS);
223 sa = PRINTER_ACE_FULL_CONTROL;
224 init_sec_ace(&ace[i++], &domadmins_sid,
225 SEC_ACE_TYPE_ACCESS_ALLOWED, sa,
226 SEC_ACE_FLAG_OBJECT_INHERIT | SEC_ACE_FLAG_INHERIT_ONLY);
227 init_sec_ace(&ace[i++], &domadmins_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
228 sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
230 else if (secrets_fetch_domain_sid(lp_workgroup(), &adm_sid)) {
231 sid_append_rid(&adm_sid, DOMAIN_USER_RID_ADMIN);
233 sa = PRINTER_ACE_FULL_CONTROL;
234 init_sec_ace(&ace[i++], &adm_sid,
235 SEC_ACE_TYPE_ACCESS_ALLOWED, sa,
236 SEC_ACE_FLAG_OBJECT_INHERIT | SEC_ACE_FLAG_INHERIT_ONLY);
237 init_sec_ace(&ace[i++], &adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
238 sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
241 /* add BUILTIN\Administrators as FULL CONTROL */
243 sa = PRINTER_ACE_FULL_CONTROL;
244 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
245 SEC_ACE_TYPE_ACCESS_ALLOWED, sa,
246 SEC_ACE_FLAG_OBJECT_INHERIT | SEC_ACE_FLAG_INHERIT_ONLY);
247 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
248 SEC_ACE_TYPE_ACCESS_ALLOWED,
249 sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
251 /* Make the security descriptor owned by the BUILTIN\Administrators */
253 /* The ACL revision number in rpc_secdesc.h differs from the one
254 created by NT when setting ACE entries in printer
255 descriptors. NT4 complains about the property being edited by a
256 NT5 machine. */
258 if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) != NULL) {
259 psd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE,
260 &global_sid_Builtin_Administrators,
261 &global_sid_Builtin_Administrators,
262 NULL, psa, &sd_size);
265 if (!psd) {
266 DEBUG(0,("construct_default_printer_sd: Failed to make SEC_DESC.\n"));
267 return NULL;
270 DEBUG(4,("construct_default_printer_sdb: size = %u.\n",
271 (unsigned int)sd_size));
273 return psd;
276 static struct spoolss_DeviceMode *winreg_printer_create_default_devmode(TALLOC_CTX *mem_ctx,
277 const char *default_devicename)
279 char adevice[MAXDEVICENAME];
280 struct spoolss_DeviceMode *devmode;
282 devmode = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
283 if (devmode == NULL) {
284 return NULL;
287 slprintf(adevice, sizeof(adevice), "%s", default_devicename);
288 devmode->devicename = talloc_strdup(mem_ctx, adevice);
289 if (devmode->devicename == NULL) {
290 return NULL;
293 devmode->formname = "Letter";
295 devmode->specversion = DMSPEC_NT4_AND_ABOVE;
296 devmode->driverversion = 0x0400;
297 devmode->size = 0x00DC;
298 devmode->__driverextra_length = 0;
299 devmode->fields = DEVMODE_FORMNAME |
300 DEVMODE_TTOPTION |
301 DEVMODE_PRINTQUALITY |
302 DEVMODE_DEFAULTSOURCE |
303 DEVMODE_COPIES |
304 DEVMODE_SCALE |
305 DEVMODE_PAPERSIZE |
306 DEVMODE_ORIENTATION;
307 devmode->orientation = DMORIENT_PORTRAIT;
308 devmode->papersize = DMPAPER_LETTER;
309 devmode->paperlength = 0;
310 devmode->paperwidth = 0;
311 devmode->scale = 0x64;
312 devmode->copies = 1;
313 devmode->defaultsource = DMBIN_FORMSOURCE;
314 devmode->printquality = DMRES_HIGH; /* 0x0258 */
315 devmode->color = DMRES_MONOCHROME;
316 devmode->duplex = DMDUP_SIMPLEX;
317 devmode->yresolution = 0;
318 devmode->ttoption = DMTT_SUBDEV;
319 devmode->collate = DMCOLLATE_FALSE;
320 devmode->icmmethod = 0;
321 devmode->icmintent = 0;
322 devmode->mediatype = 0;
323 devmode->dithertype = 0;
325 devmode->logpixels = 0;
326 devmode->bitsperpel = 0;
327 devmode->pelswidth = 0;
328 devmode->pelsheight = 0;
329 devmode->displayflags = 0;
330 devmode->displayfrequency = 0;
331 devmode->reserved1 = 0;
332 devmode->reserved2 = 0;
333 devmode->panningwidth = 0;
334 devmode->panningheight = 0;
336 devmode->driverextra_data.data = NULL;
337 devmode->driverextra_data.length = 0;
339 return devmode;
343 * @internal
345 * @brief Connect to the interal winreg server and open the given printer key.
347 * The function will create the needed subkeys if they don't exist.
349 * @param[in] mem_ctx The memory context to use.
351 * @param[in] server_info The supplied server info.
353 * @param[out] winreg_pipe A pointer for the winreg rpc client pipe.
355 * @param[in] path The path to the key to open.
357 * @param[in] key The key to open.
359 * @param[in] create_key Set to true if the key should be created if it
360 * doesn't exist.
362 * @param[in] access_mask The access mask to open the key.
364 * @param[out] hive_handle A policy handle for the opened hive.
366 * @param[out] key_handle A policy handle for the opened key.
368 * @return WERR_OK on success, the corresponding DOS error
369 * code if something gone wrong.
371 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
372 struct auth_serversupplied_info *server_info,
373 struct rpc_pipe_client **winreg_pipe,
374 const char *path,
375 const char *key,
376 bool create_key,
377 uint32_t access_mask,
378 struct policy_handle *hive_handle,
379 struct policy_handle *key_handle)
381 struct rpc_pipe_client *pipe_handle;
382 struct winreg_String wkey, wkeyclass;
383 char *keyname;
384 NTSTATUS status;
385 WERROR result = WERR_OK;
387 /* create winreg connection */
388 status = rpc_pipe_open_internal(mem_ctx,
389 &ndr_table_winreg.syntax_id,
390 rpc_winreg_dispatch,
391 server_info,
392 &pipe_handle);
393 if (!NT_STATUS_IS_OK(status)) {
394 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg_pipe: %s\n",
395 nt_errstr(status)));
396 return ntstatus_to_werror(status);
399 status = rpccli_winreg_OpenHKLM(pipe_handle,
400 mem_ctx,
401 NULL,
402 access_mask,
403 hive_handle,
404 &result);
405 if (!NT_STATUS_IS_OK(status)) {
406 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
407 nt_errstr(status)));
408 talloc_free(pipe_handle);
409 if (!W_ERROR_IS_OK(result)) {
410 return result;
412 return ntstatus_to_werror(status);
415 if (key && *key) {
416 keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
417 } else {
418 keyname = talloc_strdup(mem_ctx, path);
420 if (keyname == NULL) {
421 talloc_free(pipe_handle);
422 return WERR_NOMEM;
425 ZERO_STRUCT(wkey);
426 wkey.name = keyname;
428 if (create_key) {
429 enum winreg_CreateAction action = REG_ACTION_NONE;
431 ZERO_STRUCT(wkeyclass);
432 wkeyclass.name = "";
434 status = rpccli_winreg_CreateKey(pipe_handle,
435 mem_ctx,
436 hive_handle,
437 wkey,
438 wkeyclass,
440 access_mask,
441 NULL,
442 key_handle,
443 &action,
444 &result);
445 switch (action) {
446 case REG_ACTION_NONE:
447 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
448 break;
449 case REG_CREATED_NEW_KEY:
450 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname));
451 break;
452 case REG_OPENED_EXISTING_KEY:
453 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname));
454 break;
456 } else {
457 status = rpccli_winreg_OpenKey(pipe_handle,
458 mem_ctx,
459 hive_handle,
460 wkey,
462 access_mask,
463 key_handle,
464 &result);
466 if (!NT_STATUS_IS_OK(status)) {
467 talloc_free(pipe_handle);
468 if (!W_ERROR_IS_OK(result)) {
469 return result;
471 return ntstatus_to_werror(status);
474 *winreg_pipe = pipe_handle;
476 return WERR_OK;
480 * @brief Create the registry keyname for the given printer.
482 * @param[in] mem_ctx The memory context to use.
484 * @param[in] printer The name of the printer to get the registry key.
486 * @return The registry key or NULL on error.
488 static char *winreg_printer_data_keyname(TALLOC_CTX *mem_ctx, const char *printer) {
489 return talloc_asprintf(mem_ctx, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY, printer);
493 * @internal
495 * @brief Enumerate values of an opened key handle and retrieve the data.
497 * @param[in] mem_ctx The memory context to use.
499 * @param[in] pipe_handle The pipe handle for the rpc connection.
501 * @param[in] key_hnd The opened key handle.
503 * @param[out] pnum_values A pointer to store he number of values found.
505 * @param[out] pnum_values A pointer to store the number of values we found.
507 * @return WERR_OK on success, the corresponding DOS error
508 * code if something gone wrong.
510 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
511 struct rpc_pipe_client *pipe_handle,
512 struct policy_handle *key_hnd,
513 uint32_t *pnum_values,
514 struct spoolss_PrinterEnumValues **penum_values)
516 TALLOC_CTX *tmp_ctx;
517 uint32_t num_subkeys, max_subkeylen, max_classlen;
518 uint32_t num_values, max_valnamelen, max_valbufsize;
519 uint32_t secdescsize;
520 uint32_t i;
521 NTTIME last_changed_time;
522 struct winreg_String classname;
524 struct spoolss_PrinterEnumValues *enum_values;
526 WERROR result = WERR_OK;
527 NTSTATUS status;
529 tmp_ctx = talloc_new(mem_ctx);
530 if (tmp_ctx == NULL) {
531 return WERR_NOMEM;
534 ZERO_STRUCT(classname);
536 status = rpccli_winreg_QueryInfoKey(pipe_handle,
537 tmp_ctx,
538 key_hnd,
539 &classname,
540 &num_subkeys,
541 &max_subkeylen,
542 &max_classlen,
543 &num_values,
544 &max_valnamelen,
545 &max_valbufsize,
546 &secdescsize,
547 &last_changed_time,
548 &result);
549 if (!NT_STATUS_IS_OK(status)) {
550 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
551 nt_errstr(status)));
552 if (!W_ERROR_IS_OK(result)) {
553 goto error;
555 result = ntstatus_to_werror(status);
556 goto error;
559 if (num_values == 0) {
560 *pnum_values = 0;
561 TALLOC_FREE(tmp_ctx);
562 return WERR_OK;
565 enum_values = TALLOC_ARRAY(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
566 if (enum_values == NULL) {
567 result = WERR_NOMEM;
568 goto error;
571 for (i = 0; i < num_values; i++) {
572 struct spoolss_PrinterEnumValues val;
573 struct winreg_ValNameBuf name_buf;
574 enum winreg_Type type = REG_NONE;
575 uint8_t *data = NULL;
576 uint32_t data_size;
577 uint32_t length;
578 char n = '\0';;
580 name_buf.name = &n;
581 name_buf.size = max_valnamelen + 2;
582 name_buf.length = 0;
584 data_size = max_valbufsize;
585 data = (uint8_t *) TALLOC(tmp_ctx, data_size);
586 length = 0;
588 status = rpccli_winreg_EnumValue(pipe_handle,
589 tmp_ctx,
590 key_hnd,
592 &name_buf,
593 &type,
594 data,
595 &data_size,
596 &length,
597 &result);
598 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
599 result = WERR_OK;
600 status = NT_STATUS_OK;
601 break;
604 if (!NT_STATUS_IS_OK(status)) {
605 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
606 nt_errstr(status)));
607 if (!W_ERROR_IS_OK(result)) {
608 goto error;
610 result = ntstatus_to_werror(status);
611 goto error;
614 if (name_buf.name == NULL) {
615 result = WERR_INVALID_PARAMETER;
616 goto error;
619 val.value_name = talloc_strdup(enum_values, name_buf.name);
620 if (val.value_name == NULL) {
621 result = WERR_NOMEM;
622 goto error;
624 val.value_name_len = strlen_m_term(val.value_name) * 2;
626 val.type = type;
627 val.data_length = data_size;
628 val.data = NULL;
629 if (val.data_length) {
630 val.data = talloc(enum_values, DATA_BLOB);
631 if (val.data == NULL) {
632 result = WERR_NOMEM;
633 goto error;
635 *val.data = data_blob_talloc(enum_values, data, data_size);
638 enum_values[i] = val;
641 *pnum_values = num_values;
642 if (penum_values) {
643 *penum_values = talloc_move(mem_ctx, &enum_values);
646 result = WERR_OK;
648 error:
649 TALLOC_FREE(tmp_ctx);
650 return result;
654 * @internal
656 * @brief Enumerate subkeys of an opened key handle and get the names.
658 * @param[in] mem_ctx The memory context to use.
660 * @param[in] pipe_handle The pipe handle for the rpc connection.
662 * @param[in] key_hnd The opened key handle.
664 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
666 * @param[in] psubkeys A pointer to an array to store the found names of
667 * subkeys.
669 * @return WERR_OK on success, the corresponding DOS error
670 * code if something gone wrong.
672 static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
673 struct rpc_pipe_client *pipe_handle,
674 struct policy_handle *key_hnd,
675 uint32_t *pnum_subkeys,
676 const char ***psubkeys)
678 TALLOC_CTX *tmp_ctx;
679 const char **subkeys;
680 uint32_t num_subkeys, max_subkeylen, max_classlen;
681 uint32_t num_values, max_valnamelen, max_valbufsize;
682 uint32_t i;
683 NTTIME last_changed_time;
684 uint32_t secdescsize;
685 struct winreg_String classname;
686 WERROR result = WERR_OK;
687 NTSTATUS status;
689 tmp_ctx = talloc_new(mem_ctx);
690 if (tmp_ctx == NULL) {
691 return WERR_NOMEM;
694 ZERO_STRUCT(classname);
696 status = rpccli_winreg_QueryInfoKey(pipe_handle,
697 tmp_ctx,
698 key_hnd,
699 &classname,
700 &num_subkeys,
701 &max_subkeylen,
702 &max_classlen,
703 &num_values,
704 &max_valnamelen,
705 &max_valbufsize,
706 &secdescsize,
707 &last_changed_time,
708 &result);
709 if (!NT_STATUS_IS_OK(status)) {
710 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
711 nt_errstr(status)));
712 if (!W_ERROR_IS_OK(result)) {
713 goto error;
715 result = ntstatus_to_werror(status);
716 goto error;
719 subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
720 if (subkeys == NULL) {
721 result = WERR_NOMEM;
722 goto error;
725 if (num_subkeys == 0) {
726 subkeys[0] = talloc_strdup(subkeys, "");
727 if (subkeys[0] == NULL) {
728 result = WERR_NOMEM;
729 goto error;
731 *pnum_subkeys = 0;
732 if (psubkeys) {
733 *psubkeys = talloc_move(mem_ctx, &subkeys);
736 TALLOC_FREE(tmp_ctx);
737 return WERR_OK;
740 for (i = 0; i < num_subkeys; i++) {
741 char c = '\0';
742 char n = '\0';
743 char *name = NULL;
744 struct winreg_StringBuf class_buf;
745 struct winreg_StringBuf name_buf;
746 NTTIME modtime;
748 class_buf.name = &c;
749 class_buf.size = max_classlen + 2;
750 class_buf.length = 0;
752 name_buf.name = &n;
753 name_buf.size = max_subkeylen + 2;
754 name_buf.length = 0;
756 ZERO_STRUCT(modtime);
758 status = rpccli_winreg_EnumKey(pipe_handle,
759 tmp_ctx,
760 key_hnd,
762 &name_buf,
763 &class_buf,
764 &modtime,
765 &result);
766 if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
767 result = WERR_OK;
768 status = NT_STATUS_OK;
769 break;
772 if (!NT_STATUS_IS_OK(status)) {
773 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
774 nt_errstr(status)));
775 if (!W_ERROR_IS_OK(result)) {
776 goto error;
778 result = ntstatus_to_werror(status);
779 goto error;
782 if (name_buf.name == NULL) {
783 result = WERR_INVALID_PARAMETER;
784 goto error;
787 name = talloc_strdup(subkeys, name_buf.name);
788 if (name == NULL) {
789 result = WERR_NOMEM;
790 goto error;
793 subkeys[i] = name;
796 *pnum_subkeys = num_subkeys;
797 if (psubkeys) {
798 *psubkeys = talloc_move(mem_ctx, &subkeys);
801 error:
802 TALLOC_FREE(tmp_ctx);
803 return result;
807 * @internal
809 * @brief A function to delete a key and its subkeys recurively.
811 * @param[in] mem_ctx The memory context to use.
813 * @param[in] pipe_handle The pipe handle for the rpc connection.
815 * @param[in] hive_handle A opened hive handle to the key.
817 * @param[in] access_mask The access mask to access the key.
819 * @param[in] key The key to delete
821 * @return WERR_OK on success, the corresponding DOS error
822 * code if something gone wrong.
824 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
825 struct rpc_pipe_client *pipe_handle,
826 struct policy_handle *hive_handle,
827 uint32_t access_mask,
828 const char *key)
830 const char **subkeys = NULL;
831 uint32_t num_subkeys = 0;
832 struct policy_handle key_hnd;
833 struct winreg_String wkey;
834 WERROR result = WERR_OK;
835 NTSTATUS status;
836 uint32_t i;
838 ZERO_STRUCT(key_hnd);
839 wkey.name = key;
841 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
842 /* open the key */
843 status = rpccli_winreg_OpenKey(pipe_handle,
844 mem_ctx,
845 hive_handle,
846 wkey,
848 access_mask,
849 &key_hnd,
850 &result);
851 if (!NT_STATUS_IS_OK(status)) {
852 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
853 wkey.name, nt_errstr(status)));
854 if (!W_ERROR_IS_OK(result)) {
855 return result;
857 return ntstatus_to_werror(status);
860 result = winreg_printer_enumkeys(mem_ctx,
861 pipe_handle,
862 &key_hnd,
863 &num_subkeys,
864 &subkeys);
865 if (!W_ERROR_IS_OK(result)) {
866 goto done;
869 for (i = 0; i < num_subkeys; i++) {
870 /* create key + subkey */
871 char *subkey = talloc_asprintf(mem_ctx, "%s\\%s", key, subkeys[i]);
872 if (subkey == NULL) {
873 goto done;
876 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey));
877 result = winreg_printer_delete_subkeys(mem_ctx,
878 pipe_handle,
879 hive_handle,
880 access_mask,
881 subkey);
882 if (!W_ERROR_IS_OK(result)) {
883 goto done;
887 if (is_valid_policy_hnd(&key_hnd)) {
888 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
891 wkey.name = key;
893 status = rpccli_winreg_DeleteKey(pipe_handle,
894 mem_ctx,
895 hive_handle,
896 wkey,
897 &result);
899 done:
900 if (is_valid_policy_hnd(&key_hnd)) {
901 rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
904 return result;
907 static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
908 struct rpc_pipe_client *pipe_handle,
909 struct policy_handle *key_handle,
910 const char *value,
911 const char *data)
913 struct winreg_String wvalue;
914 DATA_BLOB blob;
915 WERROR result = WERR_OK;
916 NTSTATUS status;
918 wvalue.name = value;
919 if (data == NULL) {
920 blob = data_blob_string_const("");
921 } else {
922 if (!push_reg_sz(mem_ctx, NULL, &blob, data)) {
923 DEBUG(0, ("winreg_printer_write_sz: Could not marshall string %s for %s\n",
924 data, wvalue.name));
925 return WERR_NOMEM;
928 status = rpccli_winreg_SetValue(pipe_handle,
929 mem_ctx,
930 key_handle,
931 wvalue,
932 REG_SZ,
933 blob.data,
934 blob.length,
935 &result);
936 if (!NT_STATUS_IS_OK(status)) {
937 DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: %s\n",
938 wvalue.name, win_errstr(result)));
939 if (!W_ERROR_IS_OK(result)) {
940 result = ntstatus_to_werror(status);
944 return result;
947 static WERROR winreg_printer_write_dword(TALLOC_CTX *mem_ctx,
948 struct rpc_pipe_client *pipe_handle,
949 struct policy_handle *key_handle,
950 const char *value,
951 uint32_t data)
953 struct winreg_String wvalue;
954 DATA_BLOB blob;
955 WERROR result = WERR_OK;
956 NTSTATUS status;
958 wvalue.name = value;
959 blob = data_blob_talloc(mem_ctx, NULL, 4);
960 SIVAL(blob.data, 0, data);
962 status = rpccli_winreg_SetValue(pipe_handle,
963 mem_ctx,
964 key_handle,
965 wvalue,
966 REG_DWORD,
967 blob.data,
968 blob.length,
969 &result);
970 if (!NT_STATUS_IS_OK(status)) {
971 DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: %s\n",
972 wvalue.name, win_errstr(result)));
973 if (!W_ERROR_IS_OK(result)) {
974 result = ntstatus_to_werror(status);
978 return result;
981 static WERROR winreg_printer_write_binary(TALLOC_CTX *mem_ctx,
982 struct rpc_pipe_client *pipe_handle,
983 struct policy_handle *key_handle,
984 const char *value,
985 DATA_BLOB blob)
987 struct winreg_String wvalue;
988 WERROR result = WERR_OK;
989 NTSTATUS status;
991 wvalue.name = value;
992 status = rpccli_winreg_SetValue(pipe_handle,
993 mem_ctx,
994 key_handle,
995 wvalue,
996 REG_BINARY,
997 blob.data,
998 blob.length,
999 &result);
1000 if (!NT_STATUS_IS_OK(status)) {
1001 DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: %s\n",
1002 wvalue.name, win_errstr(result)));
1003 if (!W_ERROR_IS_OK(result)) {
1004 result = ntstatus_to_werror(status);
1008 return result;
1011 static WERROR winreg_printer_query_dword(TALLOC_CTX *mem_ctx,
1012 struct rpc_pipe_client *pipe_handle,
1013 struct policy_handle *key_handle,
1014 const char *value,
1015 uint32_t *data)
1017 struct winreg_String wvalue;
1018 enum winreg_Type type;
1019 WERROR result = WERR_OK;
1020 uint32_t value_len = 0;
1021 NTSTATUS status;
1022 DATA_BLOB blob;
1024 wvalue.name = value;
1025 status = rpccli_winreg_QueryValue(pipe_handle,
1026 mem_ctx,
1027 key_handle,
1028 &wvalue,
1029 &type,
1030 NULL,
1031 (uint32_t *) &blob.length,
1032 &value_len,
1033 &result);
1034 if (!NT_STATUS_IS_OK(status)) {
1035 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1036 wvalue.name, nt_errstr(status)));
1037 if (!W_ERROR_IS_OK(result)) {
1038 goto done;
1040 result = ntstatus_to_werror(status);
1041 goto done;
1044 if (type != REG_DWORD) {
1045 result = WERR_INVALID_DATATYPE;
1046 goto done;
1049 if (blob.length != 4) {
1050 result = WERR_INVALID_DATA;
1051 goto done;
1054 blob.data = (uint8_t *) TALLOC(mem_ctx, blob.length);
1055 if (blob.data == NULL) {
1056 result = WERR_NOMEM;
1057 goto done;
1059 value_len = 0;
1061 status = rpccli_winreg_QueryValue(pipe_handle,
1062 mem_ctx,
1063 key_handle,
1064 &wvalue,
1065 &type,
1066 blob.data,
1067 (uint32_t *) &blob.length,
1068 &value_len,
1069 &result);
1070 if (!NT_STATUS_IS_OK(status)) {
1071 DEBUG(0, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1072 wvalue.name, nt_errstr(status)));
1073 if (!W_ERROR_IS_OK(result)) {
1074 result = ntstatus_to_werror(status);
1076 goto done;
1079 if (data) {
1080 *data = IVAL(blob.data, 0);
1082 done:
1083 return result;
1086 static WERROR winreg_printer_write_multi_sz(TALLOC_CTX *mem_ctx,
1087 struct rpc_pipe_client *pipe_handle,
1088 struct policy_handle *key_handle,
1089 const char *value,
1090 const char **data)
1092 struct winreg_String wvalue;
1093 DATA_BLOB blob;
1094 WERROR result = WERR_OK;
1095 NTSTATUS status;
1097 wvalue.name = value;
1098 if (!push_reg_multi_sz(mem_ctx, NULL, &blob, data)) {
1099 return WERR_NOMEM;
1101 status = rpccli_winreg_SetValue(pipe_handle,
1102 mem_ctx,
1103 key_handle,
1104 wvalue,
1105 REG_MULTI_SZ,
1106 blob.data,
1107 blob.length,
1108 &result);
1109 if (!NT_STATUS_IS_OK(status)) {
1110 DEBUG(0, ("winreg_printer_write_multi_sz: Could not set value %s: %s\n",
1111 wvalue.name, win_errstr(result)));
1112 if (!W_ERROR_IS_OK(result)) {
1113 result = ntstatus_to_werror(status);
1117 return result;
1120 static WERROR winreg_printer_opendriver(TALLOC_CTX *mem_ctx,
1121 struct auth_serversupplied_info *server_info,
1122 const char *drivername,
1123 const char *architecture,
1124 uint32_t version,
1125 uint32_t access_mask,
1126 bool create,
1127 struct rpc_pipe_client **winreg_pipe,
1128 struct policy_handle *hive_hnd,
1129 struct policy_handle *key_hnd)
1131 WERROR result;
1132 char *key_name;
1134 key_name = talloc_asprintf(mem_ctx, "%s\\Environments\\%s\\Drivers\\Version-%u",
1135 TOP_LEVEL_CONTROL_KEY,
1136 architecture, version);
1137 if (!key_name) {
1138 return WERR_NOMEM;
1141 result = winreg_printer_openkey(mem_ctx,
1142 server_info,
1143 winreg_pipe,
1144 key_name,
1145 drivername,
1146 create,
1147 access_mask,
1148 hive_hnd,
1149 key_hnd);
1150 return result;
1153 static WERROR winreg_enumval_to_dword(TALLOC_CTX *mem_ctx,
1154 struct spoolss_PrinterEnumValues *v,
1155 const char *valuename, uint32_t *dw)
1157 /* just return if it is not the one we are looking for */
1158 if (strcmp(valuename, v->value_name) != 0) {
1159 return WERR_NOT_FOUND;
1162 if (v->type != REG_DWORD) {
1163 return WERR_INVALID_DATATYPE;
1166 *dw = IVAL(v->data->data, 0);
1167 return WERR_OK;
1170 static WERROR winreg_enumval_to_sz(TALLOC_CTX *mem_ctx,
1171 struct spoolss_PrinterEnumValues *v,
1172 const char *valuename, const char **_str)
1174 /* just return if it is not the one we are looking for */
1175 if (strcmp(valuename, v->value_name) != 0) {
1176 return WERR_NOT_FOUND;
1179 if (v->type != REG_SZ) {
1180 return WERR_INVALID_DATATYPE;
1183 if (!pull_reg_sz(mem_ctx, NULL, v->data, _str)) {
1184 return WERR_NOMEM;
1187 return WERR_OK;
1190 static WERROR winreg_enumval_to_multi_sz(TALLOC_CTX *mem_ctx,
1191 struct spoolss_PrinterEnumValues *v,
1192 const char *valuename,
1193 const char ***array)
1195 /* just return if it is not the one we are looking for */
1196 if (strcmp(valuename, v->value_name) != 0) {
1197 return WERR_NOT_FOUND;
1200 if (v->type != REG_MULTI_SZ) {
1201 return WERR_INVALID_DATATYPE;
1204 if (!pull_reg_multi_sz(mem_ctx, NULL, v->data, array)) {
1205 return WERR_NOMEM;
1208 return WERR_OK;
1211 static WERROR winreg_enumval_to_blob(TALLOC_CTX *mem_ctx,
1212 struct spoolss_PrinterEnumValues *v,
1213 const char *valuename,
1214 DATA_BLOB *blob)
1216 /* just return if it is not the one we are looking for */
1217 if (strcmp(valuename, v->value_name) != 0) {
1218 return WERR_NOT_FOUND;
1221 if (v->type != REG_BINARY) {
1222 return WERR_INVALID_DATATYPE;
1225 blob->data = v->data->data;
1226 blob->length = v->data_length;
1228 return WERR_OK;
1231 static WERROR winreg_printer_write_date(TALLOC_CTX *mem_ctx,
1232 struct rpc_pipe_client *pipe_handle,
1233 struct policy_handle *key_handle,
1234 const char *value,
1235 NTTIME data)
1237 struct winreg_String wvalue;
1238 DATA_BLOB blob;
1239 WERROR result = WERR_OK;
1240 NTSTATUS status;
1241 const char *str;
1242 struct tm *tm;
1243 time_t t;
1245 t = nt_time_to_unix(data);
1246 tm = localtime(&t);
1247 str = talloc_asprintf(mem_ctx, "%02d/%02d/%04d",
1248 tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
1249 if (!str) {
1250 return WERR_NOMEM;
1253 wvalue.name = value;
1254 if (!push_reg_sz(mem_ctx, NULL, &blob, str)) {
1255 return WERR_NOMEM;
1257 status = rpccli_winreg_SetValue(pipe_handle,
1258 mem_ctx,
1259 key_handle,
1260 wvalue,
1261 REG_SZ,
1262 blob.data,
1263 blob.length,
1264 &result);
1265 if (!NT_STATUS_IS_OK(status)) {
1266 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1267 wvalue.name, win_errstr(result)));
1268 if (!W_ERROR_IS_OK(result)) {
1269 result = ntstatus_to_werror(status);
1273 return result;
1276 static WERROR winreg_printer_date_to_NTTIME(const char *str, NTTIME *data)
1278 struct tm tm;
1279 time_t t;
1281 ZERO_STRUCT(tm);
1283 if (sscanf(str, "%d/%d/%d",
1284 &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3) {
1285 return WERR_INVALID_PARAMETER;
1287 tm.tm_mon -= 1;
1288 tm.tm_year -= 1900;
1289 tm.tm_isdst = -1;
1291 t = mktime(&tm);
1292 unix_to_nt_time(data, t);
1294 return WERR_OK;
1297 static WERROR winreg_printer_write_ver(TALLOC_CTX *mem_ctx,
1298 struct rpc_pipe_client *pipe_handle,
1299 struct policy_handle *key_handle,
1300 const char *value,
1301 uint64_t data)
1303 struct winreg_String wvalue;
1304 DATA_BLOB blob;
1305 WERROR result = WERR_OK;
1306 NTSTATUS status;
1307 char *str;
1309 /* FIXME: check format is right,
1310 * this needs to be something like: 6.1.7600.16385 */
1311 str = talloc_asprintf(mem_ctx, "%u.%u.%u.%u",
1312 (unsigned)((data >> 48) & 0xFFFF),
1313 (unsigned)((data >> 32) & 0xFFFF),
1314 (unsigned)((data >> 16) & 0xFFFF),
1315 (unsigned)(data & 0xFFFF));
1316 if (!str) {
1317 return WERR_NOMEM;
1320 wvalue.name = value;
1321 if (!push_reg_sz(mem_ctx, NULL, &blob, str)) {
1322 return WERR_NOMEM;
1324 status = rpccli_winreg_SetValue(pipe_handle,
1325 mem_ctx,
1326 key_handle,
1327 wvalue,
1328 REG_SZ,
1329 blob.data,
1330 blob.length,
1331 &result);
1332 if (!NT_STATUS_IS_OK(status)) {
1333 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1334 wvalue.name, win_errstr(result)));
1335 if (!W_ERROR_IS_OK(result)) {
1336 result = ntstatus_to_werror(status);
1340 return result;
1343 static WERROR winreg_printer_ver_to_dword(const char *str, uint64_t *data)
1345 unsigned int v1, v2, v3, v4;
1347 if (sscanf(str, "%u.%u.%u.%u", &v1, &v2, &v3, &v4) != 4) {
1348 return WERR_INVALID_PARAMETER;
1351 *data = ((uint64_t)(v1 & 0xFFFF) << 48) +
1352 ((uint64_t)(v2 & 0xFFFF) << 32) +
1353 ((uint64_t)(v3 & 0xFFFF) << 16) +
1354 (uint64_t)(v2 & 0xFFFF);
1356 return WERR_OK;
1359 /********************************************************************
1360 Public winreg function for spoolss
1361 ********************************************************************/
1363 WERROR winreg_create_printer(TALLOC_CTX *mem_ctx,
1364 struct auth_serversupplied_info *server_info,
1365 const char *sharename)
1367 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1368 struct rpc_pipe_client *winreg_pipe = NULL;
1369 struct policy_handle hive_hnd, key_hnd;
1370 struct spoolss_SetPrinterInfo2 *info2;
1371 struct spoolss_DeviceMode *devmode = NULL;
1372 struct security_descriptor *secdesc;
1373 struct winreg_String wkey, wkeyclass;
1374 const char *path;
1375 const char *subkeys[] = { "DsDriver", "DsSpooler", "PrinterDriverData" };
1376 uint32_t i, count = ARRAY_SIZE(subkeys);
1377 int snum = lp_servicenumber(sharename);
1378 uint32_t info2_mask = 0;
1379 WERROR result = WERR_OK;
1380 TALLOC_CTX *tmp_ctx;
1382 tmp_ctx = talloc_new(mem_ctx);
1383 if (tmp_ctx == NULL) {
1384 return WERR_NOMEM;
1387 path = winreg_printer_data_keyname(tmp_ctx, sharename);
1388 if (path == NULL) {
1389 TALLOC_FREE(tmp_ctx);
1390 return WERR_NOMEM;
1393 ZERO_STRUCT(hive_hnd);
1394 ZERO_STRUCT(key_hnd);
1396 result = winreg_printer_openkey(tmp_ctx,
1397 server_info,
1398 &winreg_pipe,
1399 path,
1401 false,
1402 access_mask,
1403 &hive_hnd,
1404 &key_hnd);
1405 if (W_ERROR_IS_OK(result)) {
1406 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path));
1407 goto done;
1408 } else if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
1409 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path));
1410 } else if (!W_ERROR_IS_OK(result)) {
1411 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
1412 path, win_errstr(result)));
1413 goto done;
1416 /* Create the main key */
1417 result = winreg_printer_openkey(tmp_ctx,
1418 server_info,
1419 &winreg_pipe,
1420 path,
1422 true,
1423 access_mask,
1424 &hive_hnd,
1425 &key_hnd);
1426 if (!W_ERROR_IS_OK(result)) {
1427 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1428 path, win_errstr(result)));
1429 goto done;
1432 if (is_valid_policy_hnd(&key_hnd)) {
1433 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1436 /* Create subkeys */
1437 for (i = 0; i < count; i++) {
1438 NTSTATUS status;
1439 enum winreg_CreateAction action = REG_ACTION_NONE;
1441 ZERO_STRUCT(key_hnd);
1442 ZERO_STRUCT(wkey);
1444 wkey.name = talloc_asprintf(tmp_ctx, "%s\\%s", path, subkeys[i]);
1445 if (wkey.name == NULL) {
1446 result = WERR_NOMEM;
1447 goto done;
1450 ZERO_STRUCT(wkeyclass);
1451 wkeyclass.name = "";
1453 status = rpccli_winreg_CreateKey(winreg_pipe,
1454 tmp_ctx,
1455 &hive_hnd,
1456 wkey,
1457 wkeyclass,
1459 access_mask,
1460 NULL,
1461 &key_hnd,
1462 &action,
1463 &result);
1464 if (!NT_STATUS_IS_OK(status)) {
1465 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1466 wkey.name, win_errstr(result)));
1467 if (!W_ERROR_IS_OK(result)) {
1468 result = ntstatus_to_werror(status);
1470 goto done;
1473 if (is_valid_policy_hnd(&key_hnd)) {
1474 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1477 info2 = talloc_zero(tmp_ctx, struct spoolss_SetPrinterInfo2);
1478 if (info2 == NULL) {
1479 result = WERR_NOMEM;
1480 goto done;
1483 info2->printername = sharename;
1484 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTERNAME;
1486 info2->sharename = sharename;
1487 info2_mask |= SPOOLSS_PRINTER_INFO_SHARENAME;
1489 info2->portname = SAMBA_PRINTER_PORT_NAME;
1490 info2_mask |= SPOOLSS_PRINTER_INFO_PORTNAME;
1492 info2->printprocessor = "winprint";
1493 info2_mask |= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR;
1495 info2->datatype = "RAW";
1496 info2_mask |= SPOOLSS_PRINTER_INFO_DATATYPE;
1498 info2->comment = "";
1499 info2_mask |= SPOOLSS_PRINTER_INFO_COMMENT;
1501 info2->attributes = PRINTER_ATTRIBUTE_SAMBA;
1502 info2_mask |= SPOOLSS_PRINTER_INFO_ATTRIBUTES;
1504 info2->starttime = 0; /* Minutes since 12:00am GMT */
1505 info2_mask |= SPOOLSS_PRINTER_INFO_STARTTIME;
1507 info2->untiltime = 0; /* Minutes since 12:00am GMT */
1508 info2_mask |= SPOOLSS_PRINTER_INFO_UNTILTIME;
1510 info2->priority = 1;
1511 info2_mask |= SPOOLSS_PRINTER_INFO_PRIORITY;
1513 info2->defaultpriority = 1;
1514 info2_mask |= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY;
1516 /* info2->setuptime = (uint32_t) time(NULL); */
1518 if (lp_default_devmode(snum)) {
1519 devmode = winreg_printer_create_default_devmode(tmp_ctx,
1520 info2->printername);
1521 if (devmode == NULL) {
1522 result = WERR_NOMEM;
1523 goto done;
1526 info2_mask |= SPOOLSS_PRINTER_INFO_DEVMODE;
1529 secdesc = winreg_printer_create_default_secdesc(tmp_ctx);
1530 if (secdesc == NULL) {
1531 result = WERR_NOMEM;
1532 goto done;
1534 info2_mask |= SPOOLSS_PRINTER_INFO_SECDESC;
1536 result = winreg_update_printer(tmp_ctx,
1537 server_info,
1538 info2_mask,
1539 info2,
1540 devmode,
1541 secdesc);
1543 done:
1544 if (winreg_pipe != NULL) {
1545 if (is_valid_policy_hnd(&key_hnd)) {
1546 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1548 if (is_valid_policy_hnd(&hive_hnd)) {
1549 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1553 talloc_free(tmp_ctx);
1554 return result;
1557 WERROR winreg_update_printer(TALLOC_CTX *mem_ctx,
1558 struct auth_serversupplied_info *server_info,
1559 uint32_t info2_mask,
1560 struct spoolss_SetPrinterInfo2 *info2,
1561 struct spoolss_DeviceMode *devmode,
1562 struct security_descriptor *secdesc)
1564 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1565 struct rpc_pipe_client *winreg_pipe = NULL;
1566 struct policy_handle hive_hnd, key_hnd;
1567 enum ndr_err_code ndr_err;
1568 DATA_BLOB blob;
1569 char *path;
1570 WERROR result = WERR_OK;
1571 TALLOC_CTX *tmp_ctx;
1573 tmp_ctx = talloc_new(mem_ctx);
1574 if (tmp_ctx == NULL) {
1575 return WERR_NOMEM;
1578 path = winreg_printer_data_keyname(tmp_ctx, info2->sharename);
1579 if (path == NULL) {
1580 TALLOC_FREE(tmp_ctx);
1581 return WERR_NOMEM;
1584 ZERO_STRUCT(hive_hnd);
1585 ZERO_STRUCT(key_hnd);
1587 result = winreg_printer_openkey(tmp_ctx,
1588 server_info,
1589 &winreg_pipe,
1590 path,
1592 true,
1593 access_mask,
1594 &hive_hnd,
1595 &key_hnd);
1596 if (!W_ERROR_IS_OK(result)) {
1597 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1598 path, win_errstr(result)));
1599 goto done;
1602 if (info2_mask & SPOOLSS_PRINTER_INFO_ATTRIBUTES) {
1603 result = winreg_printer_write_dword(tmp_ctx,
1604 winreg_pipe,
1605 &key_hnd,
1606 "Attributes",
1607 info2->attributes);
1608 if (!W_ERROR_IS_OK(result)) {
1609 goto done;
1613 #if 0
1614 if (info2_mask & SPOOLSS_PRINTER_INFO_AVERAGEPPM) {
1615 result = winreg_printer_write_dword(tmp_ctx,
1616 winreg_pipe,
1617 &key_hnd,
1618 "AveragePpm",
1619 info2->attributes);
1620 if (!W_ERROR_IS_OK(result)) {
1621 goto done;
1624 #endif
1626 if (info2_mask & SPOOLSS_PRINTER_INFO_COMMENT) {
1627 result = winreg_printer_write_sz(tmp_ctx,
1628 winreg_pipe,
1629 &key_hnd,
1630 "Description",
1631 info2->comment);
1632 if (!W_ERROR_IS_OK(result)) {
1633 goto done;
1637 if (info2_mask & SPOOLSS_PRINTER_INFO_DATATYPE) {
1638 result = winreg_printer_write_sz(tmp_ctx,
1639 winreg_pipe,
1640 &key_hnd,
1641 "Datatype",
1642 info2->datatype);
1643 if (!W_ERROR_IS_OK(result)) {
1644 goto done;
1648 if (info2_mask & SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY) {
1649 result = winreg_printer_write_dword(tmp_ctx,
1650 winreg_pipe,
1651 &key_hnd,
1652 "Default Priority",
1653 info2->defaultpriority);
1654 if (!W_ERROR_IS_OK(result)) {
1655 goto done;
1659 if (info2_mask & SPOOLSS_PRINTER_INFO_DEVMODE) {
1660 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, NULL, devmode,
1661 (ndr_push_flags_fn_t) ndr_push_spoolss_DeviceMode);
1662 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1663 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1664 result = WERR_NOMEM;
1665 goto done;
1668 result = winreg_printer_write_binary(tmp_ctx,
1669 winreg_pipe,
1670 &key_hnd,
1671 "Default DevMode",
1672 blob);
1673 if (!W_ERROR_IS_OK(result)) {
1674 goto done;
1678 if (info2_mask & SPOOLSS_PRINTER_INFO_DRIVERNAME) {
1679 result = winreg_printer_write_sz(tmp_ctx,
1680 winreg_pipe,
1681 &key_hnd,
1682 "Printer Driver",
1683 info2->drivername);
1684 if (!W_ERROR_IS_OK(result)) {
1685 goto done;
1689 if (info2_mask & SPOOLSS_PRINTER_INFO_LOCATION) {
1690 result = winreg_printer_write_sz(tmp_ctx,
1691 winreg_pipe,
1692 &key_hnd,
1693 "Location",
1694 info2->location);
1695 if (!W_ERROR_IS_OK(result)) {
1696 goto done;
1700 if (info2_mask & SPOOLSS_PRINTER_INFO_PARAMETERS) {
1701 result = winreg_printer_write_sz(tmp_ctx,
1702 winreg_pipe,
1703 &key_hnd,
1704 "Parameters",
1705 info2->parameters);
1706 if (!W_ERROR_IS_OK(result)) {
1707 goto done;
1711 if (info2_mask & SPOOLSS_PRINTER_INFO_PORTNAME) {
1712 result = winreg_printer_write_sz(tmp_ctx,
1713 winreg_pipe,
1714 &key_hnd,
1715 "Port",
1716 info2->portname);
1717 if (!W_ERROR_IS_OK(result)) {
1718 goto done;
1722 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTERNAME) {
1724 * in addprinter: no servername and the printer is the name
1725 * in setprinter: servername is \\server
1726 * and printer is \\server\\printer
1728 * Samba manages only local printers.
1729 * we currently don't support things like i
1730 * path=\\other_server\printer
1732 * We only store the printername, not \\server\printername
1734 const char *p = strrchr(info2->printername, '\\');
1735 if (p == NULL) {
1736 p = info2->printername;
1737 } else {
1738 p++;
1740 result = winreg_printer_write_sz(tmp_ctx,
1741 winreg_pipe,
1742 &key_hnd,
1743 "Name",
1745 if (!W_ERROR_IS_OK(result)) {
1746 goto done;
1750 if (info2_mask & SPOOLSS_PRINTER_INFO_PRINTPROCESSOR) {
1751 result = winreg_printer_write_sz(tmp_ctx,
1752 winreg_pipe,
1753 &key_hnd,
1754 "Print Processor",
1755 info2->printprocessor);
1756 if (!W_ERROR_IS_OK(result)) {
1757 goto done;
1761 if (info2_mask & SPOOLSS_PRINTER_INFO_PRIORITY) {
1762 result = winreg_printer_write_dword(tmp_ctx,
1763 winreg_pipe,
1764 &key_hnd,
1765 "Priority",
1766 info2->priority);
1767 if (!W_ERROR_IS_OK(result)) {
1768 goto done;
1772 if (info2_mask & SPOOLSS_PRINTER_INFO_SECDESC) {
1774 * We need a security descriptor, if it isn't specified by
1775 * AddPrinter{Ex} then create a default descriptor.
1777 if (secdesc == NULL) {
1778 secdesc = winreg_printer_create_default_secdesc(tmp_ctx);
1780 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, NULL, secdesc,
1781 (ndr_push_flags_fn_t) ndr_push_security_descriptor);
1782 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1783 DEBUG(0, ("winreg_update_printer: Failed to marshall security descriptor\n"));
1784 result = WERR_NOMEM;
1785 goto done;
1788 result = winreg_printer_write_binary(tmp_ctx,
1789 winreg_pipe,
1790 &key_hnd,
1791 "Security",
1792 blob);
1793 if (!W_ERROR_IS_OK(result)) {
1794 goto done;
1798 if (info2_mask & SPOOLSS_PRINTER_INFO_SEPFILE) {
1799 result = winreg_printer_write_sz(tmp_ctx,
1800 winreg_pipe,
1801 &key_hnd,
1802 "Separator File",
1803 info2->sepfile);
1804 if (!W_ERROR_IS_OK(result)) {
1805 goto done;
1809 if (info2_mask & SPOOLSS_PRINTER_INFO_SHARENAME) {
1810 result = winreg_printer_write_sz(tmp_ctx,
1811 winreg_pipe,
1812 &key_hnd,
1813 "Share Name",
1814 info2->sharename);
1815 if (!W_ERROR_IS_OK(result)) {
1816 goto done;
1820 if (info2_mask & SPOOLSS_PRINTER_INFO_STARTTIME) {
1821 result = winreg_printer_write_dword(tmp_ctx,
1822 winreg_pipe,
1823 &key_hnd,
1824 "StartTime",
1825 info2->starttime);
1826 if (!W_ERROR_IS_OK(result)) {
1827 goto done;
1831 if (info2_mask & SPOOLSS_PRINTER_INFO_STATUS) {
1832 result = winreg_printer_write_dword(tmp_ctx,
1833 winreg_pipe,
1834 &key_hnd,
1835 "Status",
1836 info2->status);
1837 if (!W_ERROR_IS_OK(result)) {
1838 goto done;
1842 if (info2_mask & SPOOLSS_PRINTER_INFO_UNTILTIME) {
1843 result = winreg_printer_write_dword(tmp_ctx,
1844 winreg_pipe,
1845 &key_hnd,
1846 "UntilTime",
1847 info2->untiltime);
1848 if (!W_ERROR_IS_OK(result)) {
1849 goto done;
1853 result = winreg_printer_write_dword(tmp_ctx,
1854 winreg_pipe,
1855 &key_hnd,
1856 "ChangeID",
1857 winreg_printer_rev_changeid());
1858 if (!W_ERROR_IS_OK(result)) {
1859 goto done;
1862 result = WERR_OK;
1863 done:
1864 if (winreg_pipe != NULL) {
1865 if (is_valid_policy_hnd(&key_hnd)) {
1866 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
1868 if (is_valid_policy_hnd(&hive_hnd)) {
1869 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
1873 TALLOC_FREE(tmp_ctx);
1874 return result;
1877 WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
1878 struct auth_serversupplied_info *server_info,
1879 const char *printer,
1880 struct spoolss_PrinterInfo2 **pinfo2)
1882 struct spoolss_PrinterInfo2 *info2;
1883 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1884 struct rpc_pipe_client *winreg_pipe = NULL;
1885 struct policy_handle hive_hnd, key_hnd;
1886 struct spoolss_PrinterEnumValues *enum_values = NULL;
1887 struct spoolss_PrinterEnumValues *v;
1888 enum ndr_err_code ndr_err;
1889 DATA_BLOB blob;
1890 uint32_t num_values = 0;
1891 uint32_t i;
1892 char *path;
1893 WERROR result = WERR_OK;
1894 TALLOC_CTX *tmp_ctx;
1896 tmp_ctx = talloc_new(mem_ctx);
1897 if (tmp_ctx == NULL) {
1898 return WERR_NOMEM;
1901 path = winreg_printer_data_keyname(tmp_ctx, printer);
1902 if (path == NULL) {
1903 TALLOC_FREE(tmp_ctx);
1904 return WERR_NOMEM;
1907 result = winreg_printer_openkey(tmp_ctx,
1908 server_info,
1909 &winreg_pipe,
1910 path,
1912 false,
1913 access_mask,
1914 &hive_hnd,
1915 &key_hnd);
1916 if (!W_ERROR_IS_OK(result)) {
1917 DEBUG(0, ("winreg_get_printer: Could not open key %s: %s\n",
1918 path, win_errstr(result)));
1919 goto done;
1922 result = winreg_printer_enumvalues(tmp_ctx,
1923 winreg_pipe,
1924 &key_hnd,
1925 &num_values,
1926 &enum_values);
1927 if (!W_ERROR_IS_OK(result)) {
1928 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1929 path, win_errstr(result)));
1930 goto done;
1933 info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
1934 if (info2 == NULL) {
1935 result = WERR_NOMEM;
1936 goto done;
1939 info2->servername = talloc_asprintf(info2, "\\\\%s", global_myname());
1940 if (info2->servername == NULL) {
1941 result = WERR_NOMEM;
1942 goto done;
1945 info2->printername = EMPTY_STRING;
1946 info2->sharename = EMPTY_STRING;
1947 info2->portname = EMPTY_STRING;
1948 info2->drivername = EMPTY_STRING;
1949 info2->comment = EMPTY_STRING;
1950 info2->location = EMPTY_STRING;
1951 info2->sepfile = EMPTY_STRING;
1952 info2->printprocessor = EMPTY_STRING;
1953 info2->datatype = EMPTY_STRING;
1954 info2->parameters = EMPTY_STRING;
1956 for (i = 0; i < num_values; i++) {
1957 v = &enum_values[i];
1959 result = winreg_enumval_to_sz(info2,
1961 "Name",
1962 &info2->printername);
1963 CHECK_ERROR(result);
1965 result = winreg_enumval_to_sz(info2,
1967 "Share Name",
1968 &info2->sharename);
1969 CHECK_ERROR(result);
1971 result = winreg_enumval_to_sz(info2,
1973 "Port",
1974 &info2->portname);
1975 CHECK_ERROR(result);
1977 result = winreg_enumval_to_sz(info2,
1979 "Description",
1980 &info2->comment);
1981 CHECK_ERROR(result);
1983 result = winreg_enumval_to_sz(info2,
1985 "Location",
1986 &info2->location);
1987 CHECK_ERROR(result);
1989 result = winreg_enumval_to_sz(info2,
1991 "Separator File",
1992 &info2->sepfile);
1993 CHECK_ERROR(result);
1995 result = winreg_enumval_to_sz(info2,
1997 "Print Processor",
1998 &info2->printprocessor);
1999 CHECK_ERROR(result);
2001 result = winreg_enumval_to_sz(info2,
2003 "Datatype",
2004 &info2->datatype);
2005 CHECK_ERROR(result);
2007 result = winreg_enumval_to_sz(info2,
2009 "Parameters",
2010 &info2->parameters);
2011 CHECK_ERROR(result);
2013 result = winreg_enumval_to_sz(info2,
2015 "Printer Driver",
2016 &info2->drivername);
2017 CHECK_ERROR(result);
2019 result = winreg_enumval_to_dword(info2,
2021 "Attributes",
2022 &info2->attributes);
2023 CHECK_ERROR(result);
2025 result = winreg_enumval_to_dword(info2,
2027 "Priority",
2028 &info2->priority);
2029 CHECK_ERROR(result);
2031 result = winreg_enumval_to_dword(info2,
2033 "Default Priority",
2034 &info2->defaultpriority);
2035 CHECK_ERROR(result);
2037 result = winreg_enumval_to_dword(info2,
2039 "StartTime",
2040 &info2->starttime);
2041 CHECK_ERROR(result);
2043 result = winreg_enumval_to_dword(info2,
2045 "UntilTime",
2046 &info2->untiltime);
2047 CHECK_ERROR(result);
2049 result = winreg_enumval_to_dword(info2,
2051 "Status",
2052 &info2->status);
2053 CHECK_ERROR(result);
2055 result = winreg_enumval_to_dword(info2,
2057 "StartTime",
2058 &info2->starttime);
2059 CHECK_ERROR(result);
2061 result = winreg_enumval_to_blob(info2,
2063 "Default DevMode",
2064 &blob);
2065 if (W_ERROR_IS_OK(result)) {
2066 info2->devmode = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
2067 if (info2->devmode == NULL) {
2068 result = WERR_NOMEM;
2069 goto done;
2071 ndr_err = ndr_pull_struct_blob(&blob,
2072 info2,
2073 NULL,
2074 info2->devmode,
2075 (ndr_pull_flags_fn_t) ndr_pull_spoolss_DeviceMode);
2076 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2077 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2078 result = WERR_NOMEM;
2079 goto done;
2082 CHECK_ERROR(result);
2084 result = winreg_enumval_to_blob(info2,
2086 "Security",
2087 &blob);
2088 if (W_ERROR_IS_OK(result)) {
2089 info2->secdesc = talloc_zero(mem_ctx, struct spoolss_security_descriptor);
2090 if (info2->secdesc == NULL) {
2091 result = WERR_NOMEM;
2092 goto done;
2094 ndr_err = ndr_pull_struct_blob(&blob,
2095 mem_ctx,
2096 NULL,
2097 info2->secdesc,
2098 (ndr_pull_flags_fn_t) ndr_pull_security_descriptor);
2099 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2100 DEBUG(0, ("winreg_get_printer: Failed to unmarshall security descriptor\n"));
2101 result = WERR_NOMEM;
2102 goto done;
2105 CHECK_ERROR(result);
2108 if (!W_ERROR_IS_OK(result)) {
2109 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2110 "for %s: %s\n",
2111 v->value_name,
2112 win_errstr(result)));
2113 goto done;
2116 if (pinfo2) {
2117 *pinfo2 = talloc_move(mem_ctx, &info2);
2120 result = WERR_OK;
2121 done:
2122 if (winreg_pipe != NULL) {
2123 if (is_valid_policy_hnd(&key_hnd)) {
2124 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2126 if (is_valid_policy_hnd(&hive_hnd)) {
2127 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2131 TALLOC_FREE(tmp_ctx);
2132 return result;
2135 /* Set printer data over the winreg pipe. */
2136 WERROR winreg_set_printer_dataex(TALLOC_CTX *mem_ctx,
2137 struct auth_serversupplied_info *server_info,
2138 const char *printer,
2139 const char *key,
2140 const char *value,
2141 enum winreg_Type type,
2142 uint8_t *data,
2143 uint32_t data_size)
2145 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2146 struct rpc_pipe_client *winreg_pipe = NULL;
2147 struct policy_handle hive_hnd, key_hnd;
2148 struct winreg_String wvalue;
2149 char *path;
2150 WERROR result = WERR_OK;
2151 NTSTATUS status;
2152 TALLOC_CTX *tmp_ctx;
2154 tmp_ctx = talloc_new(mem_ctx);
2155 if (tmp_ctx == NULL) {
2156 return WERR_NOMEM;
2159 path = winreg_printer_data_keyname(tmp_ctx, printer);
2160 if (path == NULL) {
2161 TALLOC_FREE(tmp_ctx);
2162 return WERR_NOMEM;
2165 ZERO_STRUCT(hive_hnd);
2166 ZERO_STRUCT(key_hnd);
2168 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2169 key, value, access_mask, printer));
2170 result = winreg_printer_openkey(tmp_ctx,
2171 server_info,
2172 &winreg_pipe,
2173 path,
2174 key,
2175 true,
2176 access_mask,
2177 &hive_hnd,
2178 &key_hnd);
2179 if (!W_ERROR_IS_OK(result)) {
2180 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2181 key, win_errstr(result)));
2182 goto done;
2185 wvalue.name = value;
2186 status = rpccli_winreg_SetValue(winreg_pipe,
2187 tmp_ctx,
2188 &key_hnd,
2189 wvalue,
2190 type,
2191 data,
2192 data_size,
2193 &result);
2194 if (!NT_STATUS_IS_OK(status)) {
2195 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2196 value, nt_errstr(status)));
2197 if (!W_ERROR_IS_OK(result)) {
2198 goto done;
2200 result = ntstatus_to_werror(status);
2201 goto done;
2204 result = WERR_OK;
2205 done:
2206 if (winreg_pipe != NULL) {
2207 if (is_valid_policy_hnd(&key_hnd)) {
2208 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2210 if (is_valid_policy_hnd(&hive_hnd)) {
2211 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2215 TALLOC_FREE(tmp_ctx);
2216 return result;
2219 /* Get printer data over a winreg pipe. */
2220 WERROR winreg_get_printer_dataex(TALLOC_CTX *mem_ctx,
2221 struct auth_serversupplied_info *server_info,
2222 const char *printer,
2223 const char *key,
2224 const char *value,
2225 enum winreg_Type *type,
2226 uint8_t **data,
2227 uint32_t *data_size)
2229 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2230 struct rpc_pipe_client *winreg_pipe = NULL;
2231 struct policy_handle hive_hnd, key_hnd;
2232 struct winreg_String wvalue;
2233 enum winreg_Type type_in;
2234 char *path;
2235 uint8_t *data_in;
2236 uint32_t data_in_size = 0;
2237 uint32_t value_len = 0;
2238 WERROR result = WERR_OK;
2239 NTSTATUS status;
2240 TALLOC_CTX *tmp_ctx;
2242 tmp_ctx = talloc_new(mem_ctx);
2243 if (tmp_ctx == NULL) {
2244 return WERR_NOMEM;
2247 path = winreg_printer_data_keyname(tmp_ctx, printer);
2248 if (path == NULL) {
2249 TALLOC_FREE(tmp_ctx);
2250 return WERR_NOMEM;
2253 ZERO_STRUCT(hive_hnd);
2254 ZERO_STRUCT(key_hnd);
2256 result = winreg_printer_openkey(tmp_ctx,
2257 server_info,
2258 &winreg_pipe,
2259 path,
2260 key,
2261 false,
2262 access_mask,
2263 &hive_hnd,
2264 &key_hnd);
2265 if (!W_ERROR_IS_OK(result)) {
2266 DEBUG(0, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2267 key, win_errstr(result)));
2268 goto done;
2271 wvalue.name = value;
2274 * call QueryValue once with data == NULL to get the
2275 * needed memory size to be allocated, then allocate
2276 * data buffer and call again.
2278 status = rpccli_winreg_QueryValue(winreg_pipe,
2279 tmp_ctx,
2280 &key_hnd,
2281 &wvalue,
2282 &type_in,
2283 NULL,
2284 &data_in_size,
2285 &value_len,
2286 &result);
2287 if (!NT_STATUS_IS_OK(status)) {
2288 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2289 value, nt_errstr(status)));
2290 if (!W_ERROR_IS_OK(result)) {
2291 goto done;
2293 result = ntstatus_to_werror(status);
2294 goto done;
2297 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
2298 if (data_in == NULL) {
2299 result = WERR_NOMEM;
2300 goto done;
2302 value_len = 0;
2304 status = rpccli_winreg_QueryValue(winreg_pipe,
2305 tmp_ctx,
2306 &key_hnd,
2307 &wvalue,
2308 &type_in,
2309 data_in,
2310 &data_in_size,
2311 &value_len,
2312 &result);
2313 if (!NT_STATUS_IS_OK(status)) {
2314 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2315 value, nt_errstr(status)));
2316 if (!W_ERROR_IS_OK(result)) {
2317 result = ntstatus_to_werror(status);
2319 goto done;
2322 *type = type_in;
2323 *data_size = data_in_size;
2324 if (data_in_size) {
2325 *data = talloc_move(mem_ctx, &data_in);
2328 result = WERR_OK;
2329 done:
2330 if (winreg_pipe != NULL) {
2331 if (is_valid_policy_hnd(&key_hnd)) {
2332 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2334 if (is_valid_policy_hnd(&hive_hnd)) {
2335 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2339 TALLOC_FREE(tmp_ctx);
2340 return result;
2343 /* Enumerate on the values of a given key and provide the data. */
2344 WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
2345 struct auth_serversupplied_info *server_info,
2346 const char *printer,
2347 const char *key,
2348 uint32_t *pnum_values,
2349 struct spoolss_PrinterEnumValues **penum_values)
2351 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2352 struct rpc_pipe_client *winreg_pipe = NULL;
2353 struct policy_handle hive_hnd, key_hnd;
2355 struct spoolss_PrinterEnumValues *enum_values = NULL;
2356 uint32_t num_values = 0;
2357 char *path;
2358 WERROR result = WERR_OK;
2360 TALLOC_CTX *tmp_ctx;
2362 tmp_ctx = talloc_new(mem_ctx);
2363 if (tmp_ctx == NULL) {
2364 return WERR_NOMEM;
2367 path = winreg_printer_data_keyname(tmp_ctx, printer);
2368 if (path == NULL) {
2369 TALLOC_FREE(tmp_ctx);
2370 return WERR_NOMEM;
2373 result = winreg_printer_openkey(tmp_ctx,
2374 server_info,
2375 &winreg_pipe,
2376 path,
2377 key,
2378 false,
2379 access_mask,
2380 &hive_hnd,
2381 &key_hnd);
2382 if (!W_ERROR_IS_OK(result)) {
2383 DEBUG(0, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2384 key, win_errstr(result)));
2385 goto done;
2388 result = winreg_printer_enumvalues(tmp_ctx,
2389 winreg_pipe,
2390 &key_hnd,
2391 &num_values,
2392 &enum_values);
2393 if (!W_ERROR_IS_OK(result)) {
2394 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2395 key, win_errstr(result)));
2396 goto done;
2399 *pnum_values = num_values;
2400 if (penum_values) {
2401 *penum_values = talloc_move(mem_ctx, &enum_values);
2404 result = WERR_OK;
2405 done:
2406 if (winreg_pipe != NULL) {
2407 if (is_valid_policy_hnd(&key_hnd)) {
2408 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2410 if (is_valid_policy_hnd(&hive_hnd)) {
2411 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2415 TALLOC_FREE(tmp_ctx);
2416 return result;
2419 /* Delete printer data over a winreg pipe. */
2420 WERROR winreg_delete_printer_dataex(TALLOC_CTX *mem_ctx,
2421 struct auth_serversupplied_info *server_info,
2422 const char *printer,
2423 const char *key,
2424 const char *value)
2426 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2427 struct rpc_pipe_client *winreg_pipe = NULL;
2428 struct policy_handle hive_hnd, key_hnd;
2429 struct winreg_String wvalue;
2430 char *path;
2431 WERROR result = WERR_OK;
2432 NTSTATUS status;
2434 TALLOC_CTX *tmp_ctx;
2436 tmp_ctx = talloc_new(mem_ctx);
2437 if (tmp_ctx == NULL) {
2438 return WERR_NOMEM;
2441 path = winreg_printer_data_keyname(tmp_ctx, printer);
2442 if (path == NULL) {
2443 TALLOC_FREE(tmp_ctx);
2444 return WERR_NOMEM;
2447 ZERO_STRUCT(hive_hnd);
2448 ZERO_STRUCT(key_hnd);
2450 result = winreg_printer_openkey(tmp_ctx,
2451 server_info,
2452 &winreg_pipe,
2453 path,
2454 key,
2455 false,
2456 access_mask,
2457 &hive_hnd,
2458 &key_hnd);
2459 if (!W_ERROR_IS_OK(result)) {
2460 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2461 key, win_errstr(result)));
2462 goto done;
2465 wvalue.name = value;
2466 status = rpccli_winreg_DeleteValue(winreg_pipe,
2467 tmp_ctx,
2468 &key_hnd,
2469 wvalue,
2470 &result);
2471 if (!NT_STATUS_IS_OK(status)) {
2472 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2473 value, nt_errstr(status)));
2474 if (!W_ERROR_IS_OK(result)) {
2475 goto done;
2477 result = ntstatus_to_werror(status);
2478 goto done;
2481 result = WERR_OK;
2482 done:
2483 if (winreg_pipe != NULL) {
2484 if (is_valid_policy_hnd(&key_hnd)) {
2485 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2487 if (is_valid_policy_hnd(&hive_hnd)) {
2488 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2492 TALLOC_FREE(tmp_ctx);
2493 return result;
2496 /* Enumerate on the subkeys of a given key and provide the data. */
2497 WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
2498 struct auth_serversupplied_info *server_info,
2499 const char *printer,
2500 const char *key,
2501 uint32_t *pnum_subkeys,
2502 const char ***psubkeys)
2504 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2505 struct rpc_pipe_client *winreg_pipe = NULL;
2506 struct policy_handle hive_hnd, key_hnd;
2507 char *path;
2508 const char **subkeys = NULL;
2509 uint32_t num_subkeys = -1;
2511 WERROR result = WERR_OK;
2513 TALLOC_CTX *tmp_ctx;
2515 tmp_ctx = talloc_new(mem_ctx);
2516 if (tmp_ctx == NULL) {
2517 return WERR_NOMEM;
2520 path = winreg_printer_data_keyname(tmp_ctx, printer);
2521 if (path == NULL) {
2522 TALLOC_FREE(tmp_ctx);
2523 return WERR_NOMEM;
2526 ZERO_STRUCT(hive_hnd);
2527 ZERO_STRUCT(key_hnd);
2529 result = winreg_printer_openkey(tmp_ctx,
2530 server_info,
2531 &winreg_pipe,
2532 path,
2533 key,
2534 false,
2535 access_mask,
2536 &hive_hnd,
2537 &key_hnd);
2538 if (!W_ERROR_IS_OK(result)) {
2539 DEBUG(0, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2540 key, win_errstr(result)));
2541 goto done;
2544 result = winreg_printer_enumkeys(tmp_ctx,
2545 winreg_pipe,
2546 &key_hnd,
2547 &num_subkeys,
2548 &subkeys);
2549 if (!W_ERROR_IS_OK(result)) {
2550 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2551 key, win_errstr(result)));
2552 goto done;
2555 *pnum_subkeys = num_subkeys;
2556 if (psubkeys) {
2557 *psubkeys = talloc_move(mem_ctx, &subkeys);
2560 result = WERR_OK;
2561 done:
2562 if (winreg_pipe != NULL) {
2563 if (is_valid_policy_hnd(&key_hnd)) {
2564 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2566 if (is_valid_policy_hnd(&hive_hnd)) {
2567 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2571 TALLOC_FREE(tmp_ctx);
2572 return result;
2575 /* Delete a key with subkeys of a given printer. */
2576 WERROR winreg_delete_printer_key(TALLOC_CTX *mem_ctx,
2577 struct auth_serversupplied_info *server_info,
2578 const char *printer,
2579 const char *key)
2581 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2582 struct rpc_pipe_client *winreg_pipe = NULL;
2583 struct policy_handle hive_hnd, key_hnd;
2584 char *keyname;
2585 char *path;
2586 WERROR result;
2587 TALLOC_CTX *tmp_ctx;
2589 tmp_ctx = talloc_new(mem_ctx);
2590 if (tmp_ctx == NULL) {
2591 return WERR_NOMEM;
2594 path = winreg_printer_data_keyname(tmp_ctx, printer);
2595 if (path == NULL) {
2596 TALLOC_FREE(tmp_ctx);
2597 return WERR_NOMEM;
2600 result = winreg_printer_openkey(tmp_ctx,
2601 server_info,
2602 &winreg_pipe,
2603 path,
2604 key,
2605 false,
2606 access_mask,
2607 &hive_hnd,
2608 &key_hnd);
2609 if (!W_ERROR_IS_OK(result)) {
2610 /* key doesn't exist */
2611 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2612 result = WERR_OK;
2613 goto done;
2616 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2617 key, win_errstr(result)));
2618 goto done;
2621 if (is_valid_policy_hnd(&key_hnd)) {
2622 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2625 if (key == NULL || key[0] == '\0') {
2626 keyname = path;
2627 } else {
2628 keyname = talloc_asprintf(tmp_ctx,
2629 "%s\\%s",
2630 path,
2631 key);
2632 if (keyname == NULL) {
2633 result = WERR_NOMEM;
2634 goto done;
2638 result = winreg_printer_delete_subkeys(tmp_ctx,
2639 winreg_pipe,
2640 &hive_hnd,
2641 access_mask,
2642 keyname);
2643 if (!W_ERROR_IS_OK(result)) {
2644 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2645 key, win_errstr(result)));
2646 goto done;
2649 done:
2650 if (winreg_pipe != NULL) {
2651 if (is_valid_policy_hnd(&key_hnd)) {
2652 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2654 if (is_valid_policy_hnd(&hive_hnd)) {
2655 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2659 TALLOC_FREE(tmp_ctx);
2660 return result;
2663 WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx,
2664 struct auth_serversupplied_info *server_info,
2665 const char *printer)
2667 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2668 struct rpc_pipe_client *winreg_pipe = NULL;
2669 struct policy_handle hive_hnd, key_hnd;
2670 char *path;
2671 WERROR result;
2672 TALLOC_CTX *tmp_ctx;
2674 tmp_ctx = talloc_new(mem_ctx);
2675 if (tmp_ctx == NULL) {
2676 return WERR_NOMEM;
2679 path = winreg_printer_data_keyname(tmp_ctx, printer);
2680 if (path == NULL) {
2681 TALLOC_FREE(tmp_ctx);
2682 return WERR_NOMEM;
2685 ZERO_STRUCT(hive_hnd);
2686 ZERO_STRUCT(key_hnd);
2688 result = winreg_printer_openkey(tmp_ctx,
2689 server_info,
2690 &winreg_pipe,
2691 path,
2693 false,
2694 access_mask,
2695 &hive_hnd,
2696 &key_hnd);
2697 if (!W_ERROR_IS_OK(result)) {
2698 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2699 path, win_errstr(result)));
2700 goto done;
2703 result = winreg_printer_write_dword(tmp_ctx,
2704 winreg_pipe,
2705 &key_hnd,
2706 "ChangeID",
2707 winreg_printer_rev_changeid());
2708 if (!W_ERROR_IS_OK(result)) {
2709 goto done;
2712 result = WERR_OK;
2713 done:
2714 if (winreg_pipe != NULL) {
2715 if (is_valid_policy_hnd(&key_hnd)) {
2716 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2718 if (is_valid_policy_hnd(&hive_hnd)) {
2719 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2723 TALLOC_FREE(tmp_ctx);
2724 return result;
2727 WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx,
2728 struct auth_serversupplied_info *server_info,
2729 const char *printer,
2730 uint32_t *pchangeid)
2732 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2733 struct rpc_pipe_client *winreg_pipe = NULL;
2734 struct policy_handle hive_hnd, key_hnd;
2735 uint32_t changeid = 0;
2736 char *path;
2737 WERROR result;
2738 TALLOC_CTX *tmp_ctx;
2740 tmp_ctx = talloc_new(mem_ctx);
2741 if (tmp_ctx == NULL) {
2742 return WERR_NOMEM;
2745 path = winreg_printer_data_keyname(tmp_ctx, printer);
2746 if (path == NULL) {
2747 TALLOC_FREE(tmp_ctx);
2748 return WERR_NOMEM;
2751 ZERO_STRUCT(hive_hnd);
2752 ZERO_STRUCT(key_hnd);
2754 result = winreg_printer_openkey(tmp_ctx,
2755 server_info,
2756 &winreg_pipe,
2757 path,
2759 false,
2760 access_mask,
2761 &hive_hnd,
2762 &key_hnd);
2763 if (!W_ERROR_IS_OK(result)) {
2764 DEBUG(0, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2765 path, win_errstr(result)));
2766 goto done;
2769 DEBUG(0, ("winreg_printer_get_changeid: get changeid from %s\n", path));
2770 result = winreg_printer_query_dword(tmp_ctx,
2771 winreg_pipe,
2772 &key_hnd,
2773 "ChangeID",
2774 &changeid);
2775 if (!W_ERROR_IS_OK(result)) {
2776 goto done;
2779 if (pchangeid) {
2780 *pchangeid = changeid;
2783 result = WERR_OK;
2784 done:
2785 if (winreg_pipe != NULL) {
2786 if (is_valid_policy_hnd(&key_hnd)) {
2787 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2789 if (is_valid_policy_hnd(&hive_hnd)) {
2790 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2794 TALLOC_FREE(tmp_ctx);
2795 return result;
2799 * The special behaviour of the spoolss forms is documented at the website:
2801 * Managing Win32 Printserver Forms
2802 * http://unixwiz.net/techtips/winspooler-forms.html
2805 WERROR winreg_printer_addform1(TALLOC_CTX *mem_ctx,
2806 struct auth_serversupplied_info *server_info,
2807 struct spoolss_AddFormInfo1 *form)
2809 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2810 struct rpc_pipe_client *winreg_pipe = NULL;
2811 struct policy_handle hive_hnd, key_hnd;
2812 struct winreg_String wvalue;
2813 DATA_BLOB blob;
2814 uint32_t num_info = 0;
2815 union spoolss_FormInfo *info = NULL;
2816 uint32_t i;
2817 WERROR result;
2818 NTSTATUS status;
2819 TALLOC_CTX *tmp_ctx;
2821 tmp_ctx = talloc_new(mem_ctx);
2822 if (tmp_ctx == NULL) {
2823 return WERR_NOMEM;
2826 ZERO_STRUCT(hive_hnd);
2827 ZERO_STRUCT(key_hnd);
2829 result = winreg_printer_openkey(tmp_ctx,
2830 server_info,
2831 &winreg_pipe,
2832 TOP_LEVEL_CONTROL_FORMS_KEY,
2834 true,
2835 access_mask,
2836 &hive_hnd,
2837 &key_hnd);
2838 if (!W_ERROR_IS_OK(result)) {
2839 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2840 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2841 goto done;
2844 result = winreg_printer_enumforms1(tmp_ctx, server_info, &num_info, &info);
2845 if (!W_ERROR_IS_OK(result)) {
2846 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2847 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2848 goto done;
2851 /* If form name already exists or is builtin return ALREADY_EXISTS */
2852 for (i = 0; i < num_info; i++) {
2853 if (strequal(info[i].info1.form_name, form->form_name)) {
2854 result = WERR_FILE_EXISTS;
2855 goto done;
2859 wvalue.name = form->form_name;
2861 blob = data_blob_talloc(tmp_ctx, NULL, 32);
2862 SIVAL(blob.data, 0, form->size.width);
2863 SIVAL(blob.data, 4, form->size.height);
2864 SIVAL(blob.data, 8, form->area.left);
2865 SIVAL(blob.data, 12, form->area.top);
2866 SIVAL(blob.data, 16, form->area.right);
2867 SIVAL(blob.data, 20, form->area.bottom);
2868 SIVAL(blob.data, 24, num_info + 1); /* FIXME */
2869 SIVAL(blob.data, 28, form->flags);
2871 status = rpccli_winreg_SetValue(winreg_pipe,
2872 tmp_ctx,
2873 &key_hnd,
2874 wvalue,
2875 REG_BINARY,
2876 blob.data,
2877 blob.length,
2878 &result);
2879 if (!NT_STATUS_IS_OK(status)) {
2880 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2881 wvalue.name, nt_errstr(status)));
2882 if (!W_ERROR_IS_OK(result)) {
2883 goto done;
2885 result = ntstatus_to_werror(status);
2886 goto done;
2889 result = WERR_OK;
2890 done:
2891 if (winreg_pipe != NULL) {
2892 if (is_valid_policy_hnd(&key_hnd)) {
2893 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
2895 if (is_valid_policy_hnd(&hive_hnd)) {
2896 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
2900 TALLOC_FREE(info);
2901 TALLOC_FREE(tmp_ctx);
2902 return result;
2905 WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
2906 struct auth_serversupplied_info *server_info,
2907 uint32_t *pnum_info,
2908 union spoolss_FormInfo **pinfo)
2910 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2911 struct rpc_pipe_client *winreg_pipe = NULL;
2912 struct policy_handle hive_hnd, key_hnd;
2913 union spoolss_FormInfo *info;
2914 struct spoolss_PrinterEnumValues *enum_values = NULL;
2915 uint32_t num_values = 0;
2916 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
2917 uint32_t i;
2918 WERROR result;
2919 TALLOC_CTX *tmp_ctx;
2921 tmp_ctx = talloc_new(mem_ctx);
2922 if (tmp_ctx == NULL) {
2923 return WERR_NOMEM;
2926 ZERO_STRUCT(hive_hnd);
2927 ZERO_STRUCT(key_hnd);
2929 result = winreg_printer_openkey(tmp_ctx,
2930 server_info,
2931 &winreg_pipe,
2932 TOP_LEVEL_CONTROL_FORMS_KEY,
2934 true,
2935 access_mask,
2936 &hive_hnd,
2937 &key_hnd);
2938 if (!W_ERROR_IS_OK(result)) {
2939 /* key doesn't exist */
2940 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
2941 result = WERR_OK;
2942 goto done;
2945 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
2946 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2947 goto done;
2950 result = winreg_printer_enumvalues(tmp_ctx,
2951 winreg_pipe,
2952 &key_hnd,
2953 &num_values,
2954 &enum_values);
2955 if (!W_ERROR_IS_OK(result)) {
2956 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2957 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
2958 goto done;
2961 info = TALLOC_ARRAY(tmp_ctx, union spoolss_FormInfo, num_builtin + num_values);
2962 if (info == NULL) {
2963 result = WERR_NOMEM;
2964 goto done;
2967 /* Enumerate BUILTIN forms */
2968 for (i = 0; i < num_builtin; i++) {
2969 info[i].info1 = builtin_forms1[i];
2972 /* Enumerate registry forms */
2973 for (i = 0; i < num_values; i++) {
2974 union spoolss_FormInfo val;
2976 if (enum_values[i].type != REG_BINARY ||
2977 enum_values[i].data_length != 32) {
2978 continue;
2981 val.info1.form_name = talloc_strdup(info, enum_values[i].value_name);
2982 if (val.info1.form_name == NULL) {
2983 result = WERR_NOMEM;
2984 goto done;
2987 val.info1.size.width = IVAL(enum_values[i].data->data, 0);
2988 val.info1.size.height = IVAL(enum_values[i].data->data, 4);
2989 val.info1.area.left = IVAL(enum_values[i].data->data, 8);
2990 val.info1.area.top = IVAL(enum_values[i].data->data, 12);
2991 val.info1.area.right = IVAL(enum_values[i].data->data, 16);
2992 val.info1.area.bottom = IVAL(enum_values[i].data->data, 20);
2993 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
2994 val.info1.flags = IVAL(enum_values[i].data->data, 28);
2996 info[i + num_builtin] = val;
2999 *pnum_info = num_builtin + num_values;
3000 if (pinfo) {
3001 *pinfo = talloc_move(mem_ctx, &info);
3004 done:
3005 if (winreg_pipe != NULL) {
3006 if (is_valid_policy_hnd(&key_hnd)) {
3007 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3009 if (is_valid_policy_hnd(&hive_hnd)) {
3010 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3014 TALLOC_FREE(enum_values);
3015 TALLOC_FREE(tmp_ctx);
3016 return result;
3019 WERROR winreg_printer_deleteform1(TALLOC_CTX *mem_ctx,
3020 struct auth_serversupplied_info *server_info,
3021 const char *form_name)
3023 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3024 struct rpc_pipe_client *winreg_pipe = NULL;
3025 struct policy_handle hive_hnd, key_hnd;
3026 struct winreg_String wvalue;
3027 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3028 uint32_t i;
3029 WERROR result = WERR_OK;
3030 NTSTATUS status;
3031 TALLOC_CTX *tmp_ctx;
3033 for (i = 0; i < num_builtin; i++) {
3034 if (strequal(builtin_forms1[i].form_name, form_name)) {
3035 return WERR_INVALID_PARAMETER;
3039 tmp_ctx = talloc_new(mem_ctx);
3040 if (tmp_ctx == NULL) {
3041 return WERR_NOMEM;
3044 ZERO_STRUCT(hive_hnd);
3045 ZERO_STRUCT(key_hnd);
3047 result = winreg_printer_openkey(tmp_ctx,
3048 server_info,
3049 &winreg_pipe,
3050 TOP_LEVEL_CONTROL_FORMS_KEY,
3052 false,
3053 access_mask,
3054 &hive_hnd,
3055 &key_hnd);
3056 if (!W_ERROR_IS_OK(result)) {
3057 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3058 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3059 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3060 result = WERR_INVALID_FORM_NAME;
3062 goto done;
3065 wvalue.name = form_name;
3066 status = rpccli_winreg_DeleteValue(winreg_pipe,
3067 tmp_ctx,
3068 &key_hnd,
3069 wvalue,
3070 &result);
3071 if (!NT_STATUS_IS_OK(status)) {
3072 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3073 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3074 result = WERR_INVALID_FORM_NAME;
3075 goto done;
3077 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3078 wvalue.name, nt_errstr(status)));
3079 if (!W_ERROR_IS_OK(result)) {
3080 goto done;
3082 result = ntstatus_to_werror(status);
3083 goto done;
3086 result = WERR_OK;
3087 done:
3088 if (winreg_pipe != NULL) {
3089 if (is_valid_policy_hnd(&key_hnd)) {
3090 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3092 if (is_valid_policy_hnd(&hive_hnd)) {
3093 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3097 TALLOC_FREE(tmp_ctx);
3098 return result;
3101 WERROR winreg_printer_setform1(TALLOC_CTX *mem_ctx,
3102 struct auth_serversupplied_info *server_info,
3103 const char *form_name,
3104 struct spoolss_AddFormInfo1 *form)
3106 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3107 struct rpc_pipe_client *winreg_pipe = NULL;
3108 struct policy_handle hive_hnd, key_hnd;
3109 struct winreg_String wvalue;
3110 DATA_BLOB blob;
3111 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3112 uint32_t i;
3113 WERROR result;
3114 NTSTATUS status;
3115 TALLOC_CTX *tmp_ctx = NULL;
3117 for (i = 0; i < num_builtin; i++) {
3118 if (strequal(builtin_forms1[i].form_name, form->form_name)) {
3119 result = WERR_INVALID_PARAM;
3120 goto done;
3124 tmp_ctx = talloc_new(mem_ctx);
3125 if (tmp_ctx == NULL) {
3126 return WERR_NOMEM;
3129 ZERO_STRUCT(hive_hnd);
3130 ZERO_STRUCT(key_hnd);
3132 result = winreg_printer_openkey(tmp_ctx,
3133 server_info,
3134 &winreg_pipe,
3135 TOP_LEVEL_CONTROL_FORMS_KEY,
3137 true,
3138 access_mask,
3139 &hive_hnd,
3140 &key_hnd);
3141 if (!W_ERROR_IS_OK(result)) {
3142 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3143 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3144 goto done;
3147 /* If form_name != form->form_name then we renamed the form */
3148 if (strequal(form_name, form->form_name)) {
3149 result = winreg_printer_deleteform1(tmp_ctx, server_info, form_name);
3150 if (!W_ERROR_IS_OK(result)) {
3151 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3152 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3153 goto done;
3157 wvalue.name = form->form_name;
3159 blob = data_blob_talloc(tmp_ctx, NULL, 32);
3160 SIVAL(blob.data, 0, form->size.width);
3161 SIVAL(blob.data, 4, form->size.height);
3162 SIVAL(blob.data, 8, form->area.left);
3163 SIVAL(blob.data, 12, form->area.top);
3164 SIVAL(blob.data, 16, form->area.right);
3165 SIVAL(blob.data, 20, form->area.bottom);
3166 SIVAL(blob.data, 24, 42);
3167 SIVAL(blob.data, 28, form->flags);
3169 status = rpccli_winreg_SetValue(winreg_pipe,
3170 tmp_ctx,
3171 &key_hnd,
3172 wvalue,
3173 REG_BINARY,
3174 blob.data,
3175 blob.length,
3176 &result);
3177 if (!NT_STATUS_IS_OK(status)) {
3178 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3179 wvalue.name, nt_errstr(status)));
3180 if (!W_ERROR_IS_OK(result)) {
3181 goto done;
3183 result = ntstatus_to_werror(status);
3184 goto done;
3187 result = WERR_OK;
3188 done:
3189 if (winreg_pipe != NULL) {
3190 if (is_valid_policy_hnd(&key_hnd)) {
3191 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3193 if (is_valid_policy_hnd(&hive_hnd)) {
3194 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3198 TALLOC_FREE(tmp_ctx);
3199 return result;
3202 WERROR winreg_printer_getform1(TALLOC_CTX *mem_ctx,
3203 struct auth_serversupplied_info *server_info,
3204 const char *form_name,
3205 struct spoolss_FormInfo1 *r)
3207 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3208 struct rpc_pipe_client *winreg_pipe = NULL;
3209 struct policy_handle hive_hnd, key_hnd;
3210 struct winreg_String wvalue;
3211 enum winreg_Type type_in;
3212 uint8_t *data_in;
3213 uint32_t data_in_size = 0;
3214 uint32_t value_len = 0;
3215 uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
3216 uint32_t i;
3217 WERROR result;
3218 NTSTATUS status;
3219 TALLOC_CTX *tmp_ctx;
3221 /* check builtin forms first */
3222 for (i = 0; i < num_builtin; i++) {
3223 if (strequal(builtin_forms1[i].form_name, form_name)) {
3224 *r = builtin_forms1[i];
3225 return WERR_OK;
3229 tmp_ctx = talloc_new(mem_ctx);
3230 if (tmp_ctx == NULL) {
3231 return WERR_NOMEM;
3234 ZERO_STRUCT(hive_hnd);
3235 ZERO_STRUCT(key_hnd);
3237 result = winreg_printer_openkey(tmp_ctx,
3238 server_info,
3239 &winreg_pipe,
3240 TOP_LEVEL_CONTROL_FORMS_KEY,
3242 true,
3243 access_mask,
3244 &hive_hnd,
3245 &key_hnd);
3246 if (!W_ERROR_IS_OK(result)) {
3247 DEBUG(0, ("winreg_printer_getform1: Could not open key %s: %s\n",
3248 TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
3249 goto done;
3252 wvalue.name = form_name;
3255 * call QueryValue once with data == NULL to get the
3256 * needed memory size to be allocated, then allocate
3257 * data buffer and call again.
3259 status = rpccli_winreg_QueryValue(winreg_pipe,
3260 tmp_ctx,
3261 &key_hnd,
3262 &wvalue,
3263 &type_in,
3264 NULL,
3265 &data_in_size,
3266 &value_len,
3267 &result);
3268 if (!NT_STATUS_IS_OK(status)) {
3269 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3270 wvalue.name, nt_errstr(status)));
3271 if (!W_ERROR_IS_OK(result)) {
3272 goto done;
3274 result = ntstatus_to_werror(status);
3275 goto done;
3278 data_in = (uint8_t *) TALLOC(tmp_ctx, data_in_size);
3279 if (data_in == NULL) {
3280 result = WERR_NOMEM;
3281 goto done;
3283 value_len = 0;
3285 status = rpccli_winreg_QueryValue(winreg_pipe,
3286 tmp_ctx,
3287 &key_hnd,
3288 &wvalue,
3289 &type_in,
3290 data_in,
3291 &data_in_size,
3292 &value_len,
3293 &result);
3294 if (!NT_STATUS_IS_OK(status)) {
3295 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3296 wvalue.name, nt_errstr(status)));
3297 if (!W_ERROR_IS_OK(result)) {
3298 goto done;
3300 result = ntstatus_to_werror(status);
3301 goto done;
3304 r->form_name = talloc_strdup(mem_ctx, form_name);
3305 if (r->form_name == NULL) {
3306 result = WERR_NOMEM;
3307 goto done;
3310 r->size.width = IVAL(data_in, 0);
3311 r->size.height = IVAL(data_in, 4);
3312 r->area.left = IVAL(data_in, 8);
3313 r->area.top = IVAL(data_in, 12);
3314 r->area.right = IVAL(data_in, 16);
3315 r->area.bottom = IVAL(data_in, 20);
3316 /* skip index IVAL(data_in, 24)));*/
3317 r->flags = IVAL(data_in, 28);
3319 result = WERR_OK;
3320 done:
3321 if (winreg_pipe != NULL) {
3322 if (is_valid_policy_hnd(&key_hnd)) {
3323 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3325 if (is_valid_policy_hnd(&hive_hnd)) {
3326 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3330 TALLOC_FREE(tmp_ctx);
3331 return result;
3334 WERROR winreg_add_driver(TALLOC_CTX *mem_ctx,
3335 struct auth_serversupplied_info *server_info,
3336 struct spoolss_AddDriverInfoCtr *r,
3337 const char **driver_name,
3338 uint32_t *driver_version)
3340 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3341 struct rpc_pipe_client *winreg_pipe = NULL;
3342 struct policy_handle hive_hnd, key_hnd;
3343 struct spoolss_DriverInfo8 info8;
3344 TALLOC_CTX *tmp_ctx = NULL;
3345 WERROR result;
3347 ZERO_STRUCT(hive_hnd);
3348 ZERO_STRUCT(key_hnd);
3349 ZERO_STRUCT(info8);
3351 if (!driver_info_ctr_to_info8(r, &info8)) {
3352 result = WERR_INVALID_PARAMETER;
3353 goto done;
3356 tmp_ctx = talloc_new(mem_ctx);
3357 if (tmp_ctx == NULL) {
3358 return WERR_NOMEM;
3361 result = winreg_printer_opendriver(tmp_ctx,
3362 server_info,
3363 info8.driver_name,
3364 info8.architecture,
3365 info8.version,
3366 access_mask, true,
3367 &winreg_pipe,
3368 &hive_hnd,
3369 &key_hnd);
3370 if (!W_ERROR_IS_OK(result)) {
3371 DEBUG(0, ("winreg_add_driver: "
3372 "Could not open driver key (%s,%s,%d): %s\n",
3373 info8.driver_name, info8.architecture,
3374 info8.version, win_errstr(result)));
3375 goto done;
3378 /* TODO: "Attributes" ? */
3380 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe,
3381 &key_hnd, "Version",
3382 info8.version);
3383 if (!W_ERROR_IS_OK(result)) {
3384 goto done;
3387 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3388 &key_hnd, "Driver",
3389 info8.driver_path);
3390 if (!W_ERROR_IS_OK(result)) {
3391 goto done;
3394 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3395 &key_hnd, "Data File",
3396 info8.data_file);
3397 if (!W_ERROR_IS_OK(result)) {
3398 goto done;
3401 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3402 &key_hnd, "Configuration File",
3403 info8.config_file);
3404 if (!W_ERROR_IS_OK(result)) {
3405 goto done;
3408 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3409 &key_hnd, "Help File",
3410 info8.help_file);
3411 if (!W_ERROR_IS_OK(result)) {
3412 goto done;
3415 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3416 &key_hnd, "Dependent Files",
3417 info8.dependent_files);
3418 if (!W_ERROR_IS_OK(result)) {
3419 goto done;
3422 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3423 &key_hnd, "Monitor",
3424 info8.monitor_name);
3425 if (!W_ERROR_IS_OK(result)) {
3426 goto done;
3429 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3430 &key_hnd, "Datatype",
3431 info8.default_datatype);
3432 if (!W_ERROR_IS_OK(result)) {
3433 goto done;
3436 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3437 &key_hnd, "Previous Names",
3438 info8.previous_names);
3439 if (!W_ERROR_IS_OK(result)) {
3440 goto done;
3443 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3444 &key_hnd, "DriverDate",
3445 info8.driver_date);
3446 if (!W_ERROR_IS_OK(result)) {
3447 goto done;
3450 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe,
3451 &key_hnd, "DriverVersion",
3452 info8.driver_version);
3453 if (!W_ERROR_IS_OK(result)) {
3454 goto done;
3457 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3458 &key_hnd, "Manufacturer",
3459 info8.manufacturer_name);
3460 if (!W_ERROR_IS_OK(result)) {
3461 goto done;
3464 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3465 &key_hnd, "OEM URL",
3466 info8.manufacturer_url);
3467 if (!W_ERROR_IS_OK(result)) {
3468 goto done;
3471 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3472 &key_hnd, "HardwareID",
3473 info8.hardware_id);
3474 if (!W_ERROR_IS_OK(result)) {
3475 goto done;
3478 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3479 &key_hnd, "Provider",
3480 info8.provider);
3481 if (!W_ERROR_IS_OK(result)) {
3482 goto done;
3485 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3486 &key_hnd, "Print Processor",
3487 info8.print_processor);
3488 if (!W_ERROR_IS_OK(result)) {
3489 goto done;
3492 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3493 &key_hnd, "VendorSetup",
3494 info8.vendor_setup);
3495 if (!W_ERROR_IS_OK(result)) {
3496 goto done;
3499 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3500 &key_hnd, "Color Profiles",
3501 info8.color_profiles);
3502 if (!W_ERROR_IS_OK(result)) {
3503 goto done;
3506 result = winreg_printer_write_sz(tmp_ctx, winreg_pipe,
3507 &key_hnd, "InfPath",
3508 info8.inf_path);
3509 if (!W_ERROR_IS_OK(result)) {
3510 goto done;
3513 result = winreg_printer_write_dword(tmp_ctx, winreg_pipe, &key_hnd,
3514 "PrinterDriverAttributes",
3515 info8.printer_driver_attributes);
3516 if (!W_ERROR_IS_OK(result)) {
3517 goto done;
3520 result = winreg_printer_write_multi_sz(tmp_ctx, winreg_pipe,
3521 &key_hnd, "CoreDependencies",
3522 info8.core_driver_dependencies);
3523 if (!W_ERROR_IS_OK(result)) {
3524 goto done;
3527 result = winreg_printer_write_date(tmp_ctx, winreg_pipe,
3528 &key_hnd, "MinInboxDriverVerDate",
3529 info8.min_inbox_driver_ver_date);
3530 if (!W_ERROR_IS_OK(result)) {
3531 goto done;
3534 result = winreg_printer_write_ver(tmp_ctx, winreg_pipe, &key_hnd,
3535 "MinInboxDriverVerVersion",
3536 info8.min_inbox_driver_ver_version);
3537 if (!W_ERROR_IS_OK(result)) {
3538 goto done;
3541 *driver_name = info8.driver_name;
3542 *driver_version = info8.version;
3543 result = WERR_OK;
3544 done:
3545 if (winreg_pipe != NULL) {
3546 if (is_valid_policy_hnd(&key_hnd)) {
3547 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3549 if (is_valid_policy_hnd(&hive_hnd)) {
3550 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3554 TALLOC_FREE(tmp_ctx);
3555 return result;
3558 WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
3559 struct auth_serversupplied_info *server_info,
3560 const char *architecture,
3561 const char *driver_name,
3562 uint32_t driver_version,
3563 struct spoolss_DriverInfo8 **_info8)
3565 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3566 struct rpc_pipe_client *winreg_pipe = NULL;
3567 struct policy_handle hive_hnd, key_hnd;
3568 struct spoolss_DriverInfo8 i8, *info8;
3569 struct spoolss_PrinterEnumValues *enum_values = NULL;
3570 struct spoolss_PrinterEnumValues *v;
3571 uint32_t num_values = 0;
3572 TALLOC_CTX *tmp_ctx;
3573 WERROR result;
3574 uint32_t i;
3576 ZERO_STRUCT(hive_hnd);
3577 ZERO_STRUCT(key_hnd);
3578 ZERO_STRUCT(i8);
3580 tmp_ctx = talloc_new(mem_ctx);
3581 if (tmp_ctx == NULL) {
3582 return WERR_NOMEM;
3585 if (driver_version == DRIVER_ANY_VERSION) {
3586 /* look for Win2k first and then for NT4 */
3587 result = winreg_printer_opendriver(tmp_ctx,
3588 server_info,
3589 driver_name,
3590 architecture,
3592 access_mask, false,
3593 &winreg_pipe,
3594 &hive_hnd,
3595 &key_hnd);
3596 if (!W_ERROR_IS_OK(result)) {
3597 result = winreg_printer_opendriver(tmp_ctx,
3598 server_info,
3599 driver_name,
3600 architecture,
3602 access_mask, false,
3603 &winreg_pipe,
3604 &hive_hnd,
3605 &key_hnd);
3607 } else {
3608 /* ok normal case */
3609 result = winreg_printer_opendriver(tmp_ctx,
3610 server_info,
3611 driver_name,
3612 architecture,
3613 driver_version,
3614 access_mask, false,
3615 &winreg_pipe,
3616 &hive_hnd,
3617 &key_hnd);
3619 if (!W_ERROR_IS_OK(result)) {
3620 DEBUG(5, ("winreg_get_driver: "
3621 "Could not open driver key (%s,%s,%d): %s\n",
3622 driver_name, architecture,
3623 driver_version, win_errstr(result)));
3624 goto done;
3627 result = winreg_printer_enumvalues(tmp_ctx,
3628 winreg_pipe,
3629 &key_hnd,
3630 &num_values,
3631 &enum_values);
3632 if (!W_ERROR_IS_OK(result)) {
3633 DEBUG(0, ("winreg_get_driver: "
3634 "Could not enumerate values for (%s,%s,%d): %s\n",
3635 driver_name, architecture,
3636 driver_version, win_errstr(result)));
3637 goto done;
3640 info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
3641 if (!info8) {
3642 result = WERR_NOMEM;
3643 goto done;
3646 result = WERR_OK;
3648 for (i = 0; i < num_values; i++) {
3649 const char *tmp_str;
3651 v = &enum_values[i];
3653 result = winreg_enumval_to_dword(info8, v,
3654 "Version",
3655 &info8->version);
3656 CHECK_ERROR(result);
3658 result = winreg_enumval_to_sz(info8, v,
3659 "Driver",
3660 &info8->driver_path);
3661 CHECK_ERROR(result);
3663 result = winreg_enumval_to_sz(info8, v,
3664 "Data File",
3665 &info8->data_file);
3666 CHECK_ERROR(result);
3668 result = winreg_enumval_to_sz(info8, v,
3669 "Configuration File",
3670 &info8->config_file);
3671 CHECK_ERROR(result);
3673 result = winreg_enumval_to_sz(info8, v,
3674 "Help File",
3675 &info8->help_file);
3676 CHECK_ERROR(result);
3678 result = winreg_enumval_to_multi_sz(info8, v,
3679 "Dependent Files",
3680 &info8->dependent_files);
3681 CHECK_ERROR(result);
3683 result = winreg_enumval_to_sz(info8, v,
3684 "Monitor",
3685 &info8->monitor_name);
3686 CHECK_ERROR(result);
3688 result = winreg_enumval_to_sz(info8, v,
3689 "Datatype",
3690 &info8->default_datatype);
3691 CHECK_ERROR(result);
3693 result = winreg_enumval_to_multi_sz(info8, v,
3694 "Previous Names",
3695 &info8->previous_names);
3696 CHECK_ERROR(result);
3698 result = winreg_enumval_to_sz(info8, v,
3699 "DriverDate",
3700 &tmp_str);
3701 if (W_ERROR_IS_OK(result)) {
3702 result = winreg_printer_date_to_NTTIME(tmp_str,
3703 &info8->driver_date);
3705 CHECK_ERROR(result);
3707 result = winreg_enumval_to_sz(info8, v,
3708 "DriverVersion",
3709 &tmp_str);
3710 if (W_ERROR_IS_OK(result)) {
3711 result = winreg_printer_ver_to_dword(tmp_str,
3712 &info8->driver_version);
3714 CHECK_ERROR(result);
3716 result = winreg_enumval_to_sz(info8, v,
3717 "Manufacturer",
3718 &info8->manufacturer_name);
3719 CHECK_ERROR(result);
3721 result = winreg_enumval_to_sz(info8, v,
3722 "OEM URL",
3723 &info8->manufacturer_url);
3724 CHECK_ERROR(result);
3726 result = winreg_enumval_to_sz(info8, v,
3727 "HardwareID",
3728 &info8->hardware_id);
3729 CHECK_ERROR(result);
3731 result = winreg_enumval_to_sz(info8, v,
3732 "Provider",
3733 &info8->provider);
3734 CHECK_ERROR(result);
3736 result = winreg_enumval_to_sz(info8, v,
3737 "Print Processor",
3738 &info8->print_processor);
3739 CHECK_ERROR(result);
3741 result = winreg_enumval_to_sz(info8, v,
3742 "VendorSetup",
3743 &info8->vendor_setup);
3744 CHECK_ERROR(result);
3746 result = winreg_enumval_to_multi_sz(info8, v,
3747 "Color Profiles",
3748 &info8->color_profiles);
3749 CHECK_ERROR(result);
3751 result = winreg_enumval_to_sz(info8, v,
3752 "InfPath",
3753 &info8->inf_path);
3754 CHECK_ERROR(result);
3756 result = winreg_enumval_to_dword(info8, v,
3757 "PrinterDriverAttributes",
3758 &info8->printer_driver_attributes);
3759 CHECK_ERROR(result);
3761 result = winreg_enumval_to_multi_sz(info8, v,
3762 "CoreDependencies",
3763 &info8->core_driver_dependencies);
3764 CHECK_ERROR(result);
3766 result = winreg_enumval_to_sz(info8, v,
3767 "MinInboxDriverVerDate",
3768 &tmp_str);
3769 if (W_ERROR_IS_OK(result)) {
3770 result = winreg_printer_date_to_NTTIME(tmp_str,
3771 &info8->min_inbox_driver_ver_date);
3773 CHECK_ERROR(result);
3775 result = winreg_enumval_to_sz(info8, v,
3776 "MinInboxDriverVerVersion",
3777 &tmp_str);
3778 if (W_ERROR_IS_OK(result)) {
3779 result = winreg_printer_ver_to_dword(tmp_str,
3780 &info8->min_inbox_driver_ver_version);
3782 CHECK_ERROR(result);
3785 if (!W_ERROR_IS_OK(result)) {
3786 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3787 "for %s: %s\n", v->value_name,
3788 win_errstr(result)));
3789 goto done;
3792 *_info8 = talloc_steal(mem_ctx, info8);
3793 result = WERR_OK;
3794 done:
3795 if (winreg_pipe != NULL) {
3796 if (is_valid_policy_hnd(&key_hnd)) {
3797 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3799 if (is_valid_policy_hnd(&hive_hnd)) {
3800 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3804 TALLOC_FREE(tmp_ctx);
3805 return result;
3808 WERROR winreg_del_driver(TALLOC_CTX *mem_ctx,
3809 struct auth_serversupplied_info *server_info,
3810 struct spoolss_DriverInfo8 *info8,
3811 uint32_t version)
3813 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3814 struct rpc_pipe_client *winreg_pipe = NULL;
3815 struct policy_handle hive_hnd, key_hnd;
3816 TALLOC_CTX *tmp_ctx;
3817 char *key_name;
3818 WERROR result;
3820 ZERO_STRUCT(hive_hnd);
3821 ZERO_STRUCT(key_hnd);
3823 tmp_ctx = talloc_new(mem_ctx);
3824 if (tmp_ctx == NULL) {
3825 return WERR_NOMEM;
3828 /* test that the key exists */
3829 result = winreg_printer_opendriver(tmp_ctx,
3830 server_info,
3831 info8->driver_name,
3832 info8->architecture,
3833 version,
3834 access_mask, false,
3835 &winreg_pipe,
3836 &hive_hnd,
3837 &key_hnd);
3838 if (!W_ERROR_IS_OK(result)) {
3839 /* key doesn't exist */
3840 if (W_ERROR_EQUAL(result, WERR_BADFILE)) {
3841 result = WERR_OK;
3842 goto done;
3845 DEBUG(5, ("winreg_del_driver: "
3846 "Could not open driver (%s,%s,%u): %s\n",
3847 info8->driver_name, info8->architecture,
3848 version, win_errstr(result)));
3849 goto done;
3853 if (is_valid_policy_hnd(&key_hnd)) {
3854 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3857 key_name = talloc_asprintf(tmp_ctx,
3858 "%s\\Environments\\%s\\Drivers\\Version-%u",
3859 TOP_LEVEL_CONTROL_KEY,
3860 info8->architecture, version);
3861 if (key_name == NULL) {
3862 result = WERR_NOMEM;
3863 goto done;
3866 result = winreg_printer_delete_subkeys(tmp_ctx,
3867 winreg_pipe,
3868 &hive_hnd,
3869 access_mask,
3870 key_name);
3871 if (!W_ERROR_IS_OK(result)) {
3872 DEBUG(0, ("winreg_del_driver: "
3873 "Could not open driver (%s,%s,%u): %s\n",
3874 info8->driver_name, info8->architecture,
3875 version, win_errstr(result)));
3876 goto done;
3879 result = WERR_OK;
3880 done:
3881 if (winreg_pipe != NULL) {
3882 if (is_valid_policy_hnd(&key_hnd)) {
3883 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3885 if (is_valid_policy_hnd(&hive_hnd)) {
3886 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3890 TALLOC_FREE(tmp_ctx);
3891 return result;
3894 WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
3895 struct auth_serversupplied_info *server_info,
3896 const char *architecture,
3897 uint32_t version,
3898 uint32_t *num_drivers,
3899 const char ***drivers)
3901 uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
3902 struct rpc_pipe_client *winreg_pipe = NULL;
3903 struct policy_handle hive_hnd, key_hnd;
3904 TALLOC_CTX *tmp_ctx;
3905 WERROR result;
3907 ZERO_STRUCT(hive_hnd);
3908 ZERO_STRUCT(key_hnd);
3910 tmp_ctx = talloc_new(mem_ctx);
3911 if (tmp_ctx == NULL) {
3912 return WERR_NOMEM;
3915 /* use NULL for the driver name so we open the key that is
3916 * parent of all drivers for this architecture and version */
3917 result = winreg_printer_opendriver(tmp_ctx,
3918 server_info,
3919 NULL,
3920 architecture,
3921 version,
3922 access_mask, false,
3923 &winreg_pipe,
3924 &hive_hnd,
3925 &key_hnd);
3926 if (!W_ERROR_IS_OK(result)) {
3927 DEBUG(5, ("winreg_get_driver_list: "
3928 "Could not open key (%s,%u): %s\n",
3929 architecture, version, win_errstr(result)));
3930 goto done;
3933 result = winreg_printer_enumkeys(tmp_ctx,
3934 winreg_pipe,
3935 &key_hnd,
3936 num_drivers,
3937 drivers);
3938 if (!W_ERROR_IS_OK(result)) {
3939 DEBUG(0, ("winreg_get_driver_list: "
3940 "Could not enumerate drivers for (%s,%u): %s\n",
3941 architecture, version, win_errstr(result)));
3942 goto done;
3945 result = WERR_OK;
3946 done:
3947 if (winreg_pipe != NULL) {
3948 if (is_valid_policy_hnd(&key_hnd)) {
3949 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL);
3951 if (is_valid_policy_hnd(&hive_hnd)) {
3952 rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL);
3956 TALLOC_FREE(tmp_ctx);
3957 return result;