FileDocCategorySizeDatePackage
ServerMessageBlock.javaAPI DocJCIFS 1.3.17 API21969Tue Oct 18 15:26:24 BST 2011jcifs.smb

ServerMessageBlock

public abstract class ServerMessageBlock extends Response implements Request, SmbConstants

Fields Summary
static jcifs.util.LogStream
log
static final byte[]
header
static final byte
SMB_COM_CREATE_DIRECTORY
static final byte
SMB_COM_DELETE_DIRECTORY
static final byte
SMB_COM_CLOSE
static final byte
SMB_COM_DELETE
static final byte
SMB_COM_RENAME
static final byte
SMB_COM_QUERY_INFORMATION
static final byte
SMB_COM_WRITE
static final byte
SMB_COM_CHECK_DIRECTORY
static final byte
SMB_COM_TRANSACTION
static final byte
SMB_COM_TRANSACTION_SECONDARY
static final byte
SMB_COM_MOVE
static final byte
SMB_COM_ECHO
static final byte
SMB_COM_OPEN_ANDX
static final byte
SMB_COM_READ_ANDX
static final byte
SMB_COM_WRITE_ANDX
static final byte
SMB_COM_TRANSACTION2
static final byte
SMB_COM_FIND_CLOSE2
static final byte
SMB_COM_TREE_DISCONNECT
static final byte
SMB_COM_NEGOTIATE
static final byte
SMB_COM_SESSION_SETUP_ANDX
static final byte
SMB_COM_LOGOFF_ANDX
static final byte
SMB_COM_TREE_CONNECT_ANDX
static final byte
SMB_COM_NT_TRANSACT
static final byte
SMB_COM_NT_TRANSACT_SECONDARY
static final byte
SMB_COM_NT_CREATE_ANDX
byte
command
byte
flags
int
headerStart
int
length
int
batchLevel
int
errorCode
int
flags2
int
tid
int
pid
int
uid
int
mid
int
wordCount
int
byteCount
boolean
useUnicode
boolean
received
boolean
extendedSecurity
long
responseTimeout
int
signSeq
boolean
verifyFailed
NtlmPasswordAuthentication
auth
String
path
SigningDigest
digest
ServerMessageBlock
response
Constructors Summary
ServerMessageBlock()


     
        flags = (byte)( FLAGS_PATH_NAMES_CASELESS | FLAGS_PATH_NAMES_CANONICALIZED );
        pid = PID;
        batchLevel = 0;
    
Methods Summary
intdecode(byte[] buffer, int bufferIndex)

        int start = headerStart = bufferIndex;

        bufferIndex += readHeaderWireFormat( buffer, bufferIndex );

        wordCount = buffer[bufferIndex++];
        if( wordCount != 0 ) {
            int n;
            if(( n = readParameterWordsWireFormat( buffer, bufferIndex )) != wordCount * 2 ) {
                if( log.level >= 5 ) {
                    log.println( "wordCount * 2=" + ( wordCount * 2 ) +
                            " but readParameterWordsWireFormat returned " + n );
                }
            }
            bufferIndex += wordCount * 2;
        }

        byteCount = readInt2( buffer, bufferIndex );
        bufferIndex += 2;

        if( byteCount != 0 ) {
            int n;
            if(( n = readBytesWireFormat( buffer, bufferIndex )) != byteCount ) {
                if( log.level >= 5 ) {
                    log.println( "byteCount=" + byteCount +
                            " but readBytesWireFormat returned " + n );
                }
            }
            // Don't think we can rely on n being correct here. Must use byteCount.
            // Last paragraph of section 3.13.3 eludes to this.

            bufferIndex += byteCount;
        }

        length = bufferIndex - start;
        return length;
    
intencode(byte[] dst, int dstIndex)

        int start = headerStart = dstIndex;

        dstIndex += writeHeaderWireFormat( dst, dstIndex );
        wordCount = writeParameterWordsWireFormat( dst, dstIndex + 1 );
        dst[dstIndex++] = (byte)(( wordCount / 2 ) & 0xFF );
        dstIndex += wordCount;
        wordCount /= 2;
        byteCount = writeBytesWireFormat( dst, dstIndex + 2 );
        dst[dstIndex++] = (byte)( byteCount & 0xFF );
        dst[dstIndex++] = (byte)(( byteCount >> 8 ) & 0xFF );
        dstIndex += byteCount;

        length = dstIndex - start;

        if( digest != null ) {
            digest.sign( dst, headerStart, length, this, response );
        }

        return length;
    
public booleanequals(java.lang.Object obj)

        return obj instanceof ServerMessageBlock && ((ServerMessageBlock)obj).mid == mid;
    
public inthashCode()

        return mid;
    
booleanisResponse()

        return ( flags & FLAGS_RESPONSE ) == FLAGS_RESPONSE;
    
abstract intreadBytesWireFormat(byte[] buffer, int bufferIndex)

intreadHeaderWireFormat(byte[] buffer, int bufferIndex)

        command = buffer[bufferIndex + CMD_OFFSET];
        errorCode = readInt4( buffer, bufferIndex + ERROR_CODE_OFFSET );
        flags = buffer[bufferIndex + FLAGS_OFFSET];
        flags2 = readInt2( buffer, bufferIndex + FLAGS_OFFSET + 1 );
        tid = readInt2( buffer, bufferIndex + TID_OFFSET );
        pid = readInt2( buffer, bufferIndex + TID_OFFSET + 2 );
        uid = readInt2( buffer, bufferIndex + TID_OFFSET + 4 );
        mid = readInt2( buffer, bufferIndex + TID_OFFSET + 6 );
        return HEADER_LENGTH;
    
static intreadInt2(byte[] src, int srcIndex)

        return ( src[srcIndex] & 0xFF ) +
                (( src[srcIndex + 1] & 0xFF ) << 8 );
    
static intreadInt4(byte[] src, int srcIndex)

        return ( src[srcIndex] & 0xFF ) +
                (( src[srcIndex + 1] & 0xFF ) << 8 ) +
                (( src[srcIndex + 2] & 0xFF ) << 16 ) +
                (( src[srcIndex + 3] & 0xFF ) << 24 );
    
static longreadInt8(byte[] src, int srcIndex)

        return (readInt4( src, srcIndex ) & 0xFFFFFFFFL) +
            ((long)(readInt4( src, srcIndex + 4 )) << 32);
    
abstract intreadParameterWordsWireFormat(byte[] buffer, int bufferIndex)

java.lang.StringreadString(byte[] src, int srcIndex)

        return readString( src, srcIndex, 256, useUnicode );
    
java.lang.StringreadString(byte[] src, int srcIndex, int maxLen, boolean useUnicode)

        int len = 0;
        String str = null;
        try {
            if( useUnicode ) {
                // Unicode requires word alignment
                if((( srcIndex - headerStart ) % 2 ) != 0 ) {
                    srcIndex++;
                }
                while( src[srcIndex + len] != (byte)0x00 ||
                                            src[srcIndex + len + 1] != (byte)0x00 ) {
                    len += 2;
                    if( len > maxLen ) {
if( log.level > 0 )
Hexdump.hexdump( System.err, src, srcIndex, maxLen < 128 ? maxLen + 8 : 128 );
                        throw new RuntimeException( "zero termination not found" );
                    }
                }
                str = new String( src, srcIndex, len, UNI_ENCODING );
            } else {
                while( src[srcIndex + len] != (byte)0x00 ) {
                    len++;
                    if( len > maxLen ) {
if( log.level > 0 )
Hexdump.hexdump( System.err, src, srcIndex, maxLen < 128 ? maxLen + 8 : 128 );
                        throw new RuntimeException( "zero termination not found" );
                    }
                }
                str = new String( src, srcIndex, len, OEM_ENCODING );
            }
        } catch( UnsupportedEncodingException uee ) {
            if( log.level > 1 )
                uee.printStackTrace( log );
        }
        return str;
    
java.lang.StringreadString(byte[] src, int srcIndex, int srcEnd, int maxLen, boolean useUnicode)

        int len = 0;
        String str = null;
        try {
            if (useUnicode) {
                // Unicode requires word alignment
                if (((srcIndex - headerStart) % 2) != 0) {
                    srcIndex++;
                }
                for (len = 0; (srcIndex + len + 1) < srcEnd; len += 2) {
                    if (src[srcIndex + len] == (byte)0x00 && src[srcIndex + len + 1] == (byte)0x00) {
                        break;
                    }
                    if (len > maxLen) {
                        if (log.level > 0)
                            Hexdump.hexdump(System.err, src, srcIndex, maxLen < 128 ? maxLen + 8 : 128);
                        throw new RuntimeException("zero termination not found");
                    }
                }
                str = new String(src, srcIndex, len, UNI_ENCODING);
            } else {
                for (len = 0; srcIndex < srcEnd; len++) {
                    if (src[srcIndex + len] == (byte)0x00) {
                        break;
                    }
                    if (len > maxLen) {
                        if (log.level > 0)
                            Hexdump.hexdump(System.err, src, srcIndex, maxLen < 128 ? maxLen + 8 : 128);
                        throw new RuntimeException("zero termination not found");
                    }
                }
                str = new String(src, srcIndex, len, OEM_ENCODING);
            }
        } catch( UnsupportedEncodingException uee ) {
            if( log.level > 1 )
                uee.printStackTrace( log );
        }
        return str;
    
