1 18 19 package jcifs.smb; 20 21 import java.util.Date ; 22 import java.io.UnsupportedEncodingException ; 23 import jcifs.util.Hexdump; 24 25 class SmbComNegotiateResponse extends ServerMessageBlock { 26 27 int dialectIndex; 28 SmbTransport.ServerData server; 29 30 SmbComNegotiateResponse( SmbTransport.ServerData server ) { 31 this.server = server; 32 } 33 34 int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) { 35 return 0; 36 } 37 int writeBytesWireFormat( byte[] dst, int dstIndex ) { 38 return 0; 39 } 40 int readParameterWordsWireFormat( byte[] buffer, 41 int bufferIndex ) { 42 int start = bufferIndex; 43 44 dialectIndex = readInt2( buffer, bufferIndex ); bufferIndex += 2; 45 if( dialectIndex > 10 ) { 46 return bufferIndex - start; 47 } 48 server.securityMode = buffer[bufferIndex++] & 0xFF; 49 server.security = server.securityMode & 0x01; 50 server.encryptedPasswords = ( server.securityMode & 0x02 ) == 0x02; 51 server.signaturesEnabled = ( server.securityMode & 0x04 ) == 0x04; 52 server.signaturesRequired = ( server.securityMode & 0x08 ) == 0x08; 53 server.maxMpxCount = readInt2( buffer, bufferIndex ); bufferIndex += 2; 54 server.maxNumberVcs = readInt2( buffer, bufferIndex ); bufferIndex += 2; 55 server.maxBufferSize = readInt4( buffer, bufferIndex ); bufferIndex += 4; 56 server.maxRawSize = readInt4( buffer, bufferIndex ); bufferIndex += 4; 57 server.sessionKey = readInt4( buffer, bufferIndex ); bufferIndex += 4; 58 server.capabilities = readInt4( buffer, bufferIndex ); bufferIndex += 4; 59 server.serverTime = readTime( buffer, bufferIndex ); bufferIndex += 8; 60 server.serverTimeZone = readInt2( buffer, bufferIndex ); bufferIndex += 2; 61 server.encryptionKeyLength = buffer[bufferIndex++] & 0xFF; 62 63 return bufferIndex - start; 64 } 65 int readBytesWireFormat( byte[] buffer, 66 int bufferIndex ) { 67 int start = bufferIndex; 68 69 server.encryptionKey = new byte[server.encryptionKeyLength]; 70 System.arraycopy( buffer, bufferIndex, 71 server.encryptionKey, 0, server.encryptionKeyLength ); 72 bufferIndex += server.encryptionKeyLength; 73 if( byteCount > server.encryptionKeyLength ) { 74 int len = 0; 75 try { 76 if(( flags2 & FLAGS2_UNICODE ) == FLAGS2_UNICODE ) { 77 while( buffer[bufferIndex + len] != (byte)0x00 || 78 buffer[bufferIndex + len + 1] != (byte)0x00 ) { 79 len += 2; 80 if( len > 256 ) { 81 throw new RuntimeException ( "zero termination not found" ); 82 } 83 } 84 server.oemDomainName = new String ( buffer, bufferIndex, 85 len, "UnicodeLittle" ); 86 } else { 87 while( buffer[bufferIndex + len] != (byte)0x00 ) { 88 len++; 89 if( len > 256 ) { 90 throw new RuntimeException ( "zero termination not found" ); 91 } 92 } 93 server.oemDomainName = new String ( buffer, bufferIndex, 94 len, ServerMessageBlock.OEM_ENCODING ); 95 } 96 } catch( UnsupportedEncodingException uee ) { 97 if( log.level > 1 ) 98 uee.printStackTrace( log ); 99 } 100 bufferIndex += len; 101 } else { 102 server.oemDomainName = new String (); 103 } 104 105 return bufferIndex - start; 106 } 107 public String toString() { 108 return new String ( "SmbComNegotiateResponse[" + 109 super.toString() + 110 ",wordCount=" + wordCount + 111 ",dialectIndex=" + dialectIndex + 112 ",securityMode=0x" + Hexdump.toHexString( server.securityMode, 1 ) + 113 ",security=" + ( server.security == SECURITY_SHARE ? "share" : "user" ) + 114 ",encryptedPasswords=" + server.encryptedPasswords + 115 ",maxMpxCount=" + server.maxMpxCount + 116 ",maxNumberVcs=" + server.maxNumberVcs + 117 ",maxBufferSize=" + server.maxBufferSize + 118 ",maxRawSize=" + server.maxRawSize + 119 ",sessionKey=0x" + Hexdump.toHexString( server.sessionKey, 8 ) + 120 ",capabilities=0x" + Hexdump.toHexString( server.capabilities, 8 ) + 121 ",serverTime=" + new Date ( server.serverTime ) + 122 ",serverTimeZone=" + server.serverTimeZone + 123 ",encryptionKeyLength=" + server.encryptionKeyLength + 124 ",byteCount=" + byteCount + 125 ",encryptionKey=0x" + Hexdump.toHexString( server.encryptionKey, 126 0, 127 server.encryptionKeyLength * 2 ) + 128 ",oemDomainName=" + server.oemDomainName + "]" ); 129 } 130 } 131 132 | Popular Tags |