FileDocCategorySizeDatePackage
SmbComSessionSetupAndX.javaAPI DocJCIFS 1.3.17 API7626Tue Oct 18 15:26:24 BST 2011jcifs.smb

SmbComSessionSetupAndX

public class SmbComSessionSetupAndX extends AndXServerMessageBlock

Fields Summary
private static final int
BATCH_LIMIT
private static final boolean
DISABLE_PLAIN_TEXT_PASSWORDS
private byte[]
lmHash
private byte[]
ntHash
private byte[]
blob
private int
sessionKey
private int
capabilities
private String
accountName
private String
primaryDomain
SmbSession
session
Object
cred
Constructors Summary
SmbComSessionSetupAndX(SmbSession session, ServerMessageBlock andx, Object cred)


              
        super( andx );
        command = SMB_COM_SESSION_SETUP_ANDX;
        this.session = session;
        this.cred = cred;

        sessionKey = session.transport.sessionKey;
        capabilities = session.transport.capabilities;

        if (session.transport.server.security == SECURITY_USER) {
            if (cred instanceof NtlmPasswordAuthentication) {
                NtlmPasswordAuthentication auth = (NtlmPasswordAuthentication)cred;

                if (auth == NtlmPasswordAuthentication.ANONYMOUS) {
                    lmHash = new byte[0];
                    ntHash = new byte[0];
                    capabilities &= ~SmbConstants.CAP_EXTENDED_SECURITY;
                } else if (session.transport.server.encryptedPasswords) {
                    lmHash = auth.getAnsiHash( session.transport.server.encryptionKey );
                    ntHash = auth.getUnicodeHash( session.transport.server.encryptionKey );
                    // prohibit HTTP auth attempts for the null session
                    if (lmHash.length == 0 && ntHash.length == 0) {
                        throw new RuntimeException("Null setup prohibited.");
                    }
                } else if( DISABLE_PLAIN_TEXT_PASSWORDS ) {
                    throw new RuntimeException( "Plain text passwords are disabled" );
                } else if( useUnicode ) {
                    // plain text
                    String password = auth.getPassword();
                    lmHash = new byte[0];
                    ntHash = new byte[(password.length() + 1) * 2];
                    writeString( password, ntHash, 0 );
                } else {
                    // plain text
                    String password = auth.getPassword();
                    lmHash = new byte[(password.length() + 1) * 2];
                    ntHash = new byte[0];
                    writeString( password, lmHash, 0 );
                }
                accountName = auth.username;
                if (useUnicode)
                    accountName = accountName.toUpperCase();
                primaryDomain = auth.domain.toUpperCase();
            } else if (cred instanceof byte[]) {
                blob = (byte[])cred;
            } else {
                throw new SmbException("Unsupported credential type");
            }
        } else if (session.transport.server.security == SECURITY_SHARE) {
            if (cred instanceof NtlmPasswordAuthentication) {
                NtlmPasswordAuthentication auth = (NtlmPasswordAuthentication)cred;
                lmHash = new byte[0];
                ntHash = new byte[0];
                accountName = auth.username;
                if (useUnicode)
                    accountName = accountName.toUpperCase();
                primaryDomain = auth.domain.toUpperCase();
            } else {
                throw new SmbException("Unsupported credential type");
            }
        } else {
            throw new SmbException("Unsupported");
        }
    
Methods Summary
intgetBatchLimit(byte command)

        return command == SMB_COM_TREE_CONNECT_ANDX ? BATCH_LIMIT : 0;
    
intreadBytesWireFormat(byte[] buffer, int bufferIndex)

        return 0;
    
intreadParameterWordsWireFormat(byte[] buffer, int bufferIndex)

        return 0;
    
public java.lang.StringtoString()

        String result = new String( "SmbComSessionSetupAndX[" +
            super.toString() +
            ",snd_buf_size=" + session.transport.snd_buf_size +
            ",maxMpxCount=" + session.transport.maxMpxCount +
            ",VC_NUMBER=" + session.transport.VC_NUMBER +
            ",sessionKey=" + sessionKey +
            ",lmHash.length=" + (lmHash == null ? 0 : lmHash.length) +
            ",ntHash.length=" + (ntHash == null ? 0 : ntHash.length) +
            ",capabilities=" + capabilities +
            ",accountName=" + accountName +
            ",primaryDomain=" + primaryDomain +
            ",NATIVE_OS=" + session.transport.NATIVE_OS +
            ",NATIVE_LANMAN=" + session.transport.NATIVE_LANMAN + "]" );
        return result;
    
intwriteBytesWireFormat(byte[] dst, int dstIndex)

        int start = dstIndex;

        if (blob != null) {
            System.arraycopy(blob, 0, dst, dstIndex, blob.length );
            dstIndex += blob.length;
        } else {
            System.arraycopy( lmHash, 0, dst, dstIndex, lmHash.length );
            dstIndex += lmHash.length;
            System.arraycopy( ntHash, 0, dst, dstIndex, ntHash.length );
            dstIndex += ntHash.length;
    
            dstIndex += writeString( accountName, dst, dstIndex );
            dstIndex += writeString( primaryDomain, dst, dstIndex );
        }
        dstIndex += writeString( session.transport.NATIVE_OS, dst, dstIndex );
        dstIndex += writeString( session.transport.NATIVE_LANMAN, dst, dstIndex );

        return dstIndex - start;
    
intwriteParameterWordsWireFormat(byte[] dst, int dstIndex)

        int start = dstIndex;

        writeInt2( session.transport.snd_buf_size, dst, dstIndex );
        dstIndex += 2;
        writeInt2( session.transport.maxMpxCount, dst, dstIndex );
        dstIndex += 2;
        writeInt2( session.transport.VC_NUMBER, dst, dstIndex );
        dstIndex += 2;
        writeInt4( sessionKey, dst, dstIndex );
        dstIndex += 4;
        if (blob != null) {
            writeInt2( blob.length, dst, dstIndex );
            dstIndex += 2;
        } else {
            writeInt2( lmHash.length, dst, dstIndex );
            dstIndex += 2;
            writeInt2( ntHash.length, dst, dstIndex );
            dstIndex += 2;
        }
        dst[dstIndex++] = (byte)0x00;
        dst[dstIndex++] = (byte)0x00;
        dst[dstIndex++] = (byte)0x00;
        dst[dstIndex++] = (byte)0x00;
        writeInt4( capabilities, dst, dstIndex );
        dstIndex += 4;

        return dstIndex - start;