2020-12-28 16:07:33 -05:00
|
|
|
|
package msdns
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"runtime"
|
|
|
|
|
|
2023-05-20 19:21:45 +02:00
|
|
|
|
"github.com/StackExchange/dnscontrol/v4/models"
|
|
|
|
|
"github.com/StackExchange/dnscontrol/v4/pkg/printer"
|
|
|
|
|
"github.com/StackExchange/dnscontrol/v4/providers"
|
2020-12-28 16:07:33 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// This is the struct that matches either (or both) of the Registrar and/or DNSProvider interfaces:
|
|
|
|
|
type msdnsProvider struct {
|
2021-05-02 11:25:06 -04:00
|
|
|
|
dnsserver string // Which DNS Server to update
|
|
|
|
|
pssession string // Remote machine to PSSession to
|
|
|
|
|
psusername string // Remote username for PSSession
|
|
|
|
|
pspassword string // Remote password for PSSession
|
|
|
|
|
shell DNSAccessor // Handle for
|
2020-12-28 16:07:33 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var features = providers.DocumentationNotes{
|
|
|
|
|
providers.CanGetZones: providers.Can(),
|
|
|
|
|
providers.CanUseAlias: providers.Cannot(),
|
|
|
|
|
providers.CanUseCAA: providers.Cannot(),
|
|
|
|
|
providers.CanUseDS: providers.Unimplemented(),
|
2023-03-16 19:04:20 +01:00
|
|
|
|
providers.CanUseLOC: providers.Cannot(),
|
2021-06-24 18:26:21 -04:00
|
|
|
|
providers.CanUseNAPTR: providers.Can(),
|
2020-12-28 16:07:33 -05:00
|
|
|
|
providers.CanUsePTR: providers.Can(),
|
|
|
|
|
providers.CanUseSRV: providers.Can(),
|
|
|
|
|
providers.CanUseTLSA: providers.Unimplemented(),
|
|
|
|
|
providers.DocCreateDomains: providers.Cannot("This provider assumes the zone already existing on the dns server"),
|
|
|
|
|
providers.DocDualHost: providers.Cannot("This driver does not manage NS records, so should not be used for dual-host scenarios"),
|
|
|
|
|
providers.DocOfficiallySupported: providers.Can(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Register with the dnscontrol system.
|
2022-08-14 20:49:57 -04:00
|
|
|
|
//
|
|
|
|
|
// This establishes the name (all caps), and the function to call to initialize it.
|
2020-12-28 16:07:33 -05:00
|
|
|
|
func init() {
|
2021-03-07 13:19:22 -05:00
|
|
|
|
fns := providers.DspFuncs{
|
2021-05-02 11:25:06 -04:00
|
|
|
|
Initializer: newDNS,
|
2021-03-08 20:14:30 -05:00
|
|
|
|
RecordAuditor: AuditRecords,
|
2021-03-07 13:19:22 -05:00
|
|
|
|
}
|
|
|
|
|
providers.RegisterDomainServiceProviderType("MSDNS", fns, features)
|
2020-12-28 16:07:33 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newDNS(config map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
|
|
|
|
|
|
|
|
|
|
if runtime.GOOS != "windows" {
|
2022-08-16 18:09:54 -04:00
|
|
|
|
printer.Println("INFO: MSDNS deactivated. Required OS not detected.")
|
2020-12-28 16:07:33 -05:00
|
|
|
|
return providers.None{}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
p := &msdnsProvider{
|
2021-05-02 11:25:06 -04:00
|
|
|
|
dnsserver: config["dnsserver"],
|
|
|
|
|
pssession: config["pssession"],
|
|
|
|
|
psusername: config["psusername"],
|
|
|
|
|
pspassword: config["pspassword"],
|
2020-12-28 16:07:33 -05:00
|
|
|
|
}
|
|
|
|
|
p.shell, err = newPowerShell(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return p, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Section 3: Domain Service Provider (DSP) related functions
|
|
|
|
|
|
|
|
|
|
// GetZoneRecords gathers the DNS records and converts them to
|
|
|
|
|
// dnscontrol's format.
|
2023-05-02 13:04:59 -04:00
|
|
|
|
func (client *msdnsProvider) GetZoneRecords(domain string, meta map[string]string) (models.Records, error) {
|
2020-12-28 16:07:33 -05:00
|
|
|
|
|
|
|
|
|
// Get the existing DNS records in native format.
|
|
|
|
|
nativeExistingRecords, err := client.shell.GetDNSZoneRecords(client.dnsserver, domain)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
// Convert them to DNScontrol's native format:
|
|
|
|
|
existingRecords := make([]*models.RecordConfig, 0, len(nativeExistingRecords))
|
|
|
|
|
for _, rr := range nativeExistingRecords {
|
|
|
|
|
rc, err := nativeToRecords(rr, domain)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if rc != nil {
|
|
|
|
|
existingRecords = append(existingRecords, rc)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return existingRecords, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NB(tlim): If we want to implement a registrar, refer to
|
|
|
|
|
// http://go.microsoft.com/fwlink/?LinkId=288158
|
|
|
|
|
// (Get-DnsServerZoneDelegation) for hints about which PowerShell
|
|
|
|
|
// commands to use.
|