s4: implemented server side of DSUpdateRefs call
[Samba/aatanasov.git] / source4 / rpc_server / service_rpc.c
blob01bc00762d9edc5eae3d82cc114d18c67770a161
1 /*
2 Unix SMB/CIFS implementation.
4 smbd-specific dcerpc server code
6 Copyright (C) Andrew Tridgell 2003-2005
7 Copyright (C) Stefan (metze) Metzmacher 2004-2005
8 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2004,2007
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "librpc/gen_ndr/ndr_dcerpc.h"
26 #include "auth/auth.h"
27 #include "auth/gensec/gensec.h"
28 #include "../lib/util/dlinklist.h"
29 #include "rpc_server/dcerpc_server.h"
30 #include "rpc_server/dcerpc_server_proto.h"
31 #include "lib/events/events.h"
32 #include "smbd/service_task.h"
33 #include "smbd/service_stream.h"
34 #include "smbd/service.h"
35 #include "system/filesys.h"
36 #include "libcli/security/security.h"
37 #include "lib/socket/socket.h"
38 #include "lib/messaging/irpc.h"
39 #include "system/network.h"
40 #include "lib/socket/netif.h"
41 #include "param/param.h"
42 #include "../lib/tsocket/tsocket.h"
43 #include "librpc/rpc/dcerpc_proto.h"
44 #include "../lib/util/tevent_ntstatus.h"
45 #include "libcli/raw/smb.h"
46 #include "../libcli/named_pipe_auth/npa_tstream.h"
48 struct dcesrv_socket_context {
49 const struct dcesrv_endpoint *endpoint;
50 struct dcesrv_context *dcesrv_ctx;
53 static void dcesrv_terminate_connection(struct dcesrv_connection *dce_conn, const char *reason)
55 struct stream_connection *srv_conn;
56 srv_conn = talloc_get_type(dce_conn->transport.private_data,
57 struct stream_connection);
59 stream_terminate_connection(srv_conn, reason);
62 static void dcesrv_sock_reply_done(struct tevent_req *subreq);
64 struct dcesrv_sock_reply_state {
65 struct dcesrv_connection *dce_conn;
66 struct dcesrv_call_state *call;
67 struct iovec iov;
70 static void dcesrv_sock_report_output_data(struct dcesrv_connection *dce_conn)
72 struct dcesrv_call_state *call;
74 call = dce_conn->call_list;
75 if (!call || !call->replies) {
76 return;
79 while (call->replies) {
80 struct data_blob_list_item *rep = call->replies;
81 struct dcesrv_sock_reply_state *substate;
82 struct tevent_req *subreq;
84 substate = talloc(call, struct dcesrv_sock_reply_state);
85 if (!substate) {
86 dcesrv_terminate_connection(dce_conn, "no memory");
87 return;
90 substate->dce_conn = dce_conn;
91 substate->call = NULL;
93 DLIST_REMOVE(call->replies, rep);
95 if (call->replies == NULL) {
96 substate->call = call;
99 substate->iov.iov_base = rep->blob.data;
100 substate->iov.iov_len = rep->blob.length;
102 subreq = tstream_writev_queue_send(substate,
103 dce_conn->event_ctx,
104 dce_conn->stream,
105 dce_conn->send_queue,
106 &substate->iov, 1);
107 if (!subreq) {
108 dcesrv_terminate_connection(dce_conn, "no memory");
109 return;
111 tevent_req_set_callback(subreq, dcesrv_sock_reply_done,
112 substate);
115 DLIST_REMOVE(call->conn->call_list, call);
116 call->list = DCESRV_LIST_NONE;
119 static void dcesrv_sock_reply_done(struct tevent_req *subreq)
121 struct dcesrv_sock_reply_state *substate = tevent_req_callback_data(subreq,
122 struct dcesrv_sock_reply_state);
123 int ret;
124 int sys_errno;
125 NTSTATUS status;
126 struct dcesrv_call_state *call = substate->call;
128 ret = tstream_writev_queue_recv(subreq, &sys_errno);
129 TALLOC_FREE(subreq);
130 if (ret == -1) {
131 status = map_nt_error_from_unix(sys_errno);
132 dcesrv_terminate_connection(substate->dce_conn, nt_errstr(status));
133 return;
136 talloc_free(substate);
137 if (call) {
138 talloc_free(call);
142 static struct socket_address *dcesrv_sock_get_my_addr(struct dcesrv_connection *dcesrv_conn, TALLOC_CTX *mem_ctx)
144 struct stream_connection *srv_conn;
145 srv_conn = talloc_get_type(dcesrv_conn->transport.private_data,
146 struct stream_connection);
148 return socket_get_my_addr(srv_conn->socket, mem_ctx);
151 static struct socket_address *dcesrv_sock_get_peer_addr(struct dcesrv_connection *dcesrv_conn, TALLOC_CTX *mem_ctx)
153 struct stream_connection *srv_conn;
154 srv_conn = talloc_get_type(dcesrv_conn->transport.private_data,
155 struct stream_connection);
157 return socket_get_peer_addr(srv_conn->socket, mem_ctx);
160 struct dcerpc_read_ncacn_packet_state {
161 struct {
162 struct smb_iconv_convenience *smb_iconv_c;
163 } caller;
164 DATA_BLOB buffer;
165 struct ncacn_packet *pkt;
168 static int dcerpc_read_ncacn_packet_next_vector(struct tstream_context *stream,
169 void *private_data,
170 TALLOC_CTX *mem_ctx,
171 struct iovec **_vector,
172 size_t *_count);
173 static void dcerpc_read_ncacn_packet_done(struct tevent_req *subreq);
175 static struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
176 struct tevent_context *ev,
177 struct tstream_context *stream,
178 struct smb_iconv_convenience *ic)
180 struct tevent_req *req;
181 struct dcerpc_read_ncacn_packet_state *state;
182 struct tevent_req *subreq;
184 req = tevent_req_create(mem_ctx, &state,
185 struct dcerpc_read_ncacn_packet_state);
186 if (req == NULL) {
187 return NULL;
190 state->caller.smb_iconv_c = ic;
191 state->buffer = data_blob_const(NULL, 0);
192 state->pkt = talloc(state, struct ncacn_packet);
193 if (tevent_req_nomem(state->pkt, req)) {
194 goto post;
197 subreq = tstream_readv_pdu_send(state, ev,
198 stream,
199 dcerpc_read_ncacn_packet_next_vector,
200 state);
201 if (tevent_req_nomem(subreq, req)) {
202 goto post;
204 tevent_req_set_callback(subreq, dcerpc_read_ncacn_packet_done, req);
206 return req;
207 post:
208 tevent_req_post(req, ev);
209 return req;
212 static int dcerpc_read_ncacn_packet_next_vector(struct tstream_context *stream,
213 void *private_data,
214 TALLOC_CTX *mem_ctx,
215 struct iovec **_vector,
216 size_t *_count)
218 struct dcerpc_read_ncacn_packet_state *state =
219 talloc_get_type_abort(private_data,
220 struct dcerpc_read_ncacn_packet_state);
221 struct iovec *vector;
222 off_t ofs = 0;
224 if (state->buffer.length == 0) {
225 /* first get enough to read the fragment length */
226 ofs = 0;
227 state->buffer.length = DCERPC_FRAG_LEN_OFFSET + 2;
228 state->buffer.data = talloc_array(state, uint8_t,
229 state->buffer.length);
230 if (!state->buffer.data) {
231 return -1;
233 } else if (state->buffer.length == (DCERPC_FRAG_LEN_OFFSET + 2)) {
234 /* now read the fragment length and allocate the full buffer */
235 size_t frag_len = dcerpc_get_frag_length(&state->buffer);
237 ofs = state->buffer.length;
239 state->buffer.data = talloc_realloc(state,
240 state->buffer.data,
241 uint8_t, frag_len);
242 if (!state->buffer.data) {
243 return -1;
245 state->buffer.length = frag_len;
246 } else {
247 /* if we reach this we have a full fragment */
248 *_vector = NULL;
249 *_count = 0;
250 return 0;
253 /* now create the vector that we want to be filled */
254 vector = talloc_array(mem_ctx, struct iovec, 1);
255 if (!vector) {
256 return -1;
259 vector[0].iov_base = state->buffer.data + ofs;
260 vector[0].iov_len = state->buffer.length - ofs;
262 *_vector = vector;
263 *_count = 1;
264 return 0;
267 static void dcerpc_read_ncacn_packet_done(struct tevent_req *subreq)
269 struct tevent_req *req = tevent_req_callback_data(subreq,
270 struct tevent_req);
271 struct dcerpc_read_ncacn_packet_state *state = tevent_req_data(req,
272 struct dcerpc_read_ncacn_packet_state);
273 int ret;
274 int sys_errno;
275 struct ndr_pull *ndr;
276 enum ndr_err_code ndr_err;
277 NTSTATUS status;
279 ret = tstream_readv_pdu_recv(subreq, &sys_errno);
280 TALLOC_FREE(subreq);
281 if (ret == -1) {
282 status = map_nt_error_from_unix(sys_errno);
283 tevent_req_nterror(req, status);
284 return;
287 ndr = ndr_pull_init_blob(&state->buffer,
288 state->pkt,
289 state->caller.smb_iconv_c);
290 if (tevent_req_nomem(ndr, req)) {
291 return;
294 if (!(CVAL(ndr->data, DCERPC_DREP_OFFSET) & DCERPC_DREP_LE)) {
295 ndr->flags |= LIBNDR_FLAG_BIGENDIAN;
298 if (CVAL(ndr->data, DCERPC_PFC_OFFSET) & DCERPC_PFC_FLAG_OBJECT_UUID) {
299 ndr->flags |= LIBNDR_FLAG_OBJECT_PRESENT;
302 ndr_err = ndr_pull_ncacn_packet(ndr, NDR_SCALARS|NDR_BUFFERS, state->pkt);
303 TALLOC_FREE(ndr);
304 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
305 status = ndr_map_error2ntstatus(ndr_err);
306 tevent_req_nterror(req, status);
307 return;
310 tevent_req_done(req);
313 static NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
314 TALLOC_CTX *mem_ctx,
315 struct ncacn_packet **pkt,
316 DATA_BLOB *buffer)
318 struct dcerpc_read_ncacn_packet_state *state = tevent_req_data(req,
319 struct dcerpc_read_ncacn_packet_state);
320 NTSTATUS status;
322 if (tevent_req_is_nterror(req, &status)) {
323 tevent_req_received(req);
324 return status;
327 *pkt = talloc_move(mem_ctx, &state->pkt);
328 if (buffer) {
329 buffer->data = talloc_move(mem_ctx, &state->buffer.data);
330 buffer->length = state->buffer.length;
333 tevent_req_received(req);
334 return NT_STATUS_OK;
337 static void dcesrv_read_fragment_done(struct tevent_req *subreq);
339 static void dcesrv_sock_accept(struct stream_connection *srv_conn)
341 NTSTATUS status;
342 struct dcesrv_socket_context *dcesrv_sock =
343 talloc_get_type(srv_conn->private_data, struct dcesrv_socket_context);
344 struct dcesrv_connection *dcesrv_conn = NULL;
345 int ret;
346 struct tevent_req *subreq;
347 struct loadparm_context *lp_ctx = dcesrv_sock->dcesrv_ctx->lp_ctx;
349 if (!srv_conn->session_info) {
350 status = auth_anonymous_session_info(srv_conn,
351 srv_conn->event.ctx,
352 lp_ctx,
353 &srv_conn->session_info);
354 if (!NT_STATUS_IS_OK(status)) {
355 DEBUG(0,("dcesrv_sock_accept: auth_anonymous_session_info failed: %s\n",
356 nt_errstr(status)));
357 stream_terminate_connection(srv_conn, nt_errstr(status));
358 return;
362 status = dcesrv_endpoint_connect(dcesrv_sock->dcesrv_ctx,
363 srv_conn,
364 dcesrv_sock->endpoint,
365 srv_conn->session_info,
366 srv_conn->event.ctx,
367 srv_conn->msg_ctx,
368 srv_conn->server_id,
369 DCESRV_CALL_STATE_FLAG_MAY_ASYNC,
370 &dcesrv_conn);
371 if (!NT_STATUS_IS_OK(status)) {
372 DEBUG(0,("dcesrv_sock_accept: dcesrv_endpoint_connect failed: %s\n",
373 nt_errstr(status)));
374 stream_terminate_connection(srv_conn, nt_errstr(status));
375 return;
378 dcesrv_conn->transport.private_data = srv_conn;
379 dcesrv_conn->transport.report_output_data = dcesrv_sock_report_output_data;
380 dcesrv_conn->transport.get_my_addr = dcesrv_sock_get_my_addr;
381 dcesrv_conn->transport.get_peer_addr = dcesrv_sock_get_peer_addr;
383 TALLOC_FREE(srv_conn->event.fde);
385 dcesrv_conn->send_queue = tevent_queue_create(dcesrv_conn, "dcesrv send queue");
386 if (!dcesrv_conn->send_queue) {
387 status = NT_STATUS_NO_MEMORY;
388 DEBUG(0,("dcesrv_sock_accept: tevent_queue_create(%s)\n",
389 nt_errstr(status)));
390 stream_terminate_connection(srv_conn, nt_errstr(status));
391 return;
394 if (dcesrv_sock->endpoint->ep_description->transport == NCACN_NP) {
395 dcesrv_conn->auth_state.session_key = dcesrv_inherited_session_key;
396 ret = tstream_npa_existing_socket(dcesrv_conn,
397 socket_get_fd(srv_conn->socket),
398 FILE_TYPE_MESSAGE_MODE_PIPE,
399 &dcesrv_conn->stream);
400 } else {
401 ret = tstream_bsd_existing_socket(dcesrv_conn,
402 socket_get_fd(srv_conn->socket),
403 &dcesrv_conn->stream);
405 if (ret == -1) {
406 status = map_nt_error_from_unix(errno);
407 DEBUG(0,("dcesrv_sock_accept: failed to setup tstream: %s\n",
408 nt_errstr(status)));
409 stream_terminate_connection(srv_conn, nt_errstr(status));
410 return;
413 srv_conn->private_data = dcesrv_conn;
415 irpc_add_name(srv_conn->msg_ctx, "rpc_server");
417 subreq = dcerpc_read_ncacn_packet_send(dcesrv_conn,
418 dcesrv_conn->event_ctx,
419 dcesrv_conn->stream,
420 lp_iconv_convenience(lp_ctx));
421 if (!subreq) {
422 status = NT_STATUS_NO_MEMORY;
423 DEBUG(0,("dcesrv_sock_accept: dcerpc_read_fragment_buffer_send(%s)\n",
424 nt_errstr(status)));
425 stream_terminate_connection(srv_conn, nt_errstr(status));
426 return;
428 tevent_req_set_callback(subreq, dcesrv_read_fragment_done, dcesrv_conn);
430 return;
433 static void dcesrv_read_fragment_done(struct tevent_req *subreq)
435 struct dcesrv_connection *dce_conn = tevent_req_callback_data(subreq,
436 struct dcesrv_connection);
437 struct ncacn_packet *pkt;
438 DATA_BLOB buffer;
439 NTSTATUS status;
440 struct loadparm_context *lp_ctx = dce_conn->dce_ctx->lp_ctx;
442 status = dcerpc_read_ncacn_packet_recv(subreq, dce_conn,
443 &pkt, &buffer);
444 TALLOC_FREE(subreq);
445 if (!NT_STATUS_IS_OK(status)) {
446 dcesrv_terminate_connection(dce_conn, nt_errstr(status));
447 return;
450 status = dcesrv_process_ncacn_packet(dce_conn, pkt, buffer);
451 if (!NT_STATUS_IS_OK(status)) {
452 dcesrv_terminate_connection(dce_conn, nt_errstr(status));
453 return;
456 subreq = dcerpc_read_ncacn_packet_send(dce_conn,
457 dce_conn->event_ctx,
458 dce_conn->stream,
459 lp_iconv_convenience(lp_ctx));
460 if (!subreq) {
461 status = NT_STATUS_NO_MEMORY;
462 dcesrv_terminate_connection(dce_conn, nt_errstr(status));
463 return;
465 tevent_req_set_callback(subreq, dcesrv_read_fragment_done, dce_conn);
468 static void dcesrv_sock_recv(struct stream_connection *conn, uint16_t flags)
470 struct dcesrv_connection *dce_conn = talloc_get_type(conn->private_data,
471 struct dcesrv_connection);
472 dcesrv_terminate_connection(dce_conn, "dcesrv_sock_recv triggered");
475 static void dcesrv_sock_send(struct stream_connection *conn, uint16_t flags)
477 struct dcesrv_connection *dce_conn = talloc_get_type(conn->private_data,
478 struct dcesrv_connection);
479 dcesrv_terminate_connection(dce_conn, "dcesrv_sock_send triggered");
483 static const struct stream_server_ops dcesrv_stream_ops = {
484 .name = "rpc",
485 .accept_connection = dcesrv_sock_accept,
486 .recv_handler = dcesrv_sock_recv,
487 .send_handler = dcesrv_sock_send,
492 static NTSTATUS dcesrv_add_ep_unix(struct dcesrv_context *dce_ctx,
493 struct loadparm_context *lp_ctx,
494 struct dcesrv_endpoint *e,
495 struct tevent_context *event_ctx, const struct model_ops *model_ops)
497 struct dcesrv_socket_context *dcesrv_sock;
498 uint16_t port = 1;
499 NTSTATUS status;
501 dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context);
502 NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock);
504 /* remember the endpoint of this socket */
505 dcesrv_sock->endpoint = e;
506 dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx);
508 status = stream_setup_socket(event_ctx, lp_ctx,
509 model_ops, &dcesrv_stream_ops,
510 "unix", e->ep_description->endpoint, &port,
511 lp_socket_options(lp_ctx),
512 dcesrv_sock);
513 if (!NT_STATUS_IS_OK(status)) {
514 DEBUG(0,("service_setup_stream_socket(path=%s) failed - %s\n",
515 e->ep_description->endpoint, nt_errstr(status)));
518 return status;
521 static NTSTATUS dcesrv_add_ep_ncalrpc(struct dcesrv_context *dce_ctx,
522 struct loadparm_context *lp_ctx,
523 struct dcesrv_endpoint *e,
524 struct tevent_context *event_ctx, const struct model_ops *model_ops)
526 struct dcesrv_socket_context *dcesrv_sock;
527 uint16_t port = 1;
528 char *full_path;
529 NTSTATUS status;
531 if (!e->ep_description->endpoint) {
532 /* No identifier specified: use DEFAULT.
533 * DO NOT hardcode this value anywhere else. Rather, specify
534 * no endpoint and let the epmapper worry about it. */
535 e->ep_description->endpoint = talloc_strdup(dce_ctx, "DEFAULT");
538 full_path = talloc_asprintf(dce_ctx, "%s/%s", lp_ncalrpc_dir(lp_ctx),
539 e->ep_description->endpoint);
541 dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context);
542 NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock);
544 /* remember the endpoint of this socket */
545 dcesrv_sock->endpoint = e;
546 dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx);
548 status = stream_setup_socket(event_ctx, lp_ctx,
549 model_ops, &dcesrv_stream_ops,
550 "unix", full_path, &port,
551 lp_socket_options(lp_ctx),
552 dcesrv_sock);
553 if (!NT_STATUS_IS_OK(status)) {
554 DEBUG(0,("service_setup_stream_socket(identifier=%s,path=%s) failed - %s\n",
555 e->ep_description->endpoint, full_path, nt_errstr(status)));
557 return status;
560 static NTSTATUS dcesrv_add_ep_np(struct dcesrv_context *dce_ctx,
561 struct loadparm_context *lp_ctx,
562 struct dcesrv_endpoint *e,
563 struct tevent_context *event_ctx, const struct model_ops *model_ops)
565 struct dcesrv_socket_context *dcesrv_sock;
566 NTSTATUS status;
568 if (e->ep_description->endpoint == NULL) {
569 DEBUG(0, ("Endpoint mandatory for named pipes\n"));
570 return NT_STATUS_INVALID_PARAMETER;
573 dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context);
574 NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock);
576 /* remember the endpoint of this socket */
577 dcesrv_sock->endpoint = e;
578 dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx);
580 status = stream_setup_named_pipe(event_ctx, lp_ctx,
581 model_ops, &dcesrv_stream_ops,
582 e->ep_description->endpoint, dcesrv_sock);
583 if (!NT_STATUS_IS_OK(status)) {
584 DEBUG(0,("stream_setup_named_pipe(pipe=%s) failed - %s\n",
585 e->ep_description->endpoint, nt_errstr(status)));
586 return status;
589 return NT_STATUS_OK;
593 add a socket address to the list of events, one event per dcerpc endpoint
595 static NTSTATUS add_socket_rpc_tcp_iface(struct dcesrv_context *dce_ctx, struct dcesrv_endpoint *e,
596 struct tevent_context *event_ctx, const struct model_ops *model_ops,
597 const char *address)
599 struct dcesrv_socket_context *dcesrv_sock;
600 uint16_t port = 0;
601 NTSTATUS status;
603 if (e->ep_description->endpoint) {
604 port = atoi(e->ep_description->endpoint);
607 dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context);
608 NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock);
610 /* remember the endpoint of this socket */
611 dcesrv_sock->endpoint = e;
612 dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx);
614 status = stream_setup_socket(event_ctx, dce_ctx->lp_ctx,
615 model_ops, &dcesrv_stream_ops,
616 "ipv4", address, &port,
617 lp_socket_options(dce_ctx->lp_ctx),
618 dcesrv_sock);
619 if (!NT_STATUS_IS_OK(status)) {
620 DEBUG(0,("service_setup_stream_socket(address=%s,port=%u) failed - %s\n",
621 address, port, nt_errstr(status)));
624 if (e->ep_description->endpoint == NULL) {
625 e->ep_description->endpoint = talloc_asprintf(dce_ctx, "%d", port);
628 return status;
631 static NTSTATUS dcesrv_add_ep_tcp(struct dcesrv_context *dce_ctx,
632 struct loadparm_context *lp_ctx,
633 struct dcesrv_endpoint *e,
634 struct tevent_context *event_ctx, const struct model_ops *model_ops)
636 NTSTATUS status;
638 /* Add TCP/IP sockets */
639 if (lp_interfaces(lp_ctx) && lp_bind_interfaces_only(lp_ctx)) {
640 int num_interfaces;
641 int i;
642 struct interface *ifaces;
644 load_interfaces(dce_ctx, lp_interfaces(lp_ctx), &ifaces);
646 num_interfaces = iface_count(ifaces);
647 for(i = 0; i < num_interfaces; i++) {
648 const char *address = iface_n_ip(ifaces, i);
649 status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops, address);
650 NT_STATUS_NOT_OK_RETURN(status);
652 } else {
653 status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops,
654 lp_socket_address(lp_ctx));
655 NT_STATUS_NOT_OK_RETURN(status);
658 return NT_STATUS_OK;
662 static NTSTATUS dcesrv_add_ep(struct dcesrv_context *dce_ctx,
663 struct loadparm_context *lp_ctx,
664 struct dcesrv_endpoint *e,
665 struct tevent_context *event_ctx, const struct model_ops *model_ops)
667 switch (e->ep_description->transport) {
668 case NCACN_UNIX_STREAM:
669 return dcesrv_add_ep_unix(dce_ctx, lp_ctx, e, event_ctx, model_ops);
671 case NCALRPC:
672 return dcesrv_add_ep_ncalrpc(dce_ctx, lp_ctx, e, event_ctx, model_ops);
674 case NCACN_IP_TCP:
675 return dcesrv_add_ep_tcp(dce_ctx, lp_ctx, e, event_ctx, model_ops);
677 case NCACN_NP:
678 return dcesrv_add_ep_np(dce_ctx, lp_ctx, e, event_ctx, model_ops);
680 default:
681 return NT_STATUS_NOT_SUPPORTED;
686 open the dcerpc server sockets
688 static void dcesrv_task_init(struct task_server *task)
690 NTSTATUS status;
691 struct dcesrv_context *dce_ctx;
692 struct dcesrv_endpoint *e;
694 dcerpc_server_init(task->lp_ctx);
696 task_server_set_title(task, "task[dcesrv]");
698 status = dcesrv_init_context(task->event_ctx,
699 task->lp_ctx,
700 lp_dcerpc_endpoint_servers(task->lp_ctx),
701 &dce_ctx);
702 if (!NT_STATUS_IS_OK(status)) goto failed;
704 /* Make sure the directory for NCALRPC exists */
705 if (!directory_exist(lp_ncalrpc_dir(task->lp_ctx))) {
706 mkdir(lp_ncalrpc_dir(task->lp_ctx), 0755);
709 for (e=dce_ctx->endpoint_list;e;e=e->next) {
710 status = dcesrv_add_ep(dce_ctx, task->lp_ctx, e, task->event_ctx, task->model_ops);
711 if (!NT_STATUS_IS_OK(status)) goto failed;
714 return;
715 failed:
716 task_server_terminate(task, "Failed to startup dcerpc server task");
719 NTSTATUS server_service_rpc_init(void)
722 return register_server_service("rpc", dcesrv_task_init);