Ejemplo n.º 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 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
}
Ejemplo n.º 3
0
func lookupFullNameDomain(domainAndUser string) (string, error) {
	return syscall.TranslateAccountName(domainAndUser,
		syscall.NameSamCompatible, syscall.NameDisplay, 50)
}