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 return ntstatus_to_werror(status
);
303 if (!W_ERROR_IS_OK(result
)) {
311 * @brief Create the registry keyname for the given printer.
313 * @param[in] mem_ctx The memory context to use.
315 * @param[in] printer The name of the printer to get the registry key.
317 * @return The registry key or NULL on error.
319 static char *winreg_printer_data_keyname(TALLOC_CTX
*mem_ctx
, const char *printer
) {
320 return talloc_asprintf(mem_ctx
, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY
, printer
);
326 * @brief Enumerate values of an opened key handle and retrieve the data.
328 * @param[in] mem_ctx The memory context to use.
330 * @param[in] winreg_handle The binding handle for the rpc connection.
332 * @param[in] key_hnd The opened key handle.
334 * @param[out] pnum_values A pointer to store he number of values found.
336 * @param[out] pnum_values A pointer to store the number of values we found.
338 * @return WERR_OK on success, the corresponding DOS error
339 * code if something gone wrong.
341 static WERROR
winreg_printer_enumvalues(TALLOC_CTX
*mem_ctx
,
342 struct dcerpc_binding_handle
*winreg_handle
,
343 struct policy_handle
*key_hnd
,
344 uint32_t *pnum_values
,
345 struct spoolss_PrinterEnumValues
**penum_values
)
348 uint32_t num_subkeys
, max_subkeylen
, max_classlen
;
349 uint32_t num_values
, max_valnamelen
, max_valbufsize
;
350 uint32_t secdescsize
;
352 NTTIME last_changed_time
;
353 struct winreg_String classname
;
355 struct spoolss_PrinterEnumValues
*enum_values
;
357 WERROR result
= WERR_OK
;
360 tmp_ctx
= talloc_stackframe();
361 if (tmp_ctx
== NULL
) {
365 ZERO_STRUCT(classname
);
367 status
= dcerpc_winreg_QueryInfoKey(winreg_handle
,
380 if (!NT_STATUS_IS_OK(status
)) {
381 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
383 result
= ntstatus_to_werror(status
);
386 if (!W_ERROR_IS_OK(result
)) {
387 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
388 win_errstr(result
)));
392 if (num_values
== 0) {
394 TALLOC_FREE(tmp_ctx
);
398 enum_values
= talloc_array(tmp_ctx
, struct spoolss_PrinterEnumValues
, num_values
);
399 if (enum_values
== NULL
) {
404 for (i
= 0; i
< num_values
; i
++) {
405 struct spoolss_PrinterEnumValues val
;
406 struct winreg_ValNameBuf name_buf
;
407 enum winreg_Type type
= REG_NONE
;
414 name_buf
.size
= max_valnamelen
+ 2;
417 data_size
= max_valbufsize
;
420 data
= (uint8_t *) talloc_zero_size(tmp_ctx
, data_size
);
424 status
= dcerpc_winreg_EnumValue(winreg_handle
,
431 data_size
? &data_size
: NULL
,
434 if (W_ERROR_EQUAL(result
, WERR_NO_MORE_ITEMS
) ) {
436 status
= NT_STATUS_OK
;
440 if (!NT_STATUS_IS_OK(status
)) {
441 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
443 result
= ntstatus_to_werror(status
);
446 if (!W_ERROR_IS_OK(result
)) {
447 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
448 win_errstr(result
)));
452 if (name_buf
.name
== NULL
) {
453 result
= WERR_INVALID_PARAMETER
;
457 val
.value_name
= talloc_strdup(enum_values
, name_buf
.name
);
458 if (val
.value_name
== NULL
) {
462 val
.value_name_len
= strlen_m_term(val
.value_name
) * 2;
465 val
.data_length
= length
;
467 if (val
.data_length
) {
468 val
.data
= talloc(enum_values
, DATA_BLOB
);
469 if (val
.data
== NULL
) {
473 *val
.data
= data_blob_talloc(val
.data
, data
, val
.data_length
);
476 enum_values
[i
] = val
;
479 *pnum_values
= num_values
;
481 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
487 TALLOC_FREE(tmp_ctx
);
494 * @brief A function to delete a key and its subkeys recurively.
496 * @param[in] mem_ctx The memory context to use.
498 * @param[in] winreg_handle The binding handle for the rpc connection.
500 * @param[in] hive_handle A opened hive handle to the key.
502 * @param[in] access_mask The access mask to access the key.
504 * @param[in] key The key to delete
506 * @return WERR_OK on success, the corresponding DOS error
507 * code if something gone wrong.
509 static WERROR
winreg_printer_delete_subkeys(TALLOC_CTX
*mem_ctx
,
510 struct dcerpc_binding_handle
*winreg_handle
,
511 struct policy_handle
*hive_handle
,
512 uint32_t access_mask
,
515 const char **subkeys
= NULL
;
516 uint32_t num_subkeys
= 0;
517 struct policy_handle key_hnd
;
518 struct winreg_String wkey
= { 0, };
519 WERROR result
= WERR_OK
;
523 ZERO_STRUCT(key_hnd
);
526 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key
));
528 status
= dcerpc_winreg_OpenKey(winreg_handle
,
536 if (!NT_STATUS_IS_OK(status
)) {
537 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
538 wkey
.name
, nt_errstr(status
)));
539 return ntstatus_to_werror(status
);
541 if (!W_ERROR_IS_OK(result
)) {
542 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
543 wkey
.name
, win_errstr(result
)));
547 status
= dcerpc_winreg_enum_keys(mem_ctx
,
553 if (!NT_STATUS_IS_OK(status
)) {
554 result
= ntstatus_to_werror(status
);
556 if (!W_ERROR_IS_OK(result
)) {
560 for (i
= 0; i
< num_subkeys
; i
++) {
561 /* create key + subkey */
562 char *subkey
= talloc_asprintf(mem_ctx
, "%s\\%s", key
, subkeys
[i
]);
563 if (subkey
== NULL
) {
567 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey
));
568 result
= winreg_printer_delete_subkeys(mem_ctx
,
573 if (!W_ERROR_IS_OK(result
)) {
578 if (is_valid_policy_hnd(&key_hnd
)) {
580 dcerpc_winreg_CloseKey(winreg_handle
, mem_ctx
, &key_hnd
, &ignore
);
585 status
= dcerpc_winreg_DeleteKey(winreg_handle
,
590 if (!NT_STATUS_IS_OK(status
)) {
591 result
= ntstatus_to_werror(status
);
595 if (is_valid_policy_hnd(&key_hnd
)) {
598 dcerpc_winreg_CloseKey(winreg_handle
, mem_ctx
, &key_hnd
, &ignore
);
604 static WERROR
winreg_printer_opendriver(TALLOC_CTX
*mem_ctx
,
605 struct dcerpc_binding_handle
*winreg_handle
,
606 const char *drivername
,
607 const char *architecture
,
609 uint32_t access_mask
,
611 struct policy_handle
*hive_hnd
,
612 struct policy_handle
*key_hnd
)
617 key_name
= talloc_asprintf(mem_ctx
, "%s\\Environments\\%s\\Drivers\\Version-%u",
618 TOP_LEVEL_CONTROL_KEY
,
619 architecture
, version
);
624 result
= winreg_printer_openkey(mem_ctx
,
635 static WERROR
winreg_enumval_to_dword(TALLOC_CTX
*mem_ctx
,
636 struct spoolss_PrinterEnumValues
*v
,
637 const char *valuename
, uint32_t *dw
)
639 /* just return if it is not the one we are looking for */
640 if (strcmp(valuename
, v
->value_name
) != 0) {
641 return WERR_NOT_FOUND
;
644 if (v
->type
!= REG_DWORD
) {
645 return WERR_INVALID_DATATYPE
;
648 if (v
->data_length
!= 4) {
653 *dw
= IVAL(v
->data
->data
, 0);
657 static WERROR
winreg_enumval_to_sz(TALLOC_CTX
*mem_ctx
,
658 struct spoolss_PrinterEnumValues
*v
,
659 const char *valuename
, const char **_str
)
661 /* just return if it is not the one we are looking for */
662 if (strcmp(valuename
, v
->value_name
) != 0) {
663 return WERR_NOT_FOUND
;
666 if (v
->type
!= REG_SZ
) {
667 return WERR_INVALID_DATATYPE
;
670 if (v
->data_length
== 0) {
671 *_str
= talloc_strdup(mem_ctx
, EMPTY_STRING
);
678 if (!pull_reg_sz(mem_ctx
, v
->data
, _str
)) {
685 static WERROR
winreg_enumval_to_multi_sz(TALLOC_CTX
*mem_ctx
,
686 struct spoolss_PrinterEnumValues
*v
,
687 const char *valuename
,
690 /* just return if it is not the one we are looking for */
691 if (strcmp(valuename
, v
->value_name
) != 0) {
692 return WERR_NOT_FOUND
;
695 if (v
->type
!= REG_MULTI_SZ
) {
696 return WERR_INVALID_DATATYPE
;
699 if (v
->data_length
== 0) {
700 *array
= talloc_array(mem_ctx
, const char *, 1);
701 if (*array
== NULL
) {
708 if (!pull_reg_multi_sz(mem_ctx
, v
->data
, array
)) {
715 static WERROR
winreg_printer_write_date(TALLOC_CTX
*mem_ctx
,
716 struct dcerpc_binding_handle
*winreg_handle
,
717 struct policy_handle
*key_handle
,
721 struct winreg_String wvalue
= { 0, };
723 WERROR result
= WERR_OK
;
730 str
= talloc_strdup(mem_ctx
, "01/01/1601");
732 t
= nt_time_to_unix(data
);
735 return map_werror_from_unix(errno
);
737 str
= talloc_asprintf(mem_ctx
, "%02d/%02d/%04d",
738 tm
->tm_mon
+ 1, tm
->tm_mday
, tm
->tm_year
+ 1900);
745 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
748 status
= dcerpc_winreg_SetValue(winreg_handle
,
756 if (!NT_STATUS_IS_OK(status
)) {
757 result
= ntstatus_to_werror(status
);
759 if (!W_ERROR_IS_OK(result
)) {
760 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
761 wvalue
.name
, win_errstr(result
)));
767 static WERROR
winreg_printer_date_to_NTTIME(const char *str
, NTTIME
*data
)
772 if (strequal(str
, "01/01/1601")) {
779 if (sscanf(str
, "%d/%d/%d",
780 &tm
.tm_mon
, &tm
.tm_mday
, &tm
.tm_year
) != 3) {
781 return WERR_INVALID_PARAMETER
;
788 unix_to_nt_time(data
, t
);
793 static WERROR
winreg_printer_write_ver(TALLOC_CTX
*mem_ctx
,
794 struct dcerpc_binding_handle
*winreg_handle
,
795 struct policy_handle
*key_handle
,
799 struct winreg_String wvalue
= { 0, };
801 WERROR result
= WERR_OK
;
805 /* FIXME: check format is right,
806 * this needs to be something like: 6.1.7600.16385 */
807 str
= talloc_asprintf(mem_ctx
, "%u.%u.%u.%u",
808 (unsigned)((data
>> 48) & 0xFFFF),
809 (unsigned)((data
>> 32) & 0xFFFF),
810 (unsigned)((data
>> 16) & 0xFFFF),
811 (unsigned)(data
& 0xFFFF));
817 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
820 status
= dcerpc_winreg_SetValue(winreg_handle
,
828 if (!NT_STATUS_IS_OK(status
)) {
829 result
= ntstatus_to_werror(status
);
831 if (!W_ERROR_IS_OK(result
)) {
832 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
833 wvalue
.name
, win_errstr(result
)));
839 static WERROR
winreg_printer_ver_to_dword(const char *str
, uint64_t *data
)
841 unsigned int v1
, v2
, v3
, v4
;
843 if (sscanf(str
, "%u.%u.%u.%u", &v1
, &v2
, &v3
, &v4
) != 4) {
844 return WERR_INVALID_PARAMETER
;
847 *data
= ((uint64_t)(v1
& 0xFFFF) << 48) +
848 ((uint64_t)(v2
& 0xFFFF) << 32) +
849 ((uint64_t)(v3
& 0xFFFF) << 16) +
850 (uint64_t)(v2
& 0xFFFF);
855 /********************************************************************
856 Public winreg function for spoolss
857 ********************************************************************/
859 WERROR
winreg_create_printer(TALLOC_CTX
*mem_ctx
,
860 struct dcerpc_binding_handle
*winreg_handle
,
861 const char *sharename
)
863 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
864 struct policy_handle hive_hnd
, key_hnd
;
865 struct spoolss_SetPrinterInfo2
*info2
;
866 struct security_descriptor
*secdesc
;
867 struct winreg_String wkey
, wkeyclass
;
869 const char *subkeys
[] = { SPOOL_DSDRIVER_KEY
, SPOOL_DSSPOOLER_KEY
, SPOOL_PRINTERDATA_KEY
};
870 uint32_t i
, count
= ARRAY_SIZE(subkeys
);
871 uint32_t info2_mask
= 0;
872 WERROR result
= WERR_OK
;
875 tmp_ctx
= talloc_stackframe();
876 if (tmp_ctx
== NULL
) {
880 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
882 TALLOC_FREE(tmp_ctx
);
886 ZERO_STRUCT(hive_hnd
);
887 ZERO_STRUCT(key_hnd
);
889 result
= winreg_printer_openkey(tmp_ctx
,
897 if (W_ERROR_IS_OK(result
)) {
898 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path
));
900 } else if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
901 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path
));
902 } else if (!W_ERROR_IS_OK(result
)) {
903 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
904 path
, win_errstr(result
)));
908 /* Create the main key */
909 result
= winreg_printer_openkey(tmp_ctx
,
917 if (!W_ERROR_IS_OK(result
)) {
918 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
919 path
, win_errstr(result
)));
923 if (is_valid_policy_hnd(&key_hnd
)) {
924 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
928 for (i
= 0; i
< count
; i
++) {
930 enum winreg_CreateAction action
= REG_ACTION_NONE
;
932 ZERO_STRUCT(key_hnd
);
935 wkey
.name
= talloc_asprintf(tmp_ctx
, "%s\\%s", path
, subkeys
[i
]);
936 if (wkey
.name
== NULL
) {
941 ZERO_STRUCT(wkeyclass
);
944 status
= dcerpc_winreg_CreateKey(winreg_handle
,
955 if (!NT_STATUS_IS_OK(status
)) {
956 result
= ntstatus_to_werror(status
);
958 if (!W_ERROR_IS_OK(result
)) {
959 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
960 wkey
.name
, win_errstr(result
)));
964 if (strequal(subkeys
[i
], SPOOL_DSSPOOLER_KEY
)) {
965 const char *dnssuffix
;
966 const char *longname
;
969 status
= dcerpc_winreg_set_sz(tmp_ctx
,
972 SPOOL_REG_PRINTERNAME
,
975 if (!NT_STATUS_IS_OK(status
)) {
976 result
= ntstatus_to_werror(status
);
978 if (!W_ERROR_IS_OK(result
)) {
982 status
= dcerpc_winreg_set_sz(tmp_ctx
,
985 SPOOL_REG_SHORTSERVERNAME
,
988 if (!NT_STATUS_IS_OK(status
)) {
989 result
= ntstatus_to_werror(status
);
991 if (!W_ERROR_IS_OK(result
)) {
995 /* We make the assumption that the netbios name
996 * is the same as the DNS name since the former
997 * will be what we used to join the domain
999 dnssuffix
= get_mydnsdomname(tmp_ctx
);
1000 if (dnssuffix
!= NULL
&& dnssuffix
[0] != '\0') {
1001 longname
= talloc_asprintf(tmp_ctx
, "%s.%s", global_myname(), dnssuffix
);
1003 longname
= talloc_strdup(tmp_ctx
, global_myname());
1005 if (longname
== NULL
) {
1006 result
= WERR_NOMEM
;
1010 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1013 SPOOL_REG_SERVERNAME
,
1016 if (!NT_STATUS_IS_OK(status
)) {
1017 result
= ntstatus_to_werror(status
);
1019 if (!W_ERROR_IS_OK(result
)) {
1023 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
1024 longname
, sharename
);
1025 if (uncname
== NULL
) {
1026 result
= WERR_NOMEM
;
1030 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1036 if (!NT_STATUS_IS_OK(status
)) {
1037 result
= ntstatus_to_werror(status
);
1039 if (!W_ERROR_IS_OK(result
)) {
1043 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1046 SPOOL_REG_VERSIONNUMBER
,
1049 if (!NT_STATUS_IS_OK(status
)) {
1050 result
= ntstatus_to_werror(status
);
1052 if (!W_ERROR_IS_OK(result
)) {
1056 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1059 SPOOL_REG_PRINTSTARTTIME
,
1062 if (!NT_STATUS_IS_OK(status
)) {
1063 result
= ntstatus_to_werror(status
);
1065 if (!W_ERROR_IS_OK(result
)) {
1069 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1072 SPOOL_REG_PRINTENDTIME
,
1075 if (!NT_STATUS_IS_OK(status
)) {
1076 result
= ntstatus_to_werror(status
);
1078 if (!W_ERROR_IS_OK(result
)) {
1082 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1088 if (!NT_STATUS_IS_OK(status
)) {
1089 result
= ntstatus_to_werror(status
);
1091 if (!W_ERROR_IS_OK(result
)) {
1095 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1098 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
1101 if (!NT_STATUS_IS_OK(status
)) {
1102 result
= ntstatus_to_werror(status
);
1104 if (!W_ERROR_IS_OK(result
)) {
1109 if (is_valid_policy_hnd(&key_hnd
)) {
1110 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
1113 info2
= talloc_zero(tmp_ctx
, struct spoolss_SetPrinterInfo2
);
1114 if (info2
== NULL
) {
1115 result
= WERR_NOMEM
;
1119 info2
->printername
= sharename
;
1120 if (info2
->printername
== NULL
) {
1121 result
= WERR_NOMEM
;
1124 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTERNAME
;
1126 info2
->sharename
= sharename
;
1127 info2_mask
|= SPOOLSS_PRINTER_INFO_SHARENAME
;
1129 info2
->portname
= SAMBA_PRINTER_PORT_NAME
;
1130 info2_mask
|= SPOOLSS_PRINTER_INFO_PORTNAME
;
1132 info2
->printprocessor
= "winprint";
1133 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
;
1135 info2
->datatype
= "RAW";
1136 info2_mask
|= SPOOLSS_PRINTER_INFO_DATATYPE
;
1138 info2
->comment
= "";
1139 info2_mask
|= SPOOLSS_PRINTER_INFO_COMMENT
;
1141 info2
->attributes
= PRINTER_ATTRIBUTE_SAMBA
;
1142 info2_mask
|= SPOOLSS_PRINTER_INFO_ATTRIBUTES
;
1144 info2
->starttime
= 0; /* Minutes since 12:00am GMT */
1145 info2_mask
|= SPOOLSS_PRINTER_INFO_STARTTIME
;
1147 info2
->untiltime
= 0; /* Minutes since 12:00am GMT */
1148 info2_mask
|= SPOOLSS_PRINTER_INFO_UNTILTIME
;
1150 info2
->priority
= 1;
1151 info2_mask
|= SPOOLSS_PRINTER_INFO_PRIORITY
;
1153 info2
->defaultpriority
= 1;
1154 info2_mask
|= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
;
1156 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1157 if (!W_ERROR_IS_OK(result
)) {
1160 info2_mask
|= SPOOLSS_PRINTER_INFO_SECDESC
;
1163 * Don't write a default Device Mode to the registry! The Device Mode is
1164 * only written to disk with a SetPrinter level 2 or 8.
1167 result
= winreg_update_printer(tmp_ctx
,
1176 if (winreg_handle
!= NULL
) {
1179 if (is_valid_policy_hnd(&key_hnd
)) {
1180 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1182 if (is_valid_policy_hnd(&hive_hnd
)) {
1183 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1187 talloc_free(tmp_ctx
);
1191 WERROR
winreg_update_printer(TALLOC_CTX
*mem_ctx
,
1192 struct dcerpc_binding_handle
*winreg_handle
,
1193 const char *sharename
,
1194 uint32_t info2_mask
,
1195 struct spoolss_SetPrinterInfo2
*info2
,
1196 struct spoolss_DeviceMode
*devmode
,
1197 struct security_descriptor
*secdesc
)
1199 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1200 struct policy_handle hive_hnd
, key_hnd
;
1201 int snum
= lp_servicenumber(sharename
);
1202 enum ndr_err_code ndr_err
;
1205 WERROR result
= WERR_OK
;
1207 TALLOC_CTX
*tmp_ctx
;
1209 tmp_ctx
= talloc_stackframe();
1210 if (tmp_ctx
== NULL
) {
1214 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1216 TALLOC_FREE(tmp_ctx
);
1220 ZERO_STRUCT(hive_hnd
);
1221 ZERO_STRUCT(key_hnd
);
1223 result
= winreg_printer_openkey(tmp_ctx
,
1231 if (!W_ERROR_IS_OK(result
)) {
1232 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1233 path
, win_errstr(result
)));
1237 if (info2_mask
& SPOOLSS_PRINTER_INFO_ATTRIBUTES
) {
1238 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1244 if (!NT_STATUS_IS_OK(status
)) {
1245 result
= ntstatus_to_werror(status
);
1247 if (!W_ERROR_IS_OK(result
)) {
1253 if (info2_mask
& SPOOLSS_PRINTER_INFO_AVERAGEPPM
) {
1254 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1260 if (!NT_STATUS_IS_OK(status
)) {
1261 result
= ntstatus_to_werror(status
);
1263 if (!W_ERROR_IS_OK(result
)) {
1269 if (info2_mask
& SPOOLSS_PRINTER_INFO_COMMENT
) {
1270 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1276 if (!NT_STATUS_IS_OK(status
)) {
1277 result
= ntstatus_to_werror(status
);
1279 if (!W_ERROR_IS_OK(result
)) {
1284 if (info2_mask
& SPOOLSS_PRINTER_INFO_DATATYPE
) {
1285 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1291 if (!NT_STATUS_IS_OK(status
)) {
1292 result
= ntstatus_to_werror(status
);
1294 if (!W_ERROR_IS_OK(result
)) {
1299 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
) {
1300 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1304 info2
->defaultpriority
,
1306 if (!NT_STATUS_IS_OK(status
)) {
1307 result
= ntstatus_to_werror(status
);
1309 if (!W_ERROR_IS_OK(result
)) {
1314 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEVMODE
) {
1316 * Some client drivers freak out if there is a NULL devmode
1317 * (probably the driver is not checking before accessing
1318 * the devmode pointer) --jerry
1320 if (devmode
== NULL
&& lp_default_devmode(snum
) && info2
!= NULL
) {
1321 result
= spoolss_create_default_devmode(tmp_ctx
,
1324 if (!W_ERROR_IS_OK(result
)) {
1329 if (devmode
->size
!= (ndr_size_spoolss_DeviceMode(devmode
, 0) - devmode
->__driverextra_length
)) {
1330 result
= WERR_INVALID_PARAM
;
1334 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, devmode
,
1335 (ndr_push_flags_fn_t
) ndr_push_spoolss_DeviceMode
);
1336 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1337 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1338 result
= WERR_NOMEM
;
1342 status
= dcerpc_winreg_set_binary(tmp_ctx
,
1348 if (!NT_STATUS_IS_OK(status
)) {
1349 result
= ntstatus_to_werror(status
);
1351 if (!W_ERROR_IS_OK(result
)) {
1356 if (info2_mask
& SPOOLSS_PRINTER_INFO_DRIVERNAME
) {
1357 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1363 if (!NT_STATUS_IS_OK(status
)) {
1364 result
= ntstatus_to_werror(status
);
1366 if (!W_ERROR_IS_OK(result
)) {
1371 if (info2_mask
& SPOOLSS_PRINTER_INFO_LOCATION
) {
1372 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1378 if (!NT_STATUS_IS_OK(status
)) {
1379 result
= ntstatus_to_werror(status
);
1381 if (!W_ERROR_IS_OK(result
)) {
1386 if (info2_mask
& SPOOLSS_PRINTER_INFO_PARAMETERS
) {
1387 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1393 if (!NT_STATUS_IS_OK(status
)) {
1394 result
= ntstatus_to_werror(status
);
1396 if (!W_ERROR_IS_OK(result
)) {
1401 if (info2_mask
& SPOOLSS_PRINTER_INFO_PORTNAME
) {
1402 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1408 if (!NT_STATUS_IS_OK(status
)) {
1409 result
= ntstatus_to_werror(status
);
1411 if (!W_ERROR_IS_OK(result
)) {
1416 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTERNAME
) {
1418 * in addprinter: no servername and the printer is the name
1419 * in setprinter: servername is \\server
1420 * and printer is \\server\\printer
1422 * Samba manages only local printers.
1423 * we currently don't support things like i
1424 * path=\\other_server\printer
1426 * We only store the printername, not \\server\printername
1428 const char *p
= strrchr(info2
->printername
, '\\');
1430 p
= info2
->printername
;
1434 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1440 if (!NT_STATUS_IS_OK(status
)) {
1441 result
= ntstatus_to_werror(status
);
1443 if (!W_ERROR_IS_OK(result
)) {
1448 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
) {
1449 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1453 info2
->printprocessor
,
1455 if (!NT_STATUS_IS_OK(status
)) {
1456 result
= ntstatus_to_werror(status
);
1458 if (!W_ERROR_IS_OK(result
)) {
1463 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRIORITY
) {
1464 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1470 if (!NT_STATUS_IS_OK(status
)) {
1471 result
= ntstatus_to_werror(status
);
1473 if (!W_ERROR_IS_OK(result
)) {
1478 if (info2_mask
& SPOOLSS_PRINTER_INFO_SECDESC
) {
1480 * We need a security descriptor, if it isn't specified by
1481 * AddPrinter{Ex} then create a default descriptor.
1483 if (secdesc
== NULL
) {
1484 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1485 if (!W_ERROR_IS_OK(result
)) {
1489 result
= winreg_set_printer_secdesc(tmp_ctx
,
1493 if (!W_ERROR_IS_OK(result
)) {
1498 if (info2_mask
& SPOOLSS_PRINTER_INFO_SEPFILE
) {
1499 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1505 if (!NT_STATUS_IS_OK(status
)) {
1506 result
= ntstatus_to_werror(status
);
1508 if (!W_ERROR_IS_OK(result
)) {
1513 if (info2_mask
& SPOOLSS_PRINTER_INFO_SHARENAME
) {
1514 status
= dcerpc_winreg_set_sz(tmp_ctx
,
1520 if (!NT_STATUS_IS_OK(status
)) {
1521 result
= ntstatus_to_werror(status
);
1523 if (!W_ERROR_IS_OK(result
)) {
1528 if (info2_mask
& SPOOLSS_PRINTER_INFO_STARTTIME
) {
1529 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1535 if (!NT_STATUS_IS_OK(status
)) {
1536 result
= ntstatus_to_werror(status
);
1538 if (!W_ERROR_IS_OK(result
)) {
1543 if (info2_mask
& SPOOLSS_PRINTER_INFO_STATUS
) {
1544 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1550 if (!NT_STATUS_IS_OK(status
)) {
1551 result
= ntstatus_to_werror(status
);
1553 if (!W_ERROR_IS_OK(result
)) {
1558 if (info2_mask
& SPOOLSS_PRINTER_INFO_UNTILTIME
) {
1559 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1565 if (!NT_STATUS_IS_OK(status
)) {
1566 result
= ntstatus_to_werror(status
);
1568 if (!W_ERROR_IS_OK(result
)) {
1573 status
= dcerpc_winreg_set_dword(tmp_ctx
,
1577 winreg_printer_rev_changeid(),
1579 if (!NT_STATUS_IS_OK(status
)) {
1580 result
= ntstatus_to_werror(status
);
1582 if (!W_ERROR_IS_OK(result
)) {
1588 if (winreg_handle
!= NULL
) {
1591 if (is_valid_policy_hnd(&key_hnd
)) {
1592 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1594 if (is_valid_policy_hnd(&hive_hnd
)) {
1595 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1599 TALLOC_FREE(tmp_ctx
);
1603 WERROR
winreg_get_printer(TALLOC_CTX
*mem_ctx
,
1604 struct dcerpc_binding_handle
*winreg_handle
,
1605 const char *printer
,
1606 struct spoolss_PrinterInfo2
**pinfo2
)
1608 struct spoolss_PrinterInfo2
*info2
;
1609 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1610 struct policy_handle hive_hnd
, key_hnd
;
1611 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
1612 struct spoolss_PrinterEnumValues
*v
= NULL
;
1613 enum ndr_err_code ndr_err
;
1615 int snum
= lp_servicenumber(printer
);
1616 uint32_t num_values
= 0;
1620 WERROR result
= WERR_OK
;
1621 TALLOC_CTX
*tmp_ctx
;
1623 tmp_ctx
= talloc_stackframe();
1624 if (tmp_ctx
== NULL
) {
1628 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
1630 TALLOC_FREE(tmp_ctx
);
1634 result
= winreg_printer_openkey(tmp_ctx
,
1642 if (!W_ERROR_IS_OK(result
)) {
1643 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
1644 path
, win_errstr(result
)));
1648 result
= winreg_printer_enumvalues(tmp_ctx
,
1653 if (!W_ERROR_IS_OK(result
)) {
1654 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
1655 path
, win_errstr(result
)));
1659 info2
= talloc_zero(tmp_ctx
, struct spoolss_PrinterInfo2
);
1660 if (info2
== NULL
) {
1661 result
= WERR_NOMEM
;
1665 FILL_STRING(info2
, EMPTY_STRING
, info2
->servername
);
1666 FILL_STRING(info2
, EMPTY_STRING
, info2
->printername
);
1667 FILL_STRING(info2
, EMPTY_STRING
, info2
->sharename
);
1668 FILL_STRING(info2
, EMPTY_STRING
, info2
->portname
);
1669 FILL_STRING(info2
, EMPTY_STRING
, info2
->drivername
);
1670 FILL_STRING(info2
, EMPTY_STRING
, info2
->comment
);
1671 FILL_STRING(info2
, EMPTY_STRING
, info2
->location
);
1672 FILL_STRING(info2
, EMPTY_STRING
, info2
->sepfile
);
1673 FILL_STRING(info2
, EMPTY_STRING
, info2
->printprocessor
);
1674 FILL_STRING(info2
, EMPTY_STRING
, info2
->datatype
);
1675 FILL_STRING(info2
, EMPTY_STRING
, info2
->parameters
);
1677 for (i
= 0; i
< num_values
; i
++) {
1678 v
= &enum_values
[i
];
1680 result
= winreg_enumval_to_sz(info2
,
1683 &info2
->printername
);
1684 CHECK_ERROR(result
);
1686 result
= winreg_enumval_to_sz(info2
,
1690 CHECK_ERROR(result
);
1692 result
= winreg_enumval_to_sz(info2
,
1696 CHECK_ERROR(result
);
1698 result
= winreg_enumval_to_sz(info2
,
1702 CHECK_ERROR(result
);
1704 result
= winreg_enumval_to_sz(info2
,
1708 CHECK_ERROR(result
);
1710 result
= winreg_enumval_to_sz(info2
,
1714 CHECK_ERROR(result
);
1716 result
= winreg_enumval_to_sz(info2
,
1719 &info2
->printprocessor
);
1720 CHECK_ERROR(result
);
1722 result
= winreg_enumval_to_sz(info2
,
1726 CHECK_ERROR(result
);
1728 result
= winreg_enumval_to_sz(info2
,
1731 &info2
->parameters
);
1732 CHECK_ERROR(result
);
1734 result
= winreg_enumval_to_sz(info2
,
1737 &info2
->drivername
);
1738 CHECK_ERROR(result
);
1740 result
= winreg_enumval_to_dword(info2
,
1743 &info2
->attributes
);
1744 CHECK_ERROR(result
);
1746 result
= winreg_enumval_to_dword(info2
,
1750 CHECK_ERROR(result
);
1752 result
= winreg_enumval_to_dword(info2
,
1755 &info2
->defaultpriority
);
1756 CHECK_ERROR(result
);
1758 result
= winreg_enumval_to_dword(info2
,
1762 CHECK_ERROR(result
);
1764 result
= winreg_enumval_to_dword(info2
,
1768 CHECK_ERROR(result
);
1770 result
= winreg_enumval_to_dword(info2
,
1774 CHECK_ERROR(result
);
1776 result
= winreg_enumval_to_dword(info2
,
1780 CHECK_ERROR(result
);
1783 if (!W_ERROR_IS_OK(result
)) {
1784 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
1787 win_errstr(result
)));
1791 /* Construct the Device Mode */
1792 status
= dcerpc_winreg_query_binary(tmp_ctx
,
1798 if (!NT_STATUS_IS_OK(status
)) {
1799 result
= ntstatus_to_werror(status
);
1801 if (W_ERROR_IS_OK(result
)) {
1802 info2
->devmode
= talloc_zero(info2
, struct spoolss_DeviceMode
);
1803 if (info2
->devmode
== NULL
) {
1804 result
= WERR_NOMEM
;
1807 ndr_err
= ndr_pull_struct_blob(&blob
,
1810 (ndr_pull_flags_fn_t
) ndr_pull_spoolss_DeviceMode
);
1811 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1812 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
1813 result
= WERR_NOMEM
;
1818 if (info2
->devmode
== NULL
&& lp_default_devmode(snum
)) {
1819 result
= spoolss_create_default_devmode(info2
,
1822 if (!W_ERROR_IS_OK(result
)) {
1827 if (info2
->devmode
) {
1828 info2
->devmode
->size
= ndr_size_spoolss_DeviceMode(info2
->devmode
, 0) - info2
->devmode
->driverextra_data
.length
;
1831 result
= winreg_get_printer_secdesc(info2
,
1835 if (!W_ERROR_IS_OK(result
)) {
1839 /* Fix for OS/2 drivers. */
1840 if (get_remote_arch() == RA_OS2
) {
1841 spoolss_map_to_os2_driver(info2
, &info2
->drivername
);
1845 *pinfo2
= talloc_move(mem_ctx
, &info2
);
1850 if (winreg_handle
!= NULL
) {
1853 if (is_valid_policy_hnd(&key_hnd
)) {
1854 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1856 if (is_valid_policy_hnd(&hive_hnd
)) {
1857 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1861 TALLOC_FREE(tmp_ctx
);
1865 WERROR
winreg_get_printer_secdesc(TALLOC_CTX
*mem_ctx
,
1866 struct dcerpc_binding_handle
*winreg_handle
,
1867 const char *sharename
,
1868 struct spoolss_security_descriptor
**psecdesc
)
1870 struct spoolss_security_descriptor
*secdesc
;
1871 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1872 struct policy_handle hive_hnd
, key_hnd
;
1874 TALLOC_CTX
*tmp_ctx
;
1878 tmp_ctx
= talloc_stackframe();
1879 if (tmp_ctx
== NULL
) {
1883 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1885 talloc_free(tmp_ctx
);
1889 ZERO_STRUCT(hive_hnd
);
1890 ZERO_STRUCT(key_hnd
);
1892 result
= winreg_printer_openkey(tmp_ctx
,
1900 if (!W_ERROR_IS_OK(result
)) {
1901 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1902 goto create_default
;
1907 status
= dcerpc_winreg_query_sd(tmp_ctx
,
1913 if (!NT_STATUS_IS_OK(status
)) {
1914 result
= ntstatus_to_werror(status
);
1916 if (!W_ERROR_IS_OK(result
)) {
1917 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1918 goto create_default
;
1924 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
1931 result
= winreg_printer_openkey(tmp_ctx
,
1939 if (!W_ERROR_IS_OK(result
)) {
1943 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1944 if (!W_ERROR_IS_OK(result
)) {
1948 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
1949 this security descriptor has been created when winbindd was
1950 down. Take ownership of security descriptor. */
1951 if (dom_sid_equal(secdesc
->owner_sid
, &global_sid_World
)) {
1952 struct dom_sid owner_sid
;
1954 /* Change sd owner to workgroup administrator */
1956 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid
)) {
1957 struct spoolss_security_descriptor
*new_secdesc
;
1961 sid_append_rid(&owner_sid
, DOMAIN_RID_ADMINISTRATOR
);
1963 new_secdesc
= make_sec_desc(tmp_ctx
,
1972 if (new_secdesc
== NULL
) {
1973 result
= WERR_NOMEM
;
1977 /* Swap with other one */
1978 secdesc
= new_secdesc
;
1982 status
= dcerpc_winreg_set_sd(tmp_ctx
,
1988 if (!NT_STATUS_IS_OK(status
)) {
1989 result
= ntstatus_to_werror(status
);
1991 if (!W_ERROR_IS_OK(result
)) {
1996 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
2001 if (winreg_handle
!= NULL
) {
2004 if (is_valid_policy_hnd(&key_hnd
)) {
2005 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2007 if (is_valid_policy_hnd(&hive_hnd
)) {
2008 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2012 talloc_free(tmp_ctx
);
2016 WERROR
winreg_set_printer_secdesc(TALLOC_CTX
*mem_ctx
,
2017 struct dcerpc_binding_handle
*winreg_handle
,
2018 const char *sharename
,
2019 const struct spoolss_security_descriptor
*secdesc
)
2021 const struct spoolss_security_descriptor
*new_secdesc
= secdesc
;
2022 struct spoolss_security_descriptor
*old_secdesc
;
2023 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2024 struct policy_handle hive_hnd
, key_hnd
;
2026 TALLOC_CTX
*tmp_ctx
;
2030 tmp_ctx
= talloc_stackframe();
2031 if (tmp_ctx
== NULL
) {
2035 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
2037 talloc_free(tmp_ctx
);
2042 * The old owner and group sids of the security descriptor are not
2043 * present when new ACEs are added or removed by changing printer
2044 * permissions through NT. If they are NULL in the new security
2045 * descriptor then copy them over from the old one.
2047 if (!secdesc
->owner_sid
|| !secdesc
->group_sid
) {
2048 struct dom_sid
*owner_sid
, *group_sid
;
2049 struct security_acl
*dacl
, *sacl
;
2052 result
= winreg_get_printer_secdesc(tmp_ctx
,
2056 if (!W_ERROR_IS_OK(result
)) {
2057 talloc_free(tmp_ctx
);
2061 /* Pick out correct owner and group sids */
2062 owner_sid
= secdesc
->owner_sid
?
2063 secdesc
->owner_sid
:
2064 old_secdesc
->owner_sid
;
2066 group_sid
= secdesc
->group_sid
?
2067 secdesc
->group_sid
:
2068 old_secdesc
->group_sid
;
2070 dacl
= secdesc
->dacl
?
2074 sacl
= secdesc
->sacl
?
2078 /* Make a deep copy of the security descriptor */
2079 new_secdesc
= make_sec_desc(tmp_ctx
,
2087 if (new_secdesc
== NULL
) {
2088 talloc_free(tmp_ctx
);
2093 ZERO_STRUCT(hive_hnd
);
2094 ZERO_STRUCT(key_hnd
);
2096 result
= winreg_printer_openkey(tmp_ctx
,
2104 if (!W_ERROR_IS_OK(result
)) {
2108 status
= dcerpc_winreg_set_sd(tmp_ctx
,
2114 if (!NT_STATUS_IS_OK(status
)) {
2115 result
= ntstatus_to_werror(status
);
2119 if (winreg_handle
!= NULL
) {
2122 if (is_valid_policy_hnd(&key_hnd
)) {
2123 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2125 if (is_valid_policy_hnd(&hive_hnd
)) {
2126 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2130 talloc_free(tmp_ctx
);
2134 /* Set printer data over the winreg pipe. */
2135 WERROR
winreg_set_printer_dataex(TALLOC_CTX
*mem_ctx
,
2136 struct dcerpc_binding_handle
*winreg_handle
,
2137 const char *printer
,
2140 enum winreg_Type type
,
2144 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2145 struct policy_handle hive_hnd
, key_hnd
;
2146 struct winreg_String wvalue
= { 0, };
2148 WERROR result
= WERR_OK
;
2150 TALLOC_CTX
*tmp_ctx
;
2152 tmp_ctx
= talloc_stackframe();
2153 if (tmp_ctx
== NULL
) {
2157 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2159 TALLOC_FREE(tmp_ctx
);
2163 ZERO_STRUCT(hive_hnd
);
2164 ZERO_STRUCT(key_hnd
);
2166 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2167 key
, value
, access_mask
, printer
));
2168 result
= winreg_printer_openkey(tmp_ctx
,
2176 if (!W_ERROR_IS_OK(result
)) {
2177 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2178 key
, win_errstr(result
)));
2182 wvalue
.name
= value
;
2183 status
= dcerpc_winreg_SetValue(winreg_handle
,
2191 if (!NT_STATUS_IS_OK(status
)) {
2192 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2193 value
, nt_errstr(status
)));
2194 result
= ntstatus_to_werror(status
);
2198 if (winreg_handle
!= NULL
) {
2201 if (is_valid_policy_hnd(&key_hnd
)) {
2202 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2204 if (is_valid_policy_hnd(&hive_hnd
)) {
2205 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2209 TALLOC_FREE(tmp_ctx
);
2213 /* Get printer data over a winreg pipe. */
2214 WERROR
winreg_get_printer_dataex(TALLOC_CTX
*mem_ctx
,
2215 struct dcerpc_binding_handle
*winreg_handle
,
2216 const char *printer
,
2219 enum winreg_Type
*type
,
2221 uint32_t *data_size
)
2223 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2224 struct policy_handle hive_hnd
, key_hnd
;
2225 struct winreg_String wvalue
;
2226 enum winreg_Type type_in
= REG_NONE
;
2228 uint8_t *data_in
= NULL
;
2229 uint32_t data_in_size
= 0;
2230 uint32_t value_len
= 0;
2231 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(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2259 key
, win_errstr(result
)));
2263 wvalue
.name
= value
;
2266 * call QueryValue once with data == NULL to get the
2267 * needed memory size to be allocated, then allocate
2268 * data buffer and call again.
2270 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2279 if (!NT_STATUS_IS_OK(status
)) {
2280 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2281 value
, nt_errstr(status
)));
2282 result
= ntstatus_to_werror(status
);
2285 if (!W_ERROR_IS_OK(result
)) {
2289 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
2290 if (data_in
== NULL
) {
2291 result
= WERR_NOMEM
;
2296 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2305 if (!NT_STATUS_IS_OK(status
)) {
2306 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2307 value
, nt_errstr(status
)));
2308 result
= ntstatus_to_werror(status
);
2311 if (!W_ERROR_IS_OK(result
)) {
2316 *data_size
= data_in_size
;
2318 *data
= talloc_move(mem_ctx
, &data_in
);
2323 if (winreg_handle
!= NULL
) {
2326 if (is_valid_policy_hnd(&key_hnd
)) {
2327 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2329 if (is_valid_policy_hnd(&hive_hnd
)) {
2330 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2334 TALLOC_FREE(tmp_ctx
);
2338 /* Enumerate on the values of a given key and provide the data. */
2339 WERROR
winreg_enum_printer_dataex(TALLOC_CTX
*mem_ctx
,
2340 struct dcerpc_binding_handle
*winreg_handle
,
2341 const char *printer
,
2343 uint32_t *pnum_values
,
2344 struct spoolss_PrinterEnumValues
**penum_values
)
2346 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2347 struct policy_handle hive_hnd
, key_hnd
;
2349 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2350 uint32_t num_values
= 0;
2352 WERROR result
= WERR_OK
;
2354 TALLOC_CTX
*tmp_ctx
;
2356 tmp_ctx
= talloc_stackframe();
2357 if (tmp_ctx
== NULL
) {
2361 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2363 TALLOC_FREE(tmp_ctx
);
2367 result
= winreg_printer_openkey(tmp_ctx
,
2375 if (!W_ERROR_IS_OK(result
)) {
2376 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2377 key
, win_errstr(result
)));
2381 result
= winreg_printer_enumvalues(tmp_ctx
,
2386 if (!W_ERROR_IS_OK(result
)) {
2387 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2388 key
, win_errstr(result
)));
2392 *pnum_values
= num_values
;
2394 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
2399 if (winreg_handle
!= NULL
) {
2402 if (is_valid_policy_hnd(&key_hnd
)) {
2403 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2405 if (is_valid_policy_hnd(&hive_hnd
)) {
2406 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2410 TALLOC_FREE(tmp_ctx
);
2414 /* Delete printer data over a winreg pipe. */
2415 WERROR
winreg_delete_printer_dataex(TALLOC_CTX
*mem_ctx
,
2416 struct dcerpc_binding_handle
*winreg_handle
,
2417 const char *printer
,
2421 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2422 struct policy_handle hive_hnd
, key_hnd
;
2423 struct winreg_String wvalue
= { 0, };
2425 WERROR result
= WERR_OK
;
2428 TALLOC_CTX
*tmp_ctx
;
2430 tmp_ctx
= talloc_stackframe();
2431 if (tmp_ctx
== NULL
) {
2435 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2437 TALLOC_FREE(tmp_ctx
);
2441 ZERO_STRUCT(hive_hnd
);
2442 ZERO_STRUCT(key_hnd
);
2444 result
= winreg_printer_openkey(tmp_ctx
,
2452 if (!W_ERROR_IS_OK(result
)) {
2453 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2454 key
, win_errstr(result
)));
2458 wvalue
.name
= value
;
2459 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
2464 if (!NT_STATUS_IS_OK(status
)) {
2465 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2466 value
, nt_errstr(status
)));
2467 result
= ntstatus_to_werror(status
);
2471 if (winreg_handle
!= NULL
) {
2474 if (is_valid_policy_hnd(&key_hnd
)) {
2475 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2477 if (is_valid_policy_hnd(&hive_hnd
)) {
2478 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2482 TALLOC_FREE(tmp_ctx
);
2486 /* Enumerate on the subkeys of a given key and provide the data. */
2487 WERROR
winreg_enum_printer_key(TALLOC_CTX
*mem_ctx
,
2488 struct dcerpc_binding_handle
*winreg_handle
,
2489 const char *printer
,
2491 uint32_t *pnum_subkeys
,
2492 const char ***psubkeys
)
2494 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2495 struct policy_handle hive_hnd
, key_hnd
;
2497 const char **subkeys
= NULL
;
2498 uint32_t num_subkeys
= -1;
2500 WERROR result
= WERR_OK
;
2503 TALLOC_CTX
*tmp_ctx
;
2505 tmp_ctx
= talloc_stackframe();
2506 if (tmp_ctx
== NULL
) {
2510 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2512 TALLOC_FREE(tmp_ctx
);
2516 ZERO_STRUCT(hive_hnd
);
2517 ZERO_STRUCT(key_hnd
);
2519 result
= winreg_printer_openkey(tmp_ctx
,
2527 if (!W_ERROR_IS_OK(result
)) {
2528 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
2529 key
, win_errstr(result
)));
2533 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
2539 if (!NT_STATUS_IS_OK(status
)) {
2540 result
= ntstatus_to_werror(status
);
2542 if (!W_ERROR_IS_OK(result
)) {
2543 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
2544 key
, win_errstr(result
)));
2548 *pnum_subkeys
= num_subkeys
;
2550 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
2555 if (winreg_handle
!= NULL
) {
2558 if (is_valid_policy_hnd(&key_hnd
)) {
2559 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2561 if (is_valid_policy_hnd(&hive_hnd
)) {
2562 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2566 TALLOC_FREE(tmp_ctx
);
2570 /* Delete a key with subkeys of a given printer. */
2571 WERROR
winreg_delete_printer_key(TALLOC_CTX
*mem_ctx
,
2572 struct dcerpc_binding_handle
*winreg_handle
,
2573 const char *printer
,
2576 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2577 struct policy_handle hive_hnd
, key_hnd
;
2581 TALLOC_CTX
*tmp_ctx
;
2583 tmp_ctx
= talloc_stackframe();
2584 if (tmp_ctx
== NULL
) {
2588 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2590 TALLOC_FREE(tmp_ctx
);
2594 result
= winreg_printer_openkey(tmp_ctx
,
2602 if (!W_ERROR_IS_OK(result
)) {
2603 /* key doesn't exist */
2604 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2609 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
2610 key
, win_errstr(result
)));
2614 if (is_valid_policy_hnd(&key_hnd
)) {
2615 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
2618 if (key
== NULL
|| key
[0] == '\0') {
2621 keyname
= talloc_asprintf(tmp_ctx
,
2625 if (keyname
== NULL
) {
2626 result
= WERR_NOMEM
;
2631 result
= winreg_printer_delete_subkeys(tmp_ctx
,
2636 if (!W_ERROR_IS_OK(result
)) {
2637 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
2638 key
, win_errstr(result
)));
2643 if (winreg_handle
!= NULL
) {
2646 if (is_valid_policy_hnd(&key_hnd
)) {
2647 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2649 if (is_valid_policy_hnd(&hive_hnd
)) {
2650 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2654 TALLOC_FREE(tmp_ctx
);
2658 WERROR
winreg_printer_update_changeid(TALLOC_CTX
*mem_ctx
,
2659 struct dcerpc_binding_handle
*winreg_handle
,
2660 const char *printer
)
2662 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2663 struct policy_handle hive_hnd
, key_hnd
;
2667 TALLOC_CTX
*tmp_ctx
;
2669 tmp_ctx
= talloc_stackframe();
2670 if (tmp_ctx
== NULL
) {
2674 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2676 TALLOC_FREE(tmp_ctx
);
2680 ZERO_STRUCT(hive_hnd
);
2681 ZERO_STRUCT(key_hnd
);
2683 result
= winreg_printer_openkey(tmp_ctx
,
2691 if (!W_ERROR_IS_OK(result
)) {
2692 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
2693 path
, win_errstr(result
)));
2697 status
= dcerpc_winreg_set_dword(tmp_ctx
,
2701 winreg_printer_rev_changeid(),
2703 if (!NT_STATUS_IS_OK(status
)) {
2704 result
= ntstatus_to_werror(status
);
2706 if (!W_ERROR_IS_OK(result
)) {
2712 if (winreg_handle
!= NULL
) {
2715 if (is_valid_policy_hnd(&key_hnd
)) {
2716 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2718 if (is_valid_policy_hnd(&hive_hnd
)) {
2719 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2723 TALLOC_FREE(tmp_ctx
);
2727 WERROR
winreg_printer_get_changeid(TALLOC_CTX
*mem_ctx
,
2728 struct dcerpc_binding_handle
*winreg_handle
,
2729 const char *printer
,
2730 uint32_t *pchangeid
)
2732 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2733 struct policy_handle hive_hnd
, key_hnd
;
2734 uint32_t changeid
= 0;
2738 TALLOC_CTX
*tmp_ctx
;
2740 tmp_ctx
= talloc_stackframe();
2741 if (tmp_ctx
== NULL
) {
2745 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2747 TALLOC_FREE(tmp_ctx
);
2751 ZERO_STRUCT(hive_hnd
);
2752 ZERO_STRUCT(key_hnd
);
2754 result
= winreg_printer_openkey(tmp_ctx
,
2762 if (!W_ERROR_IS_OK(result
)) {
2763 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
2764 path
, win_errstr(result
)));
2768 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path
));
2770 status
= dcerpc_winreg_query_dword(tmp_ctx
,
2776 if (!NT_STATUS_IS_OK(status
)) {
2777 result
= ntstatus_to_werror(status
);
2779 if (!W_ERROR_IS_OK(result
)) {
2784 *pchangeid
= changeid
;
2789 if (winreg_handle
!= NULL
) {
2792 if (is_valid_policy_hnd(&key_hnd
)) {
2793 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2795 if (is_valid_policy_hnd(&hive_hnd
)) {
2796 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2800 TALLOC_FREE(tmp_ctx
);
2805 * The special behaviour of the spoolss forms is documented at the website:
2807 * Managing Win32 Printserver Forms
2808 * http://unixwiz.net/techtips/winspooler-forms.html
2811 WERROR
winreg_printer_addform1(TALLOC_CTX
*mem_ctx
,
2812 struct dcerpc_binding_handle
*winreg_handle
,
2813 struct spoolss_AddFormInfo1
*form
)
2815 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2816 struct policy_handle hive_hnd
, key_hnd
;
2817 struct winreg_String wvalue
= { 0, };
2819 uint32_t num_info
= 0;
2820 union spoolss_FormInfo
*info
= NULL
;
2824 TALLOC_CTX
*tmp_ctx
;
2826 tmp_ctx
= talloc_stackframe();
2827 if (tmp_ctx
== NULL
) {
2831 ZERO_STRUCT(hive_hnd
);
2832 ZERO_STRUCT(key_hnd
);
2834 result
= winreg_printer_openkey(tmp_ctx
,
2836 TOP_LEVEL_CONTROL_FORMS_KEY
,
2842 if (!W_ERROR_IS_OK(result
)) {
2843 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
2844 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2848 result
= winreg_printer_enumforms1(tmp_ctx
, winreg_handle
,
2850 if (!W_ERROR_IS_OK(result
)) {
2851 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
2852 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2856 /* If form name already exists or is builtin return ALREADY_EXISTS */
2857 for (i
= 0; i
< num_info
; i
++) {
2858 if (strequal(info
[i
].info1
.form_name
, form
->form_name
)) {
2859 result
= WERR_FILE_EXISTS
;
2864 wvalue
.name
= form
->form_name
;
2866 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
2867 SIVAL(blob
.data
, 0, form
->size
.width
);
2868 SIVAL(blob
.data
, 4, form
->size
.height
);
2869 SIVAL(blob
.data
, 8, form
->area
.left
);
2870 SIVAL(blob
.data
, 12, form
->area
.top
);
2871 SIVAL(blob
.data
, 16, form
->area
.right
);
2872 SIVAL(blob
.data
, 20, form
->area
.bottom
);
2873 SIVAL(blob
.data
, 24, num_info
+ 1); /* FIXME */
2874 SIVAL(blob
.data
, 28, form
->flags
);
2876 status
= dcerpc_winreg_SetValue(winreg_handle
,
2884 if (!NT_STATUS_IS_OK(status
)) {
2885 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
2886 wvalue
.name
, nt_errstr(status
)));
2887 result
= ntstatus_to_werror(status
);
2891 if (winreg_handle
!= NULL
) {
2894 if (is_valid_policy_hnd(&key_hnd
)) {
2895 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2897 if (is_valid_policy_hnd(&hive_hnd
)) {
2898 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2903 TALLOC_FREE(tmp_ctx
);
2907 WERROR
winreg_printer_enumforms1(TALLOC_CTX
*mem_ctx
,
2908 struct dcerpc_binding_handle
*winreg_handle
,
2909 uint32_t *pnum_info
,
2910 union spoolss_FormInfo
**pinfo
)
2912 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2913 struct policy_handle hive_hnd
, key_hnd
;
2914 union spoolss_FormInfo
*info
;
2915 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2916 uint32_t num_values
= 0;
2917 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
2920 TALLOC_CTX
*tmp_ctx
;
2922 tmp_ctx
= talloc_stackframe();
2923 if (tmp_ctx
== NULL
) {
2927 ZERO_STRUCT(hive_hnd
);
2928 ZERO_STRUCT(key_hnd
);
2930 result
= winreg_printer_openkey(tmp_ctx
,
2932 TOP_LEVEL_CONTROL_FORMS_KEY
,
2938 if (!W_ERROR_IS_OK(result
)) {
2939 /* key doesn't exist */
2940 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2945 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
2946 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2950 result
= winreg_printer_enumvalues(tmp_ctx
,
2955 if (!W_ERROR_IS_OK(result
)) {
2956 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
2957 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
2961 info
= talloc_array(tmp_ctx
, union spoolss_FormInfo
, num_builtin
+ num_values
);
2963 result
= WERR_NOMEM
;
2967 /* Enumerate BUILTIN forms */
2968 for (i
= 0; i
< num_builtin
; i
++) {
2969 info
[i
].info1
= builtin_forms1
[i
];
2972 /* Enumerate registry forms */
2973 for (i
= 0; i
< num_values
; i
++) {
2974 union spoolss_FormInfo val
;
2976 if (enum_values
[i
].type
!= REG_BINARY
||
2977 enum_values
[i
].data_length
!= 32) {
2981 val
.info1
.form_name
= talloc_strdup(info
, enum_values
[i
].value_name
);
2982 if (val
.info1
.form_name
== NULL
) {
2983 result
= WERR_NOMEM
;
2987 val
.info1
.size
.width
= IVAL(enum_values
[i
].data
->data
, 0);
2988 val
.info1
.size
.height
= IVAL(enum_values
[i
].data
->data
, 4);
2989 val
.info1
.area
.left
= IVAL(enum_values
[i
].data
->data
, 8);
2990 val
.info1
.area
.top
= IVAL(enum_values
[i
].data
->data
, 12);
2991 val
.info1
.area
.right
= IVAL(enum_values
[i
].data
->data
, 16);
2992 val
.info1
.area
.bottom
= IVAL(enum_values
[i
].data
->data
, 20);
2993 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
2994 val
.info1
.flags
= (enum spoolss_FormFlags
) IVAL(enum_values
[i
].data
->data
, 28);
2996 info
[i
+ num_builtin
] = val
;
2999 *pnum_info
= num_builtin
+ num_values
;
3001 *pinfo
= talloc_move(mem_ctx
, &info
);
3005 if (winreg_handle
!= NULL
) {
3008 if (is_valid_policy_hnd(&key_hnd
)) {
3009 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3011 if (is_valid_policy_hnd(&hive_hnd
)) {
3012 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3016 TALLOC_FREE(enum_values
);
3017 TALLOC_FREE(tmp_ctx
);
3021 WERROR
winreg_printer_deleteform1(TALLOC_CTX
*mem_ctx
,
3022 struct dcerpc_binding_handle
*winreg_handle
,
3023 const char *form_name
)
3025 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3026 struct policy_handle hive_hnd
, key_hnd
;
3027 struct winreg_String wvalue
= { 0, };
3028 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3030 WERROR result
= WERR_OK
;
3032 TALLOC_CTX
*tmp_ctx
;
3034 for (i
= 0; i
< num_builtin
; i
++) {
3035 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3036 return WERR_INVALID_PARAMETER
;
3040 tmp_ctx
= talloc_stackframe();
3041 if (tmp_ctx
== NULL
) {
3045 ZERO_STRUCT(hive_hnd
);
3046 ZERO_STRUCT(key_hnd
);
3048 result
= winreg_printer_openkey(tmp_ctx
,
3050 TOP_LEVEL_CONTROL_FORMS_KEY
,
3056 if (!W_ERROR_IS_OK(result
)) {
3057 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3058 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3059 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3060 result
= WERR_INVALID_FORM_NAME
;
3065 wvalue
.name
= form_name
;
3066 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
3071 if (!NT_STATUS_IS_OK(status
)) {
3072 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3073 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3074 wvalue
.name
, nt_errstr(status
)));
3075 result
= ntstatus_to_werror(status
);
3079 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3080 result
= WERR_INVALID_FORM_NAME
;
3084 if (winreg_handle
!= NULL
) {
3087 if (is_valid_policy_hnd(&key_hnd
)) {
3088 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3090 if (is_valid_policy_hnd(&hive_hnd
)) {
3091 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3095 TALLOC_FREE(tmp_ctx
);
3099 WERROR
winreg_printer_setform1(TALLOC_CTX
*mem_ctx
,
3100 struct dcerpc_binding_handle
*winreg_handle
,
3101 const char *form_name
,
3102 struct spoolss_AddFormInfo1
*form
)
3104 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3105 struct policy_handle hive_hnd
, key_hnd
;
3106 struct winreg_String wvalue
= { 0, };
3108 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3112 TALLOC_CTX
*tmp_ctx
= NULL
;
3114 for (i
= 0; i
< num_builtin
; i
++) {
3115 if (strequal(builtin_forms1
[i
].form_name
, form
->form_name
)) {
3116 result
= WERR_INVALID_PARAM
;
3121 tmp_ctx
= talloc_stackframe();
3122 if (tmp_ctx
== NULL
) {
3126 ZERO_STRUCT(hive_hnd
);
3127 ZERO_STRUCT(key_hnd
);
3129 result
= winreg_printer_openkey(tmp_ctx
,
3131 TOP_LEVEL_CONTROL_FORMS_KEY
,
3137 if (!W_ERROR_IS_OK(result
)) {
3138 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3139 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3143 /* If form_name != form->form_name then we renamed the form */
3144 if (strequal(form_name
, form
->form_name
)) {
3145 result
= winreg_printer_deleteform1(tmp_ctx
, winreg_handle
,
3147 if (!W_ERROR_IS_OK(result
)) {
3148 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3149 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3154 wvalue
.name
= form
->form_name
;
3156 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
3157 SIVAL(blob
.data
, 0, form
->size
.width
);
3158 SIVAL(blob
.data
, 4, form
->size
.height
);
3159 SIVAL(blob
.data
, 8, form
->area
.left
);
3160 SIVAL(blob
.data
, 12, form
->area
.top
);
3161 SIVAL(blob
.data
, 16, form
->area
.right
);
3162 SIVAL(blob
.data
, 20, form
->area
.bottom
);
3163 SIVAL(blob
.data
, 24, 42);
3164 SIVAL(blob
.data
, 28, form
->flags
);
3166 status
= dcerpc_winreg_SetValue(winreg_handle
,
3174 if (!NT_STATUS_IS_OK(status
)) {
3175 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3176 wvalue
.name
, nt_errstr(status
)));
3177 result
= ntstatus_to_werror(status
);
3181 if (winreg_handle
!= NULL
) {
3184 if (is_valid_policy_hnd(&key_hnd
)) {
3185 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3187 if (is_valid_policy_hnd(&hive_hnd
)) {
3188 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3192 TALLOC_FREE(tmp_ctx
);
3196 WERROR
winreg_printer_getform1(TALLOC_CTX
*mem_ctx
,
3197 struct dcerpc_binding_handle
*winreg_handle
,
3198 const char *form_name
,
3199 struct spoolss_FormInfo1
*r
)
3201 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3202 struct policy_handle hive_hnd
, key_hnd
;
3203 struct winreg_String wvalue
;
3204 enum winreg_Type type_in
= REG_NONE
;
3205 uint8_t *data_in
= NULL
;
3206 uint32_t data_in_size
= 0;
3207 uint32_t value_len
= 0;
3208 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3212 TALLOC_CTX
*tmp_ctx
;
3214 /* check builtin forms first */
3215 for (i
= 0; i
< num_builtin
; i
++) {
3216 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3217 *r
= builtin_forms1
[i
];
3222 tmp_ctx
= talloc_stackframe();
3223 if (tmp_ctx
== NULL
) {
3227 ZERO_STRUCT(hive_hnd
);
3228 ZERO_STRUCT(key_hnd
);
3230 result
= winreg_printer_openkey(tmp_ctx
,
3232 TOP_LEVEL_CONTROL_FORMS_KEY
,
3238 if (!W_ERROR_IS_OK(result
)) {
3239 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3240 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3244 wvalue
.name
= form_name
;
3247 * call QueryValue once with data == NULL to get the
3248 * needed memory size to be allocated, then allocate
3249 * data buffer and call again.
3251 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3260 if (!NT_STATUS_IS_OK(status
)) {
3261 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3262 wvalue
.name
, nt_errstr(status
)));
3263 result
= ntstatus_to_werror(status
);
3266 if (!W_ERROR_IS_OK(result
)) {
3270 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
3271 if (data_in
== NULL
) {
3272 result
= WERR_NOMEM
;
3277 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3286 if (!NT_STATUS_IS_OK(status
)) {
3287 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3288 wvalue
.name
, nt_errstr(status
)));
3289 result
= ntstatus_to_werror(status
);
3292 if (!W_ERROR_IS_OK(result
)) {
3296 r
->form_name
= talloc_strdup(mem_ctx
, form_name
);
3297 if (r
->form_name
== NULL
) {
3298 result
= WERR_NOMEM
;
3302 r
->size
.width
= IVAL(data_in
, 0);
3303 r
->size
.height
= IVAL(data_in
, 4);
3304 r
->area
.left
= IVAL(data_in
, 8);
3305 r
->area
.top
= IVAL(data_in
, 12);
3306 r
->area
.right
= IVAL(data_in
, 16);
3307 r
->area
.bottom
= IVAL(data_in
, 20);
3308 /* skip index IVAL(data_in, 24)));*/
3309 r
->flags
= (enum spoolss_FormFlags
) IVAL(data_in
, 28);
3313 if (winreg_handle
!= NULL
) {
3316 if (is_valid_policy_hnd(&key_hnd
)) {
3317 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3319 if (is_valid_policy_hnd(&hive_hnd
)) {
3320 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3324 TALLOC_FREE(tmp_ctx
);
3328 WERROR
winreg_add_driver(TALLOC_CTX
*mem_ctx
,
3329 struct dcerpc_binding_handle
*winreg_handle
,
3330 struct spoolss_AddDriverInfoCtr
*r
,
3331 const char **driver_name
,
3332 uint32_t *driver_version
)
3334 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3335 struct policy_handle hive_hnd
, key_hnd
;
3336 struct spoolss_DriverInfo8 info8
;
3337 TALLOC_CTX
*tmp_ctx
= NULL
;
3341 ZERO_STRUCT(hive_hnd
);
3342 ZERO_STRUCT(key_hnd
);
3345 if (!driver_info_ctr_to_info8(r
, &info8
)) {
3346 result
= WERR_INVALID_PARAMETER
;
3350 tmp_ctx
= talloc_stackframe();
3351 if (tmp_ctx
== NULL
) {
3355 result
= winreg_printer_opendriver(tmp_ctx
,
3363 if (!W_ERROR_IS_OK(result
)) {
3364 DEBUG(0, ("winreg_add_driver: "
3365 "Could not open driver key (%s,%s,%d): %s\n",
3366 info8
.driver_name
, info8
.architecture
,
3367 info8
.version
, win_errstr(result
)));
3371 /* TODO: "Attributes" ? */
3373 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3379 if (!NT_STATUS_IS_OK(status
)) {
3380 result
= ntstatus_to_werror(status
);
3382 if (!W_ERROR_IS_OK(result
)) {
3386 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3392 if (!NT_STATUS_IS_OK(status
)) {
3393 result
= ntstatus_to_werror(status
);
3395 if (!W_ERROR_IS_OK(result
)) {
3399 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3405 if (!NT_STATUS_IS_OK(status
)) {
3406 result
= ntstatus_to_werror(status
);
3408 if (!W_ERROR_IS_OK(result
)) {
3412 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3415 "Configuration File",
3418 if (!NT_STATUS_IS_OK(status
)) {
3419 result
= ntstatus_to_werror(status
);
3421 if (!W_ERROR_IS_OK(result
)) {
3425 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3431 if (!NT_STATUS_IS_OK(status
)) {
3432 result
= ntstatus_to_werror(status
);
3434 if (!W_ERROR_IS_OK(result
)) {
3438 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3442 info8
.dependent_files
,
3444 if (!NT_STATUS_IS_OK(status
)) {
3445 result
= ntstatus_to_werror(status
);
3447 if (!W_ERROR_IS_OK(result
)) {
3451 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3457 if (!NT_STATUS_IS_OK(status
)) {
3458 result
= ntstatus_to_werror(status
);
3460 if (!W_ERROR_IS_OK(result
)) {
3464 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3468 info8
.default_datatype
,
3470 if (!NT_STATUS_IS_OK(status
)) {
3471 result
= ntstatus_to_werror(status
);
3473 if (!W_ERROR_IS_OK(result
)) {
3477 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3479 &key_hnd
, "Previous Names",
3480 info8
.previous_names
,
3482 if (!NT_STATUS_IS_OK(status
)) {
3483 result
= ntstatus_to_werror(status
);
3485 if (!W_ERROR_IS_OK(result
)) {
3489 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3490 &key_hnd
, "DriverDate",
3492 if (!W_ERROR_IS_OK(result
)) {
3496 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
,
3497 &key_hnd
, "DriverVersion",
3498 info8
.driver_version
);
3499 if (!W_ERROR_IS_OK(result
)) {
3503 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3507 info8
.manufacturer_name
,
3509 if (!NT_STATUS_IS_OK(status
)) {
3510 result
= ntstatus_to_werror(status
);
3512 if (!W_ERROR_IS_OK(result
)) {
3516 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3520 info8
.manufacturer_url
,
3522 if (!NT_STATUS_IS_OK(status
)) {
3523 result
= ntstatus_to_werror(status
);
3525 if (!W_ERROR_IS_OK(result
)) {
3529 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3535 if (!NT_STATUS_IS_OK(status
)) {
3536 result
= ntstatus_to_werror(status
);
3538 if (!W_ERROR_IS_OK(result
)) {
3542 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3548 if (!NT_STATUS_IS_OK(status
)) {
3549 result
= ntstatus_to_werror(status
);
3551 if (!W_ERROR_IS_OK(result
)) {
3555 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3559 info8
.print_processor
,
3561 if (!NT_STATUS_IS_OK(status
)) {
3562 result
= ntstatus_to_werror(status
);
3564 if (!W_ERROR_IS_OK(result
)) {
3568 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3574 if (!NT_STATUS_IS_OK(status
)) {
3575 result
= ntstatus_to_werror(status
);
3577 if (!W_ERROR_IS_OK(result
)) {
3581 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3585 info8
.color_profiles
,
3587 if (!NT_STATUS_IS_OK(status
)) {
3588 result
= ntstatus_to_werror(status
);
3590 if (!W_ERROR_IS_OK(result
)) {
3594 status
= dcerpc_winreg_set_sz(tmp_ctx
,
3600 if (!NT_STATUS_IS_OK(status
)) {
3601 result
= ntstatus_to_werror(status
);
3603 if (!W_ERROR_IS_OK(result
)) {
3607 status
= dcerpc_winreg_set_dword(tmp_ctx
,
3610 "PrinterDriverAttributes",
3611 info8
.printer_driver_attributes
,
3613 if (!NT_STATUS_IS_OK(status
)) {
3614 result
= ntstatus_to_werror(status
);
3616 if (!W_ERROR_IS_OK(result
)) {
3620 status
= dcerpc_winreg_set_multi_sz(tmp_ctx
,
3624 info8
.core_driver_dependencies
,
3626 if (!NT_STATUS_IS_OK(status
)) {
3627 result
= ntstatus_to_werror(status
);
3629 if (!W_ERROR_IS_OK(result
)) {
3633 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3634 &key_hnd
, "MinInboxDriverVerDate",
3635 info8
.min_inbox_driver_ver_date
);
3636 if (!W_ERROR_IS_OK(result
)) {
3640 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
, &key_hnd
,
3641 "MinInboxDriverVerVersion",
3642 info8
.min_inbox_driver_ver_version
);
3643 if (!W_ERROR_IS_OK(result
)) {
3647 *driver_name
= info8
.driver_name
;
3648 *driver_version
= info8
.version
;
3651 if (winreg_handle
!= NULL
) {
3654 if (is_valid_policy_hnd(&key_hnd
)) {
3655 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3657 if (is_valid_policy_hnd(&hive_hnd
)) {
3658 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3662 TALLOC_FREE(tmp_ctx
);
3666 WERROR
winreg_get_driver(TALLOC_CTX
*mem_ctx
,
3667 struct dcerpc_binding_handle
*winreg_handle
,
3668 const char *architecture
,
3669 const char *driver_name
,
3670 uint32_t driver_version
,
3671 struct spoolss_DriverInfo8
**_info8
)
3673 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3674 struct policy_handle hive_hnd
, key_hnd
;
3675 struct spoolss_DriverInfo8 i8
, *info8
;
3676 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
3677 struct spoolss_PrinterEnumValues
*v
;
3678 uint32_t num_values
= 0;
3679 TALLOC_CTX
*tmp_ctx
;
3683 ZERO_STRUCT(hive_hnd
);
3684 ZERO_STRUCT(key_hnd
);
3687 tmp_ctx
= talloc_stackframe();
3688 if (tmp_ctx
== NULL
) {
3692 if (driver_version
== DRIVER_ANY_VERSION
) {
3693 /* look for Win2k first and then for NT4 */
3694 result
= winreg_printer_opendriver(tmp_ctx
,
3702 if (!W_ERROR_IS_OK(result
)) {
3703 result
= winreg_printer_opendriver(tmp_ctx
,
3713 /* ok normal case */
3714 result
= winreg_printer_opendriver(tmp_ctx
,
3723 if (!W_ERROR_IS_OK(result
)) {
3724 DEBUG(5, ("winreg_get_driver: "
3725 "Could not open driver key (%s,%s,%d): %s\n",
3726 driver_name
, architecture
,
3727 driver_version
, win_errstr(result
)));
3731 result
= winreg_printer_enumvalues(tmp_ctx
,
3736 if (!W_ERROR_IS_OK(result
)) {
3737 DEBUG(0, ("winreg_get_driver: "
3738 "Could not enumerate values for (%s,%s,%d): %s\n",
3739 driver_name
, architecture
,
3740 driver_version
, win_errstr(result
)));
3744 info8
= talloc_zero(tmp_ctx
, struct spoolss_DriverInfo8
);
3745 if (info8
== NULL
) {
3746 result
= WERR_NOMEM
;
3750 info8
->driver_name
= talloc_strdup(info8
, driver_name
);
3751 if (info8
->driver_name
== NULL
) {
3752 result
= WERR_NOMEM
;
3756 info8
->architecture
= talloc_strdup(info8
, architecture
);
3757 if (info8
->architecture
== NULL
) {
3758 result
= WERR_NOMEM
;
3764 for (i
= 0; i
< num_values
; i
++) {
3765 const char *tmp_str
;
3768 v
= &enum_values
[i
];
3770 result
= winreg_enumval_to_dword(info8
, v
,
3773 if (NT_STATUS_IS_OK(result
)) {
3774 info8
->version
= (enum spoolss_DriverOSVersion
) tmp
;
3776 CHECK_ERROR(result
);
3778 result
= winreg_enumval_to_sz(info8
, v
,
3780 &info8
->driver_path
);
3781 CHECK_ERROR(result
);
3783 result
= winreg_enumval_to_sz(info8
, v
,
3786 CHECK_ERROR(result
);
3788 result
= winreg_enumval_to_sz(info8
, v
,
3789 "Configuration File",
3790 &info8
->config_file
);
3791 CHECK_ERROR(result
);
3793 result
= winreg_enumval_to_sz(info8
, v
,
3796 CHECK_ERROR(result
);
3798 result
= winreg_enumval_to_multi_sz(info8
, v
,
3800 &info8
->dependent_files
);
3801 CHECK_ERROR(result
);
3803 result
= winreg_enumval_to_sz(info8
, v
,
3805 &info8
->monitor_name
);
3806 CHECK_ERROR(result
);
3808 result
= winreg_enumval_to_sz(info8
, v
,
3810 &info8
->default_datatype
);
3811 CHECK_ERROR(result
);
3813 result
= winreg_enumval_to_multi_sz(info8
, v
,
3815 &info8
->previous_names
);
3816 CHECK_ERROR(result
);
3818 result
= winreg_enumval_to_sz(info8
, v
,
3821 if (W_ERROR_IS_OK(result
)) {
3822 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3823 &info8
->driver_date
);
3825 CHECK_ERROR(result
);
3827 result
= winreg_enumval_to_sz(info8
, v
,
3830 if (W_ERROR_IS_OK(result
)) {
3831 result
= winreg_printer_ver_to_dword(tmp_str
,
3832 &info8
->driver_version
);
3834 CHECK_ERROR(result
);
3836 result
= winreg_enumval_to_sz(info8
, v
,
3838 &info8
->manufacturer_name
);
3839 CHECK_ERROR(result
);
3841 result
= winreg_enumval_to_sz(info8
, v
,
3843 &info8
->manufacturer_url
);
3844 CHECK_ERROR(result
);
3846 result
= winreg_enumval_to_sz(info8
, v
,
3848 &info8
->hardware_id
);
3849 CHECK_ERROR(result
);
3851 result
= winreg_enumval_to_sz(info8
, v
,
3854 CHECK_ERROR(result
);
3856 result
= winreg_enumval_to_sz(info8
, v
,
3858 &info8
->print_processor
);
3859 CHECK_ERROR(result
);
3861 result
= winreg_enumval_to_sz(info8
, v
,
3863 &info8
->vendor_setup
);
3864 CHECK_ERROR(result
);
3866 result
= winreg_enumval_to_multi_sz(info8
, v
,
3868 &info8
->color_profiles
);
3869 CHECK_ERROR(result
);
3871 result
= winreg_enumval_to_sz(info8
, v
,
3874 CHECK_ERROR(result
);
3876 result
= winreg_enumval_to_dword(info8
, v
,
3877 "PrinterDriverAttributes",
3878 &info8
->printer_driver_attributes
);
3879 CHECK_ERROR(result
);
3881 result
= winreg_enumval_to_multi_sz(info8
, v
,
3883 &info8
->core_driver_dependencies
);
3884 CHECK_ERROR(result
);
3886 result
= winreg_enumval_to_sz(info8
, v
,
3887 "MinInboxDriverVerDate",
3889 if (W_ERROR_IS_OK(result
)) {
3890 result
= winreg_printer_date_to_NTTIME(tmp_str
,
3891 &info8
->min_inbox_driver_ver_date
);
3893 CHECK_ERROR(result
);
3895 result
= winreg_enumval_to_sz(info8
, v
,
3896 "MinInboxDriverVerVersion",
3898 if (W_ERROR_IS_OK(result
)) {
3899 result
= winreg_printer_ver_to_dword(tmp_str
,
3900 &info8
->min_inbox_driver_ver_version
);
3902 CHECK_ERROR(result
);
3905 if (!W_ERROR_IS_OK(result
)) {
3906 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
3907 "for %s: %s\n", v
->value_name
,
3908 win_errstr(result
)));
3912 *_info8
= talloc_steal(mem_ctx
, info8
);
3915 if (winreg_handle
!= NULL
) {
3918 if (is_valid_policy_hnd(&key_hnd
)) {
3919 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3921 if (is_valid_policy_hnd(&hive_hnd
)) {
3922 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3926 TALLOC_FREE(tmp_ctx
);
3930 WERROR
winreg_del_driver(TALLOC_CTX
*mem_ctx
,
3931 struct dcerpc_binding_handle
*winreg_handle
,
3932 struct spoolss_DriverInfo8
*info8
,
3935 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3936 struct policy_handle hive_hnd
, key_hnd
;
3937 TALLOC_CTX
*tmp_ctx
;
3941 ZERO_STRUCT(hive_hnd
);
3942 ZERO_STRUCT(key_hnd
);
3944 tmp_ctx
= talloc_stackframe();
3945 if (tmp_ctx
== NULL
) {
3949 /* test that the key exists */
3950 result
= winreg_printer_opendriver(tmp_ctx
,
3953 info8
->architecture
,
3958 if (!W_ERROR_IS_OK(result
)) {
3959 /* key doesn't exist */
3960 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3965 DEBUG(5, ("winreg_del_driver: "
3966 "Could not open driver (%s,%s,%u): %s\n",
3967 info8
->driver_name
, info8
->architecture
,
3968 version
, win_errstr(result
)));
3973 if (is_valid_policy_hnd(&key_hnd
)) {
3974 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
3977 key_name
= talloc_asprintf(tmp_ctx
,
3978 "%s\\Environments\\%s\\Drivers\\Version-%u\\%s",
3979 TOP_LEVEL_CONTROL_KEY
,
3980 info8
->architecture
, version
,
3981 info8
->driver_name
);
3982 if (key_name
== NULL
) {
3983 result
= WERR_NOMEM
;
3987 result
= winreg_printer_delete_subkeys(tmp_ctx
,
3992 if (!W_ERROR_IS_OK(result
)) {
3993 DEBUG(0, ("winreg_del_driver: "
3994 "Could not open driver (%s,%s,%u): %s\n",
3995 info8
->driver_name
, info8
->architecture
,
3996 version
, win_errstr(result
)));
4002 if (winreg_handle
!= NULL
) {
4005 if (is_valid_policy_hnd(&key_hnd
)) {
4006 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4008 if (is_valid_policy_hnd(&hive_hnd
)) {
4009 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4013 TALLOC_FREE(tmp_ctx
);
4017 WERROR
winreg_get_driver_list(TALLOC_CTX
*mem_ctx
,
4018 struct dcerpc_binding_handle
*winreg_handle
,
4019 const char *architecture
,
4021 uint32_t *num_drivers
,
4022 const char ***drivers_p
)
4024 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4025 struct policy_handle hive_hnd
, key_hnd
;
4026 const char **drivers
;
4027 TALLOC_CTX
*tmp_ctx
;
4034 ZERO_STRUCT(hive_hnd
);
4035 ZERO_STRUCT(key_hnd
);
4037 tmp_ctx
= talloc_stackframe();
4038 if (tmp_ctx
== NULL
) {
4042 /* use NULL for the driver name so we open the key that is
4043 * parent of all drivers for this architecture and version */
4044 result
= winreg_printer_opendriver(tmp_ctx
,
4052 if (!W_ERROR_IS_OK(result
)) {
4053 DEBUG(5, ("winreg_get_driver_list: "
4054 "Could not open key (%s,%u): %s\n",
4055 architecture
, version
, win_errstr(result
)));
4060 status
= dcerpc_winreg_enum_keys(tmp_ctx
,
4066 if (!NT_STATUS_IS_OK(status
)) {
4067 result
= ntstatus_to_werror(status
);
4069 if (!W_ERROR_IS_OK(result
)) {
4070 DEBUG(0, ("winreg_get_driver_list: "
4071 "Could not enumerate drivers for (%s,%u): %s\n",
4072 architecture
, version
, win_errstr(result
)));
4076 *drivers_p
= talloc_steal(mem_ctx
, drivers
);
4080 if (winreg_handle
!= NULL
) {
4083 if (is_valid_policy_hnd(&key_hnd
)) {
4084 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4086 if (is_valid_policy_hnd(&hive_hnd
)) {
4087 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4091 TALLOC_FREE(tmp_ctx
);