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 "srv_spoolss_util.h"
25 #include "../librpc/gen_ndr/ndr_spoolss.h"
26 #include "../librpc/gen_ndr/srv_winreg.h"
27 #include "../librpc/gen_ndr/cli_winreg.h"
28 #include "../librpc/gen_ndr/ndr_security.h"
30 #include "rpc_server/rpc_ncacn_np.h"
31 #include "../libcli/security/dom_sid.h"
33 #define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
34 #define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
35 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
36 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
38 #define EMPTY_STRING ""
40 #define FILL_STRING(mem_ctx, in, out) \
42 if (in && strlen(in)) { \
43 out = talloc_strdup(mem_ctx, in); \
45 out = talloc_strdup(mem_ctx, ""); \
47 W_ERROR_HAVE_NO_MEMORY(out); \
50 #define CHECK_ERROR(result) \
51 if (W_ERROR_IS_OK(result)) continue; \
52 if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
53 if (!W_ERROR_IS_OK(result)) break
55 /* FLAGS, NAME, with, height, left, top, right, bottom */
56 static const struct spoolss_FormInfo1 builtin_forms1
[] = {
57 { SPOOLSS_FORM_BUILTIN
, "10x11", {0x3e030,0x44368}, {0x0,0x0,0x3e030,0x44368} },
58 { SPOOLSS_FORM_BUILTIN
, "10x14", {0x3e030,0x56d10}, {0x0,0x0,0x3e030,0x56d10} },
59 { SPOOLSS_FORM_BUILTIN
, "11x17", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
60 { SPOOLSS_FORM_BUILTIN
, "12x11", {0x4a724,0x443e1}, {0x0,0x0,0x4a724,0x443e1} },
61 { SPOOLSS_FORM_BUILTIN
, "15x11", {0x5d048,0x44368}, {0x0,0x0,0x5d048,0x44368} },
62 { SPOOLSS_FORM_BUILTIN
, "6 3/4 Envelope", {0x167ab,0x284ec}, {0x0,0x0,0x167ab,0x284ec} },
63 { SPOOLSS_FORM_BUILTIN
, "9x11", {0x37cf8,0x44368}, {0x0,0x0,0x37cf8,0x44368} },
64 { SPOOLSS_FORM_BUILTIN
, "A0", {0xcd528,0x122488},{0x0,0x0,0xcd528,0x122488} },
65 { SPOOLSS_FORM_BUILTIN
, "A1", {0x91050,0xcd528}, {0x0,0x0,0x91050,0xcd528} },
66 { SPOOLSS_FORM_BUILTIN
, "A2", {0x668a0,0x91050}, {0x0,0x0,0x668a0,0x91050} },
67 { SPOOLSS_FORM_BUILTIN
, "A3 Extra Transverse", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
68 { SPOOLSS_FORM_BUILTIN
, "A3 Extra", {0x4e9d0,0x6ca48}, {0x0,0x0,0x4e9d0,0x6ca48} },
69 { SPOOLSS_FORM_BUILTIN
, "A3 Rotated", {0x668a0,0x48828}, {0x0,0x0,0x668a0,0x48828} },
70 { SPOOLSS_FORM_BUILTIN
, "A3 Transverse", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
71 { SPOOLSS_FORM_BUILTIN
, "A3", {0x48828,0x668a0}, {0x0,0x0,0x48828,0x668a0} },
72 { SPOOLSS_FORM_BUILTIN
, "A4 Extra", {0x397c2,0x4eb16}, {0x0,0x0,0x397c2,0x4eb16} },
73 { SPOOLSS_FORM_BUILTIN
, "A4 Plus", {0x33450,0x50910}, {0x0,0x0,0x33450,0x50910} },
74 { SPOOLSS_FORM_BUILTIN
, "A4 Rotated", {0x48828,0x33450}, {0x0,0x0,0x48828,0x33450} },
75 { SPOOLSS_FORM_BUILTIN
, "A4 Small", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
76 { SPOOLSS_FORM_BUILTIN
, "A4 Transverse", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
77 { SPOOLSS_FORM_BUILTIN
, "A4", {0x33450,0x48828}, {0x0,0x0,0x33450,0x48828} },
78 { SPOOLSS_FORM_BUILTIN
, "A5 Extra", {0x2a7b0,0x395f8}, {0x0,0x0,0x2a7b0,0x395f8} },
79 { SPOOLSS_FORM_BUILTIN
, "A5 Rotated", {0x33450,0x24220}, {0x0,0x0,0x33450,0x24220} },
80 { SPOOLSS_FORM_BUILTIN
, "A5 Transverse", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
81 { SPOOLSS_FORM_BUILTIN
, "A5", {0x24220,0x33450}, {0x0,0x0,0x24220,0x33450} },
82 { SPOOLSS_FORM_BUILTIN
, "A6 Rotated", {0x24220,0x19a28}, {0x0,0x0,0x24220,0x19a28} },
83 { SPOOLSS_FORM_BUILTIN
, "A6", {0x19a28,0x24220}, {0x0,0x0,0x19a28,0x24220} },
84 { SPOOLSS_FORM_BUILTIN
, "B4 (ISO)", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
85 { SPOOLSS_FORM_BUILTIN
, "B4 (JIS) Rotated", {0x58de0,0x3ebe8}, {0x0,0x0,0x58de0,0x3ebe8} },
86 { SPOOLSS_FORM_BUILTIN
, "B4 (JIS)", {0x3ebe8,0x58de0}, {0x0,0x0,0x3ebe8,0x58de0} },
87 { SPOOLSS_FORM_BUILTIN
, "B5 (ISO) Extra", {0x31128,0x43620}, {0x0,0x0,0x31128,0x43620} },
88 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS) Rotated", {0x3ebe8,0x2c6f0}, {0x0,0x0,0x3ebe8,0x2c6f0} },
89 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS) Transverse", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
90 { SPOOLSS_FORM_BUILTIN
, "B5 (JIS)", {0x2c6f0,0x3ebe8}, {0x0,0x0,0x2c6f0,0x3ebe8} },
91 { SPOOLSS_FORM_BUILTIN
, "B6 (JIS) Rotated", {0x2c6f0,0x1f400}, {0x0,0x0,0x2c6f0,0x1f400} },
92 { SPOOLSS_FORM_BUILTIN
, "B6 (JIS)", {0x1f400,0x2c6f0}, {0x0,0x0,0x1f400,0x2c6f0} },
93 { SPOOLSS_FORM_BUILTIN
, "C size sheet", {0x696b8,0x886d0}, {0x0,0x0,0x696b8,0x886d0} },
94 { SPOOLSS_FORM_BUILTIN
, "D size sheet", {0x886d0,0xd2d70}, {0x0,0x0,0x886d0,0xd2d70} },
95 { SPOOLSS_FORM_BUILTIN
, "Double Japan Postcard Rotated", {0x24220,0x30d40}, {0x0,0x0,0x24220,0x30d40} },
96 { SPOOLSS_FORM_BUILTIN
, "E size sheet", {0xd2d70,0x110da0},{0x0,0x0,0xd2d70,0x110da0} },
97 { SPOOLSS_FORM_BUILTIN
, "Envelope #10", {0x19947,0x3ae94}, {0x0,0x0,0x19947,0x3ae94} },
98 { SPOOLSS_FORM_BUILTIN
, "Envelope #11", {0x1be7c,0x40565}, {0x0,0x0,0x1be7c,0x40565} },
99 { SPOOLSS_FORM_BUILTIN
, "Envelope #12", {0x1d74a,0x44368}, {0x0,0x0,0x1d74a,0x44368} },
100 { SPOOLSS_FORM_BUILTIN
, "Envelope #14", {0x1f018,0x47504}, {0x0,0x0,0x1f018,0x47504} },
101 { SPOOLSS_FORM_BUILTIN
, "Envelope #9", {0x18079,0x37091}, {0x0,0x0,0x18079,0x37091} },
102 { SPOOLSS_FORM_BUILTIN
, "Envelope B4", {0x3d090,0x562e8}, {0x0,0x0,0x3d090,0x562e8} },
103 { SPOOLSS_FORM_BUILTIN
, "Envelope B5", {0x2af80,0x3d090}, {0x0,0x0,0x2af80,0x3d090} },
104 { SPOOLSS_FORM_BUILTIN
, "Envelope B6", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
105 { SPOOLSS_FORM_BUILTIN
, "Envelope C3", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
106 { SPOOLSS_FORM_BUILTIN
, "Envelope C4", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
107 { SPOOLSS_FORM_BUILTIN
, "Envelope C5", {0x278d0,0x37e88}, {0x0,0x0,0x278d0,0x37e88} },
108 { SPOOLSS_FORM_BUILTIN
, "Envelope C6", {0x1bd50,0x278d0}, {0x0,0x0,0x1bd50,0x278d0} },
109 { SPOOLSS_FORM_BUILTIN
, "Envelope C65", {0x1bd50,0x37e88}, {0x0,0x0,0x1bd50,0x37e88} },
110 { SPOOLSS_FORM_BUILTIN
, "Envelope DL", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
111 { SPOOLSS_FORM_BUILTIN
, "Envelope Invite", {0x35b60,0x35b60}, {0x0,0x0,0x35b60,0x35b60} },
112 { SPOOLSS_FORM_BUILTIN
, "Envelope Monarch", {0x18079,0x2e824}, {0x0,0x0,0x18079,0x2e824} },
113 { SPOOLSS_FORM_BUILTIN
, "Envelope", {0x1adb0,0x38270}, {0x0,0x0,0x1adb0,0x38270} },
114 { SPOOLSS_FORM_BUILTIN
, "Executive", {0x2cf56,0x411cc}, {0x0,0x0,0x2cf56,0x411cc} },
115 { SPOOLSS_FORM_BUILTIN
, "Folio", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
116 { SPOOLSS_FORM_BUILTIN
, "German Legal Fanfold", {0x34b5c,0x509d8}, {0x0,0x0,0x34b5c,0x509d8} },
117 { SPOOLSS_FORM_BUILTIN
, "German Std Fanfold", {0x34b5c,0x4a6a0}, {0x0,0x0,0x34b5c,0x4a6a0} },
118 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Chou #3 Rotated", {0x395f8,0x1d4c0}, {0x0,0x0,0x395f8,0x1d4c0} },
119 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Chou #4 Rotated", {0x320c8,0x15f90}, {0x0,0x0,0x320c8,0x15f90} },
120 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Kaku #2 Rotated", {0x510e0,0x3a980}, {0x0,0x0,0x510e0,0x3a980} },
121 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope Kaku #3 Rotated", {0x43a08,0x34bc0}, {0x0,0x0,0x43a08,0x34bc0} },
122 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope You #4 Rotated", {0x395f8,0x19a28}, {0x0,0x0,0x395f8,0x19a28} },
123 { SPOOLSS_FORM_BUILTIN
, "Japan Envelope You #4", {0x19a28,0x395f8}, {0x0,0x0,0x19a28,0x395f8} },
124 { SPOOLSS_FORM_BUILTIN
, "Japanese Double Postcard", {0x30d40,0x24220}, {0x0,0x0,0x30d40,0x24220} },
125 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Chou #3", {0x1d4c0,0x395f8}, {0x0,0x0,0x1d4c0,0x395f8} },
126 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Chou #4", {0x15f90,0x320c8}, {0x0,0x0,0x15f90,0x320c8} },
127 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Kaku #2", {0x3a980,0x510e0}, {0x0,0x0,0x3a980,0x510e0} },
128 { SPOOLSS_FORM_BUILTIN
, "Japanese Envelope Kaku #3", {0x34bc0,0x43a08}, {0x0,0x0,0x34bc0,0x43a08} },
129 { SPOOLSS_FORM_BUILTIN
, "Japanese Postcard Rotated", {0x24220,0x186a0}, {0x0,0x0,0x24220,0x186a0} },
130 { SPOOLSS_FORM_BUILTIN
, "Japanese Postcard", {0x186a0,0x24220}, {0x0,0x0,0x186a0,0x24220} },
131 { SPOOLSS_FORM_BUILTIN
, "Ledger", {0x696b8,0x44368}, {0x0,0x0,0x696b8,0x44368} },
132 { SPOOLSS_FORM_BUILTIN
, "Legal Extra", {0x3ae94,0x5d048}, {0x0,0x0,0x3ae94,0x5d048} },
133 { SPOOLSS_FORM_BUILTIN
, "Legal", {0x34b5c,0x56d10}, {0x0,0x0,0x34b5c,0x56d10} },
134 { SPOOLSS_FORM_BUILTIN
, "Letter Extra Transverse", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
135 { SPOOLSS_FORM_BUILTIN
, "Letter Extra", {0x3ae94,0x4a6a0}, {0x0,0x0,0x3ae94,0x4a6a0} },
136 { SPOOLSS_FORM_BUILTIN
, "Letter Plus", {0x34b5c,0x4eb16}, {0x0,0x0,0x34b5c,0x4eb16} },
137 { SPOOLSS_FORM_BUILTIN
, "Letter Rotated", {0x44368,0x34b5c}, {0x0,0x0,0x44368,0x34b5c} },
138 { SPOOLSS_FORM_BUILTIN
, "Letter Small", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
139 { SPOOLSS_FORM_BUILTIN
, "Letter Transverse", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
140 { SPOOLSS_FORM_BUILTIN
, "Letter", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
141 { SPOOLSS_FORM_BUILTIN
, "Note", {0x34b5c,0x44368}, {0x0,0x0,0x34b5c,0x44368} },
142 { SPOOLSS_FORM_BUILTIN
, "PRC 16K Rotated", {0x3f7a0,0x2de60}, {0x0,0x0,0x3f7a0,0x2de60} },
143 { SPOOLSS_FORM_BUILTIN
, "PRC 16K", {0x2de60,0x3f7a0}, {0x0,0x0,0x2de60,0x3f7a0} },
144 { SPOOLSS_FORM_BUILTIN
, "PRC 32K Rotated", {0x2cec0,0x1fbd0}, {0x0,0x0,0x2cec0,0x1fbd0} },
145 { SPOOLSS_FORM_BUILTIN
, "PRC 32K", {0x1fbd0,0x2cec0}, {0x0,0x0,0x1fbd0,0x2cec0} },
146 { SPOOLSS_FORM_BUILTIN
, "PRC 32K(Big) Rotated", {0x318f8,0x222e0}, {0x0,0x0,0x318f8,0x222e0} },
147 { SPOOLSS_FORM_BUILTIN
, "PRC 32K(Big)", {0x222e0,0x318f8}, {0x0,0x0,0x222e0,0x318f8} },
148 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #1 Rotated", {0x28488,0x18e70}, {0x0,0x0,0x28488,0x18e70} },
149 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #1", {0x18e70,0x28488}, {0x0,0x0,0x18e70,0x28488} },
150 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #10 Rotated", {0x6fd10,0x4f1a0}, {0x0,0x0,0x6fd10,0x4f1a0} },
151 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #10", {0x4f1a0,0x6fd10}, {0x0,0x0,0x4f1a0,0x6fd10} },
152 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #2 Rotated", {0x2af80,0x18e70}, {0x0,0x0,0x2af80,0x18e70} },
153 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #2", {0x18e70,0x2af80}, {0x0,0x0,0x18e70,0x2af80} },
154 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #3 Rotated", {0x2af80,0x1e848}, {0x0,0x0,0x2af80,0x1e848} },
155 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #3", {0x1e848,0x2af80}, {0x0,0x0,0x1e848,0x2af80} },
156 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #4 Rotated", {0x32c80,0x1adb0}, {0x0,0x0,0x32c80,0x1adb0} },
157 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #4", {0x1adb0,0x32c80}, {0x0,0x0,0x1adb0,0x32c80} },
158 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #5 Rotated", {0x35b60,0x1adb0}, {0x0,0x0,0x35b60,0x1adb0} },
159 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #5", {0x1adb0,0x35b60}, {0x0,0x0,0x1adb0,0x35b60} },
160 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #6 Rotated", {0x38270,0x1d4c0}, {0x0,0x0,0x38270,0x1d4c0} },
161 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #6", {0x1d4c0,0x38270}, {0x0,0x0,0x1d4c0,0x38270} },
162 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #7 Rotated", {0x38270,0x27100}, {0x0,0x0,0x38270,0x27100} },
163 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #7", {0x27100,0x38270}, {0x0,0x0,0x27100,0x38270} },
164 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #8 Rotated", {0x4b708,0x1d4c0}, {0x0,0x0,0x4b708,0x1d4c0} },
165 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #8", {0x1d4c0,0x4b708}, {0x0,0x0,0x1d4c0,0x4b708} },
166 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #9 Rotated", {0x4f1a0,0x37e88}, {0x0,0x0,0x4f1a0,0x37e88} },
167 { SPOOLSS_FORM_BUILTIN
, "PRC Envelope #9", {0x37e88,0x4f1a0}, {0x0,0x0,0x37e88,0x4f1a0} },
168 { SPOOLSS_FORM_BUILTIN
, "Quarto", {0x347d8,0x43238}, {0x0,0x0,0x347d8,0x43238} },
169 { SPOOLSS_FORM_BUILTIN
, "Reserved48", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
170 { SPOOLSS_FORM_BUILTIN
, "Reserved49", {0x1,0x1}, {0x0,0x0,0x1,0x1} },
171 { SPOOLSS_FORM_BUILTIN
, "Statement", {0x221b4,0x34b5c}, {0x0,0x0,0x221b4,0x34b5c} },
172 { SPOOLSS_FORM_BUILTIN
, "Super A", {0x376b8,0x56ea0}, {0x0,0x0,0x376b8,0x56ea0} },
173 { SPOOLSS_FORM_BUILTIN
, "Super B", {0x4a768,0x76e58}, {0x0,0x0,0x4a768,0x76e58} },
174 { SPOOLSS_FORM_BUILTIN
, "Tabloid Extra", {0x4a6a0,0x6f9f0}, {0x0,0x0,0x4a6a0,0x6f9f0} },
175 { SPOOLSS_FORM_BUILTIN
, "Tabloid", {0x44368,0x696b8}, {0x0,0x0,0x44368,0x696b8} },
176 { SPOOLSS_FORM_BUILTIN
, "US Std Fanfold", {0x5c3e1,0x44368}, {0x0,0x0,0x5c3e1,0x44368} }
179 /********************************************************************
180 static helper functions
181 ********************************************************************/
183 /****************************************************************************
184 Update the changeid time.
185 ****************************************************************************/
189 * @brief Update the ChangeID time of a printer.
191 * This is SO NASTY as some drivers need this to change, others need it
192 * static. This value will change every second, and I must hope that this
193 * is enough..... DON'T CHANGE THIS CODE WITHOUT A TEST MATRIX THE SIZE OF
196 * @return The ChangeID.
198 static uint32_t winreg_printer_rev_changeid(void)
202 get_process_uptime(&tv
);
205 /* Return changeid as msec since spooler restart */
206 return tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
209 * This setting seems to work well but is too untested
210 * to replace the above calculation. Left in for experiementation
211 * of the reader --jerry (Tue Mar 12 09:15:05 CST 2002)
213 return tv
.tv_sec
* 10 + tv
.tv_usec
/ 100000;
220 * @brief Connect to the interal winreg server and open the given printer key.
222 * The function will create the needed subkeys if they don't exist.
224 * @param[in] mem_ctx The memory context to use.
226 * @param[in] server_info The supplied server info.
228 * @param[out] binding_handle A pointer for the winreg dcerpc binding handle.
230 * @param[in] path The path to the key to open.
232 * @param[in] key The key to open.
234 * @param[in] create_key Set to true if the key should be created if it
237 * @param[in] access_mask The access mask to open the key.
239 * @param[out] hive_handle A policy handle for the opened hive.
241 * @param[out] key_handle A policy handle for the opened key.
243 * @return WERR_OK on success, the corresponding DOS error
244 * code if something gone wrong.
246 static WERROR
winreg_printer_openkey(TALLOC_CTX
*mem_ctx
,
247 const struct auth_serversupplied_info
*server_info
,
248 struct messaging_context
*msg_ctx
,
249 struct dcerpc_binding_handle
**winreg_binding_handle
,
253 uint32_t access_mask
,
254 struct policy_handle
*hive_handle
,
255 struct policy_handle
*key_handle
)
257 static struct client_address client_id
;
258 struct dcerpc_binding_handle
*binding_handle
;
259 struct winreg_String wkey
, wkeyclass
;
262 WERROR result
= WERR_OK
;
264 strlcpy(client_id
.addr
, "127.0.0.1", sizeof(client_id
.addr
));
265 client_id
.name
= "127.0.0.1";
267 status
= rpcint_binding_handle(mem_ctx
,
273 if (!NT_STATUS_IS_OK(status
)) {
274 DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg pipe: %s\n",
276 return ntstatus_to_werror(status
);
279 status
= dcerpc_winreg_OpenHKLM(binding_handle
,
285 if (!NT_STATUS_IS_OK(status
)) {
286 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
288 talloc_free(binding_handle
);
289 return ntstatus_to_werror(status
);
291 if (!W_ERROR_IS_OK(result
)) {
292 DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: %s\n",
293 win_errstr(result
)));
294 talloc_free(binding_handle
);
299 keyname
= talloc_asprintf(mem_ctx
, "%s\\%s", path
, key
);
301 keyname
= talloc_strdup(mem_ctx
, path
);
303 if (keyname
== NULL
) {
304 talloc_free(binding_handle
);
312 enum winreg_CreateAction action
= REG_ACTION_NONE
;
314 ZERO_STRUCT(wkeyclass
);
317 status
= dcerpc_winreg_CreateKey(binding_handle
,
329 case REG_ACTION_NONE
:
330 DEBUG(8, ("winreg_printer_openkey:createkey did nothing -- huh?\n"));
332 case REG_CREATED_NEW_KEY
:
333 DEBUG(8, ("winreg_printer_openkey: createkey created %s\n", keyname
));
335 case REG_OPENED_EXISTING_KEY
:
336 DEBUG(8, ("winreg_printer_openkey: createkey opened existing %s\n", keyname
));
340 status
= dcerpc_winreg_OpenKey(binding_handle
,
349 if (!NT_STATUS_IS_OK(status
)) {
350 talloc_free(binding_handle
);
351 return ntstatus_to_werror(status
);
353 if (!W_ERROR_IS_OK(result
)) {
354 talloc_free(binding_handle
);
358 *winreg_binding_handle
= binding_handle
;
364 * @brief Create the registry keyname for the given printer.
366 * @param[in] mem_ctx The memory context to use.
368 * @param[in] printer The name of the printer to get the registry key.
370 * @return The registry key or NULL on error.
372 static char *winreg_printer_data_keyname(TALLOC_CTX
*mem_ctx
, const char *printer
) {
373 return talloc_asprintf(mem_ctx
, "%s\\%s", TOP_LEVEL_PRINT_PRINTERS_KEY
, printer
);
379 * @brief Enumerate values of an opened key handle and retrieve the data.
381 * @param[in] mem_ctx The memory context to use.
383 * @param[in] winreg_handle The binding handle for the rpc connection.
385 * @param[in] key_hnd The opened key handle.
387 * @param[out] pnum_values A pointer to store he number of values found.
389 * @param[out] pnum_values A pointer to store the number of values we found.
391 * @return WERR_OK on success, the corresponding DOS error
392 * code if something gone wrong.
394 static WERROR
winreg_printer_enumvalues(TALLOC_CTX
*mem_ctx
,
395 struct dcerpc_binding_handle
*winreg_handle
,
396 struct policy_handle
*key_hnd
,
397 uint32_t *pnum_values
,
398 struct spoolss_PrinterEnumValues
**penum_values
)
401 uint32_t num_subkeys
, max_subkeylen
, max_classlen
;
402 uint32_t num_values
, max_valnamelen
, max_valbufsize
;
403 uint32_t secdescsize
;
405 NTTIME last_changed_time
;
406 struct winreg_String classname
;
408 struct spoolss_PrinterEnumValues
*enum_values
;
410 WERROR result
= WERR_OK
;
413 tmp_ctx
= talloc_stackframe();
414 if (tmp_ctx
== NULL
) {
418 ZERO_STRUCT(classname
);
420 status
= dcerpc_winreg_QueryInfoKey(winreg_handle
,
433 if (!NT_STATUS_IS_OK(status
)) {
434 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
436 result
= ntstatus_to_werror(status
);
439 if (!W_ERROR_IS_OK(result
)) {
440 DEBUG(0, ("winreg_printer_enumvalues: Could not query info: %s\n",
441 win_errstr(result
)));
445 if (num_values
== 0) {
447 TALLOC_FREE(tmp_ctx
);
451 enum_values
= TALLOC_ARRAY(tmp_ctx
, struct spoolss_PrinterEnumValues
, num_values
);
452 if (enum_values
== NULL
) {
457 for (i
= 0; i
< num_values
; i
++) {
458 struct spoolss_PrinterEnumValues val
;
459 struct winreg_ValNameBuf name_buf
;
460 enum winreg_Type type
= REG_NONE
;
467 name_buf
.size
= max_valnamelen
+ 2;
470 data_size
= max_valbufsize
;
473 data
= (uint8_t *) TALLOC(tmp_ctx
, data_size
);
477 status
= dcerpc_winreg_EnumValue(winreg_handle
,
484 data_size
? &data_size
: NULL
,
487 if (W_ERROR_EQUAL(result
, WERR_NO_MORE_ITEMS
) ) {
489 status
= NT_STATUS_OK
;
493 if (!NT_STATUS_IS_OK(status
)) {
494 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
496 result
= ntstatus_to_werror(status
);
499 if (!W_ERROR_IS_OK(result
)) {
500 DEBUG(0, ("winreg_printer_enumvalues: Could not enumerate values: %s\n",
501 win_errstr(result
)));
505 if (name_buf
.name
== NULL
) {
506 result
= WERR_INVALID_PARAMETER
;
510 val
.value_name
= talloc_strdup(enum_values
, name_buf
.name
);
511 if (val
.value_name
== NULL
) {
515 val
.value_name_len
= strlen_m_term(val
.value_name
) * 2;
518 val
.data_length
= length
;
520 if (val
.data_length
) {
521 val
.data
= talloc(enum_values
, DATA_BLOB
);
522 if (val
.data
== NULL
) {
526 *val
.data
= data_blob_talloc(val
.data
, data
, val
.data_length
);
529 enum_values
[i
] = val
;
532 *pnum_values
= num_values
;
534 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
540 TALLOC_FREE(tmp_ctx
);
547 * @brief Enumerate subkeys of an opened key handle and get the names.
549 * @param[in] mem_ctx The memory context to use.
551 * @param[in] winreg_handle The binding handle for the rpc connection.
553 * @param[in] key_hnd The opened key handle.
555 * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
557 * @param[in] psubkeys A pointer to an array to store the found names of
560 * @return WERR_OK on success, the corresponding DOS error
561 * code if something gone wrong.
563 static WERROR
winreg_printer_enumkeys(TALLOC_CTX
*mem_ctx
,
564 struct dcerpc_binding_handle
*winreg_handle
,
565 struct policy_handle
*key_hnd
,
566 uint32_t *pnum_subkeys
,
567 const char ***psubkeys
)
570 const char **subkeys
;
571 uint32_t num_subkeys
, max_subkeylen
, max_classlen
;
572 uint32_t num_values
, max_valnamelen
, max_valbufsize
;
574 NTTIME last_changed_time
;
575 uint32_t secdescsize
;
576 struct winreg_String classname
;
577 WERROR result
= WERR_OK
;
580 tmp_ctx
= talloc_stackframe();
581 if (tmp_ctx
== NULL
) {
585 ZERO_STRUCT(classname
);
587 status
= dcerpc_winreg_QueryInfoKey(winreg_handle
,
600 if (!NT_STATUS_IS_OK(status
)) {
601 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
603 result
= ntstatus_to_werror(status
);
606 if (!W_ERROR_IS_OK(result
)) {
607 DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
608 win_errstr(result
)));
612 subkeys
= talloc_zero_array(tmp_ctx
, const char *, num_subkeys
+ 2);
613 if (subkeys
== NULL
) {
618 if (num_subkeys
== 0) {
619 subkeys
[0] = talloc_strdup(subkeys
, "");
620 if (subkeys
[0] == NULL
) {
626 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
629 TALLOC_FREE(tmp_ctx
);
633 for (i
= 0; i
< num_subkeys
; i
++) {
637 struct winreg_StringBuf class_buf
;
638 struct winreg_StringBuf name_buf
;
642 class_buf
.size
= max_classlen
+ 2;
643 class_buf
.length
= 0;
646 name_buf
.size
= max_subkeylen
+ 2;
649 ZERO_STRUCT(modtime
);
651 status
= dcerpc_winreg_EnumKey(winreg_handle
,
659 if (W_ERROR_EQUAL(result
, WERR_NO_MORE_ITEMS
) ) {
661 status
= NT_STATUS_OK
;
665 if (!NT_STATUS_IS_OK(status
)) {
666 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
668 result
= ntstatus_to_werror(status
);
671 if (!W_ERROR_IS_OK(result
)) {
672 DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
673 win_errstr(result
)));
677 if (name_buf
.name
== NULL
) {
678 result
= WERR_INVALID_PARAMETER
;
682 name
= talloc_strdup(subkeys
, name_buf
.name
);
691 *pnum_subkeys
= num_subkeys
;
693 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
697 TALLOC_FREE(tmp_ctx
);
704 * @brief A function to delete a key and its subkeys recurively.
706 * @param[in] mem_ctx The memory context to use.
708 * @param[in] winreg_handle The binding handle for the rpc connection.
710 * @param[in] hive_handle A opened hive handle to the key.
712 * @param[in] access_mask The access mask to access the key.
714 * @param[in] key The key to delete
716 * @return WERR_OK on success, the corresponding DOS error
717 * code if something gone wrong.
719 static WERROR
winreg_printer_delete_subkeys(TALLOC_CTX
*mem_ctx
,
720 struct dcerpc_binding_handle
*winreg_handle
,
721 struct policy_handle
*hive_handle
,
722 uint32_t access_mask
,
725 const char **subkeys
= NULL
;
726 uint32_t num_subkeys
= 0;
727 struct policy_handle key_hnd
;
728 struct winreg_String wkey
;
729 WERROR result
= WERR_OK
;
733 ZERO_STRUCT(key_hnd
);
736 DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key
));
738 status
= dcerpc_winreg_OpenKey(winreg_handle
,
746 if (!NT_STATUS_IS_OK(status
)) {
747 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
748 wkey
.name
, nt_errstr(status
)));
749 return ntstatus_to_werror(status
);
751 if (!W_ERROR_IS_OK(result
)) {
752 DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key %s: %s\n",
753 wkey
.name
, win_errstr(result
)));
757 result
= winreg_printer_enumkeys(mem_ctx
,
762 if (!W_ERROR_IS_OK(result
)) {
766 for (i
= 0; i
< num_subkeys
; i
++) {
767 /* create key + subkey */
768 char *subkey
= talloc_asprintf(mem_ctx
, "%s\\%s", key
, subkeys
[i
]);
769 if (subkey
== NULL
) {
773 DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", subkey
));
774 result
= winreg_printer_delete_subkeys(mem_ctx
,
779 if (!W_ERROR_IS_OK(result
)) {
784 if (is_valid_policy_hnd(&key_hnd
)) {
786 dcerpc_winreg_CloseKey(winreg_handle
, mem_ctx
, &key_hnd
, &ignore
);
791 status
= dcerpc_winreg_DeleteKey(winreg_handle
,
796 if (!NT_STATUS_IS_OK(status
)) {
797 result
= ntstatus_to_werror(status
);
801 if (is_valid_policy_hnd(&key_hnd
)) {
804 dcerpc_winreg_CloseKey(winreg_handle
, mem_ctx
, &key_hnd
, &ignore
);
810 static WERROR
winreg_printer_write_sz(TALLOC_CTX
*mem_ctx
,
811 struct dcerpc_binding_handle
*winreg_handle
,
812 struct policy_handle
*key_handle
,
816 struct winreg_String wvalue
;
818 WERROR result
= WERR_OK
;
823 blob
= data_blob_string_const("");
825 if (!push_reg_sz(mem_ctx
, &blob
, data
)) {
826 DEBUG(0, ("winreg_printer_write_sz: Could not marshall string %s for %s\n",
831 status
= dcerpc_winreg_SetValue(winreg_handle
,
839 if (!NT_STATUS_IS_OK(status
)) {
840 result
= ntstatus_to_werror(status
);
842 if (!W_ERROR_IS_OK(result
)) {
843 DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: %s\n",
844 wvalue
.name
, win_errstr(result
)));
850 static WERROR
winreg_printer_write_dword(TALLOC_CTX
*mem_ctx
,
851 struct dcerpc_binding_handle
*winreg_handle
,
852 struct policy_handle
*key_handle
,
856 struct winreg_String wvalue
;
858 WERROR result
= WERR_OK
;
862 blob
= data_blob_talloc(mem_ctx
, NULL
, 4);
863 SIVAL(blob
.data
, 0, data
);
865 status
= dcerpc_winreg_SetValue(winreg_handle
,
873 if (!NT_STATUS_IS_OK(status
)) {
874 result
= ntstatus_to_werror(status
);
876 if (!W_ERROR_IS_OK(result
)) {
877 DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: %s\n",
878 wvalue
.name
, win_errstr(result
)));
884 static WERROR
winreg_printer_write_binary(TALLOC_CTX
*mem_ctx
,
885 struct dcerpc_binding_handle
*winreg_handle
,
886 struct policy_handle
*key_handle
,
890 struct winreg_String wvalue
;
891 WERROR result
= WERR_OK
;
895 status
= dcerpc_winreg_SetValue(winreg_handle
,
903 if (!NT_STATUS_IS_OK(status
)) {
904 result
= ntstatus_to_werror(status
);
906 if (!W_ERROR_IS_OK(result
)) {
907 DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: %s\n",
908 wvalue
.name
, win_errstr(result
)));
914 static WERROR
winreg_printer_query_binary(TALLOC_CTX
*mem_ctx
,
915 struct dcerpc_binding_handle
*winreg_handle
,
916 struct policy_handle
*key_handle
,
920 struct winreg_String wvalue
;
921 enum winreg_Type type
;
922 WERROR result
= WERR_OK
;
923 uint32_t value_len
= 0;
924 uint32_t data_size
= 0;
929 status
= dcerpc_winreg_QueryValue(winreg_handle
,
938 if (!NT_STATUS_IS_OK(status
)) {
939 result
= ntstatus_to_werror(status
);
941 if (!W_ERROR_IS_OK(result
)) {
942 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
943 wvalue
.name
, win_errstr(result
)));
947 if (type
!= REG_BINARY
) {
948 result
= WERR_INVALID_DATATYPE
;
951 blob
= data_blob_talloc(mem_ctx
, NULL
, data_size
);
952 if (blob
.data
== NULL
) {
958 status
= dcerpc_winreg_QueryValue(winreg_handle
,
967 if (!NT_STATUS_IS_OK(status
)) {
968 result
= ntstatus_to_werror(status
);
970 if (!W_ERROR_IS_OK(result
)) {
971 DEBUG(2, ("winreg_printer_query_binary: Could not query value %s: %s\n",
972 wvalue
.name
, win_errstr(result
)));
977 data
->data
= blob
.data
;
978 data
->length
= blob
.length
;
984 static WERROR
winreg_printer_query_dword(TALLOC_CTX
*mem_ctx
,
985 struct dcerpc_binding_handle
*winreg_handle
,
986 struct policy_handle
*key_handle
,
990 struct winreg_String wvalue
;
991 enum winreg_Type type
;
992 WERROR result
= WERR_OK
;
993 uint32_t value_len
= 0;
994 uint32_t data_size
= 0;
999 status
= dcerpc_winreg_QueryValue(winreg_handle
,
1008 if (!NT_STATUS_IS_OK(status
)) {
1009 result
= ntstatus_to_werror(status
);
1011 if (!W_ERROR_IS_OK(result
)) {
1012 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1013 wvalue
.name
, win_errstr(result
)));
1017 if (type
!= REG_DWORD
) {
1018 result
= WERR_INVALID_DATATYPE
;
1022 if (data_size
!= 4) {
1023 result
= WERR_INVALID_DATA
;
1027 blob
= data_blob_talloc(mem_ctx
, NULL
, data_size
);
1028 if (blob
.data
== NULL
) {
1029 result
= WERR_NOMEM
;
1034 status
= dcerpc_winreg_QueryValue(winreg_handle
,
1043 if (!NT_STATUS_IS_OK(status
)) {
1044 result
= ntstatus_to_werror(status
);
1046 if (!W_ERROR_IS_OK(result
)) {
1047 DEBUG(2, ("winreg_printer_query_dword: Could not query value %s: %s\n",
1048 wvalue
.name
, win_errstr(result
)));
1053 *data
= IVAL(blob
.data
, 0);
1059 static WERROR
winreg_printer_write_multi_sz(TALLOC_CTX
*mem_ctx
,
1060 struct dcerpc_binding_handle
*winreg_handle
,
1061 struct policy_handle
*key_handle
,
1065 struct winreg_String wvalue
;
1067 WERROR result
= WERR_OK
;
1070 wvalue
.name
= value
;
1071 if (!push_reg_multi_sz(mem_ctx
, &blob
, data
)) {
1074 status
= dcerpc_winreg_SetValue(winreg_handle
,
1082 if (!NT_STATUS_IS_OK(status
)) {
1083 result
= ntstatus_to_werror(status
);
1085 if (!W_ERROR_IS_OK(result
)) {
1086 DEBUG(0, ("winreg_printer_write_multi_sz: Could not set value %s: %s\n",
1087 wvalue
.name
, win_errstr(result
)));
1093 static WERROR
winreg_printer_opendriver(TALLOC_CTX
*mem_ctx
,
1094 const struct auth_serversupplied_info
*server_info
,
1095 struct messaging_context
*msg_ctx
,
1096 const char *drivername
,
1097 const char *architecture
,
1099 uint32_t access_mask
,
1101 struct dcerpc_binding_handle
**winreg_binding_handle
,
1102 struct policy_handle
*hive_hnd
,
1103 struct policy_handle
*key_hnd
)
1108 key_name
= talloc_asprintf(mem_ctx
, "%s\\Environments\\%s\\Drivers\\Version-%u",
1109 TOP_LEVEL_CONTROL_KEY
,
1110 architecture
, version
);
1115 result
= winreg_printer_openkey(mem_ctx
,
1118 winreg_binding_handle
,
1128 static WERROR
winreg_enumval_to_dword(TALLOC_CTX
*mem_ctx
,
1129 struct spoolss_PrinterEnumValues
*v
,
1130 const char *valuename
, uint32_t *dw
)
1132 /* just return if it is not the one we are looking for */
1133 if (strcmp(valuename
, v
->value_name
) != 0) {
1134 return WERR_NOT_FOUND
;
1137 if (v
->type
!= REG_DWORD
) {
1138 return WERR_INVALID_DATATYPE
;
1141 if (v
->data_length
!= 4) {
1146 *dw
= IVAL(v
->data
->data
, 0);
1150 static WERROR
winreg_enumval_to_sz(TALLOC_CTX
*mem_ctx
,
1151 struct spoolss_PrinterEnumValues
*v
,
1152 const char *valuename
, const char **_str
)
1154 /* just return if it is not the one we are looking for */
1155 if (strcmp(valuename
, v
->value_name
) != 0) {
1156 return WERR_NOT_FOUND
;
1159 if (v
->type
!= REG_SZ
) {
1160 return WERR_INVALID_DATATYPE
;
1163 if (v
->data_length
== 0) {
1164 *_str
= talloc_strdup(mem_ctx
, EMPTY_STRING
);
1165 if (*_str
== NULL
) {
1171 if (!pull_reg_sz(mem_ctx
, v
->data
, _str
)) {
1178 static WERROR
winreg_enumval_to_multi_sz(TALLOC_CTX
*mem_ctx
,
1179 struct spoolss_PrinterEnumValues
*v
,
1180 const char *valuename
,
1181 const char ***array
)
1183 /* just return if it is not the one we are looking for */
1184 if (strcmp(valuename
, v
->value_name
) != 0) {
1185 return WERR_NOT_FOUND
;
1188 if (v
->type
!= REG_MULTI_SZ
) {
1189 return WERR_INVALID_DATATYPE
;
1192 if (v
->data_length
== 0) {
1193 *array
= talloc_array(mem_ctx
, const char *, 1);
1194 if (*array
== NULL
) {
1201 if (!pull_reg_multi_sz(mem_ctx
, v
->data
, array
)) {
1208 static WERROR
winreg_printer_write_date(TALLOC_CTX
*mem_ctx
,
1209 struct dcerpc_binding_handle
*winreg_handle
,
1210 struct policy_handle
*key_handle
,
1214 struct winreg_String wvalue
;
1216 WERROR result
= WERR_OK
;
1222 t
= nt_time_to_unix(data
);
1224 str
= talloc_asprintf(mem_ctx
, "%02d/%02d/%04d",
1225 tm
->tm_mon
+ 1, tm
->tm_mday
, tm
->tm_year
+ 1900);
1230 wvalue
.name
= value
;
1231 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
1234 status
= dcerpc_winreg_SetValue(winreg_handle
,
1242 if (!NT_STATUS_IS_OK(status
)) {
1243 result
= ntstatus_to_werror(status
);
1245 if (!W_ERROR_IS_OK(result
)) {
1246 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1247 wvalue
.name
, win_errstr(result
)));
1253 static WERROR
winreg_printer_date_to_NTTIME(const char *str
, NTTIME
*data
)
1260 if (sscanf(str
, "%d/%d/%d",
1261 &tm
.tm_mon
, &tm
.tm_mday
, &tm
.tm_year
) != 3) {
1262 return WERR_INVALID_PARAMETER
;
1269 unix_to_nt_time(data
, t
);
1274 static WERROR
winreg_printer_write_ver(TALLOC_CTX
*mem_ctx
,
1275 struct dcerpc_binding_handle
*winreg_handle
,
1276 struct policy_handle
*key_handle
,
1280 struct winreg_String wvalue
;
1282 WERROR result
= WERR_OK
;
1286 /* FIXME: check format is right,
1287 * this needs to be something like: 6.1.7600.16385 */
1288 str
= talloc_asprintf(mem_ctx
, "%u.%u.%u.%u",
1289 (unsigned)((data
>> 48) & 0xFFFF),
1290 (unsigned)((data
>> 32) & 0xFFFF),
1291 (unsigned)((data
>> 16) & 0xFFFF),
1292 (unsigned)(data
& 0xFFFF));
1297 wvalue
.name
= value
;
1298 if (!push_reg_sz(mem_ctx
, &blob
, str
)) {
1301 status
= dcerpc_winreg_SetValue(winreg_handle
,
1309 if (!NT_STATUS_IS_OK(status
)) {
1310 result
= ntstatus_to_werror(status
);
1312 if (!W_ERROR_IS_OK(result
)) {
1313 DEBUG(0, ("winreg_printer_write_date: Could not set value %s: %s\n",
1314 wvalue
.name
, win_errstr(result
)));
1320 static WERROR
winreg_printer_ver_to_dword(const char *str
, uint64_t *data
)
1322 unsigned int v1
, v2
, v3
, v4
;
1324 if (sscanf(str
, "%u.%u.%u.%u", &v1
, &v2
, &v3
, &v4
) != 4) {
1325 return WERR_INVALID_PARAMETER
;
1328 *data
= ((uint64_t)(v1
& 0xFFFF) << 48) +
1329 ((uint64_t)(v2
& 0xFFFF) << 32) +
1330 ((uint64_t)(v3
& 0xFFFF) << 16) +
1331 (uint64_t)(v2
& 0xFFFF);
1336 /********************************************************************
1337 Public winreg function for spoolss
1338 ********************************************************************/
1340 WERROR
winreg_create_printer(TALLOC_CTX
*mem_ctx
,
1341 const struct auth_serversupplied_info
*server_info
,
1342 struct messaging_context
*msg_ctx
,
1343 const char *servername
,
1344 const char *sharename
)
1346 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1347 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
1348 struct policy_handle hive_hnd
, key_hnd
;
1349 struct spoolss_SetPrinterInfo2
*info2
;
1350 struct security_descriptor
*secdesc
;
1351 struct winreg_String wkey
, wkeyclass
;
1353 const char *subkeys
[] = { SPOOL_DSDRIVER_KEY
, SPOOL_DSSPOOLER_KEY
, SPOOL_PRINTERDATA_KEY
};
1354 uint32_t i
, count
= ARRAY_SIZE(subkeys
);
1355 uint32_t info2_mask
= 0;
1356 WERROR result
= WERR_OK
;
1357 TALLOC_CTX
*tmp_ctx
;
1359 tmp_ctx
= talloc_stackframe();
1360 if (tmp_ctx
== NULL
) {
1364 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1366 TALLOC_FREE(tmp_ctx
);
1370 ZERO_STRUCT(hive_hnd
);
1371 ZERO_STRUCT(key_hnd
);
1373 result
= winreg_printer_openkey(tmp_ctx
,
1383 if (W_ERROR_IS_OK(result
)) {
1384 DEBUG(2, ("winreg_create_printer: Skipping, %s already exists\n", path
));
1386 } else if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
1387 DEBUG(2, ("winreg_create_printer: Creating default values in %s\n", path
));
1388 } else if (!W_ERROR_IS_OK(result
)) {
1389 DEBUG(0, ("winreg_create_printer: Could not open key %s: %s\n",
1390 path
, win_errstr(result
)));
1394 /* Create the main key */
1395 result
= winreg_printer_openkey(tmp_ctx
,
1405 if (!W_ERROR_IS_OK(result
)) {
1406 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1407 path
, win_errstr(result
)));
1411 if (is_valid_policy_hnd(&key_hnd
)) {
1412 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
1415 /* Create subkeys */
1416 for (i
= 0; i
< count
; i
++) {
1418 enum winreg_CreateAction action
= REG_ACTION_NONE
;
1420 ZERO_STRUCT(key_hnd
);
1423 wkey
.name
= talloc_asprintf(tmp_ctx
, "%s\\%s", path
, subkeys
[i
]);
1424 if (wkey
.name
== NULL
) {
1425 result
= WERR_NOMEM
;
1429 ZERO_STRUCT(wkeyclass
);
1430 wkeyclass
.name
= "";
1432 status
= dcerpc_winreg_CreateKey(winreg_handle
,
1443 if (!NT_STATUS_IS_OK(status
)) {
1444 result
= ntstatus_to_werror(status
);
1446 if (!W_ERROR_IS_OK(result
)) {
1447 DEBUG(0, ("winreg_create_printer_keys: Could not create key %s: %s\n",
1448 wkey
.name
, win_errstr(result
)));
1454 const char *dnssuffix
;
1455 const char *longname
;
1456 const char *uncname
;
1458 result
= winreg_printer_write_sz(tmp_ctx
,
1461 SPOOL_REG_PRINTERNAME
,
1463 if (!W_ERROR_IS_OK(result
)) {
1467 result
= winreg_printer_write_sz(tmp_ctx
,
1470 SPOOL_REG_SHORTSERVERNAME
,
1472 if (!W_ERROR_IS_OK(result
)) {
1476 /* We make the assumption that the netbios name
1477 * is the same as the DNS name since the former
1478 * will be what we used to join the domain
1480 dnssuffix
= get_mydnsdomname(tmp_ctx
);
1481 if (dnssuffix
!= NULL
&& dnssuffix
[0] != '\0') {
1482 longname
= talloc_asprintf(tmp_ctx
, "%s.%s", global_myname(), dnssuffix
);
1484 longname
= talloc_strdup(tmp_ctx
, global_myname());
1486 if (longname
== NULL
) {
1487 result
= WERR_NOMEM
;
1491 result
= winreg_printer_write_sz(tmp_ctx
,
1494 SPOOL_REG_SERVERNAME
,
1496 if (!W_ERROR_IS_OK(result
)) {
1500 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
1501 longname
, sharename
);
1502 if (uncname
== NULL
) {
1503 result
= WERR_NOMEM
;
1507 result
= winreg_printer_write_sz(tmp_ctx
,
1512 if (!W_ERROR_IS_OK(result
)) {
1516 result
= winreg_printer_write_dword(tmp_ctx
,
1519 SPOOL_REG_VERSIONNUMBER
,
1521 if (!W_ERROR_IS_OK(result
)) {
1525 result
= winreg_printer_write_dword(tmp_ctx
,
1528 SPOOL_REG_PRINTSTARTTIME
,
1530 if (!W_ERROR_IS_OK(result
)) {
1534 result
= winreg_printer_write_dword(tmp_ctx
,
1537 SPOOL_REG_PRINTENDTIME
,
1539 if (!W_ERROR_IS_OK(result
)) {
1543 result
= winreg_printer_write_dword(tmp_ctx
,
1548 if (!W_ERROR_IS_OK(result
)) {
1552 result
= winreg_printer_write_dword(tmp_ctx
,
1555 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
1557 if (!W_ERROR_IS_OK(result
)) {
1565 if (is_valid_policy_hnd(&key_hnd
)) {
1566 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
1569 info2
= talloc_zero(tmp_ctx
, struct spoolss_SetPrinterInfo2
);
1570 if (info2
== NULL
) {
1571 result
= WERR_NOMEM
;
1575 if (servername
!= NULL
) {
1576 info2
->printername
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
1577 servername
, sharename
);
1579 info2
->printername
= sharename
;
1581 if (info2
->printername
== NULL
) {
1582 result
= WERR_NOMEM
;
1585 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTERNAME
;
1587 info2
->sharename
= sharename
;
1588 info2_mask
|= SPOOLSS_PRINTER_INFO_SHARENAME
;
1590 info2
->portname
= SAMBA_PRINTER_PORT_NAME
;
1591 info2_mask
|= SPOOLSS_PRINTER_INFO_PORTNAME
;
1593 info2
->printprocessor
= "winprint";
1594 info2_mask
|= SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
;
1596 info2
->datatype
= "RAW";
1597 info2_mask
|= SPOOLSS_PRINTER_INFO_DATATYPE
;
1599 info2
->comment
= "";
1600 info2_mask
|= SPOOLSS_PRINTER_INFO_COMMENT
;
1602 info2
->attributes
= PRINTER_ATTRIBUTE_SAMBA
;
1603 info2_mask
|= SPOOLSS_PRINTER_INFO_ATTRIBUTES
;
1605 info2
->starttime
= 0; /* Minutes since 12:00am GMT */
1606 info2_mask
|= SPOOLSS_PRINTER_INFO_STARTTIME
;
1608 info2
->untiltime
= 0; /* Minutes since 12:00am GMT */
1609 info2_mask
|= SPOOLSS_PRINTER_INFO_UNTILTIME
;
1611 info2
->priority
= 1;
1612 info2_mask
|= SPOOLSS_PRINTER_INFO_PRIORITY
;
1614 info2
->defaultpriority
= 1;
1615 info2_mask
|= SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
;
1617 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1618 if (!W_ERROR_IS_OK(result
)) {
1621 info2_mask
|= SPOOLSS_PRINTER_INFO_SECDESC
;
1624 * Don't write a default Device Mode to the registry! The Device Mode is
1625 * only written to disk with a SetPrinter level 2 or 8.
1628 result
= winreg_update_printer(tmp_ctx
,
1638 if (winreg_handle
!= NULL
) {
1641 if (is_valid_policy_hnd(&key_hnd
)) {
1642 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1644 if (is_valid_policy_hnd(&hive_hnd
)) {
1645 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1649 talloc_free(tmp_ctx
);
1653 WERROR
winreg_update_printer(TALLOC_CTX
*mem_ctx
,
1654 const struct auth_serversupplied_info
*server_info
,
1655 struct messaging_context
*msg_ctx
,
1656 const char *sharename
,
1657 uint32_t info2_mask
,
1658 struct spoolss_SetPrinterInfo2
*info2
,
1659 struct spoolss_DeviceMode
*devmode
,
1660 struct security_descriptor
*secdesc
)
1662 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1663 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
1664 struct policy_handle hive_hnd
, key_hnd
;
1665 int snum
= lp_servicenumber(sharename
);
1666 enum ndr_err_code ndr_err
;
1669 WERROR result
= WERR_OK
;
1670 TALLOC_CTX
*tmp_ctx
;
1672 tmp_ctx
= talloc_stackframe();
1673 if (tmp_ctx
== NULL
) {
1677 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
1679 TALLOC_FREE(tmp_ctx
);
1683 ZERO_STRUCT(hive_hnd
);
1684 ZERO_STRUCT(key_hnd
);
1686 result
= winreg_printer_openkey(tmp_ctx
,
1696 if (!W_ERROR_IS_OK(result
)) {
1697 DEBUG(0, ("winreg_update_printer: Could not open key %s: %s\n",
1698 path
, win_errstr(result
)));
1702 if (info2_mask
& SPOOLSS_PRINTER_INFO_ATTRIBUTES
) {
1703 result
= winreg_printer_write_dword(tmp_ctx
,
1708 if (!W_ERROR_IS_OK(result
)) {
1714 if (info2_mask
& SPOOLSS_PRINTER_INFO_AVERAGEPPM
) {
1715 result
= winreg_printer_write_dword(tmp_ctx
,
1720 if (!W_ERROR_IS_OK(result
)) {
1726 if (info2_mask
& SPOOLSS_PRINTER_INFO_COMMENT
) {
1727 result
= winreg_printer_write_sz(tmp_ctx
,
1732 if (!W_ERROR_IS_OK(result
)) {
1737 if (info2_mask
& SPOOLSS_PRINTER_INFO_DATATYPE
) {
1738 result
= winreg_printer_write_sz(tmp_ctx
,
1743 if (!W_ERROR_IS_OK(result
)) {
1748 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEFAULTPRIORITY
) {
1749 result
= winreg_printer_write_dword(tmp_ctx
,
1753 info2
->defaultpriority
);
1754 if (!W_ERROR_IS_OK(result
)) {
1759 if (info2_mask
& SPOOLSS_PRINTER_INFO_DEVMODE
) {
1761 * Some client drivers freak out if there is a NULL devmode
1762 * (probably the driver is not checking before accessing
1763 * the devmode pointer) --jerry
1765 if (devmode
== NULL
&& lp_default_devmode(snum
) && info2
!= NULL
) {
1766 result
= spoolss_create_default_devmode(tmp_ctx
,
1769 if (!W_ERROR_IS_OK(result
)) {
1773 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, devmode
,
1774 (ndr_push_flags_fn_t
) ndr_push_spoolss_DeviceMode
);
1775 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1776 DEBUG(0, ("winreg_update_printer: Failed to marshall device mode\n"));
1777 result
= WERR_NOMEM
;
1781 result
= winreg_printer_write_binary(tmp_ctx
,
1786 if (!W_ERROR_IS_OK(result
)) {
1791 if (info2_mask
& SPOOLSS_PRINTER_INFO_DRIVERNAME
) {
1792 result
= winreg_printer_write_sz(tmp_ctx
,
1797 if (!W_ERROR_IS_OK(result
)) {
1802 if (info2_mask
& SPOOLSS_PRINTER_INFO_LOCATION
) {
1803 result
= winreg_printer_write_sz(tmp_ctx
,
1808 if (!W_ERROR_IS_OK(result
)) {
1813 if (info2_mask
& SPOOLSS_PRINTER_INFO_PARAMETERS
) {
1814 result
= winreg_printer_write_sz(tmp_ctx
,
1819 if (!W_ERROR_IS_OK(result
)) {
1824 if (info2_mask
& SPOOLSS_PRINTER_INFO_PORTNAME
) {
1825 result
= winreg_printer_write_sz(tmp_ctx
,
1830 if (!W_ERROR_IS_OK(result
)) {
1835 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTERNAME
) {
1837 * in addprinter: no servername and the printer is the name
1838 * in setprinter: servername is \\server
1839 * and printer is \\server\\printer
1841 * Samba manages only local printers.
1842 * we currently don't support things like i
1843 * path=\\other_server\printer
1845 * We only store the printername, not \\server\printername
1847 const char *p
= strrchr(info2
->printername
, '\\');
1849 p
= info2
->printername
;
1853 result
= winreg_printer_write_sz(tmp_ctx
,
1858 if (!W_ERROR_IS_OK(result
)) {
1863 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRINTPROCESSOR
) {
1864 result
= winreg_printer_write_sz(tmp_ctx
,
1868 info2
->printprocessor
);
1869 if (!W_ERROR_IS_OK(result
)) {
1874 if (info2_mask
& SPOOLSS_PRINTER_INFO_PRIORITY
) {
1875 result
= winreg_printer_write_dword(tmp_ctx
,
1880 if (!W_ERROR_IS_OK(result
)) {
1885 if (info2_mask
& SPOOLSS_PRINTER_INFO_SECDESC
) {
1887 * We need a security descriptor, if it isn't specified by
1888 * AddPrinter{Ex} then create a default descriptor.
1890 if (secdesc
== NULL
) {
1891 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
1892 if (!W_ERROR_IS_OK(result
)) {
1896 result
= winreg_set_printer_secdesc(tmp_ctx
,
1901 if (!W_ERROR_IS_OK(result
)) {
1906 if (info2_mask
& SPOOLSS_PRINTER_INFO_SEPFILE
) {
1907 result
= winreg_printer_write_sz(tmp_ctx
,
1912 if (!W_ERROR_IS_OK(result
)) {
1917 if (info2_mask
& SPOOLSS_PRINTER_INFO_SHARENAME
) {
1918 result
= winreg_printer_write_sz(tmp_ctx
,
1923 if (!W_ERROR_IS_OK(result
)) {
1928 if (info2_mask
& SPOOLSS_PRINTER_INFO_STARTTIME
) {
1929 result
= winreg_printer_write_dword(tmp_ctx
,
1934 if (!W_ERROR_IS_OK(result
)) {
1939 if (info2_mask
& SPOOLSS_PRINTER_INFO_STATUS
) {
1940 result
= winreg_printer_write_dword(tmp_ctx
,
1945 if (!W_ERROR_IS_OK(result
)) {
1950 if (info2_mask
& SPOOLSS_PRINTER_INFO_UNTILTIME
) {
1951 result
= winreg_printer_write_dword(tmp_ctx
,
1956 if (!W_ERROR_IS_OK(result
)) {
1961 result
= winreg_printer_write_dword(tmp_ctx
,
1965 winreg_printer_rev_changeid());
1966 if (!W_ERROR_IS_OK(result
)) {
1972 if (winreg_handle
!= NULL
) {
1975 if (is_valid_policy_hnd(&key_hnd
)) {
1976 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
1978 if (is_valid_policy_hnd(&hive_hnd
)) {
1979 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
1983 TALLOC_FREE(tmp_ctx
);
1987 WERROR
winreg_get_printer(TALLOC_CTX
*mem_ctx
,
1988 const struct auth_serversupplied_info
*server_info
,
1989 struct messaging_context
*msg_ctx
,
1990 const char *servername
,
1991 const char *printer
,
1992 struct spoolss_PrinterInfo2
**pinfo2
)
1994 struct spoolss_PrinterInfo2
*info2
;
1995 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1996 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
1997 struct policy_handle hive_hnd
, key_hnd
;
1998 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
1999 struct spoolss_PrinterEnumValues
*v
;
2000 enum ndr_err_code ndr_err
;
2002 int snum
= lp_servicenumber(printer
);
2003 uint32_t num_values
= 0;
2006 WERROR result
= WERR_OK
;
2007 TALLOC_CTX
*tmp_ctx
;
2009 tmp_ctx
= talloc_stackframe();
2010 if (tmp_ctx
== NULL
) {
2014 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2016 TALLOC_FREE(tmp_ctx
);
2020 result
= winreg_printer_openkey(tmp_ctx
,
2030 if (!W_ERROR_IS_OK(result
)) {
2031 DEBUG(2, ("winreg_get_printer: Could not open key %s: %s\n",
2032 path
, win_errstr(result
)));
2036 result
= winreg_printer_enumvalues(tmp_ctx
,
2041 if (!W_ERROR_IS_OK(result
)) {
2042 DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
2043 path
, win_errstr(result
)));
2047 info2
= talloc_zero(tmp_ctx
, struct spoolss_PrinterInfo2
);
2048 if (info2
== NULL
) {
2049 result
= WERR_NOMEM
;
2053 FILL_STRING(info2
, EMPTY_STRING
, info2
->servername
);
2054 FILL_STRING(info2
, EMPTY_STRING
, info2
->printername
);
2055 FILL_STRING(info2
, EMPTY_STRING
, info2
->sharename
);
2056 FILL_STRING(info2
, EMPTY_STRING
, info2
->portname
);
2057 FILL_STRING(info2
, EMPTY_STRING
, info2
->drivername
);
2058 FILL_STRING(info2
, EMPTY_STRING
, info2
->comment
);
2059 FILL_STRING(info2
, EMPTY_STRING
, info2
->location
);
2060 FILL_STRING(info2
, EMPTY_STRING
, info2
->sepfile
);
2061 FILL_STRING(info2
, EMPTY_STRING
, info2
->printprocessor
);
2062 FILL_STRING(info2
, EMPTY_STRING
, info2
->datatype
);
2063 FILL_STRING(info2
, EMPTY_STRING
, info2
->parameters
);
2065 if (servername
!= NULL
&& servername
[0] != '\0') {
2066 info2
->servername
= talloc_asprintf(info2
, "\\\\%s", servername
);
2067 if (info2
->servername
== NULL
) {
2068 result
= WERR_NOMEM
;
2073 for (i
= 0; i
< num_values
; i
++) {
2074 v
= &enum_values
[i
];
2076 result
= winreg_enumval_to_sz(info2
,
2079 &info2
->printername
);
2080 CHECK_ERROR(result
);
2082 result
= winreg_enumval_to_sz(info2
,
2086 CHECK_ERROR(result
);
2088 result
= winreg_enumval_to_sz(info2
,
2092 CHECK_ERROR(result
);
2094 result
= winreg_enumval_to_sz(info2
,
2098 CHECK_ERROR(result
);
2100 result
= winreg_enumval_to_sz(info2
,
2104 CHECK_ERROR(result
);
2106 result
= winreg_enumval_to_sz(info2
,
2110 CHECK_ERROR(result
);
2112 result
= winreg_enumval_to_sz(info2
,
2115 &info2
->printprocessor
);
2116 CHECK_ERROR(result
);
2118 result
= winreg_enumval_to_sz(info2
,
2122 CHECK_ERROR(result
);
2124 result
= winreg_enumval_to_sz(info2
,
2127 &info2
->parameters
);
2128 CHECK_ERROR(result
);
2130 result
= winreg_enumval_to_sz(info2
,
2133 &info2
->drivername
);
2134 CHECK_ERROR(result
);
2136 result
= winreg_enumval_to_dword(info2
,
2139 &info2
->attributes
);
2140 CHECK_ERROR(result
);
2142 result
= winreg_enumval_to_dword(info2
,
2146 CHECK_ERROR(result
);
2148 result
= winreg_enumval_to_dword(info2
,
2151 &info2
->defaultpriority
);
2152 CHECK_ERROR(result
);
2154 result
= winreg_enumval_to_dword(info2
,
2158 CHECK_ERROR(result
);
2160 result
= winreg_enumval_to_dword(info2
,
2164 CHECK_ERROR(result
);
2166 result
= winreg_enumval_to_dword(info2
,
2170 CHECK_ERROR(result
);
2172 result
= winreg_enumval_to_dword(info2
,
2176 CHECK_ERROR(result
);
2179 if (!W_ERROR_IS_OK(result
)) {
2180 DEBUG(0, ("winreg_get_printer: winreg_enumval_to_TYPE() failed "
2183 win_errstr(result
)));
2187 /* Create the printername */
2188 if (info2
->servername
!= NULL
&& info2
->servername
[0] != '\0') {
2189 if (lp_force_printername(snum
)) {
2190 const char *p
= talloc_asprintf(info2
, "%s\\%s",
2194 result
= WERR_NOMEM
;
2197 info2
->printername
= p
;
2199 char *p
= talloc_asprintf(info2
, "%s\\%s",
2201 info2
->printername
);
2203 result
= WERR_NOMEM
;
2206 info2
->printername
= p
;
2210 /* Construct the Device Mode */
2211 result
= winreg_printer_query_binary(tmp_ctx
,
2216 if (W_ERROR_IS_OK(result
)) {
2217 info2
->devmode
= talloc_zero(info2
, struct spoolss_DeviceMode
);
2218 if (info2
->devmode
== NULL
) {
2219 result
= WERR_NOMEM
;
2222 ndr_err
= ndr_pull_struct_blob(&blob
,
2225 (ndr_pull_flags_fn_t
) ndr_pull_spoolss_DeviceMode
);
2226 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2227 DEBUG(0, ("winreg_get_printer: Failed to unmarshall device mode\n"));
2228 result
= WERR_NOMEM
;
2233 if (info2
->devmode
== NULL
&& lp_default_devmode(snum
)) {
2234 result
= spoolss_create_default_devmode(info2
,
2237 if (!W_ERROR_IS_OK(result
)) {
2242 if (info2
->devmode
!= NULL
) {
2243 info2
->devmode
->devicename
= talloc_strdup(info2
->devmode
,
2244 info2
->printername
);
2245 if (info2
->devmode
->devicename
== NULL
) {
2246 DEBUG(0, ("winreg_get_printer: Failed to set devicename\n"));
2247 result
= WERR_NOMEM
;
2252 result
= winreg_get_printer_secdesc(info2
,
2257 if (!W_ERROR_IS_OK(result
)) {
2261 /* Fix for OS/2 drivers. */
2262 if (get_remote_arch() == RA_OS2
) {
2263 spoolss_map_to_os2_driver(info2
, &info2
->drivername
);
2267 *pinfo2
= talloc_move(mem_ctx
, &info2
);
2272 if (winreg_handle
!= NULL
) {
2275 if (is_valid_policy_hnd(&key_hnd
)) {
2276 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2278 if (is_valid_policy_hnd(&hive_hnd
)) {
2279 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2283 TALLOC_FREE(tmp_ctx
);
2287 WERROR
winreg_get_printer_secdesc(TALLOC_CTX
*mem_ctx
,
2288 const struct auth_serversupplied_info
*server_info
,
2289 struct messaging_context
*msg_ctx
,
2290 const char *sharename
,
2291 struct spoolss_security_descriptor
**psecdesc
)
2293 struct spoolss_security_descriptor
*secdesc
;
2294 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2295 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
2296 struct policy_handle hive_hnd
, key_hnd
;
2297 enum ndr_err_code ndr_err
;
2300 TALLOC_CTX
*tmp_ctx
;
2303 tmp_ctx
= talloc_stackframe();
2304 if (tmp_ctx
== NULL
) {
2308 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
2310 talloc_free(tmp_ctx
);
2314 ZERO_STRUCT(hive_hnd
);
2315 ZERO_STRUCT(key_hnd
);
2317 result
= winreg_printer_openkey(tmp_ctx
,
2327 if (!W_ERROR_IS_OK(result
)) {
2328 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2329 goto create_default
;
2334 result
= winreg_printer_query_binary(tmp_ctx
,
2339 if (!W_ERROR_IS_OK(result
)) {
2340 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
2341 goto create_default
;
2346 secdesc
= talloc_zero(tmp_ctx
, struct spoolss_security_descriptor
);
2347 if (secdesc
== NULL
) {
2348 result
= WERR_NOMEM
;
2351 ndr_err
= ndr_pull_struct_blob(&blob
,
2354 (ndr_pull_flags_fn_t
) ndr_pull_security_descriptor
);
2355 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2356 DEBUG(0, ("winreg_get_secdesc: Failed to unmarshall security descriptor\n"));
2357 result
= WERR_NOMEM
;
2362 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
2369 result
= winreg_printer_openkey(tmp_ctx
,
2379 if (!W_ERROR_IS_OK(result
)) {
2383 result
= spoolss_create_default_secdesc(tmp_ctx
, &secdesc
);
2384 if (!W_ERROR_IS_OK(result
)) {
2388 /* If security descriptor is owned by S-1-1-0 and winbindd is up,
2389 this security descriptor has been created when winbindd was
2390 down. Take ownership of security descriptor. */
2391 if (dom_sid_equal(secdesc
->owner_sid
, &global_sid_World
)) {
2392 struct dom_sid owner_sid
;
2394 /* Change sd owner to workgroup administrator */
2396 if (secrets_fetch_domain_sid(lp_workgroup(), &owner_sid
)) {
2397 struct spoolss_security_descriptor
*new_secdesc
;
2401 sid_append_rid(&owner_sid
, DOMAIN_RID_ADMINISTRATOR
);
2403 new_secdesc
= make_sec_desc(tmp_ctx
,
2412 if (new_secdesc
== NULL
) {
2413 result
= WERR_NOMEM
;
2417 /* Swap with other one */
2418 secdesc
= new_secdesc
;
2422 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, secdesc
,
2423 (ndr_push_flags_fn_t
) ndr_push_security_descriptor
);
2424 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2425 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2426 result
= WERR_NOMEM
;
2430 result
= winreg_printer_write_binary(tmp_ctx
,
2435 if (!W_ERROR_IS_OK(result
)) {
2440 *psecdesc
= talloc_move(mem_ctx
, &secdesc
);
2445 if (winreg_handle
!= NULL
) {
2448 if (is_valid_policy_hnd(&key_hnd
)) {
2449 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2451 if (is_valid_policy_hnd(&hive_hnd
)) {
2452 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2456 talloc_free(tmp_ctx
);
2460 WERROR
winreg_set_printer_secdesc(TALLOC_CTX
*mem_ctx
,
2461 const struct auth_serversupplied_info
*server_info
,
2462 struct messaging_context
*msg_ctx
,
2463 const char *sharename
,
2464 const struct spoolss_security_descriptor
*secdesc
)
2466 const struct spoolss_security_descriptor
*new_secdesc
= secdesc
;
2467 struct spoolss_security_descriptor
*old_secdesc
;
2468 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2469 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
2470 struct policy_handle hive_hnd
, key_hnd
;
2471 enum ndr_err_code ndr_err
;
2474 TALLOC_CTX
*tmp_ctx
;
2477 tmp_ctx
= talloc_stackframe();
2478 if (tmp_ctx
== NULL
) {
2482 path
= winreg_printer_data_keyname(tmp_ctx
, sharename
);
2484 talloc_free(tmp_ctx
);
2489 * The old owner and group sids of the security descriptor are not
2490 * present when new ACEs are added or removed by changing printer
2491 * permissions through NT. If they are NULL in the new security
2492 * descriptor then copy them over from the old one.
2494 if (!secdesc
->owner_sid
|| !secdesc
->group_sid
) {
2495 struct dom_sid
*owner_sid
, *group_sid
;
2496 struct security_acl
*dacl
, *sacl
;
2499 result
= winreg_get_printer_secdesc(tmp_ctx
,
2504 if (!W_ERROR_IS_OK(result
)) {
2505 talloc_free(tmp_ctx
);
2509 /* Pick out correct owner and group sids */
2510 owner_sid
= secdesc
->owner_sid
?
2511 secdesc
->owner_sid
:
2512 old_secdesc
->owner_sid
;
2514 group_sid
= secdesc
->group_sid
?
2515 secdesc
->group_sid
:
2516 old_secdesc
->group_sid
;
2518 dacl
= secdesc
->dacl
?
2522 sacl
= secdesc
->sacl
?
2526 /* Make a deep copy of the security descriptor */
2527 new_secdesc
= make_sec_desc(tmp_ctx
,
2535 if (new_secdesc
== NULL
) {
2536 talloc_free(tmp_ctx
);
2541 ZERO_STRUCT(hive_hnd
);
2542 ZERO_STRUCT(key_hnd
);
2544 result
= winreg_printer_openkey(tmp_ctx
,
2554 if (!W_ERROR_IS_OK(result
)) {
2558 ndr_err
= ndr_push_struct_blob(&blob
, tmp_ctx
, new_secdesc
,
2559 (ndr_push_flags_fn_t
) ndr_push_security_descriptor
);
2560 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2561 DEBUG(0, ("winreg_set_secdesc: Failed to marshall security descriptor\n"));
2562 result
= WERR_NOMEM
;
2566 result
= winreg_printer_write_binary(tmp_ctx
,
2573 if (winreg_handle
!= NULL
) {
2576 if (is_valid_policy_hnd(&key_hnd
)) {
2577 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2579 if (is_valid_policy_hnd(&hive_hnd
)) {
2580 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2584 talloc_free(tmp_ctx
);
2588 /* Set printer data over the winreg pipe. */
2589 WERROR
winreg_set_printer_dataex(TALLOC_CTX
*mem_ctx
,
2590 const struct auth_serversupplied_info
*server_info
,
2591 struct messaging_context
*msg_ctx
,
2592 const char *printer
,
2595 enum winreg_Type type
,
2599 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2600 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
2601 struct policy_handle hive_hnd
, key_hnd
;
2602 struct winreg_String wvalue
;
2604 WERROR result
= WERR_OK
;
2606 TALLOC_CTX
*tmp_ctx
;
2608 tmp_ctx
= talloc_stackframe();
2609 if (tmp_ctx
== NULL
) {
2613 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2615 TALLOC_FREE(tmp_ctx
);
2619 ZERO_STRUCT(hive_hnd
);
2620 ZERO_STRUCT(key_hnd
);
2622 DEBUG(8, ("winreg_set_printer_dataex: Open printer key %s, value %s, access_mask: 0x%05x for [%s]\n",
2623 key
, value
, access_mask
, printer
));
2624 result
= winreg_printer_openkey(tmp_ctx
,
2634 if (!W_ERROR_IS_OK(result
)) {
2635 DEBUG(0, ("winreg_set_printer_dataex: Could not open key %s: %s\n",
2636 key
, win_errstr(result
)));
2640 wvalue
.name
= value
;
2641 status
= dcerpc_winreg_SetValue(winreg_handle
,
2649 if (!NT_STATUS_IS_OK(status
)) {
2650 DEBUG(0, ("winreg_set_printer_dataex: Could not set value %s: %s\n",
2651 value
, nt_errstr(status
)));
2652 result
= ntstatus_to_werror(status
);
2656 if (winreg_handle
!= NULL
) {
2659 if (is_valid_policy_hnd(&key_hnd
)) {
2660 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2662 if (is_valid_policy_hnd(&hive_hnd
)) {
2663 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2667 TALLOC_FREE(tmp_ctx
);
2671 /* Get printer data over a winreg pipe. */
2672 WERROR
winreg_get_printer_dataex(TALLOC_CTX
*mem_ctx
,
2673 const struct auth_serversupplied_info
*server_info
,
2674 struct messaging_context
*msg_ctx
,
2675 const char *printer
,
2678 enum winreg_Type
*type
,
2680 uint32_t *data_size
)
2682 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2683 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
2684 struct policy_handle hive_hnd
, key_hnd
;
2685 struct winreg_String wvalue
;
2686 enum winreg_Type type_in
;
2689 uint32_t data_in_size
= 0;
2690 uint32_t value_len
= 0;
2691 WERROR result
= WERR_OK
;
2693 TALLOC_CTX
*tmp_ctx
;
2695 tmp_ctx
= talloc_stackframe();
2696 if (tmp_ctx
== NULL
) {
2700 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2702 TALLOC_FREE(tmp_ctx
);
2706 ZERO_STRUCT(hive_hnd
);
2707 ZERO_STRUCT(key_hnd
);
2709 result
= winreg_printer_openkey(tmp_ctx
,
2719 if (!W_ERROR_IS_OK(result
)) {
2720 DEBUG(2, ("winreg_get_printer_dataex: Could not open key %s: %s\n",
2721 key
, win_errstr(result
)));
2725 wvalue
.name
= value
;
2728 * call QueryValue once with data == NULL to get the
2729 * needed memory size to be allocated, then allocate
2730 * data buffer and call again.
2732 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2741 if (!NT_STATUS_IS_OK(status
)) {
2742 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2743 value
, nt_errstr(status
)));
2744 result
= ntstatus_to_werror(status
);
2747 if (!W_ERROR_IS_OK(result
)) {
2751 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
2752 if (data_in
== NULL
) {
2753 result
= WERR_NOMEM
;
2758 status
= dcerpc_winreg_QueryValue(winreg_handle
,
2767 if (!NT_STATUS_IS_OK(status
)) {
2768 DEBUG(0, ("winreg_get_printer_dataex: Could not query value %s: %s\n",
2769 value
, nt_errstr(status
)));
2770 result
= ntstatus_to_werror(status
);
2773 if (!W_ERROR_IS_OK(result
)) {
2778 *data_size
= data_in_size
;
2780 *data
= talloc_move(mem_ctx
, &data_in
);
2785 if (winreg_handle
!= NULL
) {
2788 if (is_valid_policy_hnd(&key_hnd
)) {
2789 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2791 if (is_valid_policy_hnd(&hive_hnd
)) {
2792 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2796 TALLOC_FREE(tmp_ctx
);
2800 /* Enumerate on the values of a given key and provide the data. */
2801 WERROR
winreg_enum_printer_dataex(TALLOC_CTX
*mem_ctx
,
2802 const struct auth_serversupplied_info
*server_info
,
2803 struct messaging_context
*msg_ctx
,
2804 const char *printer
,
2806 uint32_t *pnum_values
,
2807 struct spoolss_PrinterEnumValues
**penum_values
)
2809 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2810 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
2811 struct policy_handle hive_hnd
, key_hnd
;
2813 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
2814 uint32_t num_values
= 0;
2816 WERROR result
= WERR_OK
;
2818 TALLOC_CTX
*tmp_ctx
;
2820 tmp_ctx
= talloc_stackframe();
2821 if (tmp_ctx
== NULL
) {
2825 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2827 TALLOC_FREE(tmp_ctx
);
2831 result
= winreg_printer_openkey(tmp_ctx
,
2841 if (!W_ERROR_IS_OK(result
)) {
2842 DEBUG(2, ("winreg_enum_printer_dataex: Could not open key %s: %s\n",
2843 key
, win_errstr(result
)));
2847 result
= winreg_printer_enumvalues(tmp_ctx
,
2852 if (!W_ERROR_IS_OK(result
)) {
2853 DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
2854 key
, win_errstr(result
)));
2858 *pnum_values
= num_values
;
2860 *penum_values
= talloc_move(mem_ctx
, &enum_values
);
2865 if (winreg_handle
!= NULL
) {
2868 if (is_valid_policy_hnd(&key_hnd
)) {
2869 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2871 if (is_valid_policy_hnd(&hive_hnd
)) {
2872 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2876 TALLOC_FREE(tmp_ctx
);
2880 /* Delete printer data over a winreg pipe. */
2881 WERROR
winreg_delete_printer_dataex(TALLOC_CTX
*mem_ctx
,
2882 const struct auth_serversupplied_info
*server_info
,
2883 struct messaging_context
*msg_ctx
,
2884 const char *printer
,
2888 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2889 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
2890 struct policy_handle hive_hnd
, key_hnd
;
2891 struct winreg_String wvalue
;
2893 WERROR result
= WERR_OK
;
2896 TALLOC_CTX
*tmp_ctx
;
2898 tmp_ctx
= talloc_stackframe();
2899 if (tmp_ctx
== NULL
) {
2903 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2905 TALLOC_FREE(tmp_ctx
);
2909 ZERO_STRUCT(hive_hnd
);
2910 ZERO_STRUCT(key_hnd
);
2912 result
= winreg_printer_openkey(tmp_ctx
,
2922 if (!W_ERROR_IS_OK(result
)) {
2923 DEBUG(0, ("winreg_delete_printer_dataex: Could not open key %s: %s\n",
2924 key
, win_errstr(result
)));
2928 wvalue
.name
= value
;
2929 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
2934 if (!NT_STATUS_IS_OK(status
)) {
2935 DEBUG(0, ("winreg_delete_printer_dataex: Could not delete value %s: %s\n",
2936 value
, nt_errstr(status
)));
2937 result
= ntstatus_to_werror(status
);
2941 if (winreg_handle
!= NULL
) {
2944 if (is_valid_policy_hnd(&key_hnd
)) {
2945 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
2947 if (is_valid_policy_hnd(&hive_hnd
)) {
2948 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
2952 TALLOC_FREE(tmp_ctx
);
2956 /* Enumerate on the subkeys of a given key and provide the data. */
2957 WERROR
winreg_enum_printer_key(TALLOC_CTX
*mem_ctx
,
2958 const struct auth_serversupplied_info
*server_info
,
2959 struct messaging_context
*msg_ctx
,
2960 const char *printer
,
2962 uint32_t *pnum_subkeys
,
2963 const char ***psubkeys
)
2965 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2966 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
2967 struct policy_handle hive_hnd
, key_hnd
;
2969 const char **subkeys
= NULL
;
2970 uint32_t num_subkeys
= -1;
2972 WERROR result
= WERR_OK
;
2974 TALLOC_CTX
*tmp_ctx
;
2976 tmp_ctx
= talloc_stackframe();
2977 if (tmp_ctx
== NULL
) {
2981 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
2983 TALLOC_FREE(tmp_ctx
);
2987 ZERO_STRUCT(hive_hnd
);
2988 ZERO_STRUCT(key_hnd
);
2990 result
= winreg_printer_openkey(tmp_ctx
,
3000 if (!W_ERROR_IS_OK(result
)) {
3001 DEBUG(2, ("winreg_enum_printer_key: Could not open key %s: %s\n",
3002 key
, win_errstr(result
)));
3006 result
= winreg_printer_enumkeys(tmp_ctx
,
3011 if (!W_ERROR_IS_OK(result
)) {
3012 DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
3013 key
, win_errstr(result
)));
3017 *pnum_subkeys
= num_subkeys
;
3019 *psubkeys
= talloc_move(mem_ctx
, &subkeys
);
3024 if (winreg_handle
!= NULL
) {
3027 if (is_valid_policy_hnd(&key_hnd
)) {
3028 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3030 if (is_valid_policy_hnd(&hive_hnd
)) {
3031 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3035 TALLOC_FREE(tmp_ctx
);
3039 /* Delete a key with subkeys of a given printer. */
3040 WERROR
winreg_delete_printer_key(TALLOC_CTX
*mem_ctx
,
3041 const struct auth_serversupplied_info
*server_info
,
3042 struct messaging_context
*msg_ctx
,
3043 const char *printer
,
3046 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3047 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
3048 struct policy_handle hive_hnd
, key_hnd
;
3052 TALLOC_CTX
*tmp_ctx
;
3054 tmp_ctx
= talloc_stackframe();
3055 if (tmp_ctx
== NULL
) {
3059 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
3061 TALLOC_FREE(tmp_ctx
);
3065 result
= winreg_printer_openkey(tmp_ctx
,
3075 if (!W_ERROR_IS_OK(result
)) {
3076 /* key doesn't exist */
3077 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3082 DEBUG(0, ("winreg_delete_printer_key: Could not open key %s: %s\n",
3083 key
, win_errstr(result
)));
3087 if (is_valid_policy_hnd(&key_hnd
)) {
3088 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
3091 if (key
== NULL
|| key
[0] == '\0') {
3094 keyname
= talloc_asprintf(tmp_ctx
,
3098 if (keyname
== NULL
) {
3099 result
= WERR_NOMEM
;
3104 result
= winreg_printer_delete_subkeys(tmp_ctx
,
3109 if (!W_ERROR_IS_OK(result
)) {
3110 DEBUG(0, ("winreg_delete_printer_key: Could not delete key %s: %s\n",
3111 key
, win_errstr(result
)));
3116 if (winreg_handle
!= NULL
) {
3119 if (is_valid_policy_hnd(&key_hnd
)) {
3120 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3122 if (is_valid_policy_hnd(&hive_hnd
)) {
3123 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3127 TALLOC_FREE(tmp_ctx
);
3131 WERROR
winreg_printer_update_changeid(TALLOC_CTX
*mem_ctx
,
3132 const struct auth_serversupplied_info
*server_info
,
3133 struct messaging_context
*msg_ctx
,
3134 const char *printer
)
3136 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3137 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
3138 struct policy_handle hive_hnd
, key_hnd
;
3141 TALLOC_CTX
*tmp_ctx
;
3143 tmp_ctx
= talloc_stackframe();
3144 if (tmp_ctx
== NULL
) {
3148 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
3150 TALLOC_FREE(tmp_ctx
);
3154 ZERO_STRUCT(hive_hnd
);
3155 ZERO_STRUCT(key_hnd
);
3157 result
= winreg_printer_openkey(tmp_ctx
,
3167 if (!W_ERROR_IS_OK(result
)) {
3168 DEBUG(0, ("winreg_printer_update_changeid: Could not open key %s: %s\n",
3169 path
, win_errstr(result
)));
3173 result
= winreg_printer_write_dword(tmp_ctx
,
3177 winreg_printer_rev_changeid());
3178 if (!W_ERROR_IS_OK(result
)) {
3184 if (winreg_handle
!= NULL
) {
3187 if (is_valid_policy_hnd(&key_hnd
)) {
3188 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3190 if (is_valid_policy_hnd(&hive_hnd
)) {
3191 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3195 TALLOC_FREE(tmp_ctx
);
3199 WERROR
winreg_printer_get_changeid(TALLOC_CTX
*mem_ctx
,
3200 const struct auth_serversupplied_info
*server_info
,
3201 struct messaging_context
*msg_ctx
,
3202 const char *printer
,
3203 uint32_t *pchangeid
)
3205 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3206 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
3207 struct policy_handle hive_hnd
, key_hnd
;
3208 uint32_t changeid
= 0;
3211 TALLOC_CTX
*tmp_ctx
;
3213 tmp_ctx
= talloc_stackframe();
3214 if (tmp_ctx
== NULL
) {
3218 path
= winreg_printer_data_keyname(tmp_ctx
, printer
);
3220 TALLOC_FREE(tmp_ctx
);
3224 ZERO_STRUCT(hive_hnd
);
3225 ZERO_STRUCT(key_hnd
);
3227 result
= winreg_printer_openkey(tmp_ctx
,
3237 if (!W_ERROR_IS_OK(result
)) {
3238 DEBUG(2, ("winreg_printer_get_changeid: Could not open key %s: %s\n",
3239 path
, win_errstr(result
)));
3243 DEBUG(10, ("winreg_printer_get_changeid: get changeid from %s\n", path
));
3245 result
= winreg_printer_query_dword(tmp_ctx
,
3250 if (!W_ERROR_IS_OK(result
)) {
3255 *pchangeid
= changeid
;
3260 if (winreg_handle
!= NULL
) {
3263 if (is_valid_policy_hnd(&key_hnd
)) {
3264 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3266 if (is_valid_policy_hnd(&hive_hnd
)) {
3267 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3271 TALLOC_FREE(tmp_ctx
);
3276 * The special behaviour of the spoolss forms is documented at the website:
3278 * Managing Win32 Printserver Forms
3279 * http://unixwiz.net/techtips/winspooler-forms.html
3282 WERROR
winreg_printer_addform1(TALLOC_CTX
*mem_ctx
,
3283 const struct auth_serversupplied_info
*server_info
,
3284 struct messaging_context
*msg_ctx
,
3285 struct spoolss_AddFormInfo1
*form
)
3287 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3288 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
3289 struct policy_handle hive_hnd
, key_hnd
;
3290 struct winreg_String wvalue
;
3292 uint32_t num_info
= 0;
3293 union spoolss_FormInfo
*info
= NULL
;
3297 TALLOC_CTX
*tmp_ctx
;
3299 tmp_ctx
= talloc_stackframe();
3300 if (tmp_ctx
== NULL
) {
3304 ZERO_STRUCT(hive_hnd
);
3305 ZERO_STRUCT(key_hnd
);
3307 result
= winreg_printer_openkey(tmp_ctx
,
3311 TOP_LEVEL_CONTROL_FORMS_KEY
,
3317 if (!W_ERROR_IS_OK(result
)) {
3318 DEBUG(0, ("winreg_printer_addform1: Could not open key %s: %s\n",
3319 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3323 result
= winreg_printer_enumforms1(tmp_ctx
, server_info
, msg_ctx
,
3325 if (!W_ERROR_IS_OK(result
)) {
3326 DEBUG(0, ("winreg_printer_addform: Could not enum keys %s: %s\n",
3327 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3331 /* If form name already exists or is builtin return ALREADY_EXISTS */
3332 for (i
= 0; i
< num_info
; i
++) {
3333 if (strequal(info
[i
].info1
.form_name
, form
->form_name
)) {
3334 result
= WERR_FILE_EXISTS
;
3339 wvalue
.name
= form
->form_name
;
3341 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
3342 SIVAL(blob
.data
, 0, form
->size
.width
);
3343 SIVAL(blob
.data
, 4, form
->size
.height
);
3344 SIVAL(blob
.data
, 8, form
->area
.left
);
3345 SIVAL(blob
.data
, 12, form
->area
.top
);
3346 SIVAL(blob
.data
, 16, form
->area
.right
);
3347 SIVAL(blob
.data
, 20, form
->area
.bottom
);
3348 SIVAL(blob
.data
, 24, num_info
+ 1); /* FIXME */
3349 SIVAL(blob
.data
, 28, form
->flags
);
3351 status
= dcerpc_winreg_SetValue(winreg_handle
,
3359 if (!NT_STATUS_IS_OK(status
)) {
3360 DEBUG(0, ("winreg_printer_addform1: Could not set value %s: %s\n",
3361 wvalue
.name
, nt_errstr(status
)));
3362 result
= ntstatus_to_werror(status
);
3366 if (winreg_handle
!= NULL
) {
3369 if (is_valid_policy_hnd(&key_hnd
)) {
3370 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3372 if (is_valid_policy_hnd(&hive_hnd
)) {
3373 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3378 TALLOC_FREE(tmp_ctx
);
3382 WERROR
winreg_printer_enumforms1(TALLOC_CTX
*mem_ctx
,
3383 const struct auth_serversupplied_info
*server_info
,
3384 struct messaging_context
*msg_ctx
,
3385 uint32_t *pnum_info
,
3386 union spoolss_FormInfo
**pinfo
)
3388 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3389 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
3390 struct policy_handle hive_hnd
, key_hnd
;
3391 union spoolss_FormInfo
*info
;
3392 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
3393 uint32_t num_values
= 0;
3394 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3397 TALLOC_CTX
*tmp_ctx
;
3399 tmp_ctx
= talloc_stackframe();
3400 if (tmp_ctx
== NULL
) {
3404 ZERO_STRUCT(hive_hnd
);
3405 ZERO_STRUCT(key_hnd
);
3407 result
= winreg_printer_openkey(tmp_ctx
,
3411 TOP_LEVEL_CONTROL_FORMS_KEY
,
3417 if (!W_ERROR_IS_OK(result
)) {
3418 /* key doesn't exist */
3419 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3424 DEBUG(0, ("winreg_printer_enumforms1: Could not open key %s: %s\n",
3425 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3429 result
= winreg_printer_enumvalues(tmp_ctx
,
3434 if (!W_ERROR_IS_OK(result
)) {
3435 DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
3436 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3440 info
= TALLOC_ARRAY(tmp_ctx
, union spoolss_FormInfo
, num_builtin
+ num_values
);
3442 result
= WERR_NOMEM
;
3446 /* Enumerate BUILTIN forms */
3447 for (i
= 0; i
< num_builtin
; i
++) {
3448 info
[i
].info1
= builtin_forms1
[i
];
3451 /* Enumerate registry forms */
3452 for (i
= 0; i
< num_values
; i
++) {
3453 union spoolss_FormInfo val
;
3455 if (enum_values
[i
].type
!= REG_BINARY
||
3456 enum_values
[i
].data_length
!= 32) {
3460 val
.info1
.form_name
= talloc_strdup(info
, enum_values
[i
].value_name
);
3461 if (val
.info1
.form_name
== NULL
) {
3462 result
= WERR_NOMEM
;
3466 val
.info1
.size
.width
= IVAL(enum_values
[i
].data
->data
, 0);
3467 val
.info1
.size
.height
= IVAL(enum_values
[i
].data
->data
, 4);
3468 val
.info1
.area
.left
= IVAL(enum_values
[i
].data
->data
, 8);
3469 val
.info1
.area
.top
= IVAL(enum_values
[i
].data
->data
, 12);
3470 val
.info1
.area
.right
= IVAL(enum_values
[i
].data
->data
, 16);
3471 val
.info1
.area
.bottom
= IVAL(enum_values
[i
].data
->data
, 20);
3472 /* skip form index IVAL(enum_values[i].data->data, 24)));*/
3473 val
.info1
.flags
= (enum spoolss_FormFlags
) IVAL(enum_values
[i
].data
->data
, 28);
3475 info
[i
+ num_builtin
] = val
;
3478 *pnum_info
= num_builtin
+ num_values
;
3480 *pinfo
= talloc_move(mem_ctx
, &info
);
3484 if (winreg_handle
!= NULL
) {
3487 if (is_valid_policy_hnd(&key_hnd
)) {
3488 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3490 if (is_valid_policy_hnd(&hive_hnd
)) {
3491 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3495 TALLOC_FREE(enum_values
);
3496 TALLOC_FREE(tmp_ctx
);
3500 WERROR
winreg_printer_deleteform1(TALLOC_CTX
*mem_ctx
,
3501 const struct auth_serversupplied_info
*server_info
,
3502 struct messaging_context
*msg_ctx
,
3503 const char *form_name
)
3505 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3506 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
3507 struct policy_handle hive_hnd
, key_hnd
;
3508 struct winreg_String wvalue
;
3509 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3511 WERROR result
= WERR_OK
;
3513 TALLOC_CTX
*tmp_ctx
;
3515 for (i
= 0; i
< num_builtin
; i
++) {
3516 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3517 return WERR_INVALID_PARAMETER
;
3521 tmp_ctx
= talloc_stackframe();
3522 if (tmp_ctx
== NULL
) {
3526 ZERO_STRUCT(hive_hnd
);
3527 ZERO_STRUCT(key_hnd
);
3529 result
= winreg_printer_openkey(tmp_ctx
,
3533 TOP_LEVEL_CONTROL_FORMS_KEY
,
3539 if (!W_ERROR_IS_OK(result
)) {
3540 DEBUG(0, ("winreg_printer_deleteform1: Could not open key %s: %s\n",
3541 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3542 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3543 result
= WERR_INVALID_FORM_NAME
;
3548 wvalue
.name
= form_name
;
3549 status
= dcerpc_winreg_DeleteValue(winreg_handle
,
3554 if (!NT_STATUS_IS_OK(status
)) {
3555 /* If the value doesn't exist, return WERR_INVALID_FORM_NAME */
3556 DEBUG(0, ("winreg_printer_delteform1: Could not delete value %s: %s\n",
3557 wvalue
.name
, nt_errstr(status
)));
3558 result
= ntstatus_to_werror(status
);
3562 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
3563 result
= WERR_INVALID_FORM_NAME
;
3567 if (winreg_handle
!= NULL
) {
3570 if (is_valid_policy_hnd(&key_hnd
)) {
3571 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3573 if (is_valid_policy_hnd(&hive_hnd
)) {
3574 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3578 TALLOC_FREE(tmp_ctx
);
3582 WERROR
winreg_printer_setform1(TALLOC_CTX
*mem_ctx
,
3583 const struct auth_serversupplied_info
*server_info
,
3584 struct messaging_context
*msg_ctx
,
3585 const char *form_name
,
3586 struct spoolss_AddFormInfo1
*form
)
3588 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3589 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
3590 struct policy_handle hive_hnd
, key_hnd
;
3591 struct winreg_String wvalue
;
3593 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3597 TALLOC_CTX
*tmp_ctx
= NULL
;
3599 for (i
= 0; i
< num_builtin
; i
++) {
3600 if (strequal(builtin_forms1
[i
].form_name
, form
->form_name
)) {
3601 result
= WERR_INVALID_PARAM
;
3606 tmp_ctx
= talloc_stackframe();
3607 if (tmp_ctx
== NULL
) {
3611 ZERO_STRUCT(hive_hnd
);
3612 ZERO_STRUCT(key_hnd
);
3614 result
= winreg_printer_openkey(tmp_ctx
,
3618 TOP_LEVEL_CONTROL_FORMS_KEY
,
3624 if (!W_ERROR_IS_OK(result
)) {
3625 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3626 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3630 /* If form_name != form->form_name then we renamed the form */
3631 if (strequal(form_name
, form
->form_name
)) {
3632 result
= winreg_printer_deleteform1(tmp_ctx
, server_info
,
3633 msg_ctx
, form_name
);
3634 if (!W_ERROR_IS_OK(result
)) {
3635 DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
3636 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3641 wvalue
.name
= form
->form_name
;
3643 blob
= data_blob_talloc(tmp_ctx
, NULL
, 32);
3644 SIVAL(blob
.data
, 0, form
->size
.width
);
3645 SIVAL(blob
.data
, 4, form
->size
.height
);
3646 SIVAL(blob
.data
, 8, form
->area
.left
);
3647 SIVAL(blob
.data
, 12, form
->area
.top
);
3648 SIVAL(blob
.data
, 16, form
->area
.right
);
3649 SIVAL(blob
.data
, 20, form
->area
.bottom
);
3650 SIVAL(blob
.data
, 24, 42);
3651 SIVAL(blob
.data
, 28, form
->flags
);
3653 status
= dcerpc_winreg_SetValue(winreg_handle
,
3661 if (!NT_STATUS_IS_OK(status
)) {
3662 DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
3663 wvalue
.name
, nt_errstr(status
)));
3664 result
= ntstatus_to_werror(status
);
3668 if (winreg_handle
!= NULL
) {
3671 if (is_valid_policy_hnd(&key_hnd
)) {
3672 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3674 if (is_valid_policy_hnd(&hive_hnd
)) {
3675 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3679 TALLOC_FREE(tmp_ctx
);
3683 WERROR
winreg_printer_getform1(TALLOC_CTX
*mem_ctx
,
3684 const struct auth_serversupplied_info
*server_info
,
3685 struct messaging_context
*msg_ctx
,
3686 const char *form_name
,
3687 struct spoolss_FormInfo1
*r
)
3689 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3690 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
3691 struct policy_handle hive_hnd
, key_hnd
;
3692 struct winreg_String wvalue
;
3693 enum winreg_Type type_in
;
3695 uint32_t data_in_size
= 0;
3696 uint32_t value_len
= 0;
3697 uint32_t num_builtin
= ARRAY_SIZE(builtin_forms1
);
3701 TALLOC_CTX
*tmp_ctx
;
3703 /* check builtin forms first */
3704 for (i
= 0; i
< num_builtin
; i
++) {
3705 if (strequal(builtin_forms1
[i
].form_name
, form_name
)) {
3706 *r
= builtin_forms1
[i
];
3711 tmp_ctx
= talloc_stackframe();
3712 if (tmp_ctx
== NULL
) {
3716 ZERO_STRUCT(hive_hnd
);
3717 ZERO_STRUCT(key_hnd
);
3719 result
= winreg_printer_openkey(tmp_ctx
,
3723 TOP_LEVEL_CONTROL_FORMS_KEY
,
3729 if (!W_ERROR_IS_OK(result
)) {
3730 DEBUG(2, ("winreg_printer_getform1: Could not open key %s: %s\n",
3731 TOP_LEVEL_CONTROL_FORMS_KEY
, win_errstr(result
)));
3735 wvalue
.name
= form_name
;
3738 * call QueryValue once with data == NULL to get the
3739 * needed memory size to be allocated, then allocate
3740 * data buffer and call again.
3742 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3751 if (!NT_STATUS_IS_OK(status
)) {
3752 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3753 wvalue
.name
, nt_errstr(status
)));
3754 result
= ntstatus_to_werror(status
);
3757 if (!W_ERROR_IS_OK(result
)) {
3761 data_in
= (uint8_t *) TALLOC(tmp_ctx
, data_in_size
);
3762 if (data_in
== NULL
) {
3763 result
= WERR_NOMEM
;
3768 status
= dcerpc_winreg_QueryValue(winreg_handle
,
3777 if (!NT_STATUS_IS_OK(status
)) {
3778 DEBUG(0, ("winreg_printer_getform1: Could not query value %s: %s\n",
3779 wvalue
.name
, nt_errstr(status
)));
3780 result
= ntstatus_to_werror(status
);
3783 if (!W_ERROR_IS_OK(result
)) {
3787 r
->form_name
= talloc_strdup(mem_ctx
, form_name
);
3788 if (r
->form_name
== NULL
) {
3789 result
= WERR_NOMEM
;
3793 r
->size
.width
= IVAL(data_in
, 0);
3794 r
->size
.height
= IVAL(data_in
, 4);
3795 r
->area
.left
= IVAL(data_in
, 8);
3796 r
->area
.top
= IVAL(data_in
, 12);
3797 r
->area
.right
= IVAL(data_in
, 16);
3798 r
->area
.bottom
= IVAL(data_in
, 20);
3799 /* skip index IVAL(data_in, 24)));*/
3800 r
->flags
= (enum spoolss_FormFlags
) IVAL(data_in
, 28);
3804 if (winreg_handle
!= NULL
) {
3807 if (is_valid_policy_hnd(&key_hnd
)) {
3808 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
3810 if (is_valid_policy_hnd(&hive_hnd
)) {
3811 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
3815 TALLOC_FREE(tmp_ctx
);
3819 WERROR
winreg_add_driver(TALLOC_CTX
*mem_ctx
,
3820 const struct auth_serversupplied_info
*server_info
,
3821 struct messaging_context
*msg_ctx
,
3822 struct spoolss_AddDriverInfoCtr
*r
,
3823 const char **driver_name
,
3824 uint32_t *driver_version
)
3826 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
3827 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
3828 struct policy_handle hive_hnd
, key_hnd
;
3829 struct spoolss_DriverInfo8 info8
;
3830 TALLOC_CTX
*tmp_ctx
= NULL
;
3833 ZERO_STRUCT(hive_hnd
);
3834 ZERO_STRUCT(key_hnd
);
3837 if (!driver_info_ctr_to_info8(r
, &info8
)) {
3838 result
= WERR_INVALID_PARAMETER
;
3842 tmp_ctx
= talloc_stackframe();
3843 if (tmp_ctx
== NULL
) {
3847 result
= winreg_printer_opendriver(tmp_ctx
,
3857 if (!W_ERROR_IS_OK(result
)) {
3858 DEBUG(0, ("winreg_add_driver: "
3859 "Could not open driver key (%s,%s,%d): %s\n",
3860 info8
.driver_name
, info8
.architecture
,
3861 info8
.version
, win_errstr(result
)));
3865 /* TODO: "Attributes" ? */
3867 result
= winreg_printer_write_dword(tmp_ctx
, winreg_handle
,
3868 &key_hnd
, "Version",
3870 if (!W_ERROR_IS_OK(result
)) {
3874 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3877 if (!W_ERROR_IS_OK(result
)) {
3881 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3882 &key_hnd
, "Data File",
3884 if (!W_ERROR_IS_OK(result
)) {
3888 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3889 &key_hnd
, "Configuration File",
3891 if (!W_ERROR_IS_OK(result
)) {
3895 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3896 &key_hnd
, "Help File",
3898 if (!W_ERROR_IS_OK(result
)) {
3902 result
= winreg_printer_write_multi_sz(tmp_ctx
, winreg_handle
,
3903 &key_hnd
, "Dependent Files",
3904 info8
.dependent_files
);
3905 if (!W_ERROR_IS_OK(result
)) {
3909 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3910 &key_hnd
, "Monitor",
3911 info8
.monitor_name
);
3912 if (!W_ERROR_IS_OK(result
)) {
3916 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3917 &key_hnd
, "Datatype",
3918 info8
.default_datatype
);
3919 if (!W_ERROR_IS_OK(result
)) {
3923 result
= winreg_printer_write_multi_sz(tmp_ctx
, winreg_handle
,
3924 &key_hnd
, "Previous Names",
3925 info8
.previous_names
);
3926 if (!W_ERROR_IS_OK(result
)) {
3930 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
3931 &key_hnd
, "DriverDate",
3933 if (!W_ERROR_IS_OK(result
)) {
3937 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
,
3938 &key_hnd
, "DriverVersion",
3939 info8
.driver_version
);
3940 if (!W_ERROR_IS_OK(result
)) {
3944 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3945 &key_hnd
, "Manufacturer",
3946 info8
.manufacturer_name
);
3947 if (!W_ERROR_IS_OK(result
)) {
3951 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3952 &key_hnd
, "OEM URL",
3953 info8
.manufacturer_url
);
3954 if (!W_ERROR_IS_OK(result
)) {
3958 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3959 &key_hnd
, "HardwareID",
3961 if (!W_ERROR_IS_OK(result
)) {
3965 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3966 &key_hnd
, "Provider",
3968 if (!W_ERROR_IS_OK(result
)) {
3972 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3973 &key_hnd
, "Print Processor",
3974 info8
.print_processor
);
3975 if (!W_ERROR_IS_OK(result
)) {
3979 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3980 &key_hnd
, "VendorSetup",
3981 info8
.vendor_setup
);
3982 if (!W_ERROR_IS_OK(result
)) {
3986 result
= winreg_printer_write_multi_sz(tmp_ctx
, winreg_handle
,
3987 &key_hnd
, "Color Profiles",
3988 info8
.color_profiles
);
3989 if (!W_ERROR_IS_OK(result
)) {
3993 result
= winreg_printer_write_sz(tmp_ctx
, winreg_handle
,
3994 &key_hnd
, "InfPath",
3996 if (!W_ERROR_IS_OK(result
)) {
4000 result
= winreg_printer_write_dword(tmp_ctx
, winreg_handle
, &key_hnd
,
4001 "PrinterDriverAttributes",
4002 info8
.printer_driver_attributes
);
4003 if (!W_ERROR_IS_OK(result
)) {
4007 result
= winreg_printer_write_multi_sz(tmp_ctx
, winreg_handle
,
4008 &key_hnd
, "CoreDependencies",
4009 info8
.core_driver_dependencies
);
4010 if (!W_ERROR_IS_OK(result
)) {
4014 result
= winreg_printer_write_date(tmp_ctx
, winreg_handle
,
4015 &key_hnd
, "MinInboxDriverVerDate",
4016 info8
.min_inbox_driver_ver_date
);
4017 if (!W_ERROR_IS_OK(result
)) {
4021 result
= winreg_printer_write_ver(tmp_ctx
, winreg_handle
, &key_hnd
,
4022 "MinInboxDriverVerVersion",
4023 info8
.min_inbox_driver_ver_version
);
4024 if (!W_ERROR_IS_OK(result
)) {
4028 *driver_name
= info8
.driver_name
;
4029 *driver_version
= info8
.version
;
4032 if (winreg_handle
!= NULL
) {
4035 if (is_valid_policy_hnd(&key_hnd
)) {
4036 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4038 if (is_valid_policy_hnd(&hive_hnd
)) {
4039 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4043 TALLOC_FREE(tmp_ctx
);
4047 WERROR
winreg_get_driver(TALLOC_CTX
*mem_ctx
,
4048 const struct auth_serversupplied_info
*server_info
,
4049 struct messaging_context
*msg_ctx
,
4050 const char *architecture
,
4051 const char *driver_name
,
4052 uint32_t driver_version
,
4053 struct spoolss_DriverInfo8
**_info8
)
4055 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4056 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
4057 struct policy_handle hive_hnd
, key_hnd
;
4058 struct spoolss_DriverInfo8 i8
, *info8
;
4059 struct spoolss_PrinterEnumValues
*enum_values
= NULL
;
4060 struct spoolss_PrinterEnumValues
*v
;
4061 uint32_t num_values
= 0;
4062 TALLOC_CTX
*tmp_ctx
;
4066 ZERO_STRUCT(hive_hnd
);
4067 ZERO_STRUCT(key_hnd
);
4070 tmp_ctx
= talloc_stackframe();
4071 if (tmp_ctx
== NULL
) {
4075 if (driver_version
== DRIVER_ANY_VERSION
) {
4076 /* look for Win2k first and then for NT4 */
4077 result
= winreg_printer_opendriver(tmp_ctx
,
4087 if (!W_ERROR_IS_OK(result
)) {
4088 result
= winreg_printer_opendriver(tmp_ctx
,
4100 /* ok normal case */
4101 result
= winreg_printer_opendriver(tmp_ctx
,
4112 if (!W_ERROR_IS_OK(result
)) {
4113 DEBUG(5, ("winreg_get_driver: "
4114 "Could not open driver key (%s,%s,%d): %s\n",
4115 driver_name
, architecture
,
4116 driver_version
, win_errstr(result
)));
4120 result
= winreg_printer_enumvalues(tmp_ctx
,
4125 if (!W_ERROR_IS_OK(result
)) {
4126 DEBUG(0, ("winreg_get_driver: "
4127 "Could not enumerate values for (%s,%s,%d): %s\n",
4128 driver_name
, architecture
,
4129 driver_version
, win_errstr(result
)));
4133 info8
= talloc_zero(tmp_ctx
, struct spoolss_DriverInfo8
);
4134 if (info8
== NULL
) {
4135 result
= WERR_NOMEM
;
4139 info8
->driver_name
= talloc_strdup(info8
, driver_name
);
4140 if (info8
->driver_name
== NULL
) {
4141 result
= WERR_NOMEM
;
4145 info8
->architecture
= talloc_strdup(info8
, architecture
);
4146 if (info8
->architecture
== NULL
) {
4147 result
= WERR_NOMEM
;
4153 for (i
= 0; i
< num_values
; i
++) {
4154 const char *tmp_str
;
4157 v
= &enum_values
[i
];
4159 result
= winreg_enumval_to_dword(info8
, v
,
4162 if (NT_STATUS_IS_OK(result
)) {
4163 info8
->version
= (enum spoolss_DriverOSVersion
) tmp
;
4165 CHECK_ERROR(result
);
4167 result
= winreg_enumval_to_sz(info8
, v
,
4169 &info8
->driver_path
);
4170 CHECK_ERROR(result
);
4172 result
= winreg_enumval_to_sz(info8
, v
,
4175 CHECK_ERROR(result
);
4177 result
= winreg_enumval_to_sz(info8
, v
,
4178 "Configuration File",
4179 &info8
->config_file
);
4180 CHECK_ERROR(result
);
4182 result
= winreg_enumval_to_sz(info8
, v
,
4185 CHECK_ERROR(result
);
4187 result
= winreg_enumval_to_multi_sz(info8
, v
,
4189 &info8
->dependent_files
);
4190 CHECK_ERROR(result
);
4192 result
= winreg_enumval_to_sz(info8
, v
,
4194 &info8
->monitor_name
);
4195 CHECK_ERROR(result
);
4197 result
= winreg_enumval_to_sz(info8
, v
,
4199 &info8
->default_datatype
);
4200 CHECK_ERROR(result
);
4202 result
= winreg_enumval_to_multi_sz(info8
, v
,
4204 &info8
->previous_names
);
4205 CHECK_ERROR(result
);
4207 result
= winreg_enumval_to_sz(info8
, v
,
4210 if (W_ERROR_IS_OK(result
)) {
4211 result
= winreg_printer_date_to_NTTIME(tmp_str
,
4212 &info8
->driver_date
);
4214 CHECK_ERROR(result
);
4216 result
= winreg_enumval_to_sz(info8
, v
,
4219 if (W_ERROR_IS_OK(result
)) {
4220 result
= winreg_printer_ver_to_dword(tmp_str
,
4221 &info8
->driver_version
);
4223 CHECK_ERROR(result
);
4225 result
= winreg_enumval_to_sz(info8
, v
,
4227 &info8
->manufacturer_name
);
4228 CHECK_ERROR(result
);
4230 result
= winreg_enumval_to_sz(info8
, v
,
4232 &info8
->manufacturer_url
);
4233 CHECK_ERROR(result
);
4235 result
= winreg_enumval_to_sz(info8
, v
,
4237 &info8
->hardware_id
);
4238 CHECK_ERROR(result
);
4240 result
= winreg_enumval_to_sz(info8
, v
,
4243 CHECK_ERROR(result
);
4245 result
= winreg_enumval_to_sz(info8
, v
,
4247 &info8
->print_processor
);
4248 CHECK_ERROR(result
);
4250 result
= winreg_enumval_to_sz(info8
, v
,
4252 &info8
->vendor_setup
);
4253 CHECK_ERROR(result
);
4255 result
= winreg_enumval_to_multi_sz(info8
, v
,
4257 &info8
->color_profiles
);
4258 CHECK_ERROR(result
);
4260 result
= winreg_enumval_to_sz(info8
, v
,
4263 CHECK_ERROR(result
);
4265 result
= winreg_enumval_to_dword(info8
, v
,
4266 "PrinterDriverAttributes",
4267 &info8
->printer_driver_attributes
);
4268 CHECK_ERROR(result
);
4270 result
= winreg_enumval_to_multi_sz(info8
, v
,
4272 &info8
->core_driver_dependencies
);
4273 CHECK_ERROR(result
);
4275 result
= winreg_enumval_to_sz(info8
, v
,
4276 "MinInboxDriverVerDate",
4278 if (W_ERROR_IS_OK(result
)) {
4279 result
= winreg_printer_date_to_NTTIME(tmp_str
,
4280 &info8
->min_inbox_driver_ver_date
);
4282 CHECK_ERROR(result
);
4284 result
= winreg_enumval_to_sz(info8
, v
,
4285 "MinInboxDriverVerVersion",
4287 if (W_ERROR_IS_OK(result
)) {
4288 result
= winreg_printer_ver_to_dword(tmp_str
,
4289 &info8
->min_inbox_driver_ver_version
);
4291 CHECK_ERROR(result
);
4294 if (!W_ERROR_IS_OK(result
)) {
4295 DEBUG(0, ("winreg_enumval_to_TYPE() failed "
4296 "for %s: %s\n", v
->value_name
,
4297 win_errstr(result
)));
4301 *_info8
= talloc_steal(mem_ctx
, info8
);
4304 if (winreg_handle
!= NULL
) {
4307 if (is_valid_policy_hnd(&key_hnd
)) {
4308 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4310 if (is_valid_policy_hnd(&hive_hnd
)) {
4311 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4315 TALLOC_FREE(tmp_ctx
);
4319 WERROR
winreg_del_driver(TALLOC_CTX
*mem_ctx
,
4320 const struct auth_serversupplied_info
*server_info
,
4321 struct messaging_context
*msg_ctx
,
4322 struct spoolss_DriverInfo8
*info8
,
4325 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4326 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
4327 struct policy_handle hive_hnd
, key_hnd
;
4328 TALLOC_CTX
*tmp_ctx
;
4332 ZERO_STRUCT(hive_hnd
);
4333 ZERO_STRUCT(key_hnd
);
4335 tmp_ctx
= talloc_stackframe();
4336 if (tmp_ctx
== NULL
) {
4340 /* test that the key exists */
4341 result
= winreg_printer_opendriver(tmp_ctx
,
4345 info8
->architecture
,
4351 if (!W_ERROR_IS_OK(result
)) {
4352 /* key doesn't exist */
4353 if (W_ERROR_EQUAL(result
, WERR_BADFILE
)) {
4358 DEBUG(5, ("winreg_del_driver: "
4359 "Could not open driver (%s,%s,%u): %s\n",
4360 info8
->driver_name
, info8
->architecture
,
4361 version
, win_errstr(result
)));
4366 if (is_valid_policy_hnd(&key_hnd
)) {
4367 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &result
);
4370 key_name
= talloc_asprintf(tmp_ctx
,
4371 "%s\\Environments\\%s\\Drivers\\Version-%u",
4372 TOP_LEVEL_CONTROL_KEY
,
4373 info8
->architecture
, version
);
4374 if (key_name
== NULL
) {
4375 result
= WERR_NOMEM
;
4379 result
= winreg_printer_delete_subkeys(tmp_ctx
,
4384 if (!W_ERROR_IS_OK(result
)) {
4385 DEBUG(0, ("winreg_del_driver: "
4386 "Could not open driver (%s,%s,%u): %s\n",
4387 info8
->driver_name
, info8
->architecture
,
4388 version
, win_errstr(result
)));
4394 if (winreg_handle
!= NULL
) {
4397 if (is_valid_policy_hnd(&key_hnd
)) {
4398 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4400 if (is_valid_policy_hnd(&hive_hnd
)) {
4401 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4405 TALLOC_FREE(tmp_ctx
);
4409 WERROR
winreg_get_driver_list(TALLOC_CTX
*mem_ctx
,
4410 const struct auth_serversupplied_info
*server_info
,
4411 struct messaging_context
*msg_ctx
,
4412 const char *architecture
,
4414 uint32_t *num_drivers
,
4415 const char ***drivers_p
)
4417 uint32_t access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
4418 struct dcerpc_binding_handle
*winreg_handle
= NULL
;
4419 struct policy_handle hive_hnd
, key_hnd
;
4420 const char **drivers
;
4421 TALLOC_CTX
*tmp_ctx
;
4427 ZERO_STRUCT(hive_hnd
);
4428 ZERO_STRUCT(key_hnd
);
4430 tmp_ctx
= talloc_stackframe();
4431 if (tmp_ctx
== NULL
) {
4435 /* use NULL for the driver name so we open the key that is
4436 * parent of all drivers for this architecture and version */
4437 result
= winreg_printer_opendriver(tmp_ctx
,
4447 if (!W_ERROR_IS_OK(result
)) {
4448 DEBUG(5, ("winreg_get_driver_list: "
4449 "Could not open key (%s,%u): %s\n",
4450 architecture
, version
, win_errstr(result
)));
4455 result
= winreg_printer_enumkeys(tmp_ctx
,
4460 if (!W_ERROR_IS_OK(result
)) {
4461 DEBUG(0, ("winreg_get_driver_list: "
4462 "Could not enumerate drivers for (%s,%u): %s\n",
4463 architecture
, version
, win_errstr(result
)));
4467 *drivers_p
= talloc_steal(mem_ctx
, drivers
);
4471 if (winreg_handle
!= NULL
) {
4474 if (is_valid_policy_hnd(&key_hnd
)) {
4475 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &key_hnd
, &ignore
);
4477 if (is_valid_policy_hnd(&hive_hnd
)) {
4478 dcerpc_winreg_CloseKey(winreg_handle
, tmp_ctx
, &hive_hnd
, &ignore
);
4482 TALLOC_FREE(tmp_ctx
);