s3-rpc_server: Remove obsolete FAKE_FILE_TYPE_NAMED_PIPE handling.
[kai/samba-autobuild/.git] / source3 / rpc_server / srv_pipe_hnd.c
index 5c906561c097053a2bbdd178084bf0ff1eaafc54..a95aa06525a780f0187699b75c9bdeec5e9bb929 100644 (file)
 #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
@@ -280,7 +282,8 @@ static ssize_t read_from_internal_pipe(struct pipes_struct *p, char *data,
        }
 
        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));
 
        /*
@@ -298,7 +301,8 @@ static ssize_t read_from_internal_pipe(struct pipes_struct *p, char *data,
                 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;
        }
@@ -319,7 +323,8 @@ static ssize_t read_from_internal_pipe(struct pipes_struct *p, char *data,
 
                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));
@@ -340,7 +345,8 @@ static ssize_t read_from_internal_pipe(struct pipes_struct *p, char *data,
 
        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));
@@ -362,7 +368,8 @@ static ssize_t read_from_internal_pipe(struct pipes_struct *p, char *data,
 
        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;
        }
 
@@ -404,21 +411,24 @@ bool fsp_is_np(struct files_struct *fsp)
 
        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);
 
@@ -429,48 +439,60 @@ NTSTATUS np_open(TALLOC_CTX *mem_ctx, const char *name,
 
        /* 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;
@@ -480,13 +502,10 @@ NTSTATUS np_open(TALLOC_CTX *mem_ctx, const char *name,
 
 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);
@@ -501,15 +520,15 @@ bool np_read_in_progress(struct fake_file_handle *handle)
 }
 
 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)
 {
@@ -531,20 +550,9 @@ struct tevent_req *np_write_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
                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;
@@ -553,7 +561,7 @@ struct tevent_req *np_write_send(TALLOC_CTX *mem_ctx, struct event_context *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) {
@@ -684,16 +692,16 @@ static int np_ipc_readv_next_vector(struct tstream_context *stream,
 }
 
 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)
 {
@@ -706,21 +714,9 @@ struct tevent_req *np_read_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
                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,
@@ -728,7 +724,7 @@ struct tevent_req *np_read_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
 
                subreq = tstream_readv_pdu_queue_send(state,
                                                      ev,
-                                                     p->npipe,
+                                                     p->stream,
                                                      p->read_queue,
                                                      np_ipc_readv_next_vector,
                                                      &state->next_vector);