2016-08-22 18:31:50 -06:00
package activedir
import (
"encoding/json"
"fmt"
"runtime"
2020-04-14 16:47:30 -04:00
"github.com/StackExchange/dnscontrol/v3/providers"
2016-08-22 18:31:50 -06:00
)
// This is the struct that matches either (or both) of the Registrar and/or DNSProvider interfaces:
2020-10-26 09:25:30 -04:00
type activedirProvider struct {
2016-08-22 18:31:50 -06:00
adServer string
2017-09-13 10:00:41 -04:00
fake bool
psOut string
psLog string
2016-08-22 18:31:50 -06:00
}
2018-01-04 19:19:35 -05:00
var features = providers . DocumentationNotes {
2022-03-02 11:19:15 -05:00
providers . CanGetZones : providers . Unimplemented ( ) ,
2017-09-14 16:13:17 -04:00
providers . CanUseAlias : providers . Cannot ( ) ,
providers . CanUseCAA : providers . Cannot ( ) ,
2018-01-04 19:19:35 -05: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-14 16:13:17 -04:00
}
2016-08-22 18:31:50 -06:00
// Register with the dnscontrol system.
// This establishes the name (all caps), and the function to call to initialize it.
func init ( ) {
2021-03-07 13:19:22 -05:00
fns := providers . DspFuncs {
2021-05-04 14:15:31 -04:00
Initializer : newDNS ,
2021-03-08 20:14:30 -05:00
RecordAuditor : AuditRecords ,
2021-03-07 13:19:22 -05:00
}
providers . RegisterDomainServiceProviderType ( "ACTIVEDIRECTORY_PS" , fns , features )
2016-08-22 18:31:50 -06:00
}
func newDNS ( config map [ string ] string , metadata json . RawMessage ) ( providers . DNSServiceProvider , error ) {
2020-12-28 16:07:33 -05:00
fmt . Printf ( "WARNING: ACTIVEDIRECTORY_PS provider is being replaced by MSDNS. Please convert. Details in https://stackexchange.github.io/dnscontrol/providers/msdns\n" )
2017-09-13 10:00:41 -04:00
fake := false
if fVal := config [ "fakeps" ] ; fVal == "true" {
fake = true
} else if fVal != "" && fVal != "false" {
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589)
* Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Replaced errors.Wrapf with fmt.Errorf (#589)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)
* Replaced errors.Errorf with fmt.Errorf (#589)
* Find: errors\.Errorf
Replace: fmt.Errorf
* Cleaned up remaining imports
* Cleanup
* Regenerate provider support matrix
This was broken by #533 ... and it's now the third time this has been missed.
2020-01-28 11:06:56 -05:00
return nil , fmt . Errorf ( "fakeps value must be 'true' or 'false'" )
2017-09-13 10:00:41 -04:00
}
psOut , psLog := config [ "psout" ] , config [ "pslog" ]
if psOut == "" {
psOut = "dns_update_commands.ps1"
}
if psLog == "" {
psLog = "powershell.log"
}
2020-10-26 09:25:30 -04:00
p := & activedirProvider { psLog : psLog , psOut : psOut , fake : fake }
2017-09-13 10:00:41 -04:00
if fake {
return p , nil
}
if runtime . GOOS == "windows" {
2016-08-22 18:31:50 -06:00
srv := config [ "ADServer" ]
if srv == "" {
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589)
* Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Replaced errors.Wrapf with fmt.Errorf (#589)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)
* Replaced errors.Errorf with fmt.Errorf (#589)
* Find: errors\.Errorf
Replace: fmt.Errorf
* Cleaned up remaining imports
* Cleanup
* Regenerate provider support matrix
This was broken by #533 ... and it's now the third time this has been missed.
2020-01-28 11:06:56 -05:00
return nil , fmt . Errorf ( "ADServer required for Active Directory provider" )
2016-08-22 18:31:50 -06:00
}
2017-09-13 10:00:41 -04:00
p . adServer = srv
return p , nil
2016-08-22 18:31:50 -06:00
}
2019-05-23 06:29:21 -07:00
fmt . Printf ( "WARNING: PowerShell not available. Active Directory will not be updated.\n" )
2016-08-22 18:31:50 -06:00
return providers . None { } , nil
}