Add context for libcli_resolve.
[samba-svnmirror.git] / source / libcli / raw / clisocket.c
index be25b360072b1e8fcd0f388650ec13ce7de01682..c09104e256b00b2d66c3aa09f086e5786195ba98 100644 (file)
@@ -8,7 +8,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -17,8 +17,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -26,6 +25,8 @@
 #include "libcli/raw/libcliraw.h"
 #include "libcli/composite/composite.h"
 #include "lib/socket/socket.h"
+#include "libcli/resolve/resolve.h"
+#include "param/param.h"
 
 struct sock_connect_state {
        struct composite_context *ctx;
@@ -72,7 +73,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx,
        if (state->host_name == NULL) goto failed;
 
        if (port == 0) {
-               const char **ports = lp_smb_ports();
+               const char **ports = lp_smb_ports(global_loadparm);
                int i;
 
                for (i=0;ports[i];i++) /* noop */ ;
@@ -95,6 +96,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx,
 
        ctx = socket_connect_multi_send(state, host_addr,
                                        state->num_ports, state->ports,
+                                       lp_resolve_context(global_loadparm),
                                        state->ctx->event_ctx);
        if (ctx == NULL) goto failed;
        ctx->async.fn = smbcli_sock_connect_recv_conn;
@@ -119,7 +121,7 @@ static void smbcli_sock_connect_recv_conn(struct composite_context *ctx)
        if (!composite_is_ok(state->ctx)) return;
 
        state->ctx->status =
-               socket_set_option(sock, lp_socket_options(), NULL);
+               socket_set_option(sock, lp_socket_options(global_loadparm), NULL);
        if (!composite_is_ok(state->ctx)) return;
 
 
@@ -179,10 +181,10 @@ NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx,
 ****************************************************************************/
 void smbcli_sock_dead(struct smbcli_socket *sock)
 {
-       if (sock->sock != NULL) {
-               talloc_free(sock->sock);
-               sock->sock = NULL;
-       }
+       talloc_free(sock->event.fde);
+       sock->event.fde = NULL;
+       talloc_free(sock->sock);
+       sock->sock = NULL;
 }
 
 /****************************************************************************
@@ -198,6 +200,7 @@ resolve a hostname and connect
 ****************************************************************************/
 struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port,
                                                 TALLOC_CTX *mem_ctx,
+                                                struct resolve_context *resolve_ctx,
                                                 struct event_context *event_ctx)
 {
        int name_type = NBT_NAME_SERVER;
@@ -238,10 +241,10 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port,
 
        make_nbt_name(&nbt_name, host, name_type);
        
-       status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx);
+       status = resolve_name(resolve_ctx, &nbt_name, tmp_ctx, &address, event_ctx);
        if (!NT_STATUS_IS_OK(status)) {
                talloc_free(tmp_ctx);
-               return False;
+               return NULL;
        }
 
        status = smbcli_sock_connect(mem_ctx, address, port, name, event_ctx,