2 * Unix SMB/CIFS implementation.
4 * SPOOLSS RPC Pipe server / winreg client routines
6 * Copyright (c) 2010 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "nt_printing.h"
24 #include "../librpc/gen_ndr/ndr_spoolss.h"
25 #include "../librpc/gen_ndr/ndr_winreg_c.h"
26 #include "../librpc/gen_ndr/ndr_security.h"
28 #include "../libcli/security/security.h"
29 #include "rpc_client/cli_winreg.h"
30 #include "../libcli/registry/util_reg.h"
31 #include "rpc_client/cli_winreg_spoolss.h"
32 #include "printing/nt_printing_os2.h"
33 #include "rpc_client/init_spoolss.h"
35 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
36 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
37 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
38 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
40 #define EMPTY_STRING ""
42 #define FILL_STRING(mem_ctx, in, out) \
44 if (in && strlen(in)) { \
45 out = talloc_strdup(mem_ctx, in); \
47 out = talloc_strdup(mem_ctx, ""); \
49 W_ERROR_HAVE_NO_MEMORY(out); \
52 #define CHECK_ERROR(result) \
53 if (W_ERROR_IS_OK(result)) continue; \
54 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
55 if (!W_ERROR_IS_OK(result)) break
57 /* FLAGS, NAME, with, height, left, top, right, bottom */
58 static const struct spoolss_FormInfo1 builtin_forms1
[] = {
59 { SPOOLSS_FORM_BUILTIN
, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
60 { SPOOLSS_FORM_BUILTIN
, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
61 { SPOOLSS_FORM_BUILTIN
, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
62 { SPOOLSS_FORM_BUILTIN
, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
63 { SPOOLSS_FORM_BUILTIN
, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
64 { SPOOLSS_FORM_BUILTIN
, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
65 { SPOOLSS_FORM_BUILTIN
, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
66 { SPOOLSS_FORM_BUILTIN
, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
67 { SPOOLSS_FORM_BUILTIN
, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
68 { SPOOLSS_FORM_BUILTIN
, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
69 { SPOOLSS_FORM_BUILTIN
, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
70 { SPOOLSS_FORM_BUILTIN
, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
71 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
72 { SPOOLSS_FORM_BUILTIN
, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
73 { SPOOLSS_FORM_BUILTIN
, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
74 { SPOOLSS_FORM_BUILTIN
, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
75 { SPOOLSS_FORM_BUILTIN
, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
76 { SPOOLSS_FORM_BUILTIN
, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
77 { SPOOLSS_FORM_BUILTIN
, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
78 { SPOOLSS_FORM_BUILTIN
, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
79 { SPOOLSS_FORM_BUILTIN
, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
80 { SPOOLSS_FORM_BUILTIN
, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
81 { SPOOLSS_FORM_BUILTIN
, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
82 { SPOOLSS_FORM_BUILTIN
, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
83 { SPOOLSS_FORM_BUILTIN
, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
84 { SPOOLSS_FORM_BUILTIN
, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
85 { SPOOLSS_FORM_BUILTIN
, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
86 { SPOOLSS_FORM_BUILTIN
, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
87 { SPOOLSS_FORM_BUILTIN
, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
88 { SPOOLSS_FORM_BUILTIN
, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
89 { SPOOLSS_FORM_BUILTIN
, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
90 { SPOOLSS_FORM_BUILTIN
, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
91 { SPOOLSS_FORM_BUILTIN
, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
92 { SPOOLSS_FORM_BUILTIN
, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
93 { SPOOLSS_FORM_BUILTIN
, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
94 { SPOOLSS_FORM_BUILTIN
, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
95 { SPOOLSS_FORM_BUILTIN
, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
96 { SPOOLSS_FORM_BUILTIN
, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
97 { SPOOLSS_FORM_BUILTIN
, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} },
98 { SPOOLSS_FORM_BUILTIN
, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
99 { SPOOLSS_FORM_BUILTIN
, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
100 { SPOOLSS_FORM_BUILTIN
, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
101 { SPOOLSS_FORM_BUILTIN
, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
102 { SPOOLSS_FORM_BUILTIN
, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
103 { SPOOLSS_FORM_BUILTIN
, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
104 { SPOOLSS_FORM_BUILTIN
, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
105 { SPOOLSS_FORM_BUILTIN
, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
106 { SPOOLSS_FORM_BUILTIN
, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
107 { SPOOLSS_FORM_BUILTIN
, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
108 { SPOOLSS_FORM_BUILTIN
, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
109 { SPOOLSS_FORM_BUILTIN
, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
110 { SPOOLSS_FORM_BUILTIN
, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
111 { SPOOLSS_FORM_BUILTIN
, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
112 { SPOOLSS_FORM_BUILTIN
, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
113 { SPOOLSS_FORM_BUILTIN
, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
114 { SPOOLSS_FORM_BUILTIN
, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
115 { SPOOLSS_FORM_BUILTIN
, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
116 { SPOOLSS_FORM_BUILTIN
, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
117 { SPOOLSS_FORM_BUILTIN
, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
118 { SPOOLSS_FORM_BUILTIN
, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
119 { SPOOLSS_FORM_BUILTIN
, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
120 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
121 { SPOOLSS_FORM_BUILTIN
, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
122 { SPOOLSS_FORM_BUILTIN
, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
123 { SPOOLSS_FORM_BUILTIN
, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
124 { SPOOLSS_FORM_BUILTIN
, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
125 { SPOOLSS_FORM_BUILTIN
, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
126 { SPOOLSS_FORM_BUILTIN
, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
127 { SPOOLSS_FORM_BUILTIN
, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
128 { SPOOLSS_FORM_BUILTIN
, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
129 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
130 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
131 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
132 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
133 { SPOOLSS_FORM_BUILTIN
, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
134 { SPOOLSS_FORM_BUILTIN
, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
135 { SPOOLSS_FORM_BUILTIN
, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
136 { SPOOLSS_FORM_BUILTIN
, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
137 { SPOOLSS_FORM_BUILTIN
, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
138 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
139 { SPOOLSS_FORM_BUILTIN
, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
140 { SPOOLSS_FORM_BUILTIN
, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
141 { SPOOLSS_FORM_BUILTIN
, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
142 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
143 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
144 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
145 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
146 { SPOOLSS_FORM_BUILTIN
, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
147 { SPOOLSS_FORM_BUILTIN
, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
148 { SPOOLSS_FORM_BUILTIN
, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
149 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
150 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
151 { SPOOLSS_FORM_BUILTIN
, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
152 { SPOOLSS_FORM_BUILTIN
, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
153 { SPOOLSS_FORM_BUILTIN
, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
154 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
155 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
156 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
157 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
158 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
159 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
160 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
161 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
162 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
163 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
164 { SPOOLSS_FORM_BUILTIN
, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
165 { SPOOLSS_FORM_BUILTIN
, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
166 { SPOOLSS_FORM_BUILTIN
, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
167 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
168 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
169 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
170 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
171 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
172 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
173 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
174 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
175 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
176 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} }
179 /********************************************************************
180 static helper functions
181 ********************************************************************/
183 /****************************************************************************
184 Update the changeid time.
185 ****************************************************************************/
189 * @brief Update the ChangeID time of a printer.
191 * This is SO NASTY as some drivers need this to change, others need it
192 * static. This value will change every second, and I must hope that this
193 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
196 * @return The ChangeID.
198 static uint32_t winreg_printer_rev_changeid(void)
202 get_process_uptime(&tv
);
205 /* Return changeid as msec since spooler restart */
206 return tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
209 * This setting seems to work well but is too untested
210 * to replace the above calculation. Left in for experimentation
211 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
213 return tv
.tv_sec
* 10 + tv
.tv_usec
/ 100000;
217 static WERROR
winreg_printer_openkey(TALLOC_CTX
*mem_ctx
,
218 struct dcerpc_binding_handle
*binding_handle
,
222 uint32_t access_mask
,
223 struct policy_handle
*hive_handle
,
224 struct policy_handle
*key_handle
)
226 struct winreg_String wkey
, wkeyclass
;
229 WERROR result
= WERR_OK
;
231 status
= dcerpc_winreg_OpenHKLM(binding_handle
,
237 if (!NT_STATUS_IS_OK(status
)) {
238 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
240 return ntstatus_to_werror(status
);
242 if (!W_ERROR_IS_OK(result
)) {
243 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
244 win_errstr(result
)));
249 keyname
= talloc_asprintf(mem_ctx
, "%s\\%s", path
, key
);
251 keyname
= talloc_strdup(mem_ctx
, path
);
253 if (keyname
== NULL
) {
261 enum winreg_CreateAction action
= REG_ACTION_NONE
;
263 ZERO_STRUCT(wkeyclass
);
266 status
= dcerpc_winreg_CreateKey(binding_handle
,
278 case REG_ACTION_NONE
:
279 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
281 case REG_CREATED_NEW_KEY
:
282 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname
));
284 case REG_OPENED_EXISTING_KEY
:
285 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname
));
289 status
= dcerpc_winreg_OpenKey(binding_handle
,
298 if (!NT_STATUS_IS_OK(status
)) {
299 result
= ntstatus_to_werror(status
);
301 if (!W_ERROR_IS_OK(result
)) {
304 if (is_valid_policy_hnd(hive_handle
)) {
305 dcerpc_winreg_CloseKey(binding_handle
,
310 ZERO_STRUCTP(hive_handle
);
319 * @brief Create the registry keyname for the given printer.
321 * @param[in] mem_ctx The memory context to use.
323 * @param[in] printer The name of the printer to get the registry key.
325 * @return The registry key or NULL on error.
327 static char *winreg_printer_data_keyname(TALLOC_CTX
*mem_ctx
, const char *printer
) {
328 return talloc_asprintf(mem_ctx
, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY
, printer
);
331 static WERROR
winreg_printer_opendriver(TALLOC_CTX
*mem_ctx
,
332 struct dcerpc_binding_handle
*winreg_handle
,
333 const char *drivername
,
334 const char *architecture
,
336 uint32_t access_mask
,
338 struct policy_handle
*hive_hnd
,
339 struct policy_handle
*key_hnd
)
344 key_name
= talloc_asprintf(mem_ctx
, "%s\\Environments\\%s\\Drivers\\Version-%u",
345 TOP_LEVEL_CONTROL_KEY
,
346 architecture
, version
);
351 result
= winreg_printer_openkey(mem_ctx
,
362 static WERROR
winreg_enumval_to_dword(TALLOC_CTX
*mem_ctx
,
363 struct spoolss_PrinterEnumValues
*v
,
364 const char *valuename
, uint32_t *dw
)
366 /* just return if it is not the one we are looking for */
367 if (strcmp(valuename
, v
->value_name
) != 0) {
368 return WERR_NOT_FOUND
;
371 if (v
->type
!= REG_DWORD
) {
372 return WERR_INVALID_DATATYPE
;
375 if (v
->data_length
!= 4) {
380 *dw
= IVAL(v
->data
->data
, 0);
384 static WERROR
winreg_enumval_to_sz(TALLOC_CTX
*mem_ctx
,
385 struct spoolss_PrinterEnumValues
*v
,
386 const char *valuename
, const char **_str
)
388 /* just return if it is not the one we are looking for */
389 if (strcmp(valuename
, v
->value_name
) != 0) {
390 return WERR_NOT_FOUND
;
393 if (v
->type
!= REG_SZ
) {
394 return WERR_INVALID_DATATYPE
;
397 if (v
->data_length
== 0) {
398 *_str
= talloc_strdup(mem_ctx
, EMPTY_STRING
);
405 if (!pull_reg_sz(mem_ctx
, v
->data
, _str
)) {
412 static WERROR
winreg_enumval_to_multi_sz(TALLOC_CTX
*mem_ctx
,
413 struct spoolss_PrinterEnumValues
*v
,
414 const char *valuename
,
417 /* just return if it is not the one we are looking for */
418 if (strcmp(valuename
, v
->value_name
) != 0) {
419 return WERR_NOT_FOUND
;
422 if (v
->type
!= REG_MULTI_SZ
) {
423 return WERR_INVALID_DATATYPE
;
426 if (v
->data_length
== 0) {
427 *array
= talloc_array(mem_ctx
, const char *, 1);
428 if (*array
== NULL
) {
435 if (!pull_reg_multi_sz(mem_ctx
, v
->data
, array
)) {
442 static WERROR
winreg_printer_write_date(TALLOC_CTX
*mem_ctx
,
443 struct dcerpc_binding_handle
*winreg_handle
,
444 struct policy_handle
*key_handle
,
448 struct winreg_String wvalue
= { 0, };
450 WERROR result
= WERR_OK
;
457 str
= talloc_strdup(mem_ctx
, "01/01/1601");
459 t
= nt_time_to_unix(data
);
462 return map_werror_from_unix(errno
);
464 str
= talloc_asprintf(mem_ctx
, "%02d/%02d/%04d",
465 tm
->tm_mon
+ 1, tm
->tm_mday
, tm
->tm_year
+ 1900);
472 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
475 status
= dcerpc_winreg_SetValue(winreg_handle
,
483 if (!NT_STATUS_IS_OK(status
)) {
484 result
= ntstatus_to_werror(status
);
486 if (!W_ERROR_IS_OK(result
)) {
487 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
488 wvalue
.name
, win_errstr(result
)));
494 static WERROR
winreg_printer_date_to_NTTIME(const char *str
, NTTIME
*data
)
499 if (strequal(str
, "01/01/1601")) {
506 if (sscanf(str
, "%d/%d/%d",
507 &tm
.tm_mon
, &tm
.tm_mday
, &tm
.tm_year
) != 3) {
508 return WERR_INVALID_PARAMETER
;
515 unix_to_nt_time(data
, t
);
520 static WERROR
winreg_printer_write_ver(TALLOC_CTX
*mem_ctx
,
521 struct dcerpc_binding_handle
*winreg_handle
,
522 struct policy_handle
*key_handle
,
526 struct winreg_String wvalue
= { 0, };
528 WERROR result
= WERR_OK
;
532 /* FIXME: check format is right,
533 * this needs to be something like: 6.1.7600.16385 */
534 str
= talloc_asprintf(mem_ctx
, "%u.%u.%u.%u",
535 (unsigned)((data
>> 48) & 0xFFFF),
536 (unsigned)((data
>> 32) & 0xFFFF),
537 (unsigned)((data
>> 16) & 0xFFFF),
538 (unsigned)(data
& 0xFFFF));
544 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
547 status
= dcerpc_winreg_SetValue(winreg_handle
,
555 if (!NT_STATUS_IS_OK(status
)) {
556 result
= ntstatus_to_werror(status
);
558 if (!W_ERROR_IS_OK(result
)) {
559 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
560 wvalue
.name
, win_errstr(result
)));
566 static WERROR
winreg_printer_ver_to_dword(const char *str
, uint64_t *data
)
568 unsigned int v1
, v2
, v3
, v4
;
570 if (sscanf(str
, "%u.%u.%u.%u", &v1
, &v2
, &v3
, &v4
) != 4) {
571 return WERR_INVALID_PARAMETER
;
574 *data
= ((uint64_t)(v1
& 0xFFFF) << 48) +
575 ((uint64_t)(v2
& 0xFFFF) << 32) +
576 ((uint64_t)(v3
& 0xFFFF) << 16) +
577 (uint64_t)(v2
& 0xFFFF);
582 /********************************************************************
583 Public winreg function for spoolss
584 ********************************************************************/
586 WERROR
winreg_create_printer(TALLOC_CTX
*mem_ctx
,
587 struct dcerpc_binding_handle
*winreg_handle
,
588 const char *sharename
)
590 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
591 struct policy_handle hive_hnd
, key_hnd
;
592 struct spoolss_SetPrinterInfo2
*info2
;
593 struct security_descriptor
*secdesc
;
594 struct winreg_String wkey
, wkeyclass
;
596 const char *subkeys
[] = { SPOOL_DSDRIVER_KEY
, SPOOL_DSSPOOLER_KEY
, SPOOL_PRINTERDATA_KEY
};
597 uint32_t i
, count
= ARRAY_SIZE(subkeys
);
598 uint32_t info2_mask
= 0;
599 WERROR result
= WERR_OK
;
603 tmp_ctx
= talloc_stackframe();
604 if (tmp_ctx
== NULL
) {
608 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
610 TALLOC_FREE(tmp_ctx
);
614 ZERO_STRUCT(hive_hnd
);
615 ZERO_STRUCT(key_hnd
);
617 result
= winreg_printer_openkey(tmp_ctx
,
625 if (W_ERROR_IS_OK(result
)) {
626 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path
));
628 } else if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
629 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path
));
630 } else if (!W_ERROR_IS_OK(result
)) {
631 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
632 path
, win_errstr(result
)));
636 if (is_valid_policy_hnd(&key_hnd
)) {
637 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
639 if (is_valid_policy_hnd(&hive_hnd
)) {
640 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
643 /* Create the main key */
644 result
= winreg_printer_openkey(tmp_ctx
,
652 if (!W_ERROR_IS_OK(result
)) {
653 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
654 path
, win_errstr(result
)));
658 if (is_valid_policy_hnd(&key_hnd
)) {
659 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
663 for (i
= 0; i
< count
; i
++) {
665 enum winreg_CreateAction action
= REG_ACTION_NONE
;
667 ZERO_STRUCT(key_hnd
);
670 wkey
.name
= talloc_asprintf(tmp_ctx
, "%s\\%s", path
, subkeys
[i
]);
671 if (wkey
.name
== NULL
) {
676 ZERO_STRUCT(wkeyclass
);
679 status
= dcerpc_winreg_CreateKey(winreg_handle
,
690 if (!NT_STATUS_IS_OK(status
)) {
691 result
= ntstatus_to_werror(status
);
693 if (!W_ERROR_IS_OK(result
)) {
694 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
695 wkey
.name
, win_errstr(result
)));
699 if (strequal(subkeys
[i
], SPOOL_DSSPOOLER_KEY
)) {
700 const char *dnssuffix
;
701 const char *longname
;
704 status
= dcerpc_winreg_set_sz(tmp_ctx
,
707 SPOOL_REG_PRINTERNAME
,
710 if (!NT_STATUS_IS_OK(status
)) {
711 result
= ntstatus_to_werror(status
);
713 if (!W_ERROR_IS_OK(result
)) {
717 status
= dcerpc_winreg_set_sz(tmp_ctx
,
720 SPOOL_REG_SHORTSERVERNAME
,
723 if (!NT_STATUS_IS_OK(status
)) {
724 result
= ntstatus_to_werror(status
);
726 if (!W_ERROR_IS_OK(result
)) {
730 /* We make the assumption that the netbios name
731 * is the same as the DNS name since the former
732 * will be what we used to join the domain
734 dnssuffix
= get_mydnsdomname(tmp_ctx
);
735 if (dnssuffix
!= NULL
&& dnssuffix
[0] != '\0') {
736 longname
= talloc_asprintf(tmp_ctx
, "%s.%s", lp_netbios_name(), dnssuffix
);
738 longname
= talloc_strdup(tmp_ctx
, lp_netbios_name());
740 if (longname
== NULL
) {
745 status
= dcerpc_winreg_set_sz(tmp_ctx
,
748 SPOOL_REG_SERVERNAME
,
751 if (!NT_STATUS_IS_OK(status
)) {
752 result
= ntstatus_to_werror(status
);
754 if (!W_ERROR_IS_OK(result
)) {
758 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
759 longname
, sharename
);
760 if (uncname
== NULL
) {
765 status
= dcerpc_winreg_set_sz(tmp_ctx
,
771 if (!NT_STATUS_IS_OK(status
)) {
772 result
= ntstatus_to_werror(status
);
774 if (!W_ERROR_IS_OK(result
)) {
778 status
= dcerpc_winreg_set_dword(tmp_ctx
,
781 SPOOL_REG_VERSIONNUMBER
,
784 if (!NT_STATUS_IS_OK(status
)) {
785 result
= ntstatus_to_werror(status
);
787 if (!W_ERROR_IS_OK(result
)) {
791 status
= dcerpc_winreg_set_dword(tmp_ctx
,
794 SPOOL_REG_PRINTSTARTTIME
,
797 if (!NT_STATUS_IS_OK(status
)) {
798 result
= ntstatus_to_werror(status
);
800 if (!W_ERROR_IS_OK(result
)) {
804 status
= dcerpc_winreg_set_dword(tmp_ctx
,
807 SPOOL_REG_PRINTENDTIME
,
810 if (!NT_STATUS_IS_OK(status
)) {
811 result
= ntstatus_to_werror(status
);
813 if (!W_ERROR_IS_OK(result
)) {
817 status
= dcerpc_winreg_set_dword(tmp_ctx
,
823 if (!NT_STATUS_IS_OK(status
)) {
824 result
= ntstatus_to_werror(status
);
826 if (!W_ERROR_IS_OK(result
)) {
830 status
= dcerpc_winreg_set_dword(tmp_ctx
,
833 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
836 if (!NT_STATUS_IS_OK(status
)) {
837 result
= ntstatus_to_werror(status
);
839 if (!W_ERROR_IS_OK(result
)) {
844 if (is_valid_policy_hnd(&key_hnd
)) {
845 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
848 info2
= talloc_zero(tmp_ctx
, struct spoolss_SetPrinterInfo2
);
854 info2
->printername
= sharename
;
855 if (info2
->printername
== NULL
) {
859 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTERNAME
;
861 info2
->sharename
= sharename
;
862 info2_mask
|= SPOOLSS_PRINTER_INFO_SHARENAME
;
864 info2
->portname
= SAMBA_PRINTER_PORT_NAME
;
865 info2_mask
|= SPOOLSS_PRINTER_INFO_PORTNAME
;
867 info2
->printprocessor
= "winprint";
868 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
;
870 info2
->datatype
= "RAW";
871 info2_mask
|= SPOOLSS_PRINTER_INFO_DATATYPE
;
874 info2_mask
|= SPOOLSS_PRINTER_INFO_COMMENT
;
876 info2
->attributes
= PRINTER_ATTRIBUTE_SAMBA
;
877 info2_mask
|= SPOOLSS_PRINTER_INFO_ATTRIBUTES
;
879 info2
->starttime
= 0; /* Minutes since 12:00am GMT */
880 info2_mask
|= SPOOLSS_PRINTER_INFO_STARTTIME
;
882 info2
->untiltime
= 0; /* Minutes since 12:00am GMT */
883 info2_mask
|= SPOOLSS_PRINTER_INFO_UNTILTIME
;
886 info2_mask
|= SPOOLSS_PRINTER_INFO_PRIORITY
;
888 info2
->defaultpriority
= 1;
889 info2_mask
|= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
;
891 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
892 if (!W_ERROR_IS_OK(result
)) {
895 info2_mask
|= SPOOLSS_PRINTER_INFO_SECDESC
;
898 * Don't write a default Device Mode to the registry! The Device Mode is
899 * only written to disk with a SetPrinter level 2 or 8.
902 result
= winreg_update_printer(tmp_ctx
,
911 if (is_valid_policy_hnd(&key_hnd
)) {
912 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
914 if (is_valid_policy_hnd(&hive_hnd
)) {
915 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
918 talloc_free(tmp_ctx
);
922 WERROR
winreg_update_printer(TALLOC_CTX
*mem_ctx
,
923 struct dcerpc_binding_handle
*winreg_handle
,
924 const char *sharename
,
926 struct spoolss_SetPrinterInfo2
*info2
,
927 struct spoolss_DeviceMode
*devmode
,
928 struct security_descriptor
*secdesc
)
930 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
931 struct policy_handle hive_hnd
, key_hnd
;
932 int snum
= lp_servicenumber(sharename
);
933 enum ndr_err_code ndr_err
;
936 WERROR result
= WERR_OK
;
941 tmp_ctx
= talloc_stackframe();
942 if (tmp_ctx
== NULL
) {
946 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
948 TALLOC_FREE(tmp_ctx
);
952 ZERO_STRUCT(hive_hnd
);
953 ZERO_STRUCT(key_hnd
);
955 result
= winreg_printer_openkey(tmp_ctx
,
963 if (!W_ERROR_IS_OK(result
)) {
964 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
965 path
, win_errstr(result
)));
969 if (info2_mask
& SPOOLSS_PRINTER_INFO_ATTRIBUTES
) {
970 status
= dcerpc_winreg_set_dword(tmp_ctx
,
976 if (!NT_STATUS_IS_OK(status
)) {
977 result
= ntstatus_to_werror(status
);
979 if (!W_ERROR_IS_OK(result
)) {
985 if (info2_mask
& SPOOLSS_PRINTER_INFO_AVERAGEPPM
) {
986 status
= dcerpc_winreg_set_dword(tmp_ctx
,
992 if (!NT_STATUS_IS_OK(status
)) {
993 result
= ntstatus_to_werror(status
);
995 if (!W_ERROR_IS_OK(result
)) {
1001 if (info2_mask
& SPOOLSS_PRINTER_INFO_COMMENT
) {
1002 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1008 if (!NT_STATUS_IS_OK(status
)) {
1009 result
= ntstatus_to_werror(status
);
1011 if (!W_ERROR_IS_OK(result
)) {
1016 if (info2_mask
& SPOOLSS_PRINTER_INFO_DATATYPE
) {
1017 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1023 if (!NT_STATUS_IS_OK(status
)) {
1024 result
= ntstatus_to_werror(status
);
1026 if (!W_ERROR_IS_OK(result
)) {
1031 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
) {
1032 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1036 info2
->defaultpriority
,
1038 if (!NT_STATUS_IS_OK(status
)) {
1039 result
= ntstatus_to_werror(status
);
1041 if (!W_ERROR_IS_OK(result
)) {
1046 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEVMODE
) {
1048 * Some client drivers freak out if there is a NULL devmode
1049 * (probably the driver is not checking before accessing
1050 * the devmode pointer) --jerry
1052 if (devmode
== NULL
&& lp_default_devmode(snum
) && info2
!= NULL
) {
1053 result
= spoolss_create_default_devmode(tmp_ctx
,
1056 if (!W_ERROR_IS_OK(result
)) {
1061 if (devmode
->size
!= (ndr_size_spoolss_DeviceMode(devmode
, 0) - devmode
->__driverextra_length
)) {
1062 result
= WERR_INVALID_PARAM
;
1066 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, devmode
,
1067 (ndr_push_flags_fn_t
) ndr_push_spoolss_DeviceMode
);
1068 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1069 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1070 result
= WERR_NOMEM
;
1074 status
= dcerpc_winreg_set_binary(tmp_ctx
,
1080 if (!NT_STATUS_IS_OK(status
)) {
1081 result
= ntstatus_to_werror(status
);
1083 if (!W_ERROR_IS_OK(result
)) {
1088 if (info2_mask
& SPOOLSS_PRINTER_INFO_DRIVERNAME
) {
1089 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1095 if (!NT_STATUS_IS_OK(status
)) {
1096 result
= ntstatus_to_werror(status
);
1098 if (!W_ERROR_IS_OK(result
)) {
1103 if (info2_mask
& SPOOLSS_PRINTER_INFO_LOCATION
) {
1104 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1110 if (!NT_STATUS_IS_OK(status
)) {
1111 result
= ntstatus_to_werror(status
);
1113 if (!W_ERROR_IS_OK(result
)) {
1118 if (info2_mask
& SPOOLSS_PRINTER_INFO_PARAMETERS
) {
1119 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1125 if (!NT_STATUS_IS_OK(status
)) {
1126 result
= ntstatus_to_werror(status
);
1128 if (!W_ERROR_IS_OK(result
)) {
1133 if (info2_mask
& SPOOLSS_PRINTER_INFO_PORTNAME
) {
1134 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1140 if (!NT_STATUS_IS_OK(status
)) {
1141 result
= ntstatus_to_werror(status
);
1143 if (!W_ERROR_IS_OK(result
)) {
1148 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTERNAME
) {
1150 * in addprinter: no servername and the printer is the name
1151 * in setprinter: servername is \\server
1152 * and printer is \\server\\printer
1154 * Samba manages only local printers.
1155 * we currently don't support things like i
1156 * path=\\other_server\printer
1158 * We only store the printername, not \\server\printername
1160 const char *p
= strrchr(info2
->printername
, '\\');
1162 p
= info2
->printername
;
1166 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1172 if (!NT_STATUS_IS_OK(status
)) {
1173 result
= ntstatus_to_werror(status
);
1175 if (!W_ERROR_IS_OK(result
)) {
1180 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
) {
1181 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1185 info2
->printprocessor
,
1187 if (!NT_STATUS_IS_OK(status
)) {
1188 result
= ntstatus_to_werror(status
);
1190 if (!W_ERROR_IS_OK(result
)) {
1195 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRIORITY
) {
1196 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1202 if (!NT_STATUS_IS_OK(status
)) {
1203 result
= ntstatus_to_werror(status
);
1205 if (!W_ERROR_IS_OK(result
)) {
1210 if (info2_mask
& SPOOLSS_PRINTER_INFO_SECDESC
) {
1212 * We need a security descriptor, if it isn't specified by
1213 * AddPrinter{Ex} then create a default descriptor.
1215 if (secdesc
== NULL
) {
1216 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1217 if (!W_ERROR_IS_OK(result
)) {
1221 result
= winreg_set_printer_secdesc(tmp_ctx
,
1225 if (!W_ERROR_IS_OK(result
)) {
1230 if (info2_mask
& SPOOLSS_PRINTER_INFO_SEPFILE
) {
1231 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1237 if (!NT_STATUS_IS_OK(status
)) {
1238 result
= ntstatus_to_werror(status
);
1240 if (!W_ERROR_IS_OK(result
)) {
1245 if (info2_mask
& SPOOLSS_PRINTER_INFO_SHARENAME
) {
1246 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1252 if (!NT_STATUS_IS_OK(status
)) {
1253 result
= ntstatus_to_werror(status
);
1255 if (!W_ERROR_IS_OK(result
)) {
1260 if (info2_mask
& SPOOLSS_PRINTER_INFO_STARTTIME
) {
1261 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1267 if (!NT_STATUS_IS_OK(status
)) {
1268 result
= ntstatus_to_werror(status
);
1270 if (!W_ERROR_IS_OK(result
)) {
1275 if (info2_mask
& SPOOLSS_PRINTER_INFO_STATUS
) {
1276 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1282 if (!NT_STATUS_IS_OK(status
)) {
1283 result
= ntstatus_to_werror(status
);
1285 if (!W_ERROR_IS_OK(result
)) {
1290 if (info2_mask
& SPOOLSS_PRINTER_INFO_UNTILTIME
) {
1291 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1297 if (!NT_STATUS_IS_OK(status
)) {
1298 result
= ntstatus_to_werror(status
);
1300 if (!W_ERROR_IS_OK(result
)) {
1305 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1309 winreg_printer_rev_changeid(),
1311 if (!NT_STATUS_IS_OK(status
)) {
1312 result
= ntstatus_to_werror(status
);
1314 if (!W_ERROR_IS_OK(result
)) {
1320 if (is_valid_policy_hnd(&key_hnd
)) {
1321 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1323 if (is_valid_policy_hnd(&hive_hnd
)) {
1324 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1327 TALLOC_FREE(tmp_ctx
);
1331 WERROR
winreg_get_printer(TALLOC_CTX
*mem_ctx
,
1332 struct dcerpc_binding_handle
*winreg_handle
,
1333 const char *printer
,
1334 struct spoolss_PrinterInfo2
**pinfo2
)
1336 struct spoolss_PrinterInfo2
*info2
;
1337 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1338 struct policy_handle hive_hnd
, key_hnd
;
1339 struct spoolss_PrinterEnumValues enum_value
;
1340 struct spoolss_PrinterEnumValues
*v
= NULL
;
1341 enum ndr_err_code ndr_err
;
1343 int snum
= lp_servicenumber(printer
);
1344 uint32_t num_values
= 0;
1348 WERROR result
= WERR_OK
;
1350 const char **enum_names
= NULL
;
1351 enum winreg_Type
*enum_types
= NULL
;
1352 DATA_BLOB
*enum_data_blobs
= NULL
;
1353 TALLOC_CTX
*tmp_ctx
;
1355 tmp_ctx
= talloc_stackframe();
1356 if (tmp_ctx
== NULL
) {
1360 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1362 TALLOC_FREE(tmp_ctx
);
1366 result
= winreg_printer_openkey(tmp_ctx
,
1374 if (!W_ERROR_IS_OK(result
)) {
1375 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
1376 path
, win_errstr(result
)));
1380 status
= dcerpc_winreg_enumvals(tmp_ctx
,
1388 if (!NT_STATUS_IS_OK(status
)){
1389 result
= ntstatus_to_werror(status
);
1392 if (!W_ERROR_IS_OK(result
)) {
1393 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1394 path
, win_errstr(result
)));
1398 info2
= talloc_zero(tmp_ctx
, struct spoolss_PrinterInfo2
);
1399 if (info2
== NULL
) {
1400 result
= WERR_NOMEM
;
1404 FILL_STRING(info2
, EMPTY_STRING
, info2
->servername
);
1405 FILL_STRING(info2
, EMPTY_STRING
, info2
->printername
);
1406 FILL_STRING(info2
, EMPTY_STRING
, info2
->sharename
);
1407 FILL_STRING(info2
, EMPTY_STRING
, info2
->portname
);
1408 FILL_STRING(info2
, EMPTY_STRING
, info2
->drivername
);
1409 FILL_STRING(info2
, EMPTY_STRING
, info2
->comment
);
1410 FILL_STRING(info2
, EMPTY_STRING
, info2
->location
);
1411 FILL_STRING(info2
, EMPTY_STRING
, info2
->sepfile
);
1412 FILL_STRING(info2
, EMPTY_STRING
, info2
->printprocessor
);
1413 FILL_STRING(info2
, EMPTY_STRING
, info2
->datatype
);
1414 FILL_STRING(info2
, EMPTY_STRING
, info2
->parameters
);
1416 for (i
= 0; i
< num_values
; i
++) {
1417 enum_value
.value_name
= enum_names
[i
];
1418 enum_value
.value_name_len
= 2*strlen_m_term(enum_names
[i
]);
1419 enum_value
.type
= enum_types
[i
];
1420 enum_value
.data_length
= enum_data_blobs
[i
].length
;
1421 enum_value
.data
= NULL
;
1422 if (enum_value
.data_length
!= 0){
1423 enum_value
.data
= &enum_data_blobs
[i
];
1427 result
= winreg_enumval_to_sz(info2
,
1430 &info2
->printername
);
1431 CHECK_ERROR(result
);
1433 result
= winreg_enumval_to_sz(info2
,
1437 CHECK_ERROR(result
);
1439 result
= winreg_enumval_to_sz(info2
,
1443 CHECK_ERROR(result
);
1445 result
= winreg_enumval_to_sz(info2
,
1449 CHECK_ERROR(result
);
1451 result
= winreg_enumval_to_sz(info2
,
1455 CHECK_ERROR(result
);
1457 result
= winreg_enumval_to_sz(info2
,
1461 CHECK_ERROR(result
);
1463 result
= winreg_enumval_to_sz(info2
,
1466 &info2
->printprocessor
);
1467 CHECK_ERROR(result
);
1469 result
= winreg_enumval_to_sz(info2
,
1473 CHECK_ERROR(result
);
1475 result
= winreg_enumval_to_sz(info2
,
1478 &info2
->parameters
);
1479 CHECK_ERROR(result
);
1481 result
= winreg_enumval_to_sz(info2
,
1484 &info2
->drivername
);
1485 CHECK_ERROR(result
);
1487 result
= winreg_enumval_to_dword(info2
,
1490 &info2
->attributes
);
1491 CHECK_ERROR(result
);
1493 result
= winreg_enumval_to_dword(info2
,
1497 CHECK_ERROR(result
);
1499 result
= winreg_enumval_to_dword(info2
,
1502 &info2
->defaultpriority
);
1503 CHECK_ERROR(result
);
1505 result
= winreg_enumval_to_dword(info2
,
1509 CHECK_ERROR(result
);
1511 result
= winreg_enumval_to_dword(info2
,
1515 CHECK_ERROR(result
);
1517 result
= winreg_enumval_to_dword(info2
,
1521 CHECK_ERROR(result
);
1523 result
= winreg_enumval_to_dword(info2
,
1527 CHECK_ERROR(result
);
1530 if (!W_ERROR_IS_OK(result
)) {
1531 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
1534 win_errstr(result
)));
1538 /* Construct the Device Mode */
1539 status
= dcerpc_winreg_query_binary(tmp_ctx
,
1545 if (!NT_STATUS_IS_OK(status
)) {
1546 result
= ntstatus_to_werror(status
);
1548 if (W_ERROR_IS_OK(result
)) {
1549 info2
->devmode
= talloc_zero(info2
, struct spoolss_DeviceMode
);
1550 if (info2
->devmode
== NULL
) {
1551 result
= WERR_NOMEM
;
1554 ndr_err
= ndr_pull_struct_blob(&blob
,
1557 (ndr_pull_flags_fn_t
) ndr_pull_spoolss_DeviceMode
);
1558 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1559 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
1560 result
= WERR_NOMEM
;
1565 if (info2
->devmode
== NULL
&& lp_default_devmode(snum
)) {
1566 result
= spoolss_create_default_devmode(info2
,
1569 if (!W_ERROR_IS_OK(result
)) {
1574 if (info2
->devmode
) {
1575 info2
->devmode
->size
= ndr_size_spoolss_DeviceMode(info2
->devmode
, 0) - info2
->devmode
->driverextra_data
.length
;
1578 result
= winreg_get_printer_secdesc(info2
,
1582 if (!W_ERROR_IS_OK(result
)) {
1586 /* Fix for OS/2 drivers. */
1587 if (get_remote_arch() == RA_OS2
) {
1588 spoolss_map_to_os2_driver(info2
, &info2
->drivername
);
1592 *pinfo2
= talloc_move(mem_ctx
, &info2
);
1597 if (is_valid_policy_hnd(&key_hnd
)) {
1598 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1600 if (is_valid_policy_hnd(&hive_hnd
)) {
1601 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1604 TALLOC_FREE(tmp_ctx
);
1608 WERROR
winreg_get_printer_secdesc(TALLOC_CTX
*mem_ctx
,
1609 struct dcerpc_binding_handle
*winreg_handle
,
1610 const char *sharename
,
1611 struct spoolss_security_descriptor
**psecdesc
)
1613 struct spoolss_security_descriptor
*secdesc
;
1614 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1615 struct policy_handle hive_hnd
, key_hnd
;
1617 TALLOC_CTX
*tmp_ctx
;
1622 tmp_ctx
= talloc_stackframe();
1623 if (tmp_ctx
== NULL
) {
1627 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1629 talloc_free(tmp_ctx
);
1633 ZERO_STRUCT(hive_hnd
);
1634 ZERO_STRUCT(key_hnd
);
1636 result
= winreg_printer_openkey(tmp_ctx
,
1644 if (!W_ERROR_IS_OK(result
)) {
1645 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1646 goto create_default
;
1651 status
= dcerpc_winreg_query_sd(tmp_ctx
,
1657 if (!NT_STATUS_IS_OK(status
)) {
1658 result
= ntstatus_to_werror(status
);
1660 if (!W_ERROR_IS_OK(result
)) {
1661 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1663 if (is_valid_policy_hnd(&key_hnd
)) {
1664 dcerpc_winreg_CloseKey(winreg_handle
,
1670 if (is_valid_policy_hnd(&hive_hnd
)) {
1671 dcerpc_winreg_CloseKey(winreg_handle
,
1676 goto create_default
;
1682 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1689 result
= winreg_printer_openkey(tmp_ctx
,
1697 if (!W_ERROR_IS_OK(result
)) {
1701 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1702 if (!W_ERROR_IS_OK(result
)) {
1706 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
1707 this security descriptor has been created when winbindd was
1708 down. Take ownership of security descriptor. */
1709 if (dom_sid_equal(secdesc
->owner_sid
, &global_sid_World
)) {
1710 struct dom_sid owner_sid
;
1712 /* Change sd owner to workgroup administrator */
1714 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid
)) {
1715 struct spoolss_security_descriptor
*new_secdesc
;
1719 sid_append_rid(&owner_sid
, DOMAIN_RID_ADMINISTRATOR
);
1721 new_secdesc
= make_sec_desc(tmp_ctx
,
1730 if (new_secdesc
== NULL
) {
1731 result
= WERR_NOMEM
;
1735 /* Swap with other one */
1736 secdesc
= new_secdesc
;
1740 status
= dcerpc_winreg_set_sd(tmp_ctx
,
1746 if (!NT_STATUS_IS_OK(status
)) {
1747 result
= ntstatus_to_werror(status
);
1749 if (!W_ERROR_IS_OK(result
)) {
1754 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1759 if (is_valid_policy_hnd(&key_hnd
)) {
1760 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1762 if (is_valid_policy_hnd(&hive_hnd
)) {
1763 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1766 talloc_free(tmp_ctx
);
1770 WERROR
winreg_set_printer_secdesc(TALLOC_CTX
*mem_ctx
,
1771 struct dcerpc_binding_handle
*winreg_handle
,
1772 const char *sharename
,
1773 const struct spoolss_security_descriptor
*secdesc
)
1775 const struct spoolss_security_descriptor
*new_secdesc
= secdesc
;
1776 struct spoolss_security_descriptor
*old_secdesc
;
1777 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1778 struct policy_handle hive_hnd
, key_hnd
;
1780 TALLOC_CTX
*tmp_ctx
;
1785 tmp_ctx
= talloc_stackframe();
1786 if (tmp_ctx
== NULL
) {
1790 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1792 talloc_free(tmp_ctx
);
1797 * The old owner and group sids of the security descriptor are not
1798 * present when new ACEs are added or removed by changing printer
1799 * permissions through NT. If they are NULL in the new security
1800 * descriptor then copy them over from the old one.
1802 if (!secdesc
->owner_sid
|| !secdesc
->group_sid
) {
1803 struct dom_sid
*owner_sid
, *group_sid
;
1804 struct security_acl
*dacl
, *sacl
;
1807 result
= winreg_get_printer_secdesc(tmp_ctx
,
1811 if (!W_ERROR_IS_OK(result
)) {
1812 talloc_free(tmp_ctx
);
1816 /* Pick out correct owner and group sids */
1817 owner_sid
= secdesc
->owner_sid
?
1818 secdesc
->owner_sid
:
1819 old_secdesc
->owner_sid
;
1821 group_sid
= secdesc
->group_sid
?
1822 secdesc
->group_sid
:
1823 old_secdesc
->group_sid
;
1825 dacl
= secdesc
->dacl
?
1829 sacl
= secdesc
->sacl
?
1833 /* Make a deep copy of the security descriptor */
1834 new_secdesc
= make_sec_desc(tmp_ctx
,
1842 if (new_secdesc
== NULL
) {
1843 talloc_free(tmp_ctx
);
1848 ZERO_STRUCT(hive_hnd
);
1849 ZERO_STRUCT(key_hnd
);
1851 result
= winreg_printer_openkey(tmp_ctx
,
1859 if (!W_ERROR_IS_OK(result
)) {
1863 status
= dcerpc_winreg_set_sd(tmp_ctx
,
1869 if (!NT_STATUS_IS_OK(status
)) {
1870 result
= ntstatus_to_werror(status
);
1874 if (is_valid_policy_hnd(&key_hnd
)) {
1875 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1877 if (is_valid_policy_hnd(&hive_hnd
)) {
1878 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1881 talloc_free(tmp_ctx
);
1885 /* Set printer data over the winreg pipe. */
1886 WERROR
winreg_set_printer_dataex(TALLOC_CTX
*mem_ctx
,
1887 struct dcerpc_binding_handle
*winreg_handle
,
1888 const char *printer
,
1891 enum winreg_Type type
,
1895 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1896 struct policy_handle hive_hnd
, key_hnd
;
1897 struct winreg_String wvalue
= { 0, };
1899 WERROR result
= WERR_OK
;
1902 TALLOC_CTX
*tmp_ctx
;
1904 tmp_ctx
= talloc_stackframe();
1905 if (tmp_ctx
== NULL
) {
1909 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1911 TALLOC_FREE(tmp_ctx
);
1915 ZERO_STRUCT(hive_hnd
);
1916 ZERO_STRUCT(key_hnd
);
1918 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
1919 key
, value
, access_mask
, printer
));
1920 result
= winreg_printer_openkey(tmp_ctx
,
1928 if (!W_ERROR_IS_OK(result
)) {
1929 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
1930 key
, win_errstr(result
)));
1934 wvalue
.name
= value
;
1935 status
= dcerpc_winreg_SetValue(winreg_handle
,
1943 if (!NT_STATUS_IS_OK(status
)) {
1944 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
1945 value
, nt_errstr(status
)));
1946 result
= ntstatus_to_werror(status
);
1950 if (is_valid_policy_hnd(&key_hnd
)) {
1951 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1953 if (is_valid_policy_hnd(&hive_hnd
)) {
1954 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1957 TALLOC_FREE(tmp_ctx
);
1961 /* Get printer data over a winreg pipe. */
1962 WERROR
winreg_get_printer_dataex(TALLOC_CTX
*mem_ctx
,
1963 struct dcerpc_binding_handle
*winreg_handle
,
1964 const char *printer
,
1967 enum winreg_Type
*type
,
1969 uint32_t *data_size
)
1971 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1972 struct policy_handle hive_hnd
, key_hnd
;
1973 struct winreg_String wvalue
;
1974 enum winreg_Type type_in
= REG_NONE
;
1976 uint8_t *data_in
= NULL
;
1977 uint32_t data_in_size
= 0;
1978 uint32_t value_len
= 0;
1979 WERROR result
= WERR_OK
;
1982 TALLOC_CTX
*tmp_ctx
;
1984 tmp_ctx
= talloc_stackframe();
1985 if (tmp_ctx
== NULL
) {
1989 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1991 TALLOC_FREE(tmp_ctx
);
1995 ZERO_STRUCT(hive_hnd
);
1996 ZERO_STRUCT(key_hnd
);
1998 result
= winreg_printer_openkey(tmp_ctx
,
2006 if (!W_ERROR_IS_OK(result
)) {
2007 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2008 key
, win_errstr(result
)));
2012 wvalue
.name
= value
;
2015 * call QueryValue once with data == NULL to get the
2016 * needed memory size to be allocated, then allocate
2017 * data buffer and call again.
2019 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2028 if (!NT_STATUS_IS_OK(status
)) {
2029 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2030 value
, nt_errstr(status
)));
2031 result
= ntstatus_to_werror(status
);
2034 if (!W_ERROR_IS_OK(result
)) {
2035 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2036 value
, win_errstr(result
)));
2040 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
2041 if (data_in
== NULL
) {
2042 result
= WERR_NOMEM
;
2047 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2056 if (!NT_STATUS_IS_OK(status
)) {
2057 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2058 value
, nt_errstr(status
)));
2059 result
= ntstatus_to_werror(status
);
2062 if (!W_ERROR_IS_OK(result
)) {
2063 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2064 value
, win_errstr(result
)));
2069 *data_size
= data_in_size
;
2071 *data
= talloc_move(mem_ctx
, &data_in
);
2076 if (is_valid_policy_hnd(&key_hnd
)) {
2077 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2079 if (is_valid_policy_hnd(&hive_hnd
)) {
2080 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2083 TALLOC_FREE(tmp_ctx
);
2087 /* Enumerate on the values of a given key and provide the data. */
2088 WERROR
winreg_enum_printer_dataex(TALLOC_CTX
*mem_ctx
,
2089 struct dcerpc_binding_handle
*winreg_handle
,
2090 const char *printer
,
2092 uint32_t *pnum_values
,
2093 struct spoolss_PrinterEnumValues
**penum_values
)
2096 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2097 struct policy_handle hive_hnd
, key_hnd
;
2099 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2100 uint32_t num_values
= 0;
2102 WERROR result
= WERR_OK
;
2105 const char **enum_names
= NULL
;
2106 enum winreg_Type
*enum_types
= NULL
;
2107 DATA_BLOB
*enum_data_blobs
= NULL
;
2109 TALLOC_CTX
*tmp_ctx
;
2111 tmp_ctx
= talloc_stackframe();
2112 if (tmp_ctx
== NULL
) {
2116 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2118 TALLOC_FREE(tmp_ctx
);
2122 result
= winreg_printer_openkey(tmp_ctx
,
2130 if (!W_ERROR_IS_OK(result
)) {
2131 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2132 key
, win_errstr(result
)));
2136 status
= dcerpc_winreg_enumvals(tmp_ctx
,
2144 if (!NT_STATUS_IS_OK(status
)){
2145 result
= ntstatus_to_werror(status
);
2148 if (!W_ERROR_IS_OK(result
)) {
2149 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2150 key
, win_errstr(result
)));
2154 enum_values
= talloc_array(tmp_ctx
, struct spoolss_PrinterEnumValues
, num_values
);
2155 if (enum_values
== NULL
){
2156 result
= WERR_NOMEM
;
2157 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2158 key
, win_errstr(result
)));
2162 for (i
= 0; i
< num_values
; i
++){
2163 enum_values
[i
].value_name
= enum_names
[i
];
2164 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
2165 enum_values
[i
].type
= enum_types
[i
];
2166 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
2167 enum_values
[i
].data
= NULL
;
2169 if (enum_values
[i
].data_length
!= 0){
2170 enum_values
[i
].data
= &enum_data_blobs
[i
];
2174 talloc_steal(enum_values
, enum_names
);
2175 talloc_steal(enum_values
, enum_data_blobs
);
2177 *pnum_values
= num_values
;
2179 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
2184 if (is_valid_policy_hnd(&key_hnd
)) {
2185 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2187 if (is_valid_policy_hnd(&hive_hnd
)) {
2188 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2191 TALLOC_FREE(tmp_ctx
);
2195 /* Delete printer data over a winreg pipe. */
2196 WERROR
winreg_delete_printer_dataex(TALLOC_CTX
*mem_ctx
,
2197 struct dcerpc_binding_handle
*winreg_handle
,
2198 const char *printer
,
2202 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2203 struct policy_handle hive_hnd
, key_hnd
;
2204 struct winreg_String wvalue
= { 0, };
2206 WERROR result
= WERR_OK
;
2210 TALLOC_CTX
*tmp_ctx
;
2212 tmp_ctx
= talloc_stackframe();
2213 if (tmp_ctx
== NULL
) {
2217 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2219 TALLOC_FREE(tmp_ctx
);
2223 ZERO_STRUCT(hive_hnd
);
2224 ZERO_STRUCT(key_hnd
);
2226 result
= winreg_printer_openkey(tmp_ctx
,
2234 if (!W_ERROR_IS_OK(result
)) {
2235 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2236 key
, win_errstr(result
)));
2240 wvalue
.name
= value
;
2241 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
2246 if (!NT_STATUS_IS_OK(status
)) {
2247 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2248 value
, nt_errstr(status
)));
2249 result
= ntstatus_to_werror(status
);
2253 if (is_valid_policy_hnd(&key_hnd
)) {
2254 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2256 if (is_valid_policy_hnd(&hive_hnd
)) {
2257 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2260 TALLOC_FREE(tmp_ctx
);
2264 /* Enumerate on the subkeys of a given key and provide the data. */
2265 WERROR
winreg_enum_printer_key(TALLOC_CTX
*mem_ctx
,
2266 struct dcerpc_binding_handle
*winreg_handle
,
2267 const char *printer
,
2269 uint32_t *pnum_subkeys
,
2270 const char ***psubkeys
)
2272 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2273 struct policy_handle hive_hnd
, key_hnd
;
2275 const char **subkeys
= NULL
;
2276 uint32_t num_subkeys
= -1;
2278 WERROR result
= WERR_OK
;
2282 TALLOC_CTX
*tmp_ctx
;
2284 tmp_ctx
= talloc_stackframe();
2285 if (tmp_ctx
== NULL
) {
2289 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2291 TALLOC_FREE(tmp_ctx
);
2295 ZERO_STRUCT(hive_hnd
);
2296 ZERO_STRUCT(key_hnd
);
2298 result
= winreg_printer_openkey(tmp_ctx
,
2306 if (!W_ERROR_IS_OK(result
)) {
2307 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2308 key
, win_errstr(result
)));
2312 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
2318 if (!NT_STATUS_IS_OK(status
)) {
2319 result
= ntstatus_to_werror(status
);
2321 if (!W_ERROR_IS_OK(result
)) {
2322 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2323 key
, win_errstr(result
)));
2327 *pnum_subkeys
= num_subkeys
;
2329 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
2334 if (is_valid_policy_hnd(&key_hnd
)) {
2335 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2337 if (is_valid_policy_hnd(&hive_hnd
)) {
2338 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2341 TALLOC_FREE(tmp_ctx
);
2345 /* Delete a key with subkeys of a given printer. */
2346 WERROR
winreg_delete_printer_key(TALLOC_CTX
*mem_ctx
,
2347 struct dcerpc_binding_handle
*winreg_handle
,
2348 const char *printer
,
2351 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2352 struct policy_handle hive_hnd
, key_hnd
;
2358 TALLOC_CTX
*tmp_ctx
;
2360 tmp_ctx
= talloc_stackframe();
2361 if (tmp_ctx
== NULL
) {
2365 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2367 TALLOC_FREE(tmp_ctx
);
2371 result
= winreg_printer_openkey(tmp_ctx
,
2379 if (!W_ERROR_IS_OK(result
)) {
2380 /* key doesn't exist */
2381 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2386 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2387 key
, win_errstr(result
)));
2391 if (is_valid_policy_hnd(&key_hnd
)) {
2392 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
2395 if (key
== NULL
|| key
[0] == '\0') {
2398 keyname
= talloc_asprintf(tmp_ctx
,
2402 if (keyname
== NULL
) {
2403 result
= WERR_NOMEM
;
2408 status
= dcerpc_winreg_delete_subkeys_recursive(tmp_ctx
,
2415 if (!NT_STATUS_IS_OK(status
)) {
2416 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2417 key
, nt_errstr(status
)));
2418 result
= ntstatus_to_werror(status
);
2422 if (!W_ERROR_IS_OK(result
)) {
2423 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2424 key
, win_errstr(result
)));
2429 if (is_valid_policy_hnd(&key_hnd
)) {
2430 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2432 if (is_valid_policy_hnd(&hive_hnd
)) {
2433 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2436 TALLOC_FREE(tmp_ctx
);
2440 WERROR
winreg_printer_update_changeid(TALLOC_CTX
*mem_ctx
,
2441 struct dcerpc_binding_handle
*winreg_handle
,
2442 const char *printer
)
2444 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2445 struct policy_handle hive_hnd
, key_hnd
;
2450 TALLOC_CTX
*tmp_ctx
;
2452 tmp_ctx
= talloc_stackframe();
2453 if (tmp_ctx
== NULL
) {
2457 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2459 TALLOC_FREE(tmp_ctx
);
2463 ZERO_STRUCT(hive_hnd
);
2464 ZERO_STRUCT(key_hnd
);
2466 result
= winreg_printer_openkey(tmp_ctx
,
2474 if (!W_ERROR_IS_OK(result
)) {
2475 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2476 path
, win_errstr(result
)));
2480 status
= dcerpc_winreg_set_dword(tmp_ctx
,
2484 winreg_printer_rev_changeid(),
2486 if (!NT_STATUS_IS_OK(status
)) {
2487 result
= ntstatus_to_werror(status
);
2489 if (!W_ERROR_IS_OK(result
)) {
2495 if (is_valid_policy_hnd(&key_hnd
)) {
2496 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2498 if (is_valid_policy_hnd(&hive_hnd
)) {
2499 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2502 TALLOC_FREE(tmp_ctx
);
2506 WERROR
winreg_printer_get_changeid(TALLOC_CTX
*mem_ctx
,
2507 struct dcerpc_binding_handle
*winreg_handle
,
2508 const char *printer
,
2509 uint32_t *pchangeid
)
2511 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2512 struct policy_handle hive_hnd
, key_hnd
;
2513 uint32_t changeid
= 0;
2518 TALLOC_CTX
*tmp_ctx
;
2520 tmp_ctx
= talloc_stackframe();
2521 if (tmp_ctx
== NULL
) {
2525 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2527 TALLOC_FREE(tmp_ctx
);
2531 ZERO_STRUCT(hive_hnd
);
2532 ZERO_STRUCT(key_hnd
);
2534 result
= winreg_printer_openkey(tmp_ctx
,
2542 if (!W_ERROR_IS_OK(result
)) {
2543 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2544 path
, win_errstr(result
)));
2548 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path
));
2550 status
= dcerpc_winreg_query_dword(tmp_ctx
,
2556 if (!NT_STATUS_IS_OK(status
)) {
2557 result
= ntstatus_to_werror(status
);
2559 if (!W_ERROR_IS_OK(result
)) {
2564 *pchangeid
= changeid
;
2569 if (is_valid_policy_hnd(&key_hnd
)) {
2570 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2572 if (is_valid_policy_hnd(&hive_hnd
)) {
2573 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2576 TALLOC_FREE(tmp_ctx
);
2581 * The special behaviour of the spoolss forms is documented at the website:
2583 * Managing Win32 Printserver Forms
2584 * http://unixwiz.net/techtips/winspooler-forms.html
2587 WERROR
winreg_printer_addform1(TALLOC_CTX
*mem_ctx
,
2588 struct dcerpc_binding_handle
*winreg_handle
,
2589 struct spoolss_AddFormInfo1
*form
)
2591 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2592 struct policy_handle hive_hnd
, key_hnd
;
2593 struct winreg_String wvalue
= { 0, };
2595 uint32_t num_info
= 0;
2596 union spoolss_FormInfo
*info
= NULL
;
2601 TALLOC_CTX
*tmp_ctx
;
2603 tmp_ctx
= talloc_stackframe();
2604 if (tmp_ctx
== NULL
) {
2608 ZERO_STRUCT(hive_hnd
);
2609 ZERO_STRUCT(key_hnd
);
2611 result
= winreg_printer_openkey(tmp_ctx
,
2613 TOP_LEVEL_CONTROL_FORMS_KEY
,
2619 if (!W_ERROR_IS_OK(result
)) {
2620 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2621 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2625 result
= winreg_printer_enumforms1(tmp_ctx
, winreg_handle
,
2627 if (!W_ERROR_IS_OK(result
)) {
2628 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2629 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2633 /* If form name already exists or is builtin return ALREADY_EXISTS */
2634 for (i
= 0; i
< num_info
; i
++) {
2635 if (strequal(info
[i
].info1
.form_name
, form
->form_name
)) {
2636 result
= WERR_FILE_EXISTS
;
2641 wvalue
.name
= form
->form_name
;
2643 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
2644 SIVAL(blob
.data
, 0, form
->size
.width
);
2645 SIVAL(blob
.data
, 4, form
->size
.height
);
2646 SIVAL(blob
.data
, 8, form
->area
.left
);
2647 SIVAL(blob
.data
, 12, form
->area
.top
);
2648 SIVAL(blob
.data
, 16, form
->area
.right
);
2649 SIVAL(blob
.data
, 20, form
->area
.bottom
);
2650 SIVAL(blob
.data
, 24, num_info
+ 1); /* FIXME */
2651 SIVAL(blob
.data
, 28, form
->flags
);
2653 status
= dcerpc_winreg_SetValue(winreg_handle
,
2661 if (!NT_STATUS_IS_OK(status
)) {
2662 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2663 wvalue
.name
, nt_errstr(status
)));
2664 result
= ntstatus_to_werror(status
);
2668 if (is_valid_policy_hnd(&key_hnd
)) {
2669 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2671 if (is_valid_policy_hnd(&hive_hnd
)) {
2672 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2676 TALLOC_FREE(tmp_ctx
);
2680 WERROR
winreg_printer_enumforms1(TALLOC_CTX
*mem_ctx
,
2681 struct dcerpc_binding_handle
*winreg_handle
,
2682 uint32_t *pnum_info
,
2683 union spoolss_FormInfo
**pinfo
)
2685 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2686 struct policy_handle hive_hnd
, key_hnd
;
2687 union spoolss_FormInfo
*info
;
2688 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2689 uint32_t num_values
= 0;
2690 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2695 const char **enum_names
= NULL
;
2696 enum winreg_Type
*enum_types
= NULL
;
2697 DATA_BLOB
*enum_data_blobs
= NULL
;
2698 TALLOC_CTX
*tmp_ctx
;
2700 tmp_ctx
= talloc_stackframe();
2701 if (tmp_ctx
== NULL
) {
2705 ZERO_STRUCT(hive_hnd
);
2706 ZERO_STRUCT(key_hnd
);
2708 result
= winreg_printer_openkey(tmp_ctx
,
2710 TOP_LEVEL_CONTROL_FORMS_KEY
,
2716 if (!W_ERROR_IS_OK(result
)) {
2717 /* key doesn't exist */
2718 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2723 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
2724 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2728 status
= dcerpc_winreg_enumvals(tmp_ctx
,
2736 if (!NT_STATUS_IS_OK(status
)){
2737 result
= ntstatus_to_werror(status
);
2740 if (!W_ERROR_IS_OK(result
)) {
2741 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2742 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2746 enum_values
= talloc_zero_array(tmp_ctx
,
2747 struct spoolss_PrinterEnumValues
,
2749 if (enum_values
== NULL
){
2750 result
= WERR_NOMEM
;
2754 for (i
= 0; i
< num_values
; i
++){
2755 enum_values
[i
].value_name
= enum_names
[i
];
2756 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
2757 enum_values
[i
].type
= enum_types
[i
];
2758 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
2759 enum_values
[i
].data
= NULL
;
2760 if (enum_values
[i
].data_length
!= 0){
2761 enum_values
[i
].data
= &enum_data_blobs
[i
];
2765 if (!W_ERROR_IS_OK(result
)) {
2766 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2767 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2771 info
= talloc_array(tmp_ctx
, union spoolss_FormInfo
, num_builtin
+ num_values
);
2773 result
= WERR_NOMEM
;
2777 /* Enumerate BUILTIN forms */
2778 for (i
= 0; i
< num_builtin
; i
++) {
2779 info
[i
].info1
= builtin_forms1
[i
];
2782 /* Enumerate registry forms */
2783 for (i
= 0; i
< num_values
; i
++) {
2784 union spoolss_FormInfo val
;
2786 if (enum_values
[i
].type
!= REG_BINARY
||
2787 enum_values
[i
].data_length
!= 32) {
2791 val
.info1
.form_name
= talloc_strdup(info
, enum_values
[i
].value_name
);
2792 if (val
.info1
.form_name
== NULL
) {
2793 result
= WERR_NOMEM
;
2797 val
.info1
.size
.width
= IVAL(enum_values
[i
].data
->data
, 0);
2798 val
.info1
.size
.height
= IVAL(enum_values
[i
].data
->data
, 4);
2799 val
.info1
.area
.left
= IVAL(enum_values
[i
].data
->data
, 8);
2800 val
.info1
.area
.top
= IVAL(enum_values
[i
].data
->data
, 12);
2801 val
.info1
.area
.right
= IVAL(enum_values
[i
].data
->data
, 16);
2802 val
.info1
.area
.bottom
= IVAL(enum_values
[i
].data
->data
, 20);
2803 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
2804 val
.info1
.flags
= (enum spoolss_FormFlags
) IVAL(enum_values
[i
].data
->data
, 28);
2806 info
[i
+ num_builtin
] = val
;
2809 *pnum_info
= num_builtin
+ num_values
;
2811 *pinfo
= talloc_move(mem_ctx
, &info
);
2815 if (is_valid_policy_hnd(&key_hnd
)) {
2816 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2818 if (is_valid_policy_hnd(&hive_hnd
)) {
2819 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2822 TALLOC_FREE(enum_values
);
2823 TALLOC_FREE(tmp_ctx
);
2827 WERROR
winreg_printer_deleteform1(TALLOC_CTX
*mem_ctx
,
2828 struct dcerpc_binding_handle
*winreg_handle
,
2829 const char *form_name
)
2831 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2832 struct policy_handle hive_hnd
, key_hnd
;
2833 struct winreg_String wvalue
= { 0, };
2834 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2836 WERROR result
= WERR_OK
;
2839 TALLOC_CTX
*tmp_ctx
;
2841 for (i
= 0; i
< num_builtin
; i
++) {
2842 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
2843 return WERR_INVALID_PARAMETER
;
2847 tmp_ctx
= talloc_stackframe();
2848 if (tmp_ctx
== NULL
) {
2852 ZERO_STRUCT(hive_hnd
);
2853 ZERO_STRUCT(key_hnd
);
2855 result
= winreg_printer_openkey(tmp_ctx
,
2857 TOP_LEVEL_CONTROL_FORMS_KEY
,
2863 if (!W_ERROR_IS_OK(result
)) {
2864 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
2865 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2866 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2867 result
= WERR_INVALID_FORM_NAME
;
2872 wvalue
.name
= form_name
;
2873 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
2878 if (!NT_STATUS_IS_OK(status
)) {
2879 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
2880 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
2881 wvalue
.name
, nt_errstr(status
)));
2882 result
= ntstatus_to_werror(status
);
2886 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2887 result
= WERR_INVALID_FORM_NAME
;
2891 if (is_valid_policy_hnd(&key_hnd
)) {
2892 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2894 if (is_valid_policy_hnd(&hive_hnd
)) {
2895 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2898 TALLOC_FREE(tmp_ctx
);
2902 WERROR
winreg_printer_setform1(TALLOC_CTX
*mem_ctx
,
2903 struct dcerpc_binding_handle
*winreg_handle
,
2904 const char *form_name
,
2905 struct spoolss_AddFormInfo1
*form
)
2907 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2908 struct policy_handle hive_hnd
= { 0, };
2909 struct policy_handle key_hnd
= { 0, };
2910 struct winreg_String wvalue
= { 0, };
2912 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2916 TALLOC_CTX
*tmp_ctx
= NULL
;
2918 for (i
= 0; i
< num_builtin
; i
++) {
2919 if (strequal(builtin_forms1
[i
].form_name
, form
->form_name
)) {
2920 result
= WERR_INVALID_PARAM
;
2925 tmp_ctx
= talloc_stackframe();
2926 if (tmp_ctx
== NULL
) {
2930 ZERO_STRUCT(hive_hnd
);
2931 ZERO_STRUCT(key_hnd
);
2933 result
= winreg_printer_openkey(tmp_ctx
,
2935 TOP_LEVEL_CONTROL_FORMS_KEY
,
2941 if (!W_ERROR_IS_OK(result
)) {
2942 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
2943 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2947 /* If form_name != form->form_name then we renamed the form */
2948 if (strequal(form_name
, form
->form_name
)) {
2949 result
= winreg_printer_deleteform1(tmp_ctx
, winreg_handle
,
2951 if (!W_ERROR_IS_OK(result
)) {
2952 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
2953 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2958 wvalue
.name
= form
->form_name
;
2960 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
2961 SIVAL(blob
.data
, 0, form
->size
.width
);
2962 SIVAL(blob
.data
, 4, form
->size
.height
);
2963 SIVAL(blob
.data
, 8, form
->area
.left
);
2964 SIVAL(blob
.data
, 12, form
->area
.top
);
2965 SIVAL(blob
.data
, 16, form
->area
.right
);
2966 SIVAL(blob
.data
, 20, form
->area
.bottom
);
2967 SIVAL(blob
.data
, 24, 42);
2968 SIVAL(blob
.data
, 28, form
->flags
);
2970 status
= dcerpc_winreg_SetValue(winreg_handle
,
2978 if (!NT_STATUS_IS_OK(status
)) {
2979 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
2980 wvalue
.name
, nt_errstr(status
)));
2981 result
= ntstatus_to_werror(status
);
2985 if (winreg_handle
!= NULL
) {
2988 if (is_valid_policy_hnd(&key_hnd
)) {
2989 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2991 if (is_valid_policy_hnd(&hive_hnd
)) {
2992 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2996 TALLOC_FREE(tmp_ctx
);
3000 WERROR
winreg_printer_getform1(TALLOC_CTX
*mem_ctx
,
3001 struct dcerpc_binding_handle
*winreg_handle
,
3002 const char *form_name
,
3003 struct spoolss_FormInfo1
*r
)
3005 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3006 struct policy_handle hive_hnd
, key_hnd
;
3007 struct winreg_String wvalue
;
3008 enum winreg_Type type_in
= REG_NONE
;
3009 uint8_t *data_in
= NULL
;
3010 uint32_t data_in_size
= 0;
3011 uint32_t value_len
= 0;
3012 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3017 TALLOC_CTX
*tmp_ctx
;
3019 /* check builtin forms first */
3020 for (i
= 0; i
< num_builtin
; i
++) {
3021 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3022 *r
= builtin_forms1
[i
];
3027 tmp_ctx
= talloc_stackframe();
3028 if (tmp_ctx
== NULL
) {
3032 ZERO_STRUCT(hive_hnd
);
3033 ZERO_STRUCT(key_hnd
);
3035 result
= winreg_printer_openkey(tmp_ctx
,
3037 TOP_LEVEL_CONTROL_FORMS_KEY
,
3043 if (!W_ERROR_IS_OK(result
)) {
3044 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3045 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3049 wvalue
.name
= form_name
;
3052 * call QueryValue once with data == NULL to get the
3053 * needed memory size to be allocated, then allocate
3054 * data buffer and call again.
3056 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3065 if (!NT_STATUS_IS_OK(status
)) {
3066 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3067 wvalue
.name
, nt_errstr(status
)));
3068 result
= ntstatus_to_werror(status
);
3071 if (!W_ERROR_IS_OK(result
)) {
3075 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
3076 if (data_in
== NULL
) {
3077 result
= WERR_NOMEM
;
3082 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3091 if (!NT_STATUS_IS_OK(status
)) {
3092 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3093 wvalue
.name
, nt_errstr(status
)));
3094 result
= ntstatus_to_werror(status
);
3097 if (!W_ERROR_IS_OK(result
)) {
3101 r
->form_name
= talloc_strdup(mem_ctx
, form_name
);
3102 if (r
->form_name
== NULL
) {
3103 result
= WERR_NOMEM
;
3107 r
->size
.width
= IVAL(data_in
, 0);
3108 r
->size
.height
= IVAL(data_in
, 4);
3109 r
->area
.left
= IVAL(data_in
, 8);
3110 r
->area
.top
= IVAL(data_in
, 12);
3111 r
->area
.right
= IVAL(data_in
, 16);
3112 r
->area
.bottom
= IVAL(data_in
, 20);
3113 /* skip index IVAL(data_in, 24)));*/
3114 r
->flags
= (enum spoolss_FormFlags
) IVAL(data_in
, 28);
3118 if (is_valid_policy_hnd(&key_hnd
)) {
3119 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3121 if (is_valid_policy_hnd(&hive_hnd
)) {
3122 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3125 TALLOC_FREE(tmp_ctx
);
3129 WERROR
winreg_add_driver(TALLOC_CTX
*mem_ctx
,
3130 struct dcerpc_binding_handle
*winreg_handle
,
3131 struct spoolss_AddDriverInfoCtr
*r
,
3132 const char **driver_name
,
3133 uint32_t *driver_version
)
3135 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3136 struct policy_handle hive_hnd
, key_hnd
;
3137 struct spoolss_DriverInfo8 info8
;
3138 TALLOC_CTX
*tmp_ctx
= NULL
;
3142 ZERO_STRUCT(hive_hnd
);
3143 ZERO_STRUCT(key_hnd
);
3146 if (!driver_info_ctr_to_info8(r
, &info8
)) {
3147 result
= WERR_INVALID_PARAMETER
;
3151 tmp_ctx
= talloc_stackframe();
3152 if (tmp_ctx
== NULL
) {
3156 result
= winreg_printer_opendriver(tmp_ctx
,
3164 if (!W_ERROR_IS_OK(result
)) {
3165 DEBUG(0, ("winreg_add_driver: "
3166 "Could not open driver key (%s,%s,%d): %s\n",
3167 info8
.driver_name
, info8
.architecture
,
3168 info8
.version
, win_errstr(result
)));
3172 /* TODO: "Attributes" ? */
3174 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3180 if (!NT_STATUS_IS_OK(status
)) {
3181 result
= ntstatus_to_werror(status
);
3183 if (!W_ERROR_IS_OK(result
)) {
3187 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3193 if (!NT_STATUS_IS_OK(status
)) {
3194 result
= ntstatus_to_werror(status
);
3196 if (!W_ERROR_IS_OK(result
)) {
3200 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3206 if (!NT_STATUS_IS_OK(status
)) {
3207 result
= ntstatus_to_werror(status
);
3209 if (!W_ERROR_IS_OK(result
)) {
3213 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3216 "Configuration File",
3219 if (!NT_STATUS_IS_OK(status
)) {
3220 result
= ntstatus_to_werror(status
);
3222 if (!W_ERROR_IS_OK(result
)) {
3226 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3232 if (!NT_STATUS_IS_OK(status
)) {
3233 result
= ntstatus_to_werror(status
);
3235 if (!W_ERROR_IS_OK(result
)) {
3239 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3243 info8
.dependent_files
,
3245 if (!NT_STATUS_IS_OK(status
)) {
3246 result
= ntstatus_to_werror(status
);
3248 if (!W_ERROR_IS_OK(result
)) {
3252 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3258 if (!NT_STATUS_IS_OK(status
)) {
3259 result
= ntstatus_to_werror(status
);
3261 if (!W_ERROR_IS_OK(result
)) {
3265 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3269 info8
.default_datatype
,
3271 if (!NT_STATUS_IS_OK(status
)) {
3272 result
= ntstatus_to_werror(status
);
3274 if (!W_ERROR_IS_OK(result
)) {
3278 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3280 &key_hnd
, "Previous Names",
3281 info8
.previous_names
,
3283 if (!NT_STATUS_IS_OK(status
)) {
3284 result
= ntstatus_to_werror(status
);
3286 if (!W_ERROR_IS_OK(result
)) {
3290 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3291 &key_hnd
, "DriverDate",
3293 if (!W_ERROR_IS_OK(result
)) {
3297 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
,
3298 &key_hnd
, "DriverVersion",
3299 info8
.driver_version
);
3300 if (!W_ERROR_IS_OK(result
)) {
3304 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3308 info8
.manufacturer_name
,
3310 if (!NT_STATUS_IS_OK(status
)) {
3311 result
= ntstatus_to_werror(status
);
3313 if (!W_ERROR_IS_OK(result
)) {
3317 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3321 info8
.manufacturer_url
,
3323 if (!NT_STATUS_IS_OK(status
)) {
3324 result
= ntstatus_to_werror(status
);
3326 if (!W_ERROR_IS_OK(result
)) {
3330 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3336 if (!NT_STATUS_IS_OK(status
)) {
3337 result
= ntstatus_to_werror(status
);
3339 if (!W_ERROR_IS_OK(result
)) {
3343 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3349 if (!NT_STATUS_IS_OK(status
)) {
3350 result
= ntstatus_to_werror(status
);
3352 if (!W_ERROR_IS_OK(result
)) {
3356 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3360 info8
.print_processor
,
3362 if (!NT_STATUS_IS_OK(status
)) {
3363 result
= ntstatus_to_werror(status
);
3365 if (!W_ERROR_IS_OK(result
)) {
3369 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3375 if (!NT_STATUS_IS_OK(status
)) {
3376 result
= ntstatus_to_werror(status
);
3378 if (!W_ERROR_IS_OK(result
)) {
3382 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3386 info8
.color_profiles
,
3388 if (!NT_STATUS_IS_OK(status
)) {
3389 result
= ntstatus_to_werror(status
);
3391 if (!W_ERROR_IS_OK(result
)) {
3395 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3401 if (!NT_STATUS_IS_OK(status
)) {
3402 result
= ntstatus_to_werror(status
);
3404 if (!W_ERROR_IS_OK(result
)) {
3408 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3411 "PrinterDriverAttributes",
3412 info8
.printer_driver_attributes
,
3414 if (!NT_STATUS_IS_OK(status
)) {
3415 result
= ntstatus_to_werror(status
);
3417 if (!W_ERROR_IS_OK(result
)) {
3421 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3425 info8
.core_driver_dependencies
,
3427 if (!NT_STATUS_IS_OK(status
)) {
3428 result
= ntstatus_to_werror(status
);
3430 if (!W_ERROR_IS_OK(result
)) {
3434 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3435 &key_hnd
, "MinInboxDriverVerDate",
3436 info8
.min_inbox_driver_ver_date
);
3437 if (!W_ERROR_IS_OK(result
)) {
3441 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
, &key_hnd
,
3442 "MinInboxDriverVerVersion",
3443 info8
.min_inbox_driver_ver_version
);
3444 if (!W_ERROR_IS_OK(result
)) {
3448 *driver_name
= info8
.driver_name
;
3449 *driver_version
= info8
.version
;
3452 if (winreg_handle
!= NULL
) {
3455 if (is_valid_policy_hnd(&key_hnd
)) {
3456 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3458 if (is_valid_policy_hnd(&hive_hnd
)) {
3459 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3463 TALLOC_FREE(tmp_ctx
);
3467 WERROR
winreg_get_driver(TALLOC_CTX
*mem_ctx
,
3468 struct dcerpc_binding_handle
*winreg_handle
,
3469 const char *architecture
,
3470 const char *driver_name
,
3471 uint32_t driver_version
,
3472 struct spoolss_DriverInfo8
**_info8
)
3474 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3475 struct policy_handle hive_hnd
, key_hnd
;
3476 struct spoolss_DriverInfo8 i8
, *info8
;
3477 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
3478 struct spoolss_PrinterEnumValues
*v
;
3479 uint32_t num_values
= 0;
3480 TALLOC_CTX
*tmp_ctx
;
3484 const char **enum_names
= NULL
;
3485 enum winreg_Type
*enum_types
= NULL
;
3486 DATA_BLOB
*enum_data_blobs
= NULL
;
3488 ZERO_STRUCT(hive_hnd
);
3489 ZERO_STRUCT(key_hnd
);
3492 tmp_ctx
= talloc_stackframe();
3493 if (tmp_ctx
== NULL
) {
3497 if (driver_version
== DRIVER_ANY_VERSION
) {
3498 /* look for Win2k first and then for NT4 */
3499 result
= winreg_printer_opendriver(tmp_ctx
,
3507 if (!W_ERROR_IS_OK(result
)) {
3508 result
= winreg_printer_opendriver(tmp_ctx
,
3518 /* ok normal case */
3519 result
= winreg_printer_opendriver(tmp_ctx
,
3528 if (!W_ERROR_IS_OK(result
)) {
3529 DEBUG(5, ("winreg_get_driver: "
3530 "Could not open driver key (%s,%s,%d): %s\n",
3531 driver_name
, architecture
,
3532 driver_version
, win_errstr(result
)));
3536 status
= dcerpc_winreg_enumvals(tmp_ctx
,
3544 if (!NT_STATUS_IS_OK(status
)){
3545 result
= ntstatus_to_werror(status
);
3548 if (!W_ERROR_IS_OK(result
)) {
3549 DEBUG(0, ("winreg_get_driver: "
3550 "Could not enumerate values for (%s,%s,%d): %s\n",
3551 driver_name
, architecture
,
3552 driver_version
, win_errstr(result
)));
3556 enum_values
= talloc_zero_array(tmp_ctx
,
3557 struct spoolss_PrinterEnumValues
,
3559 if (enum_values
== NULL
){
3560 result
= WERR_NOMEM
;
3564 for (i
= 0; i
< num_values
; i
++){
3565 enum_values
[i
].value_name
= enum_names
[i
];
3566 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
3567 enum_values
[i
].type
= enum_types
[i
];
3568 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
3569 enum_values
[i
].data
= NULL
;
3570 if (enum_values
[i
].data_length
!= 0){
3571 enum_values
[i
].data
= &enum_data_blobs
[i
];
3575 info8
= talloc_zero(tmp_ctx
, struct spoolss_DriverInfo8
);
3576 if (info8
== NULL
) {
3577 result
= WERR_NOMEM
;
3581 info8
->driver_name
= talloc_strdup(info8
, driver_name
);
3582 if (info8
->driver_name
== NULL
) {
3583 result
= WERR_NOMEM
;
3587 info8
->architecture
= talloc_strdup(info8
, architecture
);
3588 if (info8
->architecture
== NULL
) {
3589 result
= WERR_NOMEM
;
3595 for (i
= 0; i
< num_values
; i
++) {
3596 const char *tmp_str
;
3599 v
= &enum_values
[i
];
3601 result
= winreg_enumval_to_dword(info8
, v
,
3604 if (W_ERROR_IS_OK(result
)) {
3605 info8
->version
= (enum spoolss_DriverOSVersion
) tmp
;
3607 CHECK_ERROR(result
);
3609 result
= winreg_enumval_to_sz(info8
, v
,
3611 &info8
->driver_path
);
3612 CHECK_ERROR(result
);
3614 result
= winreg_enumval_to_sz(info8
, v
,
3617 CHECK_ERROR(result
);
3619 result
= winreg_enumval_to_sz(info8
, v
,
3620 "Configuration File",
3621 &info8
->config_file
);
3622 CHECK_ERROR(result
);
3624 result
= winreg_enumval_to_sz(info8
, v
,
3627 CHECK_ERROR(result
);
3629 result
= winreg_enumval_to_multi_sz(info8
, v
,
3631 &info8
->dependent_files
);
3632 CHECK_ERROR(result
);
3634 result
= winreg_enumval_to_sz(info8
, v
,
3636 &info8
->monitor_name
);
3637 CHECK_ERROR(result
);
3639 result
= winreg_enumval_to_sz(info8
, v
,
3641 &info8
->default_datatype
);
3642 CHECK_ERROR(result
);
3644 result
= winreg_enumval_to_multi_sz(info8
, v
,
3646 &info8
->previous_names
);
3647 CHECK_ERROR(result
);
3649 result
= winreg_enumval_to_sz(info8
, v
,
3652 if (W_ERROR_IS_OK(result
)) {
3653 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3654 &info8
->driver_date
);
3656 CHECK_ERROR(result
);
3658 result
= winreg_enumval_to_sz(info8
, v
,
3661 if (W_ERROR_IS_OK(result
)) {
3662 result
= winreg_printer_ver_to_dword(tmp_str
,
3663 &info8
->driver_version
);
3665 CHECK_ERROR(result
);
3667 result
= winreg_enumval_to_sz(info8
, v
,
3669 &info8
->manufacturer_name
);
3670 CHECK_ERROR(result
);
3672 result
= winreg_enumval_to_sz(info8
, v
,
3674 &info8
->manufacturer_url
);
3675 CHECK_ERROR(result
);
3677 result
= winreg_enumval_to_sz(info8
, v
,
3679 &info8
->hardware_id
);
3680 CHECK_ERROR(result
);
3682 result
= winreg_enumval_to_sz(info8
, v
,
3685 CHECK_ERROR(result
);
3687 result
= winreg_enumval_to_sz(info8
, v
,
3689 &info8
->print_processor
);
3690 CHECK_ERROR(result
);
3692 result
= winreg_enumval_to_sz(info8
, v
,
3694 &info8
->vendor_setup
);
3695 CHECK_ERROR(result
);
3697 result
= winreg_enumval_to_multi_sz(info8
, v
,
3699 &info8
->color_profiles
);
3700 CHECK_ERROR(result
);
3702 result
= winreg_enumval_to_sz(info8
, v
,
3705 CHECK_ERROR(result
);
3707 result
= winreg_enumval_to_dword(info8
, v
,
3708 "PrinterDriverAttributes",
3709 &info8
->printer_driver_attributes
);
3710 CHECK_ERROR(result
);
3712 result
= winreg_enumval_to_multi_sz(info8
, v
,
3714 &info8
->core_driver_dependencies
);
3715 CHECK_ERROR(result
);
3717 result
= winreg_enumval_to_sz(info8
, v
,
3718 "MinInboxDriverVerDate",
3720 if (W_ERROR_IS_OK(result
)) {
3721 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3722 &info8
->min_inbox_driver_ver_date
);
3724 CHECK_ERROR(result
);
3726 result
= winreg_enumval_to_sz(info8
, v
,
3727 "MinInboxDriverVerVersion",
3729 if (W_ERROR_IS_OK(result
)) {
3730 result
= winreg_printer_ver_to_dword(tmp_str
,
3731 &info8
->min_inbox_driver_ver_version
);
3733 CHECK_ERROR(result
);
3736 if (!W_ERROR_IS_OK(result
)) {
3737 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3738 "for %s: %s\n", v
->value_name
,
3739 win_errstr(result
)));
3743 *_info8
= talloc_steal(mem_ctx
, info8
);
3746 if (winreg_handle
!= NULL
) {
3749 if (is_valid_policy_hnd(&key_hnd
)) {
3750 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3752 if (is_valid_policy_hnd(&hive_hnd
)) {
3753 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3757 TALLOC_FREE(tmp_ctx
);
3761 WERROR
winreg_del_driver(TALLOC_CTX
*mem_ctx
,
3762 struct dcerpc_binding_handle
*winreg_handle
,
3763 struct spoolss_DriverInfo8
*info8
,
3766 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3767 struct policy_handle hive_hnd
, key_hnd
;
3768 TALLOC_CTX
*tmp_ctx
;
3773 ZERO_STRUCT(hive_hnd
);
3774 ZERO_STRUCT(key_hnd
);
3776 tmp_ctx
= talloc_stackframe();
3777 if (tmp_ctx
== NULL
) {
3781 /* test that the key exists */
3782 result
= winreg_printer_opendriver(tmp_ctx
,
3785 info8
->architecture
,
3790 if (!W_ERROR_IS_OK(result
)) {
3791 /* key doesn't exist */
3792 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3797 DEBUG(5, ("winreg_del_driver: "
3798 "Could not open driver (%s,%s,%u): %s\n",
3799 info8
->driver_name
, info8
->architecture
,
3800 version
, win_errstr(result
)));
3805 if (is_valid_policy_hnd(&key_hnd
)) {
3806 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
3809 key_name
= talloc_asprintf(tmp_ctx
,
3810 "%s\\Environments\\%s\\Drivers\\Version-%u\\%s",
3811 TOP_LEVEL_CONTROL_KEY
,
3812 info8
->architecture
, version
,
3813 info8
->driver_name
);
3814 if (key_name
== NULL
) {
3815 result
= WERR_NOMEM
;
3819 status
= dcerpc_winreg_delete_subkeys_recursive(tmp_ctx
,
3826 if (!NT_STATUS_IS_OK(status
)){
3827 DEBUG(0, ("winreg_del_driver: "
3828 "Could not open driver (%s,%s,%u): %s\n",
3829 info8
->driver_name
, info8
->architecture
,
3830 version
, nt_errstr(status
)));
3834 if (!W_ERROR_IS_OK(result
)) {
3835 DEBUG(0, ("winreg_del_driver: "
3836 "Could not open driver (%s,%s,%u): %s\n",
3837 info8
->driver_name
, info8
->architecture
,
3838 version
, win_errstr(result
)));
3844 if (winreg_handle
!= NULL
) {
3847 if (is_valid_policy_hnd(&key_hnd
)) {
3848 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3850 if (is_valid_policy_hnd(&hive_hnd
)) {
3851 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3855 TALLOC_FREE(tmp_ctx
);
3859 WERROR
winreg_get_driver_list(TALLOC_CTX
*mem_ctx
,
3860 struct dcerpc_binding_handle
*winreg_handle
,
3861 const char *architecture
,
3863 uint32_t *num_drivers
,
3864 const char ***drivers_p
)
3866 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3867 struct policy_handle hive_hnd
, key_hnd
;
3868 const char **drivers
;
3869 TALLOC_CTX
*tmp_ctx
;
3876 ZERO_STRUCT(hive_hnd
);
3877 ZERO_STRUCT(key_hnd
);
3879 tmp_ctx
= talloc_stackframe();
3880 if (tmp_ctx
== NULL
) {
3884 /* use NULL for the driver name so we open the key that is
3885 * parent of all drivers for this architecture and version */
3886 result
= winreg_printer_opendriver(tmp_ctx
,
3894 if (!W_ERROR_IS_OK(result
)) {
3895 DEBUG(5, ("winreg_get_driver_list: "
3896 "Could not open key (%s,%u): %s\n",
3897 architecture
, version
, win_errstr(result
)));
3902 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
3908 if (!NT_STATUS_IS_OK(status
)) {
3909 result
= ntstatus_to_werror(status
);
3911 if (!W_ERROR_IS_OK(result
)) {
3912 DEBUG(0, ("winreg_get_driver_list: "
3913 "Could not enumerate drivers for (%s,%u): %s\n",
3914 architecture
, version
, win_errstr(result
)));
3918 *drivers_p
= talloc_steal(mem_ctx
, drivers
);
3922 if (winreg_handle
!= NULL
) {
3925 if (is_valid_policy_hnd(&key_hnd
)) {
3926 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3928 if (is_valid_policy_hnd(&hive_hnd
)) {
3929 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3933 TALLOC_FREE(tmp_ctx
);