s3:rpc_server: Return NTSTATUS for dcesrv_setup_ncacn_np_socket
authorSamuel Cabrero <scabrero@suse.de>
Tue, 4 Jun 2019 13:46:03 +0000 (15:46 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 22 Jul 2019 16:49:12 +0000 (16:49 +0000)
Signed-off-by: Samuel Cabrero <scabrero@suse.de>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/rpc_server/epmd.c
source3/rpc_server/fssd.c
source3/rpc_server/rpc_server.c
source3/rpc_server/rpc_server.h

index 4cf07a4eacf39841d189deacb67df822cb43dc45..8aa305abbf55524a968f420cf4fd34d0d88b34ad 100644 (file)
@@ -199,8 +199,8 @@ void start_epmd(struct tevent_context *ev_ctx,
                exit(1);
        }
 
-       ok = dcesrv_setup_ncacn_np_socket("epmapper", ev_ctx, msg_ctx);
-       if (!ok) {
+       status = dcesrv_setup_ncacn_np_socket("epmapper", ev_ctx, msg_ctx);
+       if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("Failed to open epmd named pipe!\n"));
                exit(1);
        }
index ba7e8d058acbbde33d08106cc3956d911b3e02a4..766f115436644307d418a936a09bd73f81e0e2af 100644 (file)
@@ -148,7 +148,6 @@ void start_fssd(struct tevent_context *ev_ctx,
        struct rpc_srv_callbacks fss_cb;
        NTSTATUS status;
        pid_t pid;
-       bool ok;
        int rc;
 
        fss_cb.init = fss_init_cb;
@@ -195,8 +194,8 @@ void start_fssd(struct tevent_context *ev_ctx,
        }
 
        /* case is normalized by smbd on connection */
-       ok = dcesrv_setup_ncacn_np_socket("fssagentrpc", ev_ctx, msg_ctx);
-       if (!ok) {
+       status = dcesrv_setup_ncacn_np_socket("fssagentrpc", ev_ctx, msg_ctx);
+       if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("Failed to open fssd named pipe!\n"));
                exit(1);
        }
index 996caade3dfa49881c3343e47efd23e30bf8a2e9..06b6d73d6aee0697e3e47ab26489f78792e00261 100644 (file)
@@ -147,9 +147,9 @@ out:
        return status;
 }
 
-bool dcesrv_setup_ncacn_np_socket(const char *pipe_name,
-                                 struct tevent_context *ev_ctx,
-                                 struct messaging_context *msg_ctx)
+NTSTATUS dcesrv_setup_ncacn_np_socket(const char *pipe_name,
+                                     struct tevent_context *ev_ctx,
+                                     struct messaging_context *msg_ctx)
 {
        struct dcerpc_ncacn_listen_state *state;
        struct tevent_fd *fde;
@@ -159,12 +159,13 @@ bool dcesrv_setup_ncacn_np_socket(const char *pipe_name,
        state = talloc(ev_ctx, struct dcerpc_ncacn_listen_state);
        if (!state) {
                DEBUG(0, ("Out of memory\n"));
-               return false;
+               return NT_STATUS_NO_MEMORY;
        }
        state->fd = -1;
        state->ep.name = talloc_strdup(state, pipe_name);
        if (state->ep.name == NULL) {
                DEBUG(0, ("Out of memory\n"));
+               status = NT_STATUS_NO_MEMORY;
                goto out;
        }
        status = dcesrv_create_ncacn_np_socket(pipe_name, &state->fd);
@@ -174,6 +175,7 @@ bool dcesrv_setup_ncacn_np_socket(const char *pipe_name,
 
        rc = listen(state->fd, 5);
        if (rc < 0) {
+               status = map_nt_error_from_unix_common(errno);
                DEBUG(0, ("Failed to listen on pipe socket %s: %s\n",
                          pipe_name, strerror(errno)));
                goto out;
@@ -185,23 +187,28 @@ bool dcesrv_setup_ncacn_np_socket(const char *pipe_name,
        DEBUG(10, ("Opened pipe socket fd %d for %s\n",
                   state->fd, pipe_name));
 
+       errno = 0;
        fde = tevent_add_fd(ev_ctx,
                            state, state->fd, TEVENT_FD_READ,
                            named_pipe_listener, state);
-       if (!fde) {
+       if (fde == NULL) {
+               if (errno == 0) {
+                       errno = ENOMEM;
+               }
+               status = map_nt_error_from_unix_common(errno);
                DEBUG(0, ("Failed to add event handler!\n"));
                goto out;
        }
 
        tevent_fd_set_auto_close(fde);
-       return true;
+       return NT_STATUS_OK;
 
 out:
        if (state->fd != -1) {
                close(state->fd);
        }
        TALLOC_FREE(state);
-       return false;
+       return status;
 }
 
 static void named_pipe_listener(struct tevent_context *ev,
index d1f88e175ec290d7abcfce86bc1db5a92e11c068..c67291bb44561d53864b0c84946336501d0f9d66 100644 (file)
@@ -80,9 +80,9 @@ int make_server_pipes_struct(TALLOC_CTX *mem_ctx,
 void set_incoming_fault(struct pipes_struct *p);
 void process_complete_pdu(struct pipes_struct *p, struct ncacn_packet *pkt);
 NTSTATUS dcesrv_create_ncacn_np_socket(const char *pipe_name, int *out_fd);
-bool dcesrv_setup_ncacn_np_socket(const char *pipe_name,
-                                 struct tevent_context *ev_ctx,
-                                 struct messaging_context *msg_ctx);
+NTSTATUS dcesrv_setup_ncacn_np_socket(const char *pipe_name,
+                                     struct tevent_context *ev_ctx,
+                                     struct messaging_context *msg_ctx);
 void named_pipe_accept_function(struct tevent_context *ev_ctx,
                                struct messaging_context *msg_ctx,
                                const char *pipe_name, int fd,