Skip to content

Commit

Permalink
BIND: BUG: Wrong filename used in concurrent mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tlimoncelli committed Dec 16, 2024
1 parent 3643e2e commit 0548d5a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions providers/bind/bindProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type bindProvider struct {
nameservers []*models.Nameserver
directory string
filenameformat string
zonefile string // Where the zone data is e texpected
//zonefile string // Where the zone data is e texpected
//zoneFileFound bool // Did the zonefile exist?
}

Expand Down Expand Up @@ -162,6 +162,7 @@ func (c *bindProvider) ListZones() ([]string, error) {

// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
func (c *bindProvider) GetZoneRecords(domain string, meta map[string]string) (models.Records, error) {
var zonefile string

if _, err := os.Stat(c.directory); os.IsNotExist(err) {
printer.Printf("\nWARNING: BIND directory %q does not exist! (will create)\n", c.directory)
Expand All @@ -172,27 +173,27 @@ func (c *bindProvider) GetZoneRecords(domain string, meta map[string]string) (mo
// This layering violation is needed for tests only.
// Otherwise, this is set already.
// Note: In this situation there is no "uniquename" or "tag".
c.zonefile = filepath.Join(c.directory,
zonefile = filepath.Join(c.directory,
makeFileName(c.filenameformat, domain, domain, ""))
} else {
c.zonefile = filepath.Join(c.directory,
zonefile = filepath.Join(c.directory,
makeFileName(c.filenameformat,
meta[models.DomainUniqueName], domain, meta[models.DomainTag]),
)
}
content, err := os.ReadFile(c.zonefile)
content, err := os.ReadFile(zonefile)
if os.IsNotExist(err) {
// If the file doesn't exist, that's not an error. Just informational.
//c.zoneFileFound = false
fmt.Fprintf(os.Stderr, "File does not yet exist: %q (will create)\n", c.zonefile)
fmt.Fprintf(os.Stderr, "File does not yet exist: %q (will create)\n", zonefile)
return nil, nil
}
if err != nil {
return nil, fmt.Errorf("can't open %s: %w", c.zonefile, err)
return nil, fmt.Errorf("can't open %s: %w", zonefile, err)
}
//c.zoneFileFound = true

zonefileName := c.zonefile
zonefileName := zonefile

return ParseZoneContents(string(content), domain, zonefileName)
}
Expand All @@ -219,6 +220,7 @@ func ParseZoneContents(content string, zoneName string, zonefileName string) (mo
// GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records.
func (c *bindProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, foundRecords models.Records) ([]*models.Correction, int, error) {
var corrections []*models.Correction
var zonefile string

changes := false
var msg string
Expand Down Expand Up @@ -270,7 +272,7 @@ func (c *bindProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, foundR
comments = append(comments, "Automatic DNSSEC signing requested")
}

c.zonefile = filepath.Join(c.directory,
zonefile = filepath.Join(c.directory,
makeFileName(c.filenameformat,
dc.Metadata[models.DomainUniqueName], dc.Name, dc.Metadata[models.DomainTag]),
)
Expand All @@ -287,8 +289,8 @@ func (c *bindProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, foundR
&models.Correction{
Msg: msg,
F: func() error {
printer.Printf("WRITING ZONEFILE: %v\n", c.zonefile)
fname, err := preprocessFilename(c.zonefile)
printer.Printf("WRITING ZONEFILE: %v\n", zonefile)
fname, err := preprocessFilename(zonefile)
if err != nil {
return fmt.Errorf("could not create zonefile: %w", err)
}
Expand Down

0 comments on commit 0548d5a

Please sign in to comment.