/** * Determines the address of a host given it's host name. The name can be a * machine name like "jcifs.samba.org", or an IP address like "192.168.1.15". * * @param hostname NetBIOS or DNS hostname to resolve * @throws java.net.UnknownHostException if there is an error resolving the name */ public static UniAddress getByName( String hostname ) throws UnknownHostException { return getByName( hostname, false ); }
@SneakyThrows private UniAddress getUniAddress() { if (this.loadBalance) { if (StringUtils.isNotBlank(this.includePattern)) { val dcs = NbtAddress.getAllByName(this.domainController, NBT_ADDRESS_TYPE, null, null); return Arrays.stream(dcs) .filter(dc2 -> dc2.getHostAddress().matches(this.includePattern)) .findFirst() .map(UniAddress::new) .orElse(null); } return new UniAddress(NbtAddress.getByName(this.domainController, NBT_ADDRESS_TYPE, null)); } return UniAddress.getByName(this.domainController, true); }
boolean matches( UniAddress address, int port, InetAddress localAddr, int localPort, String hostName ) { if (hostName == null) hostName = address.getHostName(); return (this.tconHostName == null || hostName.equalsIgnoreCase(this.tconHostName)) && address.equals( this.address ) && (port == 0 || port == this.port || /* port 139 is ok if 445 was requested */ (port == 445 && this.port == 139)) && (localAddr == this.localAddr || (localAddr != null && localAddr.equals( this.localAddr ))) && localPort == this.localPort; } boolean hasCapability( int cap ) throws SmbException {
if( server != null && server.length() > 0 ) { addresses = new UniAddress[1]; addresses[0] = UniAddress.getByName( server ); return getNextAddress(); byte[] ip = java.net.InetAddress.getByName(address).getAddress(); addresses = new UniAddress[1]; addresses[0] = new UniAddress(java.net.InetAddress.getByAddress(host, ip)); return getNextAddress(); NbtAddress.MASTER_BROWSER_NAME, 0x01, null); addresses = new UniAddress[1]; addresses[0] = UniAddress.getByName( addr.getHostAddress() ); } catch( UnknownHostException uhe ) { NtlmPasswordAuthentication.initDefaults(); throw uhe; addresses = UniAddress.getAllByName( NtlmPasswordAuthentication.DEFAULT_DOMAIN, true ); addresses = UniAddress.getAllByName( host, true ); } else { addresses = UniAddress.getAllByName(host, false);
if( isDotQuadIP( hostname )) { UniAddress[] addrs = new UniAddress[1]; addrs[0] = new UniAddress( NbtAddress.getByName( hostname )); return addrs; addr = lookupServerOrWorkgroup( hostname, NbtAddress.getWINSAddress() ); } else { addr = NbtAddress.getByName( hostname, 0x20, null, NbtAddress.getWINSAddress() ); addr = lookupServerOrWorkgroup( hostname, baddr ); } else { addr = NbtAddress.getByName( hostname, 0x20, null, baddr ); if( isAllDigits( hostname )) { throw new UnknownHostException( hostname ); UniAddress[] addrs = new UniAddress[iaddrs.length]; for (int ii = 0; ii < iaddrs.length; ii++) { addrs[ii] = new UniAddress(iaddrs[ii]); addrs[0] = new UniAddress( addr ); return addrs; // Success } catch( IOException ioe ) {
} else if( share == null ) { if( getType() == TYPE_WORKGROUP ) { UniAddress.getByName( url.getHost(), true ); } else { UniAddress.getByName( url.getHost() ).getHostName();
void ssn139() throws IOException { Name calledName = new Name( address.firstCalledName(), 0x20, null ); do { if (localAddr == null) { socket = new Socket( address.getHostAddress(), 139 ); } else { socket = new Socket( address.getHostAddress(), 139, localAddr, localPort ); throw new NbtException( NbtException.ERR_SSN_SRVC, 0 ); } while(( calledName.name = address.nextCalledName()) != null );
socket = new Socket( address.getHostAddress(), port ); } else { socket = new Socket( address.getHostAddress(), port, localAddr, localPort );
private static NtlmChallenge interrogate( NbtAddress addr ) throws SmbException { UniAddress dc = new UniAddress( addr ); SmbTransport trans = SmbTransport.getSmbTransport( dc, 0 ); if (USERNAME == null) { trans.connect(); if (SmbTransport.log.level >= 3) SmbTransport.log.println( "Default credentials (jcifs.smb.client.username/password)" + " not specified. SMB signing may not work propertly." + " Skipping DC interrogation." ); } else { SmbSession ssn = trans.getSmbSession( NtlmPasswordAuthentication.DEFAULT ); ssn.getSmbTree( LOGON_SHARE, null ).treeConnect( null, null ); } return new NtlmChallenge( trans.server.encryptionKey, dc ); } public static NtlmChallenge getChallengeForDomain()
boolean isWorkgroup0() throws UnknownHostException { if( type == TYPE_WORKGROUP || url.getHost().length() == 0 ) { type = TYPE_WORKGROUP; return true; } else { getUncPath0(); if( share == null ) { UniAddress addr = getAddress(); if( addr.getAddress() instanceof NbtAddress ) { int code = ((NbtAddress)addr.getAddress()).getNameType(); if( code == 0x1d || code == 0x1b ) { type = TYPE_WORKGROUP; return true; } } type = TYPE_SERVER; } } return false; }
ret = getAddress().equals(f.getAddress()); } catch( UnknownHostException uhe ) { ret = getServer().equalsIgnoreCase(f.getServer());
SpnegoContext spnego = null; try{ String host = session.transport.address.getHostAddress(); try{ host = session.transport.address.getHostName(); }catch(Exception e){} context = createContext(host);
/** * Lookup <tt>hostname</tt> and return it's <tt>UniAddress</tt>. If the * <tt>possibleNTDomainOrWorkgroup</tt> parameter is <tt>true</tt> an * addtional name query will be performed to locate a master browser. */ public static UniAddress getByName( String hostname, boolean possibleNTDomainOrWorkgroup ) throws UnknownHostException { UniAddress[] addrs = UniAddress.getAllByName(hostname, possibleNTDomainOrWorkgroup); return addrs[0]; } public static UniAddress[] getAllByName( String hostname,
/** * Computes a hashCode for this file based on the URL string and IP * address if the server. The hashing function uses the hashcode of the * server address, the canonical representation of the URL, and does not * compare authentication information. In essance, two * <code>SmbFile</code> objects that refer to * the same file should generate the same hashcode provided it is possible * to make such a determination. * * @return A hashcode for this abstract file * @throws SmbException */ public int hashCode() { int hash; try { hash = getAddress().hashCode(); } catch( UnknownHostException uhe ) { hash = getServer().toUpperCase().hashCode(); } getUncPath0(); return hash + canon.toUpperCase().hashCode(); }
tconHostName = address.getHostName(); if (server.signaturesRequired || (server.signaturesEnabled && SIGNPREF)) { flags2 |= ServerMessageBlock.FLAGS2_SECURITY_SIGNATURES;
if( server != null && server.length() > 0 ) { addresses = new UniAddress[1]; addresses[0] = UniAddress.getByName( server ); return getNextAddress(); byte[] ip = java.net.InetAddress.getByName(address).getAddress(); addresses = new UniAddress[1]; addresses[0] = new UniAddress(java.net.InetAddress.getByAddress(host, ip)); return getNextAddress(); NbtAddress.MASTER_BROWSER_NAME, 0x01, null); addresses = new UniAddress[1]; addresses[0] = UniAddress.getByName( addr.getHostAddress() ); } catch( UnknownHostException uhe ) { NtlmPasswordAuthentication.initDefaults(); throw uhe; addresses = UniAddress.getAllByName( NtlmPasswordAuthentication.DEFAULT_DOMAIN, true ); addresses = UniAddress.getAllByName( host, true ); } else { addresses = UniAddress.getAllByName(host, false);
if( isDotQuadIP( hostname )) { UniAddress[] addrs = new UniAddress[1]; addrs[0] = new UniAddress( NbtAddress.getByName( hostname )); return addrs; addr = lookupServerOrWorkgroup( hostname, NbtAddress.getWINSAddress() ); } else { addr = NbtAddress.getByName( hostname, 0x20, null, NbtAddress.getWINSAddress() ); addr = lookupServerOrWorkgroup( hostname, baddr ); } else { addr = NbtAddress.getByName( hostname, 0x20, null, baddr ); if( isAllDigits( hostname )) { throw new UnknownHostException( hostname ); UniAddress[] addrs = new UniAddress[iaddrs.length]; for (int ii = 0; ii < iaddrs.length; ii++) { addrs[ii] = new UniAddress(iaddrs[ii]); addrs[0] = new UniAddress( addr ); return addrs; // Success } catch( IOException ioe ) {
} else if( share == null ) { if( getType() == TYPE_WORKGROUP ) { UniAddress.getByName( url.getHost(), true ); } else { UniAddress.getByName( url.getHost() ).getHostName();
void ssn139() throws IOException { Name calledName = new Name( address.firstCalledName(), 0x20, null ); do { if (localAddr != null) socket.bind(new InetSocketAddress(localAddr, localPort)); socket.connect(new InetSocketAddress(address.getHostAddress(), 139), CONN_TIMEOUT); socket.setSoTimeout( SO_TIMEOUT ); throw new NbtException( NbtException.ERR_SSN_SRVC, 0 ); } while(( calledName.name = address.nextCalledName()) != null );
if (localAddr != null) socket.bind(new InetSocketAddress(localAddr, localPort)); socket.connect(new InetSocketAddress(address.getHostAddress(), port), CONN_TIMEOUT); socket.setSoTimeout( SO_TIMEOUT );