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 "rpc_server/rpc_ncacn_np.h"
24 #include "../lib/tsocket/tsocket.h"
25 #include "../librpc/gen_ndr/ndr_spoolss.h"
26 #include "../librpc/gen_ndr/ndr_winreg.h"
27 #include "srv_spoolss_util.h"
28 #include "rpc_client/cli_winreg_spoolss.h"
30 WERROR
winreg_printer_binding_handle(TALLOC_CTX
*mem_ctx
,
31 const struct auth_session_info
*session_info
,
32 struct messaging_context
*msg_ctx
,
33 struct dcerpc_binding_handle
**winreg_binding_handle
)
35 struct tsocket_address
*local
;
39 rc
= tsocket_address_inet_from_strings(mem_ctx
,
48 status
= rpcint_binding_handle(mem_ctx
,
53 winreg_binding_handle
);
55 if (!NT_STATUS_IS_OK(status
)) {
56 DEBUG(0, ("winreg_printer_binding_handle: Could not connect to winreg pipe: %s\n",
58 return ntstatus_to_werror(status
);
64 WERROR
winreg_delete_printer_key_internal(TALLOC_CTX
*mem_ctx
,
65 const struct auth_session_info
*session_info
,
66 struct messaging_context
*msg_ctx
,
71 struct dcerpc_binding_handle
*b
;
74 tmp_ctx
= talloc_stackframe();
75 if (tmp_ctx
== NULL
) {
79 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
80 if (!W_ERROR_IS_OK(result
)) {
85 result
= winreg_delete_printer_key(tmp_ctx
,
94 WERROR
winreg_printer_update_changeid_internal(TALLOC_CTX
*mem_ctx
,
95 const struct auth_session_info
*session_info
,
96 struct messaging_context
*msg_ctx
,
100 struct dcerpc_binding_handle
*b
;
103 tmp_ctx
= talloc_stackframe();
104 if (tmp_ctx
== NULL
) {
108 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
109 if (!W_ERROR_IS_OK(result
)) {
110 talloc_free(tmp_ctx
);
114 result
= winreg_printer_update_changeid(mem_ctx
,
118 talloc_free(tmp_ctx
);
122 WERROR
winreg_printer_get_changeid_internal(TALLOC_CTX
*mem_ctx
,
123 const struct auth_session_info
*session_info
,
124 struct messaging_context
*msg_ctx
,
129 struct dcerpc_binding_handle
*b
;
132 tmp_ctx
= talloc_stackframe();
133 if (tmp_ctx
== NULL
) {
137 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
138 if (!W_ERROR_IS_OK(result
)) {
139 talloc_free(tmp_ctx
);
143 result
= winreg_printer_get_changeid(mem_ctx
,
148 talloc_free(tmp_ctx
);
152 WERROR
winreg_get_printer_internal(TALLOC_CTX
*mem_ctx
,
153 const struct auth_session_info
*session_info
,
154 struct messaging_context
*msg_ctx
,
156 struct spoolss_PrinterInfo2
**pinfo2
)
159 struct dcerpc_binding_handle
*b
;
162 tmp_ctx
= talloc_stackframe();
163 if (tmp_ctx
== NULL
) {
167 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
168 if (!W_ERROR_IS_OK(result
)) {
169 talloc_free(tmp_ctx
);
173 result
= winreg_get_printer(mem_ctx
,
178 talloc_free(tmp_ctx
);
182 WERROR
winreg_create_printer_internal(TALLOC_CTX
*mem_ctx
,
183 const struct auth_session_info
*session_info
,
184 struct messaging_context
*msg_ctx
,
185 const char *sharename
)
188 struct dcerpc_binding_handle
*b
;
191 tmp_ctx
= talloc_stackframe();
192 if (tmp_ctx
== NULL
) {
196 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
197 if (!W_ERROR_IS_OK(result
)) {
198 talloc_free(tmp_ctx
);
202 result
= winreg_create_printer(mem_ctx
,
206 talloc_free(tmp_ctx
);
210 WERROR
winreg_update_printer_internal(TALLOC_CTX
*mem_ctx
,
211 const struct auth_session_info
*session_info
,
212 struct messaging_context
*msg_ctx
,
213 const char *sharename
,
215 struct spoolss_SetPrinterInfo2
*info2
,
216 struct spoolss_DeviceMode
*devmode
,
217 struct security_descriptor
*secdesc
)
220 struct dcerpc_binding_handle
*b
;
223 tmp_ctx
= talloc_stackframe();
224 if (tmp_ctx
== NULL
) {
228 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
229 if (!W_ERROR_IS_OK(result
)) {
230 talloc_free(tmp_ctx
);
234 result
= winreg_update_printer(mem_ctx
,
242 talloc_free(tmp_ctx
);
246 WERROR
winreg_set_printer_dataex_internal(TALLOC_CTX
*mem_ctx
,
247 const struct auth_session_info
*session_info
,
248 struct messaging_context
*msg_ctx
,
252 enum winreg_Type type
,
257 struct dcerpc_binding_handle
*b
;
260 tmp_ctx
= talloc_stackframe();
261 if (tmp_ctx
== NULL
) {
265 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
266 if (!W_ERROR_IS_OK(result
)) {
267 talloc_free(tmp_ctx
);
271 result
= winreg_set_printer_dataex(mem_ctx
,
280 talloc_free(tmp_ctx
);
284 WERROR
winreg_enum_printer_dataex_internal(TALLOC_CTX
*mem_ctx
,
285 const struct auth_session_info
*session_info
,
286 struct messaging_context
*msg_ctx
,
289 uint32_t *pnum_values
,
290 struct spoolss_PrinterEnumValues
**penum_values
)
293 struct dcerpc_binding_handle
*b
;
296 tmp_ctx
= talloc_stackframe();
297 if (tmp_ctx
== NULL
) {
301 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
302 if (!W_ERROR_IS_OK(result
)) {
303 talloc_free(tmp_ctx
);
307 result
= winreg_enum_printer_dataex(mem_ctx
,
314 talloc_free(tmp_ctx
);
318 WERROR
winreg_get_printer_dataex_internal(TALLOC_CTX
*mem_ctx
,
319 const struct auth_session_info
*session_info
,
320 struct messaging_context
*msg_ctx
,
324 enum winreg_Type
*type
,
329 struct dcerpc_binding_handle
*b
;
332 tmp_ctx
= talloc_stackframe();
333 if (tmp_ctx
== NULL
) {
337 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
338 if (!W_ERROR_IS_OK(result
)) {
339 talloc_free(tmp_ctx
);
343 result
= winreg_get_printer_dataex(mem_ctx
,
352 talloc_free(tmp_ctx
);
356 WERROR
winreg_delete_printer_dataex_internal(TALLOC_CTX
*mem_ctx
,
357 const struct auth_session_info
*session_info
,
358 struct messaging_context
*msg_ctx
,
364 struct dcerpc_binding_handle
*b
;
367 tmp_ctx
= talloc_stackframe();
368 if (tmp_ctx
== NULL
) {
372 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
373 if (!W_ERROR_IS_OK(result
)) {
374 talloc_free(tmp_ctx
);
378 result
= winreg_delete_printer_dataex(mem_ctx
,
384 talloc_free(tmp_ctx
);
388 WERROR
winreg_get_driver_internal(TALLOC_CTX
*mem_ctx
,
389 const struct auth_session_info
*session_info
,
390 struct messaging_context
*msg_ctx
,
391 const char *architecture
,
392 const char *driver_name
,
393 uint32_t driver_version
,
394 struct spoolss_DriverInfo8
**_info8
)
397 struct dcerpc_binding_handle
*b
;
400 tmp_ctx
= talloc_stackframe();
401 if (tmp_ctx
== NULL
) {
405 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
406 if (!W_ERROR_IS_OK(result
)) {
407 talloc_free(tmp_ctx
);
411 result
= winreg_get_driver(mem_ctx
,
418 talloc_free(tmp_ctx
);
422 WERROR
winreg_get_driver_list_internal(TALLOC_CTX
*mem_ctx
,
423 const struct auth_session_info
*session_info
,
424 struct messaging_context
*msg_ctx
,
425 const char *architecture
,
427 uint32_t *num_drivers
,
428 const char ***drivers_p
)
431 struct dcerpc_binding_handle
*b
;
434 tmp_ctx
= talloc_stackframe();
435 if (tmp_ctx
== NULL
) {
439 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
440 if (!W_ERROR_IS_OK(result
)) {
441 talloc_free(tmp_ctx
);
445 result
= winreg_get_driver_list(mem_ctx
,
452 talloc_free(tmp_ctx
);
456 WERROR
winreg_del_driver_internal(TALLOC_CTX
*mem_ctx
,
457 const struct auth_session_info
*session_info
,
458 struct messaging_context
*msg_ctx
,
459 struct spoolss_DriverInfo8
*info8
,
463 struct dcerpc_binding_handle
*b
;
465 result
= winreg_printer_binding_handle(mem_ctx
, session_info
, msg_ctx
, &b
);
466 W_ERROR_NOT_OK_RETURN(result
);
468 return winreg_del_driver(mem_ctx
, b
,
473 WERROR
winreg_add_driver_internal(TALLOC_CTX
*mem_ctx
,
474 const struct auth_session_info
*session_info
,
475 struct messaging_context
*msg_ctx
,
476 struct spoolss_AddDriverInfoCtr
*r
,
477 const char **driver_name
,
478 uint32_t *driver_version
)
481 struct dcerpc_binding_handle
*b
;
483 result
= winreg_printer_binding_handle(mem_ctx
, session_info
, msg_ctx
, &b
);
484 W_ERROR_NOT_OK_RETURN(result
);
486 return winreg_add_driver(mem_ctx
, b
,
492 WERROR
winreg_get_printer_secdesc_internal(TALLOC_CTX
*mem_ctx
,
493 const struct auth_session_info
*session_info
,
494 struct messaging_context
*msg_ctx
,
495 const char *sharename
,
496 struct spoolss_security_descriptor
**psecdesc
)
499 struct dcerpc_binding_handle
*b
;
501 result
= winreg_printer_binding_handle(mem_ctx
, session_info
, msg_ctx
, &b
);
502 W_ERROR_NOT_OK_RETURN(result
);
504 return winreg_get_printer_secdesc(mem_ctx
, b
,
509 WERROR
winreg_set_printer_secdesc_internal(TALLOC_CTX
*mem_ctx
,
510 const struct auth_session_info
*session_info
,
511 struct messaging_context
*msg_ctx
,
512 const char *sharename
,
513 const struct spoolss_security_descriptor
*secdesc
)
516 struct dcerpc_binding_handle
*b
;
518 result
= winreg_printer_binding_handle(mem_ctx
, session_info
, msg_ctx
, &b
);
519 W_ERROR_NOT_OK_RETURN(result
);
521 return winreg_set_printer_secdesc(mem_ctx
, b
,
526 WERROR
winreg_printer_enumforms1_internal(TALLOC_CTX
*mem_ctx
,
527 const struct auth_session_info
*session_info
,
528 struct messaging_context
*msg_ctx
,
530 union spoolss_FormInfo
**pinfo
)
533 struct dcerpc_binding_handle
*b
;
535 result
= winreg_printer_binding_handle(mem_ctx
, session_info
, msg_ctx
, &b
);
536 W_ERROR_NOT_OK_RETURN(result
);
538 return winreg_printer_enumforms1(mem_ctx
, b
,
543 WERROR
winreg_printer_getform1_internal(TALLOC_CTX
*mem_ctx
,
544 const struct auth_session_info
*session_info
,
545 struct messaging_context
*msg_ctx
,
546 const char *form_name
,
547 struct spoolss_FormInfo1
*r
)
550 struct dcerpc_binding_handle
*b
;
552 result
= winreg_printer_binding_handle(mem_ctx
, session_info
, msg_ctx
, &b
);
553 W_ERROR_NOT_OK_RETURN(result
);
555 return winreg_printer_getform1(mem_ctx
, b
,
560 WERROR
winreg_printer_addform1_internal(TALLOC_CTX
*mem_ctx
,
561 const struct auth_session_info
*session_info
,
562 struct messaging_context
*msg_ctx
,
563 struct spoolss_AddFormInfo1
*form
)
566 struct dcerpc_binding_handle
*b
;
568 result
= winreg_printer_binding_handle(mem_ctx
, session_info
, msg_ctx
, &b
);
569 W_ERROR_NOT_OK_RETURN(result
);
571 return winreg_printer_addform1(mem_ctx
, b
,
575 WERROR
winreg_printer_setform1_internal(TALLOC_CTX
*mem_ctx
,
576 const struct auth_session_info
*session_info
,
577 struct messaging_context
*msg_ctx
,
578 const char *form_name
,
579 struct spoolss_AddFormInfo1
*form
)
582 struct dcerpc_binding_handle
*b
;
584 result
= winreg_printer_binding_handle(mem_ctx
, session_info
, msg_ctx
, &b
);
585 W_ERROR_NOT_OK_RETURN(result
);
587 return winreg_printer_setform1(mem_ctx
, b
,
592 WERROR
winreg_printer_deleteform1_internal(TALLOC_CTX
*mem_ctx
,
593 const struct auth_session_info
*session_info
,
594 struct messaging_context
*msg_ctx
,
595 const char *form_name
)
598 struct dcerpc_binding_handle
*b
;
600 result
= winreg_printer_binding_handle(mem_ctx
, session_info
, msg_ctx
, &b
);
601 W_ERROR_NOT_OK_RETURN(result
);
603 return winreg_printer_deleteform1(mem_ctx
, b
,
607 WERROR
winreg_enum_printer_key_internal(TALLOC_CTX
*mem_ctx
,
608 const struct auth_session_info
*session_info
,
609 struct messaging_context
*msg_ctx
,
612 uint32_t *pnum_subkeys
,
613 const char ***psubkeys
)
616 struct dcerpc_binding_handle
*b
;
618 result
= winreg_printer_binding_handle(mem_ctx
, session_info
, msg_ctx
, &b
);
619 W_ERROR_NOT_OK_RETURN(result
);
621 return winreg_enum_printer_key(mem_ctx
, b
,