Search in sources :

Example 1 with Name

use of org.xbill.DNS.Name in project opennms by OpenNMS.

the class ReverseDnsProvisioningAdapter method doUpdate.

private void doUpdate(AdapterOperation op) {
    LOG.debug("doUpdate: operation: {}", op.getType().name());
    for (ReverseDnsRecord record : m_reverseDnsProvisioningAdapterService.get(op.getNodeId())) {
        LOG.debug("doUpdate: ReverseDnsRecord: hostname: {} zone: {} ip address: {}", record.getIp().getHostAddress(), record.getHostname(), record.getZone());
        try {
            Update update = new Update(Name.fromString(record.getZone()));
            Name ptrRecord = ReverseMap.fromAddress(record.getIp());
            update.replace(ptrRecord, Type.PTR, 3600, record.getHostname());
            m_resolver.send(update);
            m_reverseDnsProvisioningAdapterService.update(op.getNodeId(), record);
        } catch (Exception e) {
            LOG.error("updateNode: Error handling updated event.", e);
            sendAndThrow(op.getNodeId(), e);
        }
    }
}
Also used : Update(org.xbill.DNS.Update) Name(org.xbill.DNS.Name)

Example 2 with Name

use of org.xbill.DNS.Name in project nhin-d by DirectProject.

the class WSSmtpAgentConfigFunctional_Test method setUp.

/**
     * Initialize the servers- LDAP and HTTP.
     */
@SuppressWarnings("unchecked")
@Override
public void setUp() throws Exception {
    // check for Windows... it doens't like file://<drive>... turns it into FTP
    File file = new File("./src/test/resources/bundles/testBundle.p7b");
    if (file.getAbsolutePath().contains(":/"))
        filePrefix = "file:///";
    else
        filePrefix = "file:///";
    CertCacheFactory.getInstance().flushAll();
    /*
		 * Setup the LDAP Server
		 */
    MutablePartitionConfiguration pcfg = new MutablePartitionConfiguration();
    pcfg.setName("lookupTest");
    pcfg.setSuffix("cn=lookupTest");
    // Create some indices
    Set<String> indexedAttrs = new HashSet<String>();
    indexedAttrs.add("objectClass");
    indexedAttrs.add("cn");
    pcfg.setIndexedAttributes(indexedAttrs);
    // Create a first entry associated to the partition
    Attributes attrs = new BasicAttributes(true);
    // First, the objectClass attribute
    Attribute attr = new BasicAttribute("objectClass");
    attr.add("top");
    attrs.put(attr);
    // Associate this entry to the partition
    pcfg.setContextEntry(attrs);
    // As we can create more than one partition, we must store
    // each created partition in a Set before initialization
    Set<MutablePartitionConfiguration> pcfgs = new HashSet<MutablePartitionConfiguration>();
    pcfgs.add(pcfg);
    //
    //
    //
    // add the lookupTestPublic
    //
    //
    pcfg = new MutablePartitionConfiguration();
    pcfg.setName("lookupTestPublic");
    pcfg.setSuffix("cn=lookupTestPublic");
    // Create some indices
    indexedAttrs = new HashSet<String>();
    indexedAttrs.add("objectClass");
    indexedAttrs.add("cn");
    pcfg.setIndexedAttributes(indexedAttrs);
    // Create a first entry associated to the partition
    attrs = new BasicAttributes(true);
    // First, the objectClass attribute
    attr = new BasicAttribute("objectClass");
    attr.add("top");
    attrs.put(attr);
    // Associate this entry to the partition
    pcfg.setContextEntry(attrs);
    // As we can create more than one partition, we must store
    // each created partition in a Set before initialization
    pcfgs.add(pcfg);
    configuration.setContextPartitionConfigurations(pcfgs);
    this.configuration.setWorkingDirectory(new File("LDAP-TEST"));
    // add the private key schema
    ///
    Set<AbstractBootstrapSchema> schemas = configuration.getBootstrapSchemas();
    schemas.add(new PrivkeySchema());
    configuration.setBootstrapSchemas(schemas);
    super.setUp();
    // import the ldif file
    InputStream stream = TestUtils.class.getResourceAsStream("/ldifs/privCertsOnly.ldif");
    if (stream == null)
        throw new IOException("Failed to load ldif file");
    importLdif(stream);
    // setup the mock DNS SRV adapter
    mockLookup = mock(Lookup.class);
    LookupFactory.getFactory().addOverrideImplementation(mockLookup);
    SRVRecord srvRecord = new SRVRecord(new Name("_ldap._tcp.example.com."), DClass.IN, 3600, 0, 1, port, new Name("localhost."));
    when(mockLookup.run()).thenReturn(new Record[] { srvRecord });
    // create the web service and proxy
    ConfigServiceRunner.startConfigService();
    proxy = new ConfigurationServiceProxy(ConfigServiceRunner.getConfigServiceURL());
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attribute(javax.naming.directory.Attribute) BasicAttribute(javax.naming.directory.BasicAttribute) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) IOException(java.io.IOException) PrivkeySchema(org.nhindirect.ldap.PrivkeySchema) Name(org.xbill.DNS.Name) AbstractBootstrapSchema(org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema) MutablePartitionConfiguration(org.apache.directory.server.core.configuration.MutablePartitionConfiguration) Lookup(org.nhindirect.stagent.cert.impl.util.Lookup) SRVRecord(org.xbill.DNS.SRVRecord) File(java.io.File) ConfigurationServiceProxy(org.nhind.config.ConfigurationServiceProxy) HashSet(java.util.HashSet)

