switch away from net.LookUpTxt

This commit is contained in:
Hyatt 2024-01-23 20:48:01 -06:00
parent b7c2beb01c
commit 9cfc330971
Signed by: nhyatt
GPG Key ID: C50D0BBB5BC40BEA

View File

@ -3,7 +3,6 @@ package nsupdate
import (
"bytes"
"fmt"
"net"
"strings"
"os/exec"
@ -32,22 +31,27 @@ var (
)
func (c NsUpdateStruct) UpdateTXT(record, recordType, value string) error {
var (
stdout bytes.Buffer
stderr bytes.Buffer
)
for _, v := range specialChars {
value = strings.ReplaceAll(value, v, fmt.Sprintf("\\%s", v))
}
value = sanitizeTXT(value)
r, err := net.LookupTXT(record)
if err != nil {
config.Cfg.Log.Info("unable to get existing record", "record", record, "error", err)
command := fmt.Sprintf("dig +shord TXT %s", record)
cmd := exec.Command("/usr/bin/env", "sh", "-c", command)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
config.Cfg.Log.Error("error adding record", "error", err, "stderr", stderr.String(), "stdout", stdout.String())
return err
}
var oldTXT string
for _, v := range r {
oldTXT += v
}
oldTXT := stdout.String()
if strings.ReplaceAll(oldTXT, `" "`, ``) != strings.ReplaceAll(value, `" "`, ``) {
config.Cfg.Log.Debug("deleting record", "record", record)