From 0548d5a17c8bcbf560ace55d6c164c5db8665376 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Mon, 16 Dec 2024 13:56:25 -0500 Subject: [PATCH] BIND: BUG: Wrong filename used in concurrent mode --- providers/bind/bindProvider.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/providers/bind/bindProvider.go b/providers/bind/bindProvider.go index c7e18c1930..e7bf07ead7 100644 --- a/providers/bind/bindProvider.go +++ b/providers/bind/bindProvider.go @@ -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? } @@ -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) @@ -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) } @@ -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 @@ -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]), ) @@ -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) }