Example 3 with Name

use of org.xbill.DNS.Name in project nhin-d by DirectProject.

the class ConfigServiceDNSStore method get.

/**
	 * {@inheritDoc}
	 */
@SuppressWarnings("unchecked")
@Override
public Message get(Message request) throws DNSException {
    LOGGER.trace("get(Message) Entered");
    /* for testing time out cases
		try
		{
			Thread.sleep(1000000);
		}
		catch (Exception e)
		{

		}
	    */
    if (request == null)
        throw new DNSException(DNSError.newError(Rcode.FORMERR));
    Header header = request.getHeader();
    if (header.getFlag(Flags.QR) || header.getRcode() != Rcode.NOERROR)
        throw new DNSException(DNSError.newError(Rcode.FORMERR));
    if (header.getOpcode() != Opcode.QUERY)
        throw new DNSException(DNSError.newError(Rcode.NOTIMP));
    Record question = request.getQuestion();
    if (question == null || question.getDClass() != DClass.IN) {
        throw new DNSException(DNSError.newError(Rcode.NOTIMP));
    }
    Record queryRecord = request.getQuestion();
    Name name = queryRecord.getName();
    int type = queryRecord.getType();
    if (LOGGER.isDebugEnabled()) {
        StringBuilder builder = new StringBuilder("Recieved Query Request:");
        builder.append("\r\n\tName: " + name.toString());
        builder.append("\r\n\tType: " + type);
        builder.append("\r\n\tDClass: " + queryRecord.getDClass());
        LOGGER.debug(builder.toString());
    }
    Collection<Record> lookupRecords = null;
    switch(question.getType()) {
        case Type.A:
        case Type.MX:
        case Type.SOA:
        case Type.SRV:
        case Type.NS:
        case Type.CNAME:
            {
                try {
                    final RRset set = processGenericRecordRequest(name.toString(), type);
                    if (set != null) {
                        lookupRecords = new ArrayList<Record>();
                        Iterator<Record> iter = set.rrs();
                        while (iter.hasNext()) lookupRecords.add(iter.next());
                    }
                } catch (Exception e) {
                    throw new DNSException(DNSError.newError(Rcode.SERVFAIL), "DNS service proxy call failed: " + e.getMessage(), e);
                }
                break;
            }
        case Type.CERT:
            {
                final RRset set = processCERTRecordRequest(name.toString());
                if (set != null) {
                    lookupRecords = new ArrayList<Record>();
                    Iterator<Record> iter = set.rrs();
                    while (iter.hasNext()) lookupRecords.add(iter.next());
                }
                break;
            }
        case Type.ANY:
            {
                Collection<Record> genRecs = processGenericANYRecordRequest(name.toString());
                RRset certRecs = processCERTRecordRequest(name.toString());
                if (genRecs != null || certRecs != null) {
                    lookupRecords = new ArrayList<Record>();
                    if (genRecs != null)
                        lookupRecords.addAll(genRecs);
                    if (certRecs != null) {
                        Iterator<Record> iter = certRecs.rrs();
                        while (iter.hasNext()) lookupRecords.add(iter.next());
                    }
                }
                break;
            }
        default:
            {
                LOGGER.debug("Query Type " + type + " not implemented");
                throw new DNSException(DNSError.newError(Rcode.NOTIMP), "Query Type " + type + " not implemented");
            }
    }
    if (lookupRecords == null || lookupRecords.size() == 0) {
        LOGGER.debug("No records found.");
        return null;
    }
    final Message response = new Message(request.getHeader().getID());
    response.getHeader().setFlag(Flags.QR);
    if (request.getHeader().getFlag(Flags.RD))
        response.getHeader().setFlag(Flags.RD);
    response.addRecord(queryRecord, Section.QUESTION);
    final Iterator<Record> iter = lookupRecords.iterator();
    while (iter.hasNext()) response.addRecord(iter.next(), Section.ANSWER);
    // we are authoritative only
    response.getHeader().setFlag(Flags.AA);
    // look for an SOA record
    final Record soaRecord = checkForSoaRecord(name.toString());
    if (soaRecord != null)
        response.addRecord(soaRecord, Section.AUTHORITY);
    LOGGER.trace("get(Message) Exit");
    return response;
}
Also used : Message(org.xbill.DNS.Message) RRset(org.xbill.DNS.RRset) ArrayList(java.util.ArrayList) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException) Name(org.xbill.DNS.Name) Header(org.xbill.DNS.Header) Iterator(java.util.Iterator) Collection(java.util.Collection) CERTRecord(org.xbill.DNS.CERTRecord) Record(org.xbill.DNS.Record) DnsRecord(org.nhind.config.DnsRecord)

