#include "rpc_server/srv_pipe_hnd.h"
#include "rpc_server/srv_pipe.h"
#include "rpc_server/rpc_server.h"
+#include "rpc_server/rpc_config.h"
#include "../lib/tsocket/tsocket.h"
#include "../lib/util/tevent_ntstatus.h"
+#include "librpc/ndr/ndr_table.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_SRV
}
DEBUG(6,(" name: %s len: %u\n",
- get_pipe_name_from_syntax(talloc_tos(), &p->contexts->syntax),
+ ndr_interface_name(&p->contexts->syntax.uuid,
+ p->contexts->syntax.if_version),
(unsigned int)n));
/*
DEBUG(5,("read_from_pipe: too large read (%u) requested on "
"pipe %s. We can only service %d sized reads.\n",
(unsigned int)n,
- get_pipe_name_from_syntax(talloc_tos(), &p->contexts->syntax),
+ ndr_interface_name(&p->contexts->syntax.uuid,
+ p->contexts->syntax.if_version),
RPC_MAX_PDU_FRAG_LEN ));
n = RPC_MAX_PDU_FRAG_LEN;
}
DEBUG(10,("read_from_pipe: %s: current_pdu_len = %u, "
"current_pdu_sent = %u returning %d bytes.\n",
- get_pipe_name_from_syntax(talloc_tos(), &p->contexts->syntax),
+ ndr_interface_name(&p->contexts->syntax.uuid,
+ p->contexts->syntax.if_version),
(unsigned int)p->out_data.frag.length,
(unsigned int)p->out_data.current_pdu_sent,
(int)data_returned));
DEBUG(10,("read_from_pipe: %s: fault_state = %d : data_sent_length "
"= %u, p->out_data.rdata.length = %u.\n",
- get_pipe_name_from_syntax(talloc_tos(), &p->contexts->syntax),
+ ndr_interface_name(&p->contexts->syntax.uuid,
+ p->contexts->syntax.if_version),
(int)p->fault_state,
(unsigned int)p->out_data.data_sent_length,
(unsigned int)p->out_data.rdata.length));
if(!create_next_pdu(p)) {
DEBUG(0,("read_from_pipe: %s: create_next_pdu failed.\n",
- get_pipe_name_from_syntax(talloc_tos(), &p->contexts->syntax)));
+ ndr_interface_name(&p->contexts->syntax.uuid,
+ p->contexts->syntax.if_version)));
return -1;
}
type = fsp->fake_file_handle->type;
- return ((type == FAKE_FILE_TYPE_NAMED_PIPE)
- || (type == FAKE_FILE_TYPE_NAMED_PIPE_PROXY));
+ return (type == FAKE_FILE_TYPE_NAMED_PIPE_PROXY);
}
NTSTATUS np_open(TALLOC_CTX *mem_ctx, const char *name,
const struct tsocket_address *local_address,
const struct tsocket_address *remote_address,
struct auth_session_info *session_info,
+ struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
struct fake_file_handle **phandle)
{
- const char *rpcsrv_type;
+ enum rpc_service_mode_e pipe_mode;
const char **proxy_list;
struct fake_file_handle *handle;
- bool external = false;
+ struct ndr_syntax_id syntax;
+ struct npa_state *npa = NULL;
+ NTSTATUS status;
+ bool ok;
proxy_list = lp_parm_string_list(-1, "np", "proxy", NULL);
/* Check what is the server type for this pipe.
Defaults to "embedded" */
- rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
- "rpc_server", name,
- "embedded");
- if (strcasecmp_m(rpcsrv_type, "external") == 0 ||
- strcasecmp_m(rpcsrv_type, "daemon") == 0) {
- external = true;
- }
+ pipe_mode = rpc_service_mode(name);
/* Still support the old method for defining external servers */
if ((proxy_list != NULL) && str_list_check_ci(proxy_list, name)) {
- external = true;
- }
-
- if (external) {
- struct np_proxy_state *p;
-
- p = make_external_rpc_pipe_p(handle, name,
- local_address,
- remote_address,
- session_info);
+ pipe_mode = RPC_SERVICE_MODE_EXTERNAL;
+ }
+
+ switch (pipe_mode) {
+ case RPC_SERVICE_MODE_EXTERNAL:
+ status = make_external_rpc_pipe(handle,
+ name,
+ local_address,
+ remote_address,
+ session_info,
+ &npa);
+ if (!NT_STATUS_IS_OK(status)) {
+ talloc_free(handle);
+ return status;
+ }
+ handle->private_data = (void *)npa;
handle->type = FAKE_FILE_TYPE_NAMED_PIPE_PROXY;
- handle->private_data = p;
- } else {
- struct pipes_struct *p;
- struct ndr_syntax_id syntax;
- if (!is_known_pipename(name, &syntax)) {
- TALLOC_FREE(handle);
+ break;
+ case RPC_SERVICE_MODE_EMBEDDED:
+ /* Check if we this daemon handles this pipe */
+ ok = is_known_pipename(name, &syntax);
+ if (!ok) {
+ DEBUG(0, ("ERROR! '%s' is not a registred pipe!\n",
+ name));
+ talloc_free(handle);
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
- p = make_internal_rpc_pipe_p(handle, &syntax, remote_address,
- session_info, msg_ctx);
+ status = make_internal_rpc_pipe_socketpair(handle,
+ ev_ctx,
+ msg_ctx,
+ name,
+ &syntax,
+ remote_address,
+ session_info,
+ &npa);
+ if (!NT_STATUS_IS_OK(status)) {
+ talloc_free(handle);
+ return status;
+ }
- handle->type = FAKE_FILE_TYPE_NAMED_PIPE;
- handle->private_data = p;
- }
+ handle->private_data = (void *)npa;
+ handle->type = FAKE_FILE_TYPE_NAMED_PIPE_PROXY;
- if (handle->private_data == NULL) {
- TALLOC_FREE(handle);
- return NT_STATUS_PIPE_NOT_AVAILABLE;
+ break;
+ case RPC_SERVICE_MODE_DISABLED:
+ talloc_free(handle);
+ return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
*phandle = handle;
bool np_read_in_progress(struct fake_file_handle *handle)
{
- if (handle->type == FAKE_FILE_TYPE_NAMED_PIPE) {
- return false;
- }
-
if (handle->type == FAKE_FILE_TYPE_NAMED_PIPE_PROXY) {
- struct np_proxy_state *p = talloc_get_type_abort(
- handle->private_data, struct np_proxy_state);
+ struct npa_state *p =
+ talloc_get_type_abort(handle->private_data,
+ struct npa_state);
size_t read_count;
read_count = tevent_queue_length(p->read_queue);
}
struct np_write_state {
- struct event_context *ev;
- struct np_proxy_state *p;
+ struct tevent_context *ev;
+ struct npa_state *p;
struct iovec iov;
ssize_t nwritten;
};
static void np_write_done(struct tevent_req *subreq);
-struct tevent_req *np_write_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct tevent_req *np_write_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
struct fake_file_handle *handle,
const uint8_t *data, size_t len)
{
goto post_status;
}
- if (handle->type == FAKE_FILE_TYPE_NAMED_PIPE) {
- struct pipes_struct *p = talloc_get_type_abort(
- handle->private_data, struct pipes_struct);
-
- state->nwritten = write_to_internal_pipe(p, (const char *)data, len);
-
- status = (state->nwritten >= 0)
- ? NT_STATUS_OK : NT_STATUS_UNEXPECTED_IO_ERROR;
- goto post_status;
- }
-
if (handle->type == FAKE_FILE_TYPE_NAMED_PIPE_PROXY) {
- struct np_proxy_state *p = talloc_get_type_abort(
- handle->private_data, struct np_proxy_state);
+ struct npa_state *p = talloc_get_type_abort(
+ handle->private_data, struct npa_state);
struct tevent_req *subreq;
state->ev = ev;
state->iov.iov_len = len;
subreq = tstream_writev_queue_send(state, ev,
- p->npipe,
+ p->stream,
p->write_queue,
&state->iov, 1);
if (subreq == NULL) {
}
struct np_read_state {
- struct np_proxy_state *p;
+ struct npa_state *p;
struct np_ipc_readv_next_vector_state next_vector;
- size_t nread;
+ ssize_t nread;
bool is_data_outstanding;
};
static void np_read_done(struct tevent_req *subreq);
-struct tevent_req *np_read_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct tevent_req *np_read_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
struct fake_file_handle *handle,
uint8_t *data, size_t len)
{
return NULL;
}
- if (handle->type == FAKE_FILE_TYPE_NAMED_PIPE) {
- struct pipes_struct *p = talloc_get_type_abort(
- handle->private_data, struct pipes_struct);
-
- state->nread = read_from_internal_pipe(
- p, (char *)data, len, &state->is_data_outstanding);
-
- status = (state->nread >= 0)
- ? NT_STATUS_OK : NT_STATUS_UNEXPECTED_IO_ERROR;
- goto post_status;
- }
-
if (handle->type == FAKE_FILE_TYPE_NAMED_PIPE_PROXY) {
- struct np_proxy_state *p = talloc_get_type_abort(
- handle->private_data, struct np_proxy_state);
+ struct npa_state *p = talloc_get_type_abort(
+ handle->private_data, struct npa_state);
struct tevent_req *subreq;
np_ipc_readv_next_vector_init(&state->next_vector,
subreq = tstream_readv_pdu_queue_send(state,
ev,
- p->npipe,
+ p->stream,
p->read_queue,
np_ipc_readv_next_vector,
&state->next_vector);