s3: Use smbsock_any_connect in winbind
authorVolker Lendecke <vl@samba.org>
Tue, 21 Dec 2010 20:55:01 +0000 (21:55 +0100)
committerVolker Lendecke <vl@samba.org>
Wed, 22 Dec 2010 16:04:19 +0000 (09:04 -0700)
source3/winbindd/winbindd_cm.c

index ece68f1a1d3f55f0fbf16649792883e83ce2d8d9..5a6f9e2f6b951f633466e649f6003977685aff7a 100644 (file)
@@ -803,21 +803,6 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
                goto done;
        }
 
-       if (ntohs(peeraddr_in->sin_port) == 139) {
-               struct nmb_name calling;
-               struct nmb_name called;
-
-               make_nmb_name(&calling, global_myname(), 0x0);
-               make_nmb_name(&called, "*SMBSERVER", 0x20);
-
-               if (!cli_session_request(*cli, &calling, &called)) {
-                       DEBUG(8, ("cli_session_request failed for %s\n",
-                                 controller));
-                       result = NT_STATUS_UNSUCCESSFUL;
-                       goto done;
-               }
-       }
-
        result = cli_negprot(*cli);
 
        if (!NT_STATUS_IS_OK(result)) {
@@ -1318,7 +1303,10 @@ static bool find_new_dc(TALLOC_CTX *mem_ctx,
        struct sockaddr_storage *addrs = NULL;
        int num_addrs = 0;
 
-       int i, fd_index;
+       int i;
+       size_t fd_index;
+
+       NTSTATUS status;
 
        *fd = -1;
 
@@ -1336,15 +1324,6 @@ static bool find_new_dc(TALLOC_CTX *mem_ctx,
                                      &addrs, &num_addrs)) {
                        return False;
                }
-
-               if (!add_string_to_array(mem_ctx, dcs[i].name,
-                                   &dcnames, &num_dcnames)) {
-                       return False;
-               }
-               if (!add_sockaddr_to_array(mem_ctx, &dcs[i].ss, 139,
-                                     &addrs, &num_addrs)) {
-                       return False;
-               }
        }
 
        if ((num_dcnames == 0) || (num_dcnames != num_addrs))
@@ -1353,14 +1332,15 @@ static bool find_new_dc(TALLOC_CTX *mem_ctx,
        if ((addrs == NULL) || (dcnames == NULL))
                return False;
 
-       /* 5 second timeout. */
-       if (!open_any_socket_out(addrs, num_addrs, 5000, &fd_index, fd) ) {
+       status = smbsock_any_connect(addrs, dcnames, num_addrs,
+                                    fd, &fd_index, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
                for (i=0; i<num_dcs; i++) {
                        char ab[INET6_ADDRSTRLEN];
                        print_sockaddr(ab, sizeof(ab), &dcs[i].ss);
-                       DEBUG(10, ("find_new_dc: open_any_socket_out failed for "
+                       DEBUG(10, ("find_new_dc: smbsock_any_connect failed for "
                                "domain %s address %s. Error was %s\n",
-                               domain->name, ab, strerror(errno) ));
+                                  domain->name, ab, nt_errstr(status) ));
                        winbind_add_failed_connection_entry(domain,
                                dcs[i].name, NT_STATUS_UNSUCCESSFUL);
                }
@@ -1462,23 +1442,11 @@ static NTSTATUS cm_open_connection(struct winbindd_domain *domain,
                        && NT_STATUS_IS_OK(check_negative_conn_cache( domain->name, domain->dcname))
                        && (resolve_name(domain->dcname, &domain->dcaddr, 0x20)))
                {
-                       struct sockaddr_storage *addrs = NULL;
-                       int num_addrs = 0;
-                       int dummy = 0;
-
-                       if (!add_sockaddr_to_array(mem_ctx, &domain->dcaddr, 445, &addrs, &num_addrs)) {
-                               set_domain_offline(domain);
-                               talloc_destroy(mem_ctx);
-                               return NT_STATUS_NO_MEMORY;
-                       }
-                       if (!add_sockaddr_to_array(mem_ctx, &domain->dcaddr, 139, &addrs, &num_addrs)) {
-                               set_domain_offline(domain);
-                               talloc_destroy(mem_ctx);
-                               return NT_STATUS_NO_MEMORY;
-                       }
+                       NTSTATUS status;
 
-                       /* 5 second timeout. */
-                       if (!open_any_socket_out(addrs, num_addrs, 5000, &dummy, &fd)) {
+                       status = smbsock_connect(&domain->dcaddr, NULL, NULL,
+                                                &fd, NULL);
+                       if (!NT_STATUS_IS_OK(status)) {
                                fd = -1;
                        }
                }