Example 4 with Name

use of org.xbill.DNS.Name in project nhin-d by DirectProject.

the class DNSConnectionTest method performLookup.

private static void performLookup() throws Exception {
    // turn on debug settings for the DNS client
    Options.set("verbose", "true");
    Cache ch = Lookup.getDefaultCache(DClass.IN);
    ch.clearCache();
    if (servers == null || servers.length == 0)
        servers = ResolverConfig.getCurrentConfig().servers();
    System.out.println("\r\nConfigure DNS resolvers:");
    for (String server : servers) {
        System.out.println("\t" + server);
    }
    System.out.println("\r\nLookup up record " + lookupRec);
    Lookup lu = new Lookup(new Name(lookupRec), recType);
    ExtendedResolver resolver = new ExtendedResolver(servers);
    resolver.setTCP(useTCP);
    lu.setResolver(resolver);
    Record[] retRecords = lu.run();
    if (retRecords != null && retRecords.length > 0)
        System.out.println(retRecords.length + " records found.");
    else
        System.out.println("No records found.");
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) Lookup(org.xbill.DNS.Lookup) Record(org.xbill.DNS.Record) Cache(org.xbill.DNS.Cache) Name(org.xbill.DNS.Name)

Example 5 with Name

use of org.xbill.DNS.Name in project GNS by MobilityFirst.

the class NameResolution method getARecordsFromAField.

/**
   * retrieve all A records from A field of a JSON object
   * 
   * @return
   */
private static JSONArray getARecordsFromAField(JSONObject fieldResponseJson, String nameToResolve) {
    JSONArray aList = new JSONArray();
    /**
       * Format of A record in GNS:
       * {
       * 	"A":
       * 		{
       * 			"record": String[ip1, ip2, ...],
       * 			"ttl": int
       * 		}
       * }
       */
    if (fieldResponseJson.has("A")) {
        JSONArray records = null;
        int ttl = 60;
        try {
            JSONObject recordObj = fieldResponseJson.getJSONObject("A");
            records = recordObj.getJSONArray(ManagedDNSServiceProxy.RECORD_FIELD);
            ttl = recordObj.getInt(ManagedDNSServiceProxy.TTL_FIELD);
        } catch (JSONException e) {
            // something is wrong with the JSON object, return null
            e.printStackTrace();
            return null;
        }
        // The records may contain multiple ip addresses
        for (int i = 0; i < records.length(); i++) {
            try {
                String ip = records.getString(i);
                ARecord gnsARecord = new ARecord(new Name(nameToResolve), DClass.IN, ttl, InetAddress.getByName(ip));
                aList.put(gnsARecord);
            } catch (JSONException | TextParseException | UnknownHostException e) {
                // do nothing, just trash this record
                e.printStackTrace();
            }
        }
    } else {
        // there is no A record in the original GNS record, so return null
        return null;
    }
    return aList;
}
Also used : ARecord(org.xbill.DNS.ARecord) JSONObject(org.json.JSONObject) UnknownHostException(java.net.UnknownHostException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Name(org.xbill.DNS.Name) TextParseException(org.xbill.DNS.TextParseException)

Aggregations

Name (org.xbill.DNS.Name)50 Record (org.xbill.DNS.Record)27 SRVRecord (org.xbill.DNS.SRVRecord)18 Message (org.xbill.DNS.Message)14 SimpleResolver (org.xbill.DNS.SimpleResolver)9 Lookup (org.xbill.DNS.Lookup)8 UnknownHostException (java.net.UnknownHostException)7 ARecord (org.xbill.DNS.ARecord)7 ExtendedResolver (org.xbill.DNS.ExtendedResolver)7 NSRecord (org.xbill.DNS.NSRecord)7 TXTRecord (org.xbill.DNS.TXTRecord)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)6 CNAMERecord (org.xbill.DNS.CNAMERecord)6 TextParseException (org.xbill.DNS.TextParseException)6 TSIG (org.xbill.DNS.TSIG)5 Zone (org.xbill.DNS.Zone)5 ZoneTransferIn (org.xbill.DNS.ZoneTransferIn)5 List (java.util.List)4