Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
  /** 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;
  }
Exemplo n.º 3
0
 @Test
 public void convertToSequence() {
   Folder c = db.createFolder("/top");
   c.documents().build(Name.create(db, "one")).elem("test").end("test").commit();
   XMLDocument doc = c.documents().build(Name.create(db, "two")).elem("test").end("test").commit();
   assertEquals(2, c.query().all("/test").size());
   assertEquals(1, c.query().all("$_1/test", new Object[] {doc}).size());
 }
Exemplo n.º 4
0
 @Test
 public void query4() {
   Folder c1 = db.createFolder("/c1");
   XMLDocument doc =
       c1.documents().build(Name.create(db, "original")).elem("test").end("test").commit();
   c1.documents().build(Name.create(db, "another")).elem("test").end("test").commit();
   doc.query().single("/test");
   assertEquals(2, c1.query().all("/test").size());
 }
Exemplo n.º 5
0
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   host.toWire(out, c, canonical);
   admin.toWire(out, c, canonical);
   out.writeU32(serial);
   out.writeU32(refresh);
   out.writeU32(retry);
   out.writeU32(expire);
   out.writeU32(minimum);
 }
Exemplo n.º 6
0
  private final void maybeAddRecord(Record record) throws IOException {
    int rtype = record.getType();
    Name name = record.getName();

    if (rtype == Type.SOA && !name.equals(origin)) {
      throw new IOException("SOA owner " + name + " does not match zone origin " + origin);
    }
    if (name.subdomain(origin)) addRecord(record);
  }
Exemplo n.º 7
0
 /**
  * Gets the next token from a tokenizer and converts it to a name.
  *
  * @param origin The origin to append to relative names.
  * @return The next token in the stream, as a name.
  * @throws TextParseException The input was invalid or not a valid name.
  * @throws IOException An I/O error occurred.
  * @throws RelativeNameException The parsed name was relative, even with the origin.
  * @see Name
  */
 public Name getName(Name origin) throws IOException {
   try {
     Name name = Name.fromString(getIdentifier(), origin);
     if (!name.isAbsolute()) throw new RelativeNameException(name);
     return name;
   } catch (TextParseException e) {
     throw exception(e.getMessage());
   }
 }
Exemplo n.º 8
0
 @Test
 public void copy1() {
   Folder c1 = db.createFolder("/c1"), c2 = db.createFolder("/c2");
   XMLDocument original =
       c1.documents().build(Name.create(db, "original")).elem("test").end("test").commit();
   XMLDocument copy = original.copy(c2, Name.keepCreate(db));
   assertEquals(1, c1.documents().size());
   c1.query().single("/test");
   assertEquals(1, c2.documents().size());
   c2.query().single("/test");
   copy.query().single("/test");
 }
Exemplo n.º 9
0
 @Test
 public void move1() {
   Folder c1 = db.createFolder("/c1"), c2 = db.createFolder("/c2");
   XMLDocument doc =
       c1.documents().build(Name.create(db, "original")).elem("test").end("test").commit();
   doc.move(c2, Name.keepCreate(db));
   assertEquals(0, c1.documents().size());
   assertFalse(c1.query().exists("/test"));
   assertEquals(1, c2.documents().size());
   c2.query().single("/test");
   doc.query().single("/test");
   assertEquals("/c2/original", doc.path());
 }
Exemplo n.º 10
0
 @Test
 public void query2() {
   Folder c1 = db.createFolder("/c1");
   c1.documents().build(Name.create(db, "original")).elem("test").end("test").commit();
   XMLDocument doc = c1.documents().get("original").xml();
   doc.query().single("/test");
 }
Exemplo n.º 11
0
 private synchronized void addRRset(Name name, RRset rrset) {
   if (!hasWild && name.isWild()) hasWild = true;
   Object types = data.get(name);
   if (types == null) {
     data.put(name, rrset);
     return;
   }
   int rtype = rrset.getType();
   if (types instanceof List) {
     List list = (List) types;
     for (int i = 0; i < list.size(); i++) {
       RRset set = (RRset) list.get(i);
       if (set.getType() == rtype) {
         list.set(i, rrset);
         return;
       }
     }
     list.add(rrset);
   } else {
     RRset set = (RRset) types;
     if (set.getType() == rtype) data.put(name, rrset);
     else {
       LinkedList list = new LinkedList();
       list.add(set);
       list.add(rrset);
       data.put(name, list);
     }
   }
 }
