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
,
45 return WERR_NOT_ENOUGH_MEMORY
;
48 status
= rpcint_binding_handle(mem_ctx
,
54 winreg_binding_handle
);
56 if (!NT_STATUS_IS_OK(status
)) {
57 DEBUG(0, ("winreg_printer_binding_handle: Could not connect to winreg pipe: %s\n",
59 return ntstatus_to_werror(status
);
65 WERROR
winreg_delete_printer_key_internal(TALLOC_CTX
*mem_ctx
,
66 const struct auth_session_info
*session_info
,
67 struct messaging_context
*msg_ctx
,
72 struct dcerpc_binding_handle
*b
;
75 tmp_ctx
= talloc_stackframe();
76 if (tmp_ctx
== NULL
) {
77 return WERR_NOT_ENOUGH_MEMORY
;
80 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
81 if (!W_ERROR_IS_OK(result
)) {
86 result
= winreg_delete_printer_key(tmp_ctx
,
95 WERROR
winreg_printer_update_changeid_internal(TALLOC_CTX
*mem_ctx
,
96 const struct auth_session_info
*session_info
,
97 struct messaging_context
*msg_ctx
,
101 struct dcerpc_binding_handle
*b
;
104 tmp_ctx
= talloc_stackframe();
105 if (tmp_ctx
== NULL
) {
106 return WERR_NOT_ENOUGH_MEMORY
;
109 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
110 if (!W_ERROR_IS_OK(result
)) {
111 talloc_free(tmp_ctx
);
115 result
= winreg_printer_update_changeid(mem_ctx
,
119 talloc_free(tmp_ctx
);
123 WERROR
winreg_printer_get_changeid_internal(TALLOC_CTX
*mem_ctx
,
124 const struct auth_session_info
*session_info
,
125 struct messaging_context
*msg_ctx
,
130 struct dcerpc_binding_handle
*b
;
133 tmp_ctx
= talloc_stackframe();
134 if (tmp_ctx
== NULL
) {
135 return WERR_NOT_ENOUGH_MEMORY
;
138 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
139 if (!W_ERROR_IS_OK(result
)) {
140 talloc_free(tmp_ctx
);
144 result
= winreg_printer_get_changeid(mem_ctx
,
149 talloc_free(tmp_ctx
);
153 WERROR
winreg_get_printer_internal(TALLOC_CTX
*mem_ctx
,
154 const struct auth_session_info
*session_info
,
155 struct messaging_context
*msg_ctx
,
157 struct spoolss_PrinterInfo2
**pinfo2
)
160 struct dcerpc_binding_handle
*b
;
163 tmp_ctx
= talloc_stackframe();
164 if (tmp_ctx
== NULL
) {
165 return WERR_NOT_ENOUGH_MEMORY
;
168 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
169 if (!W_ERROR_IS_OK(result
)) {
170 talloc_free(tmp_ctx
);
174 result
= winreg_get_printer(mem_ctx
,
179 talloc_free(tmp_ctx
);
183 WERROR
winreg_create_printer_internal(TALLOC_CTX
*mem_ctx
,
184 const struct auth_session_info
*session_info
,
185 struct messaging_context
*msg_ctx
,
186 const char *sharename
)
189 struct dcerpc_binding_handle
*b
;
192 tmp_ctx
= talloc_stackframe();
193 if (tmp_ctx
== NULL
) {
194 return WERR_NOT_ENOUGH_MEMORY
;
197 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
198 if (!W_ERROR_IS_OK(result
)) {
199 talloc_free(tmp_ctx
);
203 result
= winreg_create_printer(mem_ctx
,
207 talloc_free(tmp_ctx
);
211 WERROR
winreg_update_printer_internal(TALLOC_CTX
*mem_ctx
,
212 const struct auth_session_info
*session_info
,
213 struct messaging_context
*msg_ctx
,
214 const char *sharename
,
216 struct spoolss_SetPrinterInfo2
*info2
,
217 struct spoolss_DeviceMode
*devmode
,
218 struct security_descriptor
*secdesc
)
221 struct dcerpc_binding_handle
*b
;
224 tmp_ctx
= talloc_stackframe();
225 if (tmp_ctx
== NULL
) {
226 return WERR_NOT_ENOUGH_MEMORY
;
229 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
230 if (!W_ERROR_IS_OK(result
)) {
231 talloc_free(tmp_ctx
);
235 result
= winreg_update_printer(mem_ctx
,
243 talloc_free(tmp_ctx
);
247 WERROR
winreg_set_printer_dataex_internal(TALLOC_CTX
*mem_ctx
,
248 const struct auth_session_info
*session_info
,
249 struct messaging_context
*msg_ctx
,
253 enum winreg_Type type
,
258 struct dcerpc_binding_handle
*b
;
261 tmp_ctx
= talloc_stackframe();
262 if (tmp_ctx
== NULL
) {
263 return WERR_NOT_ENOUGH_MEMORY
;
266 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
267 if (!W_ERROR_IS_OK(result
)) {
268 talloc_free(tmp_ctx
);
272 result
= winreg_set_printer_dataex(mem_ctx
,
281 talloc_free(tmp_ctx
);
285 WERROR
winreg_enum_printer_dataex_internal(TALLOC_CTX
*mem_ctx
,
286 const struct auth_session_info
*session_info
,
287 struct messaging_context
*msg_ctx
,
290 uint32_t *pnum_values
,
291 struct spoolss_PrinterEnumValues
**penum_values
)
294 struct dcerpc_binding_handle
*b
;
297 tmp_ctx
= talloc_stackframe();
298 if (tmp_ctx
== NULL
) {
299 return WERR_NOT_ENOUGH_MEMORY
;
302 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
303 if (!W_ERROR_IS_OK(result
)) {
304 talloc_free(tmp_ctx
);
308 result
= winreg_enum_printer_dataex(mem_ctx
,
315 talloc_free(tmp_ctx
);
319 WERROR
winreg_get_printer_dataex_internal(TALLOC_CTX
*mem_ctx
,
320 const struct auth_session_info
*session_info
,
321 struct messaging_context
*msg_ctx
,
325 enum winreg_Type
*type
,
330 struct dcerpc_binding_handle
*b
;
333 tmp_ctx
= talloc_stackframe();
334 if (tmp_ctx
== NULL
) {
335 return WERR_NOT_ENOUGH_MEMORY
;
338 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
339 if (!W_ERROR_IS_OK(result
)) {
340 talloc_free(tmp_ctx
);
344 result
= winreg_get_printer_dataex(mem_ctx
,
353 talloc_free(tmp_ctx
);
357 WERROR
winreg_delete_printer_dataex_internal(TALLOC_CTX
*mem_ctx
,
358 const struct auth_session_info
*session_info
,
359 struct messaging_context
*msg_ctx
,
365 struct dcerpc_binding_handle
*b
;
368 tmp_ctx
= talloc_stackframe();
369 if (tmp_ctx
== NULL
) {
370 return WERR_NOT_ENOUGH_MEMORY
;
373 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
374 if (!W_ERROR_IS_OK(result
)) {
375 talloc_free(tmp_ctx
);
379 result
= winreg_delete_printer_dataex(mem_ctx
,
385 talloc_free(tmp_ctx
);
389 WERROR
winreg_get_driver_internal(TALLOC_CTX
*mem_ctx
,
390 const struct auth_session_info
*session_info
,
391 struct messaging_context
*msg_ctx
,
392 const char *architecture
,
393 const char *driver_name
,
394 uint32_t driver_version
,
395 struct spoolss_DriverInfo8
**_info8
)
398 struct dcerpc_binding_handle
*b
;
401 tmp_ctx
= talloc_stackframe();
402 if (tmp_ctx
== NULL
) {
403 return WERR_NOT_ENOUGH_MEMORY
;
406 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
407 if (!W_ERROR_IS_OK(result
)) {
408 talloc_free(tmp_ctx
);
412 result
= winreg_get_driver(mem_ctx
,
419 talloc_free(tmp_ctx
);
423 WERROR
winreg_get_driver_list_internal(TALLOC_CTX
*mem_ctx
,
424 const struct auth_session_info
*session_info
,
425 struct messaging_context
*msg_ctx
,
426 const char *architecture
,
428 uint32_t *num_drivers
,
429 const char ***drivers_p
)
432 struct dcerpc_binding_handle
*b
;
435 tmp_ctx
= talloc_stackframe();
436 if (tmp_ctx
== NULL
) {
437 return WERR_NOT_ENOUGH_MEMORY
;
440 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
441 if (!W_ERROR_IS_OK(result
)) {
442 talloc_free(tmp_ctx
);
446 result
= winreg_get_driver_list(mem_ctx
,
453 talloc_free(tmp_ctx
);
457 WERROR
winreg_del_driver_internal(TALLOC_CTX
*mem_ctx
,
458 const struct auth_session_info
*session_info
,
459 struct messaging_context
*msg_ctx
,
460 struct spoolss_DriverInfo8
*info8
,
464 struct dcerpc_binding_handle
*b
;
467 tmp_ctx
= talloc_stackframe();
468 if (tmp_ctx
== NULL
) {
469 return WERR_NOT_ENOUGH_MEMORY
;
472 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
473 if (!W_ERROR_IS_OK(result
)) {
474 talloc_free(tmp_ctx
);
478 result
= winreg_del_driver(mem_ctx
,
483 talloc_free(tmp_ctx
);
487 WERROR
winreg_add_driver_internal(TALLOC_CTX
*mem_ctx
,
488 const struct auth_session_info
*session_info
,
489 struct messaging_context
*msg_ctx
,
490 struct spoolss_AddDriverInfoCtr
*r
,
491 const char **driver_name
,
492 uint32_t *driver_version
)
495 struct dcerpc_binding_handle
*b
;
498 tmp_ctx
= talloc_stackframe();
499 if (tmp_ctx
== NULL
) {
500 return WERR_NOT_ENOUGH_MEMORY
;
503 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
504 if (!W_ERROR_IS_OK(result
)) {
505 talloc_free(tmp_ctx
);
509 result
= winreg_add_driver(mem_ctx
,
515 talloc_free(tmp_ctx
);
519 WERROR
winreg_get_core_driver_internal(TALLOC_CTX
*mem_ctx
,
520 const struct auth_session_info
*session_info
,
521 struct messaging_context
*msg_ctx
,
522 const char *architecture
,
523 const struct GUID
*core_driver_guid
,
524 struct spoolss_CorePrinterDriver
**core_printer_driver
)
527 struct dcerpc_binding_handle
*b
;
530 tmp_ctx
= talloc_stackframe();
531 if (tmp_ctx
== NULL
) {
532 return WERR_NOT_ENOUGH_MEMORY
;
535 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
536 if (!W_ERROR_IS_OK(result
)) {
537 talloc_free(tmp_ctx
);
541 result
= winreg_get_core_driver(mem_ctx
,
545 core_printer_driver
);
547 talloc_free(tmp_ctx
);
552 WERROR
winreg_get_printer_secdesc_internal(TALLOC_CTX
*mem_ctx
,
553 const struct auth_session_info
*session_info
,
554 struct messaging_context
*msg_ctx
,
555 const char *sharename
,
556 struct spoolss_security_descriptor
**psecdesc
)
559 struct dcerpc_binding_handle
*b
;
562 tmp_ctx
= talloc_stackframe();
563 if (tmp_ctx
== NULL
) {
564 return WERR_NOT_ENOUGH_MEMORY
;
567 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
568 if (!W_ERROR_IS_OK(result
)) {
569 talloc_free(tmp_ctx
);
573 result
= winreg_get_printer_secdesc(mem_ctx
,
578 talloc_free(tmp_ctx
);
582 WERROR
winreg_set_printer_secdesc_internal(TALLOC_CTX
*mem_ctx
,
583 const struct auth_session_info
*session_info
,
584 struct messaging_context
*msg_ctx
,
585 const char *sharename
,
586 const struct spoolss_security_descriptor
*secdesc
)
589 struct dcerpc_binding_handle
*b
;
592 tmp_ctx
= talloc_stackframe();
593 if (tmp_ctx
== NULL
) {
594 return WERR_NOT_ENOUGH_MEMORY
;
597 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
598 if (!W_ERROR_IS_OK(result
)) {
599 talloc_free(tmp_ctx
);
603 result
= winreg_set_printer_secdesc(mem_ctx
,
608 talloc_free(tmp_ctx
);
612 WERROR
winreg_printer_enumforms1_internal(TALLOC_CTX
*mem_ctx
,
613 const struct auth_session_info
*session_info
,
614 struct messaging_context
*msg_ctx
,
616 union spoolss_FormInfo
**pinfo
)
619 struct dcerpc_binding_handle
*b
;
622 tmp_ctx
= talloc_stackframe();
623 if (tmp_ctx
== NULL
) {
624 return WERR_NOT_ENOUGH_MEMORY
;
627 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
628 if (!W_ERROR_IS_OK(result
)) {
629 talloc_free(tmp_ctx
);
633 result
= winreg_printer_enumforms1(mem_ctx
,
638 talloc_free(tmp_ctx
);
642 WERROR
winreg_printer_getform1_internal(TALLOC_CTX
*mem_ctx
,
643 const struct auth_session_info
*session_info
,
644 struct messaging_context
*msg_ctx
,
645 const char *form_name
,
646 struct spoolss_FormInfo1
*r
)
649 struct dcerpc_binding_handle
*b
;
652 tmp_ctx
= talloc_stackframe();
653 if (tmp_ctx
== NULL
) {
654 return WERR_NOT_ENOUGH_MEMORY
;
657 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
658 if (!W_ERROR_IS_OK(result
)) {
659 talloc_free(tmp_ctx
);
663 result
= winreg_printer_getform1(mem_ctx
,
668 talloc_free(tmp_ctx
);
672 WERROR
winreg_printer_addform1_internal(TALLOC_CTX
*mem_ctx
,
673 const struct auth_session_info
*session_info
,
674 struct messaging_context
*msg_ctx
,
675 struct spoolss_AddFormInfo1
*form
)
678 struct dcerpc_binding_handle
*b
;
681 tmp_ctx
= talloc_stackframe();
682 if (tmp_ctx
== NULL
) {
683 return WERR_NOT_ENOUGH_MEMORY
;
686 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
687 if (!W_ERROR_IS_OK(result
)) {
688 talloc_free(tmp_ctx
);
692 result
= winreg_printer_addform1(mem_ctx
,
696 talloc_free(tmp_ctx
);
700 WERROR
winreg_printer_setform1_internal(TALLOC_CTX
*mem_ctx
,
701 const struct auth_session_info
*session_info
,
702 struct messaging_context
*msg_ctx
,
703 const char *form_name
,
704 struct spoolss_AddFormInfo1
*form
)
707 struct dcerpc_binding_handle
*b
;
710 tmp_ctx
= talloc_stackframe();
711 if (tmp_ctx
== NULL
) {
712 return WERR_NOT_ENOUGH_MEMORY
;
715 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
716 if (!W_ERROR_IS_OK(result
)) {
717 talloc_free(tmp_ctx
);
721 result
= winreg_printer_setform1(mem_ctx
,
726 talloc_free(tmp_ctx
);
730 WERROR
winreg_printer_deleteform1_internal(TALLOC_CTX
*mem_ctx
,
731 const struct auth_session_info
*session_info
,
732 struct messaging_context
*msg_ctx
,
733 const char *form_name
)
736 struct dcerpc_binding_handle
*b
;
739 tmp_ctx
= talloc_stackframe();
740 if (tmp_ctx
== NULL
) {
741 return WERR_NOT_ENOUGH_MEMORY
;
744 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
745 if (!W_ERROR_IS_OK(result
)) {
746 talloc_free(tmp_ctx
);
750 result
= winreg_printer_deleteform1(mem_ctx
,
754 talloc_free(tmp_ctx
);
758 WERROR
winreg_enum_printer_key_internal(TALLOC_CTX
*mem_ctx
,
759 const struct auth_session_info
*session_info
,
760 struct messaging_context
*msg_ctx
,
763 uint32_t *pnum_subkeys
,
764 const char ***psubkeys
)
767 struct dcerpc_binding_handle
*b
;
770 tmp_ctx
= talloc_stackframe();
771 if (tmp_ctx
== NULL
) {
772 return WERR_NOT_ENOUGH_MEMORY
;
775 result
= winreg_printer_binding_handle(tmp_ctx
, session_info
, msg_ctx
, &b
);
776 if (!W_ERROR_IS_OK(result
)) {
777 talloc_free(tmp_ctx
);
781 result
= winreg_enum_printer_key(mem_ctx
,
788 talloc_free(tmp_ctx
);