/** * Looks up Records in the Zone. This follows CNAMEs and wildcards. * * @param name The name to look up * @param type The type to look up * @return A SetResponse object * @see SetResponse */ public SetResponse findRecords(Name name, short type) { SetResponse zr = null; Object o = findSets(name, type); if (o == null) { /* The name does not exist */ if (name.isWild()) return SetResponse.ofType(SetResponse.NXDOMAIN); int labels = name.labels() - origin.labels(); if (labels == 0) return SetResponse.ofType(SetResponse.NXDOMAIN); if (hasWild) { SetResponse sr; Name tname = name; do { sr = findRecords(tname.wild(1), type); if (!sr.isNXDOMAIN()) return sr; tname = new Name(tname, 1); } while (labels-- >= 1); return sr; } else return SetResponse.ofType(SetResponse.NXDOMAIN); } if (o instanceof TypeMap) { /* The name exists but the type does not. */ return SetResponse.ofType(SetResponse.NXRRSET); } Object[] objects; RRset rrset; if (o instanceof RRset) { objects = null; rrset = (RRset) o; } else { objects = (Object[]) o; rrset = (RRset) objects[0]; } if (name.equals(rrset.getName())) { if (type != Type.CNAME && type != Type.ANY && rrset.getType() == Type.CNAME) zr = new SetResponse(SetResponse.CNAME, rrset); else if (rrset.getType() == Type.NS && !name.equals(origin)) zr = new SetResponse(SetResponse.DELEGATION, rrset); else { zr = new SetResponse(SetResponse.SUCCESSFUL); zr.addRRset(rrset); if (objects != null) { for (int i = 1; i < objects.length; i++) zr.addRRset((RRset) objects[i]); } } } else { if (rrset.getType() == Type.CNAME) return SetResponse.ofType(SetResponse.NXDOMAIN); else if (rrset.getType() == Type.DNAME) { zr = new SetResponse(SetResponse.DNAME, rrset); } else if (rrset.getType() == Type.NS) { zr = new SetResponse(SetResponse.DELEGATION, rrset); } } return zr; }
public SIGBase( Name name, int type, int dclass, long ttl, int covered, int alg, long origttl, Date expire, Date timeSigned, int footprint, Name signer, byte[] signature) { super(name, type, dclass, ttl); Type.check(covered); checkU8("alg", alg); checkU8("labels", labels); TTL.check(origttl); checkU16("footprint", footprint); this.covered = covered; this.alg = alg; this.labels = name.labels(); this.origttl = origttl; this.expire = expire; this.timeSigned = timeSigned; this.footprint = footprint; if (!signer.isAbsolute()) throw new RelativeNameException(signer); this.signer = signer; this.signature = signature; }
/** Parses the output of winipcfg or ipconfig. */ private static void findWin(InputStream in) { BufferedReader br = new BufferedReader(new InputStreamReader(in)); try { List lserver = new ArrayList(); List lsearch = new ArrayList(); String line = null; boolean readingServers = false; boolean readingSearches = false; while ((line = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(line); if (!st.hasMoreTokens()) { readingServers = false; readingSearches = false; continue; } String s = st.nextToken(); if (line.indexOf(":") != -1) { readingServers = false; readingSearches = false; } if (line.indexOf("Host Name") != -1) { while (st.hasMoreTokens()) s = st.nextToken(); Name name; try { name = Name.fromString(s, null); } catch (TextParseException e) { continue; } if (name.labels() == 1) continue; addSearch(s, lsearch); } else if (line.indexOf("Primary Dns Suffix") != -1) { while (st.hasMoreTokens()) s = st.nextToken(); if (s.equals(":")) continue; addSearch(s, lsearch); readingSearches = true; } else if (readingSearches || line.indexOf("DNS Suffix") != -1) { while (st.hasMoreTokens()) s = st.nextToken(); if (s.equals(":")) continue; addSearch(s, lsearch); readingSearches = true; } else if (readingServers || line.indexOf("DNS Servers") != -1) { while (st.hasMoreTokens()) s = st.nextToken(); if (s.equals(":")) continue; addServer(s, lserver); readingServers = true; } } if (servers == null && lserver.size() > 0) servers = (String[]) lserver.toArray(new String[lserver.size()]); } catch (IOException e) { } finally { try { br.close(); } catch (IOException e) { } } return; }
/** * Creates an SIG Record from the given data * * @param covered The RRset type covered by this signature * @param alg The cryptographic algorithm of the key that generated the signature * @param origttl The original TTL of the RRset * @param expire The time at which the signature expires * @param timeSigned The time at which this signature was generated * @param footprint The footprint/key id of the signing key. * @param signer The owner of the signing key * @param signature Binary data representing the signature */ public SIGRecord( Name name, short dclass, int ttl, int covered, int alg, int origttl, Date expire, Date timeSigned, int footprint, Name signer, byte[] signature) { this(name, dclass, ttl); this.covered = (short) covered; this.alg = (byte) alg; this.labels = name.labels(); this.origttl = origttl; this.expire = expire; this.timeSigned = timeSigned; this.footprint = (short) footprint; this.signer = signer; this.signature = signature; }
private synchronized SetResponse lookup(Name name, int type) { int labels; int olabels; int tlabels; RRset rrset; Name tname; Object types; SetResponse sr; if (!name.subdomain(origin)) return SetResponse.ofType(SetResponse.NXDOMAIN); labels = name.labels(); olabels = origin.labels(); for (tlabels = olabels; tlabels <= labels; tlabels++) { boolean isOrigin = (tlabels == olabels); boolean isExact = (tlabels == labels); if (isOrigin) tname = origin; else if (isExact) tname = name; else tname = new Name(name, labels - tlabels); types = exactName(tname); if (types == null) continue; /* If this is a delegation, return that. */ if (!isOrigin) { RRset ns = oneRRset(types, Type.NS); if (ns != null) return new SetResponse(SetResponse.DELEGATION, ns); } /* If this is an ANY lookup, return everything. */ if (isExact && type == Type.ANY) { sr = new SetResponse(SetResponse.SUCCESSFUL); RRset[] sets = allRRsets(types); for (int i = 0; i < sets.length; i++) sr.addRRset(sets[i]); return sr; } /* * If this is the name, look for the actual type or a CNAME. * Otherwise, look for a DNAME. */ if (isExact) { rrset = oneRRset(types, type); if (rrset != null) { sr = new SetResponse(SetResponse.SUCCESSFUL); sr.addRRset(rrset); return sr; } rrset = oneRRset(types, Type.CNAME); if (rrset != null) return new SetResponse(SetResponse.CNAME, rrset); } else { rrset = oneRRset(types, Type.DNAME); if (rrset != null) return new SetResponse(SetResponse.DNAME, rrset); } /* We found the name, but not the type. */ if (isExact) return SetResponse.ofType(SetResponse.NXRRSET); } if (hasWild) { for (int i = 0; i < labels - olabels; i++) { tname = name.wild(i + 1); types = exactName(tname); if (types == null) continue; rrset = oneRRset(types, type); if (rrset != null) { sr = new SetResponse(SetResponse.SUCCESSFUL); sr.addRRset(rrset); return sr; } } } return SetResponse.ofType(SetResponse.NXDOMAIN); }