s3-rpc_server: Add generic listener callback.
authorSimo Sorce <ssorce@redhat.com>
Thu, 20 May 2010 13:16:29 +0000 (09:16 -0400)
committerAndreas Schneider <asn@samba.org>
Wed, 15 Sep 2010 10:53:41 +0000 (12:53 +0200)
Signed-off-by: Andreas Schneider <asn@cynapses.org>
source3/rpc_server/rpc_server.c

index 047f128217b719de06d791b60cb27fe93c0db81e..923e8976894ae7031b959b0153cae7b03bfc2f61 100644 (file)
 
 struct named_pipe_listen_state {
        int fd;
+       char *name;
 };
 
 static void named_pipe_listener(struct tevent_context *ev,
                                struct tevent_fd *fde,
                                uint16_t flags,
-                               void *private_data)
-{
-       return;
-}
+                               void *private_data);
 
 bool setup_named_pipe_socket(const char *pipe_name,
                             struct tevent_context *ev_ctx)
@@ -44,6 +42,11 @@ bool setup_named_pipe_socket(const char *pipe_name,
                DEBUG(0, ("Out of memory\n"));
                return false;
        }
+       state->name = talloc_strdup(state, pipe_name);
+       if (!state->name) {
+               DEBUG(0, ("Out of memory\n"));
+               goto out;
+       }
        state->fd = -1;
 
        np_dir = talloc_asprintf(state, "%s/np", lp_ncalrpc_dir());
@@ -86,3 +89,43 @@ out:
        TALLOC_FREE(state);
        return false;
 }
+
+static void named_pipe_accept_function(const char *pipe_name, int fd);
+
+static void named_pipe_listener(struct tevent_context *ev,
+                               struct tevent_fd *fde,
+                               uint16_t flags,
+                               void *private_data)
+{
+       struct named_pipe_listen_state *state =
+                       talloc_get_type_abort(private_data,
+                                             struct named_pipe_listen_state);
+       struct sockaddr_un sunaddr;
+       socklen_t len;
+       int sd = -1;
+
+       /* TODO: should we have a limit to the number of clients ? */
+
+       len = sizeof(sunaddr);
+
+       while (sd == -1) {
+               sd = accept(state->fd,
+                           (struct sockaddr *)(void *)&sunaddr, &len);
+               if (errno != EINTR) break;
+       }
+
+       if (sd == -1) {
+               DEBUG(6, ("Failed to get a valid socket [%s]\n",
+                         strerror(errno)));
+               return;
+       }
+
+       DEBUG(6, ("Accepted socket %d\n", sd));
+
+       named_pipe_accept_function(state->name, sd);
+}
+
+static void named_pipe_accept_function(const char *pipe_name, int fd)
+{
+       return;
+}