mirror of
https://github.com/hanzozt/sdk-golang.git
synced 2026-10-30 14:46:37 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
//go:build windows
|
|
|
|
/*
|
|
Copyright 2019 NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package posture
|
|
|
|
import (
|
|
"syscall"
|
|
"unicode/utf16"
|
|
"unsafe"
|
|
)
|
|
|
|
func NewDomainProvider() DomainProvider {
|
|
return &WindowsDomainProvider{}
|
|
}
|
|
|
|
type WindowsDomainProvider struct{}
|
|
|
|
func (p *WindowsDomainProvider) GetDomain() string {
|
|
var domain *uint16
|
|
var status uint32
|
|
|
|
err := syscall.NetGetJoinInformation(nil, &domain, &status)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
defer func(buf *byte) {
|
|
_ = syscall.NetApiBufferFree(buf)
|
|
}((*byte)(unsafe.Pointer(domain)))
|
|
|
|
//todo: add this back in so that workgroups aren't allowed: status == syscall.NetSetupDomainName &&
|
|
if domain != nil {
|
|
domainName := cStringTostring(domain)
|
|
return domainName
|
|
}
|
|
|
|
return ""
|
|
}
|
|
|
|
func cStringTostring(cs *uint16) (s string) {
|
|
if cs != nil {
|
|
us := make([]uint16, 0, 256)
|
|
for p := uintptr(unsafe.Pointer(cs)); ; p += 2 {
|
|
u := *(*uint16)(unsafe.Pointer(p))
|
|
if u == 0 {
|
|
return string(utf16.Decode(us))
|
|
}
|
|
us = append(us, u)
|
|
}
|
|
}
|
|
return ""
|
|
}
|