This is another rather major change to the samba authenticaion
[kai/samba.git] / source3 / libsmb / cliconnect.c
index dc8c7c295737e67aa495f70d8b107f5dbd9d6420..4ea19db9ec61fa53f6f319334352900414748600 100644 (file)
@@ -24,7 +24,7 @@
 #include "includes.h"
 
 
-static  struct {
+static const struct {
     int prot;
     const char *name;
   }
@@ -89,7 +89,7 @@ static BOOL cli_session_setup_lanman2(struct cli_state *cli, char *user,
        p = smb_buf(cli->outbuf);
        memcpy(p,pword,passlen);
        p += passlen;
-       p += clistr_push(cli, p, user, -1, STR_UPPER|STR_TERMINATE);
+       p += clistr_push(cli, p, user, -1, STR_TERMINATE);
        cli_setup_bcc(cli, p);
 
        cli_send_smb(cli);
@@ -197,7 +197,7 @@ static BOOL cli_session_setup_plaintext(struct cli_state *cli, char *user,
        int passlen;
        char *p;
 
-       passlen = clistr_push(cli, pword, pass, sizeof(pword), STR_TERMINATE);
+       passlen = clistr_push(cli, pword, pass, sizeof(pword), STR_TERMINATE|STR_ASCII);
 
        set_message(cli->outbuf,13,0,True);
        CVAL(cli->outbuf,smb_com) = SMBsesssetupX;
@@ -341,7 +341,7 @@ static DATA_BLOB cli_session_setup_blob(struct cli_state *cli, DATA_BLOB blob)
        CVAL(cli->outbuf,smb_vwv0) = 0xFF;
        SSVAL(cli->outbuf,smb_vwv2,CLI_BUFFER_SIZE);
        SSVAL(cli->outbuf,smb_vwv3,2);
-       SSVAL(cli->outbuf,smb_vwv4,0);
+       SSVAL(cli->outbuf,smb_vwv4,1);
        SIVAL(cli->outbuf,smb_vwv5,0);
        SSVAL(cli->outbuf,smb_vwv7,blob.length);
        SIVAL(cli->outbuf,smb_vwv10,capabilities); 
@@ -403,6 +403,8 @@ static BOOL cli_session_setup_kerberos(struct cli_state *cli, char *principal, c
        /* we don't need this blob for kerberos */
        data_blob_free(&blob2);
 
+       data_blob_free(&negTokenTarg);
+
        return !cli_is_error(cli);
 }
 #endif
@@ -460,8 +462,8 @@ static BOOL cli_session_setup_ntlmssp(struct cli_state *cli, char *user,
 
        /* encrypt the password with the challenge */
        memcpy(challenge, chal1.data + 24, 8);
-       SMBencrypt(pass, challenge,lmhash);
-       SMBNTencrypt(pass, challenge,nthash);
+       SMBencrypt((unsigned char *)pass, challenge,lmhash);
+       SMBNTencrypt((unsigned char *)pass, challenge,nthash);
 
 #if 0
        file_save("nthash.dat", nthash, 24);
@@ -708,17 +710,12 @@ BOOL cli_send_tconX(struct cli_state *cli,
                return False;
        }
 
-       fstrcpy(cli->dev, "A:");
-
-       if (cli->protocol >= PROTOCOL_NT1) {
-               clistr_pull(cli, cli->dev, smb_buf(cli->inbuf), sizeof(fstring), -1, STR_TERMINATE);
-       }
+       clistr_pull(cli, cli->dev, smb_buf(cli->inbuf), sizeof(fstring), -1, STR_TERMINATE|STR_ASCII);
 
        if (strcasecmp(share,"IPC$")==0) {
                fstrcpy(cli->dev, "IPC");
        }
 
-       /* only grab the device if we have a recent protocol level */
        if (cli->protocol >= PROTOCOL_NT1 &&
            smb_buflen(cli->inbuf) == 3) {
                /* almost certainly win95 - enable bug fixes */
@@ -842,7 +839,8 @@ BOOL cli_negprot(struct cli_state *cli)
                        cli->writebraw_supported = True;      
                }
                /* work out if they sent us a workgroup */
-               if (smb_buflen(cli->inbuf) > 8) {
+               if (!(cli->capabilities & CAP_EXTENDED_SECURITY) &&
+                   smb_buflen(cli->inbuf) > 8) {
                        clistr_pull(cli, cli->server_domain, 
                                    smb_buf(cli->inbuf)+8, sizeof(cli->server_domain),
                                    smb_buflen(cli->inbuf)-8, STR_UNICODE|STR_NOALIGN);
@@ -1016,57 +1014,6 @@ BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
        return True;
 }
 
-/****************************************************************************
-re-establishes a connection
-****************************************************************************/
-BOOL cli_reestablish_connection(struct cli_state *cli)
-{
-       struct nmb_name calling;
-       struct nmb_name called;
-       fstring dest_host;
-       fstring share;
-       fstring dev;
-       BOOL do_tcon = False;
-       int oldfd = cli->fd;
-
-       if (!cli->initialised || cli->fd == -1)
-       {
-               DEBUG(3,("cli_reestablish_connection: not connected\n"));
-               return False;
-       }
-
-       /* copy the parameters necessary to re-establish the connection */
-
-       if (cli->cnum != 0)
-       {
-               fstrcpy(share, cli->share);
-               fstrcpy(dev  , cli->dev);
-               do_tcon = True;
-       }
-
-       memcpy(&called , &(cli->called ), sizeof(called ));
-       memcpy(&calling, &(cli->calling), sizeof(calling));
-       fstrcpy(dest_host, cli->full_dest_host_name);
-
-       DEBUG(5,("cli_reestablish_connection: %s connecting to %s (ip %s) - %s [%s]\n",
-                nmb_namestr(&calling), nmb_namestr(&called), 
-                inet_ntoa(cli->dest_ip),
-                cli->user_name, cli->domain));
-
-       cli->fd = -1;
-
-       if (cli_establish_connection(cli,
-                                    dest_host, &cli->dest_ip,
-                                    &calling, &called,
-                                    share, dev, False, do_tcon)) {
-               if ((cli->fd != oldfd) && (oldfd != -1)) {
-                       close( oldfd );
-               }
-               return True;
-       }
-       return False;
-}
-
 /****************************************************************************
 establishes a connection right up to doing tconX, reading in a password.
 ****************************************************************************/
@@ -1087,6 +1034,10 @@ BOOL cli_establish_connection(struct cli_state *cli,
                return False;
        }
 
+       /* cli_establish_connection() can't handle spnego yet. Once we get rid of
+          pwd_cache and other horrors we can get rid of this */
+       cli->use_spnego = False;
+
        if (cli->fd == -1)
        {
                if (!cli_connect(cli, dest_host, dest_ip))