Add --bind-conf flag for BIND domains.conf generation

Generate a BIND-format domains.conf file alongside catalog zones.
New input properties: file= (zone data path) and dnssec (bare flag).
When --bind-conf is set, every zone must have file= or it errors.

Renames ZoneEntry.File to ZonesFile (input path for error messages)
and adds ZoneFile (BIND file path) and DNSSEC (bool) fields.
This commit is contained in:
2026-03-28 11:15:06 -07:00
parent 44d7867a0c
commit 0eddb9fcfe
9 changed files with 451 additions and 51 deletions

View File

@@ -9,21 +9,23 @@ import (
// ZoneEntry represents a parsed line from the input file.
type ZoneEntry struct {
Zone string // Normalized FQDN
Catalogs []string // Catalog names (bare names from input)
Group string // Optional RFC 9432 group property
COO string // Optional RFC 9432 change-of-ownership FQDN
File string // Source file
Line int // Source line number
Zone string // Normalized FQDN
Catalogs []string // Catalog names (bare names from input)
Group string // Optional RFC 9432 group property
COO string // Optional RFC 9432 change-of-ownership FQDN
ZoneFile string // file= property: zone data path for BIND config
DNSSEC bool // dnssec flag: adds dnssec-policy to BIND config
ZonesFile string // Input file path (for error messages)
Line int // Input line number (for error messages)
}
// CatalogMembers groups zone entries by catalog name.
type CatalogMembers map[string][]ZoneEntry
func parseInput(path string, cfg *Config) (CatalogMembers, error) {
func parseInput(path string, cfg *Config) ([]ZoneEntry, CatalogMembers, error) {
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("opening input: %w", err)
return nil, nil, fmt.Errorf("opening input: %w", err)
}
defer f.Close()
@@ -39,15 +41,19 @@ func parseInput(path string, cfg *Config) (CatalogMembers, error) {
entry, err := parseLine(line, path, lineNum)
if err != nil {
return nil, err
return nil, nil, err
}
entries = append(entries, entry)
}
if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("reading %s: %w", path, err)
return nil, nil, fmt.Errorf("reading %s: %w", path, err)
}
return buildCatalogMembers(entries, cfg)
members, err := buildCatalogMembers(entries, cfg)
if err != nil {
return nil, nil, err
}
return entries, members, nil
}
func parseLine(line, file string, lineNum int) (ZoneEntry, error) {
@@ -58,9 +64,9 @@ func parseLine(line, file string, lineNum int) (ZoneEntry, error) {
}
entry := ZoneEntry{
Zone: normalizeFQDN(tokens[0]),
File: file,
Line: lineNum,
Zone: normalizeFQDN(tokens[0]),
ZonesFile: file,
Line: lineNum,
}
for _, tok := range tokens[1:] {
@@ -77,9 +83,18 @@ func parseLine(line, file string, lineNum int) (ZoneEntry, error) {
return ZoneEntry{}, fmt.Errorf("%s:%d: empty coo value", file, lineNum)
}
entry.COO = normalizeFQDN(value)
case "file":
if value == "" {
return ZoneEntry{}, fmt.Errorf("%s:%d: empty file value", file, lineNum)
}
entry.ZoneFile = value
case "dnssec":
return ZoneEntry{}, fmt.Errorf("%s:%d: dnssec is a flag, use without =", file, lineNum)
default:
return ZoneEntry{}, fmt.Errorf("%s:%d: unknown property %q", file, lineNum, key)
}
} else if tok == "dnssec" {
entry.DNSSEC = true
} else {
// Bare name = catalog assignment
entry.Catalogs = append(entry.Catalogs, tok)
@@ -107,7 +122,7 @@ func buildCatalogMembers(entries []ZoneEntry, cfg *Config) (CatalogMembers, erro
for _, entry := range entries {
for _, catName := range entry.Catalogs {
if _, ok := cfg.Catalogs[catName]; !ok {
return nil, fmt.Errorf("%s:%d: unknown catalog %q", entry.File, entry.Line, catName)
return nil, fmt.Errorf("%s:%d: unknown catalog %q", entry.ZonesFile, entry.Line, catName)
}
if seen[catName] == nil {
@@ -115,7 +130,7 @@ func buildCatalogMembers(entries []ZoneEntry, cfg *Config) (CatalogMembers, erro
}
if prevLine, dup := seen[catName][entry.Zone]; dup {
return nil, fmt.Errorf("%s:%d: zone %s already assigned to catalog %q at line %d",
entry.File, entry.Line, entry.Zone, catName, prevLine)
entry.ZonesFile, entry.Line, entry.Zone, catName, prevLine)
}
seen[catName][entry.Zone] = entry.Line