dnsns

16:35:24.469 INFO  jd.cli.Main - Decompiling dnsns.jar
package sun.net.spi.nameservice.dns;

import java.security.PrivilegedExceptionAction;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.spi.NamingManager;

class DNSNameService$1
  implements PrivilegedExceptionAction
{
  DNSNameService$1(DNSNameService paramDNSNameService, Hashtable paramHashtable) {}
  
  public Object run()
    throws NamingException
  {
    Context localContext = NamingManager.getInitialContext(val$env);
    if (!(localContext instanceof DirContext)) {
      return null;
    }
    return localContext;
  }
}

/* Location:
 * Qualified Name:     sun.net.spi.nameservice.dns.DNSNameService.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.net.spi.nameservice.dns;

import java.security.PrivilegedExceptionAction;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;

class DNSNameService$2
  implements PrivilegedExceptionAction
{
  DNSNameService$2(DNSNameService paramDNSNameService, DirContext paramDirContext, String paramString, String[] paramArrayOfString) {}
  
  public Object run()
    throws NamingException
  {
    return val$ctx.getAttributes(val$name, val$ids);
  }
}

/* Location:
 * Qualified Name:     sun.net.spi.nameservice.dns.DNSNameService.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.net.spi.nameservice.dns;

import java.util.List;
import javax.naming.directory.DirContext;

class DNSNameService$ThreadContext
{
  private DirContext dirCtxt;
  private List nsList;
  
  public DNSNameService$ThreadContext(DirContext paramDirContext, List paramList)
  {
    dirCtxt = paramDirContext;
    nsList = paramList;
  }
  
  public DirContext dirContext()
  {
    return dirCtxt;
  }
  
  public List nameservers()
  {
    return nsList;
  }
}

/* Location:
 * Qualified Name:     sun.net.spi.nameservice.dns.DNSNameService.ThreadContext
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.net.spi.nameservice.dns;

import java.lang.ref.SoftReference;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.spi.NamingManager;
import sun.net.dns.ResolverConfiguration;
import sun.net.spi.nameservice.NameService;
import sun.net.util.IPAddressUtil;
import sun.security.action.GetPropertyAction;

public final class DNSNameService
  implements NameService
{
  private LinkedList domainList = null;
  private String nameProviderUrl = null;
  private static ThreadLocal contextRef = new ThreadLocal();
  
  private static class ThreadContext
  {
    private DirContext dirCtxt;
    private List nsList;
    
    public ThreadContext(DirContext paramDirContext, List paramList)
    {
      dirCtxt = paramDirContext;
      nsList = paramList;
    }
    
    public DirContext dirContext()
    {
      return dirCtxt;
    }
    
    public List nameservers()
    {
      return nsList;
    }
  }
  
  private DirContext getTemporaryContext()
    throws NamingException
  {
    SoftReference localSoftReference = (SoftReference)contextRef.get();
    ThreadContext localThreadContext = null;
    List localList = null;
    if (nameProviderUrl == null) {
      localList = ResolverConfiguration.open().nameservers();
    }
    if ((localSoftReference != null) && ((localThreadContext = (ThreadContext)localSoftReference.get()) != null) && 
      (nameProviderUrl == null) && 
      (!localThreadContext.nameservers().equals(localList))) {
      localThreadContext = null;
    }
    if (localThreadContext == null)
    {
      final Hashtable localHashtable = new Hashtable();
      localHashtable.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
      
      String str = nameProviderUrl;
      if (str == null)
      {
        str = createProviderURL(localList);
        if (str.length() == 0) {
          throw new RuntimeException("bad nameserver configuration");
        }
      }
      localHashtable.put("java.naming.provider.url", str);
      DirContext localDirContext;
      try
      {
        localDirContext = (DirContext)AccessController.doPrivileged(new PrivilegedExceptionAction()
        {
          public Object run()
            throws NamingException
          {
            Context localContext = NamingManager.getInitialContext(localHashtable);
            if (!(localContext instanceof DirContext)) {
              return null;
            }
            return localContext;
          }
        });
      }
      catch (PrivilegedActionException localPrivilegedActionException)
      {
        throw ((NamingException)localPrivilegedActionException.getException());
      }
      localThreadContext = new ThreadContext(localDirContext, localList);
      contextRef.set(new SoftReference(localThreadContext));
    }
    return localThreadContext.dirContext();
  }
  
  private ArrayList resolve(final DirContext paramDirContext, final String paramString, final String[] paramArrayOfString, int paramInt)
    throws UnknownHostException
  {
    ArrayList localArrayList = new ArrayList();
    Attributes localAttributes;
    try
    {
      localAttributes = (Attributes)AccessController.doPrivileged(new PrivilegedExceptionAction()
      {
        public Object run()
          throws NamingException
        {
          return paramDirContext.getAttributes(paramString, paramArrayOfString);
        }
      });
    }
    catch (PrivilegedActionException localPrivilegedActionException)
    {
      throw new UnknownHostException(localPrivilegedActionException.getException().getMessage());
    }
    NamingEnumeration localNamingEnumeration1 = localAttributes.getAll();
    if (!localNamingEnumeration1.hasMoreElements()) {
      throw new UnknownHostException("DNS record not found");
    }
    Object localObject = null;
    try
    {
      String str1;
      NamingEnumeration localNamingEnumeration2;
      while (localNamingEnumeration1.hasMoreElements())
      {
        Attribute localAttribute = (Attribute)localNamingEnumeration1.next();
        str1 = localAttribute.getID();
        for (localNamingEnumeration2 = localAttribute.getAll(); localNamingEnumeration2.hasMoreElements();)
        {
          String str2 = (String)localNamingEnumeration2.next();
          if (str1.equals("CNAME"))
          {
            if (paramInt > 4) {
              throw new UnknownHostException(paramString + ": possible CNAME loop");
            }
            try
            {
              localArrayList.addAll(resolve(paramDirContext, str2, paramArrayOfString, paramInt + 1));
            }
            catch (UnknownHostException localUnknownHostException)
            {
              if (localObject == null) {
                localObject = localUnknownHostException;
              }
            }
          }
          else
          {
            localArrayList.add(str2);
          }
        }
      }
    }
    catch (NamingException localNamingException)
    {
      throw new UnknownHostException(localNamingException.getMessage());
    }
    if ((localArrayList.isEmpty()) && (localObject != null)) {
      throw ((Throwable)localObject);
    }
    return localArrayList;
  }
  
  public DNSNameService()
    throws Exception
  {
    String str1 = (String)AccessController.doPrivileged(new GetPropertyAction("sun.net.spi.nameservice.domain"));
    if ((str1 != null) && (str1.length() > 0))
    {
      domainList = new LinkedList();
      domainList.add(str1);
    }
    String str2 = (String)AccessController.doPrivileged(new GetPropertyAction("sun.net.spi.nameservice.nameservers"));
    if ((str2 != null) && (str2.length() > 0))
    {
      nameProviderUrl = createProviderURL(str2);
      if (nameProviderUrl.length() == 0) {
        throw new RuntimeException("malformed nameservers property");
      }
    }
    else
    {
      List localList = ResolverConfiguration.open().nameservers();
      if (localList.size() == 0) {
        throw new RuntimeException("no nameservers provided");
      }
      int i = 0;
      Iterator localIterator = localList.iterator();
      while (localIterator.hasNext())
      {
        String str3 = (String)localIterator.next();
        if ((IPAddressUtil.isIPv4LiteralAddress(str3)) || (IPAddressUtil.isIPv6LiteralAddress(str3)))
        {
          i = 1;
          break;
        }
      }
      if (i == 0) {
        throw new RuntimeException("bad nameserver configuration");
      }
    }
  }
  
  public InetAddress[] lookupAllHostAddr(String paramString)
    throws UnknownHostException
  {
    String[] arrayOfString = { "A", "AAAA", "CNAME" };
    DirContext localDirContext;
    try
    {
      localDirContext = getTemporaryContext();
    }
    catch (NamingException localNamingException)
    {
      throw new Error(localNamingException);
    }
    ArrayList localArrayList = null;
    Object localObject1 = null;
    if (paramString.indexOf('.') >= 0) {
      try
      {
        localArrayList = resolve(localDirContext, paramString, arrayOfString, 0);
      }
      catch (UnknownHostException localUnknownHostException1)
      {
        localObject1 = localUnknownHostException1;
      }
    }
    String str;
    if (localArrayList == null)
    {
      localObject2 = null;
      
      j = 0;
      Iterator localIterator;
      if (domainList != null)
      {
        localIterator = domainList.iterator();
      }
      else
      {
        localObject2 = ResolverConfiguration.open().searchlist();
        if (((List)localObject2).size() > 1) {
          j = 1;
        }
        localIterator = ((List)localObject2).iterator();
      }
      while (localIterator.hasNext())
      {
        str = (String)localIterator.next();
        int m = 0;
        for (;;)
        {
          if (((m = str.indexOf(".")) != -1) && (m < str.length() - 1)) {
            try
            {
              localArrayList = resolve(localDirContext, paramString + "." + str, arrayOfString, 0);
            }
            catch (UnknownHostException localUnknownHostException2)
            {
              localObject1 = localUnknownHostException2;
              if (j == 0) {
                str = str.substring(m + 1);
              }
            }
          }
        }
        if (localArrayList != null) {
          break;
        }
      }
    }
    if ((localArrayList == null) && (paramString.indexOf('.') < 0)) {
      localArrayList = resolve(localDirContext, paramString, arrayOfString, 0);
    }
    if (localArrayList == null)
    {
      assert (localObject1 != null);
      throw ((Throwable)localObject1);
    }
    assert (localArrayList.size() > 0);
    Object localObject2 = new InetAddress[localArrayList.size()];
    int i = 0;
    for (int j = 0; j < localArrayList.size(); j++)
    {
      str = (String)localArrayList.get(j);
      byte[] arrayOfByte = IPAddressUtil.textToNumericFormatV4(str);
      if (arrayOfByte == null) {
        arrayOfByte = IPAddressUtil.textToNumericFormatV6(str);
      }
      if (arrayOfByte != null) {
        localObject2[(i++)] = InetAddress.getByAddress(paramString, arrayOfByte);
      }
    }
    if (i == 0) {
      throw new UnknownHostException(paramString + ": no valid DNS records");
    }
    if (i < localArrayList.size())
    {
      InetAddress[] arrayOfInetAddress = new InetAddress[i];
      for (int k = 0; k < i; k++) {
        arrayOfInetAddress[k] = localObject2[k];
      }
      localObject2 = arrayOfInetAddress;
    }
    return (InetAddress[])localObject2;
  }
  
  public String getHostByAddr(byte[] paramArrayOfByte)
    throws UnknownHostException
  {
    String str1 = null;
    try
    {
      String str2 = "";
      String[] arrayOfString = { "PTR" };
      
      ArrayList localArrayList = null;
      DirContext localDirContext;
      try
      {
        localDirContext = getTemporaryContext();
      }
      catch (NamingException localNamingException)
      {
        throw new Error(localNamingException);
      }
      int i;
      if (paramArrayOfByte.length == 4)
      {
        for (i = paramArrayOfByte.length - 1; i >= 0; i--) {
          str2 = str2 + (paramArrayOfByte[i] & 0xFF) + ".";
        }
        str2 = str2 + "IN-ADDR.ARPA.";
        
        localArrayList = resolve(localDirContext, str2, arrayOfString, 0);
        str1 = (String)localArrayList.get(0);
      }
      else if (paramArrayOfByte.length == 16)
      {
        for (i = paramArrayOfByte.length - 1; i >= 0; i--) {
          str2 = str2 + Integer.toHexString(paramArrayOfByte[i] & 0xF) + "." + Integer.toHexString((paramArrayOfByte[i] & 0xF0) >> 4) + ".";
        }
        String str3 = str2 + "IP6.ARPA.";
        try
        {
          localArrayList = resolve(localDirContext, str3, arrayOfString, 0);
          str1 = (String)localArrayList.get(0);
        }
        catch (UnknownHostException localUnknownHostException)
        {
          str1 = null;
        }
        if (str1 == null)
        {
          str3 = str2 + "IP6.INT.";
          localArrayList = resolve(localDirContext, str3, arrayOfString, 0);
          str1 = (String)localArrayList.get(0);
        }
      }
    }
    catch (Exception localException)
    {
      throw new UnknownHostException(localException.getMessage());
    }
    if (str1 == null) {
      throw new UnknownHostException();
    }
    if (str1.endsWith(".")) {
      str1 = str1.substring(0, str1.length() - 1);
    }
    return str1;
  }
  
  private static void appendIfLiteralAddress(String paramString, StringBuffer paramStringBuffer)
  {
    if (IPAddressUtil.isIPv4LiteralAddress(paramString)) {
      paramStringBuffer.append("dns://" + paramString + " ");
    } else if (IPAddressUtil.isIPv6LiteralAddress(paramString)) {
      paramStringBuffer.append("dns://[" + paramString + "] ");
    }
  }
  
  private static String createProviderURL(List paramList)
  {
    Iterator localIterator = paramList.iterator();
    StringBuffer localStringBuffer = new StringBuffer();
    while (localIterator.hasNext()) {
      appendIfLiteralAddress((String)localIterator.next(), localStringBuffer);
    }
    return localStringBuffer.toString();
  }
  
  private static String createProviderURL(String paramString)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    StringTokenizer localStringTokenizer = new StringTokenizer(paramString, ",");
    while (localStringTokenizer.hasMoreTokens()) {
      appendIfLiteralAddress(localStringTokenizer.nextToken(), localStringBuffer);
    }
    return localStringBuffer.toString();
  }
}

/* Location:
 * Qualified Name:     sun.net.spi.nameservice.dns.DNSNameService
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package sun.net.spi.nameservice.dns;

import sun.net.spi.nameservice.NameService;
import sun.net.spi.nameservice.NameServiceDescriptor;

public final class DNSNameServiceDescriptor
  implements NameServiceDescriptor
{
  public NameService createNameService()
    throws Exception
  {
    return new DNSNameService();
  }
  
  public String getProviderName()
  {
    return "sun";
  }
  
  public String getType()
  {
    return "dns";
  }
}

/* Location:
 * Qualified Name:     sun.net.spi.nameservice.dns.DNSNameServiceDescriptor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd