2 Unix SMB/CIFS implementation.
3 async implementation of commands submitted over IRPC
4 Copyright (C) Volker Lendecke 2009
5 Copyright (C) Guenther Deschner 2009
6 Copyright (C) Andrew Bartlett 2014
7 Copyright (C) Andrew Tridgell 2009
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "librpc/gen_ndr/ndr_winbind_c.h"
26 #include "source4/lib/messaging/irpc.h"
27 #include "librpc/gen_ndr/ndr_winbind.h"
29 struct wb_irpc_forward_state
{
30 struct irpc_message
*msg
;
31 struct winbind_DsrUpdateReadOnlyServerDnsRecords
*req
;
34 struct dcesrv_call_state
*dce_call
;
38 called when the forwarded rpc request is finished
40 static void wb_irpc_forward_callback(struct tevent_req
*subreq
)
42 struct wb_irpc_forward_state
*st
=
43 tevent_req_callback_data(subreq
,
44 struct wb_irpc_forward_state
);
45 const char *opname
= st
->opname
;
48 status
= dcerpc_binding_handle_call_recv(subreq
);
50 if (!NT_STATUS_IS_OK(status
)) {
51 DEBUG(0,("RPC callback failed for %s - %s\n",
52 opname
, nt_errstr(status
)));
53 irpc_send_reply(st
->msg
, status
);
56 irpc_send_reply(st
->msg
, status
);
62 * Forward a RPC call using IRPC to another task
65 static NTSTATUS
wb_irpc_forward_rpc_call(struct irpc_message
*msg
, TALLOC_CTX
*mem_ctx
,
66 struct tevent_context
*ev
,
67 void *r
, uint32_t callid
,
69 struct winbindd_domain
*domain
,
72 struct wb_irpc_forward_state
*st
;
73 struct dcerpc_binding_handle
*binding_handle
;
74 struct tevent_req
*subreq
;
76 st
= talloc(mem_ctx
, struct wb_irpc_forward_state
);
78 return NT_STATUS_NO_MEMORY
;
84 binding_handle
= dom_child_handle(domain
);
85 if (binding_handle
== NULL
) {
86 DEBUG(0,("%s: Failed to forward request to winbind handler for %s\n",
87 opname
, domain
->name
));
88 return NT_STATUS_UNSUCCESSFUL
;
91 /* reset timeout for the handle */
92 dcerpc_binding_handle_set_timeout(binding_handle
, timeout
);
94 /* forward the call */
95 subreq
= dcerpc_binding_handle_call_send(st
, ev
,
97 NULL
, &ndr_table_winbind
,
100 if (subreq
== NULL
) {
101 DEBUG(0,("%s: Failed to forward request to winbind handler for %s\n",
102 opname
, domain
->name
));
103 return NT_STATUS_UNSUCCESSFUL
;
106 /* mark the request as replied async */
107 msg
->defer_reply
= true;
109 /* setup the callback */
110 tevent_req_set_callback(subreq
, wb_irpc_forward_callback
, st
);
114 static NTSTATUS
wb_irpc_DsrUpdateReadOnlyServerDnsRecords(struct irpc_message
*msg
,
115 struct winbind_DsrUpdateReadOnlyServerDnsRecords
*req
)
117 struct winbindd_domain
*domain
= find_our_domain();
118 if (domain
== NULL
) {
119 return NT_STATUS_NO_SUCH_DOMAIN
;
122 DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords called\n"));
124 return wb_irpc_forward_rpc_call(msg
, msg
,
125 winbind_event_context(),
126 req
, NDR_WINBIND_DSRUPDATEREADONLYSERVERDNSRECORDS
,
127 "winbind_DsrUpdateReadOnlyServerDnsRecords",
128 domain
, IRPC_CALL_TIMEOUT
);
131 static NTSTATUS
wb_irpc_SamLogon(struct irpc_message
*msg
,
132 struct winbind_SamLogon
*req
)
134 struct winbindd_domain
*domain
;
135 const char *target_domain_name
;
136 if (req
->in
.logon
.network
== NULL
) {
137 return NT_STATUS_REQUEST_NOT_ACCEPTED
;
139 target_domain_name
= req
->in
.logon
.network
->identity_info
.domain_name
.string
;
141 domain
= find_auth_domain(0, target_domain_name
);
142 if (domain
== NULL
) {
143 return NT_STATUS_NO_SUCH_USER
;
146 DEBUG(5, ("wb_irpc_SamLogon called\n"));
148 return wb_irpc_forward_rpc_call(msg
, msg
,
149 winbind_event_context(),
150 req
, NDR_WINBIND_SAMLOGON
,
152 domain
, IRPC_CALL_TIMEOUT
);
155 NTSTATUS
wb_irpc_register(void)
158 status
= IRPC_REGISTER(winbind_imessaging_context(), winbind
, WINBIND_DSRUPDATEREADONLYSERVERDNSRECORDS
,
159 wb_irpc_DsrUpdateReadOnlyServerDnsRecords
, NULL
);
160 if (!NT_STATUS_IS_OK(status
)) {
163 status
= IRPC_REGISTER(winbind_imessaging_context(), winbind
, WINBIND_SAMLOGON
,
164 wb_irpc_SamLogon
, NULL
);