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/>.
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
*pipe_hnd
,
32 struct rpc_pipe_client
*winreg_pipe
,
37 struct dcerpc_binding_handle
*b
= winreg_pipe
->binding_handle
;
38 enum ndr_err_code ndr_err
;
39 struct ntprinting_form r
;
40 struct spoolss_AddFormInfo1 f1
;
44 blob
= data_blob_const(data
, length
);
48 ndr_err
= ndr_pull_struct_blob(&blob
, mem_ctx
, &r
,
49 (ndr_pull_flags_fn_t
)ndr_pull_ntprinting_form
);
50 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
51 DEBUG(2, ("Form pull failed: %s\n",
52 ndr_errstr(ndr_err
)));
53 return NT_STATUS_NO_MEMORY
;
56 /* Don't migrate builtin forms */
57 if (r
.flag
== SPOOLSS_FORM_BUILTIN
) {
61 DEBUG(2, ("Migrating Form: %s\n", key_name
));
63 f1
.form_name
= key_name
;
66 f1
.size
.width
= r
.width
;
67 f1
.size
.height
= r
.length
;
70 f1
.area
.right
= r
.right
;
71 f1
.area
.bottom
= r
.bottom
;
72 f1
.area
.left
= r
.left
;
74 result
= winreg_printer_addform1(mem_ctx
,
77 if (!W_ERROR_IS_OK(result
)) {
78 return werror_to_ntstatus(result
);
84 NTSTATUS
printing_tdb_migrate_driver(TALLOC_CTX
*mem_ctx
,
85 struct rpc_pipe_client
*pipe_hnd
,
86 struct rpc_pipe_client
*winreg_pipe
,
91 struct dcerpc_binding_handle
*b
= winreg_pipe
->binding_handle
;
92 enum ndr_err_code ndr_err
;
93 struct ntprinting_driver r
;
94 struct spoolss_AddDriverInfoCtr d
;
95 struct spoolss_AddDriverInfo3 d3
;
96 struct spoolss_StringArray a
;
99 const char *driver_name
;
100 uint32_t driver_version
;
102 blob
= data_blob_const(data
, length
);
106 ndr_err
= ndr_pull_struct_blob(&blob
, mem_ctx
, &r
,
107 (ndr_pull_flags_fn_t
)ndr_pull_ntprinting_driver
);
108 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
109 DEBUG(2, ("Driver pull failed: %s\n",
110 ndr_errstr(ndr_err
)));
111 return NT_STATUS_NO_MEMORY
;
114 DEBUG(2, ("Migrating Printer Driver: %s\n", key_name
));
119 a
.string
= r
.dependent_files
;
121 d3
.architecture
= r
.environment
;
122 d3
.config_file
= r
.configfile
;
123 d3
.data_file
= r
.datafile
;
124 d3
.default_datatype
= r
.defaultdatatype
;
125 d3
.dependent_files
= &a
;
126 d3
.driver_path
= r
.driverpath
;
127 d3
.help_file
= r
.helpfile
;
128 d3
.monitor_name
= r
.monitorname
;
129 d3
.driver_name
= r
.name
;
130 d3
.version
= r
.version
;
135 result
= winreg_add_driver(mem_ctx
,
140 if (!W_ERROR_IS_OK(result
)) {
141 return werror_to_ntstatus(result
);
147 NTSTATUS
printing_tdb_migrate_printer(TALLOC_CTX
*mem_ctx
,
148 struct rpc_pipe_client
*pipe_hnd
,
149 struct rpc_pipe_client
*winreg_pipe
,
150 const char *key_name
,
154 struct dcerpc_binding_handle
*b
= winreg_pipe
->binding_handle
;
155 enum ndr_err_code ndr_err
;
156 struct ntprinting_printer r
;
157 struct spoolss_SetPrinterInfo2 info2
;
158 struct spoolss_DeviceMode dm
;
159 struct spoolss_DevmodeContainer devmode_ctr
;
160 struct sec_desc_buf secdesc_ctr
;
166 if (strequal(key_name
, "printers")) {
170 blob
= data_blob_const(data
, length
);
174 ndr_err
= ndr_pull_struct_blob(&blob
, mem_ctx
, &r
,
175 (ndr_pull_flags_fn_t
) ndr_pull_ntprinting_printer
);
176 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
177 DEBUG(2, ("printer pull failed: %s\n",
178 ndr_errstr(ndr_err
)));
179 return NT_STATUS_NO_MEMORY
;
182 DEBUG(2, ("Migrating Printer: %s\n", key_name
));
184 ZERO_STRUCT(devmode_ctr
);
186 /* Create printer info level 2 */
188 ZERO_STRUCT(secdesc_ctr
);
190 info2
.attributes
= r
.info
.attributes
;
191 info2
.averageppm
= r
.info
.averageppm
;
192 info2
.cjobs
= r
.info
.cjobs
;
193 info2
.comment
= r
.info
.comment
;
194 info2
.datatype
= r
.info
.datatype
;
195 info2
.defaultpriority
= r
.info
.default_priority
;
196 info2
.drivername
= r
.info
.drivername
;
197 info2
.location
= r
.info
.location
;
198 info2
.parameters
= r
.info
.parameters
;
199 info2
.portname
= r
.info
.portname
;
200 info2
.printername
= r
.info
.printername
;
201 info2
.printprocessor
= r
.info
.printprocessor
;
202 info2
.priority
= r
.info
.priority
;
203 info2
.sepfile
= r
.info
.sepfile
;
204 info2
.sharename
= r
.info
.sharename
;
205 info2
.starttime
= r
.info
.starttime
;
206 info2
.status
= r
.info
.status
;
207 info2
.untiltime
= r
.info
.untiltime
;
209 /* Create Device Mode */
210 if (r
.devmode
!= NULL
) {
213 dm
.bitsperpel
= r
.devmode
->bitsperpel
;
214 dm
.collate
= r
.devmode
->collate
;
215 dm
.color
= r
.devmode
->color
;
216 dm
.copies
= r
.devmode
->copies
;
217 dm
.defaultsource
= r
.devmode
->defaultsource
;
218 dm
.devicename
= r
.devmode
->devicename
;
219 dm
.displayflags
= r
.devmode
->displayflags
;
220 dm
.displayfrequency
= r
.devmode
->displayfrequency
;
221 dm
.dithertype
= r
.devmode
->dithertype
;
222 dm
.driverversion
= r
.devmode
->driverversion
;
223 dm
.duplex
= r
.devmode
->duplex
;
224 dm
.fields
= r
.devmode
->fields
;
225 dm
.formname
= r
.devmode
->formname
;
226 dm
.icmintent
= r
.devmode
->icmintent
;
227 dm
.icmmethod
= r
.devmode
->icmmethod
;
228 dm
.logpixels
= r
.devmode
->logpixels
;
229 dm
.mediatype
= r
.devmode
->mediatype
;
230 dm
.orientation
= r
.devmode
->orientation
;
231 dm
.panningheight
= r
.devmode
->pelsheight
;
232 dm
.panningwidth
= r
.devmode
->panningwidth
;
233 dm
.paperlength
= r
.devmode
->paperlength
;
234 dm
.papersize
= r
.devmode
->papersize
;
235 dm
.paperwidth
= r
.devmode
->paperwidth
;
236 dm
.pelsheight
= r
.devmode
->pelsheight
;
237 dm
.pelswidth
= r
.devmode
->pelswidth
;
238 dm
.printquality
= r
.devmode
->printquality
;
239 dm
.size
= r
.devmode
->size
;
240 dm
.scale
= r
.devmode
->scale
;
241 dm
.specversion
= r
.devmode
->specversion
;
242 dm
.ttoption
= r
.devmode
->ttoption
;
243 dm
.yresolution
= r
.devmode
->yresolution
;
245 if (r
.devmode
->nt_dev_private
!= NULL
) {
246 dm
.driverextra_data
.data
= r
.devmode
->nt_dev_private
->data
;
247 dm
.driverextra_data
.length
= r
.devmode
->nt_dev_private
->length
;
248 dm
.__driverextra_length
= r
.devmode
->nt_dev_private
->length
;
251 devmode_ctr
.devmode
= &dm
;
253 info2
.devmode_ptr
= 1;
256 result
= winreg_update_printer(mem_ctx
, b
,
258 0, /// FIXME !!!!!!!!!!!!!!!!!!!!!!!
262 if (!W_ERROR_IS_OK(result
)) {
263 DEBUG(2, ("SetPrinter(%s) level 2 refused -- %s.\n",
264 key_name
, win_errstr(result
)));
265 status
= werror_to_ntstatus(result
);
269 /* migrate printerdata */
270 for (j
= 0; j
< r
.count
; j
++) {
274 if (r
.printer_data
[j
].type
== REG_NONE
) {
278 keyname
= r
.printer_data
[j
].name
;
279 valuename
= strchr(keyname
, '\\');
280 if (valuename
== NULL
) {
287 result
= winreg_set_printer_dataex(mem_ctx
, b
,
291 r
.printer_data
[j
].type
,
292 r
.printer_data
[j
].data
.data
,
293 r
.printer_data
[j
].data
.length
);
294 if (!W_ERROR_IS_OK(result
)) {
295 DEBUG(2, ("SetPrinterDataEx: printer [%s], keyname [%s], "
296 "valuename [%s] refused -- %s.\n",
297 key_name
, keyname
, valuename
,
298 win_errstr(result
)));
299 status
= werror_to_ntstatus(result
);
309 NTSTATUS
printing_tdb_migrate_secdesc(TALLOC_CTX
*mem_ctx
,
310 struct rpc_pipe_client
*pipe_hnd
,
311 struct rpc_pipe_client
*winreg_pipe
,
312 const char *key_name
,
316 struct dcerpc_binding_handle
*b
= winreg_pipe
->binding_handle
;
317 enum ndr_err_code ndr_err
;
318 struct sec_desc_buf secdesc_ctr
;
322 if (strequal(key_name
, "printers")) {
326 blob
= data_blob_const(data
, length
);
328 ZERO_STRUCT(secdesc_ctr
);
330 ndr_err
= ndr_pull_struct_blob(&blob
, mem_ctx
, &secdesc_ctr
,
331 (ndr_pull_flags_fn_t
)ndr_pull_sec_desc_buf
);
332 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
333 DEBUG(2, ("security descriptor pull failed: %s\n",
334 ndr_errstr(ndr_err
)));
335 return NT_STATUS_NO_MEMORY
;
338 DEBUG(2, ("Migrating Security Descriptor: %s\n", key_name
));
340 result
= winreg_set_printer_secdesc(mem_ctx
, b
,
343 if (!W_ERROR_IS_OK(result
)) {
344 return werror_to_ntstatus(result
);