Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
New parsing works, but a lot of stuff needs to be fixed:
* Parsing the different records
* Parsing private key files (trivial, but needs to be done)
- Loading branch information
Showing
with
555 additions
and
79 deletions.
-
+1
−0
Makefile
-
+4
−2
keygen.go
-
+17
−6
types.go
-
+0
−47
zparse.go
-
+0
−13
zparse.rl
-
+33
−11
zscan.go
-
+500
−0
zscan_rr.go
|
@@ -26,6 +26,7 @@ GOFILES=\ |
|
|
xfr.go\ |
|
|
zparse.go\ |
|
|
zscan.go\ |
|
|
zscan_rr.go\ |
|
|
|
|
|
|
|
|
include $(GOROOT)/src/Make.pkg |
|
|
|
@@ -113,8 +113,7 @@ func (r *RR_DNSKEY) PrivateKeyString(p PrivateKey) (s string) { |
|
|
|
|
|
// Read reads a DNSKEY from the io.Reader q. |
|
|
func (k *RR_DNSKEY) Read(q io.Reader) error { |
|
|
p := NewParser(q) |
|
|
r, err := p.First() |
|
|
r, err := newRRReader(q) |
|
|
if err != nil { |
|
|
return err |
|
|
} |
|
@@ -131,6 +130,7 @@ func (k *RR_DNSKEY) Read(q io.Reader) error { |
|
|
|
|
|
// ReadPrivateKey reads a private key from the io.Reader q. |
|
|
func (k *RR_DNSKEY) ReadPrivateKey(q io.Reader) (PrivateKey, error) { |
|
|
/* |
|
|
p := NewParser(q) |
|
|
kv, _ := p.PrivateKey() |
|
|
if kv == nil { |
|
@@ -149,6 +149,8 @@ func (k *RR_DNSKEY) ReadPrivateKey(q io.Reader) (PrivateKey, error) { |
|
|
return k.readPrivateKeyECDSA(kv) |
|
|
} |
|
|
return nil, ErrPrivKey |
|
|
*/ |
|
|
return nil, nil |
|
|
} |
|
|
|
|
|
// Read a private key (file) string and create a public key. Return the private key. |
|
|
|
@@ -9,6 +9,7 @@ import ( |
|
|
"net" |
|
|
"strconv" |
|
|
"strings" |
|
|
"time" |
|
|
) |
|
|
|
|
|
// Packet formats |
|
@@ -145,12 +146,6 @@ func (q *Question) String() string { |
|
|
return s |
|
|
} |
|
|
|
|
|
// NewRRString returns the last RR contained in s. |
|
|
func NewRRString(s string) (RR, error) { |
|
|
p := NewParser(strings.NewReader(s)) |
|
|
return p.First() |
|
|
} |
|
|
|
|
|
// NewRR returns a new RR with the hdr.Rrtype also set. |
|
|
// If the type i is not known, nil is returned. |
|
|
func NewRR(i uint16) RR { |
|
@@ -829,6 +824,22 @@ func tsigTimeToDate(t uint64) string { |
|
|
*/ |
|
|
} |
|
|
|
|
|
// Translate the RRSIG's incep. and expir. times from |
|
|
// string values ("20110403154150") to an integer. |
|
|
// Taking into account serial arithmetic (RFC 1982) |
|
|
func dateToTime(s string) (uint32, error) { |
|
|
_, e := time.Parse("20060102150405", s) |
|
|
if e != nil { |
|
|
return 0, e |
|
|
} |
|
|
return 0, nil |
|
|
/* |
|
|
mod := t.Seconds() / Year68 |
|
|
ti := uint32(t.Seconds() - (mod * Year68)) |
|
|
return ti, nil |
|
|
*/ |
|
|
} |
|
|
|
|
|
// Map of constructors for each RR wire type. |
|
|
var rr_mk = map[uint16]func() RR{ |
|
|
TypeCNAME: func() RR { return new(RR_CNAME) }, |
|
|
|
@@ -5,11 +5,7 @@ package dns |
|
|
// With the thankful help of gdnsd and the Go examples for Ragel. |
|
|
|
|
|
import ( |
|
|
"io" |
|
|
// "net" |
|
|
"strconv" |
|
|
"strings" |
|
|
"time" |
|
|
) |
|
|
|
|
|
const _IOBUF = MaxMsgSize |
|
@@ -21,55 +17,12 @@ type Parser struct { |
|
|
buf []byte |
|
|
} |
|
|
|
|
|
type ParseError struct { |
|
|
Err string |
|
|
name string |
|
|
line int |
|
|
} |
|
|
|
|
|
func (e *ParseError) Error() string { |
|
|
s := e.Err + ": \"" + e.name + "\" at line: " + strconv.Itoa(e.line) |
|
|
return s |
|
|
} |
|
|
|
|
|
// First will return the first RR found when parsing. |
|
|
func (zp *Parser) First() (RR, error) { |
|
|
// defer close something |
|
|
return nil, nil |
|
|
} |
|
|
|
|
|
// NewParser creates a new DNS file parser from r. |
|
|
func NewParser(r io.Reader) *Parser { |
|
|
buf := make([]byte, _IOBUF) |
|
|
n, err := r.Read(buf) |
|
|
if err != nil { |
|
|
return nil |
|
|
} |
|
|
if buf[n-1] != '\n' { |
|
|
buf[n] = '\n' |
|
|
n++ |
|
|
} |
|
|
buf = buf[:n] |
|
|
p := new(Parser) |
|
|
p.buf = buf |
|
|
return p |
|
|
} |
|
|
|
|
|
// Translate the RRSIG's incep. and expir. times from |
|
|
// string values ("20110403154150") to an integer. |
|
|
// Taking into account serial arithmetic (RFC 1982) |
|
|
func dateToTime(s string) (uint32, error) { |
|
|
_, e := time.Parse("20060102150405", s) |
|
|
if e != nil { |
|
|
return 0, e |
|
|
} |
|
|
return 0, nil |
|
|
/* |
|
|
mod := t.Seconds() / Year68 |
|
|
ti := uint32(t.Seconds() - (mod * Year68)) |
|
|
return ti, nil |
|
|
*/ |
|
|
} |
|
|
|
|
|
// Return the rdata fields as a string slice. |
|
|
// All starting whitespace is deleted. |
|
|
|
@@ -55,19 +55,6 @@ func NewParser(r io.Reader) *Parser { |
|
|
return p |
|
|
} |
|
|
|
|
|
// Translate the RRSIG's incep. and expir. times from |
|
|
// string values ("20110403154150") to an integer. |
|
|
// Taking into account serial arithmetic (RFC 1982) |
|
|
func dateToTime(s string) (uint32, os.Error) { |
|
|
t, e := time.Parse("20060102150405", s) |
|
|
if e != nil { |
|
|
return 0, e |
|
|
} |
|
|
mod := t.Seconds() / Year68 |
|
|
ti := uint32(t.Seconds() - (mod * Year68)) |
|
|
return ti, nil |
|
|
} |
|
|
|
|
|
// Return the rdata fields as a string slice. |
|
|
// All starting whitespace is deleted. |
|
|
// If i is 0 no spaces are deleted from the final rdfs. |
|
|
|
@@ -36,24 +36,51 @@ const ( |
|
|
_EXPECT_RDATA_BL // Whitespace BEFORE rdata starts |
|
|
) |
|
|
|
|
|
type ParseError struct { |
|
|
err string |
|
|
lex Lex |
|
|
} |
|
|
|
|
|
func (e *ParseError) Error() string { |
|
|
s := e.err + ": `" + e.lex.token + "' at line: " + strconv.Itoa(e.lex.line) + |
|
|
"and column: " + strconv.Itoa(e.lex.column) |
|
|
return s |
|
|
} |
|
|
|
|
|
type Lex struct { |
|
|
token string |
|
|
value int |
|
|
line int |
|
|
column int |
|
|
} |
|
|
|
|
|
// ParseString parses a string and returns the RR contained in there. If they string |
|
|
// contains more than one RR, only the first is returned. |
|
|
func NewRRString(s string) (RR, error) { |
|
|
cr := make(chan RR) |
|
|
go ParseZone(strings.NewReader(s), cr) |
|
|
r := <-cr // There are no error send as of yet |
|
|
return r, nil // Todo: errors |
|
|
} |
|
|
|
|
|
func newRRReader(q io.Reader) (RR, error) { |
|
|
cr := make(chan RR) |
|
|
go ParseZone(q, cr) |
|
|
r := <-cr |
|
|
return r, nil |
|
|
} |
|
|
|
|
|
// ParseZone reads a RFC 1035 zone from r. It returns each parsed RR on the |
|
|
// channel cr. The channel cr is closed by ParseZone when the end of r is |
|
|
// reached. |
|
|
func ParseZone(r io.Reader, cr chan RR) { |
|
|
defer close(cr) |
|
|
defer close(cr) |
|
|
var s scanner.Scanner |
|
|
c := make(chan Lex) |
|
|
s.Init(r) |
|
|
s.Mode = 0 |
|
|
s.Whitespace = 0 |
|
|
// Start the lexer |
|
|
// Start the lexer |
|
|
go lexer(s, c) |
|
|
// 5 possible beginnings of a line, _ is a space |
|
|
// 1. _OWNER _ _RRTYPE -> class/ttl omitted |
|
@@ -174,16 +201,11 @@ func ParseZone(r io.Reader, cr chan RR) { |
|
|
} |
|
|
st = _EXPECT_RDATA |
|
|
case _EXPECT_RDATA: |
|
|
fmt.Printf("%v\n", h) |
|
|
// Remaining items until newline are rdata |
|
|
// reset |
|
|
fmt.Printf("%v", l) |
|
|
for rdata := range c { |
|
|
fmt.Printf("%v", rdata) |
|
|
if rdata.value == _NEWLINE { |
|
|
break |
|
|
} |
|
|
r, e := setRR(h, c) |
|
|
if e != nil { |
|
|
fmt.Printf("%v\n", e) |
|
|
} |
|
|
cr <- r |
|
|
st = _EXPECT_OWNER |
|
|
} |
|
|
} |
|
|
Oops, something went wrong.