tevent: call epoll_panic() if EPOLL_CTL_DEL failed
[Samba/gebeck_regimport.git] / source3 / printing / nt_printing_migrate.c
blob94dc3daa568b3e5f50e295c974649b31c7bda60b
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
5 * Copyright (c) Andreas Schneider 2010.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "printing/nt_printing_migrate.h"
24 #include "rpc_client/rpc_client.h"
25 #include "librpc/gen_ndr/ndr_ntprinting.h"
26 #include "librpc/gen_ndr/ndr_spoolss_c.h"
27 #include "librpc/gen_ndr/ndr_security.h"
28 #include "rpc_client/cli_winreg_spoolss.h"
30 NTSTATUS printing_tdb_migrate_form(TALLOC_CTX *mem_ctx,
31 struct rpc_pipe_client *winreg_pipe,
32 const char *key_name,
33 unsigned char *data,
34 size_t length)
36 struct dcerpc_binding_handle *b = winreg_pipe->binding_handle;
37 enum ndr_err_code ndr_err;
38 struct ntprinting_form r;
39 struct spoolss_AddFormInfo1 f1;
40 DATA_BLOB blob;
41 WERROR result;
43 blob = data_blob_const(data, length);
45 ZERO_STRUCT(r);
47 ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r,
48 (ndr_pull_flags_fn_t)ndr_pull_ntprinting_form);
49 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
50 DEBUG(2, ("Form pull failed: %s\n",
51 ndr_errstr(ndr_err)));
52 return NT_STATUS_NO_MEMORY;
55 /* Don't migrate builtin forms */
56 if (r.flag == SPOOLSS_FORM_BUILTIN) {
57 return NT_STATUS_OK;
60 DEBUG(2, ("Migrating Form: %s\n", key_name));
62 f1.form_name = key_name;
63 f1.flags = r.flag;
65 f1.size.width = r.width;
66 f1.size.height = r.length;
68 f1.area.top = r.top;
69 f1.area.right = r.right;
70 f1.area.bottom = r.bottom;
71 f1.area.left = r.left;
73 result = winreg_printer_addform1(mem_ctx,
75 &f1);
76 if (W_ERROR_EQUAL(result, WERR_FILE_EXISTS)) {
77 /* Don't migrate form if it already exists. */
78 result = WERR_OK;
80 if (!W_ERROR_IS_OK(result)) {
81 return werror_to_ntstatus(result);
84 return NT_STATUS_OK;
87 NTSTATUS printing_tdb_migrate_driver(TALLOC_CTX *mem_ctx,
88 struct rpc_pipe_client *winreg_pipe,
89 const char *key_name,
90 unsigned char *data,
91 size_t length)
93 struct dcerpc_binding_handle *b = winreg_pipe->binding_handle;
94 enum ndr_err_code ndr_err;
95 struct ntprinting_driver r;
96 struct spoolss_AddDriverInfoCtr d;
97 struct spoolss_AddDriverInfo3 d3;
98 struct spoolss_StringArray a;
99 DATA_BLOB blob;
100 WERROR result;
101 const char *driver_name;
102 uint32_t driver_version;
104 blob = data_blob_const(data, length);
106 ZERO_STRUCT(r);
108 ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r,
109 (ndr_pull_flags_fn_t)ndr_pull_ntprinting_driver);
110 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
111 DEBUG(2, ("Driver pull failed: %s\n",
112 ndr_errstr(ndr_err)));
113 return NT_STATUS_NO_MEMORY;
116 DEBUG(2, ("Migrating Printer Driver: %s\n", key_name));
118 ZERO_STRUCT(d3);
119 ZERO_STRUCT(a);
121 a.string = r.dependent_files;
123 d3.architecture = r.environment;
124 d3.config_file = r.configfile;
125 d3.data_file = r.datafile;
126 d3.default_datatype = r.defaultdatatype;
127 d3.dependent_files = &a;
128 d3.driver_path = r.driverpath;
129 d3.help_file = r.helpfile;
130 d3.monitor_name = r.monitorname;
131 d3.driver_name = r.name;
132 d3.version = r.version;
134 d.level = 3;
135 d.info.info3 = &d3;
137 result = winreg_add_driver(mem_ctx,
140 &driver_name,
141 &driver_version);
142 if (!W_ERROR_IS_OK(result)) {
143 return werror_to_ntstatus(result);
146 return NT_STATUS_OK;
149 NTSTATUS printing_tdb_migrate_printer(TALLOC_CTX *mem_ctx,
150 struct rpc_pipe_client *winreg_pipe,
151 const char *key_name,
152 unsigned char *data,
153 size_t length)
155 struct dcerpc_binding_handle *b = winreg_pipe->binding_handle;
156 enum ndr_err_code ndr_err;
157 struct ntprinting_printer r;
158 struct spoolss_SetPrinterInfo2 info2;
159 struct spoolss_DeviceMode dm;
160 struct spoolss_DevmodeContainer devmode_ctr;
161 DATA_BLOB blob;
162 NTSTATUS status;
163 WERROR result;
164 int j;
165 uint32_t info2_mask = (SPOOLSS_PRINTER_INFO_ALL)
166 & ~SPOOLSS_PRINTER_INFO_SECDESC;
168 if (strequal(key_name, "printers")) {
169 return NT_STATUS_OK;
172 blob = data_blob_const(data, length);
174 ZERO_STRUCT(r);
176 ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r,
177 (ndr_pull_flags_fn_t) ndr_pull_ntprinting_printer);
178 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
179 DEBUG(2, ("printer pull failed: %s\n",
180 ndr_errstr(ndr_err)));
181 return NT_STATUS_NO_MEMORY;
184 DEBUG(2, ("Migrating Printer: %s\n", key_name));
186 ZERO_STRUCT(devmode_ctr);
188 /* Create printer info level 2 */
189 ZERO_STRUCT(info2);
191 info2.attributes = r.info.attributes;
192 info2.averageppm = r.info.averageppm;
193 info2.cjobs = r.info.cjobs;
194 info2.comment = r.info.comment;
195 info2.datatype = r.info.datatype;
196 info2.defaultpriority = r.info.default_priority;
197 info2.drivername = r.info.drivername;
198 info2.location = r.info.location;
199 info2.parameters = r.info.parameters;
200 info2.portname = r.info.portname;
201 info2.printername = r.info.printername;
202 info2.printprocessor = r.info.printprocessor;
203 info2.priority = r.info.priority;
204 info2.sepfile = r.info.sepfile;
205 info2.sharename = r.info.sharename;
206 info2.starttime = r.info.starttime;
207 info2.status = r.info.status;
208 info2.untiltime = r.info.untiltime;
210 /* Create Device Mode */
211 if (r.devmode == NULL) {
212 info2_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
213 } else {
214 ZERO_STRUCT(dm);
216 dm.bitsperpel = r.devmode->bitsperpel;
217 dm.collate = r.devmode->collate;
218 dm.color = r.devmode->color;
219 dm.copies = r.devmode->copies;
220 dm.defaultsource = r.devmode->defaultsource;
221 dm.devicename = r.devmode->devicename;
222 dm.displayflags = r.devmode->displayflags;
223 dm.displayfrequency = r.devmode->displayfrequency;
224 dm.dithertype = r.devmode->dithertype;
225 dm.driverversion = r.devmode->driverversion;
226 dm.duplex = r.devmode->duplex;
227 dm.fields = r.devmode->fields;
228 dm.formname = r.devmode->formname;
229 dm.icmintent = r.devmode->icmintent;
230 dm.icmmethod = r.devmode->icmmethod;
231 dm.logpixels = r.devmode->logpixels;
232 dm.mediatype = r.devmode->mediatype;
233 dm.orientation = r.devmode->orientation;
234 dm.panningheight = r.devmode->pelsheight;
235 dm.panningwidth = r.devmode->panningwidth;
236 dm.paperlength = r.devmode->paperlength;
237 dm.papersize = r.devmode->papersize;
238 dm.paperwidth = r.devmode->paperwidth;
239 dm.pelsheight = r.devmode->pelsheight;
240 dm.pelswidth = r.devmode->pelswidth;
241 dm.printquality = r.devmode->printquality;
242 dm.size = r.devmode->size;
243 dm.scale = r.devmode->scale;
244 dm.specversion = r.devmode->specversion;
245 dm.ttoption = r.devmode->ttoption;
246 dm.yresolution = r.devmode->yresolution;
248 if (r.devmode->nt_dev_private != NULL) {
249 dm.driverextra_data.data = r.devmode->nt_dev_private->data;
250 dm.driverextra_data.length = r.devmode->nt_dev_private->length;
251 dm.__driverextra_length = r.devmode->nt_dev_private->length;
254 devmode_ctr.devmode = &dm;
257 result = winreg_update_printer(mem_ctx, b,
258 key_name,
259 info2_mask,
260 &info2,
261 &dm,
262 NULL);
263 if (!W_ERROR_IS_OK(result)) {
264 DEBUG(2, ("SetPrinter(%s) level 2 refused -- %s.\n",
265 key_name, win_errstr(result)));
266 status = werror_to_ntstatus(result);
267 goto done;
270 /* migrate printerdata */
271 for (j = 0; j < r.count; j++) {
272 char *valuename;
273 const char *keyname;
275 if (r.printer_data[j].type == REG_NONE) {
276 continue;
279 keyname = r.printer_data[j].name;
280 valuename = strchr(keyname, '\\');
281 if (valuename == NULL) {
282 continue;
283 } else {
284 valuename[0] = '\0';
285 valuename++;
288 result = winreg_set_printer_dataex(mem_ctx, b,
289 key_name,
290 keyname,
291 valuename,
292 r.printer_data[j].type,
293 r.printer_data[j].data.data,
294 r.printer_data[j].data.length);
295 if (!W_ERROR_IS_OK(result)) {
296 DEBUG(2, ("SetPrinterDataEx: printer [%s], keyname [%s], "
297 "valuename [%s] refused -- %s.\n",
298 key_name, keyname, valuename,
299 win_errstr(result)));
300 status = werror_to_ntstatus(result);
301 break;
305 status = NT_STATUS_OK;
306 done:
308 return status;
311 NTSTATUS printing_tdb_migrate_secdesc(TALLOC_CTX *mem_ctx,
312 struct rpc_pipe_client *winreg_pipe,
313 const char *key_name,
314 unsigned char *data,
315 size_t length)
317 struct dcerpc_binding_handle *b = winreg_pipe->binding_handle;
318 enum ndr_err_code ndr_err;
319 struct sec_desc_buf secdesc_ctr;
320 DATA_BLOB blob;
321 WERROR result;
323 if (strequal(key_name, "printers")) {
324 return NT_STATUS_OK;
327 blob = data_blob_const(data, length);
329 ZERO_STRUCT(secdesc_ctr);
331 ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &secdesc_ctr,
332 (ndr_pull_flags_fn_t)ndr_pull_sec_desc_buf);
333 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
334 DEBUG(2, ("security descriptor pull failed: %s\n",
335 ndr_errstr(ndr_err)));
336 return NT_STATUS_NO_MEMORY;
339 DEBUG(2, ("Migrating Security Descriptor: %s\n", key_name));
341 result = winreg_set_printer_secdesc(mem_ctx, b,
342 key_name,
343 secdesc_ctr.sd);
344 if (!W_ERROR_IS_OK(result)) {
345 return werror_to_ntstatus(result);
348 return NT_STATUS_OK;