001: /* jcifs smb client library in Java
002: * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package jcifs.smb;
020:
021: import java.util.Date;
022: import java.io.UnsupportedEncodingException;
023: import jcifs.util.Hexdump;
024:
025: class SmbComNegotiateResponse extends ServerMessageBlock {
026:
027: int dialectIndex, securityMode, security, maxMpxCount,
028: maxNumberVcs, maxBufferSize, maxRawSize, sessionKey,
029: capabilities, serverTimeZone, encryptionKeyLength;
030: boolean encryptedPasswords, signaturesEnabled, signaturesRequired;
031: long serverTime;
032: byte[] encryptionKey;
033: String oemDomainName;
034:
035: SmbComNegotiateResponse() {
036: }
037:
038: int writeParameterWordsWireFormat(byte[] dst, int dstIndex) {
039: return 0;
040: }
041:
042: int writeBytesWireFormat(byte[] dst, int dstIndex) {
043: return 0;
044: }
045:
046: int readParameterWordsWireFormat(byte[] buffer, int bufferIndex) {
047: int start = bufferIndex;
048: dialectIndex = readInt2(buffer, bufferIndex);
049: bufferIndex += 2;
050: if (dialectIndex > 10) {
051: return bufferIndex - start;
052: }
053: securityMode = buffer[bufferIndex++] & 0xFF;
054: security = securityMode & 0x01;
055: encryptedPasswords = (securityMode & 0x02) == 0x02 ? true
056: : false;
057: signaturesEnabled = (securityMode & 0x04) == 0x04 ? true
058: : false;
059: signaturesRequired = (securityMode & 0x08) == 0x08 ? true
060: : false;
061: maxMpxCount = readInt2(buffer, bufferIndex);
062: bufferIndex += 2;
063: maxNumberVcs = readInt2(buffer, bufferIndex);
064: bufferIndex += 2;
065: maxBufferSize = readInt4(buffer, bufferIndex);
066: bufferIndex += 4;
067: maxRawSize = readInt4(buffer, bufferIndex);
068: bufferIndex += 4;
069: sessionKey = readInt4(buffer, bufferIndex);
070: bufferIndex += 4;
071: capabilities = readInt4(buffer, bufferIndex);
072: bufferIndex += 4;
073: serverTime = readTime(buffer, bufferIndex);
074: bufferIndex += 8;
075: serverTimeZone = readInt2(buffer, bufferIndex);
076: bufferIndex += 2;
077: encryptionKeyLength = buffer[bufferIndex++] & 0xFF;
078: return bufferIndex - start;
079: }
080:
081: int readBytesWireFormat(byte[] buffer, int bufferIndex) {
082: int start = bufferIndex;
083: encryptionKey = new byte[encryptionKeyLength];
084: System.arraycopy(buffer, bufferIndex, encryptionKey, 0,
085: encryptionKeyLength);
086: bufferIndex += encryptionKeyLength;
087:
088: if (byteCount > encryptionKeyLength) {
089: int len = 0;
090: if ((flags2 & FLAGS2_UNICODE) == FLAGS2_UNICODE) {
091: while (buffer[bufferIndex + len] != (byte) 0x00
092: || buffer[bufferIndex + len + 1] != (byte) 0x00) {
093: len += 2;
094: if (len > 256) {
095: throw new RuntimeException(
096: "zero termination not found");
097: }
098: }
099: try {
100: oemDomainName = new String(buffer, bufferIndex,
101: len, "UnicodeLittle");
102: } catch (UnsupportedEncodingException uee) {
103: if (log.level > 1)
104: uee.printStackTrace(log);
105: }
106: } else {
107: while (buffer[bufferIndex + len] != (byte) 0x00) {
108: len++;
109: if (len > 256) {
110: throw new RuntimeException(
111: "zero termination not found");
112: }
113: }
114: try {
115: oemDomainName = new String(buffer, bufferIndex,
116: len, ServerMessageBlock.OEM_ENCODING);
117: } catch (UnsupportedEncodingException uee) {
118: }
119: }
120: bufferIndex += len;
121: } else {
122: oemDomainName = new String();
123: }
124:
125: return bufferIndex - start;
126: }
127:
128: public String toString() {
129: return new String("SmbComNegotiateResponse["
130: + super .toString()
131: + ",wordCount="
132: + wordCount
133: + ",dialectIndex="
134: + dialectIndex
135: + ",securityMode=0x"
136: + Hexdump.toHexString(securityMode, 1)
137: + ",security="
138: + (security == SECURITY_SHARE ? "share" : "user")
139: + ",encryptedPasswords="
140: + encryptedPasswords
141: + ",maxMpxCount="
142: + maxMpxCount
143: + ",maxNumberVcs="
144: + maxNumberVcs
145: + ",maxBufferSize="
146: + maxBufferSize
147: + ",maxRawSize="
148: + maxRawSize
149: + ",sessionKey=0x"
150: + Hexdump.toHexString(sessionKey, 8)
151: + ",capabilities=0x"
152: + Hexdump.toHexString(capabilities, 8)
153: + ",serverTime="
154: + new Date(serverTime)
155: + ",serverTimeZone="
156: + serverTimeZone
157: + ",encryptionKeyLength="
158: + encryptionKeyLength
159: + ",byteCount="
160: + byteCount
161: + ",encryptionKey=0x"
162: + Hexdump.toHexString(encryptionKey, 0,
163: encryptionKeyLength * 2) + ",oemDomainName="
164: + oemDomainName + "]");
165: }
166: }
|