HACK smbd -i
authorStefan Metzmacher <metze@samba.org>
Fri, 30 Sep 2016 13:54:03 +0000 (15:54 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Jun 2018 12:35:12 +0000 (14:35 +0200)
source3/smbd/server.c

index 6c5bbd8c43785bab6c7b8cd1ef41eae967ecf1c2..347a7d2b9d212de7fab58c503a44f964b546bf97 100644 (file)
@@ -794,6 +794,44 @@ static void cleanupd_started(struct tevent_req *req)
 
 static void smb_direct_daemon_stopped(struct tevent_req *req);
 
+static void smb_direct_daemon_accept_done(struct tevent_req *subreq)
+{
+       struct tevent_context *ev = tevent_req_callback_data(subreq,
+                       struct tevent_context);
+       struct smb_direct_connection *c = NULL;
+       int fd = -1;
+       struct sockaddr_storage laddr;
+       struct sockaddr_storage raddr;
+       NTSTATUS status;
+
+       ZERO_STRUCT(laddr);
+       ZERO_STRUCT(raddr);
+
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
+       status = smb_direct_listener_accept_recv(subreq, ev,
+                                                &c, &fd, &laddr, &raddr);
+       /* no TALLOC_FREE(subreq)! we want to get more connections */
+       if (!NT_STATUS_IS_OK(status)) {
+               //TODO...
+               return;
+       }
+       subreq = NULL;
+
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
+       status = smb_direct_connection_setup_events(c, ev);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(c);
+               close(fd);
+               //TODO...
+               return;
+       }
+
+       //TODO: pass the caller
+       TALLOC_FREE(c);
+       close(fd);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
+}
+
 static bool smb_direct_daemon_init(struct tevent_context *ev,
                                   struct messaging_context *msg,
                                   bool interactive,
@@ -812,7 +850,42 @@ static bool smb_direct_daemon_init(struct tevent_context *ev,
 
 
        if (interactive) {
-               req = smb_direct_daemon_send(ev, ev);
+               struct smb_direct_listener *l = NULL;
+               struct tevent_req *subreq = NULL;
+               struct sockaddr_storage bind_addr;
+               struct in_addr ip;
+
+               DBG_ERR("setup listen ...\n");
+
+               ZERO_STRUCT(ip);
+               in_addr_to_sockaddr_storage(&bind_addr, ip);
+
+               status = smbd_direct_listener_setup(ev, &bind_addr, &l);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DBG_ERR("smbd_direct_listener_setup() => %s\n",
+                               nt_errstr(status));
+                       return false;
+               }
+
+               // TODO: create an socketpair() with shutdown(SHUT_RD) or a pipe()
+               // and pass it allong, we'll to sendmsg() from our side
+               // and pass the metadata and the connection fd to the calling
+               // process. If the other end closes we need to free the
+               // listener.
+
+               subreq = smb_direct_listener_accept_send(ev, ev, l);
+               if (subreq == NULL) {
+                       TALLOC_FREE(l);
+                       status = NT_STATUS_NO_MEMORY;
+                       DBG_ERR("smbd_direct_listener_setup() => %s\n",
+                               nt_errstr(status));
+                       return false;
+               }
+               tevent_req_set_callback(subreq,
+                                       smb_direct_daemon_accept_done,
+                                       ev);
+
+               req = tevent_wakeup_send(ev, ev, timeval_current_ofs(999999,0));
                *ppid = getpid();
                return (req != NULL);
        }
@@ -1404,6 +1477,7 @@ static bool smb_direct_client_start(struct smbd_parent_context *parent)
        int result;
        bool ok;
 
+       if (0) {
        parent->smbd_ctr_socket = smb_direct_socket(parent);
        if (parent->smbd_ctr_socket == NULL) {
                DBG_ERR("smb_direct_socket failed\n");
@@ -1418,12 +1492,12 @@ static bool smb_direct_client_start(struct smbd_parent_context *parent)
        }
 
        DBG_ERR("smb_direct_ping got [%" PRIx32 "]\n", ping_data);
-
-       s = talloc(parent, struct smbd_open_socket);
+       }
+       s = talloc_zero(parent, struct smbd_open_socket);
        if (s == NULL) {
                return false;
        }
-
+if (0) {
        result = smb_direct_bind(parent->smbd_ctr_socket, NULL);
        if (result != 0) {
                DBG_ERR("smb_direct_bind failed\n");
@@ -1457,7 +1531,7 @@ static bool smb_direct_client_start(struct smbd_parent_context *parent)
        }
 
        tevent_fd_set_close_fn(s->fde, smbd_open_socket_close_fn);
-
+}
        DLIST_ADD_END(parent->sockets, s);
 
        return true;
@@ -1485,7 +1559,7 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
        smbd_setup_sig_chld_handler(parent);
 
        ports = lp_smb_ports();
-
+if (0) {
        /* use a reasonable default set of ports - listing on 445 and 139 */
        if (smb_ports) {
                char **l;
@@ -1584,8 +1658,8 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
                        }
                }
        }
-
-       if (lp_parm_bool(-1, "smbdirect", "enable", false)) {
+}
+       if (lp_parm_bool(-1, "smbdirect", "enable", true)) {
                bool ok;
 
                ok = smb_direct_client_start(parent);