Exemplo n.º 12
0
 @Test
 public void nameAndPathFromLoad() {
   XMLDocument doc =
       db.createFolder("/top").documents().load(Name.create(db, "foo"), Source.xml("<root/>"));
   assertEquals("foo", doc.name());
   assertEquals("/top/foo", doc.path());
 }
Exemplo n.º 13
0
  /**
   * Builds a new Record from its textual representation
   *
   * @param name The owner name of the record.
   * @param type The record's type.
   * @param dclass The record's class.
   * @param ttl The record's time to live.
   * @param st A tokenizer containing the textual representation of the rdata.
   * @param origin The default origin to be appended to relative domain names.
   * @return The new record
   * @throws IOException The text format was invalid.
   */
  public static Record fromString(
      Name name, int type, int dclass, long ttl, Tokenizer st, Name origin) throws IOException {
    Record rec;

    if (!name.isAbsolute()) throw new RelativeNameException(name);
    Type.check(type);
    DClass.check(dclass);
    TTL.check(ttl);

    Tokenizer.Token t = st.get();
    if (t.type == Tokenizer.IDENTIFIER && t.value.equals("\\#")) {
      int length = st.getUInt16();
      byte[] data = st.getHex();
      if (data == null) {
        data = new byte[0];
      }
      if (length != data.length)
        throw st.exception("invalid unknown RR encoding: " + "length mismatch");
      DNSInput in = new DNSInput(data);
      return newRecord(name, type, dclass, ttl, length, in);
    }
    st.unget();
    rec = getEmptyRecord(name, type, dclass, ttl, true);
    rec.rdataFromString(st, origin);
    t = st.get();
    if (t.type != Tokenizer.EOL && t.type != Tokenizer.EOF) {
      throw st.exception("unexpected tokens at end of record");
    }
    return rec;
  }
Exemplo n.º 14
0
 /**
  * Constructs and returns the next record in the expansion.
  *
  * @throws IOException The name or rdata was invalid after substitutions were performed.
  */
 public Record nextRecord() throws IOException {
   if (current > end) return null;
   String namestr = substitute(namePattern, current);
   Name name = Name.fromString(namestr, origin);
   String rdata = substitute(rdataPattern, current);
   current += step;
   return Record.fromString(name, type, dclass, ttl, rdata, origin);
 }
Exemplo n.º 15
0
 @Test
 public void delete1() {
   Folder c1 = db.createFolder("/c1");
   XMLDocument doc =
       c1.documents().build(Name.create(db, "original")).elem("test").end("test").commit();
   doc.delete();
   assertEquals(0, c1.documents().size());
 }
Exemplo n.º 16
0
 void rrToWire(DNSOutput out, Compression c, boolean canonical) {
   out.writeU16(order);
   out.writeU16(preference);
   out.writeCountedString(flags);
   out.writeCountedString(service);
   out.writeCountedString(regexp);
   replacement.toWire(out, null, canonical);
 }
Exemplo n.º 17
0
 /**
  * Determines if an RRset with the given name and type is already present in the given section.
  *
  * @see RRset
  * @see Section
  */
 public boolean findRRset(Name name, int type, int section) {
   if (sections[section] == null) return false;
   for (int i = 0; i < sections[section].size(); i++) {
     Record r = (Record) sections[section].get(i);
     if (r.getType() == type && name.equals(r.getName())) return true;
   }
   return false;
 }
Exemplo n.º 18
0
  private final void maybeAddRecord(Record record, Cache cache, Object source) throws IOException {
    int type = record.getType();
    Name name = record.getName();

    if (type == Type.SOA) {
      if (!name.equals(origin))
        throw new IOException("SOA owner " + name + " does not match zone origin " + origin);
      else {
        setOrigin(origin);
        dclass = record.getDClass();
      }
    }
    if (origin == null && type != Type.SOA)
      throw new IOException("non-SOA record seen at " + name + " with no origin set");
    if (name.subdomain(origin)) addRecord(record);
    else if (cache != null) cache.addRecord(record, Credibility.GLUE, source);
  }
Exemplo n.º 19
0
  protected boolean skipName(Name definedName) {
    String namename = definedName.getNameName();
    if (namename == null) {
      return true;
    }
    // ignore defined name of functions, they are macro functions that we don't support
    if (definedName.isFunctionName()) {
      return true;
    }

    if (definedName.getRefersToFormula()
        == null) { // ignore defined name with null formula, don't know when will have this case
      return true;
    }

    return false;
  }
