KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > 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 jcifs.smb;
20
21 import java.util.Date JavaDoc;
22 import java.io.UnsupportedEncodingException JavaDoc;
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 JavaDoc( "zero termination not found" );
82                         }
83                     }
84                     server.oemDomainName = new String JavaDoc( buffer, bufferIndex,
85                             len, "UnicodeLittle" );
86                 } else {
87                     while( buffer[bufferIndex + len] != (byte)0x00 ) {
88                         len++;
89                         if( len > 256 ) {
90                             throw new RuntimeException JavaDoc( "zero termination not found" );
91                         }
92                     }
93                     server.oemDomainName = new String JavaDoc( buffer, bufferIndex,
94                             len, ServerMessageBlock.OEM_ENCODING );
95                 }
96             } catch( UnsupportedEncodingException JavaDoc uee ) {
97                 if( log.level > 1 )
98                     uee.printStackTrace( log );
99             }
100             bufferIndex += len;
101         } else {
102             server.oemDomainName = new String JavaDoc();
103         }
104
105         return bufferIndex - start;
106     }
107     public String JavaDoc toString() {
108         return new String JavaDoc( "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 JavaDoc( 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