diff options
-rw-r--r-- | source4/rpc_server/dcerpc_server.c | 450 | ||||
-rw-r--r-- | source4/rpc_server/dcerpc_server.h | 5 | ||||
-rw-r--r-- | source4/rpc_server/service_rpc.c | 440 | ||||
-rw-r--r-- | source4/rpc_server/wscript_build | 10 | ||||
-rw-r--r-- | source4/smbd/service_stream.h | 2 | ||||
-rw-r--r-- | source4/torture/wscript_build | 5 |
6 files changed, 464 insertions, 448 deletions
diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c index 8260f1ec99..3064e2944b 100644 --- a/source4/rpc_server/dcerpc_server.c +++ b/source4/rpc_server/dcerpc_server.c @@ -30,6 +30,13 @@ #include "system/filesys.h" #include "libcli/security/security.h" #include "param/param.h" +#include "../lib/tsocket/tsocket.h" +#include "../libcli/named_pipe_auth/npa_tstream.h" +#include "smbd/service_stream.h" +#include "../lib/tsocket/tsocket.h" +#include "lib/socket/socket.h" +#include "smbd/process_model.h" +#include "lib/messaging/irpc.h" /* this is only used when the client asks for an unknown interface */ #define DUMMY_ASSOC_GROUP 0x0FFFFFFF @@ -1440,3 +1447,446 @@ const struct dcesrv_critical_sizes *dcerpc_module_version(void) return &critical_sizes; } +static void dcesrv_terminate_connection(struct dcesrv_connection *dce_conn, const char *reason) +{ + struct stream_connection *srv_conn; + srv_conn = talloc_get_type(dce_conn->transport.private_data, + struct stream_connection); + + stream_terminate_connection(srv_conn, reason); +} + +struct dcesrv_sock_reply_state { + struct dcesrv_connection *dce_conn; + struct dcesrv_call_state *call; + struct iovec iov; +}; + +static void dcesrv_sock_reply_done(struct tevent_req *subreq); + +static void dcesrv_sock_report_output_data(struct dcesrv_connection *dce_conn) +{ + struct dcesrv_call_state *call; + + call = dce_conn->call_list; + if (!call || !call->replies) { + return; + } + + while (call->replies) { + struct data_blob_list_item *rep = call->replies; + struct dcesrv_sock_reply_state *substate; + struct tevent_req *subreq; + + substate = talloc(call, struct dcesrv_sock_reply_state); + if (!substate) { + dcesrv_terminate_connection(dce_conn, "no memory"); + return; + } + + substate->dce_conn = dce_conn; + substate->call = NULL; + + DLIST_REMOVE(call->replies, rep); + + if (call->replies == NULL) { + substate->call = call; + } + + substate->iov.iov_base = (void *) rep->blob.data; + substate->iov.iov_len = rep->blob.length; + + subreq = tstream_writev_queue_send(substate, + dce_conn->event_ctx, + dce_conn->stream, + dce_conn->send_queue, + &substate->iov, 1); + if (!subreq) { + dcesrv_terminate_connection(dce_conn, "no memory"); + return; + } + tevent_req_set_callback(subreq, dcesrv_sock_reply_done, + substate); + } + + DLIST_REMOVE(call->conn->call_list, call); + call->list = DCESRV_LIST_NONE; +} + +static void dcesrv_sock_reply_done(struct tevent_req *subreq) +{ + struct dcesrv_sock_reply_state *substate = tevent_req_callback_data(subreq, + struct dcesrv_sock_reply_state); + int ret; + int sys_errno; + NTSTATUS status; + struct dcesrv_call_state *call = substate->call; + + ret = tstream_writev_queue_recv(subreq, &sys_errno); + TALLOC_FREE(subreq); + if (ret == -1) { + status = map_nt_error_from_unix(sys_errno); + dcesrv_terminate_connection(substate->dce_conn, nt_errstr(status)); + return; + } + + talloc_free(substate); + if (call) { + talloc_free(call); + } +} + + + + +struct dcesrv_socket_context { + const struct dcesrv_endpoint *endpoint; + struct dcesrv_context *dcesrv_ctx; +}; + + +static void dcesrv_read_fragment_done(struct tevent_req *subreq); + +static void dcesrv_sock_accept(struct stream_connection *srv_conn) +{ + NTSTATUS status; + struct dcesrv_socket_context *dcesrv_sock = + talloc_get_type(srv_conn->private_data, struct dcesrv_socket_context); + struct dcesrv_connection *dcesrv_conn = NULL; + int ret; + struct tevent_req *subreq; + struct loadparm_context *lp_ctx = dcesrv_sock->dcesrv_ctx->lp_ctx; + + if (!srv_conn->session_info) { + status = auth_anonymous_session_info(srv_conn, + lp_ctx, + &srv_conn->session_info); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0,("dcesrv_sock_accept: auth_anonymous_session_info failed: %s\n", + nt_errstr(status))); + stream_terminate_connection(srv_conn, nt_errstr(status)); + return; + } + } + + status = dcesrv_endpoint_connect(dcesrv_sock->dcesrv_ctx, + srv_conn, + dcesrv_sock->endpoint, + srv_conn->session_info, + srv_conn->event.ctx, + srv_conn->msg_ctx, + srv_conn->server_id, + DCESRV_CALL_STATE_FLAG_MAY_ASYNC, + &dcesrv_conn); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0,("dcesrv_sock_accept: dcesrv_endpoint_connect failed: %s\n", + nt_errstr(status))); + stream_terminate_connection(srv_conn, nt_errstr(status)); + return; + } + + dcesrv_conn->transport.private_data = srv_conn; + dcesrv_conn->transport.report_output_data = dcesrv_sock_report_output_data; + + TALLOC_FREE(srv_conn->event.fde); + + dcesrv_conn->send_queue = tevent_queue_create(dcesrv_conn, "dcesrv send queue"); + if (!dcesrv_conn->send_queue) { + status = NT_STATUS_NO_MEMORY; + DEBUG(0,("dcesrv_sock_accept: tevent_queue_create(%s)\n", + nt_errstr(status))); + stream_terminate_connection(srv_conn, nt_errstr(status)); + return; + } + + if (dcesrv_sock->endpoint->ep_description->transport == NCACN_NP) { + dcesrv_conn->auth_state.session_key = dcesrv_inherited_session_key; + dcesrv_conn->stream = talloc_move(dcesrv_conn, + &srv_conn->tstream); + } else { + ret = tstream_bsd_existing_socket(dcesrv_conn, + socket_get_fd(srv_conn->socket), + &dcesrv_conn->stream); + if (ret == -1) { + status = map_nt_error_from_unix(errno); + DEBUG(0, ("dcesrv_sock_accept: " + "failed to setup tstream: %s\n", + nt_errstr(status))); + stream_terminate_connection(srv_conn, nt_errstr(status)); + return; + } + socket_set_flags(srv_conn->socket, SOCKET_FLAG_NOCLOSE); + } + + dcesrv_conn->local_address = srv_conn->local_address; + dcesrv_conn->remote_address = srv_conn->remote_address; + + srv_conn->private_data = dcesrv_conn; + + irpc_add_name(srv_conn->msg_ctx, "rpc_server"); + + subreq = dcerpc_read_ncacn_packet_send(dcesrv_conn, + dcesrv_conn->event_ctx, + dcesrv_conn->stream); + if (!subreq) { + status = NT_STATUS_NO_MEMORY; + DEBUG(0,("dcesrv_sock_accept: dcerpc_read_fragment_buffer_send(%s)\n", + nt_errstr(status))); + stream_terminate_connection(srv_conn, nt_errstr(status)); + return; + } + tevent_req_set_callback(subreq, dcesrv_read_fragment_done, dcesrv_conn); + + return; +} + +static void dcesrv_read_fragment_done(struct tevent_req *subreq) +{ + struct dcesrv_connection *dce_conn = tevent_req_callback_data(subreq, + struct dcesrv_connection); + struct ncacn_packet *pkt; + DATA_BLOB buffer; + NTSTATUS status; + + status = dcerpc_read_ncacn_packet_recv(subreq, dce_conn, + &pkt, &buffer); + TALLOC_FREE(subreq); + if (!NT_STATUS_IS_OK(status)) { + dcesrv_terminate_connection(dce_conn, nt_errstr(status)); + return; + } + + status = dcesrv_process_ncacn_packet(dce_conn, pkt, buffer); + if (!NT_STATUS_IS_OK(status)) { + dcesrv_terminate_connection(dce_conn, nt_errstr(status)); + return; + } + + subreq = dcerpc_read_ncacn_packet_send(dce_conn, + dce_conn->event_ctx, + dce_conn->stream); + if (!subreq) { + status = NT_STATUS_NO_MEMORY; + dcesrv_terminate_connection(dce_conn, nt_errstr(status)); + return; + } + tevent_req_set_callback(subreq, dcesrv_read_fragment_done, dce_conn); +} + +static void dcesrv_sock_recv(struct stream_connection *conn, uint16_t flags) +{ + struct dcesrv_connection *dce_conn = talloc_get_type(conn->private_data, + struct dcesrv_connection); + dcesrv_terminate_connection(dce_conn, "dcesrv_sock_recv triggered"); +} + +static void dcesrv_sock_send(struct stream_connection *conn, uint16_t flags) +{ + struct dcesrv_connection *dce_conn = talloc_get_type(conn->private_data, + struct dcesrv_connection); + dcesrv_terminate_connection(dce_conn, "dcesrv_sock_send triggered"); +} + + +static const struct stream_server_ops dcesrv_stream_ops = { + .name = "rpc", + .accept_connection = dcesrv_sock_accept, + .recv_handler = dcesrv_sock_recv, + .send_handler = dcesrv_sock_send, +}; + +static NTSTATUS dcesrv_add_ep_unix(struct dcesrv_context *dce_ctx, + struct loadparm_context *lp_ctx, + struct dcesrv_endpoint *e, + struct tevent_context *event_ctx, const struct model_ops *model_ops) +{ + struct dcesrv_socket_context *dcesrv_sock; + uint16_t port = 1; + NTSTATUS status; + + dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context); + NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock); + + /* remember the endpoint of this socket */ + dcesrv_sock->endpoint = e; + dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx); + + status = stream_setup_socket(event_ctx, lp_ctx, + model_ops, &dcesrv_stream_ops, + "unix", e->ep_description->endpoint, &port, + lpcfg_socket_options(lp_ctx), + dcesrv_sock); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0,("service_setup_stream_socket(path=%s) failed - %s\n", + e->ep_description->endpoint, nt_errstr(status))); + } + + return status; +} + +static NTSTATUS dcesrv_add_ep_ncalrpc(struct dcesrv_context *dce_ctx, + struct loadparm_context *lp_ctx, + struct dcesrv_endpoint *e, + struct tevent_context *event_ctx, const struct model_ops *model_ops) +{ + struct dcesrv_socket_context *dcesrv_sock; + uint16_t port = 1; + char *full_path; + NTSTATUS status; + + if (!e->ep_description->endpoint) { + /* No identifier specified: use DEFAULT. + * DO NOT hardcode this value anywhere else. Rather, specify + * no endpoint and let the epmapper worry about it. */ + e->ep_description->endpoint = talloc_strdup(dce_ctx, "DEFAULT"); + } + + full_path = talloc_asprintf(dce_ctx, "%s/%s", lpcfg_ncalrpc_dir(lp_ctx), + e->ep_description->endpoint); + + dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context); + NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock); + + /* remember the endpoint of this socket */ + dcesrv_sock->endpoint = e; + dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx); + + status = stream_setup_socket(event_ctx, lp_ctx, + model_ops, &dcesrv_stream_ops, + "unix", full_path, &port, + lpcfg_socket_options(lp_ctx), + dcesrv_sock); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0,("service_setup_stream_socket(identifier=%s,path=%s) failed - %s\n", + e->ep_description->endpoint, full_path, nt_errstr(status))); + } + return status; +} + +static NTSTATUS dcesrv_add_ep_np(struct dcesrv_context *dce_ctx, + struct loadparm_context *lp_ctx, + struct dcesrv_endpoint *e, + struct tevent_context *event_ctx, const struct model_ops *model_ops) +{ + struct dcesrv_socket_context *dcesrv_sock; + NTSTATUS status; + + if (e->ep_description->endpoint == NULL) { + DEBUG(0, ("Endpoint mandatory for named pipes\n")); + return NT_STATUS_INVALID_PARAMETER; + } + + dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context); + NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock); + + /* remember the endpoint of this socket */ + dcesrv_sock->endpoint = e; + dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx); + + status = tstream_setup_named_pipe(event_ctx, lp_ctx, + model_ops, &dcesrv_stream_ops, + e->ep_description->endpoint, + dcesrv_sock); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0,("stream_setup_named_pipe(pipe=%s) failed - %s\n", + e->ep_description->endpoint, nt_errstr(status))); + return status; + } + + return NT_STATUS_OK; +} + +/* + add a socket address to the list of events, one event per dcerpc endpoint +*/ +static NTSTATUS add_socket_rpc_tcp_iface(struct dcesrv_context *dce_ctx, struct dcesrv_endpoint *e, + struct tevent_context *event_ctx, const struct model_ops *model_ops, + const char *address) +{ + struct dcesrv_socket_context *dcesrv_sock; + uint16_t port = 0; + NTSTATUS status; + + if (e->ep_description->endpoint) { + port = atoi(e->ep_description->endpoint); + } + + dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context); + NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock); + + /* remember the endpoint of this socket */ + dcesrv_sock->endpoint = e; + dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx); + + status = stream_setup_socket(event_ctx, dce_ctx->lp_ctx, + model_ops, &dcesrv_stream_ops, + "ipv4", address, &port, + lpcfg_socket_options(dce_ctx->lp_ctx), + dcesrv_sock); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0,("service_setup_stream_socket(address=%s,port=%u) failed - %s\n", + address, port, nt_errstr(status))); + } + + if (e->ep_description->endpoint == NULL) { + e->ep_description->endpoint = talloc_asprintf(dce_ctx, "%d", port); + } + + return status; +} + +#include "lib/socket/netif.h" /* Included here to work around the fact that socket_wrapper redefines bind() */ + +static NTSTATUS dcesrv_add_ep_tcp(struct dcesrv_context *dce_ctx, + struct loadparm_context *lp_ctx, + struct dcesrv_endpoint *e, + struct tevent_context *event_ctx, const struct model_ops *model_ops) +{ + NTSTATUS status; + + /* Add TCP/IP sockets */ + if (lpcfg_interfaces(lp_ctx) && lpcfg_bind_interfaces_only(lp_ctx)) { + int num_interfaces; + int i; + struct interface *ifaces; + + load_interfaces(dce_ctx, lpcfg_interfaces(lp_ctx), &ifaces); + + num_interfaces = iface_count(ifaces); + for(i = 0; i < num_interfaces; i++) { + const char *address = iface_n_ip(ifaces, i); + status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops, address); + NT_STATUS_NOT_OK_RETURN(status); + } + } else { + status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops, + lpcfg_socket_address(lp_ctx)); + NT_STATUS_NOT_OK_RETURN(status); + } + + return NT_STATUS_OK; +} + +NTSTATUS dcesrv_add_ep(struct dcesrv_context *dce_ctx, + struct loadparm_context *lp_ctx, + struct dcesrv_endpoint *e, + struct tevent_context *event_ctx, + const struct model_ops *model_ops) +{ + switch (e->ep_description->transport) { + case NCACN_UNIX_STREAM: + return dcesrv_add_ep_unix(dce_ctx, lp_ctx, e, event_ctx, model_ops); + + case NCALRPC: + return dcesrv_add_ep_ncalrpc(dce_ctx, lp_ctx, e, event_ctx, model_ops); + + case NCACN_IP_TCP: + return dcesrv_add_ep_tcp(dce_ctx, lp_ctx, e, event_ctx, model_ops); + + case NCACN_NP: + return dcesrv_add_ep_np(dce_ctx, lp_ctx, e, event_ctx, model_ops); + + default: + return NT_STATUS_NOT_SUPPORTED; + } +} diff --git a/source4/rpc_server/dcerpc_server.h b/source4/rpc_server/dcerpc_server.h index bf93380274..8e31c94403 100644 --- a/source4/rpc_server/dcerpc_server.h +++ b/source4/rpc_server/dcerpc_server.h @@ -377,6 +377,11 @@ NTSTATUS dcesrv_fetch_session_key(struct dcesrv_connection *p, DATA_BLOB *sessio #define DCESRV_PULL_HANDLE(h, inhandle, t) DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, NT_STATUS_INVALID_HANDLE) #define DCESRV_PULL_HANDLE_WERR(h, inhandle, t) DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, WERR_BADFID) +NTSTATUS dcesrv_add_ep(struct dcesrv_context *dce_ctx, + struct loadparm_context *lp_ctx, + struct dcesrv_endpoint *e, + struct tevent_context *event_ctx, + const struct model_ops *model_ops); #endif /* SAMBA_DCERPC_SERVER_H */ diff --git a/source4/rpc_server/service_rpc.c b/source4/rpc_server/service_rpc.c index d221639bd2..82d6d9be6e 100644 --- a/source4/rpc_server/service_rpc.c +++ b/source4/rpc_server/service_rpc.c @@ -39,445 +39,6 @@ #include "../libcli/named_pipe_auth/npa_tstream.h" #include "smbd/process_model.h" -struct dcesrv_socket_context { - const struct dcesrv_endpoint *endpoint; - struct dcesrv_context *dcesrv_ctx; -}; - -static void dcesrv_terminate_connection(struct dcesrv_connection *dce_conn, const char *reason) -{ - struct stream_connection *srv_conn; - srv_conn = talloc_get_type(dce_conn->transport.private_data, - struct stream_connection); - - stream_terminate_connection(srv_conn, reason); -} - -static void dcesrv_sock_reply_done(struct tevent_req *subreq); - -struct dcesrv_sock_reply_state { - struct dcesrv_connection *dce_conn; - struct dcesrv_call_state *call; - struct iovec iov; -}; - -static void dcesrv_sock_report_output_data(struct dcesrv_connection *dce_conn) -{ - struct dcesrv_call_state *call; - - call = dce_conn->call_list; - if (!call || !call->replies) { - return; - } - - while (call->replies) { - struct data_blob_list_item *rep = call->replies; - struct dcesrv_sock_reply_state *substate; - struct tevent_req *subreq; - - substate = talloc(call, struct dcesrv_sock_reply_state); - if (!substate) { - dcesrv_terminate_connection(dce_conn, "no memory"); - return; - } - - substate->dce_conn = dce_conn; - substate->call = NULL; - - DLIST_REMOVE(call->replies, rep); - - if (call->replies == NULL) { - substate->call = call; - } - - substate->iov.iov_base = (void *) rep->blob.data; - substate->iov.iov_len = rep->blob.length; - - subreq = tstream_writev_queue_send(substate, - dce_conn->event_ctx, - dce_conn->stream, - dce_conn->send_queue, - &substate->iov, 1); - if (!subreq) { - dcesrv_terminate_connection(dce_conn, "no memory"); - return; - } - tevent_req_set_callback(subreq, dcesrv_sock_reply_done, - substate); - } - - DLIST_REMOVE(call->conn->call_list, call); - call->list = DCESRV_LIST_NONE; -} - -static void dcesrv_sock_reply_done(struct tevent_req *subreq) -{ - struct dcesrv_sock_reply_state *substate = tevent_req_callback_data(subreq, - struct dcesrv_sock_reply_state); - int ret; - int sys_errno; - NTSTATUS status; - struct dcesrv_call_state *call = substate->call; - - ret = tstream_writev_queue_recv(subreq, &sys_errno); - TALLOC_FREE(subreq); - if (ret == -1) { - status = map_nt_error_from_unix(sys_errno); - dcesrv_terminate_connection(substate->dce_conn, nt_errstr(status)); - return; - } - - talloc_free(substate); - if (call) { - talloc_free(call); - } -} - -static void dcesrv_read_fragment_done(struct tevent_req *subreq); - -static void dcesrv_sock_accept(struct stream_connection *srv_conn) -{ - NTSTATUS status; - struct dcesrv_socket_context *dcesrv_sock = - talloc_get_type(srv_conn->private_data, struct dcesrv_socket_context); - struct dcesrv_connection *dcesrv_conn = NULL; - int ret; - struct tevent_req *subreq; - struct loadparm_context *lp_ctx = dcesrv_sock->dcesrv_ctx->lp_ctx; - - if (!srv_conn->session_info) { - status = auth_anonymous_session_info(srv_conn, - lp_ctx, - &srv_conn->session_info); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0,("dcesrv_sock_accept: auth_anonymous_session_info failed: %s\n", - nt_errstr(status))); - stream_terminate_connection(srv_conn, nt_errstr(status)); - return; - } - } - - status = dcesrv_endpoint_connect(dcesrv_sock->dcesrv_ctx, - srv_conn, - dcesrv_sock->endpoint, - srv_conn->session_info, - srv_conn->event.ctx, - srv_conn->msg_ctx, - srv_conn->server_id, - DCESRV_CALL_STATE_FLAG_MAY_ASYNC, - &dcesrv_conn); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0,("dcesrv_sock_accept: dcesrv_endpoint_connect failed: %s\n", - nt_errstr(status))); - stream_terminate_connection(srv_conn, nt_errstr(status)); - return; - } - - dcesrv_conn->transport.private_data = srv_conn; - dcesrv_conn->transport.report_output_data = dcesrv_sock_report_output_data; - - TALLOC_FREE(srv_conn->event.fde); - - dcesrv_conn->send_queue = tevent_queue_create(dcesrv_conn, "dcesrv send queue"); - if (!dcesrv_conn->send_queue) { - status = NT_STATUS_NO_MEMORY; - DEBUG(0,("dcesrv_sock_accept: tevent_queue_create(%s)\n", - nt_errstr(status))); - stream_terminate_connection(srv_conn, nt_errstr(status)); - return; - } - - if (dcesrv_sock->endpoint->ep_description->transport == NCACN_NP) { - dcesrv_conn->auth_state.session_key = dcesrv_inherited_session_key; - dcesrv_conn->stream = talloc_move(dcesrv_conn, - &srv_conn->tstream); - } else { - ret = tstream_bsd_existing_socket(dcesrv_conn, - socket_get_fd(srv_conn->socket), - &dcesrv_conn->stream); - if (ret == -1) { - status = map_nt_error_from_unix(errno); - DEBUG(0, ("dcesrv_sock_accept: " - "failed to setup tstream: %s\n", - nt_errstr(status))); - stream_terminate_connection(srv_conn, nt_errstr(status)); - return; - } - socket_set_flags(srv_conn->socket, SOCKET_FLAG_NOCLOSE); - } - - dcesrv_conn->local_address = srv_conn->local_address; - dcesrv_conn->remote_address = srv_conn->remote_address; - - srv_conn->private_data = dcesrv_conn; - - irpc_add_name(srv_conn->msg_ctx, "rpc_server"); - - subreq = dcerpc_read_ncacn_packet_send(dcesrv_conn, - dcesrv_conn->event_ctx, - dcesrv_conn->stream); - if (!subreq) { - status = NT_STATUS_NO_MEMORY; - DEBUG(0,("dcesrv_sock_accept: dcerpc_read_fragment_buffer_send(%s)\n", - nt_errstr(status))); - stream_terminate_connection(srv_conn, nt_errstr(status)); - return; - } - tevent_req_set_callback(subreq, dcesrv_read_fragment_done, dcesrv_conn); - - return; -} - -static void dcesrv_read_fragment_done(struct tevent_req *subreq) -{ - struct dcesrv_connection *dce_conn = tevent_req_callback_data(subreq, - struct dcesrv_connection); - struct ncacn_packet *pkt; - DATA_BLOB buffer; - NTSTATUS status; - - status = dcerpc_read_ncacn_packet_recv(subreq, dce_conn, - &pkt, &buffer); - TALLOC_FREE(subreq); - if (!NT_STATUS_IS_OK(status)) { - dcesrv_terminate_connection(dce_conn, nt_errstr(status)); - return; - } - - status = dcesrv_process_ncacn_packet(dce_conn, pkt, buffer); - if (!NT_STATUS_IS_OK(status)) { - dcesrv_terminate_connection(dce_conn, nt_errstr(status)); - return; - } - - subreq = dcerpc_read_ncacn_packet_send(dce_conn, - dce_conn->event_ctx, - dce_conn->stream); - if (!subreq) { - status = NT_STATUS_NO_MEMORY; - dcesrv_terminate_connection(dce_conn, nt_errstr(status)); - return; - } - tevent_req_set_callback(subreq, dcesrv_read_fragment_done, dce_conn); -} - -static void dcesrv_sock_recv(struct stream_connection *conn, uint16_t flags) -{ - struct dcesrv_connection *dce_conn = talloc_get_type(conn->private_data, - struct dcesrv_connection); - dcesrv_terminate_connection(dce_conn, "dcesrv_sock_recv triggered"); -} - -static void dcesrv_sock_send(struct stream_connection *conn, uint16_t flags) -{ - struct dcesrv_connection *dce_conn = talloc_get_type(conn->private_data, - struct dcesrv_connection); - dcesrv_terminate_connection(dce_conn, "dcesrv_sock_send triggered"); -} - - -static const struct stream_server_ops dcesrv_stream_ops = { - .name = "rpc", - .accept_connection = dcesrv_sock_accept, - .recv_handler = dcesrv_sock_recv, - .send_handler = dcesrv_sock_send, -}; - - - -static NTSTATUS dcesrv_add_ep_unix(struct dcesrv_context *dce_ctx, - struct loadparm_context *lp_ctx, - struct dcesrv_endpoint *e, - struct tevent_context *event_ctx, const struct model_ops *model_ops) -{ - struct dcesrv_socket_context *dcesrv_sock; - uint16_t port = 1; - NTSTATUS status; - - dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context); - NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock); - - /* remember the endpoint of this socket */ - dcesrv_sock->endpoint = e; - dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx); - - status = stream_setup_socket(event_ctx, lp_ctx, - model_ops, &dcesrv_stream_ops, - "unix", e->ep_description->endpoint, &port, - lpcfg_socket_options(lp_ctx), - dcesrv_sock); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0,("service_setup_stream_socket(path=%s) failed - %s\n", - e->ep_description->endpoint, nt_errstr(status))); - } - - return status; -} - -static NTSTATUS dcesrv_add_ep_ncalrpc(struct dcesrv_context *dce_ctx, - struct loadparm_context *lp_ctx, - struct dcesrv_endpoint *e, - struct tevent_context *event_ctx, const struct model_ops *model_ops) -{ - struct dcesrv_socket_context *dcesrv_sock; - uint16_t port = 1; - char *full_path; - NTSTATUS status; - - if (!e->ep_description->endpoint) { - /* No identifier specified: use DEFAULT. - * DO NOT hardcode this value anywhere else. Rather, specify - * no endpoint and let the epmapper worry about it. */ - e->ep_description->endpoint = talloc_strdup(dce_ctx, "DEFAULT"); - } - - full_path = talloc_asprintf(dce_ctx, "%s/%s", lpcfg_ncalrpc_dir(lp_ctx), - e->ep_description->endpoint); - - dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context); - NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock); - - /* remember the endpoint of this socket */ - dcesrv_sock->endpoint = e; - dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx); - - status = stream_setup_socket(event_ctx, lp_ctx, - model_ops, &dcesrv_stream_ops, - "unix", full_path, &port, - lpcfg_socket_options(lp_ctx), - dcesrv_sock); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0,("service_setup_stream_socket(identifier=%s,path=%s) failed - %s\n", - e->ep_description->endpoint, full_path, nt_errstr(status))); - } - return status; -} - -static NTSTATUS dcesrv_add_ep_np(struct dcesrv_context *dce_ctx, - struct loadparm_context *lp_ctx, - struct dcesrv_endpoint *e, - struct tevent_context *event_ctx, const struct model_ops *model_ops) -{ - struct dcesrv_socket_context *dcesrv_sock; - NTSTATUS status; - - if (e->ep_description->endpoint == NULL) { - DEBUG(0, ("Endpoint mandatory for named pipes\n")); - return NT_STATUS_INVALID_PARAMETER; - } - - dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context); - NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock); - - /* remember the endpoint of this socket */ - dcesrv_sock->endpoint = e; - dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx); - - status = tstream_setup_named_pipe(event_ctx, lp_ctx, - model_ops, &dcesrv_stream_ops, - e->ep_description->endpoint, - dcesrv_sock); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0,("stream_setup_named_pipe(pipe=%s) failed - %s\n", - e->ep_description->endpoint, nt_errstr(status))); - return status; - } - - return NT_STATUS_OK; -} - -/* - add a socket address to the list of events, one event per dcerpc endpoint -*/ -static NTSTATUS add_socket_rpc_tcp_iface(struct dcesrv_context *dce_ctx, struct dcesrv_endpoint *e, - struct tevent_context *event_ctx, const struct model_ops *model_ops, - const char *address) -{ - struct dcesrv_socket_context *dcesrv_sock; - uint16_t port = 0; - NTSTATUS status; - - if (e->ep_description->endpoint) { - port = atoi(e->ep_description->endpoint); - } - - dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context); - NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock); - - /* remember the endpoint of this socket */ - dcesrv_sock->endpoint = e; - dcesrv_sock->dcesrv_ctx = talloc_reference(dcesrv_sock, dce_ctx); - - status = stream_setup_socket(event_ctx, dce_ctx->lp_ctx, - model_ops, &dcesrv_stream_ops, - "ipv4", address, &port, - lpcfg_socket_options(dce_ctx->lp_ctx), - dcesrv_sock); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0,("service_setup_stream_socket(address=%s,port=%u) failed - %s\n", - address, port, nt_errstr(status))); - } - - if (e->ep_description->endpoint == NULL) { - e->ep_description->endpoint = talloc_asprintf(dce_ctx, "%d", port); - } - - return status; -} - -static NTSTATUS dcesrv_add_ep_tcp(struct dcesrv_context *dce_ctx, - struct loadparm_context *lp_ctx, - struct dcesrv_endpoint *e, - struct tevent_context *event_ctx, const struct model_ops *model_ops) -{ - NTSTATUS status; - - /* Add TCP/IP sockets */ - if (lpcfg_interfaces(lp_ctx) && lpcfg_bind_interfaces_only(lp_ctx)) { - int num_interfaces; - int i; - struct interface *ifaces; - - load_interfaces(dce_ctx, lpcfg_interfaces(lp_ctx), &ifaces); - - num_interfaces = iface_count(ifaces); - for(i = 0; i < num_interfaces; i++) { - const char *address = iface_n_ip(ifaces, i); - status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops, address); - NT_STATUS_NOT_OK_RETURN(status); - } - } else { - status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops, - lpcfg_socket_address(lp_ctx)); - NT_STATUS_NOT_OK_RETURN(status); - } - - return NT_STATUS_OK; -} - -NTSTATUS dcesrv_add_ep(struct dcesrv_context *dce_ctx, - struct loadparm_context *lp_ctx, - struct dcesrv_endpoint *e, - struct tevent_context *event_ctx, - const struct model_ops *model_ops) -{ - switch (e->ep_description->transport) { - case NCACN_UNIX_STREAM: - return dcesrv_add_ep_unix(dce_ctx, lp_ctx, e, event_ctx, model_ops); - - case NCALRPC: - return dcesrv_add_ep_ncalrpc(dce_ctx, lp_ctx, e, event_ctx, model_ops); - - case NCACN_IP_TCP: - return dcesrv_add_ep_tcp(dce_ctx, lp_ctx, e, event_ctx, model_ops); - - case NCACN_NP: - return dcesrv_add_ep_np(dce_ctx, lp_ctx, e, event_ctx, model_ops); - - default: - return NT_STATUS_NOT_SUPPORTED; - } -} /* open the dcerpc server sockets @@ -521,6 +82,5 @@ failed: NTSTATUS server_service_rpc_init(void) { - return register_server_service("rpc", dcesrv_task_init); } diff --git a/source4/rpc_server/wscript_build b/source4/rpc_server/wscript_build index 61241fcf4b..0d630a302a 100644 --- a/source4/rpc_server/wscript_build +++ b/source4/rpc_server/wscript_build @@ -4,8 +4,8 @@ bld.SAMBA_SUBSYSTEM('DCERPC_COMMON', source='common/server_info.c common/share_info.c common/forward.c', autoproto='common/proto.h', public_headers='common/common.h', - header_path='dcerpc_server', - deps='ldb' + header_path='dcerpc_server', + deps='ldb dcerpc_server' ) @@ -38,7 +38,7 @@ bld.SAMBA_MODULE('dcerpc_srvsvc', autoproto='srvsvc/proto.h', subsystem='dcerpc_server', init_function='dcerpc_server_srvsvc_init', - deps='DCERPC_COMMON NDR_SRVSVC share' + deps='DCERPC_COMMON NDR_SRVSVC share ntvfs' ) @@ -80,7 +80,7 @@ bld.SAMBA_MODULE('dcerpc_netlogon', source='netlogon/dcerpc_netlogon.c', subsystem='dcerpc_server', init_function='dcerpc_server_netlogon_init', - deps='DCERPC_COMMON RPC_NDR_IRPC SCHANNELDB NDR_STANDARD auth_sam LIBSAMBA-HOSTCONFIG' + deps='DCERPC_COMMON RPC_NDR_IRPC COMMON_SCHANNELDB NDR_STANDARD auth_sam LIBSAMBA-HOSTCONFIG CLDAPD' ) @@ -127,7 +127,7 @@ bld.SAMBA_MODULE('dcerpc_eventlog', bld.SAMBA_LIBRARY('dcerpc_server', source='dcerpc_server.c dcesrv_auth.c dcesrv_mgmt.c handles.c', pc_files='dcerpc_server.pc', - deps='LIBCLI_AUTH LIBNDR samba_server_gensec dcerpc_remote', + deps='LIBCLI_AUTH LIBNDR samba_server_gensec dcerpc_remote service', public_deps='dcerpc', autoproto='dcerpc_server_proto.h', public_headers='dcerpc_server.h', diff --git a/source4/smbd/service_stream.h b/source4/smbd/service_stream.h index 21a37b3894..202ea52327 100644 --- a/source4/smbd/service_stream.h +++ b/source4/smbd/service_stream.h @@ -74,4 +74,6 @@ struct stream_server_ops { void (*send_handler)(struct stream_connection *, uint16_t); }; +void stream_terminate_connection(struct stream_connection *srv_conn, const char *reason); + #endif /* __SERVICE_STREAM_H__ */ diff --git a/source4/torture/wscript_build b/source4/torture/wscript_build index 194758e6a9..1360a4e33b 100644 --- a/source4/torture/wscript_build +++ b/source4/torture/wscript_build @@ -35,7 +35,7 @@ bld.RECURSE('libsmbclient') bld.SAMBA_SUBSYSTEM('TORTURE_NDR', source='ndr/ndr.c ndr/winreg.c ndr/atsvc.c ndr/lsa.c ndr/epmap.c ndr/dfs.c ndr/netlogon.c ndr/drsuapi.c ndr/spoolss.c ndr/samr.c ndr/dfsblob.c ndr/drsblobs.c ndr/nbt.c ndr/ntlmssp.c', autoproto='ndr/proto.h', - deps='torture SERVICE_SMB' + deps='torture' ) @@ -44,7 +44,7 @@ bld.SAMBA_MODULE('torture_rpc', autoproto='rpc/proto.h', subsystem='smbtorture', init_function='torture_rpc_init', - deps='NDR_TABLE RPC_NDR_UNIXINFO dcerpc_samr RPC_NDR_WINREG RPC_NDR_INITSHUTDOWN RPC_NDR_OXIDRESOLVER RPC_NDR_EVENTLOG RPC_NDR_ECHO RPC_NDR_SVCCTL RPC_NDR_NETLOGON dcerpc_atsvc RPC_NDR_DRSUAPI RPC_NDR_LSA RPC_NDR_EPMAPPER RPC_NDR_DFS RPC_NDR_FRSAPI RPC_NDR_SPOOLSS RPC_NDR_SRVSVC RPC_NDR_WKSSVC RPC_NDR_ROT RPC_NDR_DSSETUP RPC_NDR_REMACT RPC_NDR_OXIDRESOLVER RPC_NDR_NTSVCS WB_HELPER LIBSAMBA-NET LIBCLI_AUTH POPT_CREDENTIALS TORTURE_LDAP TORTURE_UTIL TORTURE_RAP dcerpc_server service process_model ntvfs SERVICE_SMB RPC_NDR_BROWSER LIBCLI_DRSUAPI TORTURE_LDB_MODULE TORTURE_DFS', + deps='NDR_TABLE RPC_NDR_UNIXINFO dcerpc_samr RPC_NDR_WINREG RPC_NDR_INITSHUTDOWN RPC_NDR_OXIDRESOLVER RPC_NDR_EVENTLOG RPC_NDR_ECHO RPC_NDR_SVCCTL RPC_NDR_NETLOGON dcerpc_atsvc RPC_NDR_DRSUAPI RPC_NDR_LSA RPC_NDR_EPMAPPER RPC_NDR_DFS RPC_NDR_FRSAPI RPC_NDR_SPOOLSS RPC_NDR_SRVSVC RPC_NDR_WKSSVC RPC_NDR_ROT RPC_NDR_DSSETUP RPC_NDR_REMACT RPC_NDR_OXIDRESOLVER RPC_NDR_NTSVCS WB_HELPER LIBSAMBA-NET LIBCLI_AUTH POPT_CREDENTIALS TORTURE_LDAP TORTURE_UTIL TORTURE_RAP dcerpc_server service process_model ntvfs RPC_NDR_BROWSER LIBCLI_DRSUAPI TORTURE_LDB_MODULE TORTURE_DFS', internal_module=True ) @@ -144,7 +144,6 @@ bld.SAMBA_SUBSYSTEM('torturemain', source='smbtorture.c torture.c shell.c', subsystem_name='smbtorture', deps='torture popt POPT_SAMBA POPT_CREDENTIALS dcerpc LIBCLI_SMB SMBREADLINE ' + TORTURE_MODULES, - pyembed=True ) bld.SAMBA_BINARY('smbtorture', |