Exemplo n.º 20
0
 /**
  * Determines if two Records are identical. This compares the name, type, class, and rdata (with
  * names canonicalized). The TTLs are not compared.
  *
  * @param arg The record to compare to
  * @return true if the records are equal, false otherwise.
  */
 public boolean equals(Object arg) {
   if (arg == null || !(arg instanceof Record)) return false;
   Record r = (Record) arg;
   if (type != r.type || dclass != r.dclass || !name.equals(r.name)) return false;
   byte[] array1 = rdataToWireCanonical();
   byte[] array2 = r.rdataToWireCanonical();
   return Arrays.equals(array1, array2);
 }
Exemplo n.º 21
0
  /**
   * Creates a new empty record, with the given parameters.
   *
   * @param name The owner name of the record.
   * @param type The record's type.
   * @param dclass The record's class.
   * @param ttl The record's time to live.
   * @return An object of a subclass of Record
   */
  public static Record newRecord(Name name, int type, int dclass, long ttl) {
    if (!name.isAbsolute()) throw new RelativeNameException(name);
    Type.check(type);
    DClass.check(dclass);
    TTL.check(ttl);

    return getEmptyRecord(name, type, dclass, ttl, false);
  }
Exemplo n.º 22
0
  /**
   * 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;
  }
Exemplo n.º 23
0
 @Test
 public void writeToOutputStream() throws IOException {
   XMLDocument doc =
       db.createFolder("/top").documents().load(Name.create(db, "foo"), Source.xml("<root/>"));
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   doc.write(out);
   out.close();
   assertEquals("<root/>", out.toString());
 }
Exemplo n.º 24
0
 /** Returns the contents of the Zone in master file format. */
 public String toMasterFile() {
   Iterator zentries = data.entrySet().iterator();
   StringBuffer sb = new StringBuffer();
   nodeToString(sb, originNode);
   while (zentries.hasNext()) {
     Map.Entry entry = (Map.Entry) zentries.next();
     if (!origin.equals(entry.getKey())) nodeToString(sb, entry.getValue());
   }
   return sb.toString();
 }
Exemplo n.º 25
0
 Record(Name name, int type, int dclass, long ttl) {
   if (!name.isAbsolute()) throw new RelativeNameException(name);
   Type.check(type);
   DClass.check(dclass);
   TTL.check(ttl);
   this.name = name;
   this.type = type;
   this.dclass = dclass;
   this.ttl = ttl;
 }
Exemplo n.º 26
0
 /**
  * Constructs and returns all records in the expansion.
  *
  * @throws IOException The name or rdata of a record was invalid after substitutions were
  *     performed.
  */
 public Record[] expand() throws IOException {
   List list = new ArrayList();
   for (long i = start; i < end; i += step) {
     String namestr = substitute(namePattern, current);
     Name name = Name.fromString(namestr, origin);
     String rdata = substitute(rdataPattern, current);
     list.add(Record.fromString(name, type, dclass, ttl, rdata, origin));
   }
   return (Record[]) list.toArray(new Record[list.size()]);
 }
Exemplo n.º 27
0
 private static void addSearch(String search, List list) {
   Name name;
   if (Options.check("verbose")) System.out.println("adding search " + search);
   try {
     name = Name.fromString(search, Name.root);
   } catch (TextParseException e) {
     return;
   }
   if (list.contains(name)) return;
   list.add(name);
 }
Exemplo n.º 28
0
 @Test
 public void contentsAsStringFromCreate() {
   XMLDocument doc =
       db.createFolder("/top")
           .documents()
           .build(Name.create(db, "foo"))
           .elem("root")
           .end("root")
           .commit();
   assertEquals("<root/>", doc.contentsAsString());
 }
Exemplo n.º 29
0
 @Test
 public void lengthFromCreate() {
   XMLDocument doc =
       db.createFolder("/top")
           .documents()
           .build(Name.create(db, "foo"))
           .elem("root")
           .end("root")
           .commit();
   assertThat(doc.length(), Matchers.greaterThan(0L));
 }
Exemplo n.º 30
0
 @Test
 public void delete2() {
   Folder c1 = db.createFolder("/c1");
   XMLDocument doc1 =
       c1.documents()
           .build(Name.create(db, "doc1"))
           .elem("test")
           .attr("xml:id", "a")
           .end("test")
           .commit();
   XMLDocument doc2 =
       c1.documents()
           .build(Name.create(db, "doc2"))
           .elem("test2")
           .attr("xml:id", "b")
           .end("test2")
           .commit();
   doc1.delete();
   doc2.delete();
   assertEquals(0, c1.documents().size());
 }