2016-08-23 08:31:50 +08:00
|
|
|
package activedir
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/StackExchange/dnscontrol/providers"
|
2018-02-06 05:17:20 +08:00
|
|
|
"github.com/pkg/errors"
|
2016-08-23 08:31:50 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// This is the struct that matches either (or both) of the Registrar and/or DNSProvider interfaces:
|
|
|
|
type adProvider struct {
|
|
|
|
adServer string
|
2017-09-13 22:00:41 +08:00
|
|
|
fake bool
|
|
|
|
psOut string
|
|
|
|
psLog string
|
2016-08-23 08:31:50 +08:00
|
|
|
}
|
|
|
|
|
2018-01-05 08:19:35 +08:00
|
|
|
var features = providers.DocumentationNotes{
|
2017-09-15 04:13:17 +08:00
|
|
|
providers.CanUseAlias: providers.Cannot(),
|
|
|
|
providers.CanUseCAA: providers.Cannot(),
|
2018-01-05 08:19:35 +08:00
|
|
|
providers.CanUsePTR: providers.Cannot(),
|
|
|
|
providers.CanUseSRV: providers.Cannot(),
|
|
|
|
providers.DocCreateDomains: providers.Cannot("AD depends on 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(),
|
2017-09-15 04:13:17 +08:00
|
|
|
}
|
|
|
|
|
2016-08-23 08:31:50 +08:00
|
|
|
// Register with the dnscontrol system.
|
|
|
|
// This establishes the name (all caps), and the function to call to initialize it.
|
|
|
|
func init() {
|
2018-01-05 08:19:35 +08:00
|
|
|
providers.RegisterDomainServiceProviderType("ACTIVEDIRECTORY_PS", newDNS, features)
|
2016-08-23 08:31:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func newDNS(config map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
|
2017-09-13 22:00:41 +08:00
|
|
|
|
|
|
|
fake := false
|
|
|
|
if fVal := config["fakeps"]; fVal == "true" {
|
|
|
|
fake = true
|
|
|
|
} else if fVal != "" && fVal != "false" {
|
2018-02-06 05:17:20 +08:00
|
|
|
return nil, errors.Errorf("fakeps value must be 'true' or 'false'")
|
2017-09-13 22:00:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
psOut, psLog := config["psout"], config["pslog"]
|
|
|
|
if psOut == "" {
|
|
|
|
psOut = "dns_update_commands.ps1"
|
|
|
|
}
|
|
|
|
if psLog == "" {
|
|
|
|
psLog = "powershell.log"
|
|
|
|
}
|
|
|
|
|
|
|
|
p := &adProvider{psLog: psLog, psOut: psOut, fake: fake}
|
|
|
|
if fake {
|
|
|
|
return p, nil
|
|
|
|
}
|
|
|
|
if runtime.GOOS == "windows" {
|
2016-08-23 08:31:50 +08:00
|
|
|
srv := config["ADServer"]
|
|
|
|
if srv == "" {
|
2018-02-06 05:17:20 +08:00
|
|
|
return nil, errors.Errorf("ADServer required for Active Directory provider")
|
2016-08-23 08:31:50 +08:00
|
|
|
}
|
2017-09-13 22:00:41 +08:00
|
|
|
p.adServer = srv
|
|
|
|
return p, nil
|
2016-08-23 08:31:50 +08:00
|
|
|
}
|
|
|
|
fmt.Printf("WARNING: PowerShell not available. ActiveDirectory will not be updated.\n")
|
|
|
|
return providers.None{}, nil
|
|
|
|
}
|