1 18 19 package com.knowgate.jcifs.smb; 20 21 import com.knowgate.jcifs.Config; 22 import com.knowgate.misc.Gadgets; 23 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.UnsupportedEncodingException ; 27 28 class SmbComTreeConnectAndX extends AndXServerMessageBlock { 29 30 private static final boolean DISABLE_PLAIN_TEXT_PASSWORDS = 31 Config.getBoolean( "jcifs.smb.client.disablePlainTextPasswords", true ); 32 33 private SmbSession session; 34 private boolean disconnectTid = false; 35 private String path, service; 36 private byte[] password; 37 private int passwordLength; 38 39 50 51 53 54 private static byte[] batchLimits = { 55 1, 1, 1, 1, 1, 1, 1, 1, 0 56 }; 57 58 static { 59 String s; 60 61 if(( s = Config.getProperty( "jcifs.smb.client.TreeConnectAndX.CheckDirectory" )) != null ) { 62 batchLimits[0] = Byte.parseByte( s ); 63 } 64 if(( s = Config.getProperty( "jcifs.smb.client.TreeConnectAndX.CreateDirectory" )) != null ) { 65 batchLimits[2] = Byte.parseByte( s ); 66 } 67 if(( s = Config.getProperty( "jcifs.smb.client.TreeConnectAndX.Delete" )) != null ) { 68 batchLimits[3] = Byte.parseByte( s ); 69 } 70 if(( s = Config.getProperty( "jcifs.smb.client.TreeConnectAndX.DeleteDirectory" )) != null ) { 71 batchLimits[4] = Byte.parseByte( s ); 72 } 73 if(( s = Config.getProperty( "jcifs.smb.client.TreeConnectAndX.OpenAndX" )) != null ) { 74 batchLimits[5] = Byte.parseByte( s ); 75 } 76 if(( s = Config.getProperty( "jcifs.smb.client.TreeConnectAndX.Rename" )) != null ) { 77 batchLimits[6] = Byte.parseByte( s ); 78 } 79 if(( s = Config.getProperty( "jcifs.smb.client.TreeConnectAndX.Transaction" )) != null ) { 80 batchLimits[7] = Byte.parseByte( s ); 81 } 82 if(( s = Config.getProperty( "jcifs.smb.client.TreeConnectAndX.QueryInformation" )) != null ) { 83 batchLimits[8] = Byte.parseByte( s ); 84 } 85 } 86 87 SmbComTreeConnectAndX( SmbSession session, String path, 88 String service, ServerMessageBlock andx ) { 89 super( andx ); 90 this.session = session; 91 this.path = path; 92 this.service = service; 93 command = SMB_COM_TREE_CONNECT_ANDX; 94 } 95 96 int getBatchLimit( byte command ) { 97 int c = (int)( command & 0xFF ); 98 switch( c ) { 100 case SMB_COM_CHECK_DIRECTORY: 101 return batchLimits[0]; 102 case SMB_COM_CREATE_DIRECTORY: 103 return batchLimits[2]; 104 case SMB_COM_DELETE: 105 return batchLimits[3]; 106 case SMB_COM_DELETE_DIRECTORY: 107 return batchLimits[4]; 108 case SMB_COM_OPEN_ANDX: 109 return batchLimits[5]; 110 case SMB_COM_RENAME: 111 return batchLimits[6]; 112 case SMB_COM_TRANSACTION: 113 return batchLimits[7]; 114 case SMB_COM_QUERY_INFORMATION: 115 return batchLimits[8]; 116 } 117 return 0; 118 } 119 120 int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) { 121 122 if( session.transport.server.security == SECURITY_SHARE && 123 ( session.auth.hashesExternal || 124 session.auth.password.length() > 0 )) { 125 126 if( session.transport.server.encryptedPasswords ) { 127 password = session.auth.getAnsiHash( session.transport.server.encryptionKey ); 129 passwordLength = password.length; 130 } else if( DISABLE_PLAIN_TEXT_PASSWORDS ) { 131 throw new RuntimeException ( "Plain text passwords are disabled" ); 132 } else { 133 password = new byte[(session.auth.password.length() + 1) * 2]; 135 passwordLength = writeString( session.auth.password, password, 0 ); 136 } 137 } else { 138 passwordLength = 1; 140 } 141 142 dst[dstIndex++] = disconnectTid ? (byte)0x01 : (byte)0x00; 143 dst[dstIndex++] = (byte)0x00; 144 writeInt2( passwordLength, dst, dstIndex ); 145 return 4; 146 } 147 int writeBytesWireFormat( byte[] dst, int dstIndex ) { 148 int start = dstIndex; 149 150 if( session.transport.server.security == SECURITY_SHARE && 151 ( session.auth.hashesExternal || 152 session.auth.password.length() > 0 )) { 153 System.arraycopy( password, 0, dst, dstIndex, passwordLength ); 154 dstIndex += passwordLength; 155 } else { 156 dst[dstIndex++] = (byte)0x00; 158 } 159 dstIndex += writeString( path, dst, dstIndex ); 160 try { 161 System.arraycopy( service.getBytes( "ASCII" ), 0, dst, dstIndex, service.length() ); 162 } catch( UnsupportedEncodingException uee ) { 163 return 0; 164 } 165 dstIndex += service.length(); 166 dst[dstIndex++] = (byte)'\0'; 167 168 return dstIndex - start; 169 } 170 int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) { 171 return 0; 172 } 173 int readBytesWireFormat( byte[] buffer, int bufferIndex ) { 174 return 0; 175 } 176 int readBytesDirectWireFormat( InputStream in, int byteCount, 177 byte[] buffer, int bufferIndex ) throws IOException { 178 return 0; 179 } 180 public String toString() { 181 String result = new String ( "SmbComTreeConnectAndX[" + 182 super.toString() + 183 ",disconnectTid=" + disconnectTid + 184 ",passwordLength=" + passwordLength + 185 ",password=" + Gadgets.toHexString( password, passwordLength, 0 ) + 186 ",path=" + path + 187 ",service=" + service + "]" ); 188 return result; 189 } 190 } 191 192 | Popular Tags |