- got client code cleartext passwords working again in cli_session_setup.
[samba.git] / source / libsmb / clientgen.c
index 688764fa7320f6c938c91de89a75a2c0bb0d8dc2..428f8e237fd4f518954dd4a2258c9318656c72ed 100644 (file)
 
 extern int DEBUGLEVEL;
 
+/* 
+ * set the port that will be used for connections by the client
+ */
+
+int cli_set_port(struct cli_state *cli, int port)
+{
+
+       if (port != 0)
+         cli -> port = port;
+
+       return cli -> port;   /* return it incase caller wants it */
+
+}
 
 /****************************************************************************
 recv an smb
@@ -683,36 +696,42 @@ BOOL cli_session_setup(struct cli_state *cli,
        fstring pword, ntpword;
 
        if (cli->protocol < PROTOCOL_LANMAN1)
+       {
                return True;
+       }
 
-       if (passlen > sizeof(pword)-1 || ntpasslen > sizeof(ntpword)-1) {
+       if (passlen > sizeof(pword)-1 || ntpasslen > sizeof(ntpword)-1)
+       {
                return False;
        }
 
-        if (((passlen == 0) || (passlen == 1)) && (pass[0] == '\0')) {
-          /* Null session connect. */
-          pword[0] = '\0';
-          ntpword[0] = '\0';
-        } else {
-          if ((cli->sec_mode & 2) && passlen != 24) {
-            passlen = 24;
-            ntpasslen = 24;
-            SMBencrypt((uchar *)pass,(uchar *)cli->cryptkey,(uchar *)pword);
-            SMBNTencrypt((uchar *)ntpass,(uchar *)cli->cryptkey,(uchar *)ntpword);
-          } else {
-                 fstrcpy(pword, pass);
-                 fstrcpy(ntpword, "");
-                 ntpasslen = 0;
-          }
-        }
-
-       /* if in share level security then don't send a password now */
-       if (!(cli->sec_mode & 1)) {
+       if (!IS_BITS_SET_ALL(cli->sec_mode, 1))
+       {
+               /* if in share level security then don't send a password now */
                fstrcpy(pword, "");
                passlen=1;
                fstrcpy(ntpword, "");
                ntpasslen=1;
        } 
+       else if (((passlen == 0) || (passlen == 1)) && (pass[0] == '\0'))
+       {
+               /* Null session connect. */
+               pword[0] = '\0';
+               ntpword[0] = '\0';
+       }
+       else if (passlen == 24 && ntpasslen == 24)
+       {
+               /* encrypted password send, implicit from 24-byte lengths */
+               memcpy(pword, pass, 24);
+               memcpy(ntpword, ntpass, 24);
+       }
+       else
+       {
+               /* plain-text password send */
+               fstrcpy(pword, pass);
+               fstrcpy(ntpword, "");
+               ntpasslen = 0;
+       }
 
        /* send a session setup command */
        bzero(cli->outbuf,smb_size);
@@ -2355,8 +2374,10 @@ BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
        }
 
 
+       if (cli -> port == 0) cli -> port = 139;
+
        cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, 
-                                 139, cli->timeout);
+                                 cli -> port, cli->timeout);
        if (cli->fd == -1)
                return False;
 
@@ -2382,6 +2403,7 @@ struct cli_state *cli_initialise(struct cli_state *cli)
 
        ZERO_STRUCTP(cli);
 
+       cli -> port = 0;
        cli->fd = -1;
        cli->cnum = -1;
        cli->pid = (uint16)getpid();
@@ -2755,7 +2777,7 @@ BOOL cli_connect_serverlist(struct cli_state *cli, char *p)
                        continue;
                }   
 
-               if (ismyip(dest_ip))
+               if ((lp_security() != SEC_USER) && (ismyip(dest_ip)))
                {
                        DEBUG(1,("cli_connect_serverlist: Password server loop - not using password server %s\n", remote_machine));
                        continue;