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 return ntstatus_to_werror(status
);
301 if (!W_ERROR_IS_OK(result
)) {
309 * @brief Create the registry keyname for the given printer.
311 * @param[in] mem_ctx The memory context to use.
313 * @param[in] printer The name of the printer to get the registry key.
315 * @return The registry key or NULL on error.
317 static char *winreg_printer_data_keyname(TALLOC_CTX
*mem_ctx
, const char *printer
) {
318 return talloc_asprintf(mem_ctx
, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY
, printer
);
324 * @brief Enumerate values of an opened key handle and retrieve the data.
326 * @param[in] mem_ctx The memory context to use.
328 * @param[in] winreg_handle The binding handle for the rpc connection.
330 * @param[in] key_hnd The opened key handle.
332 * @param[out] pnum_values A pointer to store he number of values found.
334 * @param[out] pnum_values A pointer to store the number of values we found.
336 * @return WERR_OK on success, the corresponding DOS error
337 * code if something gone wrong.
339 static WERROR
winreg_printer_enumvalues(TALLOC_CTX
*mem_ctx
,
340 struct dcerpc_binding_handle
*winreg_handle
,
341 struct policy_handle
*key_hnd
,
342 uint32_t *pnum_values
,
343 struct spoolss_PrinterEnumValues
**penum_values
)
346 uint32_t num_subkeys
, max_subkeylen
, max_classlen
;
347 uint32_t num_values
, max_valnamelen
, max_valbufsize
;
348 uint32_t secdescsize
;
350 NTTIME last_changed_time
;
351 struct winreg_String classname
;
353 struct spoolss_PrinterEnumValues
*enum_values
;
355 WERROR result
= WERR_OK
;
358 tmp_ctx
= talloc_stackframe();
359 if (tmp_ctx
== NULL
) {
363 ZERO_STRUCT(classname
);
365 status
= dcerpc_winreg_QueryInfoKey(winreg_handle
,
378 if (!NT_STATUS_IS_OK(status
)) {
379 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
381 result
= ntstatus_to_werror(status
);
384 if (!W_ERROR_IS_OK(result
)) {
385 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
386 win_errstr(result
)));
390 if (num_values
== 0) {
392 TALLOC_FREE(tmp_ctx
);
396 enum_values
= talloc_array(tmp_ctx
, struct spoolss_PrinterEnumValues
, num_values
);
397 if (enum_values
== NULL
) {
402 for (i
= 0; i
< num_values
; i
++) {
403 struct spoolss_PrinterEnumValues val
;
404 struct winreg_ValNameBuf name_buf
;
405 enum winreg_Type type
= REG_NONE
;
412 name_buf
.size
= max_valnamelen
+ 2;
415 data_size
= max_valbufsize
;
418 data
= (uint8_t *) talloc_zero_size(tmp_ctx
, data_size
);
422 status
= dcerpc_winreg_EnumValue(winreg_handle
,
429 data_size
? &data_size
: NULL
,
432 if (W_ERROR_EQUAL(result
, WERR_NO_MORE_ITEMS
) ) {
434 status
= NT_STATUS_OK
;
438 if (!NT_STATUS_IS_OK(status
)) {
439 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
441 result
= ntstatus_to_werror(status
);
444 if (!W_ERROR_IS_OK(result
)) {
445 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
446 win_errstr(result
)));
450 if (name_buf
.name
== NULL
) {
451 result
= WERR_INVALID_PARAMETER
;
455 val
.value_name
= talloc_strdup(enum_values
, name_buf
.name
);
456 if (val
.value_name
== NULL
) {
460 val
.value_name_len
= strlen_m_term(val
.value_name
) * 2;
463 val
.data_length
= length
;
465 if (val
.data_length
) {
466 val
.data
= talloc(enum_values
, DATA_BLOB
);
467 if (val
.data
== NULL
) {
471 *val
.data
= data_blob_talloc(val
.data
, data
, val
.data_length
);
474 enum_values
[i
] = val
;
477 *pnum_values
= num_values
;
479 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
485 TALLOC_FREE(tmp_ctx
);
492 * @brief A function to delete a key and its subkeys recurively.
494 * @param[in] mem_ctx The memory context to use.
496 * @param[in] winreg_handle The binding handle for the rpc connection.
498 * @param[in] hive_handle A opened hive handle to the key.
500 * @param[in] access_mask The access mask to access the key.
502 * @param[in] key The key to delete
504 * @return WERR_OK on success, the corresponding DOS error
505 * code if something gone wrong.
507 static WERROR
winreg_printer_delete_subkeys(TALLOC_CTX
*mem_ctx
,
508 struct dcerpc_binding_handle
*winreg_handle
,
509 struct policy_handle
*hive_handle
,
510 uint32_t access_mask
,
513 const char **subkeys
= NULL
;
514 uint32_t num_subkeys
= 0;
515 struct policy_handle key_hnd
;
516 struct winreg_String wkey
= { 0, };
517 WERROR result
= WERR_OK
;
521 ZERO_STRUCT(key_hnd
);
524 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key
));
526 status
= dcerpc_winreg_OpenKey(winreg_handle
,
534 if (!NT_STATUS_IS_OK(status
)) {
535 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
536 wkey
.name
, nt_errstr(status
)));
537 return ntstatus_to_werror(status
);
539 if (!W_ERROR_IS_OK(result
)) {
540 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
541 wkey
.name
, win_errstr(result
)));
545 status
= dcerpc_winreg_enum_keys(mem_ctx
,
551 if (!NT_STATUS_IS_OK(status
)) {
552 result
= ntstatus_to_werror(status
);
554 if (!W_ERROR_IS_OK(result
)) {
558 for (i
= 0; i
< num_subkeys
; i
++) {
559 /* create key + subkey */
560 char *subkey
= talloc_asprintf(mem_ctx
, "%s\\%s", key
, subkeys
[i
]);
561 if (subkey
== NULL
) {
565 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey
));
566 result
= winreg_printer_delete_subkeys(mem_ctx
,
571 if (!W_ERROR_IS_OK(result
)) {
576 if (is_valid_policy_hnd(&key_hnd
)) {
578 dcerpc_winreg_CloseKey(winreg_handle
, mem_ctx
, &key_hnd
, &ignore
);
583 status
= dcerpc_winreg_DeleteKey(winreg_handle
,
588 if (!NT_STATUS_IS_OK(status
)) {
589 result
= ntstatus_to_werror(status
);
593 if (is_valid_policy_hnd(&key_hnd
)) {
596 dcerpc_winreg_CloseKey(winreg_handle
, mem_ctx
, &key_hnd
, &ignore
);
602 static WERROR
winreg_printer_opendriver(TALLOC_CTX
*mem_ctx
,
603 struct dcerpc_binding_handle
*winreg_handle
,
604 const char *drivername
,
605 const char *architecture
,
607 uint32_t access_mask
,
609 struct policy_handle
*hive_hnd
,
610 struct policy_handle
*key_hnd
)
615 key_name
= talloc_asprintf(mem_ctx
, "%s\\Environments\\%s\\Drivers\\Version-%u",
616 TOP_LEVEL_CONTROL_KEY
,
617 architecture
, version
);
622 result
= winreg_printer_openkey(mem_ctx
,
633 static WERROR
winreg_enumval_to_dword(TALLOC_CTX
*mem_ctx
,
634 struct spoolss_PrinterEnumValues
*v
,
635 const char *valuename
, uint32_t *dw
)
637 /* just return if it is not the one we are looking for */
638 if (strcmp(valuename
, v
->value_name
) != 0) {
639 return WERR_NOT_FOUND
;
642 if (v
->type
!= REG_DWORD
) {
643 return WERR_INVALID_DATATYPE
;
646 if (v
->data_length
!= 4) {
651 *dw
= IVAL(v
->data
->data
, 0);
655 static WERROR
winreg_enumval_to_sz(TALLOC_CTX
*mem_ctx
,
656 struct spoolss_PrinterEnumValues
*v
,
657 const char *valuename
, const char **_str
)
659 /* just return if it is not the one we are looking for */
660 if (strcmp(valuename
, v
->value_name
) != 0) {
661 return WERR_NOT_FOUND
;
664 if (v
->type
!= REG_SZ
) {
665 return WERR_INVALID_DATATYPE
;
668 if (v
->data_length
== 0) {
669 *_str
= talloc_strdup(mem_ctx
, EMPTY_STRING
);
676 if (!pull_reg_sz(mem_ctx
, v
->data
, _str
)) {
683 static WERROR
winreg_enumval_to_multi_sz(TALLOC_CTX
*mem_ctx
,
684 struct spoolss_PrinterEnumValues
*v
,
685 const char *valuename
,
688 /* just return if it is not the one we are looking for */
689 if (strcmp(valuename
, v
->value_name
) != 0) {
690 return WERR_NOT_FOUND
;
693 if (v
->type
!= REG_MULTI_SZ
) {
694 return WERR_INVALID_DATATYPE
;
697 if (v
->data_length
== 0) {
698 *array
= talloc_array(mem_ctx
, const char *, 1);
699 if (*array
== NULL
) {
706 if (!pull_reg_multi_sz(mem_ctx
, v
->data
, array
)) {
713 static WERROR
winreg_printer_write_date(TALLOC_CTX
*mem_ctx
,
714 struct dcerpc_binding_handle
*winreg_handle
,
715 struct policy_handle
*key_handle
,
719 struct winreg_String wvalue
= { 0, };
721 WERROR result
= WERR_OK
;
728 str
= talloc_strdup(mem_ctx
, "01/01/1601");
730 t
= nt_time_to_unix(data
);
733 return map_werror_from_unix(errno
);
735 str
= talloc_asprintf(mem_ctx
, "%02d/%02d/%04d",
736 tm
->tm_mon
+ 1, tm
->tm_mday
, tm
->tm_year
+ 1900);
743 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
746 status
= dcerpc_winreg_SetValue(winreg_handle
,
754 if (!NT_STATUS_IS_OK(status
)) {
755 result
= ntstatus_to_werror(status
);
757 if (!W_ERROR_IS_OK(result
)) {
758 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
759 wvalue
.name
, win_errstr(result
)));
765 static WERROR
winreg_printer_date_to_NTTIME(const char *str
, NTTIME
*data
)
770 if (strequal(str
, "01/01/1601")) {
777 if (sscanf(str
, "%d/%d/%d",
778 &tm
.tm_mon
, &tm
.tm_mday
, &tm
.tm_year
) != 3) {
779 return WERR_INVALID_PARAMETER
;
786 unix_to_nt_time(data
, t
);
791 static WERROR
winreg_printer_write_ver(TALLOC_CTX
*mem_ctx
,
792 struct dcerpc_binding_handle
*winreg_handle
,
793 struct policy_handle
*key_handle
,
797 struct winreg_String wvalue
= { 0, };
799 WERROR result
= WERR_OK
;
803 /* FIXME: check format is right,
804 * this needs to be something like: 6.1.7600.16385 */
805 str
= talloc_asprintf(mem_ctx
, "%u.%u.%u.%u",
806 (unsigned)((data
>> 48) & 0xFFFF),
807 (unsigned)((data
>> 32) & 0xFFFF),
808 (unsigned)((data
>> 16) & 0xFFFF),
809 (unsigned)(data
& 0xFFFF));
815 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
818 status
= dcerpc_winreg_SetValue(winreg_handle
,
826 if (!NT_STATUS_IS_OK(status
)) {
827 result
= ntstatus_to_werror(status
);
829 if (!W_ERROR_IS_OK(result
)) {
830 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
831 wvalue
.name
, win_errstr(result
)));
837 static WERROR
winreg_printer_ver_to_dword(const char *str
, uint64_t *data
)
839 unsigned int v1
, v2
, v3
, v4
;
841 if (sscanf(str
, "%u.%u.%u.%u", &v1
, &v2
, &v3
, &v4
) != 4) {
842 return WERR_INVALID_PARAMETER
;
845 *data
= ((uint64_t)(v1
& 0xFFFF) << 48) +
846 ((uint64_t)(v2
& 0xFFFF) << 32) +
847 ((uint64_t)(v3
& 0xFFFF) << 16) +
848 (uint64_t)(v2
& 0xFFFF);
853 /********************************************************************
854 Public winreg function for spoolss
855 ********************************************************************/
857 WERROR
winreg_create_printer(TALLOC_CTX
*mem_ctx
,
858 struct dcerpc_binding_handle
*winreg_handle
,
859 const char *sharename
)
861 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
862 struct policy_handle hive_hnd
, key_hnd
;
863 struct spoolss_SetPrinterInfo2
*info2
;
864 struct security_descriptor
*secdesc
;
865 struct winreg_String wkey
, wkeyclass
;
867 const char *subkeys
[] = { SPOOL_DSDRIVER_KEY
, SPOOL_DSSPOOLER_KEY
, SPOOL_PRINTERDATA_KEY
};
868 uint32_t i
, count
= ARRAY_SIZE(subkeys
);
869 uint32_t info2_mask
= 0;
870 WERROR result
= WERR_OK
;
873 tmp_ctx
= talloc_stackframe();
874 if (tmp_ctx
== NULL
) {
878 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
880 TALLOC_FREE(tmp_ctx
);
884 ZERO_STRUCT(hive_hnd
);
885 ZERO_STRUCT(key_hnd
);
887 result
= winreg_printer_openkey(tmp_ctx
,
895 if (W_ERROR_IS_OK(result
)) {
896 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path
));
898 } else if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
899 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path
));
900 } else if (!W_ERROR_IS_OK(result
)) {
901 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
902 path
, win_errstr(result
)));
906 /* Create the main key */
907 result
= winreg_printer_openkey(tmp_ctx
,
915 if (!W_ERROR_IS_OK(result
)) {
916 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
917 path
, win_errstr(result
)));
921 if (is_valid_policy_hnd(&key_hnd
)) {
922 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
926 for (i
= 0; i
< count
; i
++) {
928 enum winreg_CreateAction action
= REG_ACTION_NONE
;
930 ZERO_STRUCT(key_hnd
);
933 wkey
.name
= talloc_asprintf(tmp_ctx
, "%s\\%s", path
, subkeys
[i
]);
934 if (wkey
.name
== NULL
) {
939 ZERO_STRUCT(wkeyclass
);
942 status
= dcerpc_winreg_CreateKey(winreg_handle
,
953 if (!NT_STATUS_IS_OK(status
)) {
954 result
= ntstatus_to_werror(status
);
956 if (!W_ERROR_IS_OK(result
)) {
957 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
958 wkey
.name
, win_errstr(result
)));
962 if (strequal(subkeys
[i
], SPOOL_DSSPOOLER_KEY
)) {
963 const char *dnssuffix
;
964 const char *longname
;
967 status
= dcerpc_winreg_set_sz(tmp_ctx
,
970 SPOOL_REG_PRINTERNAME
,
973 if (!NT_STATUS_IS_OK(status
)) {
974 result
= ntstatus_to_werror(status
);
976 if (!W_ERROR_IS_OK(result
)) {
980 status
= dcerpc_winreg_set_sz(tmp_ctx
,
983 SPOOL_REG_SHORTSERVERNAME
,
986 if (!NT_STATUS_IS_OK(status
)) {
987 result
= ntstatus_to_werror(status
);
989 if (!W_ERROR_IS_OK(result
)) {
993 /* We make the assumption that the netbios name
994 * is the same as the DNS name since the former
995 * will be what we used to join the domain
997 dnssuffix
= get_mydnsdomname(tmp_ctx
);
998 if (dnssuffix
!= NULL
&& dnssuffix
[0] != '\0') {
999 longname
= talloc_asprintf(tmp_ctx
, "%s.%s", global_myname(), dnssuffix
);
1001 longname
= talloc_strdup(tmp_ctx
, global_myname());
1003 if (longname
== NULL
) {
1004 result
= WERR_NOMEM
;
1008 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1011 SPOOL_REG_SERVERNAME
,
1014 if (!NT_STATUS_IS_OK(status
)) {
1015 result
= ntstatus_to_werror(status
);
1017 if (!W_ERROR_IS_OK(result
)) {
1021 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
1022 longname
, sharename
);
1023 if (uncname
== NULL
) {
1024 result
= WERR_NOMEM
;
1028 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1034 if (!NT_STATUS_IS_OK(status
)) {
1035 result
= ntstatus_to_werror(status
);
1037 if (!W_ERROR_IS_OK(result
)) {
1041 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1044 SPOOL_REG_VERSIONNUMBER
,
1047 if (!NT_STATUS_IS_OK(status
)) {
1048 result
= ntstatus_to_werror(status
);
1050 if (!W_ERROR_IS_OK(result
)) {
1054 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1057 SPOOL_REG_PRINTSTARTTIME
,
1060 if (!NT_STATUS_IS_OK(status
)) {
1061 result
= ntstatus_to_werror(status
);
1063 if (!W_ERROR_IS_OK(result
)) {
1067 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1070 SPOOL_REG_PRINTENDTIME
,
1073 if (!NT_STATUS_IS_OK(status
)) {
1074 result
= ntstatus_to_werror(status
);
1076 if (!W_ERROR_IS_OK(result
)) {
1080 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1086 if (!NT_STATUS_IS_OK(status
)) {
1087 result
= ntstatus_to_werror(status
);
1089 if (!W_ERROR_IS_OK(result
)) {
1093 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1096 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
1099 if (!NT_STATUS_IS_OK(status
)) {
1100 result
= ntstatus_to_werror(status
);
1102 if (!W_ERROR_IS_OK(result
)) {
1107 if (is_valid_policy_hnd(&key_hnd
)) {
1108 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
1111 info2
= talloc_zero(tmp_ctx
, struct spoolss_SetPrinterInfo2
);
1112 if (info2
== NULL
) {
1113 result
= WERR_NOMEM
;
1117 info2
->printername
= sharename
;
1118 if (info2
->printername
== NULL
) {
1119 result
= WERR_NOMEM
;
1122 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTERNAME
;
1124 info2
->sharename
= sharename
;
1125 info2_mask
|= SPOOLSS_PRINTER_INFO_SHARENAME
;
1127 info2
->portname
= SAMBA_PRINTER_PORT_NAME
;
1128 info2_mask
|= SPOOLSS_PRINTER_INFO_PORTNAME
;
1130 info2
->printprocessor
= "winprint";
1131 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
;
1133 info2
->datatype
= "RAW";
1134 info2_mask
|= SPOOLSS_PRINTER_INFO_DATATYPE
;
1136 info2
->comment
= "";
1137 info2_mask
|= SPOOLSS_PRINTER_INFO_COMMENT
;
1139 info2
->attributes
= PRINTER_ATTRIBUTE_SAMBA
;
1140 info2_mask
|= SPOOLSS_PRINTER_INFO_ATTRIBUTES
;
1142 info2
->starttime
= 0; /* Minutes since 12:00am GMT */
1143 info2_mask
|= SPOOLSS_PRINTER_INFO_STARTTIME
;
1145 info2
->untiltime
= 0; /* Minutes since 12:00am GMT */
1146 info2_mask
|= SPOOLSS_PRINTER_INFO_UNTILTIME
;
1148 info2
->priority
= 1;
1149 info2_mask
|= SPOOLSS_PRINTER_INFO_PRIORITY
;
1151 info2
->defaultpriority
= 1;
1152 info2_mask
|= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
;
1154 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1155 if (!W_ERROR_IS_OK(result
)) {
1158 info2_mask
|= SPOOLSS_PRINTER_INFO_SECDESC
;
1161 * Don't write a default Device Mode to the registry! The Device Mode is
1162 * only written to disk with a SetPrinter level 2 or 8.
1165 result
= winreg_update_printer(tmp_ctx
,
1174 if (winreg_handle
!= NULL
) {
1177 if (is_valid_policy_hnd(&key_hnd
)) {
1178 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1180 if (is_valid_policy_hnd(&hive_hnd
)) {
1181 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1185 talloc_free(tmp_ctx
);
1189 WERROR
winreg_update_printer(TALLOC_CTX
*mem_ctx
,
1190 struct dcerpc_binding_handle
*winreg_handle
,
1191 const char *sharename
,
1192 uint32_t info2_mask
,
1193 struct spoolss_SetPrinterInfo2
*info2
,
1194 struct spoolss_DeviceMode
*devmode
,
1195 struct security_descriptor
*secdesc
)
1197 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1198 struct policy_handle hive_hnd
, key_hnd
;
1199 int snum
= lp_servicenumber(sharename
);
1200 enum ndr_err_code ndr_err
;
1203 WERROR result
= WERR_OK
;
1205 TALLOC_CTX
*tmp_ctx
;
1207 tmp_ctx
= talloc_stackframe();
1208 if (tmp_ctx
== NULL
) {
1212 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1214 TALLOC_FREE(tmp_ctx
);
1218 ZERO_STRUCT(hive_hnd
);
1219 ZERO_STRUCT(key_hnd
);
1221 result
= winreg_printer_openkey(tmp_ctx
,
1229 if (!W_ERROR_IS_OK(result
)) {
1230 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1231 path
, win_errstr(result
)));
1235 if (info2_mask
& SPOOLSS_PRINTER_INFO_ATTRIBUTES
) {
1236 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1242 if (!NT_STATUS_IS_OK(status
)) {
1243 result
= ntstatus_to_werror(status
);
1245 if (!W_ERROR_IS_OK(result
)) {
1251 if (info2_mask
& SPOOLSS_PRINTER_INFO_AVERAGEPPM
) {
1252 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1258 if (!NT_STATUS_IS_OK(status
)) {
1259 result
= ntstatus_to_werror(status
);
1261 if (!W_ERROR_IS_OK(result
)) {
1267 if (info2_mask
& SPOOLSS_PRINTER_INFO_COMMENT
) {
1268 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1274 if (!NT_STATUS_IS_OK(status
)) {
1275 result
= ntstatus_to_werror(status
);
1277 if (!W_ERROR_IS_OK(result
)) {
1282 if (info2_mask
& SPOOLSS_PRINTER_INFO_DATATYPE
) {
1283 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1289 if (!NT_STATUS_IS_OK(status
)) {
1290 result
= ntstatus_to_werror(status
);
1292 if (!W_ERROR_IS_OK(result
)) {
1297 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
) {
1298 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1302 info2
->defaultpriority
,
1304 if (!NT_STATUS_IS_OK(status
)) {
1305 result
= ntstatus_to_werror(status
);
1307 if (!W_ERROR_IS_OK(result
)) {
1312 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEVMODE
) {
1314 * Some client drivers freak out if there is a NULL devmode
1315 * (probably the driver is not checking before accessing
1316 * the devmode pointer) --jerry
1318 if (devmode
== NULL
&& lp_default_devmode(snum
) && info2
!= NULL
) {
1319 result
= spoolss_create_default_devmode(tmp_ctx
,
1322 if (!W_ERROR_IS_OK(result
)) {
1327 if (devmode
->size
!= (ndr_size_spoolss_DeviceMode(devmode
, 0) - devmode
->__driverextra_length
)) {
1328 result
= WERR_INVALID_PARAM
;
1332 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, devmode
,
1333 (ndr_push_flags_fn_t
) ndr_push_spoolss_DeviceMode
);
1334 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1335 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1336 result
= WERR_NOMEM
;
1340 status
= dcerpc_winreg_set_binary(tmp_ctx
,
1346 if (!NT_STATUS_IS_OK(status
)) {
1347 result
= ntstatus_to_werror(status
);
1349 if (!W_ERROR_IS_OK(result
)) {
1354 if (info2_mask
& SPOOLSS_PRINTER_INFO_DRIVERNAME
) {
1355 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1361 if (!NT_STATUS_IS_OK(status
)) {
1362 result
= ntstatus_to_werror(status
);
1364 if (!W_ERROR_IS_OK(result
)) {
1369 if (info2_mask
& SPOOLSS_PRINTER_INFO_LOCATION
) {
1370 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1376 if (!NT_STATUS_IS_OK(status
)) {
1377 result
= ntstatus_to_werror(status
);
1379 if (!W_ERROR_IS_OK(result
)) {
1384 if (info2_mask
& SPOOLSS_PRINTER_INFO_PARAMETERS
) {
1385 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1391 if (!NT_STATUS_IS_OK(status
)) {
1392 result
= ntstatus_to_werror(status
);
1394 if (!W_ERROR_IS_OK(result
)) {
1399 if (info2_mask
& SPOOLSS_PRINTER_INFO_PORTNAME
) {
1400 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1406 if (!NT_STATUS_IS_OK(status
)) {
1407 result
= ntstatus_to_werror(status
);
1409 if (!W_ERROR_IS_OK(result
)) {
1414 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTERNAME
) {
1416 * in addprinter: no servername and the printer is the name
1417 * in setprinter: servername is \\server
1418 * and printer is \\server\\printer
1420 * Samba manages only local printers.
1421 * we currently don't support things like i
1422 * path=\\other_server\printer
1424 * We only store the printername, not \\server\printername
1426 const char *p
= strrchr(info2
->printername
, '\\');
1428 p
= info2
->printername
;
1432 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1438 if (!NT_STATUS_IS_OK(status
)) {
1439 result
= ntstatus_to_werror(status
);
1441 if (!W_ERROR_IS_OK(result
)) {
1446 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
) {
1447 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1451 info2
->printprocessor
,
1453 if (!NT_STATUS_IS_OK(status
)) {
1454 result
= ntstatus_to_werror(status
);
1456 if (!W_ERROR_IS_OK(result
)) {
1461 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRIORITY
) {
1462 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1468 if (!NT_STATUS_IS_OK(status
)) {
1469 result
= ntstatus_to_werror(status
);
1471 if (!W_ERROR_IS_OK(result
)) {
1476 if (info2_mask
& SPOOLSS_PRINTER_INFO_SECDESC
) {
1478 * We need a security descriptor, if it isn't specified by
1479 * AddPrinter{Ex} then create a default descriptor.
1481 if (secdesc
== NULL
) {
1482 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1483 if (!W_ERROR_IS_OK(result
)) {
1487 result
= winreg_set_printer_secdesc(tmp_ctx
,
1491 if (!W_ERROR_IS_OK(result
)) {
1496 if (info2_mask
& SPOOLSS_PRINTER_INFO_SEPFILE
) {
1497 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1503 if (!NT_STATUS_IS_OK(status
)) {
1504 result
= ntstatus_to_werror(status
);
1506 if (!W_ERROR_IS_OK(result
)) {
1511 if (info2_mask
& SPOOLSS_PRINTER_INFO_SHARENAME
) {
1512 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1518 if (!NT_STATUS_IS_OK(status
)) {
1519 result
= ntstatus_to_werror(status
);
1521 if (!W_ERROR_IS_OK(result
)) {
1526 if (info2_mask
& SPOOLSS_PRINTER_INFO_STARTTIME
) {
1527 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1533 if (!NT_STATUS_IS_OK(status
)) {
1534 result
= ntstatus_to_werror(status
);
1536 if (!W_ERROR_IS_OK(result
)) {
1541 if (info2_mask
& SPOOLSS_PRINTER_INFO_STATUS
) {
1542 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1548 if (!NT_STATUS_IS_OK(status
)) {
1549 result
= ntstatus_to_werror(status
);
1551 if (!W_ERROR_IS_OK(result
)) {
1556 if (info2_mask
& SPOOLSS_PRINTER_INFO_UNTILTIME
) {
1557 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1563 if (!NT_STATUS_IS_OK(status
)) {
1564 result
= ntstatus_to_werror(status
);
1566 if (!W_ERROR_IS_OK(result
)) {
1571 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1575 winreg_printer_rev_changeid(),
1577 if (!NT_STATUS_IS_OK(status
)) {
1578 result
= ntstatus_to_werror(status
);
1580 if (!W_ERROR_IS_OK(result
)) {
1586 if (winreg_handle
!= NULL
) {
1589 if (is_valid_policy_hnd(&key_hnd
)) {
1590 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1592 if (is_valid_policy_hnd(&hive_hnd
)) {
1593 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1597 TALLOC_FREE(tmp_ctx
);
1601 WERROR
winreg_get_printer(TALLOC_CTX
*mem_ctx
,
1602 struct dcerpc_binding_handle
*winreg_handle
,
1603 const char *printer
,
1604 struct spoolss_PrinterInfo2
**pinfo2
)
1606 struct spoolss_PrinterInfo2
*info2
;
1607 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1608 struct policy_handle hive_hnd
, key_hnd
;
1609 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
1610 struct spoolss_PrinterEnumValues
*v
= NULL
;
1611 enum ndr_err_code ndr_err
;
1613 int snum
= lp_servicenumber(printer
);
1614 uint32_t num_values
= 0;
1618 WERROR result
= WERR_OK
;
1619 TALLOC_CTX
*tmp_ctx
;
1621 tmp_ctx
= talloc_stackframe();
1622 if (tmp_ctx
== NULL
) {
1626 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1628 TALLOC_FREE(tmp_ctx
);
1632 result
= winreg_printer_openkey(tmp_ctx
,
1640 if (!W_ERROR_IS_OK(result
)) {
1641 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
1642 path
, win_errstr(result
)));
1646 result
= winreg_printer_enumvalues(tmp_ctx
,
1651 if (!W_ERROR_IS_OK(result
)) {
1652 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1653 path
, win_errstr(result
)));
1657 info2
= talloc_zero(tmp_ctx
, struct spoolss_PrinterInfo2
);
1658 if (info2
== NULL
) {
1659 result
= WERR_NOMEM
;
1663 FILL_STRING(info2
, EMPTY_STRING
, info2
->servername
);
1664 FILL_STRING(info2
, EMPTY_STRING
, info2
->printername
);
1665 FILL_STRING(info2
, EMPTY_STRING
, info2
->sharename
);
1666 FILL_STRING(info2
, EMPTY_STRING
, info2
->portname
);
1667 FILL_STRING(info2
, EMPTY_STRING
, info2
->drivername
);
1668 FILL_STRING(info2
, EMPTY_STRING
, info2
->comment
);
1669 FILL_STRING(info2
, EMPTY_STRING
, info2
->location
);
1670 FILL_STRING(info2
, EMPTY_STRING
, info2
->sepfile
);
1671 FILL_STRING(info2
, EMPTY_STRING
, info2
->printprocessor
);
1672 FILL_STRING(info2
, EMPTY_STRING
, info2
->datatype
);
1673 FILL_STRING(info2
, EMPTY_STRING
, info2
->parameters
);
1675 for (i
= 0; i
< num_values
; i
++) {
1676 v
= &enum_values
[i
];
1678 result
= winreg_enumval_to_sz(info2
,
1681 &info2
->printername
);
1682 CHECK_ERROR(result
);
1684 result
= winreg_enumval_to_sz(info2
,
1688 CHECK_ERROR(result
);
1690 result
= winreg_enumval_to_sz(info2
,
1694 CHECK_ERROR(result
);
1696 result
= winreg_enumval_to_sz(info2
,
1700 CHECK_ERROR(result
);
1702 result
= winreg_enumval_to_sz(info2
,
1706 CHECK_ERROR(result
);
1708 result
= winreg_enumval_to_sz(info2
,
1712 CHECK_ERROR(result
);
1714 result
= winreg_enumval_to_sz(info2
,
1717 &info2
->printprocessor
);
1718 CHECK_ERROR(result
);
1720 result
= winreg_enumval_to_sz(info2
,
1724 CHECK_ERROR(result
);
1726 result
= winreg_enumval_to_sz(info2
,
1729 &info2
->parameters
);
1730 CHECK_ERROR(result
);
1732 result
= winreg_enumval_to_sz(info2
,
1735 &info2
->drivername
);
1736 CHECK_ERROR(result
);
1738 result
= winreg_enumval_to_dword(info2
,
1741 &info2
->attributes
);
1742 CHECK_ERROR(result
);
1744 result
= winreg_enumval_to_dword(info2
,
1748 CHECK_ERROR(result
);
1750 result
= winreg_enumval_to_dword(info2
,
1753 &info2
->defaultpriority
);
1754 CHECK_ERROR(result
);
1756 result
= winreg_enumval_to_dword(info2
,
1760 CHECK_ERROR(result
);
1762 result
= winreg_enumval_to_dword(info2
,
1766 CHECK_ERROR(result
);
1768 result
= winreg_enumval_to_dword(info2
,
1772 CHECK_ERROR(result
);
1774 result
= winreg_enumval_to_dword(info2
,
1778 CHECK_ERROR(result
);
1781 if (!W_ERROR_IS_OK(result
)) {
1782 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
1785 win_errstr(result
)));
1789 /* Construct the Device Mode */
1790 status
= dcerpc_winreg_query_binary(tmp_ctx
,
1796 if (!NT_STATUS_IS_OK(status
)) {
1797 result
= ntstatus_to_werror(status
);
1799 if (W_ERROR_IS_OK(result
)) {
1800 info2
->devmode
= talloc_zero(info2
, struct spoolss_DeviceMode
);
1801 if (info2
->devmode
== NULL
) {
1802 result
= WERR_NOMEM
;
1805 ndr_err
= ndr_pull_struct_blob(&blob
,
1808 (ndr_pull_flags_fn_t
) ndr_pull_spoolss_DeviceMode
);
1809 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1810 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
1811 result
= WERR_NOMEM
;
1816 if (info2
->devmode
== NULL
&& lp_default_devmode(snum
)) {
1817 result
= spoolss_create_default_devmode(info2
,
1820 if (!W_ERROR_IS_OK(result
)) {
1825 if (info2
->devmode
) {
1826 info2
->devmode
->size
= ndr_size_spoolss_DeviceMode(info2
->devmode
, 0) - info2
->devmode
->driverextra_data
.length
;
1829 result
= winreg_get_printer_secdesc(info2
,
1833 if (!W_ERROR_IS_OK(result
)) {
1837 /* Fix for OS/2 drivers. */
1838 if (get_remote_arch() == RA_OS2
) {
1839 spoolss_map_to_os2_driver(info2
, &info2
->drivername
);
1843 *pinfo2
= talloc_move(mem_ctx
, &info2
);
1848 if (winreg_handle
!= NULL
) {
1851 if (is_valid_policy_hnd(&key_hnd
)) {
1852 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1854 if (is_valid_policy_hnd(&hive_hnd
)) {
1855 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1859 TALLOC_FREE(tmp_ctx
);
1863 WERROR
winreg_get_printer_secdesc(TALLOC_CTX
*mem_ctx
,
1864 struct dcerpc_binding_handle
*winreg_handle
,
1865 const char *sharename
,
1866 struct spoolss_security_descriptor
**psecdesc
)
1868 struct spoolss_security_descriptor
*secdesc
;
1869 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1870 struct policy_handle hive_hnd
, key_hnd
;
1872 TALLOC_CTX
*tmp_ctx
;
1876 tmp_ctx
= talloc_stackframe();
1877 if (tmp_ctx
== NULL
) {
1881 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1883 talloc_free(tmp_ctx
);
1887 ZERO_STRUCT(hive_hnd
);
1888 ZERO_STRUCT(key_hnd
);
1890 result
= winreg_printer_openkey(tmp_ctx
,
1898 if (!W_ERROR_IS_OK(result
)) {
1899 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1900 goto create_default
;
1905 status
= dcerpc_winreg_query_sd(tmp_ctx
,
1911 if (!NT_STATUS_IS_OK(status
)) {
1912 result
= ntstatus_to_werror(status
);
1914 if (!W_ERROR_IS_OK(result
)) {
1915 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1916 goto create_default
;
1922 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1929 result
= winreg_printer_openkey(tmp_ctx
,
1937 if (!W_ERROR_IS_OK(result
)) {
1941 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1942 if (!W_ERROR_IS_OK(result
)) {
1946 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
1947 this security descriptor has been created when winbindd was
1948 down. Take ownership of security descriptor. */
1949 if (dom_sid_equal(secdesc
->owner_sid
, &global_sid_World
)) {
1950 struct dom_sid owner_sid
;
1952 /* Change sd owner to workgroup administrator */
1954 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid
)) {
1955 struct spoolss_security_descriptor
*new_secdesc
;
1959 sid_append_rid(&owner_sid
, DOMAIN_RID_ADMINISTRATOR
);
1961 new_secdesc
= make_sec_desc(tmp_ctx
,
1970 if (new_secdesc
== NULL
) {
1971 result
= WERR_NOMEM
;
1975 /* Swap with other one */
1976 secdesc
= new_secdesc
;
1980 status
= dcerpc_winreg_set_sd(tmp_ctx
,
1986 if (!NT_STATUS_IS_OK(status
)) {
1987 result
= ntstatus_to_werror(status
);
1989 if (!W_ERROR_IS_OK(result
)) {
1994 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1999 if (winreg_handle
!= NULL
) {
2002 if (is_valid_policy_hnd(&key_hnd
)) {
2003 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2005 if (is_valid_policy_hnd(&hive_hnd
)) {
2006 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2010 talloc_free(tmp_ctx
);
2014 WERROR
winreg_set_printer_secdesc(TALLOC_CTX
*mem_ctx
,
2015 struct dcerpc_binding_handle
*winreg_handle
,
2016 const char *sharename
,
2017 const struct spoolss_security_descriptor
*secdesc
)
2019 const struct spoolss_security_descriptor
*new_secdesc
= secdesc
;
2020 struct spoolss_security_descriptor
*old_secdesc
;
2021 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2022 struct policy_handle hive_hnd
, key_hnd
;
2024 TALLOC_CTX
*tmp_ctx
;
2028 tmp_ctx
= talloc_stackframe();
2029 if (tmp_ctx
== NULL
) {
2033 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
2035 talloc_free(tmp_ctx
);
2040 * The old owner and group sids of the security descriptor are not
2041 * present when new ACEs are added or removed by changing printer
2042 * permissions through NT. If they are NULL in the new security
2043 * descriptor then copy them over from the old one.
2045 if (!secdesc
->owner_sid
|| !secdesc
->group_sid
) {
2046 struct dom_sid
*owner_sid
, *group_sid
;
2047 struct security_acl
*dacl
, *sacl
;
2050 result
= winreg_get_printer_secdesc(tmp_ctx
,
2054 if (!W_ERROR_IS_OK(result
)) {
2055 talloc_free(tmp_ctx
);
2059 /* Pick out correct owner and group sids */
2060 owner_sid
= secdesc
->owner_sid
?
2061 secdesc
->owner_sid
:
2062 old_secdesc
->owner_sid
;
2064 group_sid
= secdesc
->group_sid
?
2065 secdesc
->group_sid
:
2066 old_secdesc
->group_sid
;
2068 dacl
= secdesc
->dacl
?
2072 sacl
= secdesc
->sacl
?
2076 /* Make a deep copy of the security descriptor */
2077 new_secdesc
= make_sec_desc(tmp_ctx
,
2085 if (new_secdesc
== NULL
) {
2086 talloc_free(tmp_ctx
);
2091 ZERO_STRUCT(hive_hnd
);
2092 ZERO_STRUCT(key_hnd
);
2094 result
= winreg_printer_openkey(tmp_ctx
,
2102 if (!W_ERROR_IS_OK(result
)) {
2106 status
= dcerpc_winreg_set_sd(tmp_ctx
,
2112 if (!NT_STATUS_IS_OK(status
)) {
2113 result
= ntstatus_to_werror(status
);
2117 if (winreg_handle
!= NULL
) {
2120 if (is_valid_policy_hnd(&key_hnd
)) {
2121 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2123 if (is_valid_policy_hnd(&hive_hnd
)) {
2124 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2128 talloc_free(tmp_ctx
);
2132 /* Set printer data over the winreg pipe. */
2133 WERROR
winreg_set_printer_dataex(TALLOC_CTX
*mem_ctx
,
2134 struct dcerpc_binding_handle
*winreg_handle
,
2135 const char *printer
,
2138 enum winreg_Type type
,
2142 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2143 struct policy_handle hive_hnd
, key_hnd
;
2144 struct winreg_String wvalue
= { 0, };
2146 WERROR result
= WERR_OK
;
2148 TALLOC_CTX
*tmp_ctx
;
2150 tmp_ctx
= talloc_stackframe();
2151 if (tmp_ctx
== NULL
) {
2155 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2157 TALLOC_FREE(tmp_ctx
);
2161 ZERO_STRUCT(hive_hnd
);
2162 ZERO_STRUCT(key_hnd
);
2164 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2165 key
, value
, access_mask
, printer
));
2166 result
= winreg_printer_openkey(tmp_ctx
,
2174 if (!W_ERROR_IS_OK(result
)) {
2175 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2176 key
, win_errstr(result
)));
2180 wvalue
.name
= value
;
2181 status
= dcerpc_winreg_SetValue(winreg_handle
,
2189 if (!NT_STATUS_IS_OK(status
)) {
2190 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2191 value
, nt_errstr(status
)));
2192 result
= ntstatus_to_werror(status
);
2196 if (winreg_handle
!= NULL
) {
2199 if (is_valid_policy_hnd(&key_hnd
)) {
2200 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2202 if (is_valid_policy_hnd(&hive_hnd
)) {
2203 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2207 TALLOC_FREE(tmp_ctx
);
2211 /* Get printer data over a winreg pipe. */
2212 WERROR
winreg_get_printer_dataex(TALLOC_CTX
*mem_ctx
,
2213 struct dcerpc_binding_handle
*winreg_handle
,
2214 const char *printer
,
2217 enum winreg_Type
*type
,
2219 uint32_t *data_size
)
2221 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2222 struct policy_handle hive_hnd
, key_hnd
;
2223 struct winreg_String wvalue
;
2224 enum winreg_Type type_in
= REG_NONE
;
2226 uint8_t *data_in
= NULL
;
2227 uint32_t data_in_size
= 0;
2228 uint32_t value_len
= 0;
2229 WERROR result
= WERR_OK
;
2231 TALLOC_CTX
*tmp_ctx
;
2233 tmp_ctx
= talloc_stackframe();
2234 if (tmp_ctx
== NULL
) {
2238 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2240 TALLOC_FREE(tmp_ctx
);
2244 ZERO_STRUCT(hive_hnd
);
2245 ZERO_STRUCT(key_hnd
);
2247 result
= winreg_printer_openkey(tmp_ctx
,
2255 if (!W_ERROR_IS_OK(result
)) {
2256 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2257 key
, win_errstr(result
)));
2261 wvalue
.name
= value
;
2264 * call QueryValue once with data == NULL to get the
2265 * needed memory size to be allocated, then allocate
2266 * data buffer and call again.
2268 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2277 if (!NT_STATUS_IS_OK(status
)) {
2278 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2279 value
, nt_errstr(status
)));
2280 result
= ntstatus_to_werror(status
);
2283 if (!W_ERROR_IS_OK(result
)) {
2287 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
2288 if (data_in
== NULL
) {
2289 result
= WERR_NOMEM
;
2294 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2303 if (!NT_STATUS_IS_OK(status
)) {
2304 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2305 value
, nt_errstr(status
)));
2306 result
= ntstatus_to_werror(status
);
2309 if (!W_ERROR_IS_OK(result
)) {
2314 *data_size
= data_in_size
;
2316 *data
= talloc_move(mem_ctx
, &data_in
);
2321 if (winreg_handle
!= NULL
) {
2324 if (is_valid_policy_hnd(&key_hnd
)) {
2325 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2327 if (is_valid_policy_hnd(&hive_hnd
)) {
2328 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2332 TALLOC_FREE(tmp_ctx
);
2336 /* Enumerate on the values of a given key and provide the data. */
2337 WERROR
winreg_enum_printer_dataex(TALLOC_CTX
*mem_ctx
,
2338 struct dcerpc_binding_handle
*winreg_handle
,
2339 const char *printer
,
2341 uint32_t *pnum_values
,
2342 struct spoolss_PrinterEnumValues
**penum_values
)
2344 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2345 struct policy_handle hive_hnd
, key_hnd
;
2347 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2348 uint32_t num_values
= 0;
2350 WERROR result
= WERR_OK
;
2352 TALLOC_CTX
*tmp_ctx
;
2354 tmp_ctx
= talloc_stackframe();
2355 if (tmp_ctx
== NULL
) {
2359 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2361 TALLOC_FREE(tmp_ctx
);
2365 result
= winreg_printer_openkey(tmp_ctx
,
2373 if (!W_ERROR_IS_OK(result
)) {
2374 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2375 key
, win_errstr(result
)));
2379 result
= winreg_printer_enumvalues(tmp_ctx
,
2384 if (!W_ERROR_IS_OK(result
)) {
2385 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2386 key
, win_errstr(result
)));
2390 *pnum_values
= num_values
;
2392 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
2397 if (winreg_handle
!= NULL
) {
2400 if (is_valid_policy_hnd(&key_hnd
)) {
2401 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2403 if (is_valid_policy_hnd(&hive_hnd
)) {
2404 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2408 TALLOC_FREE(tmp_ctx
);
2412 /* Delete printer data over a winreg pipe. */
2413 WERROR
winreg_delete_printer_dataex(TALLOC_CTX
*mem_ctx
,
2414 struct dcerpc_binding_handle
*winreg_handle
,
2415 const char *printer
,
2419 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2420 struct policy_handle hive_hnd
, key_hnd
;
2421 struct winreg_String wvalue
= { 0, };
2423 WERROR result
= WERR_OK
;
2426 TALLOC_CTX
*tmp_ctx
;
2428 tmp_ctx
= talloc_stackframe();
2429 if (tmp_ctx
== NULL
) {
2433 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2435 TALLOC_FREE(tmp_ctx
);
2439 ZERO_STRUCT(hive_hnd
);
2440 ZERO_STRUCT(key_hnd
);
2442 result
= winreg_printer_openkey(tmp_ctx
,
2450 if (!W_ERROR_IS_OK(result
)) {
2451 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2452 key
, win_errstr(result
)));
2456 wvalue
.name
= value
;
2457 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
2462 if (!NT_STATUS_IS_OK(status
)) {
2463 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2464 value
, nt_errstr(status
)));
2465 result
= ntstatus_to_werror(status
);
2469 if (winreg_handle
!= NULL
) {
2472 if (is_valid_policy_hnd(&key_hnd
)) {
2473 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2475 if (is_valid_policy_hnd(&hive_hnd
)) {
2476 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2480 TALLOC_FREE(tmp_ctx
);
2484 /* Enumerate on the subkeys of a given key and provide the data. */
2485 WERROR
winreg_enum_printer_key(TALLOC_CTX
*mem_ctx
,
2486 struct dcerpc_binding_handle
*winreg_handle
,
2487 const char *printer
,
2489 uint32_t *pnum_subkeys
,
2490 const char ***psubkeys
)
2492 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2493 struct policy_handle hive_hnd
, key_hnd
;
2495 const char **subkeys
= NULL
;
2496 uint32_t num_subkeys
= -1;
2498 WERROR result
= WERR_OK
;
2501 TALLOC_CTX
*tmp_ctx
;
2503 tmp_ctx
= talloc_stackframe();
2504 if (tmp_ctx
== NULL
) {
2508 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2510 TALLOC_FREE(tmp_ctx
);
2514 ZERO_STRUCT(hive_hnd
);
2515 ZERO_STRUCT(key_hnd
);
2517 result
= winreg_printer_openkey(tmp_ctx
,
2525 if (!W_ERROR_IS_OK(result
)) {
2526 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2527 key
, win_errstr(result
)));
2531 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
2537 if (!NT_STATUS_IS_OK(status
)) {
2538 result
= ntstatus_to_werror(status
);
2540 if (!W_ERROR_IS_OK(result
)) {
2541 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2542 key
, win_errstr(result
)));
2546 *pnum_subkeys
= num_subkeys
;
2548 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
2553 if (winreg_handle
!= NULL
) {
2556 if (is_valid_policy_hnd(&key_hnd
)) {
2557 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2559 if (is_valid_policy_hnd(&hive_hnd
)) {
2560 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2564 TALLOC_FREE(tmp_ctx
);
2568 /* Delete a key with subkeys of a given printer. */
2569 WERROR
winreg_delete_printer_key(TALLOC_CTX
*mem_ctx
,
2570 struct dcerpc_binding_handle
*winreg_handle
,
2571 const char *printer
,
2574 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2575 struct policy_handle hive_hnd
, key_hnd
;
2579 TALLOC_CTX
*tmp_ctx
;
2581 tmp_ctx
= talloc_stackframe();
2582 if (tmp_ctx
== NULL
) {
2586 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2588 TALLOC_FREE(tmp_ctx
);
2592 result
= winreg_printer_openkey(tmp_ctx
,
2600 if (!W_ERROR_IS_OK(result
)) {
2601 /* key doesn't exist */
2602 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2607 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2608 key
, win_errstr(result
)));
2612 if (is_valid_policy_hnd(&key_hnd
)) {
2613 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
2616 if (key
== NULL
|| key
[0] == '\0') {
2619 keyname
= talloc_asprintf(tmp_ctx
,
2623 if (keyname
== NULL
) {
2624 result
= WERR_NOMEM
;
2629 result
= winreg_printer_delete_subkeys(tmp_ctx
,
2634 if (!W_ERROR_IS_OK(result
)) {
2635 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2636 key
, win_errstr(result
)));
2641 if (winreg_handle
!= NULL
) {
2644 if (is_valid_policy_hnd(&key_hnd
)) {
2645 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2647 if (is_valid_policy_hnd(&hive_hnd
)) {
2648 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2652 TALLOC_FREE(tmp_ctx
);
2656 WERROR
winreg_printer_update_changeid(TALLOC_CTX
*mem_ctx
,
2657 struct dcerpc_binding_handle
*winreg_handle
,
2658 const char *printer
)
2660 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2661 struct policy_handle hive_hnd
, key_hnd
;
2665 TALLOC_CTX
*tmp_ctx
;
2667 tmp_ctx
= talloc_stackframe();
2668 if (tmp_ctx
== NULL
) {
2672 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2674 TALLOC_FREE(tmp_ctx
);
2678 ZERO_STRUCT(hive_hnd
);
2679 ZERO_STRUCT(key_hnd
);
2681 result
= winreg_printer_openkey(tmp_ctx
,
2689 if (!W_ERROR_IS_OK(result
)) {
2690 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2691 path
, win_errstr(result
)));
2695 status
= dcerpc_winreg_set_dword(tmp_ctx
,
2699 winreg_printer_rev_changeid(),
2701 if (!NT_STATUS_IS_OK(status
)) {
2702 result
= ntstatus_to_werror(status
);
2704 if (!W_ERROR_IS_OK(result
)) {
2710 if (winreg_handle
!= NULL
) {
2713 if (is_valid_policy_hnd(&key_hnd
)) {
2714 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2716 if (is_valid_policy_hnd(&hive_hnd
)) {
2717 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2721 TALLOC_FREE(tmp_ctx
);
2725 WERROR
winreg_printer_get_changeid(TALLOC_CTX
*mem_ctx
,
2726 struct dcerpc_binding_handle
*winreg_handle
,
2727 const char *printer
,
2728 uint32_t *pchangeid
)
2730 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2731 struct policy_handle hive_hnd
, key_hnd
;
2732 uint32_t changeid
= 0;
2736 TALLOC_CTX
*tmp_ctx
;
2738 tmp_ctx
= talloc_stackframe();
2739 if (tmp_ctx
== NULL
) {
2743 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2745 TALLOC_FREE(tmp_ctx
);
2749 ZERO_STRUCT(hive_hnd
);
2750 ZERO_STRUCT(key_hnd
);
2752 result
= winreg_printer_openkey(tmp_ctx
,
2760 if (!W_ERROR_IS_OK(result
)) {
2761 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2762 path
, win_errstr(result
)));
2766 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path
));
2768 status
= dcerpc_winreg_query_dword(tmp_ctx
,
2774 if (!NT_STATUS_IS_OK(status
)) {
2775 result
= ntstatus_to_werror(status
);
2777 if (!W_ERROR_IS_OK(result
)) {
2782 *pchangeid
= changeid
;
2787 if (winreg_handle
!= NULL
) {
2790 if (is_valid_policy_hnd(&key_hnd
)) {
2791 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2793 if (is_valid_policy_hnd(&hive_hnd
)) {
2794 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2798 TALLOC_FREE(tmp_ctx
);
2803 * The special behaviour of the spoolss forms is documented at the website:
2805 * Managing Win32 Printserver Forms
2806 * http://unixwiz.net/techtips/winspooler-forms.html
2809 WERROR
winreg_printer_addform1(TALLOC_CTX
*mem_ctx
,
2810 struct dcerpc_binding_handle
*winreg_handle
,
2811 struct spoolss_AddFormInfo1
*form
)
2813 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2814 struct policy_handle hive_hnd
, key_hnd
;
2815 struct winreg_String wvalue
= { 0, };
2817 uint32_t num_info
= 0;
2818 union spoolss_FormInfo
*info
= NULL
;
2822 TALLOC_CTX
*tmp_ctx
;
2824 tmp_ctx
= talloc_stackframe();
2825 if (tmp_ctx
== NULL
) {
2829 ZERO_STRUCT(hive_hnd
);
2830 ZERO_STRUCT(key_hnd
);
2832 result
= winreg_printer_openkey(tmp_ctx
,
2834 TOP_LEVEL_CONTROL_FORMS_KEY
,
2840 if (!W_ERROR_IS_OK(result
)) {
2841 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2842 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2846 result
= winreg_printer_enumforms1(tmp_ctx
, winreg_handle
,
2848 if (!W_ERROR_IS_OK(result
)) {
2849 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2850 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2854 /* If form name already exists or is builtin return ALREADY_EXISTS */
2855 for (i
= 0; i
< num_info
; i
++) {
2856 if (strequal(info
[i
].info1
.form_name
, form
->form_name
)) {
2857 result
= WERR_FILE_EXISTS
;
2862 wvalue
.name
= form
->form_name
;
2864 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
2865 SIVAL(blob
.data
, 0, form
->size
.width
);
2866 SIVAL(blob
.data
, 4, form
->size
.height
);
2867 SIVAL(blob
.data
, 8, form
->area
.left
);
2868 SIVAL(blob
.data
, 12, form
->area
.top
);
2869 SIVAL(blob
.data
, 16, form
->area
.right
);
2870 SIVAL(blob
.data
, 20, form
->area
.bottom
);
2871 SIVAL(blob
.data
, 24, num_info
+ 1); /* FIXME */
2872 SIVAL(blob
.data
, 28, form
->flags
);
2874 status
= dcerpc_winreg_SetValue(winreg_handle
,
2882 if (!NT_STATUS_IS_OK(status
)) {
2883 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2884 wvalue
.name
, nt_errstr(status
)));
2885 result
= ntstatus_to_werror(status
);
2889 if (winreg_handle
!= NULL
) {
2892 if (is_valid_policy_hnd(&key_hnd
)) {
2893 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2895 if (is_valid_policy_hnd(&hive_hnd
)) {
2896 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2901 TALLOC_FREE(tmp_ctx
);
2905 WERROR
winreg_printer_enumforms1(TALLOC_CTX
*mem_ctx
,
2906 struct dcerpc_binding_handle
*winreg_handle
,
2907 uint32_t *pnum_info
,
2908 union spoolss_FormInfo
**pinfo
)
2910 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2911 struct policy_handle hive_hnd
, key_hnd
;
2912 union spoolss_FormInfo
*info
;
2913 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2914 uint32_t num_values
= 0;
2915 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2918 TALLOC_CTX
*tmp_ctx
;
2920 tmp_ctx
= talloc_stackframe();
2921 if (tmp_ctx
== NULL
) {
2925 ZERO_STRUCT(hive_hnd
);
2926 ZERO_STRUCT(key_hnd
);
2928 result
= winreg_printer_openkey(tmp_ctx
,
2930 TOP_LEVEL_CONTROL_FORMS_KEY
,
2936 if (!W_ERROR_IS_OK(result
)) {
2937 /* key doesn't exist */
2938 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2943 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
2944 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2948 result
= winreg_printer_enumvalues(tmp_ctx
,
2953 if (!W_ERROR_IS_OK(result
)) {
2954 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2955 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2959 info
= talloc_array(tmp_ctx
, union spoolss_FormInfo
, num_builtin
+ num_values
);
2961 result
= WERR_NOMEM
;
2965 /* Enumerate BUILTIN forms */
2966 for (i
= 0; i
< num_builtin
; i
++) {
2967 info
[i
].info1
= builtin_forms1
[i
];
2970 /* Enumerate registry forms */
2971 for (i
= 0; i
< num_values
; i
++) {
2972 union spoolss_FormInfo val
;
2974 if (enum_values
[i
].type
!= REG_BINARY
||
2975 enum_values
[i
].data_length
!= 32) {
2979 val
.info1
.form_name
= talloc_strdup(info
, enum_values
[i
].value_name
);
2980 if (val
.info1
.form_name
== NULL
) {
2981 result
= WERR_NOMEM
;
2985 val
.info1
.size
.width
= IVAL(enum_values
[i
].data
->data
, 0);
2986 val
.info1
.size
.height
= IVAL(enum_values
[i
].data
->data
, 4);
2987 val
.info1
.area
.left
= IVAL(enum_values
[i
].data
->data
, 8);
2988 val
.info1
.area
.top
= IVAL(enum_values
[i
].data
->data
, 12);
2989 val
.info1
.area
.right
= IVAL(enum_values
[i
].data
->data
, 16);
2990 val
.info1
.area
.bottom
= IVAL(enum_values
[i
].data
->data
, 20);
2991 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
2992 val
.info1
.flags
= (enum spoolss_FormFlags
) IVAL(enum_values
[i
].data
->data
, 28);
2994 info
[i
+ num_builtin
] = val
;
2997 *pnum_info
= num_builtin
+ num_values
;
2999 *pinfo
= talloc_move(mem_ctx
, &info
);
3003 if (winreg_handle
!= NULL
) {
3006 if (is_valid_policy_hnd(&key_hnd
)) {
3007 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3009 if (is_valid_policy_hnd(&hive_hnd
)) {
3010 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3014 TALLOC_FREE(enum_values
);
3015 TALLOC_FREE(tmp_ctx
);
3019 WERROR
winreg_printer_deleteform1(TALLOC_CTX
*mem_ctx
,
3020 struct dcerpc_binding_handle
*winreg_handle
,
3021 const char *form_name
)
3023 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3024 struct policy_handle hive_hnd
, key_hnd
;
3025 struct winreg_String wvalue
= { 0, };
3026 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3028 WERROR result
= WERR_OK
;
3030 TALLOC_CTX
*tmp_ctx
;
3032 for (i
= 0; i
< num_builtin
; i
++) {
3033 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3034 return WERR_INVALID_PARAMETER
;
3038 tmp_ctx
= talloc_stackframe();
3039 if (tmp_ctx
== NULL
) {
3043 ZERO_STRUCT(hive_hnd
);
3044 ZERO_STRUCT(key_hnd
);
3046 result
= winreg_printer_openkey(tmp_ctx
,
3048 TOP_LEVEL_CONTROL_FORMS_KEY
,
3054 if (!W_ERROR_IS_OK(result
)) {
3055 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3056 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3057 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3058 result
= WERR_INVALID_FORM_NAME
;
3063 wvalue
.name
= form_name
;
3064 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
3069 if (!NT_STATUS_IS_OK(status
)) {
3070 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3071 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3072 wvalue
.name
, nt_errstr(status
)));
3073 result
= ntstatus_to_werror(status
);
3077 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3078 result
= WERR_INVALID_FORM_NAME
;
3082 if (winreg_handle
!= NULL
) {
3085 if (is_valid_policy_hnd(&key_hnd
)) {
3086 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3088 if (is_valid_policy_hnd(&hive_hnd
)) {
3089 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3093 TALLOC_FREE(tmp_ctx
);
3097 WERROR
winreg_printer_setform1(TALLOC_CTX
*mem_ctx
,
3098 struct dcerpc_binding_handle
*winreg_handle
,
3099 const char *form_name
,
3100 struct spoolss_AddFormInfo1
*form
)
3102 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3103 struct policy_handle hive_hnd
, key_hnd
;
3104 struct winreg_String wvalue
= { 0, };
3106 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3110 TALLOC_CTX
*tmp_ctx
= NULL
;
3112 for (i
= 0; i
< num_builtin
; i
++) {
3113 if (strequal(builtin_forms1
[i
].form_name
, form
->form_name
)) {
3114 result
= WERR_INVALID_PARAM
;
3119 tmp_ctx
= talloc_stackframe();
3120 if (tmp_ctx
== NULL
) {
3124 ZERO_STRUCT(hive_hnd
);
3125 ZERO_STRUCT(key_hnd
);
3127 result
= winreg_printer_openkey(tmp_ctx
,
3129 TOP_LEVEL_CONTROL_FORMS_KEY
,
3135 if (!W_ERROR_IS_OK(result
)) {
3136 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3137 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3141 /* If form_name != form->form_name then we renamed the form */
3142 if (strequal(form_name
, form
->form_name
)) {
3143 result
= winreg_printer_deleteform1(tmp_ctx
, winreg_handle
,
3145 if (!W_ERROR_IS_OK(result
)) {
3146 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3147 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3152 wvalue
.name
= form
->form_name
;
3154 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
3155 SIVAL(blob
.data
, 0, form
->size
.width
);
3156 SIVAL(blob
.data
, 4, form
->size
.height
);
3157 SIVAL(blob
.data
, 8, form
->area
.left
);
3158 SIVAL(blob
.data
, 12, form
->area
.top
);
3159 SIVAL(blob
.data
, 16, form
->area
.right
);
3160 SIVAL(blob
.data
, 20, form
->area
.bottom
);
3161 SIVAL(blob
.data
, 24, 42);
3162 SIVAL(blob
.data
, 28, form
->flags
);
3164 status
= dcerpc_winreg_SetValue(winreg_handle
,
3172 if (!NT_STATUS_IS_OK(status
)) {
3173 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3174 wvalue
.name
, nt_errstr(status
)));
3175 result
= ntstatus_to_werror(status
);
3179 if (winreg_handle
!= NULL
) {
3182 if (is_valid_policy_hnd(&key_hnd
)) {
3183 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3185 if (is_valid_policy_hnd(&hive_hnd
)) {
3186 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3190 TALLOC_FREE(tmp_ctx
);
3194 WERROR
winreg_printer_getform1(TALLOC_CTX
*mem_ctx
,
3195 struct dcerpc_binding_handle
*winreg_handle
,
3196 const char *form_name
,
3197 struct spoolss_FormInfo1
*r
)
3199 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3200 struct policy_handle hive_hnd
, key_hnd
;
3201 struct winreg_String wvalue
;
3202 enum winreg_Type type_in
= REG_NONE
;
3203 uint8_t *data_in
= NULL
;
3204 uint32_t data_in_size
= 0;
3205 uint32_t value_len
= 0;
3206 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3210 TALLOC_CTX
*tmp_ctx
;
3212 /* check builtin forms first */
3213 for (i
= 0; i
< num_builtin
; i
++) {
3214 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3215 *r
= builtin_forms1
[i
];
3220 tmp_ctx
= talloc_stackframe();
3221 if (tmp_ctx
== NULL
) {
3225 ZERO_STRUCT(hive_hnd
);
3226 ZERO_STRUCT(key_hnd
);
3228 result
= winreg_printer_openkey(tmp_ctx
,
3230 TOP_LEVEL_CONTROL_FORMS_KEY
,
3236 if (!W_ERROR_IS_OK(result
)) {
3237 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3238 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3242 wvalue
.name
= form_name
;
3245 * call QueryValue once with data == NULL to get the
3246 * needed memory size to be allocated, then allocate
3247 * data buffer and call again.
3249 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3258 if (!NT_STATUS_IS_OK(status
)) {
3259 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3260 wvalue
.name
, nt_errstr(status
)));
3261 result
= ntstatus_to_werror(status
);
3264 if (!W_ERROR_IS_OK(result
)) {
3268 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
3269 if (data_in
== NULL
) {
3270 result
= WERR_NOMEM
;
3275 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3284 if (!NT_STATUS_IS_OK(status
)) {
3285 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3286 wvalue
.name
, nt_errstr(status
)));
3287 result
= ntstatus_to_werror(status
);
3290 if (!W_ERROR_IS_OK(result
)) {
3294 r
->form_name
= talloc_strdup(mem_ctx
, form_name
);
3295 if (r
->form_name
== NULL
) {
3296 result
= WERR_NOMEM
;
3300 r
->size
.width
= IVAL(data_in
, 0);
3301 r
->size
.height
= IVAL(data_in
, 4);
3302 r
->area
.left
= IVAL(data_in
, 8);
3303 r
->area
.top
= IVAL(data_in
, 12);
3304 r
->area
.right
= IVAL(data_in
, 16);
3305 r
->area
.bottom
= IVAL(data_in
, 20);
3306 /* skip index IVAL(data_in, 24)));*/
3307 r
->flags
= (enum spoolss_FormFlags
) IVAL(data_in
, 28);
3311 if (winreg_handle
!= NULL
) {
3314 if (is_valid_policy_hnd(&key_hnd
)) {
3315 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3317 if (is_valid_policy_hnd(&hive_hnd
)) {
3318 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3322 TALLOC_FREE(tmp_ctx
);
3326 WERROR
winreg_add_driver(TALLOC_CTX
*mem_ctx
,
3327 struct dcerpc_binding_handle
*winreg_handle
,
3328 struct spoolss_AddDriverInfoCtr
*r
,
3329 const char **driver_name
,
3330 uint32_t *driver_version
)
3332 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3333 struct policy_handle hive_hnd
, key_hnd
;
3334 struct spoolss_DriverInfo8 info8
;
3335 TALLOC_CTX
*tmp_ctx
= NULL
;
3339 ZERO_STRUCT(hive_hnd
);
3340 ZERO_STRUCT(key_hnd
);
3343 if (!driver_info_ctr_to_info8(r
, &info8
)) {
3344 result
= WERR_INVALID_PARAMETER
;
3348 tmp_ctx
= talloc_stackframe();
3349 if (tmp_ctx
== NULL
) {
3353 result
= winreg_printer_opendriver(tmp_ctx
,
3361 if (!W_ERROR_IS_OK(result
)) {
3362 DEBUG(0, ("winreg_add_driver: "
3363 "Could not open driver key (%s,%s,%d): %s\n",
3364 info8
.driver_name
, info8
.architecture
,
3365 info8
.version
, win_errstr(result
)));
3369 /* TODO: "Attributes" ? */
3371 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3377 if (!NT_STATUS_IS_OK(status
)) {
3378 result
= ntstatus_to_werror(status
);
3380 if (!W_ERROR_IS_OK(result
)) {
3384 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3390 if (!NT_STATUS_IS_OK(status
)) {
3391 result
= ntstatus_to_werror(status
);
3393 if (!W_ERROR_IS_OK(result
)) {
3397 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3403 if (!NT_STATUS_IS_OK(status
)) {
3404 result
= ntstatus_to_werror(status
);
3406 if (!W_ERROR_IS_OK(result
)) {
3410 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3413 "Configuration File",
3416 if (!NT_STATUS_IS_OK(status
)) {
3417 result
= ntstatus_to_werror(status
);
3419 if (!W_ERROR_IS_OK(result
)) {
3423 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3429 if (!NT_STATUS_IS_OK(status
)) {
3430 result
= ntstatus_to_werror(status
);
3432 if (!W_ERROR_IS_OK(result
)) {
3436 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3440 info8
.dependent_files
,
3442 if (!NT_STATUS_IS_OK(status
)) {
3443 result
= ntstatus_to_werror(status
);
3445 if (!W_ERROR_IS_OK(result
)) {
3449 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3455 if (!NT_STATUS_IS_OK(status
)) {
3456 result
= ntstatus_to_werror(status
);
3458 if (!W_ERROR_IS_OK(result
)) {
3462 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3466 info8
.default_datatype
,
3468 if (!NT_STATUS_IS_OK(status
)) {
3469 result
= ntstatus_to_werror(status
);
3471 if (!W_ERROR_IS_OK(result
)) {
3475 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3477 &key_hnd
, "Previous Names",
3478 info8
.previous_names
,
3480 if (!NT_STATUS_IS_OK(status
)) {
3481 result
= ntstatus_to_werror(status
);
3483 if (!W_ERROR_IS_OK(result
)) {
3487 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3488 &key_hnd
, "DriverDate",
3490 if (!W_ERROR_IS_OK(result
)) {
3494 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
,
3495 &key_hnd
, "DriverVersion",
3496 info8
.driver_version
);
3497 if (!W_ERROR_IS_OK(result
)) {
3501 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3505 info8
.manufacturer_name
,
3507 if (!NT_STATUS_IS_OK(status
)) {
3508 result
= ntstatus_to_werror(status
);
3510 if (!W_ERROR_IS_OK(result
)) {
3514 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3518 info8
.manufacturer_url
,
3520 if (!NT_STATUS_IS_OK(status
)) {
3521 result
= ntstatus_to_werror(status
);
3523 if (!W_ERROR_IS_OK(result
)) {
3527 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3533 if (!NT_STATUS_IS_OK(status
)) {
3534 result
= ntstatus_to_werror(status
);
3536 if (!W_ERROR_IS_OK(result
)) {
3540 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3546 if (!NT_STATUS_IS_OK(status
)) {
3547 result
= ntstatus_to_werror(status
);
3549 if (!W_ERROR_IS_OK(result
)) {
3553 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3557 info8
.print_processor
,
3559 if (!NT_STATUS_IS_OK(status
)) {
3560 result
= ntstatus_to_werror(status
);
3562 if (!W_ERROR_IS_OK(result
)) {
3566 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3572 if (!NT_STATUS_IS_OK(status
)) {
3573 result
= ntstatus_to_werror(status
);
3575 if (!W_ERROR_IS_OK(result
)) {
3579 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3583 info8
.color_profiles
,
3585 if (!NT_STATUS_IS_OK(status
)) {
3586 result
= ntstatus_to_werror(status
);
3588 if (!W_ERROR_IS_OK(result
)) {
3592 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3598 if (!NT_STATUS_IS_OK(status
)) {
3599 result
= ntstatus_to_werror(status
);
3601 if (!W_ERROR_IS_OK(result
)) {
3605 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3608 "PrinterDriverAttributes",
3609 info8
.printer_driver_attributes
,
3611 if (!NT_STATUS_IS_OK(status
)) {
3612 result
= ntstatus_to_werror(status
);
3614 if (!W_ERROR_IS_OK(result
)) {
3618 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3622 info8
.core_driver_dependencies
,
3624 if (!NT_STATUS_IS_OK(status
)) {
3625 result
= ntstatus_to_werror(status
);
3627 if (!W_ERROR_IS_OK(result
)) {
3631 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3632 &key_hnd
, "MinInboxDriverVerDate",
3633 info8
.min_inbox_driver_ver_date
);
3634 if (!W_ERROR_IS_OK(result
)) {
3638 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
, &key_hnd
,
3639 "MinInboxDriverVerVersion",
3640 info8
.min_inbox_driver_ver_version
);
3641 if (!W_ERROR_IS_OK(result
)) {
3645 *driver_name
= info8
.driver_name
;
3646 *driver_version
= info8
.version
;
3649 if (winreg_handle
!= NULL
) {
3652 if (is_valid_policy_hnd(&key_hnd
)) {
3653 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3655 if (is_valid_policy_hnd(&hive_hnd
)) {
3656 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3660 TALLOC_FREE(tmp_ctx
);
3664 WERROR
winreg_get_driver(TALLOC_CTX
*mem_ctx
,
3665 struct dcerpc_binding_handle
*winreg_handle
,
3666 const char *architecture
,
3667 const char *driver_name
,
3668 uint32_t driver_version
,
3669 struct spoolss_DriverInfo8
**_info8
)
3671 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3672 struct policy_handle hive_hnd
, key_hnd
;
3673 struct spoolss_DriverInfo8 i8
, *info8
;
3674 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
3675 struct spoolss_PrinterEnumValues
*v
;
3676 uint32_t num_values
= 0;
3677 TALLOC_CTX
*tmp_ctx
;
3681 ZERO_STRUCT(hive_hnd
);
3682 ZERO_STRUCT(key_hnd
);
3685 tmp_ctx
= talloc_stackframe();
3686 if (tmp_ctx
== NULL
) {
3690 if (driver_version
== DRIVER_ANY_VERSION
) {
3691 /* look for Win2k first and then for NT4 */
3692 result
= winreg_printer_opendriver(tmp_ctx
,
3700 if (!W_ERROR_IS_OK(result
)) {
3701 result
= winreg_printer_opendriver(tmp_ctx
,
3711 /* ok normal case */
3712 result
= winreg_printer_opendriver(tmp_ctx
,
3721 if (!W_ERROR_IS_OK(result
)) {
3722 DEBUG(5, ("winreg_get_driver: "
3723 "Could not open driver key (%s,%s,%d): %s\n",
3724 driver_name
, architecture
,
3725 driver_version
, win_errstr(result
)));
3729 result
= winreg_printer_enumvalues(tmp_ctx
,
3734 if (!W_ERROR_IS_OK(result
)) {
3735 DEBUG(0, ("winreg_get_driver: "
3736 "Could not enumerate values for (%s,%s,%d): %s\n",
3737 driver_name
, architecture
,
3738 driver_version
, win_errstr(result
)));
3742 info8
= talloc_zero(tmp_ctx
, struct spoolss_DriverInfo8
);
3743 if (info8
== NULL
) {
3744 result
= WERR_NOMEM
;
3748 info8
->driver_name
= talloc_strdup(info8
, driver_name
);
3749 if (info8
->driver_name
== NULL
) {
3750 result
= WERR_NOMEM
;
3754 info8
->architecture
= talloc_strdup(info8
, architecture
);
3755 if (info8
->architecture
== NULL
) {
3756 result
= WERR_NOMEM
;
3762 for (i
= 0; i
< num_values
; i
++) {
3763 const char *tmp_str
;
3766 v
= &enum_values
[i
];
3768 result
= winreg_enumval_to_dword(info8
, v
,
3771 if (NT_STATUS_IS_OK(result
)) {
3772 info8
->version
= (enum spoolss_DriverOSVersion
) tmp
;
3774 CHECK_ERROR(result
);
3776 result
= winreg_enumval_to_sz(info8
, v
,
3778 &info8
->driver_path
);
3779 CHECK_ERROR(result
);
3781 result
= winreg_enumval_to_sz(info8
, v
,
3784 CHECK_ERROR(result
);
3786 result
= winreg_enumval_to_sz(info8
, v
,
3787 "Configuration File",
3788 &info8
->config_file
);
3789 CHECK_ERROR(result
);
3791 result
= winreg_enumval_to_sz(info8
, v
,
3794 CHECK_ERROR(result
);
3796 result
= winreg_enumval_to_multi_sz(info8
, v
,
3798 &info8
->dependent_files
);
3799 CHECK_ERROR(result
);
3801 result
= winreg_enumval_to_sz(info8
, v
,
3803 &info8
->monitor_name
);
3804 CHECK_ERROR(result
);
3806 result
= winreg_enumval_to_sz(info8
, v
,
3808 &info8
->default_datatype
);
3809 CHECK_ERROR(result
);
3811 result
= winreg_enumval_to_multi_sz(info8
, v
,
3813 &info8
->previous_names
);
3814 CHECK_ERROR(result
);
3816 result
= winreg_enumval_to_sz(info8
, v
,
3819 if (W_ERROR_IS_OK(result
)) {
3820 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3821 &info8
->driver_date
);
3823 CHECK_ERROR(result
);
3825 result
= winreg_enumval_to_sz(info8
, v
,
3828 if (W_ERROR_IS_OK(result
)) {
3829 result
= winreg_printer_ver_to_dword(tmp_str
,
3830 &info8
->driver_version
);
3832 CHECK_ERROR(result
);
3834 result
= winreg_enumval_to_sz(info8
, v
,
3836 &info8
->manufacturer_name
);
3837 CHECK_ERROR(result
);
3839 result
= winreg_enumval_to_sz(info8
, v
,
3841 &info8
->manufacturer_url
);
3842 CHECK_ERROR(result
);
3844 result
= winreg_enumval_to_sz(info8
, v
,
3846 &info8
->hardware_id
);
3847 CHECK_ERROR(result
);
3849 result
= winreg_enumval_to_sz(info8
, v
,
3852 CHECK_ERROR(result
);
3854 result
= winreg_enumval_to_sz(info8
, v
,
3856 &info8
->print_processor
);
3857 CHECK_ERROR(result
);
3859 result
= winreg_enumval_to_sz(info8
, v
,
3861 &info8
->vendor_setup
);
3862 CHECK_ERROR(result
);
3864 result
= winreg_enumval_to_multi_sz(info8
, v
,
3866 &info8
->color_profiles
);
3867 CHECK_ERROR(result
);
3869 result
= winreg_enumval_to_sz(info8
, v
,
3872 CHECK_ERROR(result
);
3874 result
= winreg_enumval_to_dword(info8
, v
,
3875 "PrinterDriverAttributes",
3876 &info8
->printer_driver_attributes
);
3877 CHECK_ERROR(result
);
3879 result
= winreg_enumval_to_multi_sz(info8
, v
,
3881 &info8
->core_driver_dependencies
);
3882 CHECK_ERROR(result
);
3884 result
= winreg_enumval_to_sz(info8
, v
,
3885 "MinInboxDriverVerDate",
3887 if (W_ERROR_IS_OK(result
)) {
3888 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3889 &info8
->min_inbox_driver_ver_date
);
3891 CHECK_ERROR(result
);
3893 result
= winreg_enumval_to_sz(info8
, v
,
3894 "MinInboxDriverVerVersion",
3896 if (W_ERROR_IS_OK(result
)) {
3897 result
= winreg_printer_ver_to_dword(tmp_str
,
3898 &info8
->min_inbox_driver_ver_version
);
3900 CHECK_ERROR(result
);
3903 if (!W_ERROR_IS_OK(result
)) {
3904 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3905 "for %s: %s\n", v
->value_name
,
3906 win_errstr(result
)));
3910 *_info8
= talloc_steal(mem_ctx
, info8
);
3913 if (winreg_handle
!= NULL
) {
3916 if (is_valid_policy_hnd(&key_hnd
)) {
3917 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3919 if (is_valid_policy_hnd(&hive_hnd
)) {
3920 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3924 TALLOC_FREE(tmp_ctx
);
3928 WERROR
winreg_del_driver(TALLOC_CTX
*mem_ctx
,
3929 struct dcerpc_binding_handle
*winreg_handle
,
3930 struct spoolss_DriverInfo8
*info8
,
3933 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3934 struct policy_handle hive_hnd
, key_hnd
;
3935 TALLOC_CTX
*tmp_ctx
;
3939 ZERO_STRUCT(hive_hnd
);
3940 ZERO_STRUCT(key_hnd
);
3942 tmp_ctx
= talloc_stackframe();
3943 if (tmp_ctx
== NULL
) {
3947 /* test that the key exists */
3948 result
= winreg_printer_opendriver(tmp_ctx
,
3951 info8
->architecture
,
3956 if (!W_ERROR_IS_OK(result
)) {
3957 /* key doesn't exist */
3958 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3963 DEBUG(5, ("winreg_del_driver: "
3964 "Could not open driver (%s,%s,%u): %s\n",
3965 info8
->driver_name
, info8
->architecture
,
3966 version
, win_errstr(result
)));
3971 if (is_valid_policy_hnd(&key_hnd
)) {
3972 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
3975 key_name
= talloc_asprintf(tmp_ctx
,
3976 "%s\\Environments\\%s\\Drivers\\Version-%u\\%s",
3977 TOP_LEVEL_CONTROL_KEY
,
3978 info8
->architecture
, version
,
3979 info8
->driver_name
);
3980 if (key_name
== NULL
) {
3981 result
= WERR_NOMEM
;
3985 result
= winreg_printer_delete_subkeys(tmp_ctx
,
3990 if (!W_ERROR_IS_OK(result
)) {
3991 DEBUG(0, ("winreg_del_driver: "
3992 "Could not open driver (%s,%s,%u): %s\n",
3993 info8
->driver_name
, info8
->architecture
,
3994 version
, win_errstr(result
)));
4000 if (winreg_handle
!= NULL
) {
4003 if (is_valid_policy_hnd(&key_hnd
)) {
4004 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4006 if (is_valid_policy_hnd(&hive_hnd
)) {
4007 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4011 TALLOC_FREE(tmp_ctx
);
4015 WERROR
winreg_get_driver_list(TALLOC_CTX
*mem_ctx
,
4016 struct dcerpc_binding_handle
*winreg_handle
,
4017 const char *architecture
,
4019 uint32_t *num_drivers
,
4020 const char ***drivers_p
)
4022 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4023 struct policy_handle hive_hnd
, key_hnd
;
4024 const char **drivers
;
4025 TALLOC_CTX
*tmp_ctx
;
4032 ZERO_STRUCT(hive_hnd
);
4033 ZERO_STRUCT(key_hnd
);
4035 tmp_ctx
= talloc_stackframe();
4036 if (tmp_ctx
== NULL
) {
4040 /* use NULL for the driver name so we open the key that is
4041 * parent of all drivers for this architecture and version */
4042 result
= winreg_printer_opendriver(tmp_ctx
,
4050 if (!W_ERROR_IS_OK(result
)) {
4051 DEBUG(5, ("winreg_get_driver_list: "
4052 "Could not open key (%s,%u): %s\n",
4053 architecture
, version
, win_errstr(result
)));
4058 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
4064 if (!NT_STATUS_IS_OK(status
)) {
4065 result
= ntstatus_to_werror(status
);
4067 if (!W_ERROR_IS_OK(result
)) {
4068 DEBUG(0, ("winreg_get_driver_list: "
4069 "Could not enumerate drivers for (%s,%u): %s\n",
4070 architecture
, version
, win_errstr(result
)));
4074 *drivers_p
= talloc_steal(mem_ctx
, drivers
);
4078 if (winreg_handle
!= NULL
) {
4081 if (is_valid_policy_hnd(&key_hnd
)) {
4082 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4084 if (is_valid_policy_hnd(&hive_hnd
)) {
4085 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4089 TALLOC_FREE(tmp_ctx
);