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
;
942 tmp_ctx
= talloc_stackframe();
943 if (tmp_ctx
== NULL
) {
947 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
949 TALLOC_FREE(tmp_ctx
);
953 ZERO_STRUCT(hive_hnd
);
954 ZERO_STRUCT(key_hnd
);
956 result
= winreg_printer_openkey(tmp_ctx
,
964 if (!W_ERROR_IS_OK(result
)) {
965 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
966 path
, win_errstr(result
)));
970 if (info2_mask
& SPOOLSS_PRINTER_INFO_ATTRIBUTES
) {
971 status
= dcerpc_winreg_set_dword(tmp_ctx
,
977 if (!NT_STATUS_IS_OK(status
)) {
978 result
= ntstatus_to_werror(status
);
980 if (!W_ERROR_IS_OK(result
)) {
986 if (info2_mask
& SPOOLSS_PRINTER_INFO_AVERAGEPPM
) {
987 status
= dcerpc_winreg_set_dword(tmp_ctx
,
993 if (!NT_STATUS_IS_OK(status
)) {
994 result
= ntstatus_to_werror(status
);
996 if (!W_ERROR_IS_OK(result
)) {
1002 if (info2_mask
& SPOOLSS_PRINTER_INFO_COMMENT
) {
1003 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1009 if (!NT_STATUS_IS_OK(status
)) {
1010 result
= ntstatus_to_werror(status
);
1012 if (!W_ERROR_IS_OK(result
)) {
1017 if (info2_mask
& SPOOLSS_PRINTER_INFO_DATATYPE
) {
1018 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1024 if (!NT_STATUS_IS_OK(status
)) {
1025 result
= ntstatus_to_werror(status
);
1027 if (!W_ERROR_IS_OK(result
)) {
1032 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
) {
1033 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1037 info2
->defaultpriority
,
1039 if (!NT_STATUS_IS_OK(status
)) {
1040 result
= ntstatus_to_werror(status
);
1042 if (!W_ERROR_IS_OK(result
)) {
1047 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEVMODE
) {
1049 * Some client drivers freak out if there is a NULL devmode
1050 * (probably the driver is not checking before accessing
1051 * the devmode pointer) --jerry
1053 if (devmode
== NULL
&& lp_default_devmode(snum
) && info2
!= NULL
) {
1054 result
= spoolss_create_default_devmode(tmp_ctx
,
1057 if (!W_ERROR_IS_OK(result
)) {
1062 if (devmode
->size
!= (ndr_size_spoolss_DeviceMode(devmode
, 0) - devmode
->__driverextra_length
)) {
1063 result
= WERR_INVALID_PARAM
;
1067 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, devmode
,
1068 (ndr_push_flags_fn_t
) ndr_push_spoolss_DeviceMode
);
1069 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1070 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1071 result
= WERR_NOMEM
;
1075 status
= dcerpc_winreg_set_binary(tmp_ctx
,
1081 if (!NT_STATUS_IS_OK(status
)) {
1082 result
= ntstatus_to_werror(status
);
1084 if (!W_ERROR_IS_OK(result
)) {
1089 if (info2_mask
& SPOOLSS_PRINTER_INFO_DRIVERNAME
) {
1090 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1096 if (!NT_STATUS_IS_OK(status
)) {
1097 result
= ntstatus_to_werror(status
);
1099 if (!W_ERROR_IS_OK(result
)) {
1104 if (info2_mask
& SPOOLSS_PRINTER_INFO_LOCATION
) {
1105 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1111 if (!NT_STATUS_IS_OK(status
)) {
1112 result
= ntstatus_to_werror(status
);
1114 if (!W_ERROR_IS_OK(result
)) {
1119 if (info2_mask
& SPOOLSS_PRINTER_INFO_PARAMETERS
) {
1120 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1126 if (!NT_STATUS_IS_OK(status
)) {
1127 result
= ntstatus_to_werror(status
);
1129 if (!W_ERROR_IS_OK(result
)) {
1134 if (info2_mask
& SPOOLSS_PRINTER_INFO_PORTNAME
) {
1135 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1141 if (!NT_STATUS_IS_OK(status
)) {
1142 result
= ntstatus_to_werror(status
);
1144 if (!W_ERROR_IS_OK(result
)) {
1149 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTERNAME
) {
1151 * in addprinter: no servername and the printer is the name
1152 * in setprinter: servername is \\server
1153 * and printer is \\server\\printer
1155 * Samba manages only local printers.
1156 * we currently don't support things like i
1157 * path=\\other_server\printer
1159 * We only store the printername, not \\server\printername
1161 const char *p
= strrchr(info2
->printername
, '\\');
1163 p
= info2
->printername
;
1167 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1173 if (!NT_STATUS_IS_OK(status
)) {
1174 result
= ntstatus_to_werror(status
);
1176 if (!W_ERROR_IS_OK(result
)) {
1181 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
) {
1182 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1186 info2
->printprocessor
,
1188 if (!NT_STATUS_IS_OK(status
)) {
1189 result
= ntstatus_to_werror(status
);
1191 if (!W_ERROR_IS_OK(result
)) {
1196 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRIORITY
) {
1197 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1203 if (!NT_STATUS_IS_OK(status
)) {
1204 result
= ntstatus_to_werror(status
);
1206 if (!W_ERROR_IS_OK(result
)) {
1211 if (info2_mask
& SPOOLSS_PRINTER_INFO_SECDESC
) {
1213 * We need a security descriptor, if it isn't specified by
1214 * AddPrinter{Ex} then create a default descriptor.
1216 if (secdesc
== NULL
) {
1217 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1218 if (!W_ERROR_IS_OK(result
)) {
1222 result
= winreg_set_printer_secdesc(tmp_ctx
,
1226 if (!W_ERROR_IS_OK(result
)) {
1231 if (info2_mask
& SPOOLSS_PRINTER_INFO_SEPFILE
) {
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_SHARENAME
) {
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_STARTTIME
) {
1262 status
= dcerpc_winreg_set_dword(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_STATUS
) {
1277 status
= dcerpc_winreg_set_dword(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_UNTILTIME
) {
1292 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1298 if (!NT_STATUS_IS_OK(status
)) {
1299 result
= ntstatus_to_werror(status
);
1301 if (!W_ERROR_IS_OK(result
)) {
1306 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1310 winreg_printer_rev_changeid(),
1312 if (!NT_STATUS_IS_OK(status
)) {
1313 result
= ntstatus_to_werror(status
);
1315 if (!W_ERROR_IS_OK(result
)) {
1321 if (winreg_handle
!= NULL
) {
1324 if (is_valid_policy_hnd(&key_hnd
)) {
1325 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1327 if (is_valid_policy_hnd(&hive_hnd
)) {
1328 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1332 TALLOC_FREE(tmp_ctx
);
1336 WERROR
winreg_get_printer(TALLOC_CTX
*mem_ctx
,
1337 struct dcerpc_binding_handle
*winreg_handle
,
1338 const char *printer
,
1339 struct spoolss_PrinterInfo2
**pinfo2
)
1341 struct spoolss_PrinterInfo2
*info2
;
1342 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1343 struct policy_handle hive_hnd
, key_hnd
;
1344 struct spoolss_PrinterEnumValues enum_value
;
1345 struct spoolss_PrinterEnumValues
*v
= NULL
;
1346 enum ndr_err_code ndr_err
;
1348 int snum
= lp_servicenumber(printer
);
1349 uint32_t num_values
= 0;
1353 WERROR result
= WERR_OK
;
1354 const char **enum_names
= NULL
;
1355 enum winreg_Type
*enum_types
= NULL
;
1356 DATA_BLOB
*enum_data_blobs
= NULL
;
1357 TALLOC_CTX
*tmp_ctx
;
1359 tmp_ctx
= talloc_stackframe();
1360 if (tmp_ctx
== NULL
) {
1364 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1366 TALLOC_FREE(tmp_ctx
);
1370 result
= winreg_printer_openkey(tmp_ctx
,
1378 if (!W_ERROR_IS_OK(result
)) {
1379 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
1380 path
, win_errstr(result
)));
1384 status
= dcerpc_winreg_enumvals(tmp_ctx
,
1392 if (!NT_STATUS_IS_OK(status
)){
1393 result
= ntstatus_to_werror(status
);
1396 if (!W_ERROR_IS_OK(result
)) {
1397 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1398 path
, win_errstr(result
)));
1402 info2
= talloc_zero(tmp_ctx
, struct spoolss_PrinterInfo2
);
1403 if (info2
== NULL
) {
1404 result
= WERR_NOMEM
;
1408 FILL_STRING(info2
, EMPTY_STRING
, info2
->servername
);
1409 FILL_STRING(info2
, EMPTY_STRING
, info2
->printername
);
1410 FILL_STRING(info2
, EMPTY_STRING
, info2
->sharename
);
1411 FILL_STRING(info2
, EMPTY_STRING
, info2
->portname
);
1412 FILL_STRING(info2
, EMPTY_STRING
, info2
->drivername
);
1413 FILL_STRING(info2
, EMPTY_STRING
, info2
->comment
);
1414 FILL_STRING(info2
, EMPTY_STRING
, info2
->location
);
1415 FILL_STRING(info2
, EMPTY_STRING
, info2
->sepfile
);
1416 FILL_STRING(info2
, EMPTY_STRING
, info2
->printprocessor
);
1417 FILL_STRING(info2
, EMPTY_STRING
, info2
->datatype
);
1418 FILL_STRING(info2
, EMPTY_STRING
, info2
->parameters
);
1420 for (i
= 0; i
< num_values
; i
++) {
1421 enum_value
.value_name
= enum_names
[i
];
1422 enum_value
.value_name_len
= 2*strlen_m_term(enum_names
[i
]);
1423 enum_value
.type
= enum_types
[i
];
1424 enum_value
.data_length
= enum_data_blobs
[i
].length
;
1425 enum_value
.data
= NULL
;
1426 if (enum_value
.data_length
!= 0){
1427 enum_value
.data
= &enum_data_blobs
[i
];
1431 result
= winreg_enumval_to_sz(info2
,
1434 &info2
->printername
);
1435 CHECK_ERROR(result
);
1437 result
= winreg_enumval_to_sz(info2
,
1441 CHECK_ERROR(result
);
1443 result
= winreg_enumval_to_sz(info2
,
1447 CHECK_ERROR(result
);
1449 result
= winreg_enumval_to_sz(info2
,
1453 CHECK_ERROR(result
);
1455 result
= winreg_enumval_to_sz(info2
,
1459 CHECK_ERROR(result
);
1461 result
= winreg_enumval_to_sz(info2
,
1465 CHECK_ERROR(result
);
1467 result
= winreg_enumval_to_sz(info2
,
1470 &info2
->printprocessor
);
1471 CHECK_ERROR(result
);
1473 result
= winreg_enumval_to_sz(info2
,
1477 CHECK_ERROR(result
);
1479 result
= winreg_enumval_to_sz(info2
,
1482 &info2
->parameters
);
1483 CHECK_ERROR(result
);
1485 result
= winreg_enumval_to_sz(info2
,
1488 &info2
->drivername
);
1489 CHECK_ERROR(result
);
1491 result
= winreg_enumval_to_dword(info2
,
1494 &info2
->attributes
);
1495 CHECK_ERROR(result
);
1497 result
= winreg_enumval_to_dword(info2
,
1501 CHECK_ERROR(result
);
1503 result
= winreg_enumval_to_dword(info2
,
1506 &info2
->defaultpriority
);
1507 CHECK_ERROR(result
);
1509 result
= winreg_enumval_to_dword(info2
,
1513 CHECK_ERROR(result
);
1515 result
= winreg_enumval_to_dword(info2
,
1519 CHECK_ERROR(result
);
1521 result
= winreg_enumval_to_dword(info2
,
1525 CHECK_ERROR(result
);
1527 result
= winreg_enumval_to_dword(info2
,
1531 CHECK_ERROR(result
);
1534 if (!W_ERROR_IS_OK(result
)) {
1535 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
1538 win_errstr(result
)));
1542 /* Construct the Device Mode */
1543 status
= dcerpc_winreg_query_binary(tmp_ctx
,
1549 if (!NT_STATUS_IS_OK(status
)) {
1550 result
= ntstatus_to_werror(status
);
1552 if (W_ERROR_IS_OK(result
)) {
1553 info2
->devmode
= talloc_zero(info2
, struct spoolss_DeviceMode
);
1554 if (info2
->devmode
== NULL
) {
1555 result
= WERR_NOMEM
;
1558 ndr_err
= ndr_pull_struct_blob(&blob
,
1561 (ndr_pull_flags_fn_t
) ndr_pull_spoolss_DeviceMode
);
1562 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1563 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
1564 result
= WERR_NOMEM
;
1569 if (info2
->devmode
== NULL
&& lp_default_devmode(snum
)) {
1570 result
= spoolss_create_default_devmode(info2
,
1573 if (!W_ERROR_IS_OK(result
)) {
1578 if (info2
->devmode
) {
1579 info2
->devmode
->size
= ndr_size_spoolss_DeviceMode(info2
->devmode
, 0) - info2
->devmode
->driverextra_data
.length
;
1582 result
= winreg_get_printer_secdesc(info2
,
1586 if (!W_ERROR_IS_OK(result
)) {
1590 /* Fix for OS/2 drivers. */
1591 if (get_remote_arch() == RA_OS2
) {
1592 spoolss_map_to_os2_driver(info2
, &info2
->drivername
);
1596 *pinfo2
= talloc_move(mem_ctx
, &info2
);
1601 if (winreg_handle
!= NULL
) {
1604 if (is_valid_policy_hnd(&key_hnd
)) {
1605 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1607 if (is_valid_policy_hnd(&hive_hnd
)) {
1608 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1612 TALLOC_FREE(tmp_ctx
);
1616 WERROR
winreg_get_printer_secdesc(TALLOC_CTX
*mem_ctx
,
1617 struct dcerpc_binding_handle
*winreg_handle
,
1618 const char *sharename
,
1619 struct spoolss_security_descriptor
**psecdesc
)
1621 struct spoolss_security_descriptor
*secdesc
;
1622 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1623 struct policy_handle hive_hnd
, key_hnd
;
1625 TALLOC_CTX
*tmp_ctx
;
1629 tmp_ctx
= talloc_stackframe();
1630 if (tmp_ctx
== NULL
) {
1634 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1636 talloc_free(tmp_ctx
);
1640 ZERO_STRUCT(hive_hnd
);
1641 ZERO_STRUCT(key_hnd
);
1643 result
= winreg_printer_openkey(tmp_ctx
,
1651 if (!W_ERROR_IS_OK(result
)) {
1652 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1653 goto create_default
;
1658 status
= dcerpc_winreg_query_sd(tmp_ctx
,
1664 if (!NT_STATUS_IS_OK(status
)) {
1665 result
= ntstatus_to_werror(status
);
1667 if (!W_ERROR_IS_OK(result
)) {
1668 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1671 if (is_valid_policy_hnd(&key_hnd
)) {
1672 dcerpc_winreg_CloseKey(winreg_handle
,
1678 if (is_valid_policy_hnd(&hive_hnd
)) {
1679 dcerpc_winreg_CloseKey(winreg_handle
,
1684 goto create_default
;
1690 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1697 result
= winreg_printer_openkey(tmp_ctx
,
1705 if (!W_ERROR_IS_OK(result
)) {
1709 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1710 if (!W_ERROR_IS_OK(result
)) {
1714 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
1715 this security descriptor has been created when winbindd was
1716 down. Take ownership of security descriptor. */
1717 if (dom_sid_equal(secdesc
->owner_sid
, &global_sid_World
)) {
1718 struct dom_sid owner_sid
;
1720 /* Change sd owner to workgroup administrator */
1722 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid
)) {
1723 struct spoolss_security_descriptor
*new_secdesc
;
1727 sid_append_rid(&owner_sid
, DOMAIN_RID_ADMINISTRATOR
);
1729 new_secdesc
= make_sec_desc(tmp_ctx
,
1738 if (new_secdesc
== NULL
) {
1739 result
= WERR_NOMEM
;
1743 /* Swap with other one */
1744 secdesc
= new_secdesc
;
1748 status
= dcerpc_winreg_set_sd(tmp_ctx
,
1754 if (!NT_STATUS_IS_OK(status
)) {
1755 result
= ntstatus_to_werror(status
);
1757 if (!W_ERROR_IS_OK(result
)) {
1762 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1767 if (winreg_handle
!= NULL
) {
1770 if (is_valid_policy_hnd(&key_hnd
)) {
1771 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1773 if (is_valid_policy_hnd(&hive_hnd
)) {
1774 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1778 talloc_free(tmp_ctx
);
1782 WERROR
winreg_set_printer_secdesc(TALLOC_CTX
*mem_ctx
,
1783 struct dcerpc_binding_handle
*winreg_handle
,
1784 const char *sharename
,
1785 const struct spoolss_security_descriptor
*secdesc
)
1787 const struct spoolss_security_descriptor
*new_secdesc
= secdesc
;
1788 struct spoolss_security_descriptor
*old_secdesc
;
1789 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1790 struct policy_handle hive_hnd
, key_hnd
;
1792 TALLOC_CTX
*tmp_ctx
;
1796 tmp_ctx
= talloc_stackframe();
1797 if (tmp_ctx
== NULL
) {
1801 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1803 talloc_free(tmp_ctx
);
1808 * The old owner and group sids of the security descriptor are not
1809 * present when new ACEs are added or removed by changing printer
1810 * permissions through NT. If they are NULL in the new security
1811 * descriptor then copy them over from the old one.
1813 if (!secdesc
->owner_sid
|| !secdesc
->group_sid
) {
1814 struct dom_sid
*owner_sid
, *group_sid
;
1815 struct security_acl
*dacl
, *sacl
;
1818 result
= winreg_get_printer_secdesc(tmp_ctx
,
1822 if (!W_ERROR_IS_OK(result
)) {
1823 talloc_free(tmp_ctx
);
1827 /* Pick out correct owner and group sids */
1828 owner_sid
= secdesc
->owner_sid
?
1829 secdesc
->owner_sid
:
1830 old_secdesc
->owner_sid
;
1832 group_sid
= secdesc
->group_sid
?
1833 secdesc
->group_sid
:
1834 old_secdesc
->group_sid
;
1836 dacl
= secdesc
->dacl
?
1840 sacl
= secdesc
->sacl
?
1844 /* Make a deep copy of the security descriptor */
1845 new_secdesc
= make_sec_desc(tmp_ctx
,
1853 if (new_secdesc
== NULL
) {
1854 talloc_free(tmp_ctx
);
1859 ZERO_STRUCT(hive_hnd
);
1860 ZERO_STRUCT(key_hnd
);
1862 result
= winreg_printer_openkey(tmp_ctx
,
1870 if (!W_ERROR_IS_OK(result
)) {
1874 status
= dcerpc_winreg_set_sd(tmp_ctx
,
1880 if (!NT_STATUS_IS_OK(status
)) {
1881 result
= ntstatus_to_werror(status
);
1885 if (winreg_handle
!= NULL
) {
1888 if (is_valid_policy_hnd(&key_hnd
)) {
1889 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1891 if (is_valid_policy_hnd(&hive_hnd
)) {
1892 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1896 talloc_free(tmp_ctx
);
1900 /* Set printer data over the winreg pipe. */
1901 WERROR
winreg_set_printer_dataex(TALLOC_CTX
*mem_ctx
,
1902 struct dcerpc_binding_handle
*winreg_handle
,
1903 const char *printer
,
1906 enum winreg_Type type
,
1910 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1911 struct policy_handle hive_hnd
, key_hnd
;
1912 struct winreg_String wvalue
= { 0, };
1914 WERROR result
= WERR_OK
;
1916 TALLOC_CTX
*tmp_ctx
;
1918 tmp_ctx
= talloc_stackframe();
1919 if (tmp_ctx
== NULL
) {
1923 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1925 TALLOC_FREE(tmp_ctx
);
1929 ZERO_STRUCT(hive_hnd
);
1930 ZERO_STRUCT(key_hnd
);
1932 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
1933 key
, value
, access_mask
, printer
));
1934 result
= winreg_printer_openkey(tmp_ctx
,
1942 if (!W_ERROR_IS_OK(result
)) {
1943 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
1944 key
, win_errstr(result
)));
1948 wvalue
.name
= value
;
1949 status
= dcerpc_winreg_SetValue(winreg_handle
,
1957 if (!NT_STATUS_IS_OK(status
)) {
1958 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
1959 value
, nt_errstr(status
)));
1960 result
= ntstatus_to_werror(status
);
1964 if (winreg_handle
!= NULL
) {
1967 if (is_valid_policy_hnd(&key_hnd
)) {
1968 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1970 if (is_valid_policy_hnd(&hive_hnd
)) {
1971 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1975 TALLOC_FREE(tmp_ctx
);
1979 /* Get printer data over a winreg pipe. */
1980 WERROR
winreg_get_printer_dataex(TALLOC_CTX
*mem_ctx
,
1981 struct dcerpc_binding_handle
*winreg_handle
,
1982 const char *printer
,
1985 enum winreg_Type
*type
,
1987 uint32_t *data_size
)
1989 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1990 struct policy_handle hive_hnd
, key_hnd
;
1991 struct winreg_String wvalue
;
1992 enum winreg_Type type_in
= REG_NONE
;
1994 uint8_t *data_in
= NULL
;
1995 uint32_t data_in_size
= 0;
1996 uint32_t value_len
= 0;
1997 WERROR result
= WERR_OK
;
1999 TALLOC_CTX
*tmp_ctx
;
2001 tmp_ctx
= talloc_stackframe();
2002 if (tmp_ctx
== NULL
) {
2006 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2008 TALLOC_FREE(tmp_ctx
);
2012 ZERO_STRUCT(hive_hnd
);
2013 ZERO_STRUCT(key_hnd
);
2015 result
= winreg_printer_openkey(tmp_ctx
,
2023 if (!W_ERROR_IS_OK(result
)) {
2024 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2025 key
, win_errstr(result
)));
2029 wvalue
.name
= value
;
2032 * call QueryValue once with data == NULL to get the
2033 * needed memory size to be allocated, then allocate
2034 * data buffer and call again.
2036 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2045 if (!NT_STATUS_IS_OK(status
)) {
2046 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2047 value
, nt_errstr(status
)));
2048 result
= ntstatus_to_werror(status
);
2051 if (!W_ERROR_IS_OK(result
)) {
2052 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2053 value
, win_errstr(result
)));
2057 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
2058 if (data_in
== NULL
) {
2059 result
= WERR_NOMEM
;
2064 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2073 if (!NT_STATUS_IS_OK(status
)) {
2074 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2075 value
, nt_errstr(status
)));
2076 result
= ntstatus_to_werror(status
);
2079 if (!W_ERROR_IS_OK(result
)) {
2080 DEBUG(2, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2081 value
, win_errstr(result
)));
2086 *data_size
= data_in_size
;
2088 *data
= talloc_move(mem_ctx
, &data_in
);
2093 if (winreg_handle
!= NULL
) {
2096 if (is_valid_policy_hnd(&key_hnd
)) {
2097 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2099 if (is_valid_policy_hnd(&hive_hnd
)) {
2100 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2104 TALLOC_FREE(tmp_ctx
);
2108 /* Enumerate on the values of a given key and provide the data. */
2109 WERROR
winreg_enum_printer_dataex(TALLOC_CTX
*mem_ctx
,
2110 struct dcerpc_binding_handle
*winreg_handle
,
2111 const char *printer
,
2113 uint32_t *pnum_values
,
2114 struct spoolss_PrinterEnumValues
**penum_values
)
2117 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2118 struct policy_handle hive_hnd
, key_hnd
;
2120 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2121 uint32_t num_values
= 0;
2123 WERROR result
= WERR_OK
;
2125 const char **enum_names
= NULL
;
2126 enum winreg_Type
*enum_types
= NULL
;
2127 DATA_BLOB
*enum_data_blobs
= NULL
;
2129 TALLOC_CTX
*tmp_ctx
;
2131 tmp_ctx
= talloc_stackframe();
2132 if (tmp_ctx
== NULL
) {
2136 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2138 TALLOC_FREE(tmp_ctx
);
2142 result
= winreg_printer_openkey(tmp_ctx
,
2150 if (!W_ERROR_IS_OK(result
)) {
2151 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2152 key
, win_errstr(result
)));
2156 status
= dcerpc_winreg_enumvals(tmp_ctx
,
2164 if (!NT_STATUS_IS_OK(status
)){
2165 result
= ntstatus_to_werror(status
);
2168 if (!W_ERROR_IS_OK(result
)) {
2169 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2170 key
, win_errstr(result
)));
2174 enum_values
= talloc_array(tmp_ctx
, struct spoolss_PrinterEnumValues
, num_values
);
2175 if (enum_values
== NULL
){
2176 result
= WERR_NOMEM
;
2177 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2178 key
, win_errstr(result
)));
2182 for (i
= 0; i
< num_values
; i
++){
2183 enum_values
[i
].value_name
= enum_names
[i
];
2184 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
2185 enum_values
[i
].type
= enum_types
[i
];
2186 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
2187 enum_values
[i
].data
= NULL
;
2189 if (enum_values
[i
].data_length
!= 0){
2190 enum_values
[i
].data
= &enum_data_blobs
[i
];
2194 talloc_steal(enum_values
, enum_names
);
2195 talloc_steal(enum_values
, enum_data_blobs
);
2197 *pnum_values
= num_values
;
2199 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
2204 if (winreg_handle
!= NULL
) {
2207 if (is_valid_policy_hnd(&key_hnd
)) {
2208 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2210 if (is_valid_policy_hnd(&hive_hnd
)) {
2211 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2215 TALLOC_FREE(tmp_ctx
);
2219 /* Delete printer data over a winreg pipe. */
2220 WERROR
winreg_delete_printer_dataex(TALLOC_CTX
*mem_ctx
,
2221 struct dcerpc_binding_handle
*winreg_handle
,
2222 const char *printer
,
2226 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2227 struct policy_handle hive_hnd
, key_hnd
;
2228 struct winreg_String wvalue
= { 0, };
2230 WERROR result
= WERR_OK
;
2233 TALLOC_CTX
*tmp_ctx
;
2235 tmp_ctx
= talloc_stackframe();
2236 if (tmp_ctx
== NULL
) {
2240 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2242 TALLOC_FREE(tmp_ctx
);
2246 ZERO_STRUCT(hive_hnd
);
2247 ZERO_STRUCT(key_hnd
);
2249 result
= winreg_printer_openkey(tmp_ctx
,
2257 if (!W_ERROR_IS_OK(result
)) {
2258 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2259 key
, win_errstr(result
)));
2263 wvalue
.name
= value
;
2264 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
2269 if (!NT_STATUS_IS_OK(status
)) {
2270 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2271 value
, nt_errstr(status
)));
2272 result
= ntstatus_to_werror(status
);
2276 if (winreg_handle
!= NULL
) {
2279 if (is_valid_policy_hnd(&key_hnd
)) {
2280 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2282 if (is_valid_policy_hnd(&hive_hnd
)) {
2283 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2287 TALLOC_FREE(tmp_ctx
);
2291 /* Enumerate on the subkeys of a given key and provide the data. */
2292 WERROR
winreg_enum_printer_key(TALLOC_CTX
*mem_ctx
,
2293 struct dcerpc_binding_handle
*winreg_handle
,
2294 const char *printer
,
2296 uint32_t *pnum_subkeys
,
2297 const char ***psubkeys
)
2299 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2300 struct policy_handle hive_hnd
, key_hnd
;
2302 const char **subkeys
= NULL
;
2303 uint32_t num_subkeys
= -1;
2305 WERROR result
= WERR_OK
;
2308 TALLOC_CTX
*tmp_ctx
;
2310 tmp_ctx
= talloc_stackframe();
2311 if (tmp_ctx
== NULL
) {
2315 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2317 TALLOC_FREE(tmp_ctx
);
2321 ZERO_STRUCT(hive_hnd
);
2322 ZERO_STRUCT(key_hnd
);
2324 result
= winreg_printer_openkey(tmp_ctx
,
2332 if (!W_ERROR_IS_OK(result
)) {
2333 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2334 key
, win_errstr(result
)));
2338 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
2344 if (!NT_STATUS_IS_OK(status
)) {
2345 result
= ntstatus_to_werror(status
);
2347 if (!W_ERROR_IS_OK(result
)) {
2348 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2349 key
, win_errstr(result
)));
2353 *pnum_subkeys
= num_subkeys
;
2355 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
2360 if (winreg_handle
!= NULL
) {
2363 if (is_valid_policy_hnd(&key_hnd
)) {
2364 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2366 if (is_valid_policy_hnd(&hive_hnd
)) {
2367 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2371 TALLOC_FREE(tmp_ctx
);
2375 /* Delete a key with subkeys of a given printer. */
2376 WERROR
winreg_delete_printer_key(TALLOC_CTX
*mem_ctx
,
2377 struct dcerpc_binding_handle
*winreg_handle
,
2378 const char *printer
,
2381 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2382 struct policy_handle hive_hnd
, key_hnd
;
2387 TALLOC_CTX
*tmp_ctx
;
2389 tmp_ctx
= talloc_stackframe();
2390 if (tmp_ctx
== NULL
) {
2394 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2396 TALLOC_FREE(tmp_ctx
);
2400 result
= winreg_printer_openkey(tmp_ctx
,
2408 if (!W_ERROR_IS_OK(result
)) {
2409 /* key doesn't exist */
2410 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2415 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2416 key
, win_errstr(result
)));
2420 if (is_valid_policy_hnd(&key_hnd
)) {
2421 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
2424 if (key
== NULL
|| key
[0] == '\0') {
2427 keyname
= talloc_asprintf(tmp_ctx
,
2431 if (keyname
== NULL
) {
2432 result
= WERR_NOMEM
;
2437 status
= dcerpc_winreg_delete_subkeys_recursive(tmp_ctx
,
2444 if (!NT_STATUS_IS_OK(status
)) {
2445 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2446 key
, nt_errstr(status
)));
2447 result
= ntstatus_to_werror(status
);
2451 if (!W_ERROR_IS_OK(result
)) {
2452 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2453 key
, win_errstr(result
)));
2458 if (winreg_handle
!= NULL
) {
2461 if (is_valid_policy_hnd(&key_hnd
)) {
2462 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2464 if (is_valid_policy_hnd(&hive_hnd
)) {
2465 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2469 TALLOC_FREE(tmp_ctx
);
2473 WERROR
winreg_printer_update_changeid(TALLOC_CTX
*mem_ctx
,
2474 struct dcerpc_binding_handle
*winreg_handle
,
2475 const char *printer
)
2477 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2478 struct policy_handle hive_hnd
, key_hnd
;
2482 TALLOC_CTX
*tmp_ctx
;
2484 tmp_ctx
= talloc_stackframe();
2485 if (tmp_ctx
== NULL
) {
2489 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2491 TALLOC_FREE(tmp_ctx
);
2495 ZERO_STRUCT(hive_hnd
);
2496 ZERO_STRUCT(key_hnd
);
2498 result
= winreg_printer_openkey(tmp_ctx
,
2506 if (!W_ERROR_IS_OK(result
)) {
2507 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2508 path
, win_errstr(result
)));
2512 status
= dcerpc_winreg_set_dword(tmp_ctx
,
2516 winreg_printer_rev_changeid(),
2518 if (!NT_STATUS_IS_OK(status
)) {
2519 result
= ntstatus_to_werror(status
);
2521 if (!W_ERROR_IS_OK(result
)) {
2527 if (winreg_handle
!= NULL
) {
2530 if (is_valid_policy_hnd(&key_hnd
)) {
2531 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2533 if (is_valid_policy_hnd(&hive_hnd
)) {
2534 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2538 TALLOC_FREE(tmp_ctx
);
2542 WERROR
winreg_printer_get_changeid(TALLOC_CTX
*mem_ctx
,
2543 struct dcerpc_binding_handle
*winreg_handle
,
2544 const char *printer
,
2545 uint32_t *pchangeid
)
2547 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2548 struct policy_handle hive_hnd
, key_hnd
;
2549 uint32_t changeid
= 0;
2553 TALLOC_CTX
*tmp_ctx
;
2555 tmp_ctx
= talloc_stackframe();
2556 if (tmp_ctx
== NULL
) {
2560 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2562 TALLOC_FREE(tmp_ctx
);
2566 ZERO_STRUCT(hive_hnd
);
2567 ZERO_STRUCT(key_hnd
);
2569 result
= winreg_printer_openkey(tmp_ctx
,
2577 if (!W_ERROR_IS_OK(result
)) {
2578 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2579 path
, win_errstr(result
)));
2583 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path
));
2585 status
= dcerpc_winreg_query_dword(tmp_ctx
,
2591 if (!NT_STATUS_IS_OK(status
)) {
2592 result
= ntstatus_to_werror(status
);
2594 if (!W_ERROR_IS_OK(result
)) {
2599 *pchangeid
= changeid
;
2604 if (winreg_handle
!= NULL
) {
2607 if (is_valid_policy_hnd(&key_hnd
)) {
2608 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2610 if (is_valid_policy_hnd(&hive_hnd
)) {
2611 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2615 TALLOC_FREE(tmp_ctx
);
2620 * The special behaviour of the spoolss forms is documented at the website:
2622 * Managing Win32 Printserver Forms
2623 * http://unixwiz.net/techtips/winspooler-forms.html
2626 WERROR
winreg_printer_addform1(TALLOC_CTX
*mem_ctx
,
2627 struct dcerpc_binding_handle
*winreg_handle
,
2628 struct spoolss_AddFormInfo1
*form
)
2630 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2631 struct policy_handle hive_hnd
, key_hnd
;
2632 struct winreg_String wvalue
= { 0, };
2634 uint32_t num_info
= 0;
2635 union spoolss_FormInfo
*info
= NULL
;
2639 TALLOC_CTX
*tmp_ctx
;
2641 tmp_ctx
= talloc_stackframe();
2642 if (tmp_ctx
== NULL
) {
2646 ZERO_STRUCT(hive_hnd
);
2647 ZERO_STRUCT(key_hnd
);
2649 result
= winreg_printer_openkey(tmp_ctx
,
2651 TOP_LEVEL_CONTROL_FORMS_KEY
,
2657 if (!W_ERROR_IS_OK(result
)) {
2658 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2659 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2663 result
= winreg_printer_enumforms1(tmp_ctx
, winreg_handle
,
2665 if (!W_ERROR_IS_OK(result
)) {
2666 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2667 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2671 /* If form name already exists or is builtin return ALREADY_EXISTS */
2672 for (i
= 0; i
< num_info
; i
++) {
2673 if (strequal(info
[i
].info1
.form_name
, form
->form_name
)) {
2674 result
= WERR_FILE_EXISTS
;
2679 wvalue
.name
= form
->form_name
;
2681 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
2682 SIVAL(blob
.data
, 0, form
->size
.width
);
2683 SIVAL(blob
.data
, 4, form
->size
.height
);
2684 SIVAL(blob
.data
, 8, form
->area
.left
);
2685 SIVAL(blob
.data
, 12, form
->area
.top
);
2686 SIVAL(blob
.data
, 16, form
->area
.right
);
2687 SIVAL(blob
.data
, 20, form
->area
.bottom
);
2688 SIVAL(blob
.data
, 24, num_info
+ 1); /* FIXME */
2689 SIVAL(blob
.data
, 28, form
->flags
);
2691 status
= dcerpc_winreg_SetValue(winreg_handle
,
2699 if (!NT_STATUS_IS_OK(status
)) {
2700 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2701 wvalue
.name
, nt_errstr(status
)));
2702 result
= ntstatus_to_werror(status
);
2706 if (winreg_handle
!= NULL
) {
2709 if (is_valid_policy_hnd(&key_hnd
)) {
2710 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2712 if (is_valid_policy_hnd(&hive_hnd
)) {
2713 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2718 TALLOC_FREE(tmp_ctx
);
2722 WERROR
winreg_printer_enumforms1(TALLOC_CTX
*mem_ctx
,
2723 struct dcerpc_binding_handle
*winreg_handle
,
2724 uint32_t *pnum_info
,
2725 union spoolss_FormInfo
**pinfo
)
2727 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2728 struct policy_handle hive_hnd
, key_hnd
;
2729 union spoolss_FormInfo
*info
;
2730 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2731 uint32_t num_values
= 0;
2732 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2736 const char **enum_names
= NULL
;
2737 enum winreg_Type
*enum_types
= NULL
;
2738 DATA_BLOB
*enum_data_blobs
= NULL
;
2739 TALLOC_CTX
*tmp_ctx
;
2741 tmp_ctx
= talloc_stackframe();
2742 if (tmp_ctx
== NULL
) {
2746 ZERO_STRUCT(hive_hnd
);
2747 ZERO_STRUCT(key_hnd
);
2749 result
= winreg_printer_openkey(tmp_ctx
,
2751 TOP_LEVEL_CONTROL_FORMS_KEY
,
2757 if (!W_ERROR_IS_OK(result
)) {
2758 /* key doesn't exist */
2759 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2764 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
2765 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2769 status
= dcerpc_winreg_enumvals(tmp_ctx
,
2777 if (!NT_STATUS_IS_OK(status
)){
2778 result
= ntstatus_to_werror(status
);
2781 if (!W_ERROR_IS_OK(result
)) {
2782 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2783 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2787 enum_values
= talloc_zero_array(tmp_ctx
,
2788 struct spoolss_PrinterEnumValues
,
2790 if (enum_values
== NULL
){
2791 result
= WERR_NOMEM
;
2795 for (i
= 0; i
< num_values
; i
++){
2796 enum_values
[i
].value_name
= enum_names
[i
];
2797 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
2798 enum_values
[i
].type
= enum_types
[i
];
2799 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
2800 enum_values
[i
].data
= NULL
;
2801 if (enum_values
[i
].data_length
!= 0){
2802 enum_values
[i
].data
= &enum_data_blobs
[i
];
2806 if (!W_ERROR_IS_OK(result
)) {
2807 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2808 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2812 info
= talloc_array(tmp_ctx
, union spoolss_FormInfo
, num_builtin
+ num_values
);
2814 result
= WERR_NOMEM
;
2818 /* Enumerate BUILTIN forms */
2819 for (i
= 0; i
< num_builtin
; i
++) {
2820 info
[i
].info1
= builtin_forms1
[i
];
2823 /* Enumerate registry forms */
2824 for (i
= 0; i
< num_values
; i
++) {
2825 union spoolss_FormInfo val
;
2827 if (enum_values
[i
].type
!= REG_BINARY
||
2828 enum_values
[i
].data_length
!= 32) {
2832 val
.info1
.form_name
= talloc_strdup(info
, enum_values
[i
].value_name
);
2833 if (val
.info1
.form_name
== NULL
) {
2834 result
= WERR_NOMEM
;
2838 val
.info1
.size
.width
= IVAL(enum_values
[i
].data
->data
, 0);
2839 val
.info1
.size
.height
= IVAL(enum_values
[i
].data
->data
, 4);
2840 val
.info1
.area
.left
= IVAL(enum_values
[i
].data
->data
, 8);
2841 val
.info1
.area
.top
= IVAL(enum_values
[i
].data
->data
, 12);
2842 val
.info1
.area
.right
= IVAL(enum_values
[i
].data
->data
, 16);
2843 val
.info1
.area
.bottom
= IVAL(enum_values
[i
].data
->data
, 20);
2844 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
2845 val
.info1
.flags
= (enum spoolss_FormFlags
) IVAL(enum_values
[i
].data
->data
, 28);
2847 info
[i
+ num_builtin
] = val
;
2850 *pnum_info
= num_builtin
+ num_values
;
2852 *pinfo
= talloc_move(mem_ctx
, &info
);
2856 if (winreg_handle
!= NULL
) {
2859 if (is_valid_policy_hnd(&key_hnd
)) {
2860 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2862 if (is_valid_policy_hnd(&hive_hnd
)) {
2863 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2867 TALLOC_FREE(enum_values
);
2868 TALLOC_FREE(tmp_ctx
);
2872 WERROR
winreg_printer_deleteform1(TALLOC_CTX
*mem_ctx
,
2873 struct dcerpc_binding_handle
*winreg_handle
,
2874 const char *form_name
)
2876 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2877 struct policy_handle hive_hnd
, key_hnd
;
2878 struct winreg_String wvalue
= { 0, };
2879 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2881 WERROR result
= WERR_OK
;
2883 TALLOC_CTX
*tmp_ctx
;
2885 for (i
= 0; i
< num_builtin
; i
++) {
2886 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
2887 return WERR_INVALID_PARAMETER
;
2891 tmp_ctx
= talloc_stackframe();
2892 if (tmp_ctx
== NULL
) {
2896 ZERO_STRUCT(hive_hnd
);
2897 ZERO_STRUCT(key_hnd
);
2899 result
= winreg_printer_openkey(tmp_ctx
,
2901 TOP_LEVEL_CONTROL_FORMS_KEY
,
2907 if (!W_ERROR_IS_OK(result
)) {
2908 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
2909 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2910 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2911 result
= WERR_INVALID_FORM_NAME
;
2916 wvalue
.name
= form_name
;
2917 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
2922 if (!NT_STATUS_IS_OK(status
)) {
2923 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
2924 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
2925 wvalue
.name
, nt_errstr(status
)));
2926 result
= ntstatus_to_werror(status
);
2930 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2931 result
= WERR_INVALID_FORM_NAME
;
2935 if (winreg_handle
!= NULL
) {
2938 if (is_valid_policy_hnd(&key_hnd
)) {
2939 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2941 if (is_valid_policy_hnd(&hive_hnd
)) {
2942 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2946 TALLOC_FREE(tmp_ctx
);
2950 WERROR
winreg_printer_setform1(TALLOC_CTX
*mem_ctx
,
2951 struct dcerpc_binding_handle
*winreg_handle
,
2952 const char *form_name
,
2953 struct spoolss_AddFormInfo1
*form
)
2955 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2956 struct policy_handle hive_hnd
, key_hnd
;
2957 struct winreg_String wvalue
= { 0, };
2959 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2963 TALLOC_CTX
*tmp_ctx
= NULL
;
2965 for (i
= 0; i
< num_builtin
; i
++) {
2966 if (strequal(builtin_forms1
[i
].form_name
, form
->form_name
)) {
2967 result
= WERR_INVALID_PARAM
;
2972 tmp_ctx
= talloc_stackframe();
2973 if (tmp_ctx
== NULL
) {
2977 ZERO_STRUCT(hive_hnd
);
2978 ZERO_STRUCT(key_hnd
);
2980 result
= winreg_printer_openkey(tmp_ctx
,
2982 TOP_LEVEL_CONTROL_FORMS_KEY
,
2988 if (!W_ERROR_IS_OK(result
)) {
2989 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
2990 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2994 /* If form_name != form->form_name then we renamed the form */
2995 if (strequal(form_name
, form
->form_name
)) {
2996 result
= winreg_printer_deleteform1(tmp_ctx
, winreg_handle
,
2998 if (!W_ERROR_IS_OK(result
)) {
2999 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3000 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3005 wvalue
.name
= form
->form_name
;
3007 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
3008 SIVAL(blob
.data
, 0, form
->size
.width
);
3009 SIVAL(blob
.data
, 4, form
->size
.height
);
3010 SIVAL(blob
.data
, 8, form
->area
.left
);
3011 SIVAL(blob
.data
, 12, form
->area
.top
);
3012 SIVAL(blob
.data
, 16, form
->area
.right
);
3013 SIVAL(blob
.data
, 20, form
->area
.bottom
);
3014 SIVAL(blob
.data
, 24, 42);
3015 SIVAL(blob
.data
, 28, form
->flags
);
3017 status
= dcerpc_winreg_SetValue(winreg_handle
,
3025 if (!NT_STATUS_IS_OK(status
)) {
3026 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3027 wvalue
.name
, nt_errstr(status
)));
3028 result
= ntstatus_to_werror(status
);
3032 if (winreg_handle
!= NULL
) {
3035 if (is_valid_policy_hnd(&key_hnd
)) {
3036 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3038 if (is_valid_policy_hnd(&hive_hnd
)) {
3039 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3043 TALLOC_FREE(tmp_ctx
);
3047 WERROR
winreg_printer_getform1(TALLOC_CTX
*mem_ctx
,
3048 struct dcerpc_binding_handle
*winreg_handle
,
3049 const char *form_name
,
3050 struct spoolss_FormInfo1
*r
)
3052 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3053 struct policy_handle hive_hnd
, key_hnd
;
3054 struct winreg_String wvalue
;
3055 enum winreg_Type type_in
= REG_NONE
;
3056 uint8_t *data_in
= NULL
;
3057 uint32_t data_in_size
= 0;
3058 uint32_t value_len
= 0;
3059 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3063 TALLOC_CTX
*tmp_ctx
;
3065 /* check builtin forms first */
3066 for (i
= 0; i
< num_builtin
; i
++) {
3067 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3068 *r
= builtin_forms1
[i
];
3073 tmp_ctx
= talloc_stackframe();
3074 if (tmp_ctx
== NULL
) {
3078 ZERO_STRUCT(hive_hnd
);
3079 ZERO_STRUCT(key_hnd
);
3081 result
= winreg_printer_openkey(tmp_ctx
,
3083 TOP_LEVEL_CONTROL_FORMS_KEY
,
3089 if (!W_ERROR_IS_OK(result
)) {
3090 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3091 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3095 wvalue
.name
= form_name
;
3098 * call QueryValue once with data == NULL to get the
3099 * needed memory size to be allocated, then allocate
3100 * data buffer and call again.
3102 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3111 if (!NT_STATUS_IS_OK(status
)) {
3112 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3113 wvalue
.name
, nt_errstr(status
)));
3114 result
= ntstatus_to_werror(status
);
3117 if (!W_ERROR_IS_OK(result
)) {
3121 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
3122 if (data_in
== NULL
) {
3123 result
= WERR_NOMEM
;
3128 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3137 if (!NT_STATUS_IS_OK(status
)) {
3138 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3139 wvalue
.name
, nt_errstr(status
)));
3140 result
= ntstatus_to_werror(status
);
3143 if (!W_ERROR_IS_OK(result
)) {
3147 r
->form_name
= talloc_strdup(mem_ctx
, form_name
);
3148 if (r
->form_name
== NULL
) {
3149 result
= WERR_NOMEM
;
3153 r
->size
.width
= IVAL(data_in
, 0);
3154 r
->size
.height
= IVAL(data_in
, 4);
3155 r
->area
.left
= IVAL(data_in
, 8);
3156 r
->area
.top
= IVAL(data_in
, 12);
3157 r
->area
.right
= IVAL(data_in
, 16);
3158 r
->area
.bottom
= IVAL(data_in
, 20);
3159 /* skip index IVAL(data_in, 24)));*/
3160 r
->flags
= (enum spoolss_FormFlags
) IVAL(data_in
, 28);
3164 if (winreg_handle
!= NULL
) {
3167 if (is_valid_policy_hnd(&key_hnd
)) {
3168 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3170 if (is_valid_policy_hnd(&hive_hnd
)) {
3171 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3175 TALLOC_FREE(tmp_ctx
);
3179 WERROR
winreg_add_driver(TALLOC_CTX
*mem_ctx
,
3180 struct dcerpc_binding_handle
*winreg_handle
,
3181 struct spoolss_AddDriverInfoCtr
*r
,
3182 const char **driver_name
,
3183 uint32_t *driver_version
)
3185 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3186 struct policy_handle hive_hnd
, key_hnd
;
3187 struct spoolss_DriverInfo8 info8
;
3188 TALLOC_CTX
*tmp_ctx
= NULL
;
3192 ZERO_STRUCT(hive_hnd
);
3193 ZERO_STRUCT(key_hnd
);
3196 if (!driver_info_ctr_to_info8(r
, &info8
)) {
3197 result
= WERR_INVALID_PARAMETER
;
3201 tmp_ctx
= talloc_stackframe();
3202 if (tmp_ctx
== NULL
) {
3206 result
= winreg_printer_opendriver(tmp_ctx
,
3214 if (!W_ERROR_IS_OK(result
)) {
3215 DEBUG(0, ("winreg_add_driver: "
3216 "Could not open driver key (%s,%s,%d): %s\n",
3217 info8
.driver_name
, info8
.architecture
,
3218 info8
.version
, win_errstr(result
)));
3222 /* TODO: "Attributes" ? */
3224 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3230 if (!NT_STATUS_IS_OK(status
)) {
3231 result
= ntstatus_to_werror(status
);
3233 if (!W_ERROR_IS_OK(result
)) {
3237 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3243 if (!NT_STATUS_IS_OK(status
)) {
3244 result
= ntstatus_to_werror(status
);
3246 if (!W_ERROR_IS_OK(result
)) {
3250 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3256 if (!NT_STATUS_IS_OK(status
)) {
3257 result
= ntstatus_to_werror(status
);
3259 if (!W_ERROR_IS_OK(result
)) {
3263 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3266 "Configuration File",
3269 if (!NT_STATUS_IS_OK(status
)) {
3270 result
= ntstatus_to_werror(status
);
3272 if (!W_ERROR_IS_OK(result
)) {
3276 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3282 if (!NT_STATUS_IS_OK(status
)) {
3283 result
= ntstatus_to_werror(status
);
3285 if (!W_ERROR_IS_OK(result
)) {
3289 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3293 info8
.dependent_files
,
3295 if (!NT_STATUS_IS_OK(status
)) {
3296 result
= ntstatus_to_werror(status
);
3298 if (!W_ERROR_IS_OK(result
)) {
3302 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3308 if (!NT_STATUS_IS_OK(status
)) {
3309 result
= ntstatus_to_werror(status
);
3311 if (!W_ERROR_IS_OK(result
)) {
3315 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3319 info8
.default_datatype
,
3321 if (!NT_STATUS_IS_OK(status
)) {
3322 result
= ntstatus_to_werror(status
);
3324 if (!W_ERROR_IS_OK(result
)) {
3328 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3330 &key_hnd
, "Previous Names",
3331 info8
.previous_names
,
3333 if (!NT_STATUS_IS_OK(status
)) {
3334 result
= ntstatus_to_werror(status
);
3336 if (!W_ERROR_IS_OK(result
)) {
3340 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3341 &key_hnd
, "DriverDate",
3343 if (!W_ERROR_IS_OK(result
)) {
3347 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
,
3348 &key_hnd
, "DriverVersion",
3349 info8
.driver_version
);
3350 if (!W_ERROR_IS_OK(result
)) {
3354 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3358 info8
.manufacturer_name
,
3360 if (!NT_STATUS_IS_OK(status
)) {
3361 result
= ntstatus_to_werror(status
);
3363 if (!W_ERROR_IS_OK(result
)) {
3367 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3371 info8
.manufacturer_url
,
3373 if (!NT_STATUS_IS_OK(status
)) {
3374 result
= ntstatus_to_werror(status
);
3376 if (!W_ERROR_IS_OK(result
)) {
3380 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3386 if (!NT_STATUS_IS_OK(status
)) {
3387 result
= ntstatus_to_werror(status
);
3389 if (!W_ERROR_IS_OK(result
)) {
3393 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3399 if (!NT_STATUS_IS_OK(status
)) {
3400 result
= ntstatus_to_werror(status
);
3402 if (!W_ERROR_IS_OK(result
)) {
3406 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3410 info8
.print_processor
,
3412 if (!NT_STATUS_IS_OK(status
)) {
3413 result
= ntstatus_to_werror(status
);
3415 if (!W_ERROR_IS_OK(result
)) {
3419 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3425 if (!NT_STATUS_IS_OK(status
)) {
3426 result
= ntstatus_to_werror(status
);
3428 if (!W_ERROR_IS_OK(result
)) {
3432 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3436 info8
.color_profiles
,
3438 if (!NT_STATUS_IS_OK(status
)) {
3439 result
= ntstatus_to_werror(status
);
3441 if (!W_ERROR_IS_OK(result
)) {
3445 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3451 if (!NT_STATUS_IS_OK(status
)) {
3452 result
= ntstatus_to_werror(status
);
3454 if (!W_ERROR_IS_OK(result
)) {
3458 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3461 "PrinterDriverAttributes",
3462 info8
.printer_driver_attributes
,
3464 if (!NT_STATUS_IS_OK(status
)) {
3465 result
= ntstatus_to_werror(status
);
3467 if (!W_ERROR_IS_OK(result
)) {
3471 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3475 info8
.core_driver_dependencies
,
3477 if (!NT_STATUS_IS_OK(status
)) {
3478 result
= ntstatus_to_werror(status
);
3480 if (!W_ERROR_IS_OK(result
)) {
3484 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3485 &key_hnd
, "MinInboxDriverVerDate",
3486 info8
.min_inbox_driver_ver_date
);
3487 if (!W_ERROR_IS_OK(result
)) {
3491 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
, &key_hnd
,
3492 "MinInboxDriverVerVersion",
3493 info8
.min_inbox_driver_ver_version
);
3494 if (!W_ERROR_IS_OK(result
)) {
3498 *driver_name
= info8
.driver_name
;
3499 *driver_version
= info8
.version
;
3502 if (winreg_handle
!= NULL
) {
3505 if (is_valid_policy_hnd(&key_hnd
)) {
3506 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3508 if (is_valid_policy_hnd(&hive_hnd
)) {
3509 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3513 TALLOC_FREE(tmp_ctx
);
3517 WERROR
winreg_get_driver(TALLOC_CTX
*mem_ctx
,
3518 struct dcerpc_binding_handle
*winreg_handle
,
3519 const char *architecture
,
3520 const char *driver_name
,
3521 uint32_t driver_version
,
3522 struct spoolss_DriverInfo8
**_info8
)
3524 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3525 struct policy_handle hive_hnd
, key_hnd
;
3526 struct spoolss_DriverInfo8 i8
, *info8
;
3527 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
3528 struct spoolss_PrinterEnumValues
*v
;
3529 uint32_t num_values
= 0;
3530 TALLOC_CTX
*tmp_ctx
;
3534 const char **enum_names
= NULL
;
3535 enum winreg_Type
*enum_types
= NULL
;
3536 DATA_BLOB
*enum_data_blobs
= NULL
;
3538 ZERO_STRUCT(hive_hnd
);
3539 ZERO_STRUCT(key_hnd
);
3542 tmp_ctx
= talloc_stackframe();
3543 if (tmp_ctx
== NULL
) {
3547 if (driver_version
== DRIVER_ANY_VERSION
) {
3548 /* look for Win2k first and then for NT4 */
3549 result
= winreg_printer_opendriver(tmp_ctx
,
3557 if (!W_ERROR_IS_OK(result
)) {
3558 result
= winreg_printer_opendriver(tmp_ctx
,
3568 /* ok normal case */
3569 result
= winreg_printer_opendriver(tmp_ctx
,
3578 if (!W_ERROR_IS_OK(result
)) {
3579 DEBUG(5, ("winreg_get_driver: "
3580 "Could not open driver key (%s,%s,%d): %s\n",
3581 driver_name
, architecture
,
3582 driver_version
, win_errstr(result
)));
3586 status
= dcerpc_winreg_enumvals(tmp_ctx
,
3594 if (!NT_STATUS_IS_OK(status
)){
3595 result
= ntstatus_to_werror(status
);
3598 if (!W_ERROR_IS_OK(result
)) {
3599 DEBUG(0, ("winreg_get_driver: "
3600 "Could not enumerate values for (%s,%s,%d): %s\n",
3601 driver_name
, architecture
,
3602 driver_version
, win_errstr(result
)));
3606 enum_values
= talloc_zero_array(tmp_ctx
,
3607 struct spoolss_PrinterEnumValues
,
3609 if (enum_values
== NULL
){
3610 result
= WERR_NOMEM
;
3614 for (i
= 0; i
< num_values
; i
++){
3615 enum_values
[i
].value_name
= enum_names
[i
];
3616 enum_values
[i
].value_name_len
= strlen_m_term(enum_names
[i
]) * 2;
3617 enum_values
[i
].type
= enum_types
[i
];
3618 enum_values
[i
].data_length
= enum_data_blobs
[i
].length
;
3619 enum_values
[i
].data
= NULL
;
3620 if (enum_values
[i
].data_length
!= 0){
3621 enum_values
[i
].data
= &enum_data_blobs
[i
];
3625 info8
= talloc_zero(tmp_ctx
, struct spoolss_DriverInfo8
);
3626 if (info8
== NULL
) {
3627 result
= WERR_NOMEM
;
3631 info8
->driver_name
= talloc_strdup(info8
, driver_name
);
3632 if (info8
->driver_name
== NULL
) {
3633 result
= WERR_NOMEM
;
3637 info8
->architecture
= talloc_strdup(info8
, architecture
);
3638 if (info8
->architecture
== NULL
) {
3639 result
= WERR_NOMEM
;
3645 for (i
= 0; i
< num_values
; i
++) {
3646 const char *tmp_str
;
3649 v
= &enum_values
[i
];
3651 result
= winreg_enumval_to_dword(info8
, v
,
3654 if (W_ERROR_IS_OK(result
)) {
3655 info8
->version
= (enum spoolss_DriverOSVersion
) tmp
;
3657 CHECK_ERROR(result
);
3659 result
= winreg_enumval_to_sz(info8
, v
,
3661 &info8
->driver_path
);
3662 CHECK_ERROR(result
);
3664 result
= winreg_enumval_to_sz(info8
, v
,
3667 CHECK_ERROR(result
);
3669 result
= winreg_enumval_to_sz(info8
, v
,
3670 "Configuration File",
3671 &info8
->config_file
);
3672 CHECK_ERROR(result
);
3674 result
= winreg_enumval_to_sz(info8
, v
,
3677 CHECK_ERROR(result
);
3679 result
= winreg_enumval_to_multi_sz(info8
, v
,
3681 &info8
->dependent_files
);
3682 CHECK_ERROR(result
);
3684 result
= winreg_enumval_to_sz(info8
, v
,
3686 &info8
->monitor_name
);
3687 CHECK_ERROR(result
);
3689 result
= winreg_enumval_to_sz(info8
, v
,
3691 &info8
->default_datatype
);
3692 CHECK_ERROR(result
);
3694 result
= winreg_enumval_to_multi_sz(info8
, v
,
3696 &info8
->previous_names
);
3697 CHECK_ERROR(result
);
3699 result
= winreg_enumval_to_sz(info8
, v
,
3702 if (W_ERROR_IS_OK(result
)) {
3703 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3704 &info8
->driver_date
);
3706 CHECK_ERROR(result
);
3708 result
= winreg_enumval_to_sz(info8
, v
,
3711 if (W_ERROR_IS_OK(result
)) {
3712 result
= winreg_printer_ver_to_dword(tmp_str
,
3713 &info8
->driver_version
);
3715 CHECK_ERROR(result
);
3717 result
= winreg_enumval_to_sz(info8
, v
,
3719 &info8
->manufacturer_name
);
3720 CHECK_ERROR(result
);
3722 result
= winreg_enumval_to_sz(info8
, v
,
3724 &info8
->manufacturer_url
);
3725 CHECK_ERROR(result
);
3727 result
= winreg_enumval_to_sz(info8
, v
,
3729 &info8
->hardware_id
);
3730 CHECK_ERROR(result
);
3732 result
= winreg_enumval_to_sz(info8
, v
,
3735 CHECK_ERROR(result
);
3737 result
= winreg_enumval_to_sz(info8
, v
,
3739 &info8
->print_processor
);
3740 CHECK_ERROR(result
);
3742 result
= winreg_enumval_to_sz(info8
, v
,
3744 &info8
->vendor_setup
);
3745 CHECK_ERROR(result
);
3747 result
= winreg_enumval_to_multi_sz(info8
, v
,
3749 &info8
->color_profiles
);
3750 CHECK_ERROR(result
);
3752 result
= winreg_enumval_to_sz(info8
, v
,
3755 CHECK_ERROR(result
);
3757 result
= winreg_enumval_to_dword(info8
, v
,
3758 "PrinterDriverAttributes",
3759 &info8
->printer_driver_attributes
);
3760 CHECK_ERROR(result
);
3762 result
= winreg_enumval_to_multi_sz(info8
, v
,
3764 &info8
->core_driver_dependencies
);
3765 CHECK_ERROR(result
);
3767 result
= winreg_enumval_to_sz(info8
, v
,
3768 "MinInboxDriverVerDate",
3770 if (W_ERROR_IS_OK(result
)) {
3771 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3772 &info8
->min_inbox_driver_ver_date
);
3774 CHECK_ERROR(result
);
3776 result
= winreg_enumval_to_sz(info8
, v
,
3777 "MinInboxDriverVerVersion",
3779 if (W_ERROR_IS_OK(result
)) {
3780 result
= winreg_printer_ver_to_dword(tmp_str
,
3781 &info8
->min_inbox_driver_ver_version
);
3783 CHECK_ERROR(result
);
3786 if (!W_ERROR_IS_OK(result
)) {
3787 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3788 "for %s: %s\n", v
->value_name
,
3789 win_errstr(result
)));
3793 *_info8
= talloc_steal(mem_ctx
, info8
);
3796 if (winreg_handle
!= NULL
) {
3799 if (is_valid_policy_hnd(&key_hnd
)) {
3800 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3802 if (is_valid_policy_hnd(&hive_hnd
)) {
3803 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3807 TALLOC_FREE(tmp_ctx
);
3811 WERROR
winreg_del_driver(TALLOC_CTX
*mem_ctx
,
3812 struct dcerpc_binding_handle
*winreg_handle
,
3813 struct spoolss_DriverInfo8
*info8
,
3816 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3817 struct policy_handle hive_hnd
, key_hnd
;
3818 TALLOC_CTX
*tmp_ctx
;
3823 ZERO_STRUCT(hive_hnd
);
3824 ZERO_STRUCT(key_hnd
);
3826 tmp_ctx
= talloc_stackframe();
3827 if (tmp_ctx
== NULL
) {
3831 /* test that the key exists */
3832 result
= winreg_printer_opendriver(tmp_ctx
,
3835 info8
->architecture
,
3840 if (!W_ERROR_IS_OK(result
)) {
3841 /* key doesn't exist */
3842 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3847 DEBUG(5, ("winreg_del_driver: "
3848 "Could not open driver (%s,%s,%u): %s\n",
3849 info8
->driver_name
, info8
->architecture
,
3850 version
, win_errstr(result
)));
3855 if (is_valid_policy_hnd(&key_hnd
)) {
3856 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
3859 key_name
= talloc_asprintf(tmp_ctx
,
3860 "%s\\Environments\\%s\\Drivers\\Version-%u\\%s",
3861 TOP_LEVEL_CONTROL_KEY
,
3862 info8
->architecture
, version
,
3863 info8
->driver_name
);
3864 if (key_name
== NULL
) {
3865 result
= WERR_NOMEM
;
3869 status
= dcerpc_winreg_delete_subkeys_recursive(tmp_ctx
,
3876 if (!NT_STATUS_IS_OK(status
)){
3877 DEBUG(0, ("winreg_del_driver: "
3878 "Could not open driver (%s,%s,%u): %s\n",
3879 info8
->driver_name
, info8
->architecture
,
3880 version
, nt_errstr(status
)));
3884 if (!W_ERROR_IS_OK(result
)) {
3885 DEBUG(0, ("winreg_del_driver: "
3886 "Could not open driver (%s,%s,%u): %s\n",
3887 info8
->driver_name
, info8
->architecture
,
3888 version
, win_errstr(result
)));
3894 if (winreg_handle
!= NULL
) {
3897 if (is_valid_policy_hnd(&key_hnd
)) {
3898 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3900 if (is_valid_policy_hnd(&hive_hnd
)) {
3901 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3905 TALLOC_FREE(tmp_ctx
);
3909 WERROR
winreg_get_driver_list(TALLOC_CTX
*mem_ctx
,
3910 struct dcerpc_binding_handle
*winreg_handle
,
3911 const char *architecture
,
3913 uint32_t *num_drivers
,
3914 const char ***drivers_p
)
3916 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3917 struct policy_handle hive_hnd
, key_hnd
;
3918 const char **drivers
;
3919 TALLOC_CTX
*tmp_ctx
;
3926 ZERO_STRUCT(hive_hnd
);
3927 ZERO_STRUCT(key_hnd
);
3929 tmp_ctx
= talloc_stackframe();
3930 if (tmp_ctx
== NULL
) {
3934 /* use NULL for the driver name so we open the key that is
3935 * parent of all drivers for this architecture and version */
3936 result
= winreg_printer_opendriver(tmp_ctx
,
3944 if (!W_ERROR_IS_OK(result
)) {
3945 DEBUG(5, ("winreg_get_driver_list: "
3946 "Could not open key (%s,%u): %s\n",
3947 architecture
, version
, win_errstr(result
)));
3952 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
3958 if (!NT_STATUS_IS_OK(status
)) {
3959 result
= ntstatus_to_werror(status
);
3961 if (!W_ERROR_IS_OK(result
)) {
3962 DEBUG(0, ("winreg_get_driver_list: "
3963 "Could not enumerate drivers for (%s,%u): %s\n",
3964 architecture
, version
, win_errstr(result
)));
3968 *drivers_p
= talloc_steal(mem_ctx
, drivers
);
3972 if (winreg_handle
!= NULL
) {
3975 if (is_valid_policy_hnd(&key_hnd
)) {
3976 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3978 if (is_valid_policy_hnd(&hive_hnd
)) {
3979 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3983 TALLOC_FREE(tmp_ctx
);