1 18 19 package jcifs.smb; 20 21 import java.io.IOException ; 22 import java.net.UnknownHostException ; 23 import jcifs.UniAddress; 24 import jcifs.netbios.NbtAddress; 25 import jcifs.Config; 26 27 class SmbTree { 28 29 private static int tree_conn_counter; 30 31 private int tid; 32 private String share; 33 34 String service = "?????"; 35 SmbSession session; 36 boolean treeConnected, inDfs; 37 int tree_num; 38 39 SmbTree( SmbSession session, String share, String service ) { 40 this.session = session; 41 this.share = share.toUpperCase(); 42 if( service != null && service.startsWith( "??" ) == false ) { 43 this.service = service; 44 } 45 } 46 47 boolean matches( String share, String service ) { 48 return this.share.equalsIgnoreCase( share ) && 49 ( service == null || service.startsWith( "??" ) || 50 this.service.equalsIgnoreCase( service )); 51 } 52 void send( ServerMessageBlock request, 53 ServerMessageBlock response ) throws SmbException { 54 if( response != null ) { 55 response.received = false; 56 } 57 treeConnect( request, response ); 58 if( request == null || (response != null && response.received )) { 59 return; 60 } 61 if( service.equals( "A:" ) == false ) { 62 switch( request.command ) { 63 case ServerMessageBlock.SMB_COM_OPEN_ANDX: 64 case ServerMessageBlock.SMB_COM_NT_CREATE_ANDX: 65 case ServerMessageBlock.SMB_COM_READ_ANDX: 66 case ServerMessageBlock.SMB_COM_WRITE_ANDX: 67 case ServerMessageBlock.SMB_COM_CLOSE: 68 case ServerMessageBlock.SMB_COM_TREE_DISCONNECT: 69 break; 70 case ServerMessageBlock.SMB_COM_TRANSACTION: 71 case ServerMessageBlock.SMB_COM_TRANSACTION2: 72 switch( ((SmbComTransaction)request).subCommand & 0xFF ) { 73 case SmbComTransaction.NET_SHARE_ENUM: 74 case SmbComTransaction.NET_SERVER_ENUM2: 75 case SmbComTransaction.NET_SERVER_ENUM3: 76 case SmbComTransaction.TRANS_PEEK_NAMED_PIPE: 77 case SmbComTransaction.TRANS_WAIT_NAMED_PIPE: 78 case SmbComTransaction.TRANS_CALL_NAMED_PIPE: 79 case SmbComTransaction.TRANS_TRANSACT_NAMED_PIPE: 80 case SmbComTransaction.TRANS2_GET_DFS_REFERRAL: 81 break; 82 default: 83 throw new SmbException( "Invalid operation for " + service + " service" ); 84 } 85 break; 86 default: 87 throw new SmbException( "Invalid operation for " + service + " service" + request ); 88 } 89 } 90 request.tid = tid; 91 if( inDfs && request.path != null && request.path.length() > 0 ) { 92 98 request.flags2 = ServerMessageBlock.FLAGS2_RESOLVE_PATHS_IN_DFS; 99 request.path = '\\' + session.transport().tconHostName + '\\' + share + request.path; 100 } 101 try { 102 session.send( request, response ); 103 } catch( SmbException se ) { 104 if (se.getNtStatus() == se.NT_STATUS_NETWORK_NAME_DELETED) { 105 110 treeDisconnect( true ); 111 } 112 throw se; 113 } 114 } 115 void treeConnect( ServerMessageBlock andx, 116 ServerMessageBlock andxResponse ) throws SmbException { 117 String unc; 118 synchronized( session.transport() ) { 119 120 if (treeConnected) { 121 return; 122 } 123 124 128 129 session.transport.connect(); 130 131 unc = "\\\\" + session.transport.tconHostName + '\\' + share; 132 133 136 137 if( session.transport.log.level > 2 ) 138 session.transport.log.println( "treeConnect: unc=" + unc + ",service=" + service ); 139 140 SmbComTreeConnectAndXResponse response = 141 new SmbComTreeConnectAndXResponse( andxResponse ); 142 SmbComTreeConnectAndX request = 143 new SmbComTreeConnectAndX( session, unc, service, andx ); 144 session.send( request, response ); 145 146 tid = response.tid; 147 service = response.service; 148 inDfs = response.shareIsInDfs; 149 treeConnected = true; 150 tree_num = tree_conn_counter++; 151 } 152 } 153 void treeDisconnect( boolean inError ) { 154 synchronized( session.transport ) { 155 if (treeConnected && !inError) { 156 try { 157 send( new SmbComTreeDisconnect(), null ); 158 } catch( SmbException se ) { 159 if (session.transport.log.level > 1) { 160 se.printStackTrace( session.transport.log ); 161 } 162 } 163 } 164 treeConnected = false; 165 } 166 } 167 168 public String toString() { 169 return "SmbTree[share=" + share + 170 ",service=" + service + 171 ",tid=" + tid + 172 ",inDfs=" + inDfs + 173 ",treeConnected=" + treeConnected + "]"; 174 } 175 } 176 | Popular Tags |