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