2 * Unix SMB/CIFS implementation.
4 * SPOOLSS RPC Pipe server / winreg client routines
6 * Copyright (c) 2010 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "nt_printing.h"
24 #include "../librpc/gen_ndr/ndr_spoolss.h"
25 #include "../librpc/gen_ndr/ndr_winreg_c.h"
26 #include "../librpc/gen_ndr/ndr_security.h"
28 #include "../libcli/security/security.h"
29 #include "rpc_client/cli_winreg.h"
30 #include "../libcli/registry/util_reg.h"
31 #include "rpc_client/cli_winreg_spoolss.h"
32 #include "printing/nt_printing_os2.h"
33 #include "rpc_client/init_spoolss.h"
35 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
36 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
37 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
38 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
40 #define EMPTY_STRING ""
42 #define FILL_STRING(mem_ctx, in, out) \
44 if (in && strlen(in)) { \
45 out = talloc_strdup(mem_ctx, in); \
47 out = talloc_strdup(mem_ctx, ""); \
49 W_ERROR_HAVE_NO_MEMORY(out); \
52 #define CHECK_ERROR(result) \
53 if (W_ERROR_IS_OK(result)) continue; \
54 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
55 if (!W_ERROR_IS_OK(result)) break
57 /* FLAGS, NAME, with, height, left, top, right, bottom */
58 static const struct spoolss_FormInfo1 builtin_forms1
[] = {
59 { SPOOLSS_FORM_BUILTIN
, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
60 { SPOOLSS_FORM_BUILTIN
, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
61 { SPOOLSS_FORM_BUILTIN
, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
62 { SPOOLSS_FORM_BUILTIN
, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
63 { SPOOLSS_FORM_BUILTIN
, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
64 { SPOOLSS_FORM_BUILTIN
, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
65 { SPOOLSS_FORM_BUILTIN
, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
66 { SPOOLSS_FORM_BUILTIN
, "A0", {0xcd528,0x122488},{0x0,0x0,0xcd528,0x122488} },
67 { SPOOLSS_FORM_BUILTIN
, "A1", {0x91050,0xcd528}, {0x0,0x0,0x91050,0xcd528} },
68 { SPOOLSS_FORM_BUILTIN
, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
69 { SPOOLSS_FORM_BUILTIN
, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
70 { SPOOLSS_FORM_BUILTIN
, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
71 { SPOOLSS_FORM_BUILTIN
, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
72 { SPOOLSS_FORM_BUILTIN
, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
73 { SPOOLSS_FORM_BUILTIN
, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
74 { SPOOLSS_FORM_BUILTIN
, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
75 { SPOOLSS_FORM_BUILTIN
, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
76 { SPOOLSS_FORM_BUILTIN
, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
77 { SPOOLSS_FORM_BUILTIN
, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
78 { SPOOLSS_FORM_BUILTIN
, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
79 { SPOOLSS_FORM_BUILTIN
, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
80 { SPOOLSS_FORM_BUILTIN
, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
81 { SPOOLSS_FORM_BUILTIN
, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
82 { SPOOLSS_FORM_BUILTIN
, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
83 { SPOOLSS_FORM_BUILTIN
, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
84 { SPOOLSS_FORM_BUILTIN
, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
85 { SPOOLSS_FORM_BUILTIN
, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
86 { SPOOLSS_FORM_BUILTIN
, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
87 { SPOOLSS_FORM_BUILTIN
, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
88 { SPOOLSS_FORM_BUILTIN
, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
89 { SPOOLSS_FORM_BUILTIN
, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
90 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
91 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
92 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
93 { SPOOLSS_FORM_BUILTIN
, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
94 { SPOOLSS_FORM_BUILTIN
, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
95 { SPOOLSS_FORM_BUILTIN
, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
96 { SPOOLSS_FORM_BUILTIN
, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
97 { SPOOLSS_FORM_BUILTIN
, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
98 { SPOOLSS_FORM_BUILTIN
, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
99 { SPOOLSS_FORM_BUILTIN
, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
100 { SPOOLSS_FORM_BUILTIN
, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
101 { SPOOLSS_FORM_BUILTIN
, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
102 { SPOOLSS_FORM_BUILTIN
, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
103 { SPOOLSS_FORM_BUILTIN
, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
104 { SPOOLSS_FORM_BUILTIN
, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
105 { SPOOLSS_FORM_BUILTIN
, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
106 { SPOOLSS_FORM_BUILTIN
, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
107 { SPOOLSS_FORM_BUILTIN
, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
108 { SPOOLSS_FORM_BUILTIN
, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
109 { SPOOLSS_FORM_BUILTIN
, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
110 { SPOOLSS_FORM_BUILTIN
, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
111 { SPOOLSS_FORM_BUILTIN
, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
112 { SPOOLSS_FORM_BUILTIN
, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
113 { SPOOLSS_FORM_BUILTIN
, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
114 { SPOOLSS_FORM_BUILTIN
, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
115 { SPOOLSS_FORM_BUILTIN
, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
116 { SPOOLSS_FORM_BUILTIN
, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
117 { SPOOLSS_FORM_BUILTIN
, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
118 { SPOOLSS_FORM_BUILTIN
, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
119 { SPOOLSS_FORM_BUILTIN
, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
120 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
121 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
122 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
123 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
124 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
125 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
126 { SPOOLSS_FORM_BUILTIN
, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
127 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
128 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
129 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
130 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
131 { SPOOLSS_FORM_BUILTIN
, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
132 { SPOOLSS_FORM_BUILTIN
, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
133 { SPOOLSS_FORM_BUILTIN
, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
134 { SPOOLSS_FORM_BUILTIN
, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
135 { SPOOLSS_FORM_BUILTIN
, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
136 { SPOOLSS_FORM_BUILTIN
, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
137 { SPOOLSS_FORM_BUILTIN
, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
138 { SPOOLSS_FORM_BUILTIN
, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
139 { SPOOLSS_FORM_BUILTIN
, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
140 { SPOOLSS_FORM_BUILTIN
, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
141 { SPOOLSS_FORM_BUILTIN
, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
142 { SPOOLSS_FORM_BUILTIN
, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
143 { SPOOLSS_FORM_BUILTIN
, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
144 { SPOOLSS_FORM_BUILTIN
, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
145 { SPOOLSS_FORM_BUILTIN
, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
146 { SPOOLSS_FORM_BUILTIN
, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
147 { SPOOLSS_FORM_BUILTIN
, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
148 { SPOOLSS_FORM_BUILTIN
, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
149 { SPOOLSS_FORM_BUILTIN
, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
150 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
151 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
152 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} },
153 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
154 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
155 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
156 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
157 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
158 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
159 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
160 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
161 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
162 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
163 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
164 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
165 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
166 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
167 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
168 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
169 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
170 { SPOOLSS_FORM_BUILTIN
, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
171 { SPOOLSS_FORM_BUILTIN
, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
172 { SPOOLSS_FORM_BUILTIN
, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
173 { SPOOLSS_FORM_BUILTIN
, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
174 { SPOOLSS_FORM_BUILTIN
, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
175 { SPOOLSS_FORM_BUILTIN
, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
176 { SPOOLSS_FORM_BUILTIN
, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
177 { SPOOLSS_FORM_BUILTIN
, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
178 { SPOOLSS_FORM_BUILTIN
, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} }
181 /********************************************************************
182 static helper functions
183 ********************************************************************/
185 /****************************************************************************
186 Update the changeid time.
187 ****************************************************************************/
191 * @brief Update the ChangeID time of a printer.
193 * This is SO NASTY as some drivers need this to change, others need it
194 * static. This value will change every second, and I must hope that this
195 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
198 * @return The ChangeID.
200 static uint32_t winreg_printer_rev_changeid(void)
204 get_process_uptime(&tv
);
207 /* Return changeid as msec since spooler restart */
208 return tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
211 * This setting seems to work well but is too untested
212 * to replace the above calculation. Left in for experimentation
213 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
215 return tv
.tv_sec
* 10 + tv
.tv_usec
/ 100000;
219 static WERROR
winreg_printer_openkey(TALLOC_CTX
*mem_ctx
,
220 struct dcerpc_binding_handle
*binding_handle
,
224 uint32_t access_mask
,
225 struct policy_handle
*hive_handle
,
226 struct policy_handle
*key_handle
)
228 struct winreg_String wkey
, wkeyclass
;
231 WERROR result
= WERR_OK
;
233 status
= dcerpc_winreg_OpenHKLM(binding_handle
,
239 if (!NT_STATUS_IS_OK(status
)) {
240 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
242 return ntstatus_to_werror(status
);
244 if (!W_ERROR_IS_OK(result
)) {
245 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
246 win_errstr(result
)));
251 keyname
= talloc_asprintf(mem_ctx
, "%s\\%s", path
, key
);
253 keyname
= talloc_strdup(mem_ctx
, path
);
255 if (keyname
== NULL
) {
263 enum winreg_CreateAction action
= REG_ACTION_NONE
;
265 ZERO_STRUCT(wkeyclass
);
268 status
= dcerpc_winreg_CreateKey(binding_handle
,
280 case REG_ACTION_NONE
:
281 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
283 case REG_CREATED_NEW_KEY
:
284 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname
));
286 case REG_OPENED_EXISTING_KEY
:
287 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname
));
291 status
= dcerpc_winreg_OpenKey(binding_handle
,
300 if (!NT_STATUS_IS_OK(status
)) {
301 result
= ntstatus_to_werror(status
);
303 if (!W_ERROR_IS_OK(result
)) {
306 if (is_valid_policy_hnd(hive_handle
)) {
307 dcerpc_winreg_CloseKey(binding_handle
,
312 ZERO_STRUCTP(hive_handle
);
321 * @brief Create the registry keyname for the given printer.
323 * @param[in] mem_ctx The memory context to use.
325 * @param[in] printer The name of the printer to get the registry key.
327 * @return The registry key or NULL on error.
329 static char *winreg_printer_data_keyname(TALLOC_CTX
*mem_ctx
, const char *printer
) {
330 return talloc_asprintf(mem_ctx
, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY
, printer
);
333 static WERROR
winreg_printer_opendriver(TALLOC_CTX
*mem_ctx
,
334 struct dcerpc_binding_handle
*winreg_handle
,
335 const char *drivername
,
336 const char *architecture
,
338 uint32_t access_mask
,
340 struct policy_handle
*hive_hnd
,
341 struct policy_handle
*key_hnd
)
346 key_name
= talloc_asprintf(mem_ctx
, "%s\\Environments\\%s\\Drivers\\Version-%u",
347 TOP_LEVEL_CONTROL_KEY
,
348 architecture
, version
);
353 result
= winreg_printer_openkey(mem_ctx
,
364 static WERROR
winreg_enumval_to_dword(TALLOC_CTX
*mem_ctx
,
365 struct spoolss_PrinterEnumValues
*v
,
366 const char *valuename
, uint32_t *dw
)
368 /* just return if it is not the one we are looking for */
369 if (strcmp(valuename
, v
->value_name
) != 0) {
370 return WERR_NOT_FOUND
;
373 if (v
->type
!= REG_DWORD
) {
374 return WERR_INVALID_DATATYPE
;
377 if (v
->data_length
!= 4) {
382 *dw
= IVAL(v
->data
->data
, 0);
386 static WERROR
winreg_enumval_to_sz(TALLOC_CTX
*mem_ctx
,
387 struct spoolss_PrinterEnumValues
*v
,
388 const char *valuename
, const char **_str
)
390 /* just return if it is not the one we are looking for */
391 if (strcmp(valuename
, v
->value_name
) != 0) {
392 return WERR_NOT_FOUND
;
395 if (v
->type
!= REG_SZ
) {
396 return WERR_INVALID_DATATYPE
;
399 if (v
->data_length
== 0) {
400 *_str
= talloc_strdup(mem_ctx
, EMPTY_STRING
);
407 if (!pull_reg_sz(mem_ctx
, v
->data
, _str
)) {
414 static WERROR
winreg_enumval_to_multi_sz(TALLOC_CTX
*mem_ctx
,
415 struct spoolss_PrinterEnumValues
*v
,
416 const char *valuename
,
419 /* just return if it is not the one we are looking for */
420 if (strcmp(valuename
, v
->value_name
) != 0) {
421 return WERR_NOT_FOUND
;
424 if (v
->type
!= REG_MULTI_SZ
) {
425 return WERR_INVALID_DATATYPE
;
428 if (v
->data_length
== 0) {
429 *array
= talloc_array(mem_ctx
, const char *, 1);
430 if (*array
== NULL
) {
437 if (!pull_reg_multi_sz(mem_ctx
, v
->data
, array
)) {
444 static WERROR
winreg_printer_write_date(TALLOC_CTX
*mem_ctx
,
445 struct dcerpc_binding_handle
*winreg_handle
,
446 struct policy_handle
*key_handle
,
450 struct winreg_String wvalue
= { 0, };
452 WERROR result
= WERR_OK
;
459 str
= talloc_strdup(mem_ctx
, "01/01/1601");
461 t
= nt_time_to_unix(data
);
464 return map_werror_from_unix(errno
);
466 str
= talloc_asprintf(mem_ctx
, "%02d/%02d/%04d",
467 tm
->tm_mon
+ 1, tm
->tm_mday
, tm
->tm_year
+ 1900);
474 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
477 status
= dcerpc_winreg_SetValue(winreg_handle
,
485 if (!NT_STATUS_IS_OK(status
)) {
486 result
= ntstatus_to_werror(status
);
488 if (!W_ERROR_IS_OK(result
)) {
489 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
490 wvalue
.name
, win_errstr(result
)));
496 static WERROR
winreg_printer_date_to_NTTIME(const char *str
, NTTIME
*data
)
501 if (strequal(str
, "01/01/1601")) {
508 if (sscanf(str
, "%d/%d/%d",
509 &tm
.tm_mon
, &tm
.tm_mday
, &tm
.tm_year
) != 3) {
510 return WERR_INVALID_PARAMETER
;
517 unix_to_nt_time(data
, t
);
522 static WERROR
winreg_printer_write_ver(TALLOC_CTX
*mem_ctx
,
523 struct dcerpc_binding_handle
*winreg_handle
,
524 struct policy_handle
*key_handle
,
528 struct winreg_String wvalue
= { 0, };
530 WERROR result
= WERR_OK
;
534 /* FIXME: check format is right,
535 * this needs to be something like: 6.1.7600.16385 */
536 str
= talloc_asprintf(mem_ctx
, "%u.%u.%u.%u",
537 (unsigned)((data
>> 48) & 0xFFFF),
538 (unsigned)((data
>> 32) & 0xFFFF),
539 (unsigned)((data
>> 16) & 0xFFFF),
540 (unsigned)(data
& 0xFFFF));
546 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
549 status
= dcerpc_winreg_SetValue(winreg_handle
,
557 if (!NT_STATUS_IS_OK(status
)) {
558 result
= ntstatus_to_werror(status
);
560 if (!W_ERROR_IS_OK(result
)) {
561 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
562 wvalue
.name
, win_errstr(result
)));
568 static WERROR
winreg_printer_ver_to_dword(const char *str
, uint64_t *data
)
570 unsigned int v1
, v2
, v3
, v4
;
572 if (sscanf(str
, "%u.%u.%u.%u", &v1
, &v2
, &v3
, &v4
) != 4) {
573 return WERR_INVALID_PARAMETER
;
576 *data
= ((uint64_t)(v1
& 0xFFFF) << 48) +
577 ((uint64_t)(v2
& 0xFFFF) << 32) +
578 ((uint64_t)(v3
& 0xFFFF) << 16) +
579 (uint64_t)(v2
& 0xFFFF);
584 /********************************************************************
585 Public winreg function for spoolss
586 ********************************************************************/
588 WERROR
winreg_create_printer(TALLOC_CTX
*mem_ctx
,
589 struct dcerpc_binding_handle
*winreg_handle
,
590 const char *sharename
)
592 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
593 struct policy_handle hive_hnd
, key_hnd
;
594 struct spoolss_SetPrinterInfo2
*info2
;
595 struct security_descriptor
*secdesc
;
596 struct winreg_String wkey
, wkeyclass
;
598 const char *subkeys
[] = { SPOOL_DSDRIVER_KEY
, SPOOL_DSSPOOLER_KEY
, SPOOL_PRINTERDATA_KEY
};
599 uint32_t i
, count
= ARRAY_SIZE(subkeys
);
600 uint32_t info2_mask
= 0;
601 WERROR result
= WERR_OK
;
605 tmp_ctx
= talloc_stackframe();
606 if (tmp_ctx
== NULL
) {
610 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
612 TALLOC_FREE(tmp_ctx
);
616 ZERO_STRUCT(hive_hnd
);
617 ZERO_STRUCT(key_hnd
);
619 result
= winreg_printer_openkey(tmp_ctx
,
627 if (W_ERROR_IS_OK(result
)) {
628 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path
));
630 } else if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
631 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path
));
632 } else if (!W_ERROR_IS_OK(result
)) {
633 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
634 path
, win_errstr(result
)));
638 if (is_valid_policy_hnd(&key_hnd
)) {
639 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
641 if (is_valid_policy_hnd(&hive_hnd
)) {
642 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
645 /* Create the main key */
646 result
= winreg_printer_openkey(tmp_ctx
,
654 if (!W_ERROR_IS_OK(result
)) {
655 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
656 path
, win_errstr(result
)));
660 if (is_valid_policy_hnd(&key_hnd
)) {
661 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
665 for (i
= 0; i
< count
; i
++) {
667 enum winreg_CreateAction action
= REG_ACTION_NONE
;
669 ZERO_STRUCT(key_hnd
);
672 wkey
.name
= talloc_asprintf(tmp_ctx
, "%s\\%s", path
, subkeys
[i
]);
673 if (wkey
.name
== NULL
) {
678 ZERO_STRUCT(wkeyclass
);
681 status
= dcerpc_winreg_CreateKey(winreg_handle
,
692 if (!NT_STATUS_IS_OK(status
)) {
693 result
= ntstatus_to_werror(status
);
695 if (!W_ERROR_IS_OK(result
)) {
696 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
697 wkey
.name
, win_errstr(result
)));
701 if (strequal(subkeys
[i
], SPOOL_DSSPOOLER_KEY
)) {
702 const char *dnssuffix
;
703 const char *longname
;
706 status
= dcerpc_winreg_set_sz(tmp_ctx
,
709 SPOOL_REG_PRINTERNAME
,
712 if (!NT_STATUS_IS_OK(status
)) {
713 result
= ntstatus_to_werror(status
);
715 if (!W_ERROR_IS_OK(result
)) {
719 status
= dcerpc_winreg_set_sz(tmp_ctx
,
722 SPOOL_REG_SHORTSERVERNAME
,
725 if (!NT_STATUS_IS_OK(status
)) {
726 result
= ntstatus_to_werror(status
);
728 if (!W_ERROR_IS_OK(result
)) {
732 /* We make the assumption that the netbios name
733 * is the same as the DNS name since the former
734 * will be what we used to join the domain
736 dnssuffix
= get_mydnsdomname(tmp_ctx
);
737 if (dnssuffix
!= NULL
&& dnssuffix
[0] != '\0') {
738 longname
= talloc_asprintf(tmp_ctx
, "%s.%s", lp_netbios_name(), dnssuffix
);
740 longname
= talloc_strdup(tmp_ctx
, lp_netbios_name());
742 if (longname
== NULL
) {
747 status
= dcerpc_winreg_set_sz(tmp_ctx
,
750 SPOOL_REG_SERVERNAME
,
753 if (!NT_STATUS_IS_OK(status
)) {
754 result
= ntstatus_to_werror(status
);
756 if (!W_ERROR_IS_OK(result
)) {
760 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
761 longname
, sharename
);
762 if (uncname
== NULL
) {
767 status
= dcerpc_winreg_set_sz(tmp_ctx
,
773 if (!NT_STATUS_IS_OK(status
)) {
774 result
= ntstatus_to_werror(status
);
776 if (!W_ERROR_IS_OK(result
)) {
780 status
= dcerpc_winreg_set_dword(tmp_ctx
,
783 SPOOL_REG_VERSIONNUMBER
,
786 if (!NT_STATUS_IS_OK(status
)) {
787 result
= ntstatus_to_werror(status
);
789 if (!W_ERROR_IS_OK(result
)) {
793 status
= dcerpc_winreg_set_dword(tmp_ctx
,
796 SPOOL_REG_PRINTSTARTTIME
,
799 if (!NT_STATUS_IS_OK(status
)) {
800 result
= ntstatus_to_werror(status
);
802 if (!W_ERROR_IS_OK(result
)) {
806 status
= dcerpc_winreg_set_dword(tmp_ctx
,
809 SPOOL_REG_PRINTENDTIME
,
812 if (!NT_STATUS_IS_OK(status
)) {
813 result
= ntstatus_to_werror(status
);
815 if (!W_ERROR_IS_OK(result
)) {
819 status
= dcerpc_winreg_set_dword(tmp_ctx
,
825 if (!NT_STATUS_IS_OK(status
)) {
826 result
= ntstatus_to_werror(status
);
828 if (!W_ERROR_IS_OK(result
)) {
832 status
= dcerpc_winreg_set_dword(tmp_ctx
,
835 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
838 if (!NT_STATUS_IS_OK(status
)) {
839 result
= ntstatus_to_werror(status
);
841 if (!W_ERROR_IS_OK(result
)) {
846 if (is_valid_policy_hnd(&key_hnd
)) {
847 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
850 info2
= talloc_zero(tmp_ctx
, struct spoolss_SetPrinterInfo2
);
856 info2
->printername
= sharename
;
857 if (info2
->printername
== NULL
) {
861 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTERNAME
;
863 info2
->sharename
= sharename
;
864 info2_mask
|= SPOOLSS_PRINTER_INFO_SHARENAME
;
866 info2
->portname
= SAMBA_PRINTER_PORT_NAME
;
867 info2_mask
|= SPOOLSS_PRINTER_INFO_PORTNAME
;
869 info2
->printprocessor
= "winprint";
870 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
;
872 info2
->datatype
= "RAW";
873 info2_mask
|= SPOOLSS_PRINTER_INFO_DATATYPE
;
876 info2_mask
|= SPOOLSS_PRINTER_INFO_COMMENT
;
878 info2
->attributes
= PRINTER_ATTRIBUTE_SAMBA
;
879 info2_mask
|= SPOOLSS_PRINTER_INFO_ATTRIBUTES
;
881 info2
->starttime
= 0; /* Minutes since 12:00am GMT */
882 info2_mask
|= SPOOLSS_PRINTER_INFO_STARTTIME
;
884 info2
->untiltime
= 0; /* Minutes since 12:00am GMT */
885 info2_mask
|= SPOOLSS_PRINTER_INFO_UNTILTIME
;
888 info2_mask
|= SPOOLSS_PRINTER_INFO_PRIORITY
;
890 info2
->defaultpriority
= 1;
891 info2_mask
|= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
;
893 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
894 if (!W_ERROR_IS_OK(result
)) {
897 info2_mask
|= SPOOLSS_PRINTER_INFO_SECDESC
;
900 * Don't write a default Device Mode to the registry! The Device Mode is
901 * only written to disk with a SetPrinter level 2 or 8.
904 result
= winreg_update_printer(tmp_ctx
,
913 if (is_valid_policy_hnd(&key_hnd
)) {
914 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
916 if (is_valid_policy_hnd(&hive_hnd
)) {
917 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
920 talloc_free(tmp_ctx
);
924 WERROR
winreg_update_printer(TALLOC_CTX
*mem_ctx
,
925 struct dcerpc_binding_handle
*winreg_handle
,
926 const char *sharename
,
928 struct spoolss_SetPrinterInfo2
*info2
,
929 struct spoolss_DeviceMode
*devmode
,
930 struct security_descriptor
*secdesc
)
932 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
933 struct policy_handle hive_hnd
, key_hnd
;
934 int snum
= lp_servicenumber(sharename
);
935 enum ndr_err_code ndr_err
;
938 WERROR result
= WERR_OK
;
943 tmp_ctx
= talloc_stackframe();
944 if (tmp_ctx
== NULL
) {
948 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
950 TALLOC_FREE(tmp_ctx
);
954 ZERO_STRUCT(hive_hnd
);
955 ZERO_STRUCT(key_hnd
);
957 result
= winreg_printer_openkey(tmp_ctx
,
965 if (!W_ERROR_IS_OK(result
)) {
966 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
967 path
, win_errstr(result
)));
971 if (info2_mask
& SPOOLSS_PRINTER_INFO_ATTRIBUTES
) {
972 status
= dcerpc_winreg_set_dword(tmp_ctx
,
978 if (!NT_STATUS_IS_OK(status
)) {
979 result
= ntstatus_to_werror(status
);
981 if (!W_ERROR_IS_OK(result
)) {
987 if (info2_mask
& SPOOLSS_PRINTER_INFO_AVERAGEPPM
) {
988 status
= dcerpc_winreg_set_dword(tmp_ctx
,
994 if (!NT_STATUS_IS_OK(status
)) {
995 result
= ntstatus_to_werror(status
);
997 if (!W_ERROR_IS_OK(result
)) {
1003 if (info2_mask
& SPOOLSS_PRINTER_INFO_COMMENT
) {
1004 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1010 if (!NT_STATUS_IS_OK(status
)) {
1011 result
= ntstatus_to_werror(status
);
1013 if (!W_ERROR_IS_OK(result
)) {
1018 if (info2_mask
& SPOOLSS_PRINTER_INFO_DATATYPE
) {
1019 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1025 if (!NT_STATUS_IS_OK(status
)) {
1026 result
= ntstatus_to_werror(status
);
1028 if (!W_ERROR_IS_OK(result
)) {
1033 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
) {
1034 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1038 info2
->defaultpriority
,
1040 if (!NT_STATUS_IS_OK(status
)) {
1041 result
= ntstatus_to_werror(status
);
1043 if (!W_ERROR_IS_OK(result
)) {
1048 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEVMODE
) {
1050 * Some client drivers freak out if there is a NULL devmode
1051 * (probably the driver is not checking before accessing
1052 * the devmode pointer) --jerry
1054 if (devmode
== NULL
&& lp_default_devmode(snum
) && info2
!= NULL
) {
1055 result
= spoolss_create_default_devmode(tmp_ctx
,
1058 if (!W_ERROR_IS_OK(result
)) {
1063 if (devmode
->size
!= (ndr_size_spoolss_DeviceMode(devmode
, 0) - devmode
->__driverextra_length
)) {
1064 result
= WERR_INVALID_PARAM
;
1068 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, devmode
,
1069 (ndr_push_flags_fn_t
) ndr_push_spoolss_DeviceMode
);
1070 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1071 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1072 result
= WERR_NOMEM
;
1076 status
= dcerpc_winreg_set_binary(tmp_ctx
,
1082 if (!NT_STATUS_IS_OK(status
)) {
1083 result
= ntstatus_to_werror(status
);
1085 if (!W_ERROR_IS_OK(result
)) {
1090 if (info2_mask
& SPOOLSS_PRINTER_INFO_DRIVERNAME
) {
1091 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1097 if (!NT_STATUS_IS_OK(status
)) {
1098 result
= ntstatus_to_werror(status
);
1100 if (!W_ERROR_IS_OK(result
)) {
1105 if (info2_mask
& SPOOLSS_PRINTER_INFO_LOCATION
) {
1106 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1112 if (!NT_STATUS_IS_OK(status
)) {
1113 result
= ntstatus_to_werror(status
);
1115 if (!W_ERROR_IS_OK(result
)) {
1120 if (info2_mask
& SPOOLSS_PRINTER_INFO_PARAMETERS
) {
1121 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1127 if (!NT_STATUS_IS_OK(status
)) {
1128 result
= ntstatus_to_werror(status
);
1130 if (!W_ERROR_IS_OK(result
)) {
1135 if (info2_mask
& SPOOLSS_PRINTER_INFO_PORTNAME
) {
1136 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1142 if (!NT_STATUS_IS_OK(status
)) {
1143 result
= ntstatus_to_werror(status
);
1145 if (!W_ERROR_IS_OK(result
)) {
1150 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTERNAME
) {
1152 * in addprinter: no servername and the printer is the name
1153 * in setprinter: servername is \\server
1154 * and printer is \\server\\printer
1156 * Samba manages only local printers.
1157 * we currently don't support things like i
1158 * path=\\other_server\printer
1160 * We only store the printername, not \\server\printername
1162 const char *p
= strrchr(info2
->printername
, '\\');
1164 p
= info2
->printername
;
1168 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1174 if (!NT_STATUS_IS_OK(status
)) {
1175 result
= ntstatus_to_werror(status
);
1177 if (!W_ERROR_IS_OK(result
)) {
1182 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
) {
1183 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1187 info2
->printprocessor
,
1189 if (!NT_STATUS_IS_OK(status
)) {
1190 result
= ntstatus_to_werror(status
);
1192 if (!W_ERROR_IS_OK(result
)) {
1197 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRIORITY
) {
1198 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1204 if (!NT_STATUS_IS_OK(status
)) {
1205 result
= ntstatus_to_werror(status
);
1207 if (!W_ERROR_IS_OK(result
)) {
1212 if (info2_mask
& SPOOLSS_PRINTER_INFO_SECDESC
) {
1214 * We need a security descriptor, if it isn't specified by
1215 * AddPrinter{Ex} then create a default descriptor.
1217 if (secdesc
== NULL
) {
1218 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1219 if (!W_ERROR_IS_OK(result
)) {
1223 result
= winreg_set_printer_secdesc(tmp_ctx
,
1227 if (!W_ERROR_IS_OK(result
)) {
1232 if (info2_mask
& SPOOLSS_PRINTER_INFO_SEPFILE
) {
1233 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1239 if (!NT_STATUS_IS_OK(status
)) {
1240 result
= ntstatus_to_werror(status
);
1242 if (!W_ERROR_IS_OK(result
)) {
1247 if (info2_mask
& SPOOLSS_PRINTER_INFO_SHARENAME
) {
1248 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1254 if (!NT_STATUS_IS_OK(status
)) {
1255 result
= ntstatus_to_werror(status
);
1257 if (!W_ERROR_IS_OK(result
)) {
1262 if (info2_mask
& SPOOLSS_PRINTER_INFO_STARTTIME
) {
1263 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1269 if (!NT_STATUS_IS_OK(status
)) {
1270 result
= ntstatus_to_werror(status
);
1272 if (!W_ERROR_IS_OK(result
)) {
1277 if (info2_mask
& SPOOLSS_PRINTER_INFO_STATUS
) {
1278 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1284 if (!NT_STATUS_IS_OK(status
)) {
1285 result
= ntstatus_to_werror(status
);
1287 if (!W_ERROR_IS_OK(result
)) {
1292 if (info2_mask
& SPOOLSS_PRINTER_INFO_UNTILTIME
) {
1293 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1299 if (!NT_STATUS_IS_OK(status
)) {
1300 result
= ntstatus_to_werror(status
);
1302 if (!W_ERROR_IS_OK(result
)) {
1307 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1311 winreg_printer_rev_changeid(),
1313 if (!NT_STATUS_IS_OK(status
)) {
1314 result
= ntstatus_to_werror(status
);
1316 if (!W_ERROR_IS_OK(result
)) {
1322 if (is_valid_policy_hnd(&key_hnd
)) {
1323 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1325 if (is_valid_policy_hnd(&hive_hnd
)) {
1326 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1329 TALLOC_FREE(tmp_ctx
);
1333 WERROR
winreg_get_printer(TALLOC_CTX
*mem_ctx
,
1334 struct dcerpc_binding_handle
*winreg_handle
,
1335 const char *printer
,
1336 struct spoolss_PrinterInfo2
**pinfo2
)
1338 struct spoolss_PrinterInfo2
*info2
;
1339 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1340 struct policy_handle hive_hnd
, key_hnd
;
1341 struct spoolss_PrinterEnumValues enum_value
;
1342 struct spoolss_PrinterEnumValues
*v
= NULL
;
1343 enum ndr_err_code ndr_err
;
1345 int snum
= lp_servicenumber(printer
);
1346 uint32_t num_values
= 0;
1350 WERROR result
= WERR_OK
;
1352 const char **enum_names
= NULL
;
1353 enum winreg_Type
*enum_types
= NULL
;
1354 DATA_BLOB
*enum_data_blobs
= NULL
;
1355 TALLOC_CTX
*tmp_ctx
;
1357 tmp_ctx
= talloc_stackframe();
1358 if (tmp_ctx
== NULL
) {
1362 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1364 TALLOC_FREE(tmp_ctx
);
1368 result
= winreg_printer_openkey(tmp_ctx
,
1376 if (!W_ERROR_IS_OK(result
)) {
1377 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
1378 path
, win_errstr(result
)));
1382 status
= dcerpc_winreg_enumvals(tmp_ctx
,
1390 if (!NT_STATUS_IS_OK(status
)){
1391 result
= ntstatus_to_werror(status
);
1394 if (!W_ERROR_IS_OK(result
)) {
1395 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1396 path
, win_errstr(result
)));
1400 info2
= talloc_zero(tmp_ctx
, struct spoolss_PrinterInfo2
);
1401 if (info2
== NULL
) {
1402 result
= WERR_NOMEM
;
1406 FILL_STRING(info2
, EMPTY_STRING
, info2
->servername
);
1407 FILL_STRING(info2
, EMPTY_STRING
, info2
->printername
);
1408 FILL_STRING(info2
, EMPTY_STRING
, info2
->sharename
);
1409 FILL_STRING(info2
, EMPTY_STRING
, info2
->portname
);
1410 FILL_STRING(info2
, EMPTY_STRING
, info2
->drivername
);
1411 FILL_STRING(info2
, EMPTY_STRING
, info2
->comment
);
1412 FILL_STRING(info2
, EMPTY_STRING
, info2
->location
);
1413 FILL_STRING(info2
, EMPTY_STRING
, info2
->sepfile
);
1414 FILL_STRING(info2
, EMPTY_STRING
, info2
->printprocessor
);
1415 FILL_STRING(info2
, EMPTY_STRING
, info2
->datatype
);
1416 FILL_STRING(info2
, EMPTY_STRING
, info2
->parameters
);
1418 for (i
= 0; i
< num_values
; i
++) {
1419 enum_value
.value_name
= enum_names
[i
];
1420 enum_value
.value_name_len
= 2*strlen_m_term(enum_names
[i
]);
1421 enum_value
.type
= enum_types
[i
];
1422 enum_value
.data_length
= enum_data_blobs
[i
].length
;
1423 enum_value
.data
= NULL
;
1424 if (enum_value
.data_length
!= 0){
1425 enum_value
.data
= &enum_data_blobs
[i
];
1429 result
= winreg_enumval_to_sz(info2
,
1432 &info2
->printername
);
1433 CHECK_ERROR(result
);
1435 result
= winreg_enumval_to_sz(info2
,
1439 CHECK_ERROR(result
);
1441 result
= winreg_enumval_to_sz(info2
,
1445 CHECK_ERROR(result
);
1447 result
= winreg_enumval_to_sz(info2
,
1451 CHECK_ERROR(result
);
1453 result
= winreg_enumval_to_sz(info2
,
1457 CHECK_ERROR(result
);
1459 result
= winreg_enumval_to_sz(info2
,
1463 CHECK_ERROR(result
);
1465 result
= winreg_enumval_to_sz(info2
,
1468 &info2
->printprocessor
);
1469 CHECK_ERROR(result
);
1471 result
= winreg_enumval_to_sz(info2
,
1475 CHECK_ERROR(result
);
1477 result
= winreg_enumval_to_sz(info2
,
1480 &info2
->parameters
);
1481 CHECK_ERROR(result
);
1483 result
= winreg_enumval_to_sz(info2
,
1486 &info2
->drivername
);
1487 CHECK_ERROR(result
);
1489 result
= winreg_enumval_to_dword(info2
,
1492 &info2
->attributes
);
1493 CHECK_ERROR(result
);
1495 result
= winreg_enumval_to_dword(info2
,
1499 CHECK_ERROR(result
);
1501 result
= winreg_enumval_to_dword(info2
,
1504 &info2
->defaultpriority
);
1505 CHECK_ERROR(result
);
1507 result
= winreg_enumval_to_dword(info2
,
1511 CHECK_ERROR(result
);
1513 result
= winreg_enumval_to_dword(info2
,
1517 CHECK_ERROR(result
);
1519 result
= winreg_enumval_to_dword(info2
,
1523 CHECK_ERROR(result
);
1525 result
= winreg_enumval_to_dword(info2
,
1529 CHECK_ERROR(result
);
1532 if (!W_ERROR_IS_OK(result
)) {
1533 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
1536 win_errstr(result
)));
1540 /* Construct the Device Mode */
1541 status
= dcerpc_winreg_query_binary(tmp_ctx
,
1547 if (!NT_STATUS_IS_OK(status
)) {
1548 result
= ntstatus_to_werror(status
);
1550 if (W_ERROR_IS_OK(result
)) {
1551 info2
->devmode
= talloc_zero(info2
, struct spoolss_DeviceMode
);
1552 if (info2
->devmode
== NULL
) {
1553 result
= WERR_NOMEM
;
1556 ndr_err
= ndr_pull_struct_blob(&blob
,
1559 (ndr_pull_flags_fn_t
) ndr_pull_spoolss_DeviceMode
);
1560 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1561 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
1562 result
= WERR_NOMEM
;
1567 if (info2
->devmode
== NULL
&& lp_default_devmode(snum
)) {
1568 result
= spoolss_create_default_devmode(info2
,
1571 if (!W_ERROR_IS_OK(result
)) {
1576 if (info2
->devmode
) {
1577 info2
->devmode
->size
= ndr_size_spoolss_DeviceMode(info2
->devmode
, 0) - info2
->devmode
->driverextra_data
.length
;
1580 result
= winreg_get_printer_secdesc(info2
,
1584 if (!W_ERROR_IS_OK(result
)) {
1588 /* Fix for OS/2 drivers. */
1589 if (get_remote_arch() == RA_OS2
) {
1590 spoolss_map_to_os2_driver(info2
, &info2
->drivername
);
1594 *pinfo2
= talloc_move(mem_ctx
, &info2
);
1599 if (is_valid_policy_hnd(&key_hnd
)) {
1600 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1602 if (is_valid_policy_hnd(&hive_hnd
)) {
1603 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1606 TALLOC_FREE(tmp_ctx
);
1610 WERROR
winreg_get_printer_secdesc(TALLOC_CTX
*mem_ctx
,
1611 struct dcerpc_binding_handle
*winreg_handle
,
1612 const char *sharename
,
1613 struct spoolss_security_descriptor
**psecdesc
)
1615 struct spoolss_security_descriptor
*secdesc
;
1616 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1617 struct policy_handle hive_hnd
, key_hnd
;
1619 TALLOC_CTX
*tmp_ctx
;
1624 tmp_ctx
= talloc_stackframe();
1625 if (tmp_ctx
== NULL
) {
1629 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1631 talloc_free(tmp_ctx
);
1635 ZERO_STRUCT(hive_hnd
);
1636 ZERO_STRUCT(key_hnd
);
1638 result
= winreg_printer_openkey(tmp_ctx
,
1646 if (!W_ERROR_IS_OK(result
)) {
1647 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1648 goto create_default
;
1653 status
= dcerpc_winreg_query_sd(tmp_ctx
,
1659 if (!NT_STATUS_IS_OK(status
)) {
1660 result
= ntstatus_to_werror(status
);
1662 if (!W_ERROR_IS_OK(result
)) {
1663 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1665 if (is_valid_policy_hnd(&key_hnd
)) {
1666 dcerpc_winreg_CloseKey(winreg_handle
,
1672 if (is_valid_policy_hnd(&hive_hnd
)) {
1673 dcerpc_winreg_CloseKey(winreg_handle
,
1678 goto create_default
;
1684 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1691 result
= winreg_printer_openkey(tmp_ctx
,
1699 if (!W_ERROR_IS_OK(result
)) {
1703 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1704 if (!W_ERROR_IS_OK(result
)) {
1708 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
1709 this security descriptor has been created when winbindd was
1710 down. Take ownership of security descriptor. */
1711 if (dom_sid_equal(secdesc
->owner_sid
, &global_sid_World
)) {
1712 struct dom_sid owner_sid
;
1714 /* Change sd owner to workgroup administrator */
1716 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid
)) {
1717 struct spoolss_security_descriptor
*new_secdesc
;
1721 sid_append_rid(&owner_sid
, DOMAIN_RID_ADMINISTRATOR
);
1723 new_secdesc
= make_sec_desc(tmp_ctx
,
1732 if (new_secdesc
== NULL
) {
1733 result
= WERR_NOMEM
;
1737 /* Swap with other one */
1738 secdesc
= new_secdesc
;
1742 status
= dcerpc_winreg_set_sd(tmp_ctx
,
1748 if (!NT_STATUS_IS_OK(status
)) {
1749 result
= ntstatus_to_werror(status
);
1751 if (!W_ERROR_IS_OK(result
)) {
1756 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1761 if (is_valid_policy_hnd(&key_hnd
)) {
1762 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1764 if (is_valid_policy_hnd(&hive_hnd
)) {
1765 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1768 talloc_free(tmp_ctx
);
1772 WERROR
winreg_set_printer_secdesc(TALLOC_CTX
*mem_ctx
,
1773 struct dcerpc_binding_handle
*winreg_handle
,
1774 const char *sharename
,
1775 const struct spoolss_security_descriptor
*secdesc
)
1777 const struct spoolss_security_descriptor
*new_secdesc
= secdesc
;
1778 struct spoolss_security_descriptor
*old_secdesc
;
1779 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1780 struct policy_handle hive_hnd
, key_hnd
;
1782 TALLOC_CTX
*tmp_ctx
;
1787 tmp_ctx
= talloc_stackframe();
1788 if (tmp_ctx
== NULL
) {
1792 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1794 talloc_free(tmp_ctx
);
1799 * The old owner and group sids of the security descriptor are not
1800 * present when new ACEs are added or removed by changing printer
1801 * permissions through NT. If they are NULL in the new security
1802 * descriptor then copy them over from the old one.
1804 if (!secdesc
->owner_sid
|| !secdesc
->group_sid
) {
1805 struct dom_sid
*owner_sid
, *group_sid
;
1806 struct security_acl
*dacl
, *sacl
;
1809 result
= winreg_get_printer_secdesc(tmp_ctx
,
1813 if (!W_ERROR_IS_OK(result
)) {
1814 talloc_free(tmp_ctx
);
1818 /* Pick out correct owner and group sids */
1819 owner_sid
= secdesc
->owner_sid
?
1820 secdesc
->owner_sid
:
1821 old_secdesc
->owner_sid
;
1823 group_sid
= secdesc
->group_sid
?
1824 secdesc
->group_sid
:
1825 old_secdesc
->group_sid
;
1827 dacl
= secdesc
->dacl
?
1831 sacl
= secdesc
->sacl
?
1835 /* Make a deep copy of the security descriptor */
1836 new_secdesc
= make_sec_desc(tmp_ctx
,
1844 if (new_secdesc
== NULL
) {
1845 talloc_free(tmp_ctx
);
1850 ZERO_STRUCT(hive_hnd
);
1851 ZERO_STRUCT(key_hnd
);
1853 result
= winreg_printer_openkey(tmp_ctx
,
1861 if (!W_ERROR_IS_OK(result
)) {
1865 status
= dcerpc_winreg_set_sd(tmp_ctx
,
1871 if (!NT_STATUS_IS_OK(status
)) {
1872 result
= ntstatus_to_werror(status
);
1876 if (is_valid_policy_hnd(&key_hnd
)) {
1877 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1879 if (is_valid_policy_hnd(&hive_hnd
)) {
1880 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1883 talloc_free(tmp_ctx
);
1887 /* Set printer data over the winreg pipe. */
1888 WERROR
winreg_set_printer_dataex(TALLOC_CTX
*mem_ctx
,
1889 struct dcerpc_binding_handle
*winreg_handle
,
1890 const char *printer
,
1893 enum winreg_Type type
,
1897 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1898 struct policy_handle hive_hnd
, key_hnd
;
1899 struct winreg_String wvalue
= { 0, };
1901 WERROR result
= WERR_OK
;
1904 TALLOC_CTX
*tmp_ctx
;
1906 tmp_ctx
= talloc_stackframe();
1907 if (tmp_ctx
== NULL
) {
1911 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1913 TALLOC_FREE(tmp_ctx
);
1917 ZERO_STRUCT(hive_hnd
);
1918 ZERO_STRUCT(key_hnd
);
1920 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
1921 key
, value
, access_mask
, printer
));
1922 result
= winreg_printer_openkey(tmp_ctx
,
1930 if (!W_ERROR_IS_OK(result
)) {
1931 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
1932 key
, win_errstr(result
)));
1936 wvalue
.name
= value
;
1937 status
= dcerpc_winreg_SetValue(winreg_handle
,
1945 if (!NT_STATUS_IS_OK(status
)) {
1946 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
1947 value
, nt_errstr(status
)));
1948 result
= ntstatus_to_werror(status
);
1952 if (is_valid_policy_hnd(&key_hnd
)) {
1953 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1955 if (is_valid_policy_hnd(&hive_hnd
)) {
1956 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1959 TALLOC_FREE(tmp_ctx
);
1963 /* Get printer data over a winreg pipe. */
1964 WERROR
winreg_get_printer_dataex(TALLOC_CTX
*mem_ctx
,
1965 struct dcerpc_binding_handle
*winreg_handle
,
1966 const char *printer
,
1969 enum winreg_Type
*type
,
1971 uint32_t *data_size
)
1973 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1974 struct policy_handle hive_hnd
, key_hnd
;
1975 struct winreg_String wvalue
;
1976 enum winreg_Type type_in
= REG_NONE
;
1978 uint8_t *data_in
= NULL
;
1979 uint32_t data_in_size
= 0;
1980 uint32_t value_len
= 0;
1981 WERROR result
= WERR_OK
;
1984 TALLOC_CTX
*tmp_ctx
;
1986 tmp_ctx
= talloc_stackframe();
1987 if (tmp_ctx
== NULL
) {
1991 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1993 TALLOC_FREE(tmp_ctx
);
1997 ZERO_STRUCT(hive_hnd
);
1998 ZERO_STRUCT(key_hnd
);
2000 result
= winreg_printer_openkey(tmp_ctx
,
2008 if (!W_ERROR_IS_OK(result
)) {
2009 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2010 key
, win_errstr(result
)));
2014 wvalue
.name
= value
;
2017 * call QueryValue once with data == NULL to get the
2018 * needed memory size to be allocated, then allocate
2019 * data buffer and call again.
2021 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2030 if (!NT_STATUS_IS_OK(status
)) {
2031 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2032 value
, nt_errstr(status
)));
2033 result
= ntstatus_to_werror(status
);
2036 if (!W_ERROR_IS_OK(result
)) {
2037 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2038 value
, win_errstr(result
)));
2042 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
2043 if (data_in
== NULL
) {
2044 result
= WERR_NOMEM
;
2049 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2058 if (!NT_STATUS_IS_OK(status
)) {
2059 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2060 value
, nt_errstr(status
)));
2061 result
= ntstatus_to_werror(status
);
2064 if (!W_ERROR_IS_OK(result
)) {
2065 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2066 value
, win_errstr(result
)));
2071 *data_size
= data_in_size
;
2073 *data
= talloc_move(mem_ctx
, &data_in
);
2078 if (is_valid_policy_hnd(&key_hnd
)) {
2079 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2081 if (is_valid_policy_hnd(&hive_hnd
)) {
2082 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2085 TALLOC_FREE(tmp_ctx
);
2089 /* Enumerate on the values of a given key and provide the data. */
2090 WERROR
winreg_enum_printer_dataex(TALLOC_CTX
*mem_ctx
,
2091 struct dcerpc_binding_handle
*winreg_handle
,
2092 const char *printer
,
2094 uint32_t *pnum_values
,
2095 struct spoolss_PrinterEnumValues
**penum_values
)
2098 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2099 struct policy_handle hive_hnd
, key_hnd
;
2101 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2102 uint32_t num_values
= 0;
2104 WERROR result
= WERR_OK
;
2107 const char **enum_names
= NULL
;
2108 enum winreg_Type
*enum_types
= NULL
;
2109 DATA_BLOB
*enum_data_blobs
= NULL
;
2111 TALLOC_CTX
*tmp_ctx
;
2113 tmp_ctx
= talloc_stackframe();
2114 if (tmp_ctx
== NULL
) {
2118 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2120 TALLOC_FREE(tmp_ctx
);
2124 result
= winreg_printer_openkey(tmp_ctx
,
2132 if (!W_ERROR_IS_OK(result
)) {
2133 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2134 key
, win_errstr(result
)));
2138 status
= dcerpc_winreg_enumvals(tmp_ctx
,
2146 if (!NT_STATUS_IS_OK(status
)){
2147 result
= ntstatus_to_werror(status
);
2150 if (!W_ERROR_IS_OK(result
)) {
2151 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2152 key
, win_errstr(result
)));
2156 enum_values
= talloc_array(tmp_ctx
, struct spoolss_PrinterEnumValues
, num_values
);
2157 if (enum_values
== NULL
){
2158 result
= WERR_NOMEM
;
2159 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2160 key
, win_errstr(result
)));
2164 for (i
= 0; i
< num_values
; i
++){
2165 enum_values
[i
].value_name
= enum_names
[i
];
2166 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
2167 enum_values
[i
].type
= enum_types
[i
];
2168 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
2169 enum_values
[i
].data
= NULL
;
2171 if (enum_values
[i
].data_length
!= 0){
2172 enum_values
[i
].data
= &enum_data_blobs
[i
];
2176 talloc_steal(enum_values
, enum_names
);
2177 talloc_steal(enum_values
, enum_data_blobs
);
2179 *pnum_values
= num_values
;
2181 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
2186 if (is_valid_policy_hnd(&key_hnd
)) {
2187 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2189 if (is_valid_policy_hnd(&hive_hnd
)) {
2190 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2193 TALLOC_FREE(tmp_ctx
);
2197 /* Delete printer data over a winreg pipe. */
2198 WERROR
winreg_delete_printer_dataex(TALLOC_CTX
*mem_ctx
,
2199 struct dcerpc_binding_handle
*winreg_handle
,
2200 const char *printer
,
2204 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2205 struct policy_handle hive_hnd
, key_hnd
;
2206 struct winreg_String wvalue
= { 0, };
2208 WERROR result
= WERR_OK
;
2212 TALLOC_CTX
*tmp_ctx
;
2214 tmp_ctx
= talloc_stackframe();
2215 if (tmp_ctx
== NULL
) {
2219 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2221 TALLOC_FREE(tmp_ctx
);
2225 ZERO_STRUCT(hive_hnd
);
2226 ZERO_STRUCT(key_hnd
);
2228 result
= winreg_printer_openkey(tmp_ctx
,
2236 if (!W_ERROR_IS_OK(result
)) {
2237 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2238 key
, win_errstr(result
)));
2242 wvalue
.name
= value
;
2243 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
2248 if (!NT_STATUS_IS_OK(status
)) {
2249 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2250 value
, nt_errstr(status
)));
2251 result
= ntstatus_to_werror(status
);
2255 if (is_valid_policy_hnd(&key_hnd
)) {
2256 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2258 if (is_valid_policy_hnd(&hive_hnd
)) {
2259 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2262 TALLOC_FREE(tmp_ctx
);
2266 /* Enumerate on the subkeys of a given key and provide the data. */
2267 WERROR
winreg_enum_printer_key(TALLOC_CTX
*mem_ctx
,
2268 struct dcerpc_binding_handle
*winreg_handle
,
2269 const char *printer
,
2271 uint32_t *pnum_subkeys
,
2272 const char ***psubkeys
)
2274 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2275 struct policy_handle hive_hnd
, key_hnd
;
2277 const char **subkeys
= NULL
;
2278 uint32_t num_subkeys
= -1;
2280 WERROR result
= WERR_OK
;
2284 TALLOC_CTX
*tmp_ctx
;
2286 tmp_ctx
= talloc_stackframe();
2287 if (tmp_ctx
== NULL
) {
2291 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2293 TALLOC_FREE(tmp_ctx
);
2297 ZERO_STRUCT(hive_hnd
);
2298 ZERO_STRUCT(key_hnd
);
2300 result
= winreg_printer_openkey(tmp_ctx
,
2308 if (!W_ERROR_IS_OK(result
)) {
2309 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2310 key
, win_errstr(result
)));
2314 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
2320 if (!NT_STATUS_IS_OK(status
)) {
2321 result
= ntstatus_to_werror(status
);
2323 if (!W_ERROR_IS_OK(result
)) {
2324 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2325 key
, win_errstr(result
)));
2329 *pnum_subkeys
= num_subkeys
;
2331 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
2336 if (is_valid_policy_hnd(&key_hnd
)) {
2337 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2339 if (is_valid_policy_hnd(&hive_hnd
)) {
2340 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2343 TALLOC_FREE(tmp_ctx
);
2347 /* Delete a key with subkeys of a given printer. */
2348 WERROR
winreg_delete_printer_key(TALLOC_CTX
*mem_ctx
,
2349 struct dcerpc_binding_handle
*winreg_handle
,
2350 const char *printer
,
2353 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2354 struct policy_handle hive_hnd
, key_hnd
;
2360 TALLOC_CTX
*tmp_ctx
;
2362 tmp_ctx
= talloc_stackframe();
2363 if (tmp_ctx
== NULL
) {
2367 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2369 TALLOC_FREE(tmp_ctx
);
2373 result
= winreg_printer_openkey(tmp_ctx
,
2381 if (!W_ERROR_IS_OK(result
)) {
2382 /* key doesn't exist */
2383 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2388 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2389 key
, win_errstr(result
)));
2393 if (is_valid_policy_hnd(&key_hnd
)) {
2394 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
2397 if (key
== NULL
|| key
[0] == '\0') {
2400 keyname
= talloc_asprintf(tmp_ctx
,
2404 if (keyname
== NULL
) {
2405 result
= WERR_NOMEM
;
2410 status
= dcerpc_winreg_delete_subkeys_recursive(tmp_ctx
,
2417 if (!NT_STATUS_IS_OK(status
)) {
2418 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2419 key
, nt_errstr(status
)));
2420 result
= ntstatus_to_werror(status
);
2424 if (!W_ERROR_IS_OK(result
)) {
2425 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2426 key
, win_errstr(result
)));
2431 if (is_valid_policy_hnd(&key_hnd
)) {
2432 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2434 if (is_valid_policy_hnd(&hive_hnd
)) {
2435 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2438 TALLOC_FREE(tmp_ctx
);
2442 WERROR
winreg_printer_update_changeid(TALLOC_CTX
*mem_ctx
,
2443 struct dcerpc_binding_handle
*winreg_handle
,
2444 const char *printer
)
2446 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2447 struct policy_handle hive_hnd
, key_hnd
;
2452 TALLOC_CTX
*tmp_ctx
;
2454 tmp_ctx
= talloc_stackframe();
2455 if (tmp_ctx
== NULL
) {
2459 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2461 TALLOC_FREE(tmp_ctx
);
2465 ZERO_STRUCT(hive_hnd
);
2466 ZERO_STRUCT(key_hnd
);
2468 result
= winreg_printer_openkey(tmp_ctx
,
2476 if (!W_ERROR_IS_OK(result
)) {
2477 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2478 path
, win_errstr(result
)));
2482 status
= dcerpc_winreg_set_dword(tmp_ctx
,
2486 winreg_printer_rev_changeid(),
2488 if (!NT_STATUS_IS_OK(status
)) {
2489 result
= ntstatus_to_werror(status
);
2491 if (!W_ERROR_IS_OK(result
)) {
2497 if (is_valid_policy_hnd(&key_hnd
)) {
2498 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2500 if (is_valid_policy_hnd(&hive_hnd
)) {
2501 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2504 TALLOC_FREE(tmp_ctx
);
2508 WERROR
winreg_printer_get_changeid(TALLOC_CTX
*mem_ctx
,
2509 struct dcerpc_binding_handle
*winreg_handle
,
2510 const char *printer
,
2511 uint32_t *pchangeid
)
2513 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2514 struct policy_handle hive_hnd
, key_hnd
;
2515 uint32_t changeid
= 0;
2520 TALLOC_CTX
*tmp_ctx
;
2522 tmp_ctx
= talloc_stackframe();
2523 if (tmp_ctx
== NULL
) {
2527 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2529 TALLOC_FREE(tmp_ctx
);
2533 ZERO_STRUCT(hive_hnd
);
2534 ZERO_STRUCT(key_hnd
);
2536 result
= winreg_printer_openkey(tmp_ctx
,
2544 if (!W_ERROR_IS_OK(result
)) {
2545 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2546 path
, win_errstr(result
)));
2550 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path
));
2552 status
= dcerpc_winreg_query_dword(tmp_ctx
,
2558 if (!NT_STATUS_IS_OK(status
)) {
2559 result
= ntstatus_to_werror(status
);
2561 if (!W_ERROR_IS_OK(result
)) {
2566 *pchangeid
= changeid
;
2571 if (is_valid_policy_hnd(&key_hnd
)) {
2572 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2574 if (is_valid_policy_hnd(&hive_hnd
)) {
2575 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2578 TALLOC_FREE(tmp_ctx
);
2583 * The special behaviour of the spoolss forms is documented at the website:
2585 * Managing Win32 Printserver Forms
2586 * http://unixwiz.net/techtips/winspooler-forms.html
2589 WERROR
winreg_printer_addform1(TALLOC_CTX
*mem_ctx
,
2590 struct dcerpc_binding_handle
*winreg_handle
,
2591 struct spoolss_AddFormInfo1
*form
)
2593 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2594 struct policy_handle hive_hnd
, key_hnd
;
2595 struct winreg_String wvalue
= { 0, };
2597 uint32_t num_info
= 0;
2598 union spoolss_FormInfo
*info
= NULL
;
2603 TALLOC_CTX
*tmp_ctx
;
2605 tmp_ctx
= talloc_stackframe();
2606 if (tmp_ctx
== NULL
) {
2610 ZERO_STRUCT(hive_hnd
);
2611 ZERO_STRUCT(key_hnd
);
2613 result
= winreg_printer_openkey(tmp_ctx
,
2615 TOP_LEVEL_CONTROL_FORMS_KEY
,
2621 if (!W_ERROR_IS_OK(result
)) {
2622 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2623 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2627 result
= winreg_printer_enumforms1(tmp_ctx
, winreg_handle
,
2629 if (!W_ERROR_IS_OK(result
)) {
2630 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2631 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2635 /* If form name already exists or is builtin return ALREADY_EXISTS */
2636 for (i
= 0; i
< num_info
; i
++) {
2637 if (strequal(info
[i
].info1
.form_name
, form
->form_name
)) {
2638 result
= WERR_FILE_EXISTS
;
2643 wvalue
.name
= form
->form_name
;
2645 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
2646 SIVAL(blob
.data
, 0, form
->size
.width
);
2647 SIVAL(blob
.data
, 4, form
->size
.height
);
2648 SIVAL(blob
.data
, 8, form
->area
.left
);
2649 SIVAL(blob
.data
, 12, form
->area
.top
);
2650 SIVAL(blob
.data
, 16, form
->area
.right
);
2651 SIVAL(blob
.data
, 20, form
->area
.bottom
);
2652 SIVAL(blob
.data
, 24, num_info
+ 1); /* FIXME */
2653 SIVAL(blob
.data
, 28, form
->flags
);
2655 status
= dcerpc_winreg_SetValue(winreg_handle
,
2663 if (!NT_STATUS_IS_OK(status
)) {
2664 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2665 wvalue
.name
, nt_errstr(status
)));
2666 result
= ntstatus_to_werror(status
);
2670 if (is_valid_policy_hnd(&key_hnd
)) {
2671 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2673 if (is_valid_policy_hnd(&hive_hnd
)) {
2674 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2678 TALLOC_FREE(tmp_ctx
);
2682 WERROR
winreg_printer_enumforms1(TALLOC_CTX
*mem_ctx
,
2683 struct dcerpc_binding_handle
*winreg_handle
,
2684 uint32_t *pnum_info
,
2685 union spoolss_FormInfo
**pinfo
)
2687 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2688 struct policy_handle hive_hnd
, key_hnd
;
2689 union spoolss_FormInfo
*info
;
2690 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2691 uint32_t num_values
= 0;
2692 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2697 const char **enum_names
= NULL
;
2698 enum winreg_Type
*enum_types
= NULL
;
2699 DATA_BLOB
*enum_data_blobs
= NULL
;
2700 TALLOC_CTX
*tmp_ctx
;
2702 tmp_ctx
= talloc_stackframe();
2703 if (tmp_ctx
== NULL
) {
2707 ZERO_STRUCT(hive_hnd
);
2708 ZERO_STRUCT(key_hnd
);
2710 result
= winreg_printer_openkey(tmp_ctx
,
2712 TOP_LEVEL_CONTROL_FORMS_KEY
,
2718 if (!W_ERROR_IS_OK(result
)) {
2719 /* key doesn't exist */
2720 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2725 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
2726 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2730 status
= dcerpc_winreg_enumvals(tmp_ctx
,
2738 if (!NT_STATUS_IS_OK(status
)){
2739 result
= ntstatus_to_werror(status
);
2742 if (!W_ERROR_IS_OK(result
)) {
2743 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2744 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2748 enum_values
= talloc_zero_array(tmp_ctx
,
2749 struct spoolss_PrinterEnumValues
,
2751 if (enum_values
== NULL
){
2752 result
= WERR_NOMEM
;
2756 for (i
= 0; i
< num_values
; i
++){
2757 enum_values
[i
].value_name
= enum_names
[i
];
2758 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
2759 enum_values
[i
].type
= enum_types
[i
];
2760 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
2761 enum_values
[i
].data
= NULL
;
2762 if (enum_values
[i
].data_length
!= 0){
2763 enum_values
[i
].data
= &enum_data_blobs
[i
];
2767 if (!W_ERROR_IS_OK(result
)) {
2768 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2769 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2773 info
= talloc_array(tmp_ctx
, union spoolss_FormInfo
, num_builtin
+ num_values
);
2775 result
= WERR_NOMEM
;
2779 /* Enumerate BUILTIN forms */
2780 for (i
= 0; i
< num_builtin
; i
++) {
2781 info
[i
].info1
= builtin_forms1
[i
];
2784 /* Enumerate registry forms */
2785 for (i
= 0; i
< num_values
; i
++) {
2786 union spoolss_FormInfo val
;
2788 if (enum_values
[i
].type
!= REG_BINARY
||
2789 enum_values
[i
].data_length
!= 32) {
2793 val
.info1
.form_name
= talloc_strdup(info
, enum_values
[i
].value_name
);
2794 if (val
.info1
.form_name
== NULL
) {
2795 result
= WERR_NOMEM
;
2799 val
.info1
.size
.width
= IVAL(enum_values
[i
].data
->data
, 0);
2800 val
.info1
.size
.height
= IVAL(enum_values
[i
].data
->data
, 4);
2801 val
.info1
.area
.left
= IVAL(enum_values
[i
].data
->data
, 8);
2802 val
.info1
.area
.top
= IVAL(enum_values
[i
].data
->data
, 12);
2803 val
.info1
.area
.right
= IVAL(enum_values
[i
].data
->data
, 16);
2804 val
.info1
.area
.bottom
= IVAL(enum_values
[i
].data
->data
, 20);
2805 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
2806 val
.info1
.flags
= (enum spoolss_FormFlags
) IVAL(enum_values
[i
].data
->data
, 28);
2808 info
[i
+ num_builtin
] = val
;
2811 *pnum_info
= num_builtin
+ num_values
;
2813 *pinfo
= talloc_move(mem_ctx
, &info
);
2817 if (is_valid_policy_hnd(&key_hnd
)) {
2818 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2820 if (is_valid_policy_hnd(&hive_hnd
)) {
2821 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2824 TALLOC_FREE(enum_values
);
2825 TALLOC_FREE(tmp_ctx
);
2829 WERROR
winreg_printer_deleteform1(TALLOC_CTX
*mem_ctx
,
2830 struct dcerpc_binding_handle
*winreg_handle
,
2831 const char *form_name
)
2833 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2834 struct policy_handle hive_hnd
, key_hnd
;
2835 struct winreg_String wvalue
= { 0, };
2836 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2838 WERROR result
= WERR_OK
;
2841 TALLOC_CTX
*tmp_ctx
;
2843 for (i
= 0; i
< num_builtin
; i
++) {
2844 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
2845 return WERR_INVALID_PARAMETER
;
2849 tmp_ctx
= talloc_stackframe();
2850 if (tmp_ctx
== NULL
) {
2854 ZERO_STRUCT(hive_hnd
);
2855 ZERO_STRUCT(key_hnd
);
2857 result
= winreg_printer_openkey(tmp_ctx
,
2859 TOP_LEVEL_CONTROL_FORMS_KEY
,
2865 if (!W_ERROR_IS_OK(result
)) {
2866 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
2867 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2868 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2869 result
= WERR_INVALID_FORM_NAME
;
2874 wvalue
.name
= form_name
;
2875 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
2880 if (!NT_STATUS_IS_OK(status
)) {
2881 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
2882 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
2883 wvalue
.name
, nt_errstr(status
)));
2884 result
= ntstatus_to_werror(status
);
2888 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2889 result
= WERR_INVALID_FORM_NAME
;
2893 if (is_valid_policy_hnd(&key_hnd
)) {
2894 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2896 if (is_valid_policy_hnd(&hive_hnd
)) {
2897 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2900 TALLOC_FREE(tmp_ctx
);
2904 WERROR
winreg_printer_setform1(TALLOC_CTX
*mem_ctx
,
2905 struct dcerpc_binding_handle
*winreg_handle
,
2906 const char *form_name
,
2907 struct spoolss_AddFormInfo1
*form
)
2909 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2910 struct policy_handle hive_hnd
= { 0, };
2911 struct policy_handle key_hnd
= { 0, };
2912 struct winreg_String wvalue
= { 0, };
2914 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2918 TALLOC_CTX
*tmp_ctx
= NULL
;
2920 for (i
= 0; i
< num_builtin
; i
++) {
2921 if (strequal(builtin_forms1
[i
].form_name
, form
->form_name
)) {
2922 result
= WERR_INVALID_PARAM
;
2927 tmp_ctx
= talloc_stackframe();
2928 if (tmp_ctx
== NULL
) {
2932 ZERO_STRUCT(hive_hnd
);
2933 ZERO_STRUCT(key_hnd
);
2935 result
= winreg_printer_openkey(tmp_ctx
,
2937 TOP_LEVEL_CONTROL_FORMS_KEY
,
2943 if (!W_ERROR_IS_OK(result
)) {
2944 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
2945 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2949 /* If form_name != form->form_name then we renamed the form */
2950 if (strequal(form_name
, form
->form_name
)) {
2951 result
= winreg_printer_deleteform1(tmp_ctx
, winreg_handle
,
2953 if (!W_ERROR_IS_OK(result
)) {
2954 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
2955 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2960 wvalue
.name
= form
->form_name
;
2962 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
2963 SIVAL(blob
.data
, 0, form
->size
.width
);
2964 SIVAL(blob
.data
, 4, form
->size
.height
);
2965 SIVAL(blob
.data
, 8, form
->area
.left
);
2966 SIVAL(blob
.data
, 12, form
->area
.top
);
2967 SIVAL(blob
.data
, 16, form
->area
.right
);
2968 SIVAL(blob
.data
, 20, form
->area
.bottom
);
2969 SIVAL(blob
.data
, 24, 42);
2970 SIVAL(blob
.data
, 28, form
->flags
);
2972 status
= dcerpc_winreg_SetValue(winreg_handle
,
2980 if (!NT_STATUS_IS_OK(status
)) {
2981 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
2982 wvalue
.name
, nt_errstr(status
)));
2983 result
= ntstatus_to_werror(status
);
2987 if (winreg_handle
!= NULL
) {
2990 if (is_valid_policy_hnd(&key_hnd
)) {
2991 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2993 if (is_valid_policy_hnd(&hive_hnd
)) {
2994 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2998 TALLOC_FREE(tmp_ctx
);
3002 WERROR
winreg_printer_getform1(TALLOC_CTX
*mem_ctx
,
3003 struct dcerpc_binding_handle
*winreg_handle
,
3004 const char *form_name
,
3005 struct spoolss_FormInfo1
*r
)
3007 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3008 struct policy_handle hive_hnd
, key_hnd
;
3009 struct winreg_String wvalue
;
3010 enum winreg_Type type_in
= REG_NONE
;
3011 uint8_t *data_in
= NULL
;
3012 uint32_t data_in_size
= 0;
3013 uint32_t value_len
= 0;
3014 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3019 TALLOC_CTX
*tmp_ctx
;
3021 /* check builtin forms first */
3022 for (i
= 0; i
< num_builtin
; i
++) {
3023 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3024 *r
= builtin_forms1
[i
];
3029 tmp_ctx
= talloc_stackframe();
3030 if (tmp_ctx
== NULL
) {
3034 ZERO_STRUCT(hive_hnd
);
3035 ZERO_STRUCT(key_hnd
);
3037 result
= winreg_printer_openkey(tmp_ctx
,
3039 TOP_LEVEL_CONTROL_FORMS_KEY
,
3045 if (!W_ERROR_IS_OK(result
)) {
3046 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3047 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3051 wvalue
.name
= form_name
;
3054 * call QueryValue once with data == NULL to get the
3055 * needed memory size to be allocated, then allocate
3056 * data buffer and call again.
3058 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3067 if (!NT_STATUS_IS_OK(status
)) {
3068 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3069 wvalue
.name
, nt_errstr(status
)));
3070 result
= ntstatus_to_werror(status
);
3073 if (!W_ERROR_IS_OK(result
)) {
3077 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
3078 if (data_in
== NULL
) {
3079 result
= WERR_NOMEM
;
3084 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3093 if (!NT_STATUS_IS_OK(status
)) {
3094 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3095 wvalue
.name
, nt_errstr(status
)));
3096 result
= ntstatus_to_werror(status
);
3099 if (!W_ERROR_IS_OK(result
)) {
3103 r
->form_name
= talloc_strdup(mem_ctx
, form_name
);
3104 if (r
->form_name
== NULL
) {
3105 result
= WERR_NOMEM
;
3109 r
->size
.width
= IVAL(data_in
, 0);
3110 r
->size
.height
= IVAL(data_in
, 4);
3111 r
->area
.left
= IVAL(data_in
, 8);
3112 r
->area
.top
= IVAL(data_in
, 12);
3113 r
->area
.right
= IVAL(data_in
, 16);
3114 r
->area
.bottom
= IVAL(data_in
, 20);
3115 /* skip index IVAL(data_in, 24)));*/
3116 r
->flags
= (enum spoolss_FormFlags
) IVAL(data_in
, 28);
3120 if (is_valid_policy_hnd(&key_hnd
)) {
3121 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3123 if (is_valid_policy_hnd(&hive_hnd
)) {
3124 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3127 TALLOC_FREE(tmp_ctx
);
3131 WERROR
winreg_add_driver(TALLOC_CTX
*mem_ctx
,
3132 struct dcerpc_binding_handle
*winreg_handle
,
3133 struct spoolss_AddDriverInfoCtr
*r
,
3134 const char **driver_name
,
3135 uint32_t *driver_version
)
3137 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3138 struct policy_handle hive_hnd
, key_hnd
;
3139 struct spoolss_DriverInfo8 info8
;
3140 TALLOC_CTX
*tmp_ctx
= NULL
;
3144 ZERO_STRUCT(hive_hnd
);
3145 ZERO_STRUCT(key_hnd
);
3148 if (!driver_info_ctr_to_info8(r
, &info8
)) {
3149 result
= WERR_INVALID_PARAMETER
;
3153 tmp_ctx
= talloc_stackframe();
3154 if (tmp_ctx
== NULL
) {
3158 result
= winreg_printer_opendriver(tmp_ctx
,
3166 if (!W_ERROR_IS_OK(result
)) {
3167 DEBUG(0, ("winreg_add_driver: "
3168 "Could not open driver key (%s,%s,%d): %s\n",
3169 info8
.driver_name
, info8
.architecture
,
3170 info8
.version
, win_errstr(result
)));
3174 /* TODO: "Attributes" ? */
3176 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3182 if (!NT_STATUS_IS_OK(status
)) {
3183 result
= ntstatus_to_werror(status
);
3185 if (!W_ERROR_IS_OK(result
)) {
3189 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3195 if (!NT_STATUS_IS_OK(status
)) {
3196 result
= ntstatus_to_werror(status
);
3198 if (!W_ERROR_IS_OK(result
)) {
3202 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3208 if (!NT_STATUS_IS_OK(status
)) {
3209 result
= ntstatus_to_werror(status
);
3211 if (!W_ERROR_IS_OK(result
)) {
3215 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3218 "Configuration File",
3221 if (!NT_STATUS_IS_OK(status
)) {
3222 result
= ntstatus_to_werror(status
);
3224 if (!W_ERROR_IS_OK(result
)) {
3228 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3234 if (!NT_STATUS_IS_OK(status
)) {
3235 result
= ntstatus_to_werror(status
);
3237 if (!W_ERROR_IS_OK(result
)) {
3241 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3245 info8
.dependent_files
,
3247 if (!NT_STATUS_IS_OK(status
)) {
3248 result
= ntstatus_to_werror(status
);
3250 if (!W_ERROR_IS_OK(result
)) {
3254 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3260 if (!NT_STATUS_IS_OK(status
)) {
3261 result
= ntstatus_to_werror(status
);
3263 if (!W_ERROR_IS_OK(result
)) {
3267 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3271 info8
.default_datatype
,
3273 if (!NT_STATUS_IS_OK(status
)) {
3274 result
= ntstatus_to_werror(status
);
3276 if (!W_ERROR_IS_OK(result
)) {
3280 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3282 &key_hnd
, "Previous Names",
3283 info8
.previous_names
,
3285 if (!NT_STATUS_IS_OK(status
)) {
3286 result
= ntstatus_to_werror(status
);
3288 if (!W_ERROR_IS_OK(result
)) {
3292 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3293 &key_hnd
, "DriverDate",
3295 if (!W_ERROR_IS_OK(result
)) {
3299 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
,
3300 &key_hnd
, "DriverVersion",
3301 info8
.driver_version
);
3302 if (!W_ERROR_IS_OK(result
)) {
3306 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3310 info8
.manufacturer_name
,
3312 if (!NT_STATUS_IS_OK(status
)) {
3313 result
= ntstatus_to_werror(status
);
3315 if (!W_ERROR_IS_OK(result
)) {
3319 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3323 info8
.manufacturer_url
,
3325 if (!NT_STATUS_IS_OK(status
)) {
3326 result
= ntstatus_to_werror(status
);
3328 if (!W_ERROR_IS_OK(result
)) {
3332 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3338 if (!NT_STATUS_IS_OK(status
)) {
3339 result
= ntstatus_to_werror(status
);
3341 if (!W_ERROR_IS_OK(result
)) {
3345 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3351 if (!NT_STATUS_IS_OK(status
)) {
3352 result
= ntstatus_to_werror(status
);
3354 if (!W_ERROR_IS_OK(result
)) {
3358 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3362 info8
.print_processor
,
3364 if (!NT_STATUS_IS_OK(status
)) {
3365 result
= ntstatus_to_werror(status
);
3367 if (!W_ERROR_IS_OK(result
)) {
3371 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3377 if (!NT_STATUS_IS_OK(status
)) {
3378 result
= ntstatus_to_werror(status
);
3380 if (!W_ERROR_IS_OK(result
)) {
3384 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3388 info8
.color_profiles
,
3390 if (!NT_STATUS_IS_OK(status
)) {
3391 result
= ntstatus_to_werror(status
);
3393 if (!W_ERROR_IS_OK(result
)) {
3397 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3403 if (!NT_STATUS_IS_OK(status
)) {
3404 result
= ntstatus_to_werror(status
);
3406 if (!W_ERROR_IS_OK(result
)) {
3410 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3413 "PrinterDriverAttributes",
3414 info8
.printer_driver_attributes
,
3416 if (!NT_STATUS_IS_OK(status
)) {
3417 result
= ntstatus_to_werror(status
);
3419 if (!W_ERROR_IS_OK(result
)) {
3423 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3427 info8
.core_driver_dependencies
,
3429 if (!NT_STATUS_IS_OK(status
)) {
3430 result
= ntstatus_to_werror(status
);
3432 if (!W_ERROR_IS_OK(result
)) {
3436 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3437 &key_hnd
, "MinInboxDriverVerDate",
3438 info8
.min_inbox_driver_ver_date
);
3439 if (!W_ERROR_IS_OK(result
)) {
3443 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
, &key_hnd
,
3444 "MinInboxDriverVerVersion",
3445 info8
.min_inbox_driver_ver_version
);
3446 if (!W_ERROR_IS_OK(result
)) {
3450 *driver_name
= info8
.driver_name
;
3451 *driver_version
= info8
.version
;
3454 if (winreg_handle
!= NULL
) {
3457 if (is_valid_policy_hnd(&key_hnd
)) {
3458 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3460 if (is_valid_policy_hnd(&hive_hnd
)) {
3461 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3465 TALLOC_FREE(tmp_ctx
);
3469 WERROR
winreg_get_driver(TALLOC_CTX
*mem_ctx
,
3470 struct dcerpc_binding_handle
*winreg_handle
,
3471 const char *architecture
,
3472 const char *driver_name
,
3473 uint32_t driver_version
,
3474 struct spoolss_DriverInfo8
**_info8
)
3476 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3477 struct policy_handle hive_hnd
, key_hnd
;
3478 struct spoolss_DriverInfo8 i8
, *info8
;
3479 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
3480 struct spoolss_PrinterEnumValues
*v
;
3481 uint32_t num_values
= 0;
3482 TALLOC_CTX
*tmp_ctx
;
3486 const char **enum_names
= NULL
;
3487 enum winreg_Type
*enum_types
= NULL
;
3488 DATA_BLOB
*enum_data_blobs
= NULL
;
3490 ZERO_STRUCT(hive_hnd
);
3491 ZERO_STRUCT(key_hnd
);
3494 tmp_ctx
= talloc_stackframe();
3495 if (tmp_ctx
== NULL
) {
3499 if (driver_version
== DRIVER_ANY_VERSION
) {
3500 /* look for Win2k first and then for NT4 */
3501 result
= winreg_printer_opendriver(tmp_ctx
,
3509 if (!W_ERROR_IS_OK(result
)) {
3510 result
= winreg_printer_opendriver(tmp_ctx
,
3520 /* ok normal case */
3521 result
= winreg_printer_opendriver(tmp_ctx
,
3530 if (!W_ERROR_IS_OK(result
)) {
3531 DEBUG(5, ("winreg_get_driver: "
3532 "Could not open driver key (%s,%s,%d): %s\n",
3533 driver_name
, architecture
,
3534 driver_version
, win_errstr(result
)));
3538 status
= dcerpc_winreg_enumvals(tmp_ctx
,
3546 if (!NT_STATUS_IS_OK(status
)){
3547 result
= ntstatus_to_werror(status
);
3550 if (!W_ERROR_IS_OK(result
)) {
3551 DEBUG(0, ("winreg_get_driver: "
3552 "Could not enumerate values for (%s,%s,%d): %s\n",
3553 driver_name
, architecture
,
3554 driver_version
, win_errstr(result
)));
3558 enum_values
= talloc_zero_array(tmp_ctx
,
3559 struct spoolss_PrinterEnumValues
,
3561 if (enum_values
== NULL
){
3562 result
= WERR_NOMEM
;
3566 for (i
= 0; i
< num_values
; i
++){
3567 enum_values
[i
].value_name
= enum_names
[i
];
3568 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
3569 enum_values
[i
].type
= enum_types
[i
];
3570 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
3571 enum_values
[i
].data
= NULL
;
3572 if (enum_values
[i
].data_length
!= 0){
3573 enum_values
[i
].data
= &enum_data_blobs
[i
];
3577 info8
= talloc_zero(tmp_ctx
, struct spoolss_DriverInfo8
);
3578 if (info8
== NULL
) {
3579 result
= WERR_NOMEM
;
3583 info8
->driver_name
= talloc_strdup(info8
, driver_name
);
3584 if (info8
->driver_name
== NULL
) {
3585 result
= WERR_NOMEM
;
3589 info8
->architecture
= talloc_strdup(info8
, architecture
);
3590 if (info8
->architecture
== NULL
) {
3591 result
= WERR_NOMEM
;
3597 for (i
= 0; i
< num_values
; i
++) {
3598 const char *tmp_str
;
3601 v
= &enum_values
[i
];
3603 result
= winreg_enumval_to_dword(info8
, v
,
3606 if (W_ERROR_IS_OK(result
)) {
3607 info8
->version
= (enum spoolss_DriverOSVersion
) tmp
;
3609 CHECK_ERROR(result
);
3611 result
= winreg_enumval_to_sz(info8
, v
,
3613 &info8
->driver_path
);
3614 CHECK_ERROR(result
);
3616 result
= winreg_enumval_to_sz(info8
, v
,
3619 CHECK_ERROR(result
);
3621 result
= winreg_enumval_to_sz(info8
, v
,
3622 "Configuration File",
3623 &info8
->config_file
);
3624 CHECK_ERROR(result
);
3626 result
= winreg_enumval_to_sz(info8
, v
,
3629 CHECK_ERROR(result
);
3631 result
= winreg_enumval_to_multi_sz(info8
, v
,
3633 &info8
->dependent_files
);
3634 CHECK_ERROR(result
);
3636 result
= winreg_enumval_to_sz(info8
, v
,
3638 &info8
->monitor_name
);
3639 CHECK_ERROR(result
);
3641 result
= winreg_enumval_to_sz(info8
, v
,
3643 &info8
->default_datatype
);
3644 CHECK_ERROR(result
);
3646 result
= winreg_enumval_to_multi_sz(info8
, v
,
3648 &info8
->previous_names
);
3649 CHECK_ERROR(result
);
3651 result
= winreg_enumval_to_sz(info8
, v
,
3654 if (W_ERROR_IS_OK(result
)) {
3655 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3656 &info8
->driver_date
);
3658 CHECK_ERROR(result
);
3660 result
= winreg_enumval_to_sz(info8
, v
,
3663 if (W_ERROR_IS_OK(result
)) {
3664 result
= winreg_printer_ver_to_dword(tmp_str
,
3665 &info8
->driver_version
);
3667 CHECK_ERROR(result
);
3669 result
= winreg_enumval_to_sz(info8
, v
,
3671 &info8
->manufacturer_name
);
3672 CHECK_ERROR(result
);
3674 result
= winreg_enumval_to_sz(info8
, v
,
3676 &info8
->manufacturer_url
);
3677 CHECK_ERROR(result
);
3679 result
= winreg_enumval_to_sz(info8
, v
,
3681 &info8
->hardware_id
);
3682 CHECK_ERROR(result
);
3684 result
= winreg_enumval_to_sz(info8
, v
,
3687 CHECK_ERROR(result
);
3689 result
= winreg_enumval_to_sz(info8
, v
,
3691 &info8
->print_processor
);
3692 CHECK_ERROR(result
);
3694 result
= winreg_enumval_to_sz(info8
, v
,
3696 &info8
->vendor_setup
);
3697 CHECK_ERROR(result
);
3699 result
= winreg_enumval_to_multi_sz(info8
, v
,
3701 &info8
->color_profiles
);
3702 CHECK_ERROR(result
);
3704 result
= winreg_enumval_to_sz(info8
, v
,
3707 CHECK_ERROR(result
);
3709 result
= winreg_enumval_to_dword(info8
, v
,
3710 "PrinterDriverAttributes",
3711 &info8
->printer_driver_attributes
);
3712 CHECK_ERROR(result
);
3714 result
= winreg_enumval_to_multi_sz(info8
, v
,
3716 &info8
->core_driver_dependencies
);
3717 CHECK_ERROR(result
);
3719 result
= winreg_enumval_to_sz(info8
, v
,
3720 "MinInboxDriverVerDate",
3722 if (W_ERROR_IS_OK(result
)) {
3723 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3724 &info8
->min_inbox_driver_ver_date
);
3726 CHECK_ERROR(result
);
3728 result
= winreg_enumval_to_sz(info8
, v
,
3729 "MinInboxDriverVerVersion",
3731 if (W_ERROR_IS_OK(result
)) {
3732 result
= winreg_printer_ver_to_dword(tmp_str
,
3733 &info8
->min_inbox_driver_ver_version
);
3735 CHECK_ERROR(result
);
3738 if (!W_ERROR_IS_OK(result
)) {
3739 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3740 "for %s: %s\n", v
->value_name
,
3741 win_errstr(result
)));
3745 *_info8
= talloc_steal(mem_ctx
, info8
);
3748 if (winreg_handle
!= NULL
) {
3751 if (is_valid_policy_hnd(&key_hnd
)) {
3752 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3754 if (is_valid_policy_hnd(&hive_hnd
)) {
3755 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3759 TALLOC_FREE(tmp_ctx
);
3763 WERROR
winreg_del_driver(TALLOC_CTX
*mem_ctx
,
3764 struct dcerpc_binding_handle
*winreg_handle
,
3765 struct spoolss_DriverInfo8
*info8
,
3768 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3769 struct policy_handle hive_hnd
, key_hnd
;
3770 TALLOC_CTX
*tmp_ctx
;
3775 ZERO_STRUCT(hive_hnd
);
3776 ZERO_STRUCT(key_hnd
);
3778 tmp_ctx
= talloc_stackframe();
3779 if (tmp_ctx
== NULL
) {
3783 /* test that the key exists */
3784 result
= winreg_printer_opendriver(tmp_ctx
,
3787 info8
->architecture
,
3792 if (!W_ERROR_IS_OK(result
)) {
3793 /* key doesn't exist */
3794 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3799 DEBUG(5, ("winreg_del_driver: "
3800 "Could not open driver (%s,%s,%u): %s\n",
3801 info8
->driver_name
, info8
->architecture
,
3802 version
, win_errstr(result
)));
3807 if (is_valid_policy_hnd(&key_hnd
)) {
3808 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
3811 key_name
= talloc_asprintf(tmp_ctx
,
3812 "%s\\Environments\\%s\\Drivers\\Version-%u\\%s",
3813 TOP_LEVEL_CONTROL_KEY
,
3814 info8
->architecture
, version
,
3815 info8
->driver_name
);
3816 if (key_name
== NULL
) {
3817 result
= WERR_NOMEM
;
3821 status
= dcerpc_winreg_delete_subkeys_recursive(tmp_ctx
,
3828 if (!NT_STATUS_IS_OK(status
)){
3829 DEBUG(0, ("winreg_del_driver: "
3830 "Could not open driver (%s,%s,%u): %s\n",
3831 info8
->driver_name
, info8
->architecture
,
3832 version
, nt_errstr(status
)));
3836 if (!W_ERROR_IS_OK(result
)) {
3837 DEBUG(0, ("winreg_del_driver: "
3838 "Could not open driver (%s,%s,%u): %s\n",
3839 info8
->driver_name
, info8
->architecture
,
3840 version
, win_errstr(result
)));
3846 if (winreg_handle
!= NULL
) {
3849 if (is_valid_policy_hnd(&key_hnd
)) {
3850 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3852 if (is_valid_policy_hnd(&hive_hnd
)) {
3853 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3857 TALLOC_FREE(tmp_ctx
);
3861 WERROR
winreg_get_driver_list(TALLOC_CTX
*mem_ctx
,
3862 struct dcerpc_binding_handle
*winreg_handle
,
3863 const char *architecture
,
3865 uint32_t *num_drivers
,
3866 const char ***drivers_p
)
3868 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3869 struct policy_handle hive_hnd
, key_hnd
;
3870 const char **drivers
;
3871 TALLOC_CTX
*tmp_ctx
;
3878 ZERO_STRUCT(hive_hnd
);
3879 ZERO_STRUCT(key_hnd
);
3881 tmp_ctx
= talloc_stackframe();
3882 if (tmp_ctx
== NULL
) {
3886 /* use NULL for the driver name so we open the key that is
3887 * parent of all drivers for this architecture and version */
3888 result
= winreg_printer_opendriver(tmp_ctx
,
3896 if (!W_ERROR_IS_OK(result
)) {
3897 DEBUG(5, ("winreg_get_driver_list: "
3898 "Could not open key (%s,%u): %s\n",
3899 architecture
, version
, win_errstr(result
)));
3904 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
3910 if (!NT_STATUS_IS_OK(status
)) {
3911 result
= ntstatus_to_werror(status
);
3913 if (!W_ERROR_IS_OK(result
)) {
3914 DEBUG(0, ("winreg_get_driver_list: "
3915 "Could not enumerate drivers for (%s,%u): %s\n",
3916 architecture
, version
, win_errstr(result
)));
3920 *drivers_p
= talloc_steal(mem_ctx
, drivers
);
3924 if (winreg_handle
!= NULL
) {
3927 if (is_valid_policy_hnd(&key_hnd
)) {
3928 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3930 if (is_valid_policy_hnd(&hive_hnd
)) {
3931 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3935 TALLOC_FREE(tmp_ctx
);