s3:rpc_server: Return NTSTATUS for dcesrv_create_ncacn_np_socket
authorSamuel Cabrero <scabrero@suse.de>
Tue, 4 Jun 2019 13:15:11 +0000 (15:15 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 22 Jul 2019 16:49:12 +0000 (16:49 +0000)
The 'fd' state struct member is initialized after allocation because it
is checked in the error path.

Signed-off-by: Samuel Cabrero <scabrero@suse.de>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/printing/spoolssd.c
source3/rpc_server/lsasd.c
source3/rpc_server/mdssd.c
source3/rpc_server/rpc_server.c
source3/rpc_server/rpc_server.h

index b2a2f3c250f45be9412071fd0ced4b6a20e5fd5d..a3c69dfb54fc089e1eb8d9be13856b489fadb962 100644 (file)
@@ -657,8 +657,8 @@ pid_t start_spoolssd(struct tevent_context *ev_ctx,
 
        /* the listening fd must be created before the children are actually
         * forked out. */
-       listen_fd = dcesrv_create_ncacn_np_socket(SPOOLSS_PIPE_NAME);
-       if (listen_fd == -1) {
+       status = dcesrv_create_ncacn_np_socket(SPOOLSS_PIPE_NAME, &listen_fd);
+       if (!NT_STATUS_IS_OK(status)) {
                exit(1);
        }
 
index 792d5e79489009329eae74365f59a8754016a438..653f0bed9944095a1679b22940b8323172bfb37d 100644 (file)
@@ -627,8 +627,8 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        }
 
        /* LSARPC */
-       fd = dcesrv_create_ncacn_np_socket("lsarpc");
-       if (fd < 0) {
+       status = dcesrv_create_ncacn_np_socket("lsarpc", &fd);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
 
@@ -641,8 +641,8 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        listen_fd[*listen_fd_size] = fd;
        (*listen_fd_size)++;
 
-       fd = dcesrv_create_ncacn_np_socket("lsass");
-       if (fd < 0) {
+       status = dcesrv_create_ncacn_np_socket("lsass", &fd);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
 
@@ -696,8 +696,8 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        }
 
        /* SAMR */
-       fd = dcesrv_create_ncacn_np_socket("samr");
-       if (fd < 0) {
+       status = dcesrv_create_ncacn_np_socket("samr", &fd);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
 
@@ -751,8 +751,8 @@ static bool lsasd_create_sockets(struct tevent_context *ev_ctx,
        }
 
        /* NETLOGON */
-       fd = dcesrv_create_ncacn_np_socket("netlogon");
-       if (fd < 0) {
+       status = dcesrv_create_ncacn_np_socket("netlogon", &fd);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
 
index e9737aa3069388d153b9f03b15d875967f679b72..5b39bda23690da6b237a56363886a5c10df2c006 100644 (file)
@@ -549,8 +549,8 @@ static bool mdssd_create_sockets(struct tevent_context *ev_ctx,
        }
 
        /* mdssvc */
-       fd = dcesrv_create_ncacn_np_socket("mdssvc");
-       if (fd < 0) {
+       status = dcesrv_create_ncacn_np_socket("mdssvc", &fd);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
 
index ffd6aa74fe87a0658659f212618dfbf5cc2467df..c62ed6e2b03fd099342199a444cac78d93d29694 100644 (file)
@@ -96,10 +96,11 @@ static void named_pipe_listener(struct tevent_context *ev,
                                uint16_t flags,
                                void *private_data);
 
-int dcesrv_create_ncacn_np_socket(const char *pipe_name)
+NTSTATUS dcesrv_create_ncacn_np_socket(const char *pipe_name, int *out_fd)
 {
        char *np_dir = NULL;
        int fd = -1;
+       NTSTATUS status;
 
        /*
         * As lp_ncalrpc_dir() should have 0755, but
@@ -107,6 +108,7 @@ int dcesrv_create_ncacn_np_socket(const char *pipe_name)
         * create lp_ncalrpc_dir() first.
         */
        if (!directory_create_or_exist(lp_ncalrpc_dir(), 0755)) {
+               status = map_nt_error_from_unix_common(errno);
                DEBUG(0, ("Failed to create pipe directory %s - %s\n",
                          lp_ncalrpc_dir(), strerror(errno)));
                goto out;
@@ -114,11 +116,13 @@ int dcesrv_create_ncacn_np_socket(const char *pipe_name)
 
        np_dir = talloc_asprintf(talloc_tos(), "%s/np", lp_ncalrpc_dir());
        if (!np_dir) {
+               status = NT_STATUS_NO_MEMORY;
                DEBUG(0, ("Out of memory\n"));
                goto out;
        }
 
        if (!directory_create_or_exist_strict(np_dir, geteuid(), 0700)) {
+               status = map_nt_error_from_unix_common(errno);
                DEBUG(0, ("Failed to create pipe directory %s - %s\n",
                          np_dir, strerror(errno)));
                goto out;
@@ -126,6 +130,7 @@ int dcesrv_create_ncacn_np_socket(const char *pipe_name)
 
        fd = create_pipe_sock(np_dir, pipe_name, 0700);
        if (fd == -1) {
+               status = map_nt_error_from_unix_common(errno);
                DEBUG(0, ("Failed to create pipe socket! [%s/%s]\n",
                          np_dir, pipe_name));
                goto out;
@@ -133,9 +138,13 @@ int dcesrv_create_ncacn_np_socket(const char *pipe_name)
 
        DEBUG(10, ("Opened pipe socket fd %d for %s\n", fd, pipe_name));
 
+       *out_fd = fd;
+
+       status = NT_STATUS_OK;
+
 out:
        talloc_free(np_dir);
-       return fd;
+       return status;
 }
 
 bool setup_named_pipe_socket(const char *pipe_name,
@@ -145,19 +154,21 @@ bool setup_named_pipe_socket(const char *pipe_name,
        struct dcerpc_ncacn_listen_state *state;
        struct tevent_fd *fde;
        int rc;
+       NTSTATUS status;
 
        state = talloc(ev_ctx, struct dcerpc_ncacn_listen_state);
        if (!state) {
                DEBUG(0, ("Out of memory\n"));
                return false;
        }
+       state->fd = -1;
        state->ep.name = talloc_strdup(state, pipe_name);
        if (state->ep.name == NULL) {
                DEBUG(0, ("Out of memory\n"));
                goto out;
        }
-       state->fd = dcesrv_create_ncacn_np_socket(pipe_name);
-       if (state->fd == -1) {
+       status = dcesrv_create_ncacn_np_socket(pipe_name, &state->fd);
+       if (!NT_STATUS_IS_OK(status)) {
                goto out;
        }
 
index 435b38a456fe5ceed0b87f8945bd5fbc9e6c437a..d4c37fcbb5bf7f428187afdc98d8077ca7554068 100644 (file)
@@ -79,7 +79,7 @@ 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);
-int dcesrv_create_ncacn_np_socket(const char *pipe_name);
+NTSTATUS dcesrv_create_ncacn_np_socket(const char *pipe_name, int *out_fd);
 bool setup_named_pipe_socket(const char *pipe_name,
                             struct tevent_context *ev_ctx,
                             struct messaging_context *msg_ctx);