Skip to content

Commit

Permalink
Merge pull request #182 from Control-D-Inc/release-branch-v1.3.10
Browse files Browse the repository at this point in the history
[WIP] Release branch v1.3.10
  • Loading branch information
cuonglm authored Oct 29, 2024
2 parents 7088df5 + 6ca1a7c commit 5b9ccc5
Show file tree
Hide file tree
Showing 50 changed files with 2,107 additions and 707 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
os: ["windows-latest", "ubuntu-latest", "macOS-latest"]
go: ["1.21.x"]
go: ["1.23.x"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand All @@ -21,6 +21,6 @@ jobs:
- run: "go test -race ./..."
- uses: dominikh/staticcheck-action@v1.2.0
with:
version: "2023.1.2"
version: "2024.1.1"
install-go: false
cache-key: ${{ matrix.go }}
10 changes: 10 additions & 0 deletions cmd/cli/ad_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !windows

package cli

import (
"github.com/Control-D-Inc/ctrld"
)

// addExtraSplitDnsRule adds split DNS rule if present.
func addExtraSplitDnsRule(_ *ctrld.Config) {}
45 changes: 45 additions & 0 deletions cmd/cli/ad_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cli

import (
"fmt"
"strings"

"github.com/Control-D-Inc/ctrld"
)

// addExtraSplitDnsRule adds split DNS rule for domain if it's part of active directory.
func addExtraSplitDnsRule(cfg *ctrld.Config) {
domain, err := getActiveDirectoryDomain()
if err != nil {
mainLog.Load().Debug().Msgf("unable to get active directory domain: %v", err)
return
}
if domain == "" {
mainLog.Load().Debug().Msg("no active directory domain found")
return
}
for n, lc := range cfg.Listener {
if lc.Policy == nil {
lc.Policy = &ctrld.ListenerPolicyConfig{}
}
domainRule := "*." + strings.TrimPrefix(domain, ".")
for _, rule := range lc.Policy.Rules {
if _, ok := rule[domainRule]; ok {
mainLog.Load().Debug().Msgf("domain rule already exist for listener.%s", n)
return
}
}
mainLog.Load().Debug().Msgf("adding active directory domain for listener.%s", n)
lc.Policy.Rules = append(lc.Policy.Rules, ctrld.Rule{domainRule: []string{}})
}
}

// getActiveDirectoryDomain returns AD domain name of this computer.
func getActiveDirectoryDomain() (string, error) {
cmd := "$obj = Get-WmiObject Win32_ComputerSystem; if ($obj.PartOfDomain) { $obj.Domain }"
output, err := powershell(cmd)
if err != nil {
return "", fmt.Errorf("failed to get domain name: %w, output:\n\n%s", err, string(output))
}
return string(output), nil
}
Loading

0 comments on commit 5b9ccc5

Please sign in to comment.