intreadStringLength(byte[] src, int srcIndex, int max)

        int len = 0;
        while( src[srcIndex + len] != (byte)0x00 ) {
            if( len++ > max ) {
                throw new RuntimeException( "zero termination not found: " + this );
            }
        }
        return len;
    
static longreadTime(byte[] src, int srcIndex)

        int low = readInt4( src, srcIndex );
        int hi = readInt4( src, srcIndex + 4 );
        long t = ((long)hi << 32L ) | (low & 0xFFFFFFFFL);
        t = ( t / 10000L - MILLISECONDS_BETWEEN_1970_AND_1601 );
        return t;
    
static longreadUTime(byte[] buffer, int bufferIndex)

        return readInt4( buffer, bufferIndex ) * 1000L;
    
voidreset()

        flags = (byte)( FLAGS_PATH_NAMES_CASELESS | FLAGS_PATH_NAMES_CANONICALIZED );
        flags2 = 0;
        errorCode = 0;
        received = false;
        digest = null;
    
intstringWireLength(java.lang.String str, int offset)

        int len = str.length() + 1;
        if( useUnicode ) {
            len = str.length() * 2 + 2;
            len = ( offset % 2 ) != 0 ? len + 1 : len;
        }
        return len;
    
public java.lang.StringtoString()

        String c;
        switch( command ) {
            case SMB_COM_NEGOTIATE:
                c = "SMB_COM_NEGOTIATE";
                break;
            case SMB_COM_SESSION_SETUP_ANDX:
                c = "SMB_COM_SESSION_SETUP_ANDX";
                break;
            case SMB_COM_TREE_CONNECT_ANDX:
                c = "SMB_COM_TREE_CONNECT_ANDX";
                break;
            case SMB_COM_QUERY_INFORMATION:
                c = "SMB_COM_QUERY_INFORMATION";
                break;
            case SMB_COM_CHECK_DIRECTORY:
                c = "SMB_COM_CHECK_DIRECTORY";
                break;
            case SMB_COM_TRANSACTION:
                c = "SMB_COM_TRANSACTION";
                break;
            case SMB_COM_TRANSACTION2:
                c = "SMB_COM_TRANSACTION2";
                break;
            case SMB_COM_TRANSACTION_SECONDARY:
                c = "SMB_COM_TRANSACTION_SECONDARY";
                break;
            case SMB_COM_FIND_CLOSE2:
                c = "SMB_COM_FIND_CLOSE2";
                break;
            case SMB_COM_TREE_DISCONNECT:
                c = "SMB_COM_TREE_DISCONNECT";
                break;
            case SMB_COM_LOGOFF_ANDX:
                c = "SMB_COM_LOGOFF_ANDX";
                break;
            case SMB_COM_ECHO:
                c = "SMB_COM_ECHO";
                break;
            case SMB_COM_MOVE:
                c = "SMB_COM_MOVE";
                break;
            case SMB_COM_RENAME:
                c = "SMB_COM_RENAME";
                break;
            case SMB_COM_DELETE:
                c = "SMB_COM_DELETE";
                break;
            case SMB_COM_DELETE_DIRECTORY:
                c = "SMB_COM_DELETE_DIRECTORY";
                break;
            case SMB_COM_NT_CREATE_ANDX:
                c = "SMB_COM_NT_CREATE_ANDX";
                break;
            case SMB_COM_OPEN_ANDX:
                c = "SMB_COM_OPEN_ANDX";
                break;
            case SMB_COM_READ_ANDX:
                c = "SMB_COM_READ_ANDX";
                break;
            case SMB_COM_CLOSE:
                c = "SMB_COM_CLOSE";
                break;
            case SMB_COM_WRITE_ANDX:
                c = "SMB_COM_WRITE_ANDX";
                break;
            case SMB_COM_CREATE_DIRECTORY:
                c = "SMB_COM_CREATE_DIRECTORY";
                break;
            case SMB_COM_NT_TRANSACT:
                c = "SMB_COM_NT_TRANSACT";
                break;
            case SMB_COM_NT_TRANSACT_SECONDARY:
                c = "SMB_COM_NT_TRANSACT_SECONDARY";
                break;
            default:
                c = "UNKNOWN";
        }
        String str = errorCode == 0 ? "0" : SmbException.getMessageByCode( errorCode );
        return new String(
            "command="      + c +
            ",received="    + received +
            ",errorCode="   + str +
            ",flags=0x"     + Hexdump.toHexString( flags & 0xFF, 4 ) +
            ",flags2=0x"    + Hexdump.toHexString( flags2, 4 ) +
            ",signSeq="     + signSeq +
            ",tid="         + tid +
            ",pid="         + pid +
            ",uid="         + uid +
            ",mid="         + mid +
            ",wordCount="   + wordCount +
            ",byteCount="   + byteCount );
    
