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 com.knowgate.jcifs.smb;
020:
021: import java.util.Date;
022: import java.io.UnsupportedEncodingException;
023:
024: import com.knowgate.debug.*;
025: import com.knowgate.misc.Gadgets;
026:
027: class SmbComNegotiateResponse extends ServerMessageBlock {
028:
029: int dialectIndex, securityMode, security, maxMpxCount,
030: maxNumberVcs, maxBufferSize, maxRawSize, sessionKey,
031: capabilities, serverTimeZone, encryptionKeyLength;
032: boolean encryptedPasswords, signaturesEnabled, signaturesRequired;
033: long serverTime;
034: byte[] encryptionKey;
035: String oemDomainName;
036:
037: SmbComNegotiateResponse() {
038: }
039:
040: int writeParameterWordsWireFormat(byte[] dst, int dstIndex) {
041: return 0;
042: }
043:
044: int writeBytesWireFormat(byte[] dst, int dstIndex) {
045: return 0;
046: }
047:
048: int readParameterWordsWireFormat(byte[] buffer, int bufferIndex) {
049: int start = bufferIndex;
050: dialectIndex = readInt2(buffer, bufferIndex);
051: bufferIndex += 2;
052: if (dialectIndex > 10) {
053: return bufferIndex - start;
054: }
055: securityMode = buffer[bufferIndex++] & 0xFF;
056: security = securityMode & 0x01;
057: encryptedPasswords = (securityMode & 0x02) == 0x02 ? true
058: : false;
059: signaturesEnabled = (securityMode & 0x04) == 0x04 ? true
060: : false;
061: signaturesRequired = (securityMode & 0x08) == 0x08 ? true
062: : false;
063: maxMpxCount = readInt2(buffer, bufferIndex);
064: bufferIndex += 2;
065: maxNumberVcs = readInt2(buffer, bufferIndex);
066: bufferIndex += 2;
067: maxBufferSize = readInt4(buffer, bufferIndex);
068: bufferIndex += 4;
069: maxRawSize = readInt4(buffer, bufferIndex);
070: bufferIndex += 4;
071: sessionKey = readInt4(buffer, bufferIndex);
072: bufferIndex += 4;
073: capabilities = readInt4(buffer, bufferIndex);
074: bufferIndex += 4;
075: serverTime = readTime(buffer, bufferIndex);
076: bufferIndex += 8;
077: serverTimeZone = readInt2(buffer, bufferIndex);
078: bufferIndex += 2;
079: encryptionKeyLength = buffer[bufferIndex++] & 0xFF;
080: return bufferIndex - start;
081: }
082:
083: int readBytesWireFormat(byte[] buffer, int bufferIndex) {
084: int start = bufferIndex;
085: encryptionKey = new byte[encryptionKeyLength];
086: System.arraycopy(buffer, bufferIndex, encryptionKey, 0,
087: encryptionKeyLength);
088: bufferIndex += encryptionKeyLength;
089:
090: if (byteCount > encryptionKeyLength) {
091: int len = 0;
092: if ((flags2 & FLAGS2_UNICODE) == FLAGS2_UNICODE) {
093: while (buffer[bufferIndex + len] != (byte) 0x00
094: || buffer[bufferIndex + len + 1] != (byte) 0x00) {
095: len += 2;
096: if (len > 256) {
097: throw new RuntimeException(
098: "zero termination not found");
099: }
100: }
101: try {
102: oemDomainName = new String(buffer, bufferIndex,
103: len, "UnicodeLittle");
104: } catch (UnsupportedEncodingException uee) {
105: if (DebugFile.trace)
106: new ErrorHandler(uee);
107: }
108: } else {
109: while (buffer[bufferIndex + len] != (byte) 0x00) {
110: len++;
111: if (len > 256) {
112: throw new RuntimeException(
113: "zero termination not found");
114: }
115: }
116: try {
117: oemDomainName = new String(buffer, bufferIndex,
118: len, ServerMessageBlock.OEM_ENCODING);
119: } catch (UnsupportedEncodingException uee) {
120: }
121: }
122: bufferIndex += len;
123: } else {
124: oemDomainName = new String();
125: }
126:
127: return bufferIndex - start;
128: }
129:
130: public String toString() {
131: return new String("SmbComNegotiateResponse["
132: + super .toString()
133: + ",wordCount="
134: + wordCount
135: + ",dialectIndex="
136: + dialectIndex
137: + ",securityMode=0x"
138: + Gadgets.toHexString(securityMode, 1)
139: + ",security="
140: + (security == SECURITY_SHARE ? "share" : "user")
141: + ",encryptedPasswords="
142: + encryptedPasswords
143: + ",maxMpxCount="
144: + maxMpxCount
145: + ",maxNumberVcs="
146: + maxNumberVcs
147: + ",maxBufferSize="
148: + maxBufferSize
149: + ",maxRawSize="
150: + maxRawSize
151: + ",sessionKey=0x"
152: + Gadgets.toHexString(sessionKey, 8)
153: + ",capabilities=0x"
154: + Gadgets.toHexString(capabilities, 8)
155: + ",serverTime="
156: + new Date(serverTime)
157: + ",serverTimeZone="
158: + serverTimeZone
159: + ",encryptionKeyLength="
160: + encryptionKeyLength
161: + ",byteCount="
162: + byteCount
163: + ",encryptionKey=0x"
164: + Gadgets.toHexString(encryptionKey, 0,
165: encryptionKeyLength * 2) + ",oemDomainName="
166: + oemDomainName + "]");
167: }
168: }
|