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_PRINT_PACKAGEINSTALLATION_KEY TOP_LEVEL_PRINT_KEY "\\PackageInstallation"
38 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
39 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
41 #define EMPTY_STRING ""
43 #define FILL_STRING(mem_ctx, in, out) \
45 if (in && strlen(in)) { \
46 out = talloc_strdup(mem_ctx, in); \
48 out = talloc_strdup(mem_ctx, ""); \
50 W_ERROR_HAVE_NO_MEMORY(out); \
53 #define CHECK_ERROR(result) \
54 if (W_ERROR_IS_OK(result)) continue; \
55 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
56 if (!W_ERROR_IS_OK(result)) break
58 /* FLAGS, NAME, with, height, left, top, right, bottom */
59 static const struct spoolss_FormInfo1 builtin_forms1
[] = {
60 { SPOOLSS_FORM_BUILTIN
, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
61 { SPOOLSS_FORM_BUILTIN
, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
62 { SPOOLSS_FORM_BUILTIN
, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
63 { SPOOLSS_FORM_BUILTIN
, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
64 { SPOOLSS_FORM_BUILTIN
, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
65 { SPOOLSS_FORM_BUILTIN
, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
66 { SPOOLSS_FORM_BUILTIN
, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
67 { SPOOLSS_FORM_BUILTIN
, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
68 { SPOOLSS_FORM_BUILTIN
, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
69 { SPOOLSS_FORM_BUILTIN
, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
70 { SPOOLSS_FORM_BUILTIN
, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
71 { SPOOLSS_FORM_BUILTIN
, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
72 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
73 { SPOOLSS_FORM_BUILTIN
, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
74 { SPOOLSS_FORM_BUILTIN
, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
75 { SPOOLSS_FORM_BUILTIN
, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
76 { SPOOLSS_FORM_BUILTIN
, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
77 { SPOOLSS_FORM_BUILTIN
, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
78 { SPOOLSS_FORM_BUILTIN
, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
79 { SPOOLSS_FORM_BUILTIN
, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
80 { SPOOLSS_FORM_BUILTIN
, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
81 { SPOOLSS_FORM_BUILTIN
, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
82 { SPOOLSS_FORM_BUILTIN
, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
83 { SPOOLSS_FORM_BUILTIN
, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
84 { SPOOLSS_FORM_BUILTIN
, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
85 { SPOOLSS_FORM_BUILTIN
, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
86 { SPOOLSS_FORM_BUILTIN
, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
87 { SPOOLSS_FORM_BUILTIN
, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
88 { SPOOLSS_FORM_BUILTIN
, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
89 { SPOOLSS_FORM_BUILTIN
, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
90 { SPOOLSS_FORM_BUILTIN
, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
91 { SPOOLSS_FORM_BUILTIN
, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
92 { SPOOLSS_FORM_BUILTIN
, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
93 { SPOOLSS_FORM_BUILTIN
, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
94 { SPOOLSS_FORM_BUILTIN
, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
95 { SPOOLSS_FORM_BUILTIN
, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
96 { SPOOLSS_FORM_BUILTIN
, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
97 { SPOOLSS_FORM_BUILTIN
, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
98 { SPOOLSS_FORM_BUILTIN
, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} },
99 { SPOOLSS_FORM_BUILTIN
, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
100 { SPOOLSS_FORM_BUILTIN
, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
101 { SPOOLSS_FORM_BUILTIN
, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
102 { SPOOLSS_FORM_BUILTIN
, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
103 { SPOOLSS_FORM_BUILTIN
, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
104 { SPOOLSS_FORM_BUILTIN
, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
105 { SPOOLSS_FORM_BUILTIN
, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
106 { SPOOLSS_FORM_BUILTIN
, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
107 { SPOOLSS_FORM_BUILTIN
, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
108 { SPOOLSS_FORM_BUILTIN
, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
109 { SPOOLSS_FORM_BUILTIN
, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
110 { SPOOLSS_FORM_BUILTIN
, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
111 { SPOOLSS_FORM_BUILTIN
, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
112 { SPOOLSS_FORM_BUILTIN
, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
113 { SPOOLSS_FORM_BUILTIN
, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
114 { SPOOLSS_FORM_BUILTIN
, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
115 { SPOOLSS_FORM_BUILTIN
, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
116 { SPOOLSS_FORM_BUILTIN
, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
117 { SPOOLSS_FORM_BUILTIN
, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
118 { SPOOLSS_FORM_BUILTIN
, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
119 { SPOOLSS_FORM_BUILTIN
, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
120 { SPOOLSS_FORM_BUILTIN
, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
121 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
122 { SPOOLSS_FORM_BUILTIN
, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
123 { SPOOLSS_FORM_BUILTIN
, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
124 { SPOOLSS_FORM_BUILTIN
, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
125 { SPOOLSS_FORM_BUILTIN
, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
126 { SPOOLSS_FORM_BUILTIN
, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
127 { SPOOLSS_FORM_BUILTIN
, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
128 { SPOOLSS_FORM_BUILTIN
, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
129 { SPOOLSS_FORM_BUILTIN
, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
130 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
131 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
132 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
133 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
134 { SPOOLSS_FORM_BUILTIN
, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
135 { SPOOLSS_FORM_BUILTIN
, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
136 { SPOOLSS_FORM_BUILTIN
, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
137 { SPOOLSS_FORM_BUILTIN
, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
138 { SPOOLSS_FORM_BUILTIN
, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
139 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
140 { SPOOLSS_FORM_BUILTIN
, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
141 { SPOOLSS_FORM_BUILTIN
, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
142 { SPOOLSS_FORM_BUILTIN
, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
143 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
144 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
145 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
146 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
147 { SPOOLSS_FORM_BUILTIN
, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
148 { SPOOLSS_FORM_BUILTIN
, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
149 { SPOOLSS_FORM_BUILTIN
, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
150 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
151 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
152 { SPOOLSS_FORM_BUILTIN
, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
153 { SPOOLSS_FORM_BUILTIN
, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
154 { SPOOLSS_FORM_BUILTIN
, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
155 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
156 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
157 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
158 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
159 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
160 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
161 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
162 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
163 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
164 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
165 { SPOOLSS_FORM_BUILTIN
, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
166 { SPOOLSS_FORM_BUILTIN
, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
167 { SPOOLSS_FORM_BUILTIN
, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
168 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
169 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
170 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
171 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
172 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
173 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
174 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
175 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
176 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
177 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} }
180 /********************************************************************
181 static helper functions
182 ********************************************************************/
184 /****************************************************************************
185 Update the changeid time.
186 ****************************************************************************/
190 * @brief Update the ChangeID time of a printer.
192 * This is SO NASTY as some drivers need this to change, others need it
193 * static. This value will change every second, and I must hope that this
194 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
197 * @return The ChangeID.
199 static uint32_t winreg_printer_rev_changeid(void)
203 get_process_uptime(&tv
);
206 /* Return changeid as msec since spooler restart */
207 return tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
210 * This setting seems to work well but is too untested
211 * to replace the above calculation. Left in for experimentation
212 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
214 return tv
.tv_sec
* 10 + tv
.tv_usec
/ 100000;
218 static WERROR
winreg_printer_openkey(TALLOC_CTX
*mem_ctx
,
219 struct dcerpc_binding_handle
*binding_handle
,
223 uint32_t access_mask
,
224 struct policy_handle
*hive_handle
,
225 struct policy_handle
*key_handle
)
227 struct winreg_String wkey
, wkeyclass
;
230 WERROR result
= WERR_OK
;
232 status
= dcerpc_winreg_OpenHKLM(binding_handle
,
238 if (!NT_STATUS_IS_OK(status
)) {
239 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
241 return ntstatus_to_werror(status
);
243 if (!W_ERROR_IS_OK(result
)) {
244 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
245 win_errstr(result
)));
250 keyname
= talloc_asprintf(mem_ctx
, "%s\\%s", path
, key
);
252 keyname
= talloc_strdup(mem_ctx
, path
);
254 if (keyname
== NULL
) {
255 return WERR_NOT_ENOUGH_MEMORY
;
262 enum winreg_CreateAction action
= REG_ACTION_NONE
;
264 ZERO_STRUCT(wkeyclass
);
267 status
= dcerpc_winreg_CreateKey(binding_handle
,
279 case REG_ACTION_NONE
:
280 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
282 case REG_CREATED_NEW_KEY
:
283 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname
));
285 case REG_OPENED_EXISTING_KEY
:
286 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname
));
290 status
= dcerpc_winreg_OpenKey(binding_handle
,
299 if (!NT_STATUS_IS_OK(status
)) {
300 result
= ntstatus_to_werror(status
);
302 if (!W_ERROR_IS_OK(result
)) {
305 if (is_valid_policy_hnd(hive_handle
)) {
306 dcerpc_winreg_CloseKey(binding_handle
,
311 ZERO_STRUCTP(hive_handle
);
319 static WERROR
winreg_printer_open_core_driver(TALLOC_CTX
*mem_ctx
,
320 struct dcerpc_binding_handle
*binding_handle
,
321 const char *architecture
,
323 uint32_t access_mask
,
324 struct policy_handle
*hive_handle
,
325 struct policy_handle
*key_handle
)
327 struct winreg_String wkey
, wkeyclass
;
329 WERROR result
= WERR_OK
;
331 enum winreg_CreateAction action
= REG_ACTION_NONE
;
334 status
= dcerpc_winreg_OpenHKLM(binding_handle
,
340 if (!NT_STATUS_IS_OK(status
)) {
341 DEBUG(0,("winreg_printer_open_core_driver: Could not open HKLM hive: %s\n",
343 return ntstatus_to_werror(status
);
345 if (!W_ERROR_IS_OK(result
)) {
346 DEBUG(0,("winreg_printer_open_core_driver: Could not open HKLM hive: %s\n",
347 win_errstr(result
)));
352 wkey
.name
= TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY
;
354 ZERO_STRUCT(wkeyclass
);
357 status
= dcerpc_winreg_CreateKey(binding_handle
,
368 if (!NT_STATUS_IS_OK(status
)) {
369 result
= ntstatus_to_werror(status
);
371 if (!W_ERROR_IS_OK(result
)) {
375 dcerpc_winreg_CloseKey(binding_handle
, mem_ctx
, key_handle
, &ignore
);
377 path
= talloc_asprintf(mem_ctx
, "%s\\%s",
378 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY
,
381 result
= WERR_NOT_ENOUGH_MEMORY
;
387 status
= dcerpc_winreg_CreateKey(binding_handle
,
398 if (!NT_STATUS_IS_OK(status
)) {
399 result
= ntstatus_to_werror(status
);
401 if (!W_ERROR_IS_OK(result
)) {
405 dcerpc_winreg_CloseKey(binding_handle
, mem_ctx
, key_handle
, &ignore
);
407 path
= talloc_asprintf(mem_ctx
, "%s\\%s\\CorePrinterDrivers",
408 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY
,
411 result
= WERR_NOT_ENOUGH_MEMORY
;
417 status
= dcerpc_winreg_CreateKey(binding_handle
,
428 if (!NT_STATUS_IS_OK(status
)) {
429 result
= ntstatus_to_werror(status
);
431 if (!W_ERROR_IS_OK(result
)) {
435 dcerpc_winreg_CloseKey(binding_handle
, mem_ctx
, key_handle
, &ignore
);
437 path
= talloc_asprintf(mem_ctx
, "%s\\%s\\CorePrinterDrivers\\%s",
438 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY
,
442 result
= WERR_NOT_ENOUGH_MEMORY
;
448 status
= dcerpc_winreg_CreateKey(binding_handle
,
459 if (!NT_STATUS_IS_OK(status
)) {
460 result
= ntstatus_to_werror(status
);
462 if (!W_ERROR_IS_OK(result
)) {
467 if (is_valid_policy_hnd(hive_handle
)) {
468 dcerpc_winreg_CloseKey(binding_handle
,
473 ZERO_STRUCTP(hive_handle
);
479 * @brief Create the registry keyname for the given printer.
481 * @param[in] mem_ctx The memory context to use.
483 * @param[in] printer The name of the printer to get the registry key.
485 * @return The registry key or NULL on error.
487 static char *winreg_printer_data_keyname(TALLOC_CTX
*mem_ctx
, const char *printer
) {
488 return talloc_asprintf(mem_ctx
, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY
, printer
);
491 static WERROR
winreg_printer_opendriver(TALLOC_CTX
*mem_ctx
,
492 struct dcerpc_binding_handle
*winreg_handle
,
493 const char *drivername
,
494 const char *architecture
,
496 uint32_t access_mask
,
498 struct policy_handle
*hive_hnd
,
499 struct policy_handle
*key_hnd
)
504 key_name
= talloc_asprintf(mem_ctx
, "%s\\Environments\\%s\\Drivers\\Version-%u",
505 TOP_LEVEL_CONTROL_KEY
,
506 architecture
, version
);
508 return WERR_NOT_ENOUGH_MEMORY
;
511 result
= winreg_printer_openkey(mem_ctx
,
522 static WERROR
winreg_enumval_to_dword(TALLOC_CTX
*mem_ctx
,
523 struct spoolss_PrinterEnumValues
*v
,
524 const char *valuename
, uint32_t *dw
)
526 /* just return if it is not the one we are looking for */
527 if (strcmp(valuename
, v
->value_name
) != 0) {
528 return WERR_NOT_FOUND
;
531 if (v
->type
!= REG_DWORD
) {
532 return WERR_INVALID_DATATYPE
;
535 if (v
->data_length
!= 4) {
540 *dw
= IVAL(v
->data
->data
, 0);
544 static WERROR
winreg_enumval_to_sz(TALLOC_CTX
*mem_ctx
,
545 struct spoolss_PrinterEnumValues
*v
,
546 const char *valuename
, const char **_str
)
548 /* just return if it is not the one we are looking for */
549 if (strcmp(valuename
, v
->value_name
) != 0) {
550 return WERR_NOT_FOUND
;
553 if (v
->type
!= REG_SZ
) {
554 return WERR_INVALID_DATATYPE
;
557 if (v
->data_length
== 0) {
558 *_str
= talloc_strdup(mem_ctx
, EMPTY_STRING
);
560 return WERR_NOT_ENOUGH_MEMORY
;
565 if (!pull_reg_sz(mem_ctx
, v
->data
, _str
)) {
566 return WERR_NOT_ENOUGH_MEMORY
;
572 static WERROR
winreg_enumval_to_multi_sz(TALLOC_CTX
*mem_ctx
,
573 struct spoolss_PrinterEnumValues
*v
,
574 const char *valuename
,
577 /* just return if it is not the one we are looking for */
578 if (strcmp(valuename
, v
->value_name
) != 0) {
579 return WERR_NOT_FOUND
;
582 if (v
->type
!= REG_MULTI_SZ
) {
583 return WERR_INVALID_DATATYPE
;
586 if (v
->data_length
== 0) {
587 *array
= talloc_array(mem_ctx
, const char *, 1);
588 if (*array
== NULL
) {
589 return WERR_NOT_ENOUGH_MEMORY
;
595 if (!pull_reg_multi_sz(mem_ctx
, v
->data
, array
)) {
596 return WERR_NOT_ENOUGH_MEMORY
;
602 static WERROR
winreg_printer_write_date(TALLOC_CTX
*mem_ctx
,
603 struct dcerpc_binding_handle
*winreg_handle
,
604 struct policy_handle
*key_handle
,
608 struct winreg_String wvalue
= { 0, };
610 WERROR result
= WERR_OK
;
617 str
= talloc_strdup(mem_ctx
, "01/01/1601");
619 t
= nt_time_to_unix(data
);
622 return map_werror_from_unix(errno
);
624 str
= talloc_asprintf(mem_ctx
, "%02d/%02d/%04d",
625 tm
->tm_mon
+ 1, tm
->tm_mday
, tm
->tm_year
+ 1900);
628 return WERR_NOT_ENOUGH_MEMORY
;
632 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
633 return WERR_NOT_ENOUGH_MEMORY
;
635 status
= dcerpc_winreg_SetValue(winreg_handle
,
643 if (!NT_STATUS_IS_OK(status
)) {
644 result
= ntstatus_to_werror(status
);
646 if (!W_ERROR_IS_OK(result
)) {
647 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
648 wvalue
.name
, win_errstr(result
)));
654 static WERROR
winreg_printer_date_to_NTTIME(const char *str
, NTTIME
*data
)
658 ok
= spoolss_timestr_to_NTTIME(str
, data
);
660 return WERR_INVALID_PARAMETER
;
666 static WERROR
winreg_printer_write_ver(TALLOC_CTX
*mem_ctx
,
667 struct dcerpc_binding_handle
*winreg_handle
,
668 struct policy_handle
*key_handle
,
672 struct winreg_String wvalue
= { 0, };
674 WERROR result
= WERR_OK
;
679 * this needs to be something like: 6.1.7600.16385
681 str
= talloc_asprintf(mem_ctx
, "%u.%u.%u.%u",
682 (unsigned)((data
>> 48) & 0xFFFF),
683 (unsigned)((data
>> 32) & 0xFFFF),
684 (unsigned)((data
>> 16) & 0xFFFF),
685 (unsigned)(data
& 0xFFFF));
687 return WERR_NOT_ENOUGH_MEMORY
;
691 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
692 return WERR_NOT_ENOUGH_MEMORY
;
694 status
= dcerpc_winreg_SetValue(winreg_handle
,
702 if (!NT_STATUS_IS_OK(status
)) {
703 result
= ntstatus_to_werror(status
);
705 if (!W_ERROR_IS_OK(result
)) {
706 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
707 wvalue
.name
, win_errstr(result
)));
713 static WERROR
winreg_printer_ver_to_qword(const char *str
, uint64_t *data
)
717 ok
= spoolss_driver_version_to_qword(str
, data
);
719 return WERR_INVALID_PARAMETER
;
725 /********************************************************************
726 Public winreg function for spoolss
727 ********************************************************************/
729 WERROR
winreg_create_printer(TALLOC_CTX
*mem_ctx
,
730 struct dcerpc_binding_handle
*winreg_handle
,
731 const char *sharename
)
733 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
734 struct policy_handle hive_hnd
, key_hnd
;
735 struct spoolss_SetPrinterInfo2
*info2
;
736 struct security_descriptor
*secdesc
;
737 struct winreg_String wkey
, wkeyclass
;
739 const char *subkeys
[] = { SPOOL_DSDRIVER_KEY
, SPOOL_DSSPOOLER_KEY
, SPOOL_PRINTERDATA_KEY
};
740 uint32_t i
, count
= ARRAY_SIZE(subkeys
);
741 uint32_t info2_mask
= 0;
742 WERROR result
= WERR_OK
;
746 tmp_ctx
= talloc_stackframe();
747 if (tmp_ctx
== NULL
) {
748 return WERR_NOT_ENOUGH_MEMORY
;
751 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
753 TALLOC_FREE(tmp_ctx
);
754 return WERR_NOT_ENOUGH_MEMORY
;
757 ZERO_STRUCT(hive_hnd
);
758 ZERO_STRUCT(key_hnd
);
760 result
= winreg_printer_openkey(tmp_ctx
,
768 if (W_ERROR_IS_OK(result
)) {
769 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path
));
771 } else if (W_ERROR_EQUAL(result
, WERR_FILE_NOT_FOUND
)) {
772 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path
));
773 } else if (!W_ERROR_IS_OK(result
)) {
774 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
775 path
, win_errstr(result
)));
779 if (is_valid_policy_hnd(&key_hnd
)) {
780 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
782 if (is_valid_policy_hnd(&hive_hnd
)) {
783 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
786 /* Create the main key */
787 result
= winreg_printer_openkey(tmp_ctx
,
795 if (!W_ERROR_IS_OK(result
)) {
796 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
797 path
, win_errstr(result
)));
801 if (is_valid_policy_hnd(&key_hnd
)) {
802 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
806 for (i
= 0; i
< count
; i
++) {
808 enum winreg_CreateAction action
= REG_ACTION_NONE
;
810 ZERO_STRUCT(key_hnd
);
813 wkey
.name
= talloc_asprintf(tmp_ctx
, "%s\\%s", path
, subkeys
[i
]);
814 if (wkey
.name
== NULL
) {
815 result
= WERR_NOT_ENOUGH_MEMORY
;
819 ZERO_STRUCT(wkeyclass
);
822 status
= dcerpc_winreg_CreateKey(winreg_handle
,
833 if (!NT_STATUS_IS_OK(status
)) {
834 result
= ntstatus_to_werror(status
);
836 if (!W_ERROR_IS_OK(result
)) {
837 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
838 wkey
.name
, win_errstr(result
)));
842 if (strequal(subkeys
[i
], SPOOL_DSSPOOLER_KEY
)) {
843 const char *dnssuffix
;
844 const char *longname
;
847 status
= dcerpc_winreg_set_sz(tmp_ctx
,
850 SPOOL_REG_PRINTERNAME
,
853 if (!NT_STATUS_IS_OK(status
)) {
854 result
= ntstatus_to_werror(status
);
856 if (!W_ERROR_IS_OK(result
)) {
860 status
= dcerpc_winreg_set_sz(tmp_ctx
,
863 SPOOL_REG_SHORTSERVERNAME
,
866 if (!NT_STATUS_IS_OK(status
)) {
867 result
= ntstatus_to_werror(status
);
869 if (!W_ERROR_IS_OK(result
)) {
873 /* We make the assumption that the netbios name
874 * is the same as the DNS name since the former
875 * will be what we used to join the domain
877 dnssuffix
= get_mydnsdomname(tmp_ctx
);
878 if (dnssuffix
!= NULL
&& dnssuffix
[0] != '\0') {
879 longname
= talloc_asprintf(tmp_ctx
, "%s.%s", lp_netbios_name(), dnssuffix
);
881 longname
= talloc_strdup(tmp_ctx
, lp_netbios_name());
883 if (longname
== NULL
) {
884 result
= WERR_NOT_ENOUGH_MEMORY
;
888 status
= dcerpc_winreg_set_sz(tmp_ctx
,
891 SPOOL_REG_SERVERNAME
,
894 if (!NT_STATUS_IS_OK(status
)) {
895 result
= ntstatus_to_werror(status
);
897 if (!W_ERROR_IS_OK(result
)) {
901 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
902 longname
, sharename
);
903 if (uncname
== NULL
) {
904 result
= WERR_NOT_ENOUGH_MEMORY
;
908 status
= dcerpc_winreg_set_sz(tmp_ctx
,
914 if (!NT_STATUS_IS_OK(status
)) {
915 result
= ntstatus_to_werror(status
);
917 if (!W_ERROR_IS_OK(result
)) {
921 status
= dcerpc_winreg_set_dword(tmp_ctx
,
924 SPOOL_REG_VERSIONNUMBER
,
927 if (!NT_STATUS_IS_OK(status
)) {
928 result
= ntstatus_to_werror(status
);
930 if (!W_ERROR_IS_OK(result
)) {
934 status
= dcerpc_winreg_set_dword(tmp_ctx
,
937 SPOOL_REG_PRINTSTARTTIME
,
940 if (!NT_STATUS_IS_OK(status
)) {
941 result
= ntstatus_to_werror(status
);
943 if (!W_ERROR_IS_OK(result
)) {
947 status
= dcerpc_winreg_set_dword(tmp_ctx
,
950 SPOOL_REG_PRINTENDTIME
,
953 if (!NT_STATUS_IS_OK(status
)) {
954 result
= ntstatus_to_werror(status
);
956 if (!W_ERROR_IS_OK(result
)) {
960 status
= dcerpc_winreg_set_dword(tmp_ctx
,
966 if (!NT_STATUS_IS_OK(status
)) {
967 result
= ntstatus_to_werror(status
);
969 if (!W_ERROR_IS_OK(result
)) {
973 status
= dcerpc_winreg_set_dword(tmp_ctx
,
976 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
979 if (!NT_STATUS_IS_OK(status
)) {
980 result
= ntstatus_to_werror(status
);
982 if (!W_ERROR_IS_OK(result
)) {
987 if (is_valid_policy_hnd(&key_hnd
)) {
988 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
991 info2
= talloc_zero(tmp_ctx
, struct spoolss_SetPrinterInfo2
);
993 result
= WERR_NOT_ENOUGH_MEMORY
;
997 info2
->printername
= sharename
;
998 if (info2
->printername
== NULL
) {
999 result
= WERR_NOT_ENOUGH_MEMORY
;
1002 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTERNAME
;
1004 info2
->sharename
= sharename
;
1005 info2_mask
|= SPOOLSS_PRINTER_INFO_SHARENAME
;
1007 info2
->portname
= SAMBA_PRINTER_PORT_NAME
;
1008 info2_mask
|= SPOOLSS_PRINTER_INFO_PORTNAME
;
1010 info2
->printprocessor
= "winprint";
1011 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
;
1013 info2
->datatype
= "RAW";
1014 info2_mask
|= SPOOLSS_PRINTER_INFO_DATATYPE
;
1016 info2
->comment
= "";
1017 info2_mask
|= SPOOLSS_PRINTER_INFO_COMMENT
;
1019 info2
->attributes
= PRINTER_ATTRIBUTE_SAMBA
;
1020 info2_mask
|= SPOOLSS_PRINTER_INFO_ATTRIBUTES
;
1022 info2
->starttime
= 0; /* Minutes since 12:00am GMT */
1023 info2_mask
|= SPOOLSS_PRINTER_INFO_STARTTIME
;
1025 info2
->untiltime
= 0; /* Minutes since 12:00am GMT */
1026 info2_mask
|= SPOOLSS_PRINTER_INFO_UNTILTIME
;
1028 info2
->priority
= 1;
1029 info2_mask
|= SPOOLSS_PRINTER_INFO_PRIORITY
;
1031 info2
->defaultpriority
= 1;
1032 info2_mask
|= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
;
1034 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1035 if (!W_ERROR_IS_OK(result
)) {
1038 info2_mask
|= SPOOLSS_PRINTER_INFO_SECDESC
;
1041 * Don't write a default Device Mode to the registry! The Device Mode is
1042 * only written to disk with a SetPrinter level 2 or 8.
1045 result
= winreg_update_printer(tmp_ctx
,
1054 if (is_valid_policy_hnd(&key_hnd
)) {
1055 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1057 if (is_valid_policy_hnd(&hive_hnd
)) {
1058 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1061 talloc_free(tmp_ctx
);
1065 WERROR
winreg_update_printer(TALLOC_CTX
*mem_ctx
,
1066 struct dcerpc_binding_handle
*winreg_handle
,
1067 const char *sharename
,
1068 uint32_t info2_mask
,
1069 struct spoolss_SetPrinterInfo2
*info2
,
1070 struct spoolss_DeviceMode
*devmode
,
1071 struct security_descriptor
*secdesc
)
1073 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1074 struct policy_handle hive_hnd
, key_hnd
;
1075 int snum
= lp_servicenumber(sharename
);
1076 enum ndr_err_code ndr_err
;
1079 WERROR result
= WERR_OK
;
1082 TALLOC_CTX
*tmp_ctx
;
1084 tmp_ctx
= talloc_stackframe();
1085 if (tmp_ctx
== NULL
) {
1086 return WERR_NOT_ENOUGH_MEMORY
;
1089 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1091 TALLOC_FREE(tmp_ctx
);
1092 return WERR_NOT_ENOUGH_MEMORY
;
1095 ZERO_STRUCT(hive_hnd
);
1096 ZERO_STRUCT(key_hnd
);
1098 result
= winreg_printer_openkey(tmp_ctx
,
1106 if (!W_ERROR_IS_OK(result
)) {
1107 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1108 path
, win_errstr(result
)));
1112 if (info2_mask
& SPOOLSS_PRINTER_INFO_ATTRIBUTES
) {
1113 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1119 if (!NT_STATUS_IS_OK(status
)) {
1120 result
= ntstatus_to_werror(status
);
1122 if (!W_ERROR_IS_OK(result
)) {
1128 if (info2_mask
& SPOOLSS_PRINTER_INFO_AVERAGEPPM
) {
1129 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1135 if (!NT_STATUS_IS_OK(status
)) {
1136 result
= ntstatus_to_werror(status
);
1138 if (!W_ERROR_IS_OK(result
)) {
1144 if (info2_mask
& SPOOLSS_PRINTER_INFO_COMMENT
) {
1145 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1151 if (!NT_STATUS_IS_OK(status
)) {
1152 result
= ntstatus_to_werror(status
);
1154 if (!W_ERROR_IS_OK(result
)) {
1159 if (info2_mask
& SPOOLSS_PRINTER_INFO_DATATYPE
) {
1160 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1166 if (!NT_STATUS_IS_OK(status
)) {
1167 result
= ntstatus_to_werror(status
);
1169 if (!W_ERROR_IS_OK(result
)) {
1174 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
) {
1175 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1179 info2
->defaultpriority
,
1181 if (!NT_STATUS_IS_OK(status
)) {
1182 result
= ntstatus_to_werror(status
);
1184 if (!W_ERROR_IS_OK(result
)) {
1189 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEVMODE
) {
1191 * Some client drivers freak out if there is a NULL devmode
1192 * (probably the driver is not checking before accessing
1193 * the devmode pointer) --jerry
1195 if (devmode
== NULL
&& lp_default_devmode(snum
) && info2
!= NULL
) {
1196 result
= spoolss_create_default_devmode(tmp_ctx
,
1199 if (!W_ERROR_IS_OK(result
)) {
1204 if (devmode
->size
!= (ndr_size_spoolss_DeviceMode(devmode
, 0) - devmode
->__driverextra_length
)) {
1205 result
= WERR_INVALID_PARAMETER
;
1209 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, devmode
,
1210 (ndr_push_flags_fn_t
) ndr_push_spoolss_DeviceMode
);
1211 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1212 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1213 result
= WERR_NOT_ENOUGH_MEMORY
;
1217 status
= dcerpc_winreg_set_binary(tmp_ctx
,
1223 if (!NT_STATUS_IS_OK(status
)) {
1224 result
= ntstatus_to_werror(status
);
1226 if (!W_ERROR_IS_OK(result
)) {
1231 if (info2_mask
& SPOOLSS_PRINTER_INFO_DRIVERNAME
) {
1232 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1238 if (!NT_STATUS_IS_OK(status
)) {
1239 result
= ntstatus_to_werror(status
);
1241 if (!W_ERROR_IS_OK(result
)) {
1246 if (info2_mask
& SPOOLSS_PRINTER_INFO_LOCATION
) {
1247 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1253 if (!NT_STATUS_IS_OK(status
)) {
1254 result
= ntstatus_to_werror(status
);
1256 if (!W_ERROR_IS_OK(result
)) {
1261 if (info2_mask
& SPOOLSS_PRINTER_INFO_PARAMETERS
) {
1262 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1268 if (!NT_STATUS_IS_OK(status
)) {
1269 result
= ntstatus_to_werror(status
);
1271 if (!W_ERROR_IS_OK(result
)) {
1276 if (info2_mask
& SPOOLSS_PRINTER_INFO_PORTNAME
) {
1277 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1283 if (!NT_STATUS_IS_OK(status
)) {
1284 result
= ntstatus_to_werror(status
);
1286 if (!W_ERROR_IS_OK(result
)) {
1291 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTERNAME
) {
1293 * in addprinter: no servername and the printer is the name
1294 * in setprinter: servername is \\server
1295 * and printer is \\server\\printer
1297 * Samba manages only local printers.
1298 * we currently don't support things like i
1299 * path=\\other_server\printer
1301 * We only store the printername, not \\server\printername
1303 const char *p
= strrchr(info2
->printername
, '\\');
1305 p
= info2
->printername
;
1309 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1315 if (!NT_STATUS_IS_OK(status
)) {
1316 result
= ntstatus_to_werror(status
);
1318 if (!W_ERROR_IS_OK(result
)) {
1323 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
) {
1324 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1328 info2
->printprocessor
,
1330 if (!NT_STATUS_IS_OK(status
)) {
1331 result
= ntstatus_to_werror(status
);
1333 if (!W_ERROR_IS_OK(result
)) {
1338 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRIORITY
) {
1339 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1345 if (!NT_STATUS_IS_OK(status
)) {
1346 result
= ntstatus_to_werror(status
);
1348 if (!W_ERROR_IS_OK(result
)) {
1353 if (info2_mask
& SPOOLSS_PRINTER_INFO_SECDESC
) {
1355 * We need a security descriptor, if it isn't specified by
1356 * AddPrinter{Ex} then create a default descriptor.
1358 if (secdesc
== NULL
) {
1359 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1360 if (!W_ERROR_IS_OK(result
)) {
1364 result
= winreg_set_printer_secdesc(tmp_ctx
,
1368 if (!W_ERROR_IS_OK(result
)) {
1373 if (info2_mask
& SPOOLSS_PRINTER_INFO_SEPFILE
) {
1374 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1380 if (!NT_STATUS_IS_OK(status
)) {
1381 result
= ntstatus_to_werror(status
);
1383 if (!W_ERROR_IS_OK(result
)) {
1388 if (info2_mask
& SPOOLSS_PRINTER_INFO_SHARENAME
) {
1389 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1395 if (!NT_STATUS_IS_OK(status
)) {
1396 result
= ntstatus_to_werror(status
);
1398 if (!W_ERROR_IS_OK(result
)) {
1403 if (info2_mask
& SPOOLSS_PRINTER_INFO_STARTTIME
) {
1404 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1410 if (!NT_STATUS_IS_OK(status
)) {
1411 result
= ntstatus_to_werror(status
);
1413 if (!W_ERROR_IS_OK(result
)) {
1418 if (info2_mask
& SPOOLSS_PRINTER_INFO_STATUS
) {
1419 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1425 if (!NT_STATUS_IS_OK(status
)) {
1426 result
= ntstatus_to_werror(status
);
1428 if (!W_ERROR_IS_OK(result
)) {
1433 if (info2_mask
& SPOOLSS_PRINTER_INFO_UNTILTIME
) {
1434 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1440 if (!NT_STATUS_IS_OK(status
)) {
1441 result
= ntstatus_to_werror(status
);
1443 if (!W_ERROR_IS_OK(result
)) {
1448 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1452 winreg_printer_rev_changeid(),
1454 if (!NT_STATUS_IS_OK(status
)) {
1455 result
= ntstatus_to_werror(status
);
1457 if (!W_ERROR_IS_OK(result
)) {
1463 if (is_valid_policy_hnd(&key_hnd
)) {
1464 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1466 if (is_valid_policy_hnd(&hive_hnd
)) {
1467 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1470 TALLOC_FREE(tmp_ctx
);
1474 WERROR
winreg_get_printer(TALLOC_CTX
*mem_ctx
,
1475 struct dcerpc_binding_handle
*winreg_handle
,
1476 const char *printer
,
1477 struct spoolss_PrinterInfo2
**pinfo2
)
1479 struct spoolss_PrinterInfo2
*info2
;
1480 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1481 struct policy_handle hive_hnd
, key_hnd
;
1482 struct spoolss_PrinterEnumValues enum_value
;
1483 struct spoolss_PrinterEnumValues
*v
= NULL
;
1484 enum ndr_err_code ndr_err
;
1486 int snum
= lp_servicenumber(printer
);
1487 uint32_t num_values
= 0;
1491 WERROR result
= WERR_OK
;
1493 const char **enum_names
= NULL
;
1494 enum winreg_Type
*enum_types
= NULL
;
1495 DATA_BLOB
*enum_data_blobs
= NULL
;
1496 TALLOC_CTX
*tmp_ctx
;
1498 tmp_ctx
= talloc_stackframe();
1499 if (tmp_ctx
== NULL
) {
1500 return WERR_NOT_ENOUGH_MEMORY
;
1503 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1505 TALLOC_FREE(tmp_ctx
);
1506 return WERR_NOT_ENOUGH_MEMORY
;
1509 result
= winreg_printer_openkey(tmp_ctx
,
1517 if (!W_ERROR_IS_OK(result
)) {
1518 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
1519 path
, win_errstr(result
)));
1523 status
= dcerpc_winreg_enumvals(tmp_ctx
,
1531 if (!NT_STATUS_IS_OK(status
)){
1532 result
= ntstatus_to_werror(status
);
1535 if (!W_ERROR_IS_OK(result
)) {
1536 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1537 path
, win_errstr(result
)));
1541 info2
= talloc_zero(tmp_ctx
, struct spoolss_PrinterInfo2
);
1542 if (info2
== NULL
) {
1543 result
= WERR_NOT_ENOUGH_MEMORY
;
1547 FILL_STRING(info2
, EMPTY_STRING
, info2
->servername
);
1548 FILL_STRING(info2
, EMPTY_STRING
, info2
->printername
);
1549 FILL_STRING(info2
, EMPTY_STRING
, info2
->sharename
);
1550 FILL_STRING(info2
, EMPTY_STRING
, info2
->portname
);
1551 FILL_STRING(info2
, EMPTY_STRING
, info2
->drivername
);
1552 FILL_STRING(info2
, EMPTY_STRING
, info2
->comment
);
1553 FILL_STRING(info2
, EMPTY_STRING
, info2
->location
);
1554 FILL_STRING(info2
, EMPTY_STRING
, info2
->sepfile
);
1555 FILL_STRING(info2
, EMPTY_STRING
, info2
->printprocessor
);
1556 FILL_STRING(info2
, EMPTY_STRING
, info2
->datatype
);
1557 FILL_STRING(info2
, EMPTY_STRING
, info2
->parameters
);
1559 for (i
= 0; i
< num_values
; i
++) {
1560 enum_value
.value_name
= enum_names
[i
];
1561 enum_value
.value_name_len
= 2*strlen_m_term(enum_names
[i
]);
1562 enum_value
.type
= enum_types
[i
];
1563 enum_value
.data_length
= enum_data_blobs
[i
].length
;
1564 enum_value
.data
= NULL
;
1565 if (enum_value
.data_length
!= 0){
1566 enum_value
.data
= &enum_data_blobs
[i
];
1570 result
= winreg_enumval_to_sz(info2
,
1573 &info2
->printername
);
1574 CHECK_ERROR(result
);
1576 result
= winreg_enumval_to_sz(info2
,
1580 CHECK_ERROR(result
);
1582 result
= winreg_enumval_to_sz(info2
,
1586 CHECK_ERROR(result
);
1588 result
= winreg_enumval_to_sz(info2
,
1592 CHECK_ERROR(result
);
1594 result
= winreg_enumval_to_sz(info2
,
1598 CHECK_ERROR(result
);
1600 result
= winreg_enumval_to_sz(info2
,
1604 CHECK_ERROR(result
);
1606 result
= winreg_enumval_to_sz(info2
,
1609 &info2
->printprocessor
);
1610 CHECK_ERROR(result
);
1612 result
= winreg_enumval_to_sz(info2
,
1616 CHECK_ERROR(result
);
1618 result
= winreg_enumval_to_sz(info2
,
1621 &info2
->parameters
);
1622 CHECK_ERROR(result
);
1624 result
= winreg_enumval_to_sz(info2
,
1627 &info2
->drivername
);
1628 CHECK_ERROR(result
);
1630 result
= winreg_enumval_to_dword(info2
,
1633 &info2
->attributes
);
1634 CHECK_ERROR(result
);
1636 result
= winreg_enumval_to_dword(info2
,
1640 CHECK_ERROR(result
);
1642 result
= winreg_enumval_to_dword(info2
,
1645 &info2
->defaultpriority
);
1646 CHECK_ERROR(result
);
1648 result
= winreg_enumval_to_dword(info2
,
1652 CHECK_ERROR(result
);
1654 result
= winreg_enumval_to_dword(info2
,
1658 CHECK_ERROR(result
);
1660 result
= winreg_enumval_to_dword(info2
,
1664 CHECK_ERROR(result
);
1666 result
= winreg_enumval_to_dword(info2
,
1670 CHECK_ERROR(result
);
1673 if (!W_ERROR_IS_OK(result
)) {
1674 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
1677 win_errstr(result
)));
1681 /* Construct the Device Mode */
1682 status
= dcerpc_winreg_query_binary(tmp_ctx
,
1688 if (!NT_STATUS_IS_OK(status
)) {
1689 result
= ntstatus_to_werror(status
);
1691 if (W_ERROR_IS_OK(result
)) {
1692 info2
->devmode
= talloc_zero(info2
, struct spoolss_DeviceMode
);
1693 if (info2
->devmode
== NULL
) {
1694 result
= WERR_NOT_ENOUGH_MEMORY
;
1697 ndr_err
= ndr_pull_struct_blob(&blob
,
1700 (ndr_pull_flags_fn_t
) ndr_pull_spoolss_DeviceMode
);
1701 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1702 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
1703 result
= WERR_NOT_ENOUGH_MEMORY
;
1708 if (info2
->devmode
== NULL
&& lp_default_devmode(snum
)) {
1709 result
= spoolss_create_default_devmode(info2
,
1712 if (!W_ERROR_IS_OK(result
)) {
1717 if (info2
->devmode
) {
1718 info2
->devmode
->size
= ndr_size_spoolss_DeviceMode(info2
->devmode
, 0) - info2
->devmode
->driverextra_data
.length
;
1721 result
= winreg_get_printer_secdesc(info2
,
1725 if (!W_ERROR_IS_OK(result
)) {
1729 /* Fix for OS/2 drivers. */
1730 if (get_remote_arch() == RA_OS2
) {
1731 spoolss_map_to_os2_driver(info2
, &info2
->drivername
);
1735 *pinfo2
= talloc_move(mem_ctx
, &info2
);
1740 if (is_valid_policy_hnd(&key_hnd
)) {
1741 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1743 if (is_valid_policy_hnd(&hive_hnd
)) {
1744 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1747 TALLOC_FREE(tmp_ctx
);
1751 static WERROR
winreg_get_secdesc(TALLOC_CTX
*mem_ctx
,
1752 struct dcerpc_binding_handle
*winreg_handle
,
1754 const char *attribute
,
1755 struct spoolss_security_descriptor
**psecdesc
)
1757 struct spoolss_security_descriptor
*secdesc
;
1758 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1759 struct policy_handle hive_hnd
, key_hnd
;
1760 TALLOC_CTX
*tmp_ctx
;
1765 tmp_ctx
= talloc_stackframe();
1766 if (tmp_ctx
== NULL
) {
1767 return WERR_NOT_ENOUGH_MEMORY
;
1770 ZERO_STRUCT(hive_hnd
);
1771 ZERO_STRUCT(key_hnd
);
1773 result
= winreg_printer_openkey(tmp_ctx
,
1781 if (!W_ERROR_IS_OK(result
)) {
1782 if (W_ERROR_EQUAL(result
, WERR_FILE_NOT_FOUND
)) {
1783 goto create_default
;
1788 status
= dcerpc_winreg_query_sd(tmp_ctx
,
1794 if (!NT_STATUS_IS_OK(status
)) {
1795 result
= ntstatus_to_werror(status
);
1797 if (!W_ERROR_IS_OK(result
)) {
1798 if (W_ERROR_EQUAL(result
, WERR_FILE_NOT_FOUND
)) {
1800 if (is_valid_policy_hnd(&key_hnd
)) {
1801 dcerpc_winreg_CloseKey(winreg_handle
,
1807 if (is_valid_policy_hnd(&hive_hnd
)) {
1808 dcerpc_winreg_CloseKey(winreg_handle
,
1813 goto create_default
;
1819 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1826 result
= winreg_printer_openkey(tmp_ctx
,
1834 if (!W_ERROR_IS_OK(result
)) {
1838 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1839 if (!W_ERROR_IS_OK(result
)) {
1843 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
1844 this security descriptor has been created when winbindd was
1845 down. Take ownership of security descriptor. */
1846 if (dom_sid_equal(secdesc
->owner_sid
, &global_sid_World
)) {
1847 struct dom_sid owner_sid
;
1849 /* Change sd owner to workgroup administrator */
1851 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid
)) {
1852 struct spoolss_security_descriptor
*new_secdesc
;
1856 sid_append_rid(&owner_sid
, DOMAIN_RID_ADMINISTRATOR
);
1858 new_secdesc
= make_sec_desc(tmp_ctx
,
1867 if (new_secdesc
== NULL
) {
1868 result
= WERR_NOT_ENOUGH_MEMORY
;
1872 /* Swap with other one */
1873 secdesc
= new_secdesc
;
1877 status
= dcerpc_winreg_set_sd(tmp_ctx
,
1883 if (!NT_STATUS_IS_OK(status
)) {
1884 result
= ntstatus_to_werror(status
);
1886 if (!W_ERROR_IS_OK(result
)) {
1891 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1896 if (is_valid_policy_hnd(&key_hnd
)) {
1897 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1899 if (is_valid_policy_hnd(&hive_hnd
)) {
1900 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1903 talloc_free(tmp_ctx
);
1907 WERROR
winreg_get_printer_secdesc(TALLOC_CTX
*mem_ctx
,
1908 struct dcerpc_binding_handle
*winreg_handle
,
1909 const char *sharename
,
1910 struct spoolss_security_descriptor
**psecdesc
)
1915 path
= winreg_printer_data_keyname(mem_ctx
, sharename
);
1917 return WERR_NOT_ENOUGH_MEMORY
;
1920 result
= winreg_get_secdesc(mem_ctx
, winreg_handle
,
1929 WERROR
winreg_get_printserver_secdesc(TALLOC_CTX
*mem_ctx
,
1930 struct dcerpc_binding_handle
*winreg_handle
,
1931 struct spoolss_security_descriptor
**psecdesc
)
1933 return winreg_get_secdesc(mem_ctx
, winreg_handle
,
1934 TOP_LEVEL_CONTROL_KEY
,
1935 "ServerSecurityDescriptor",
1939 static WERROR
winreg_set_secdesc(TALLOC_CTX
*mem_ctx
,
1940 struct dcerpc_binding_handle
*winreg_handle
,
1942 const char *attribute
,
1943 const struct spoolss_security_descriptor
*secdesc
)
1945 const struct spoolss_security_descriptor
*new_secdesc
= secdesc
;
1946 struct spoolss_security_descriptor
*old_secdesc
;
1947 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1948 struct policy_handle hive_hnd
, key_hnd
;
1949 TALLOC_CTX
*tmp_ctx
;
1954 tmp_ctx
= talloc_stackframe();
1955 if (tmp_ctx
== NULL
) {
1956 return WERR_NOT_ENOUGH_MEMORY
;
1960 * The old owner and group sids of the security descriptor are not
1961 * present when new ACEs are added or removed by changing printer
1962 * permissions through NT. If they are NULL in the new security
1963 * descriptor then copy them over from the old one.
1965 if (!secdesc
->owner_sid
|| !secdesc
->group_sid
) {
1966 struct dom_sid
*owner_sid
, *group_sid
;
1967 struct security_acl
*dacl
, *sacl
;
1970 result
= winreg_get_secdesc(tmp_ctx
,
1975 if (!W_ERROR_IS_OK(result
)) {
1976 talloc_free(tmp_ctx
);
1980 /* Pick out correct owner and group sids */
1981 owner_sid
= secdesc
->owner_sid
?
1982 secdesc
->owner_sid
:
1983 old_secdesc
->owner_sid
;
1985 group_sid
= secdesc
->group_sid
?
1986 secdesc
->group_sid
:
1987 old_secdesc
->group_sid
;
1989 dacl
= secdesc
->dacl
?
1993 sacl
= secdesc
->sacl
?
1997 /* Make a deep copy of the security descriptor */
1998 new_secdesc
= make_sec_desc(tmp_ctx
,
2006 if (new_secdesc
== NULL
) {
2007 talloc_free(tmp_ctx
);
2008 return WERR_NOT_ENOUGH_MEMORY
;
2012 ZERO_STRUCT(hive_hnd
);
2013 ZERO_STRUCT(key_hnd
);
2015 result
= winreg_printer_openkey(tmp_ctx
,
2023 if (!W_ERROR_IS_OK(result
)) {
2027 status
= dcerpc_winreg_set_sd(tmp_ctx
,
2033 if (!NT_STATUS_IS_OK(status
)) {
2034 result
= ntstatus_to_werror(status
);
2038 if (is_valid_policy_hnd(&key_hnd
)) {
2039 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2041 if (is_valid_policy_hnd(&hive_hnd
)) {
2042 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2045 talloc_free(tmp_ctx
);
2049 WERROR
winreg_set_printer_secdesc(TALLOC_CTX
*mem_ctx
,
2050 struct dcerpc_binding_handle
*winreg_handle
,
2051 const char *sharename
,
2052 const struct spoolss_security_descriptor
*secdesc
)
2057 path
= winreg_printer_data_keyname(mem_ctx
, sharename
);
2059 return WERR_NOT_ENOUGH_MEMORY
;
2062 result
= winreg_set_secdesc(mem_ctx
, winreg_handle
,
2064 "Security", secdesc
);
2070 WERROR
winreg_set_printserver_secdesc(TALLOC_CTX
*mem_ctx
,
2071 struct dcerpc_binding_handle
*winreg_handle
,
2072 const struct spoolss_security_descriptor
*secdesc
)
2074 return winreg_set_secdesc(mem_ctx
, winreg_handle
,
2075 TOP_LEVEL_CONTROL_KEY
,
2076 "ServerSecurityDescriptor",
2080 /* Set printer data over the winreg pipe. */
2081 WERROR
winreg_set_printer_dataex(TALLOC_CTX
*mem_ctx
,
2082 struct dcerpc_binding_handle
*winreg_handle
,
2083 const char *printer
,
2086 enum winreg_Type type
,
2090 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2091 struct policy_handle hive_hnd
, key_hnd
;
2092 struct winreg_String wvalue
= { 0, };
2094 WERROR result
= WERR_OK
;
2097 TALLOC_CTX
*tmp_ctx
;
2099 tmp_ctx
= talloc_stackframe();
2100 if (tmp_ctx
== NULL
) {
2101 return WERR_NOT_ENOUGH_MEMORY
;
2104 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2106 TALLOC_FREE(tmp_ctx
);
2107 return WERR_NOT_ENOUGH_MEMORY
;
2110 ZERO_STRUCT(hive_hnd
);
2111 ZERO_STRUCT(key_hnd
);
2113 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2114 key
, value
, access_mask
, printer
));
2115 result
= winreg_printer_openkey(tmp_ctx
,
2123 if (!W_ERROR_IS_OK(result
)) {
2124 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2125 key
, win_errstr(result
)));
2129 wvalue
.name
= value
;
2130 status
= dcerpc_winreg_SetValue(winreg_handle
,
2138 if (!NT_STATUS_IS_OK(status
)) {
2139 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2140 value
, nt_errstr(status
)));
2141 result
= ntstatus_to_werror(status
);
2145 if (is_valid_policy_hnd(&key_hnd
)) {
2146 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2148 if (is_valid_policy_hnd(&hive_hnd
)) {
2149 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2152 TALLOC_FREE(tmp_ctx
);
2156 /* Get printer data over a winreg pipe. */
2157 WERROR
winreg_get_printer_dataex(TALLOC_CTX
*mem_ctx
,
2158 struct dcerpc_binding_handle
*winreg_handle
,
2159 const char *printer
,
2162 enum winreg_Type
*type
,
2164 uint32_t *data_size
)
2166 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2167 struct policy_handle hive_hnd
, key_hnd
;
2168 struct winreg_String wvalue
;
2169 enum winreg_Type type_in
= REG_NONE
;
2171 uint8_t *data_in
= NULL
;
2172 uint32_t data_in_size
= 0;
2173 uint32_t value_len
= 0;
2174 WERROR result
= WERR_OK
;
2177 TALLOC_CTX
*tmp_ctx
;
2179 tmp_ctx
= talloc_stackframe();
2180 if (tmp_ctx
== NULL
) {
2181 return WERR_NOT_ENOUGH_MEMORY
;
2184 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2186 TALLOC_FREE(tmp_ctx
);
2187 return WERR_NOT_ENOUGH_MEMORY
;
2190 ZERO_STRUCT(hive_hnd
);
2191 ZERO_STRUCT(key_hnd
);
2193 result
= winreg_printer_openkey(tmp_ctx
,
2201 if (!W_ERROR_IS_OK(result
)) {
2202 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2203 key
, win_errstr(result
)));
2207 wvalue
.name
= value
;
2210 * call QueryValue once with data == NULL to get the
2211 * needed memory size to be allocated, then allocate
2212 * data buffer and call again.
2214 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2223 if (!NT_STATUS_IS_OK(status
)) {
2224 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2225 value
, nt_errstr(status
)));
2226 result
= ntstatus_to_werror(status
);
2229 if (!W_ERROR_IS_OK(result
)) {
2230 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2231 value
, win_errstr(result
)));
2235 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
2236 if (data_in
== NULL
) {
2237 result
= WERR_NOT_ENOUGH_MEMORY
;
2242 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2251 if (!NT_STATUS_IS_OK(status
)) {
2252 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2253 value
, nt_errstr(status
)));
2254 result
= ntstatus_to_werror(status
);
2257 if (!W_ERROR_IS_OK(result
)) {
2258 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2259 value
, win_errstr(result
)));
2264 *data_size
= data_in_size
;
2266 *data
= talloc_move(mem_ctx
, &data_in
);
2271 if (is_valid_policy_hnd(&key_hnd
)) {
2272 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2274 if (is_valid_policy_hnd(&hive_hnd
)) {
2275 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2278 TALLOC_FREE(tmp_ctx
);
2282 /* Enumerate on the values of a given key and provide the data. */
2283 WERROR
winreg_enum_printer_dataex(TALLOC_CTX
*mem_ctx
,
2284 struct dcerpc_binding_handle
*winreg_handle
,
2285 const char *printer
,
2287 uint32_t *pnum_values
,
2288 struct spoolss_PrinterEnumValues
**penum_values
)
2291 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2292 struct policy_handle hive_hnd
, key_hnd
;
2294 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2295 uint32_t num_values
= 0;
2297 WERROR result
= WERR_OK
;
2300 const char **enum_names
= NULL
;
2301 enum winreg_Type
*enum_types
= NULL
;
2302 DATA_BLOB
*enum_data_blobs
= NULL
;
2304 TALLOC_CTX
*tmp_ctx
;
2306 tmp_ctx
= talloc_stackframe();
2307 if (tmp_ctx
== NULL
) {
2308 return WERR_NOT_ENOUGH_MEMORY
;
2311 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2313 TALLOC_FREE(tmp_ctx
);
2314 return WERR_NOT_ENOUGH_MEMORY
;
2317 result
= winreg_printer_openkey(tmp_ctx
,
2325 if (!W_ERROR_IS_OK(result
)) {
2326 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2327 key
, win_errstr(result
)));
2331 status
= dcerpc_winreg_enumvals(tmp_ctx
,
2339 if (!NT_STATUS_IS_OK(status
)){
2340 result
= ntstatus_to_werror(status
);
2343 if (!W_ERROR_IS_OK(result
)) {
2344 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2345 key
, win_errstr(result
)));
2349 enum_values
= talloc_array(tmp_ctx
, struct spoolss_PrinterEnumValues
, num_values
);
2350 if (enum_values
== NULL
){
2351 result
= WERR_NOT_ENOUGH_MEMORY
;
2352 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2353 key
, win_errstr(result
)));
2357 for (i
= 0; i
< num_values
; i
++){
2358 enum_values
[i
].value_name
= enum_names
[i
];
2359 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
2360 enum_values
[i
].type
= enum_types
[i
];
2361 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
2362 enum_values
[i
].data
= NULL
;
2364 if (enum_values
[i
].data_length
!= 0){
2365 enum_values
[i
].data
= &enum_data_blobs
[i
];
2369 talloc_steal(enum_values
, enum_names
);
2370 talloc_steal(enum_values
, enum_data_blobs
);
2372 *pnum_values
= num_values
;
2374 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
2379 if (is_valid_policy_hnd(&key_hnd
)) {
2380 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2382 if (is_valid_policy_hnd(&hive_hnd
)) {
2383 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2386 TALLOC_FREE(tmp_ctx
);
2390 /* Delete printer data over a winreg pipe. */
2391 WERROR
winreg_delete_printer_dataex(TALLOC_CTX
*mem_ctx
,
2392 struct dcerpc_binding_handle
*winreg_handle
,
2393 const char *printer
,
2397 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2398 struct policy_handle hive_hnd
, key_hnd
;
2399 struct winreg_String wvalue
= { 0, };
2401 WERROR result
= WERR_OK
;
2405 TALLOC_CTX
*tmp_ctx
;
2407 tmp_ctx
= talloc_stackframe();
2408 if (tmp_ctx
== NULL
) {
2409 return WERR_NOT_ENOUGH_MEMORY
;
2412 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2414 TALLOC_FREE(tmp_ctx
);
2415 return WERR_NOT_ENOUGH_MEMORY
;
2418 ZERO_STRUCT(hive_hnd
);
2419 ZERO_STRUCT(key_hnd
);
2421 result
= winreg_printer_openkey(tmp_ctx
,
2429 if (!W_ERROR_IS_OK(result
)) {
2430 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2431 key
, win_errstr(result
)));
2435 wvalue
.name
= value
;
2436 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
2441 if (!NT_STATUS_IS_OK(status
)) {
2442 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2443 value
, nt_errstr(status
)));
2444 result
= ntstatus_to_werror(status
);
2448 if (is_valid_policy_hnd(&key_hnd
)) {
2449 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2451 if (is_valid_policy_hnd(&hive_hnd
)) {
2452 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2455 TALLOC_FREE(tmp_ctx
);
2459 /* Enumerate on the subkeys of a given key and provide the data. */
2460 WERROR
winreg_enum_printer_key(TALLOC_CTX
*mem_ctx
,
2461 struct dcerpc_binding_handle
*winreg_handle
,
2462 const char *printer
,
2464 uint32_t *pnum_subkeys
,
2465 const char ***psubkeys
)
2467 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2468 struct policy_handle hive_hnd
, key_hnd
;
2470 const char **subkeys
= NULL
;
2471 uint32_t num_subkeys
= -1;
2473 WERROR result
= WERR_OK
;
2477 TALLOC_CTX
*tmp_ctx
;
2479 tmp_ctx
= talloc_stackframe();
2480 if (tmp_ctx
== NULL
) {
2481 return WERR_NOT_ENOUGH_MEMORY
;
2484 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2486 TALLOC_FREE(tmp_ctx
);
2487 return WERR_NOT_ENOUGH_MEMORY
;
2490 ZERO_STRUCT(hive_hnd
);
2491 ZERO_STRUCT(key_hnd
);
2493 result
= winreg_printer_openkey(tmp_ctx
,
2501 if (!W_ERROR_IS_OK(result
)) {
2502 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2503 key
, win_errstr(result
)));
2507 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
2513 if (!NT_STATUS_IS_OK(status
)) {
2514 result
= ntstatus_to_werror(status
);
2516 if (!W_ERROR_IS_OK(result
)) {
2517 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2518 key
, win_errstr(result
)));
2522 *pnum_subkeys
= num_subkeys
;
2524 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
2529 if (is_valid_policy_hnd(&key_hnd
)) {
2530 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2532 if (is_valid_policy_hnd(&hive_hnd
)) {
2533 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2536 TALLOC_FREE(tmp_ctx
);
2540 /* Delete a key with subkeys of a given printer. */
2541 WERROR
winreg_delete_printer_key(TALLOC_CTX
*mem_ctx
,
2542 struct dcerpc_binding_handle
*winreg_handle
,
2543 const char *printer
,
2546 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2547 struct policy_handle hive_hnd
, key_hnd
;
2553 TALLOC_CTX
*tmp_ctx
;
2555 tmp_ctx
= talloc_stackframe();
2556 if (tmp_ctx
== NULL
) {
2557 return WERR_NOT_ENOUGH_MEMORY
;
2560 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2562 TALLOC_FREE(tmp_ctx
);
2563 return WERR_NOT_ENOUGH_MEMORY
;
2566 result
= winreg_printer_openkey(tmp_ctx
,
2574 if (!W_ERROR_IS_OK(result
)) {
2575 /* key doesn't exist */
2576 if (W_ERROR_EQUAL(result
, WERR_FILE_NOT_FOUND
)) {
2581 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2582 key
, win_errstr(result
)));
2586 if (is_valid_policy_hnd(&key_hnd
)) {
2587 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
2590 if (key
== NULL
|| key
[0] == '\0') {
2593 keyname
= talloc_asprintf(tmp_ctx
,
2597 if (keyname
== NULL
) {
2598 result
= WERR_NOT_ENOUGH_MEMORY
;
2603 status
= dcerpc_winreg_delete_subkeys_recursive(tmp_ctx
,
2610 if (!NT_STATUS_IS_OK(status
)) {
2611 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2612 key
, nt_errstr(status
)));
2613 result
= ntstatus_to_werror(status
);
2617 if (!W_ERROR_IS_OK(result
)) {
2618 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2619 key
, win_errstr(result
)));
2624 if (is_valid_policy_hnd(&key_hnd
)) {
2625 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2627 if (is_valid_policy_hnd(&hive_hnd
)) {
2628 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2631 TALLOC_FREE(tmp_ctx
);
2635 WERROR
winreg_printer_update_changeid(TALLOC_CTX
*mem_ctx
,
2636 struct dcerpc_binding_handle
*winreg_handle
,
2637 const char *printer
)
2639 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2640 struct policy_handle hive_hnd
, key_hnd
;
2645 TALLOC_CTX
*tmp_ctx
;
2647 tmp_ctx
= talloc_stackframe();
2648 if (tmp_ctx
== NULL
) {
2649 return WERR_NOT_ENOUGH_MEMORY
;
2652 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2654 TALLOC_FREE(tmp_ctx
);
2655 return WERR_NOT_ENOUGH_MEMORY
;
2658 ZERO_STRUCT(hive_hnd
);
2659 ZERO_STRUCT(key_hnd
);
2661 result
= winreg_printer_openkey(tmp_ctx
,
2669 if (!W_ERROR_IS_OK(result
)) {
2670 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2671 path
, win_errstr(result
)));
2675 status
= dcerpc_winreg_set_dword(tmp_ctx
,
2679 winreg_printer_rev_changeid(),
2681 if (!NT_STATUS_IS_OK(status
)) {
2682 result
= ntstatus_to_werror(status
);
2684 if (!W_ERROR_IS_OK(result
)) {
2690 if (is_valid_policy_hnd(&key_hnd
)) {
2691 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2693 if (is_valid_policy_hnd(&hive_hnd
)) {
2694 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2697 TALLOC_FREE(tmp_ctx
);
2701 WERROR
winreg_printer_get_changeid(TALLOC_CTX
*mem_ctx
,
2702 struct dcerpc_binding_handle
*winreg_handle
,
2703 const char *printer
,
2704 uint32_t *pchangeid
)
2706 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2707 struct policy_handle hive_hnd
, key_hnd
;
2708 uint32_t changeid
= 0;
2713 TALLOC_CTX
*tmp_ctx
;
2715 tmp_ctx
= talloc_stackframe();
2716 if (tmp_ctx
== NULL
) {
2717 return WERR_NOT_ENOUGH_MEMORY
;
2720 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2722 TALLOC_FREE(tmp_ctx
);
2723 return WERR_NOT_ENOUGH_MEMORY
;
2726 ZERO_STRUCT(hive_hnd
);
2727 ZERO_STRUCT(key_hnd
);
2729 result
= winreg_printer_openkey(tmp_ctx
,
2737 if (!W_ERROR_IS_OK(result
)) {
2738 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2739 path
, win_errstr(result
)));
2743 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path
));
2745 status
= dcerpc_winreg_query_dword(tmp_ctx
,
2751 if (!NT_STATUS_IS_OK(status
)) {
2752 result
= ntstatus_to_werror(status
);
2754 if (!W_ERROR_IS_OK(result
)) {
2759 *pchangeid
= changeid
;
2764 if (is_valid_policy_hnd(&key_hnd
)) {
2765 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2767 if (is_valid_policy_hnd(&hive_hnd
)) {
2768 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2771 TALLOC_FREE(tmp_ctx
);
2776 * The special behaviour of the spoolss forms is documented at the website:
2778 * Managing Win32 Printserver Forms
2779 * http://unixwiz.net/techtips/winspooler-forms.html
2782 WERROR
winreg_printer_addform1(TALLOC_CTX
*mem_ctx
,
2783 struct dcerpc_binding_handle
*winreg_handle
,
2784 struct spoolss_AddFormInfo1
*form
)
2786 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2787 struct policy_handle hive_hnd
, key_hnd
;
2788 struct winreg_String wvalue
= { 0, };
2790 uint32_t num_info
= 0;
2791 union spoolss_FormInfo
*info
= NULL
;
2796 TALLOC_CTX
*tmp_ctx
;
2798 tmp_ctx
= talloc_stackframe();
2799 if (tmp_ctx
== NULL
) {
2800 return WERR_NOT_ENOUGH_MEMORY
;
2803 ZERO_STRUCT(hive_hnd
);
2804 ZERO_STRUCT(key_hnd
);
2806 result
= winreg_printer_openkey(tmp_ctx
,
2808 TOP_LEVEL_CONTROL_FORMS_KEY
,
2814 if (!W_ERROR_IS_OK(result
)) {
2815 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2816 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2820 result
= winreg_printer_enumforms1(tmp_ctx
, winreg_handle
,
2822 if (!W_ERROR_IS_OK(result
)) {
2823 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2824 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2828 /* If form name already exists or is builtin return ALREADY_EXISTS */
2829 for (i
= 0; i
< num_info
; i
++) {
2830 if (strequal(info
[i
].info1
.form_name
, form
->form_name
)) {
2831 result
= WERR_FILE_EXISTS
;
2836 wvalue
.name
= form
->form_name
;
2838 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
2839 SIVAL(blob
.data
, 0, form
->size
.width
);
2840 SIVAL(blob
.data
, 4, form
->size
.height
);
2841 SIVAL(blob
.data
, 8, form
->area
.left
);
2842 SIVAL(blob
.data
, 12, form
->area
.top
);
2843 SIVAL(blob
.data
, 16, form
->area
.right
);
2844 SIVAL(blob
.data
, 20, form
->area
.bottom
);
2845 SIVAL(blob
.data
, 24, num_info
+ 1); /* FIXME */
2846 SIVAL(blob
.data
, 28, form
->flags
);
2848 status
= dcerpc_winreg_SetValue(winreg_handle
,
2856 if (!NT_STATUS_IS_OK(status
)) {
2857 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2858 wvalue
.name
, nt_errstr(status
)));
2859 result
= ntstatus_to_werror(status
);
2863 if (is_valid_policy_hnd(&key_hnd
)) {
2864 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2866 if (is_valid_policy_hnd(&hive_hnd
)) {
2867 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2871 TALLOC_FREE(tmp_ctx
);
2875 WERROR
winreg_printer_enumforms1(TALLOC_CTX
*mem_ctx
,
2876 struct dcerpc_binding_handle
*winreg_handle
,
2877 uint32_t *pnum_info
,
2878 union spoolss_FormInfo
**pinfo
)
2880 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2881 struct policy_handle hive_hnd
, key_hnd
;
2882 union spoolss_FormInfo
*info
;
2883 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2884 uint32_t num_values
= 0;
2885 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2890 const char **enum_names
= NULL
;
2891 enum winreg_Type
*enum_types
= NULL
;
2892 DATA_BLOB
*enum_data_blobs
= NULL
;
2893 TALLOC_CTX
*tmp_ctx
;
2895 tmp_ctx
= talloc_stackframe();
2896 if (tmp_ctx
== NULL
) {
2897 return WERR_NOT_ENOUGH_MEMORY
;
2900 ZERO_STRUCT(hive_hnd
);
2901 ZERO_STRUCT(key_hnd
);
2903 result
= winreg_printer_openkey(tmp_ctx
,
2905 TOP_LEVEL_CONTROL_FORMS_KEY
,
2911 if (!W_ERROR_IS_OK(result
)) {
2912 /* key doesn't exist */
2913 if (W_ERROR_EQUAL(result
, WERR_FILE_NOT_FOUND
)) {
2918 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
2919 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2923 status
= dcerpc_winreg_enumvals(tmp_ctx
,
2931 if (!NT_STATUS_IS_OK(status
)){
2932 result
= ntstatus_to_werror(status
);
2935 if (!W_ERROR_IS_OK(result
)) {
2936 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2937 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2941 enum_values
= talloc_zero_array(tmp_ctx
,
2942 struct spoolss_PrinterEnumValues
,
2944 if (enum_values
== NULL
){
2945 result
= WERR_NOT_ENOUGH_MEMORY
;
2949 for (i
= 0; i
< num_values
; i
++){
2950 enum_values
[i
].value_name
= enum_names
[i
];
2951 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
2952 enum_values
[i
].type
= enum_types
[i
];
2953 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
2954 enum_values
[i
].data
= NULL
;
2955 if (enum_values
[i
].data_length
!= 0){
2956 enum_values
[i
].data
= &enum_data_blobs
[i
];
2960 if (!W_ERROR_IS_OK(result
)) {
2961 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2962 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2966 info
= talloc_array(tmp_ctx
, union spoolss_FormInfo
, num_builtin
+ num_values
);
2968 result
= WERR_NOT_ENOUGH_MEMORY
;
2972 /* Enumerate BUILTIN forms */
2973 for (i
= 0; i
< num_builtin
; i
++) {
2974 info
[i
].info1
= builtin_forms1
[i
];
2977 /* Enumerate registry forms */
2978 for (i
= 0; i
< num_values
; i
++) {
2979 union spoolss_FormInfo val
;
2981 if (enum_values
[i
].type
!= REG_BINARY
||
2982 enum_values
[i
].data_length
!= 32) {
2986 val
.info1
.form_name
= talloc_strdup(info
, enum_values
[i
].value_name
);
2987 if (val
.info1
.form_name
== NULL
) {
2988 result
= WERR_NOT_ENOUGH_MEMORY
;
2992 val
.info1
.size
.width
= IVAL(enum_values
[i
].data
->data
, 0);
2993 val
.info1
.size
.height
= IVAL(enum_values
[i
].data
->data
, 4);
2994 val
.info1
.area
.left
= IVAL(enum_values
[i
].data
->data
, 8);
2995 val
.info1
.area
.top
= IVAL(enum_values
[i
].data
->data
, 12);
2996 val
.info1
.area
.right
= IVAL(enum_values
[i
].data
->data
, 16);
2997 val
.info1
.area
.bottom
= IVAL(enum_values
[i
].data
->data
, 20);
2998 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
2999 val
.info1
.flags
= (enum spoolss_FormFlags
) IVAL(enum_values
[i
].data
->data
, 28);
3001 info
[i
+ num_builtin
] = val
;
3004 *pnum_info
= num_builtin
+ num_values
;
3006 *pinfo
= talloc_move(mem_ctx
, &info
);
3010 if (is_valid_policy_hnd(&key_hnd
)) {
3011 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3013 if (is_valid_policy_hnd(&hive_hnd
)) {
3014 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3017 TALLOC_FREE(enum_values
);
3018 TALLOC_FREE(tmp_ctx
);
3022 WERROR
winreg_printer_deleteform1(TALLOC_CTX
*mem_ctx
,
3023 struct dcerpc_binding_handle
*winreg_handle
,
3024 const char *form_name
)
3026 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3027 struct policy_handle hive_hnd
, key_hnd
;
3028 struct winreg_String wvalue
= { 0, };
3029 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3031 WERROR result
= WERR_OK
;
3034 TALLOC_CTX
*tmp_ctx
;
3036 for (i
= 0; i
< num_builtin
; i
++) {
3037 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3038 return WERR_INVALID_PARAMETER
;
3042 tmp_ctx
= talloc_stackframe();
3043 if (tmp_ctx
== NULL
) {
3044 return WERR_NOT_ENOUGH_MEMORY
;
3047 ZERO_STRUCT(hive_hnd
);
3048 ZERO_STRUCT(key_hnd
);
3050 result
= winreg_printer_openkey(tmp_ctx
,
3052 TOP_LEVEL_CONTROL_FORMS_KEY
,
3058 if (!W_ERROR_IS_OK(result
)) {
3059 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3060 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3061 if (W_ERROR_EQUAL(result
, WERR_FILE_NOT_FOUND
)) {
3062 result
= WERR_INVALID_FORM_NAME
;
3067 wvalue
.name
= form_name
;
3068 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
3073 if (!NT_STATUS_IS_OK(status
)) {
3074 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3075 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3076 wvalue
.name
, nt_errstr(status
)));
3077 result
= ntstatus_to_werror(status
);
3081 if (W_ERROR_EQUAL(result
, WERR_FILE_NOT_FOUND
)) {
3082 result
= WERR_INVALID_FORM_NAME
;
3086 if (is_valid_policy_hnd(&key_hnd
)) {
3087 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3089 if (is_valid_policy_hnd(&hive_hnd
)) {
3090 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
= { 0, };
3104 struct policy_handle key_hnd
= { 0, };
3105 struct winreg_String wvalue
= { 0, };
3107 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3111 TALLOC_CTX
*tmp_ctx
= NULL
;
3113 for (i
= 0; i
< num_builtin
; i
++) {
3114 if (strequal(builtin_forms1
[i
].form_name
, form
->form_name
)) {
3115 result
= WERR_INVALID_PARAMETER
;
3120 tmp_ctx
= talloc_stackframe();
3121 if (tmp_ctx
== NULL
) {
3122 return WERR_NOT_ENOUGH_MEMORY
;
3125 ZERO_STRUCT(hive_hnd
);
3126 ZERO_STRUCT(key_hnd
);
3128 result
= winreg_printer_openkey(tmp_ctx
,
3130 TOP_LEVEL_CONTROL_FORMS_KEY
,
3136 if (!W_ERROR_IS_OK(result
)) {
3137 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3138 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3142 /* If form_name != form->form_name then we renamed the form */
3143 if (strequal(form_name
, form
->form_name
)) {
3144 result
= winreg_printer_deleteform1(tmp_ctx
, winreg_handle
,
3146 if (!W_ERROR_IS_OK(result
)) {
3147 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3148 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3153 wvalue
.name
= form
->form_name
;
3155 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
3156 SIVAL(blob
.data
, 0, form
->size
.width
);
3157 SIVAL(blob
.data
, 4, form
->size
.height
);
3158 SIVAL(blob
.data
, 8, form
->area
.left
);
3159 SIVAL(blob
.data
, 12, form
->area
.top
);
3160 SIVAL(blob
.data
, 16, form
->area
.right
);
3161 SIVAL(blob
.data
, 20, form
->area
.bottom
);
3162 SIVAL(blob
.data
, 24, 42);
3163 SIVAL(blob
.data
, 28, form
->flags
);
3165 status
= dcerpc_winreg_SetValue(winreg_handle
,
3173 if (!NT_STATUS_IS_OK(status
)) {
3174 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3175 wvalue
.name
, nt_errstr(status
)));
3176 result
= ntstatus_to_werror(status
);
3180 if (winreg_handle
!= NULL
) {
3183 if (is_valid_policy_hnd(&key_hnd
)) {
3184 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3186 if (is_valid_policy_hnd(&hive_hnd
)) {
3187 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3191 TALLOC_FREE(tmp_ctx
);
3195 WERROR
winreg_printer_getform1(TALLOC_CTX
*mem_ctx
,
3196 struct dcerpc_binding_handle
*winreg_handle
,
3197 const char *form_name
,
3198 struct spoolss_FormInfo1
*r
)
3200 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3201 struct policy_handle hive_hnd
, key_hnd
;
3202 struct winreg_String wvalue
;
3203 enum winreg_Type type_in
= REG_NONE
;
3204 uint8_t *data_in
= NULL
;
3205 uint32_t data_in_size
= 0;
3206 uint32_t value_len
= 0;
3207 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3212 TALLOC_CTX
*tmp_ctx
;
3214 /* check builtin forms first */
3215 for (i
= 0; i
< num_builtin
; i
++) {
3216 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3217 *r
= builtin_forms1
[i
];
3222 tmp_ctx
= talloc_stackframe();
3223 if (tmp_ctx
== NULL
) {
3224 return WERR_NOT_ENOUGH_MEMORY
;
3227 ZERO_STRUCT(hive_hnd
);
3228 ZERO_STRUCT(key_hnd
);
3230 result
= winreg_printer_openkey(tmp_ctx
,
3232 TOP_LEVEL_CONTROL_FORMS_KEY
,
3238 if (!W_ERROR_IS_OK(result
)) {
3239 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3240 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3244 wvalue
.name
= form_name
;
3247 * call QueryValue once with data == NULL to get the
3248 * needed memory size to be allocated, then allocate
3249 * data buffer and call again.
3251 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3260 if (!NT_STATUS_IS_OK(status
)) {
3261 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3262 wvalue
.name
, nt_errstr(status
)));
3263 result
= ntstatus_to_werror(status
);
3266 if (!W_ERROR_IS_OK(result
)) {
3270 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
3271 if (data_in
== NULL
) {
3272 result
= WERR_NOT_ENOUGH_MEMORY
;
3277 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3286 if (!NT_STATUS_IS_OK(status
)) {
3287 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3288 wvalue
.name
, nt_errstr(status
)));
3289 result
= ntstatus_to_werror(status
);
3292 if (!W_ERROR_IS_OK(result
)) {
3296 r
->form_name
= talloc_strdup(mem_ctx
, form_name
);
3297 if (r
->form_name
== NULL
) {
3298 result
= WERR_NOT_ENOUGH_MEMORY
;
3302 r
->size
.width
= IVAL(data_in
, 0);
3303 r
->size
.height
= IVAL(data_in
, 4);
3304 r
->area
.left
= IVAL(data_in
, 8);
3305 r
->area
.top
= IVAL(data_in
, 12);
3306 r
->area
.right
= IVAL(data_in
, 16);
3307 r
->area
.bottom
= IVAL(data_in
, 20);
3308 /* skip index IVAL(data_in, 24)));*/
3309 r
->flags
= (enum spoolss_FormFlags
) IVAL(data_in
, 28);
3313 if (is_valid_policy_hnd(&key_hnd
)) {
3314 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3316 if (is_valid_policy_hnd(&hive_hnd
)) {
3317 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3320 TALLOC_FREE(tmp_ctx
);
3324 WERROR
winreg_add_driver(TALLOC_CTX
*mem_ctx
,
3325 struct dcerpc_binding_handle
*winreg_handle
,
3326 struct spoolss_AddDriverInfoCtr
*r
,
3327 const char **driver_name
,
3328 uint32_t *driver_version
)
3330 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3331 struct policy_handle hive_hnd
, key_hnd
;
3332 struct spoolss_DriverInfo8 info8
;
3333 TALLOC_CTX
*tmp_ctx
= NULL
;
3337 ZERO_STRUCT(hive_hnd
);
3338 ZERO_STRUCT(key_hnd
);
3341 if (!driver_info_ctr_to_info8(r
, &info8
)) {
3342 result
= WERR_INVALID_PARAMETER
;
3346 tmp_ctx
= talloc_stackframe();
3347 if (tmp_ctx
== NULL
) {
3348 return WERR_NOT_ENOUGH_MEMORY
;
3351 result
= winreg_printer_opendriver(tmp_ctx
,
3359 if (!W_ERROR_IS_OK(result
)) {
3360 DEBUG(0, ("winreg_add_driver: "
3361 "Could not open driver key (%s,%s,%d): %s\n",
3362 info8
.driver_name
, info8
.architecture
,
3363 info8
.version
, win_errstr(result
)));
3367 /* TODO: "Attributes" ? */
3369 status
= dcerpc_winreg_set_dword(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_sz(tmp_ctx
,
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_sz(tmp_ctx
,
3411 "Configuration File",
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_sz(tmp_ctx
,
3427 if (!NT_STATUS_IS_OK(status
)) {
3428 result
= ntstatus_to_werror(status
);
3430 if (!W_ERROR_IS_OK(result
)) {
3434 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3438 info8
.dependent_files
,
3440 if (!NT_STATUS_IS_OK(status
)) {
3441 result
= ntstatus_to_werror(status
);
3443 if (!W_ERROR_IS_OK(result
)) {
3447 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3453 if (!NT_STATUS_IS_OK(status
)) {
3454 result
= ntstatus_to_werror(status
);
3456 if (!W_ERROR_IS_OK(result
)) {
3460 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3464 info8
.default_datatype
,
3466 if (!NT_STATUS_IS_OK(status
)) {
3467 result
= ntstatus_to_werror(status
);
3469 if (!W_ERROR_IS_OK(result
)) {
3473 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3475 &key_hnd
, "Previous Names",
3476 info8
.previous_names
,
3478 if (!NT_STATUS_IS_OK(status
)) {
3479 result
= ntstatus_to_werror(status
);
3481 if (!W_ERROR_IS_OK(result
)) {
3485 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3486 &key_hnd
, "DriverDate",
3488 if (!W_ERROR_IS_OK(result
)) {
3492 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
,
3493 &key_hnd
, "DriverVersion",
3494 info8
.driver_version
);
3495 if (!W_ERROR_IS_OK(result
)) {
3499 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3503 info8
.manufacturer_name
,
3505 if (!NT_STATUS_IS_OK(status
)) {
3506 result
= ntstatus_to_werror(status
);
3508 if (!W_ERROR_IS_OK(result
)) {
3512 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3516 info8
.manufacturer_url
,
3518 if (!NT_STATUS_IS_OK(status
)) {
3519 result
= ntstatus_to_werror(status
);
3521 if (!W_ERROR_IS_OK(result
)) {
3525 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3531 if (!NT_STATUS_IS_OK(status
)) {
3532 result
= ntstatus_to_werror(status
);
3534 if (!W_ERROR_IS_OK(result
)) {
3538 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3544 if (!NT_STATUS_IS_OK(status
)) {
3545 result
= ntstatus_to_werror(status
);
3547 if (!W_ERROR_IS_OK(result
)) {
3551 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3555 info8
.print_processor
,
3557 if (!NT_STATUS_IS_OK(status
)) {
3558 result
= ntstatus_to_werror(status
);
3560 if (!W_ERROR_IS_OK(result
)) {
3564 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3570 if (!NT_STATUS_IS_OK(status
)) {
3571 result
= ntstatus_to_werror(status
);
3573 if (!W_ERROR_IS_OK(result
)) {
3577 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3581 info8
.color_profiles
,
3583 if (!NT_STATUS_IS_OK(status
)) {
3584 result
= ntstatus_to_werror(status
);
3586 if (!W_ERROR_IS_OK(result
)) {
3590 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3596 if (!NT_STATUS_IS_OK(status
)) {
3597 result
= ntstatus_to_werror(status
);
3599 if (!W_ERROR_IS_OK(result
)) {
3603 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3606 "PrinterDriverAttributes",
3607 info8
.printer_driver_attributes
,
3609 if (!NT_STATUS_IS_OK(status
)) {
3610 result
= ntstatus_to_werror(status
);
3612 if (!W_ERROR_IS_OK(result
)) {
3616 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3620 info8
.core_driver_dependencies
,
3622 if (!NT_STATUS_IS_OK(status
)) {
3623 result
= ntstatus_to_werror(status
);
3625 if (!W_ERROR_IS_OK(result
)) {
3629 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3630 &key_hnd
, "MinInboxDriverVerDate",
3631 info8
.min_inbox_driver_ver_date
);
3632 if (!W_ERROR_IS_OK(result
)) {
3636 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
, &key_hnd
,
3637 "MinInboxDriverVerVersion",
3638 info8
.min_inbox_driver_ver_version
);
3639 if (!W_ERROR_IS_OK(result
)) {
3643 *driver_name
= info8
.driver_name
;
3644 *driver_version
= info8
.version
;
3647 if (winreg_handle
!= NULL
) {
3650 if (is_valid_policy_hnd(&key_hnd
)) {
3651 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3653 if (is_valid_policy_hnd(&hive_hnd
)) {
3654 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3658 TALLOC_FREE(tmp_ctx
);
3662 WERROR
winreg_get_driver(TALLOC_CTX
*mem_ctx
,
3663 struct dcerpc_binding_handle
*winreg_handle
,
3664 const char *architecture
,
3665 const char *driver_name
,
3666 uint32_t driver_version
,
3667 struct spoolss_DriverInfo8
**_info8
)
3669 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3670 struct policy_handle hive_hnd
, key_hnd
;
3671 struct spoolss_DriverInfo8 i8
, *info8
;
3672 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
3673 struct spoolss_PrinterEnumValues
*v
;
3674 uint32_t num_values
= 0;
3675 TALLOC_CTX
*tmp_ctx
;
3679 const char **enum_names
= NULL
;
3680 enum winreg_Type
*enum_types
= NULL
;
3681 DATA_BLOB
*enum_data_blobs
= NULL
;
3683 ZERO_STRUCT(hive_hnd
);
3684 ZERO_STRUCT(key_hnd
);
3687 tmp_ctx
= talloc_stackframe();
3688 if (tmp_ctx
== NULL
) {
3689 return WERR_NOT_ENOUGH_MEMORY
;
3692 if (driver_version
== DRIVER_ANY_VERSION
) {
3693 /* look for Win2k first and then for NT4 */
3694 result
= winreg_printer_opendriver(tmp_ctx
,
3702 if (!W_ERROR_IS_OK(result
)) {
3703 result
= winreg_printer_opendriver(tmp_ctx
,
3713 /* ok normal case */
3714 result
= winreg_printer_opendriver(tmp_ctx
,
3723 if (!W_ERROR_IS_OK(result
)) {
3724 DEBUG(5, ("winreg_get_driver: "
3725 "Could not open driver key (%s,%s,%d): %s\n",
3726 driver_name
, architecture
,
3727 driver_version
, win_errstr(result
)));
3731 status
= dcerpc_winreg_enumvals(tmp_ctx
,
3739 if (!NT_STATUS_IS_OK(status
)){
3740 result
= ntstatus_to_werror(status
);
3743 if (!W_ERROR_IS_OK(result
)) {
3744 DEBUG(0, ("winreg_get_driver: "
3745 "Could not enumerate values for (%s,%s,%d): %s\n",
3746 driver_name
, architecture
,
3747 driver_version
, win_errstr(result
)));
3751 enum_values
= talloc_zero_array(tmp_ctx
,
3752 struct spoolss_PrinterEnumValues
,
3754 if (enum_values
== NULL
){
3755 result
= WERR_NOT_ENOUGH_MEMORY
;
3759 for (i
= 0; i
< num_values
; i
++){
3760 enum_values
[i
].value_name
= enum_names
[i
];
3761 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
3762 enum_values
[i
].type
= enum_types
[i
];
3763 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
3764 enum_values
[i
].data
= NULL
;
3765 if (enum_values
[i
].data_length
!= 0){
3766 enum_values
[i
].data
= &enum_data_blobs
[i
];
3770 info8
= talloc_zero(tmp_ctx
, struct spoolss_DriverInfo8
);
3771 if (info8
== NULL
) {
3772 result
= WERR_NOT_ENOUGH_MEMORY
;
3776 info8
->driver_name
= talloc_strdup(info8
, driver_name
);
3777 if (info8
->driver_name
== NULL
) {
3778 result
= WERR_NOT_ENOUGH_MEMORY
;
3782 info8
->architecture
= talloc_strdup(info8
, architecture
);
3783 if (info8
->architecture
== NULL
) {
3784 result
= WERR_NOT_ENOUGH_MEMORY
;
3790 for (i
= 0; i
< num_values
; i
++) {
3791 const char *tmp_str
;
3794 v
= &enum_values
[i
];
3796 result
= winreg_enumval_to_dword(info8
, v
,
3799 if (W_ERROR_IS_OK(result
)) {
3800 info8
->version
= (enum spoolss_DriverOSVersion
) tmp
;
3802 CHECK_ERROR(result
);
3804 result
= winreg_enumval_to_sz(info8
, v
,
3806 &info8
->driver_path
);
3807 CHECK_ERROR(result
);
3809 result
= winreg_enumval_to_sz(info8
, v
,
3812 CHECK_ERROR(result
);
3814 result
= winreg_enumval_to_sz(info8
, v
,
3815 "Configuration File",
3816 &info8
->config_file
);
3817 CHECK_ERROR(result
);
3819 result
= winreg_enumval_to_sz(info8
, v
,
3822 CHECK_ERROR(result
);
3824 result
= winreg_enumval_to_multi_sz(info8
, v
,
3826 &info8
->dependent_files
);
3827 CHECK_ERROR(result
);
3829 result
= winreg_enumval_to_sz(info8
, v
,
3831 &info8
->monitor_name
);
3832 CHECK_ERROR(result
);
3834 result
= winreg_enumval_to_sz(info8
, v
,
3836 &info8
->default_datatype
);
3837 CHECK_ERROR(result
);
3839 result
= winreg_enumval_to_multi_sz(info8
, v
,
3841 &info8
->previous_names
);
3842 CHECK_ERROR(result
);
3844 result
= winreg_enumval_to_sz(info8
, v
,
3847 if (W_ERROR_IS_OK(result
)) {
3848 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3849 &info8
->driver_date
);
3851 CHECK_ERROR(result
);
3853 result
= winreg_enumval_to_sz(info8
, v
,
3856 if (W_ERROR_IS_OK(result
)) {
3857 result
= winreg_printer_ver_to_qword(tmp_str
,
3858 &info8
->driver_version
);
3860 CHECK_ERROR(result
);
3862 result
= winreg_enumval_to_sz(info8
, v
,
3864 &info8
->manufacturer_name
);
3865 CHECK_ERROR(result
);
3867 result
= winreg_enumval_to_sz(info8
, v
,
3869 &info8
->manufacturer_url
);
3870 CHECK_ERROR(result
);
3872 result
= winreg_enumval_to_sz(info8
, v
,
3874 &info8
->hardware_id
);
3875 CHECK_ERROR(result
);
3877 result
= winreg_enumval_to_sz(info8
, v
,
3880 CHECK_ERROR(result
);
3882 result
= winreg_enumval_to_sz(info8
, v
,
3884 &info8
->print_processor
);
3885 CHECK_ERROR(result
);
3887 result
= winreg_enumval_to_sz(info8
, v
,
3889 &info8
->vendor_setup
);
3890 CHECK_ERROR(result
);
3892 result
= winreg_enumval_to_multi_sz(info8
, v
,
3894 &info8
->color_profiles
);
3895 CHECK_ERROR(result
);
3897 result
= winreg_enumval_to_sz(info8
, v
,
3900 CHECK_ERROR(result
);
3902 result
= winreg_enumval_to_dword(info8
, v
,
3903 "PrinterDriverAttributes",
3904 &info8
->printer_driver_attributes
);
3905 CHECK_ERROR(result
);
3907 result
= winreg_enumval_to_multi_sz(info8
, v
,
3909 &info8
->core_driver_dependencies
);
3910 CHECK_ERROR(result
);
3912 result
= winreg_enumval_to_sz(info8
, v
,
3913 "MinInboxDriverVerDate",
3915 if (W_ERROR_IS_OK(result
)) {
3916 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3917 &info8
->min_inbox_driver_ver_date
);
3919 CHECK_ERROR(result
);
3921 result
= winreg_enumval_to_sz(info8
, v
,
3922 "MinInboxDriverVerVersion",
3924 if (W_ERROR_IS_OK(result
)) {
3925 result
= winreg_printer_ver_to_qword(tmp_str
,
3926 &info8
->min_inbox_driver_ver_version
);
3928 CHECK_ERROR(result
);
3931 if (!W_ERROR_IS_OK(result
)) {
3932 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3933 "for %s: %s\n", v
->value_name
,
3934 win_errstr(result
)));
3938 *_info8
= talloc_steal(mem_ctx
, info8
);
3941 if (winreg_handle
!= NULL
) {
3944 if (is_valid_policy_hnd(&key_hnd
)) {
3945 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3947 if (is_valid_policy_hnd(&hive_hnd
)) {
3948 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3952 TALLOC_FREE(tmp_ctx
);
3956 WERROR
winreg_del_driver(TALLOC_CTX
*mem_ctx
,
3957 struct dcerpc_binding_handle
*winreg_handle
,
3958 struct spoolss_DriverInfo8
*info8
,
3961 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3962 struct policy_handle hive_hnd
, key_hnd
;
3963 TALLOC_CTX
*tmp_ctx
;
3968 ZERO_STRUCT(hive_hnd
);
3969 ZERO_STRUCT(key_hnd
);
3971 tmp_ctx
= talloc_stackframe();
3972 if (tmp_ctx
== NULL
) {
3973 return WERR_NOT_ENOUGH_MEMORY
;
3976 /* test that the key exists */
3977 result
= winreg_printer_opendriver(tmp_ctx
,
3980 info8
->architecture
,
3985 if (!W_ERROR_IS_OK(result
)) {
3986 /* key doesn't exist */
3987 if (W_ERROR_EQUAL(result
, WERR_FILE_NOT_FOUND
)) {
3992 DEBUG(5, ("winreg_del_driver: "
3993 "Could not open driver (%s,%s,%u): %s\n",
3994 info8
->driver_name
, info8
->architecture
,
3995 version
, win_errstr(result
)));
4000 if (is_valid_policy_hnd(&key_hnd
)) {
4001 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
4004 key_name
= talloc_asprintf(tmp_ctx
,
4005 "%s\\Environments\\%s\\Drivers\\Version-%u\\%s",
4006 TOP_LEVEL_CONTROL_KEY
,
4007 info8
->architecture
, version
,
4008 info8
->driver_name
);
4009 if (key_name
== NULL
) {
4010 result
= WERR_NOT_ENOUGH_MEMORY
;
4014 status
= dcerpc_winreg_delete_subkeys_recursive(tmp_ctx
,
4021 if (!NT_STATUS_IS_OK(status
)){
4022 DEBUG(0, ("winreg_del_driver: "
4023 "Could not open driver (%s,%s,%u): %s\n",
4024 info8
->driver_name
, info8
->architecture
,
4025 version
, nt_errstr(status
)));
4029 if (!W_ERROR_IS_OK(result
)) {
4030 DEBUG(0, ("winreg_del_driver: "
4031 "Could not open driver (%s,%s,%u): %s\n",
4032 info8
->driver_name
, info8
->architecture
,
4033 version
, win_errstr(result
)));
4039 if (winreg_handle
!= NULL
) {
4042 if (is_valid_policy_hnd(&key_hnd
)) {
4043 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4045 if (is_valid_policy_hnd(&hive_hnd
)) {
4046 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4050 TALLOC_FREE(tmp_ctx
);
4054 WERROR
winreg_get_driver_list(TALLOC_CTX
*mem_ctx
,
4055 struct dcerpc_binding_handle
*winreg_handle
,
4056 const char *architecture
,
4058 uint32_t *num_drivers
,
4059 const char ***drivers_p
)
4061 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4062 struct policy_handle hive_hnd
, key_hnd
;
4063 const char **drivers
;
4064 TALLOC_CTX
*tmp_ctx
;
4071 ZERO_STRUCT(hive_hnd
);
4072 ZERO_STRUCT(key_hnd
);
4074 tmp_ctx
= talloc_stackframe();
4075 if (tmp_ctx
== NULL
) {
4076 return WERR_NOT_ENOUGH_MEMORY
;
4079 /* use NULL for the driver name so we open the key that is
4080 * parent of all drivers for this architecture and version */
4081 result
= winreg_printer_opendriver(tmp_ctx
,
4089 if (!W_ERROR_IS_OK(result
)) {
4090 DEBUG(5, ("winreg_get_driver_list: "
4091 "Could not open key (%s,%u): %s\n",
4092 architecture
, version
, win_errstr(result
)));
4097 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
4103 if (!NT_STATUS_IS_OK(status
)) {
4104 result
= ntstatus_to_werror(status
);
4106 if (!W_ERROR_IS_OK(result
)) {
4107 DEBUG(0, ("winreg_get_driver_list: "
4108 "Could not enumerate drivers for (%s,%u): %s\n",
4109 architecture
, version
, win_errstr(result
)));
4113 *drivers_p
= talloc_steal(mem_ctx
, drivers
);
4117 if (winreg_handle
!= NULL
) {
4120 if (is_valid_policy_hnd(&key_hnd
)) {
4121 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4123 if (is_valid_policy_hnd(&hive_hnd
)) {
4124 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4128 TALLOC_FREE(tmp_ctx
);
4132 WERROR
winreg_get_core_driver(TALLOC_CTX
*mem_ctx
,
4133 struct dcerpc_binding_handle
*winreg_handle
,
4134 const char *architecture
,
4135 const struct GUID
*core_driver_guid
,
4136 struct spoolss_CorePrinterDriver
**_core_printer_driver
)
4138 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4139 struct policy_handle hive_hnd
, key_hnd
;
4140 struct spoolss_CorePrinterDriver
*c
;
4141 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
4142 struct spoolss_PrinterEnumValues
*v
;
4143 uint32_t num_values
= 0;
4144 TALLOC_CTX
*tmp_ctx
;
4148 const char *guid_str
;
4150 const char **enum_names
= NULL
;
4151 enum winreg_Type
*enum_types
= NULL
;
4152 DATA_BLOB
*enum_data_blobs
= NULL
;
4154 ZERO_STRUCT(hive_hnd
);
4155 ZERO_STRUCT(key_hnd
);
4157 tmp_ctx
= talloc_stackframe();
4158 if (tmp_ctx
== NULL
) {
4159 return WERR_NOT_ENOUGH_MEMORY
;
4162 path
= talloc_asprintf(tmp_ctx
, "%s\\%s\\CorePrinterDrivers",
4163 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY
,
4166 result
= WERR_NOT_ENOUGH_MEMORY
;
4170 guid_str
= GUID_string2(tmp_ctx
, core_driver_guid
);
4171 if (guid_str
== NULL
) {
4172 result
= WERR_NOT_ENOUGH_MEMORY
;
4176 result
= winreg_printer_openkey(tmp_ctx
,
4185 if (!W_ERROR_IS_OK(result
)) {
4186 DEBUG(5, ("winreg_get_core_driver: "
4187 "Could not open core driver key (%s,%s): %s\n",
4188 guid_str
, architecture
, win_errstr(result
)));
4192 status
= dcerpc_winreg_enumvals(tmp_ctx
,
4200 if (!NT_STATUS_IS_OK(status
)){
4201 result
= ntstatus_to_werror(status
);
4204 if (!W_ERROR_IS_OK(result
)) {
4205 DEBUG(0, ("winreg_get_core_driver: "
4206 "Could not enumerate values for (%s,%s): %s\n",
4207 guid_str
, architecture
, win_errstr(result
)));
4211 enum_values
= talloc_zero_array(tmp_ctx
,
4212 struct spoolss_PrinterEnumValues
,
4214 if (enum_values
== NULL
){
4215 result
= WERR_NOT_ENOUGH_MEMORY
;
4219 for (i
= 0; i
< num_values
; i
++){
4220 enum_values
[i
].value_name
= enum_names
[i
];
4221 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
4222 enum_values
[i
].type
= enum_types
[i
];
4223 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
4224 enum_values
[i
].data
= NULL
;
4225 if (enum_values
[i
].data_length
!= 0){
4226 enum_values
[i
].data
= &enum_data_blobs
[i
];
4230 c
= talloc_zero(tmp_ctx
, struct spoolss_CorePrinterDriver
);
4232 result
= WERR_NOT_ENOUGH_MEMORY
;
4236 c
->core_driver_guid
= *core_driver_guid
;
4240 for (i
= 0; i
< num_values
; i
++) {
4241 const char *tmp_str
;
4243 v
= &enum_values
[i
];
4245 result
= winreg_enumval_to_sz(c
, v
,
4248 CHECK_ERROR(result
);
4250 result
= winreg_enumval_to_sz(c
, v
,
4253 if (W_ERROR_IS_OK(result
)) {
4254 result
= winreg_printer_date_to_NTTIME(tmp_str
,
4257 CHECK_ERROR(result
);
4259 result
= winreg_enumval_to_sz(c
, v
,
4262 if (W_ERROR_IS_OK(result
)) {
4263 result
= winreg_printer_ver_to_qword(tmp_str
,
4264 &c
->driver_version
);
4266 CHECK_ERROR(result
);
4269 if (!W_ERROR_IS_OK(result
)) {
4270 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4271 "for %s: %s\n", v
->value_name
,
4272 win_errstr(result
)));
4276 *_core_printer_driver
= talloc_steal(mem_ctx
, c
);
4279 if (winreg_handle
!= NULL
) {
4282 if (is_valid_policy_hnd(&key_hnd
)) {
4283 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4285 if (is_valid_policy_hnd(&hive_hnd
)) {
4286 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4290 TALLOC_FREE(tmp_ctx
);
4294 WERROR
winreg_add_core_driver(TALLOC_CTX
*mem_ctx
,
4295 struct dcerpc_binding_handle
*winreg_handle
,
4296 const char *architecture
,
4297 const struct spoolss_CorePrinterDriver
*r
)
4299 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4300 struct policy_handle hive_hnd
, key_hnd
;
4301 TALLOC_CTX
*tmp_ctx
= NULL
;
4304 const char *guid_str
;
4306 ZERO_STRUCT(hive_hnd
);
4307 ZERO_STRUCT(key_hnd
);
4309 tmp_ctx
= talloc_stackframe();
4310 if (tmp_ctx
== NULL
) {
4311 return WERR_NOT_ENOUGH_MEMORY
;
4314 guid_str
= GUID_string2(tmp_ctx
, &r
->core_driver_guid
);
4315 if (guid_str
== NULL
) {
4316 result
= WERR_NOT_ENOUGH_MEMORY
;
4320 result
= winreg_printer_open_core_driver(tmp_ctx
,
4327 if (!W_ERROR_IS_OK(result
)) {
4328 DEBUG(0, ("winreg_add_core_driver: "
4329 "Could not open core driver key (%s,%s): %s\n",
4330 guid_str
, architecture
, win_errstr(result
)));
4334 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
4335 &key_hnd
, "DriverDate",
4337 if (!W_ERROR_IS_OK(result
)) {
4341 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
,
4342 &key_hnd
, "DriverVersion",
4344 if (!W_ERROR_IS_OK(result
)) {
4348 status
= dcerpc_winreg_set_sz(tmp_ctx
,
4354 if (!NT_STATUS_IS_OK(status
)) {
4355 result
= ntstatus_to_werror(status
);
4357 if (!W_ERROR_IS_OK(result
)) {
4363 if (winreg_handle
!= NULL
) {
4366 if (is_valid_policy_hnd(&key_hnd
)) {
4367 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4369 if (is_valid_policy_hnd(&hive_hnd
)) {
4370 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4374 TALLOC_FREE(tmp_ctx
);
4378 WERROR
winreg_add_driver_package(TALLOC_CTX
*mem_ctx
,
4379 struct dcerpc_binding_handle
*winreg_handle
,
4380 const char *package_id
,
4381 const char *architecture
,
4382 const char *driver_store_path
,
4383 const char *cab_path
)
4385 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4386 struct policy_handle hive_hnd
, key_hnd
;
4387 TALLOC_CTX
*tmp_ctx
= NULL
;
4392 ZERO_STRUCT(hive_hnd
);
4393 ZERO_STRUCT(key_hnd
);
4395 tmp_ctx
= talloc_stackframe();
4396 if (tmp_ctx
== NULL
) {
4397 return WERR_NOT_ENOUGH_MEMORY
;
4400 path
= talloc_asprintf(tmp_ctx
, "%s\\%s\\DriverPackages",
4401 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY
,
4404 result
= WERR_NOT_ENOUGH_MEMORY
;
4408 result
= winreg_printer_openkey(tmp_ctx
,
4411 package_id
, /* key */
4417 if (!W_ERROR_IS_OK(result
)) {
4418 DEBUG(0, ("winreg_add_driver_package: "
4419 "Could not open driver package key (%s,%s): %s\n",
4420 package_id
, architecture
, win_errstr(result
)));
4424 status
= dcerpc_winreg_set_sz(tmp_ctx
,
4430 if (!NT_STATUS_IS_OK(status
)) {
4431 result
= ntstatus_to_werror(status
);
4433 if (!W_ERROR_IS_OK(result
)) {
4437 status
= dcerpc_winreg_set_sz(tmp_ctx
,
4443 if (!NT_STATUS_IS_OK(status
)) {
4444 result
= ntstatus_to_werror(status
);
4446 if (!W_ERROR_IS_OK(result
)) {
4452 if (winreg_handle
!= NULL
) {
4455 if (is_valid_policy_hnd(&key_hnd
)) {
4456 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4458 if (is_valid_policy_hnd(&hive_hnd
)) {
4459 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4463 TALLOC_FREE(tmp_ctx
);
4467 WERROR
winreg_get_driver_package(TALLOC_CTX
*mem_ctx
,
4468 struct dcerpc_binding_handle
*winreg_handle
,
4469 const char *package_id
,
4470 const char *architecture
,
4471 const char **driver_store_path
,
4472 const char **cab_path
)
4474 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4475 struct policy_handle hive_hnd
, key_hnd
;
4476 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
4477 struct spoolss_PrinterEnumValues
*v
;
4478 uint32_t num_values
= 0;
4479 TALLOC_CTX
*tmp_ctx
;
4484 const char **enum_names
= NULL
;
4485 enum winreg_Type
*enum_types
= NULL
;
4486 DATA_BLOB
*enum_data_blobs
= NULL
;
4488 ZERO_STRUCT(hive_hnd
);
4489 ZERO_STRUCT(key_hnd
);
4491 tmp_ctx
= talloc_stackframe();
4492 if (tmp_ctx
== NULL
) {
4493 return WERR_NOT_ENOUGH_MEMORY
;
4496 path
= talloc_asprintf(tmp_ctx
, "%s\\%s\\DriverPackages",
4497 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY
,
4500 result
= WERR_NOT_ENOUGH_MEMORY
;
4504 result
= winreg_printer_openkey(tmp_ctx
,
4507 package_id
, /* key */
4513 if (!W_ERROR_IS_OK(result
)) {
4514 DEBUG(5, ("winreg_get_driver_package: "
4515 "Could not open driver package key (%s,%s): %s\n",
4516 package_id
, architecture
, win_errstr(result
)));
4520 status
= dcerpc_winreg_enumvals(tmp_ctx
,
4528 if (!NT_STATUS_IS_OK(status
)){
4529 result
= ntstatus_to_werror(status
);
4532 if (!W_ERROR_IS_OK(result
)) {
4533 DEBUG(0, ("winreg_get_driver_package: "
4534 "Could not enumerate values for (%s,%s): %s\n",
4535 package_id
, architecture
, win_errstr(result
)));
4539 enum_values
= talloc_zero_array(tmp_ctx
,
4540 struct spoolss_PrinterEnumValues
,
4542 if (enum_values
== NULL
){
4543 result
= WERR_NOT_ENOUGH_MEMORY
;
4547 for (i
= 0; i
< num_values
; i
++){
4548 enum_values
[i
].value_name
= enum_names
[i
];
4549 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
4550 enum_values
[i
].type
= enum_types
[i
];
4551 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
4552 enum_values
[i
].data
= NULL
;
4553 if (enum_values
[i
].data_length
!= 0){
4554 enum_values
[i
].data
= &enum_data_blobs
[i
];
4560 for (i
= 0; i
< num_values
; i
++) {
4562 v
= &enum_values
[i
];
4564 result
= winreg_enumval_to_sz(mem_ctx
, v
,
4567 CHECK_ERROR(result
);
4569 result
= winreg_enumval_to_sz(mem_ctx
, v
,
4572 CHECK_ERROR(result
);
4575 if (!W_ERROR_IS_OK(result
)) {
4576 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4577 "for %s: %s\n", v
->value_name
,
4578 win_errstr(result
)));
4584 if (winreg_handle
!= NULL
) {
4587 if (is_valid_policy_hnd(&key_hnd
)) {
4588 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4590 if (is_valid_policy_hnd(&hive_hnd
)) {
4591 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4595 TALLOC_FREE(tmp_ctx
);
4599 WERROR
winreg_del_driver_package(TALLOC_CTX
*mem_ctx
,
4600 struct dcerpc_binding_handle
*winreg_handle
,
4601 const char *package_id
,
4602 const char *architecture
)
4604 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4605 struct policy_handle hive_hnd
, key_hnd
;
4606 TALLOC_CTX
*tmp_ctx
;
4611 ZERO_STRUCT(hive_hnd
);
4612 ZERO_STRUCT(key_hnd
);
4614 tmp_ctx
= talloc_stackframe();
4615 if (tmp_ctx
== NULL
) {
4616 return WERR_NOT_ENOUGH_MEMORY
;
4619 path
= talloc_asprintf(tmp_ctx
, "%s\\%s\\DriverPackages",
4620 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY
,
4623 result
= WERR_NOT_ENOUGH_MEMORY
;
4627 result
= winreg_printer_openkey(tmp_ctx
,
4630 package_id
, /* key */
4635 if (!W_ERROR_IS_OK(result
)) {
4636 /* key doesn't exist */
4637 if (W_ERROR_EQUAL(result
, WERR_FILE_NOT_FOUND
)) {
4642 DEBUG(5, ("winreg_del_driver_package: "
4643 "Could not open driver package key (%s,%s): %s\n",
4644 package_id
, architecture
, win_errstr(result
)));
4649 if (is_valid_policy_hnd(&key_hnd
)) {
4650 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
4653 path
= talloc_asprintf(tmp_ctx
, "%s\\%s\\DriverPackages\\%s",
4654 TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY
,
4658 result
= WERR_NOT_ENOUGH_MEMORY
;
4662 status
= dcerpc_winreg_delete_subkeys_recursive(tmp_ctx
,
4668 if (!NT_STATUS_IS_OK(status
)) {
4669 result
= ntstatus_to_werror(status
);
4670 DEBUG(5, ("winreg_del_driver_package: "
4671 "Could not delete driver package key (%s,%s): %s\n",
4672 package_id
, architecture
, nt_errstr(status
)));
4676 if (!W_ERROR_IS_OK(result
)) {
4677 DEBUG(5, ("winreg_del_driver_package: "
4678 "Could not delete driver package key (%s,%s): %s\n",
4679 package_id
, architecture
, win_errstr(result
)));
4685 if (winreg_handle
!= NULL
) {
4688 if (is_valid_policy_hnd(&key_hnd
)) {
4689 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4691 if (is_valid_policy_hnd(&hive_hnd
)) {
4692 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4696 TALLOC_FREE(tmp_ctx
);