abstract intwriteBytesWireFormat(byte[] dst, int dstIndex)

intwriteHeaderWireFormat(byte[] dst, int dstIndex)

        System.arraycopy( header, 0, dst, dstIndex, header.length );
        dst[dstIndex + CMD_OFFSET] = command;
        dst[dstIndex + FLAGS_OFFSET] = flags;
        writeInt2( flags2, dst, dstIndex + FLAGS_OFFSET + 1 );
        dstIndex += TID_OFFSET;
        writeInt2( tid, dst, dstIndex );
        writeInt2( pid, dst, dstIndex + 2 );
        writeInt2( uid, dst, dstIndex + 4 );
        writeInt2( mid, dst, dstIndex + 6 );
        return HEADER_LENGTH;
    
static voidwriteInt2(long val, byte[] dst, int dstIndex)


              
        dst[dstIndex] = (byte)(val);
        dst[++dstIndex] = (byte)(val >> 8);
    
static voidwriteInt4(long val, byte[] dst, int dstIndex)

        dst[dstIndex] = (byte)(val);
        dst[++dstIndex] = (byte)(val >>= 8);
        dst[++dstIndex] = (byte)(val >>= 8);
        dst[++dstIndex] = (byte)(val >> 8);
    
static voidwriteInt8(long val, byte[] dst, int dstIndex)

        dst[dstIndex] = (byte)(val);
        dst[++dstIndex] = (byte)(val >>= 8);
        dst[++dstIndex] = (byte)(val >>= 8);
        dst[++dstIndex] = (byte)(val >>= 8);
        dst[++dstIndex] = (byte)(val >>= 8);
        dst[++dstIndex] = (byte)(val >>= 8);
        dst[++dstIndex] = (byte)(val >>= 8);
        dst[++dstIndex] = (byte)(val >> 8);
    
abstract intwriteParameterWordsWireFormat(byte[] dst, int dstIndex)

intwriteString(java.lang.String str, byte[] dst, int dstIndex)

        return writeString( str, dst, dstIndex, useUnicode );
    
intwriteString(java.lang.String str, byte[] dst, int dstIndex, boolean useUnicode)

        int start = dstIndex;

        try {
            if( useUnicode ) {
                // Unicode requires word alignment
                if((( dstIndex - headerStart ) % 2 ) != 0 ) {
                    dst[dstIndex++] = (byte)'\0";
                }
                System.arraycopy( str.getBytes( UNI_ENCODING ), 0,
                                    dst, dstIndex, str.length() * 2 );
                dstIndex += str.length() * 2;
                dst[dstIndex++] = (byte)'\0";
                dst[dstIndex++] = (byte)'\0";
            } else {
                byte[] b = str.getBytes( OEM_ENCODING );
                System.arraycopy( b, 0, dst, dstIndex, b.length );
                dstIndex += b.length;
                dst[dstIndex++] = (byte)'\0";
            }
        } catch( UnsupportedEncodingException uee ) {
            if( log.level > 1 )
                uee.printStackTrace( log );
        }

        return dstIndex - start;
    
static voidwriteTime(long t, byte[] dst, int dstIndex)

        if( t != 0L ) {
            t = (t + MILLISECONDS_BETWEEN_1970_AND_1601) * 10000L;
        }
        writeInt8( t, dst, dstIndex );
    
static voidwriteUTime(long t, byte[] dst, int dstIndex)

        if( t == 0L || t == 0xFFFFFFFFFFFFFFFFL ) {
            writeInt4( 0xFFFFFFFF, dst, dstIndex );
            return;
        }
        synchronized( TZ ) {
            if( TZ.inDaylightTime( new Date() )) {
                // in DST
                if( TZ.inDaylightTime( new Date( t ))) {
                    // t also in DST so no correction
                } else {
                    // t not in DST so subtract 1 hour
                    t -= 3600000;
                }
            } else {
                // not in DST
                if( TZ.inDaylightTime( new Date( t ))) {
                    // t is in DST so add 1 hour
                    t += 3600000;
                } else {
                    // t isn't in DST either
                }
            }
        }
        writeInt4( (int)(t / 1000L), dst, dstIndex );