Beispiel #1
0
func lookupFullName(domain, username, domainAndUser string) (string, error) {
	// try domain controller first
	name, e := syscall.TranslateAccountName(domainAndUser,
		syscall.NameSamCompatible, syscall.NameDisplay, 50)
	if e != nil {
		// domain lookup failed, perhaps this pc is not part of domain
		d, e := syscall.UTF16PtrFromString(domain)
		if e != nil {
			return "", e
		}
		u, e := syscall.UTF16PtrFromString(username)
		if e != nil {
			return "", e
		}
		var p *byte
		e = syscall.NetUserGetInfo(d, u, 10, &p)
		if e != nil {
			// path executed when a domain user is disconnected from the domain
			// pretend username is fullname
			return username, nil
		}
		defer syscall.NetApiBufferFree(p)
		i := (*syscall.UserInfo10)(unsafe.Pointer(p))
		if i.FullName == nil {
			return "", nil
		}
		name = syscall.UTF16ToString((*[1024]uint16)(unsafe.Pointer(i.FullName))[:])
	}
	return name, nil
}
func GetDcName(computerName, domainName, siteName string, flags uint32) (info *DomainControllerInfo, err error) {
	var cnp, dnp, snp *uint16
	cnp, err = utf16PtrFromString(computerName)
	if err != nil {
		return
	}
	dnp, err = utf16PtrFromString(domainName)
	if err != nil {
		return
	}
	snp, err = utf16PtrFromString(siteName)
	if err != nil {
		return
	}
	var dci *DOMAIN_CONTROLLER_INFO
	err = DsGetDcName(cnp, dnp, snp, flags, &dci)
	if err != nil {
		return
	}
	defer syscall.NetApiBufferFree((*byte)(unsafe.Pointer(dci)))
	info = &DomainControllerInfo{
		DomainControllerName:        utf16PtrToString(dci.DomainControllerName),
		DomainControllerAddress:     utf16PtrToString(dci.DomainControllerAddress),
		DomainControllerAddressType: dci.DomainControllerAddressType,
		DomainGuid:                  dci.DomainGuid,
		DomainName:                  utf16PtrToString(dci.DomainName),
		DnsForestName:               utf16PtrToString(dci.DnsForestName),
		Flags:                       dci.Flags,
		DcSiteName:                  utf16PtrToString(dci.DcSiteName),
		ClientSiteName:              utf16PtrToString(dci.ClientSiteName),
	}
	return
}
Beispiel #3
0
func isDomainJoined() (bool, error) {
	var domain *uint16
	var status uint32
	err := syscall.NetGetJoinInformation(nil, &domain, &status)
	if err != nil {
		return false, err
	}
	syscall.NetApiBufferFree((*byte)(unsafe.Pointer(domain)))
	return status == syscall.NetSetupDomainName, nil
}
func GetSiteName(computerName string) (siteName string, err error) {
	var cnp, snp *uint16
	cnp, err = utf16PtrFromString(computerName)
	if err != nil {
		return
	}
	snp, err = DsGetSiteName(cnp)
	if err != nil {
		return
	}
	defer syscall.NetApiBufferFree((*byte)(unsafe.Pointer(snp)))
	siteName = utf16PtrToString(snp)
	return
}
func lookupFullName(domain, username, domainAndUser string) (string, error) {
	// try domain controller first
	name, e := syscall.TranslateAccountName(domainAndUser,
		syscall.NameSamCompatible, syscall.NameDisplay, 50)
	if e != nil {
		// domain lookup failed, perhaps this pc is not part of domain
		d := syscall.StringToUTF16Ptr(domain)
		u := syscall.StringToUTF16Ptr(username)
		var p *byte
		e := syscall.NetUserGetInfo(d, u, 10, &p)
		if e != nil {
			return "", e
		}
		defer syscall.NetApiBufferFree(p)
		i := (*syscall.UserInfo10)(unsafe.Pointer(p))
		if i.FullName == nil {
			return "", nil
		}
		name = syscall.UTF16ToString((*[1024]uint16)(unsafe.Pointer(i.FullName))[:])
	}
	return name, nil
}
Beispiel #6
0
func lookupFullNameServer(servername, username string) (string, error) {
	s, e := syscall.UTF16PtrFromString(servername)
	if e != nil {
		return "", e
	}
	u, e := syscall.UTF16PtrFromString(username)
	if e != nil {
		return "", e
	}
	var p *byte
	e = syscall.NetUserGetInfo(s, u, 10, &p)
	if e != nil {
		return "", e
	}
	defer syscall.NetApiBufferFree(p)
	i := (*syscall.UserInfo10)(unsafe.Pointer(p))
	if i.FullName == nil {
		return "", nil
	}
	name := syscall.UTF16ToString((*[1024]uint16)(unsafe.Pointer(i.FullName))[:])
	return name, nil
}