Skip to content

Commit

Permalink
Merge pull request #6298 from OpenNMS/dependabot/maven/foundation-202…
Browse files Browse the repository at this point in the history
…3/org.apache.servicemix.bundles-org.apache.servicemix.bundles.dnsjava-3.5.2_1

build(deps): bump org.apache.servicemix.bundles.dnsjava from 2.1.9_1 to 3.5.2_1
  • Loading branch information
Benjamin Reed authored Jul 6, 2023
2 parents f8f0165 + ad925b6 commit 5c9887e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2011-2012 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
* Copyright (C) 2011-2023 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2023 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
Expand Down Expand Up @@ -478,17 +478,17 @@ public RRset findExactMatch(final Name name, final int type, final int dclass, f
if (zone != null) {
return zone.findExactMatch(name, type);
} else {
final RRset[] rrsets;
final List<RRset> rrsets;
final Cache cache = getCache(dclass);
if (glue) {
rrsets = cache.findAnyRecords(name, type);
} else {
rrsets = cache.findRecords(name, type);
}
if (rrsets == null) {
if (rrsets == null || rrsets.isEmpty()) {
return null;
} else {
return rrsets[0]; /* not quite right */
return rrsets.get(0); /* not quite right */
}
}
}
Expand All @@ -498,10 +498,7 @@ void addRRset(final Name name, final Message response, final RRset rrset, final
if (response.findRRset(name, rrset.getType(), s)) return;
}
if ((flags & FLAG_SIGONLY) == 0) {
@SuppressWarnings("unchecked")
final Iterator<Record> it = rrset.rrs();
while (it.hasNext()) {
final Record r = it.next();
for (final Record r : rrset.rrs()) {
if (r.getName().isWild() && !name.isWild()) {
response.addRecord(r.withName(name), section);
} else {
Expand All @@ -510,10 +507,7 @@ void addRRset(final Name name, final Message response, final RRset rrset, final
}
}
if ((flags & (FLAG_SIGONLY | FLAG_DNSSECOK)) != 0) {
@SuppressWarnings("unchecked")
final Iterator<Record> it = rrset.sigs();
while (it.hasNext()) {
final Record r = it.next();
for (final Record r : rrset.sigs()) {
if (r.getName().isWild() && !name.isWild()) {
response.addRecord(r.withName(name), section);
} else {
Expand All @@ -536,10 +530,7 @@ private final void addCacheNS(final Message response, final Cache cache, final N
final SetResponse sr = cache.lookupRecords(name, Type.NS, Credibility.HINT);
if (!sr.isDelegation()) return;
final RRset nsRecords = sr.getNS();
@SuppressWarnings("unchecked")
final Iterator<Record> it = nsRecords.rrs();
while (it.hasNext()) {
final Record r = it.next();
for (final Record r : nsRecords.rrs()) {
response.addRecord(r, Section.AUTHORITY);
}
}
Expand All @@ -552,8 +543,7 @@ private void addGlue(final Message response, final Name name, final int flags) {

private void addAdditional2(final Message response, final int section, final int flags) {
final Record[] records = response.getSectionArray(section);
for (int i = 0; i < records.length; i++) {
final Record r = records[i];
for (final Record r : records) {
final Name glueName = r.getAdditionalName();
if (glueName != null) addGlue(response, glueName, flags);
}
Expand Down Expand Up @@ -622,9 +612,10 @@ byte addAnswer(final Message response, final Name name, int type, int dclass, in
response.getHeader().setFlag(Flags.AA);
rcode = addAnswer(response, newname, type, dclass, iterations + 1, flags);
} else if (sr.isSuccessful()) {
final RRset[] rrsets = sr.answers();
for (int i = 0; i < rrsets.length; i++)
addRRset(name, response, rrsets[i], Section.ANSWER, flags);
final List<RRset> rrsets = sr.answers();
for (final RRset rrset : rrsets) {
addRRset(name, response, rrset, Section.ANSWER, flags);
}
if (zone != null) {
addNS(response, zone, flags);
if (iterations == 0)
Expand All @@ -638,9 +629,9 @@ byte addAnswer(final Message response, final Name name, int type, int dclass, in
byte[] doAXFR(final Name name, final Message query, final TSIG tsig, TSIGRecord qtsig, final Socket s) {
final Zone zone = m_znames.get(name);
boolean first = true;
if (zone == null)
if (zone == null) {
return errorMessage(query, Rcode.REFUSED);
@SuppressWarnings("unchecked")
}
final Iterator<RRset> it = zone.AXFR();
try {
final DataOutputStream dataOut = new DataOutputStream(s.getOutputStream());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2008-2014 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
* Copyright (C) 2008-2023 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2023 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
Expand Down Expand Up @@ -235,7 +235,7 @@ private void doUpdate(AdapterOperation op) {
update.delete(Name.fromString(oldRecord.getHostname()), Type.A);
}
update.replace(Name.fromString(record.getHostname()), Type.A, 3600, record.getIp().getHostAddress());
m_resolver.send(update);
m_resolver.sendAsync(update);

m_nodeDnsRecordMap.put(Integer.valueOf(op.getNodeId()), record);
} catch (Throwable e) {
Expand All @@ -251,7 +251,7 @@ private void doDelete(AdapterOperation op) {
if (record != null) {
Update update = new Update(Name.fromString(record.getZone()));
update.delete(Name.fromString(record.getHostname()), Type.A);
m_resolver.send(update);
m_resolver.sendAsync(update);

m_nodeDnsRecordMap.remove(Integer.valueOf(op.getNodeId()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2009-2017 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2017 The OpenNMS Group, Inc.
* Copyright (C) 2009-2023 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2023 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
Expand All @@ -29,8 +29,11 @@
package org.opennms.netmgt.provision.service.dns;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -52,6 +55,8 @@
import org.xbill.DNS.Type;
import org.xbill.DNS.ZoneTransferException;
import org.xbill.DNS.ZoneTransferIn;
import org.xbill.DNS.ZoneTransferIn.Delta;
import org.xbill.DNS.ZoneTransferIn.ZoneTransferHandler;

import com.google.common.base.Strings;

Expand All @@ -77,26 +82,54 @@ public RequisitionRequest getRequest(Map<String, String> parameters) {
@Override
public Requisition getRequisitionFor(DnsRequisitionRequest request) {
ZoneTransferIn xfer = null;
List<Record> records = null;
final Set<Record> records = new LinkedHashSet<>();

final var handler = new ZoneTransferHandler() {
@Override
public void startAXFR() throws ZoneTransferException {
}

@Override
public void startIXFR() throws ZoneTransferException {
}

@Override
public void startIXFRDeletes(Record soa) throws ZoneTransferException {
}

@Override
public void startIXFRAdds(Record soa) throws ZoneTransferException {
}

@Override
public void handleRecord(final Record r) throws ZoneTransferException {
records.add(r);
}
};

LOG.debug("connecting to host {}:{}", request.getHost(), request.getPort());
try {
/*
* TODO: if we're doing IXFR, we get "delta" responses that includes deletes,
* we should support removing those nodes from the req.
*/
try {
xfer = ZoneTransferIn.newIXFR(new Name(request.getZone()), request.getSerial(),
request.getFallback(), request.getHost(), request.getPort(), null);
records = getRecords(xfer);
xfer.run(handler);
} catch (ZoneTransferException e) {
// Fallback to AXFR
String message = "IXFR not supported trying AXFR: " + e;
LOG.warn(message, e);
xfer = ZoneTransferIn.newAXFR(new Name(request.getZone()), request.getHost(), null);
records = getRecords(xfer);
xfer.run(handler);
}
} catch (IOException | ZoneTransferException e) {
throw new RuntimeException(e);
}

if (records.size() > 0) {
LOG.debug("records={}", records);
if (!records.isEmpty()) {
// for now, set the foreign source to the specified dns zone
final Requisition r = new Requisition(request.getForeignSource());
for (Record rec : records) {
Expand All @@ -109,11 +142,6 @@ public Requisition getRequisitionFor(DnsRequisitionRequest request) {
return null;
}

@SuppressWarnings("unchecked")
private static List<Record> getRecords(ZoneTransferIn xfer) throws IOException, ZoneTransferException {
return (List<Record>) xfer.run();
}

/**
* Determines if the record is an A record and if the canonical name matches
* the expression supplied in the URL, if one was supplied.
Expand All @@ -125,8 +153,9 @@ private boolean matchingRecord(DnsRequisitionRequest request, Record rec) {
LOG.info("matchingRecord: checking rec: {} to see if it should be imported...", rec);

boolean matches = false;
if ("A".equals(Type.string(rec.getType())) || "AAAA".equals(Type.string(rec.getType()))) {
LOG.debug("matchingRecord: record is an {} record, continuing...", Type.string(rec.getType()));
final var stringType = Type.string(rec.getType());
if ("A".equals(stringType) || "AAAA".equals(stringType)) {
LOG.debug("matchingRecord: record is an {} record, continuing...", stringType);

final String expression = request.getExpression();
if (expression != null) {
Expand All @@ -140,17 +169,18 @@ private boolean matchingRecord(DnsRequisitionRequest request, Record rec) {
matches = true;
} else {
// include the IP address and try again
LOG.debug("matchingRecord: attempting to match record: [{} {}] with expression: [{}]",
rec.getName(), rec.rdataToString(), expression);
if (LOG.isDebugEnabled()) {
LOG.debug("matchingRecord: attempting to match record: [{} {}] with expression: [{}]",
rec.getName(), rec.rdataToString(), expression);
}
m = p.matcher(rec.getName().toString() + " " + rec.rdataToString());
if (m.matches()) {
matches = true;
}
}
LOG.debug("matchingRecord: record matches expression: {}", matches);
} else {
LOG.debug("matchingRecord: no expression for this zone, returning valid match for this {} record...",
Type.string(rec.getType()));
LOG.debug("matchingRecord: no expression for this zone, returning valid match for this {} record...", stringType);
matches = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@
<cxfVersion>3.5.5</cxfVersion>
<cxfXjcVersion>3.3.2</cxfXjcVersion>
<dhcp4javaVersion>1.1.0</dhcp4javaVersion>
<dnsjavaVersion>2.1.9_1</dnsjavaVersion>
<dnsjavaVersion>3.5.2_1</dnsjavaVersion>
<dom4jVersion>2.1.4</dom4jVersion>
<dropwizardMetricsVersion>3.1.2</dropwizardMetricsVersion>
<ecjVersion>4.4.2</ecjVersion>
Expand Down

0 comments on commit 5c9887e

Please sign in to comment.