r25446: Merge some changes I made on the way home from SFO:
[jelmer/samba4-debian.git] / source / libcli / smb_composite / connect.c
index 81a82ad4276b714e1c376486a5053356ced29981..23974619d611eac68f050d85736e9e380cbf7564 100644 (file)
@@ -5,7 +5,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,
@@ -14,8 +14,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/>.
 */
 /*
   a composite API for making a full SMB connection
 #include "libcli/composite/composite.h"
 #include "libcli/smb_composite/smb_composite.h"
 #include "lib/events/events.h"
+#include "libcli/resolve/resolve.h"
+#include "auth/credentials/credentials.h"
+#include "librpc/gen_ndr/ndr_nbt.h"
+#include "param/param.h"
 
 /* the stages of this call */
 enum connect_stage {CONNECT_RESOLVE, 
@@ -60,7 +63,8 @@ static NTSTATUS connect_send_negprot(struct composite_context *c,
 {
        struct connect_state *state = talloc_get_type(c->private_data, struct connect_state);
 
-       state->req = smb_raw_negotiate_send(state->transport, lp_maxprotocol());
+       state->req = smb_raw_negotiate_send(state->transport, 
+                                           lp_cli_maxprotocol(global_loadparm));
        NT_STATUS_HAVE_NO_MEMORY(state->req);
 
        state->req->async.fn = request_handler;
@@ -169,13 +173,17 @@ static NTSTATUS connect_session_setup(struct composite_context *c,
 
                state->io_setup->in.credentials = cli_credentials_init(state);
                NT_STATUS_HAVE_NO_MEMORY(state->io_setup->in.credentials);
-               cli_credentials_set_conf(state->io_setup->in.credentials);
+               cli_credentials_set_conf(state->io_setup->in.credentials, 
+                                        global_loadparm);
                cli_credentials_set_anonymous(state->io_setup->in.credentials);
 
                /* If the preceding attempt was with extended security, we
                 * have been given a uid in the NTLMSSP_CHALLENGE reply. This
                 * would lead to an invalid uid in the anonymous fallback */
                state->session->vuid = 0;
+               data_blob_free(&state->session->user_session_key);
+               talloc_free(state->session->gensec);
+               state->session->gensec = NULL;
 
                state->creq = smb_composite_sesssetup_send(state->session,
                                                           state->io_setup);
@@ -302,7 +310,8 @@ static NTSTATUS connect_socket(struct composite_context *c,
        state->transport = smbcli_transport_init(state->sock, state, True);
        NT_STATUS_HAVE_NO_MEMORY(state->transport);
 
-       if (state->io->in.called_name != NULL) {
+       if (is_ipaddress(state->sock->hostname) &&
+           (state->io->in.called_name != NULL)) {
                /* If connecting to an IP address, we might want the real name
                 * of the host for later kerberos. The called name is a better
                 * approximation */
@@ -437,7 +446,7 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec
        c = talloc_zero(mem_ctx, struct composite_context);
        if (c == NULL) goto failed;
 
-       state = talloc(c, struct connect_state);
+       state = talloc_zero(c, struct connect_state);
        if (state == NULL) goto failed;
 
        if (event_ctx == NULL) {
@@ -452,7 +461,8 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec
 
        state->stage = CONNECT_RESOLVE;
        make_nbt_name_server(&name, io->in.dest_host);
-       state->creq = resolve_name_send(&name, c->event_ctx, lp_name_resolve_order());
+       state->creq = resolve_name_send(&name, c->event_ctx, 
+                                       lp_name_resolve_order(global_loadparm));
 
        if (state->creq == NULL) goto failed;
        state->creq->async.private_data = c;