Commit d386eaf9 authored by linxin's avatar linxin Committed by Brad Davidson

Validate resolv.conf for presence of nameserver entries

Co-authored-by: 's avatarBrad Davidson <brad@oatmail.org> Signed-off-by: 's avatarlinxin <linxin@geedgenetworks.com> (cherry picked from commit f24ba9d3) Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com>
parent 2434cfd4
...@@ -316,19 +316,22 @@ func isValidResolvConf(resolvConfFile string) bool { ...@@ -316,19 +316,22 @@ func isValidResolvConf(resolvConfFile string) bool {
nameserver := regexp.MustCompile(`^nameserver\s+([^\s]*)`) nameserver := regexp.MustCompile(`^nameserver\s+([^\s]*)`)
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
foundNameserver := false
for scanner.Scan() { for scanner.Scan() {
ipMatch := nameserver.FindStringSubmatch(scanner.Text()) ipMatch := nameserver.FindStringSubmatch(scanner.Text())
if len(ipMatch) == 2 { if len(ipMatch) == 2 {
ip := net.ParseIP(ipMatch[1]) ip := net.ParseIP(ipMatch[1])
if ip == nil || !ip.IsGlobalUnicast() { if ip == nil || !ip.IsGlobalUnicast() {
return false return false
} else {
foundNameserver = true
} }
} }
} }
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {
return false return false
} }
return true return foundNameserver
} }
func locateOrGenerateResolvConf(envInfo *cmds.Agent) string { func locateOrGenerateResolvConf(envInfo *cmds.Agent) string {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment