s3:rpc_server: Return NTSTATUS for dcesrv_setup_ncalrpc_socket
authorSamuel Cabrero <scabrero@suse.de>
Tue, 4 Jun 2019 15:00:30 +0000 (17:00 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 22 Jul 2019 16:49:13 +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/rpc_server.c
source3/rpc_server/rpc_server.h

index 1cc51862dc27d50d0916e38578021ac347401355..0ef4742f807d475c92a2f2b2ee514b9bdf31c0a6 100644 (file)
@@ -135,7 +135,6 @@ void start_epmd(struct tevent_context *ev_ctx,
        struct rpc_srv_callbacks epmapper_cb;
        NTSTATUS status;
        pid_t pid;
-       bool ok;
        int rc;
 
        epmapper_cb.init = NULL;
@@ -190,11 +189,11 @@ void start_epmd(struct tevent_context *ev_ctx,
                exit(1);
        }
 
-       ok = dcesrv_setup_ncalrpc_socket(ev_ctx,
-                                        msg_ctx,
-                                        "EPMAPPER",
-                                        srv_epmapper_delete_endpoints);
-       if (!ok) {
+       status = dcesrv_setup_ncalrpc_socket(ev_ctx,
+                                            msg_ctx,
+                                            "EPMAPPER",
+                                            srv_epmapper_delete_endpoints);
+       if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("Failed to open epmd ncalrpc pipe!\n"));
                exit(1);
        }
index 36c2c7176969704f84b8c50649bf661b381840df..de599beb69e0bdd3fd182412fa50271fcc0bdd12 100644 (file)
@@ -836,10 +836,10 @@ out:
        return status;
 }
 
-bool dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
-                                struct messaging_context *msg_ctx,
-                                const char *name,
-                                dcerpc_ncacn_disconnect_fn fn)
+NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
+                                    struct messaging_context *msg_ctx,
+                                    const char *name,
+                                    dcerpc_ncacn_disconnect_fn fn)
 {
        struct dcerpc_ncacn_listen_state *state;
        struct tevent_fd *fde;
@@ -849,7 +849,7 @@ bool dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
        state = talloc(ev_ctx, struct dcerpc_ncacn_listen_state);
        if (state == NULL) {
                DEBUG(0, ("Out of memory\n"));
-               return false;
+               return NT_STATUS_NO_MEMORY;
        }
 
        state->fd = -1;
@@ -863,7 +863,7 @@ bool dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
        if (state->ep.name == NULL) {
                DEBUG(0, ("Out of memory\n"));
                talloc_free(state);
-               return false;
+               return NT_STATUS_NO_MEMORY;
        }
 
        status = dcesrv_create_ncalrpc_socket(name, &state->fd);
@@ -875,6 +875,7 @@ bool dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
 
        rc = listen(state->fd, 5);
        if (rc < 0) {
+               status = map_nt_error_from_unix_common(errno);
                DEBUG(0, ("Failed to listen on ncalrpc socket %s: %s\n",
                          name, strerror(errno)));
                goto out;
@@ -886,6 +887,7 @@ bool dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
        /* Set server socket to non-blocking for the accept. */
        set_blocking(state->fd, false);
 
+       errno = 0;
        fde = tevent_add_fd(state->ev_ctx,
                            state,
                            state->fd,
@@ -893,20 +895,24 @@ bool dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
                            dcesrv_ncalrpc_listener,
                            state);
        if (fde == NULL) {
+               if (errno == 0) {
+                       errno = ENOMEM;
+               }
+               status = map_nt_error_from_unix_common(errno);
                DEBUG(0, ("Failed to add event handler for ncalrpc!\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 0;
+       return status;
 }
 
 static void dcesrv_ncalrpc_listener(struct tevent_context *ev,
index 97a53e7403f65afa5c93a45a4d0f583fd44831e2..ca0f61ce4e68dfb553d35f0953242d9362e68130 100644 (file)
@@ -99,10 +99,10 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
                                          uint16_t *port);
 
 NTSTATUS dcesrv_create_ncalrpc_socket(const char *name, int *out_fd);
-bool dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
-                                struct messaging_context *msg_ctx,
-                                const char *name,
-                                dcerpc_ncacn_disconnect_fn fn);
+NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
+                                    struct messaging_context *msg_ctx,
+                                    const char *name,
+                                    dcerpc_ncacn_disconnect_fn fn);
 
 void dcerpc_ncacn_accept(struct tevent_context *ev_ctx,
                         struct messaging_context *msg_ctx,