KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > jcifs > smb > SmbComNegotiateResponse


1 /* jcifs smb client library in Java
2  * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

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