s3: Add a 10-second timeout for the 445 or netbios connection to a DC
authorVolker Lendecke <vl@samba.org>
Sun, 17 Apr 2011 18:16:07 +0000 (20:16 +0200)
committerVolker Lendecke <vl@samba.org>
Mon, 25 Apr 2011 07:50:32 +0000 (09:50 +0200)
source3/include/proto.h
source3/libsmb/smbsock_connect.c
source3/torture/test_smbsock_any_connect.c
source3/winbindd/winbindd_cm.c

index 36f0235b02f67e43da3fc67e9bd5a2c2502eab88..69672cfdf56e07d6cbc3dbf6f01516cd2357ff21 100644 (file)
@@ -2837,7 +2837,7 @@ NTSTATUS smbsock_connect_recv(struct tevent_req *req, int *sock,
 NTSTATUS smbsock_connect(const struct sockaddr_storage *addr, uint16_t port,
                         const char *called_name, int called_type,
                         const char *calling_name, int calling_type,
-                        int *pfd, uint16_t *ret_port);
+                        int *pfd, uint16_t *ret_port, int sec_timeout);
 
 struct tevent_req *smbsock_any_connect_send(TALLOC_CTX *mem_ctx,
                                            struct tevent_context *ev,
@@ -2856,6 +2856,7 @@ NTSTATUS smbsock_any_connect(const struct sockaddr_storage *addrs,
                             int *calling_types,
                             size_t num_addrs,
                             uint16_t port,
+                            int sec_timeout,
                             int *pfd, size_t *chosen_index,
                             uint16_t *chosen_port);
 
index fd8626f5ad283e638c977cc3cf03136b77ce6dc5..9dc2f68934312e8f2ef3e71cc17a31d1c3a007ca 100644 (file)
@@ -368,7 +368,7 @@ NTSTATUS smbsock_connect_recv(struct tevent_req *req, int *sock,
 NTSTATUS smbsock_connect(const struct sockaddr_storage *addr, uint16_t port,
                         const char *called_name, int called_type,
                         const char *calling_name, int calling_type,
-                        int *pfd, uint16_t *ret_port)
+                        int *pfd, uint16_t *ret_port, int sec_timeout)
 {
        TALLOC_CTX *frame = talloc_stackframe();
        struct event_context *ev;
@@ -385,6 +385,11 @@ NTSTATUS smbsock_connect(const struct sockaddr_storage *addr, uint16_t port,
        if (req == NULL) {
                goto fail;
        }
+       if ((sec_timeout != 0) &&
+           !tevent_req_set_endtime(
+                   req, ev, timeval_current_ofs(sec_timeout, 0))) {
+               goto fail;
+       }
        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
                goto fail;
        }
@@ -610,6 +615,7 @@ NTSTATUS smbsock_any_connect(const struct sockaddr_storage *addrs,
                             int *calling_types,
                             size_t num_addrs,
                             uint16_t port,
+                            int sec_timeout,
                             int *pfd, size_t *chosen_index,
                             uint16_t *chosen_port)
 {
@@ -629,6 +635,11 @@ NTSTATUS smbsock_any_connect(const struct sockaddr_storage *addrs,
        if (req == NULL) {
                goto fail;
        }
+       if ((sec_timeout != 0) &&
+           !tevent_req_set_endtime(
+                   req, ev, timeval_current_ofs(sec_timeout, 0))) {
+               goto fail;
+       }
        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
                goto fail;
        }
index 28a99815e77ed8b8f1bbd022670eb698585b1e9d..a964e0fd831f5f3f95456fbb5340d575e92cc5f6 100644 (file)
@@ -35,7 +35,7 @@ bool run_smb_any_connect(int dummy)
        interpret_string_addr(&addrs[4], "192.168.99.9", 0);
 
        status = smbsock_any_connect(addrs, NULL, NULL, NULL, NULL,
-                                    ARRAY_SIZE(addrs), 0,
+                                    ARRAY_SIZE(addrs), 0, 0,
                                     &fd, &chosen_index, &port);
 
        d_printf("smbsock_any_connect returned %s (fd %d)\n",
index 3a701b9c0e3c81be0ba480b716e2d4a6d3b5c8b6..166e2eda52cb18cef754dcb454fe5aa6e1e1f8c8 100644 (file)
@@ -1375,7 +1375,7 @@ static bool find_new_dc(TALLOC_CTX *mem_ctx,
                return False;
 
        status = smbsock_any_connect(addrs, dcnames, NULL, NULL, NULL,
-                                    num_addrs, 0, fd, &fd_index, NULL);
+                                    num_addrs, 0, 10, fd, &fd_index, NULL);
        if (!NT_STATUS_IS_OK(status)) {
                for (i=0; i<num_dcs; i++) {
                        char ab[INET6_ADDRSTRLEN];
@@ -1571,7 +1571,7 @@ static NTSTATUS cm_open_connection(struct winbindd_domain *domain,
 
                        status = smbsock_connect(&domain->dcaddr, 0,
                                                 NULL, -1, NULL, -1,
-                                                &fd, NULL);
+                                                &fd, NULL, 10);
                        if (!NT_STATUS_IS_OK(status)) {
                                fd = -1;
                        }