re-enable config
This commit is contained in:
parent
52f694ea0d
commit
12196e35ac
2
Makefile
2
Makefile
|
@ -7,6 +7,7 @@ include $(GOROOT)/src/Make.inc
|
||||||
|
|
||||||
TARG=dns
|
TARG=dns
|
||||||
GOFILES=\
|
GOFILES=\
|
||||||
|
config.go\
|
||||||
defaults.go\
|
defaults.go\
|
||||||
dns.go\
|
dns.go\
|
||||||
dnssec.go\
|
dnssec.go\
|
||||||
|
@ -20,7 +21,6 @@ GOFILES=\
|
||||||
tsig.go\
|
tsig.go\
|
||||||
types.go\
|
types.go\
|
||||||
xfr.go\
|
xfr.go\
|
||||||
# config.go
|
|
||||||
|
|
||||||
include $(GOROOT)/src/Make.pkg
|
include $(GOROOT)/src/Make.pkg
|
||||||
|
|
||||||
|
|
46
config.go
46
config.go
|
@ -3,9 +3,8 @@
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// Read system DNS config from /etc/resolv.conf
|
// Read system DNS config from /etc/resolv.conf
|
||||||
|
// Extend this further, but need to thinks about Conn
|
||||||
|
|
||||||
// TODO: what to do with this code - we don't have a
|
|
||||||
// structure to put it in
|
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -17,19 +16,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// See resolv.conf(5) on a Linux machine.
|
// See resolv.conf(5) on a Linux machine.
|
||||||
// Set the resolver configuration from a /etc/resolv.conf like file.
|
// Parse a /etc/resolv.conf like file. For only
|
||||||
func (r *Resolver) FromFile(conf string) os.Error {
|
// only return the nameservers with :53 added as a slice.
|
||||||
|
func FromFile(conf string) ([]string, os.Error) {
|
||||||
file, err := os.Open(conf, os.O_RDONLY, 0)
|
file, err := os.Open(conf, os.O_RDONLY, 0)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
b := bufio.NewReader(file)
|
b := bufio.NewReader(file)
|
||||||
r.Servers = make([]string, 3)[0:0] // small, but the standard limit
|
servers := make([]string, 3)[0:0] // small, but the standard limit
|
||||||
r.Search = make([]string, 0)
|
search := make([]string, 0)
|
||||||
r.Ndots = 1
|
ndots := 1; var _ = ndots
|
||||||
r.Timeout = 5
|
timeout := 5; var _ = timeout
|
||||||
r.Attempts = 2
|
attempts := 2; var _ = attempts
|
||||||
for line, ok := b.ReadString('\n'); ok == nil; line, ok = b.ReadString('\n') {
|
for line, ok := b.ReadString('\n'); ok == nil; line, ok = b.ReadString('\n') {
|
||||||
f := strings.Fields(line)
|
f := strings.Fields(line)
|
||||||
if len(f) < 1 {
|
if len(f) < 1 {
|
||||||
|
@ -37,7 +37,7 @@ func (r *Resolver) FromFile(conf string) os.Error {
|
||||||
}
|
}
|
||||||
switch f[0] {
|
switch f[0] {
|
||||||
case "nameserver": // add one name server
|
case "nameserver": // add one name server
|
||||||
a := r.Servers
|
a := servers
|
||||||
n := len(a)
|
n := len(a)
|
||||||
if len(f) > 1 && n < cap(a) {
|
if len(f) > 1 && n < cap(a) {
|
||||||
// One more check: make sure server name is
|
// One more check: make sure server name is
|
||||||
|
@ -50,23 +50,23 @@ func (r *Resolver) FromFile(conf string) os.Error {
|
||||||
fallthrough
|
fallthrough
|
||||||
case 4:
|
case 4:
|
||||||
a = a[0 : n+1]
|
a = a[0 : n+1]
|
||||||
a[n] = name
|
a[n] = name + ":53"
|
||||||
r.Servers = a
|
servers = a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case "domain": // set search path to just this domain
|
case "domain": // set search path to just this domain
|
||||||
if len(f) > 1 {
|
if len(f) > 1 {
|
||||||
r.Search = make([]string, 1)
|
search = make([]string, 1)
|
||||||
r.Search[0] = f[1]
|
search[0] = f[1]
|
||||||
} else {
|
} else {
|
||||||
r.Search = make([]string, 0)
|
search = make([]string, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "search": // set search path to given servers
|
case "search": // set search path to given servers
|
||||||
r.Search = make([]string, len(f)-1)
|
search = make([]string, len(f)-1)
|
||||||
for i := 0; i < len(r.Search); i++ {
|
for i := 0; i < len(search); i++ {
|
||||||
r.Search[i] = f[i+1]
|
search[i] = f[i+1]
|
||||||
}
|
}
|
||||||
|
|
||||||
case "options": // magic options
|
case "options": // magic options
|
||||||
|
@ -78,24 +78,24 @@ func (r *Resolver) FromFile(conf string) os.Error {
|
||||||
if n < 1 {
|
if n < 1 {
|
||||||
n = 1
|
n = 1
|
||||||
}
|
}
|
||||||
r.Ndots = n
|
ndots = n
|
||||||
case len(s) >= 8 && s[:8] == "timeout:":
|
case len(s) >= 8 && s[:8] == "timeout:":
|
||||||
n, _ := strconv.Atoi(s[8:])
|
n, _ := strconv.Atoi(s[8:])
|
||||||
if n < 1 {
|
if n < 1 {
|
||||||
n = 1
|
n = 1
|
||||||
}
|
}
|
||||||
r.Timeout = n
|
timeout = n
|
||||||
case len(s) >= 8 && s[:9] == "attempts:":
|
case len(s) >= 8 && s[:9] == "attempts:":
|
||||||
n, _ := strconv.Atoi(s[9:])
|
n, _ := strconv.Atoi(s[9:])
|
||||||
if n < 1 {
|
if n < 1 {
|
||||||
n = 1
|
n = 1
|
||||||
}
|
}
|
||||||
r.Attempts = n
|
attempts = n
|
||||||
case s == "rotate":
|
case s == "rotate":
|
||||||
/* not imp */
|
/* not imp */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return servers, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue