trying to get HEAD building again. If you want the code
[gd/samba-autobuild/.git] / source3 / smbd / sesssetup.c
index 8840d4e759cefe627e2914cca75b343e41f79816..7d77ed307105162d37240b79b0488d17b8bfb894 100644 (file)
@@ -53,13 +53,13 @@ static NTSTATUS do_map_to_guest(NTSTATUS status, auth_serversupplied_info **serv
        return status;
 }
 
-
 /****************************************************************************
  Add the standard 'Samba' signature to the end of the session setup.
 ****************************************************************************/
-static int add_signature(char *outbuf) 
+
+static int add_signature(char *outbuf, char *p)
 {
-       char *p = outbuf;
+       char *start = p;
        fstring lanman;
 
        snprintf( lanman, sizeof(lanman), "Samba %s", VERSION );
@@ -68,12 +68,13 @@ static int add_signature(char *outbuf)
        p += srvstr_push(outbuf, p, lanman, -1, STR_TERMINATE);
        p += srvstr_push(outbuf, p, lp_workgroup(), -1, STR_TERMINATE);
 
-       return PTR_DIFF(p, outbuf);
+       return PTR_DIFF(p, start);
 }
 
 /****************************************************************************
-send a security blob via a session setup reply
+ Send a security blob via a session setup reply.
 ****************************************************************************/
+
 static BOOL reply_sesssetup_blob(connection_struct *conn, char *outbuf,
                                 DATA_BLOB blob, NTSTATUS nt_status)
 {
@@ -91,7 +92,7 @@ static BOOL reply_sesssetup_blob(connection_struct *conn, char *outbuf,
        memcpy(p, blob.data, blob.length);
        p += blob.length;
 
-       p += add_signature( p );
+       p += add_signature( outbuf, p );
 
        set_message_end(outbuf,p);
 
@@ -101,6 +102,7 @@ static BOOL reply_sesssetup_blob(connection_struct *conn, char *outbuf,
 /****************************************************************************
  Do a 'guest' logon, getting back the 
 ****************************************************************************/
+
 static NTSTATUS check_guest_password(auth_serversupplied_info **server_info) 
 {
        struct auth_context *auth_context;
@@ -267,12 +269,12 @@ static int reply_spnego_kerberos(connection_struct *conn,
 }
 #endif
 
-
 /****************************************************************************
send a session setup reply, wrapped in SPNEGO.
get vuid and check first.
end the NTLMSSP exchange context if we are OK/complete fail
Send a session setup reply, wrapped in SPNEGO.
Get vuid and check first.
End the NTLMSSP exchange context if we are OK/complete fail
 ***************************************************************************/
+
 static BOOL reply_spnego_ntlmssp(connection_struct *conn, char *outbuf,
                                 AUTH_NTLMSSP_STATE **auth_ntlmssp_state,
                                 DATA_BLOB *ntlmssp_blob, NTSTATUS nt_status) 
@@ -326,8 +328,9 @@ static BOOL reply_spnego_ntlmssp(connection_struct *conn, char *outbuf,
 }
 
 /****************************************************************************
-reply to a session setup spnego negotiate packet
+ Reply to a session setup spnego negotiate packet.
 ****************************************************************************/
+
 static int reply_spnego_negotiate(connection_struct *conn, 
                                  char *inbuf,
                                  char *outbuf,
@@ -387,11 +390,11 @@ static int reply_spnego_negotiate(connection_struct *conn,
        /* already replied */
        return -1;
 }
-
        
 /****************************************************************************
-reply to a session setup spnego auth packet
+ Reply to a session setup spnego auth packet.
 ****************************************************************************/
+
 static int reply_spnego_auth(connection_struct *conn, char *inbuf, char *outbuf,
                             int length, int bufsize,
                             DATA_BLOB blob1)
@@ -425,10 +428,10 @@ static int reply_spnego_auth(connection_struct *conn, char *inbuf, char *outbuf,
        return -1;
 }
 
-
 /****************************************************************************
-reply to a session setup command
+ Reply to a session setup command.
 ****************************************************************************/
+
 static int reply_sesssetup_and_X_spnego(connection_struct *conn, char *inbuf,
                                        char *outbuf,
                                        int length,int bufsize)
@@ -493,10 +496,25 @@ static int reply_sesssetup_and_X_spnego(connection_struct *conn, char *inbuf,
        return ERROR_NT(NT_STATUS_LOGON_FAILURE);
 }
 
+/****************************************************************************
+ On new VC == 0, shutdown *all* old connections and users.
+ It seems that only NT4.x does this. At W2K and above (XP etc.).
+ a new session setup with VC==0 is ignored.
+****************************************************************************/
+
+static void setup_new_vc_session(void)
+{
+       DEBUG(2,("setup_new_vc_session: New VC == 0, if NT4.x compatible we would close all old resources.\n"));
+#if 0
+       conn_close_all();
+       invalidate_all_vuids();
+#endif
+}
 
 /****************************************************************************
-reply to a session setup command
+ Reply to a session setup command.
 ****************************************************************************/
+
 int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
                          int length,int bufsize)
 {
@@ -541,6 +559,9 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
                        return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
                }
 
+               if (SVAL(inbuf,smb_vwv4) == 0) {
+                       setup_new_vc_session();
+               }
                return reply_sesssetup_and_X_spnego(conn, inbuf, outbuf, length, bufsize);
        }
 
@@ -562,7 +583,7 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
 
                srvstr_pull_buf(inbuf, user, smb_buf(inbuf)+passlen1, sizeof(user), STR_TERMINATE);
                *domain = 0;
-  
+
        } else {
                uint16 passlen1 = SVAL(inbuf,smb_vwv7);
                uint16 passlen2 = SVAL(inbuf,smb_vwv8);
@@ -620,8 +641,11 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
                        nt_resp = data_blob(p+passlen1, passlen2);
                } else {
                        pstring pass;
+                       BOOL unic;
+                       unic=SVAL(inbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS;
                        srvstr_pull(inbuf, pass, smb_buf(inbuf), 
-                                   sizeof(pass),  passlen1, STR_TERMINATE);
+                                   sizeof(pass),  unic ? passlen2 : passlen1, 
+                                   STR_TERMINATE);
                        plaintext_password = data_blob(pass, strlen(pass)+1);
                }
                
@@ -638,6 +662,10 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
 
        }
        
+       if (SVAL(inbuf,smb_vwv4) == 0) {
+               setup_new_vc_session();
+       }
+
        DEBUG(3,("sesssetupX:name=[%s]\\[%s]@[%s]\n", domain, user, get_remote_machine_name()));
 
        if (*user) {
@@ -729,7 +757,7 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf,
        set_message(outbuf,3,0,True);
        if (Protocol >= PROTOCOL_NT1) {
                char *p = smb_buf( outbuf );
-               p += add_signature( p );
+               p += add_signature( outbuf, p );
                set_message_end( outbuf, p );
                /* perhaps grab OS version here?? */
        }