Exemplo n.º 1
0
 QString fullName() {
   TCHAR username[1024];
   DWORD username_len = 1023;
   if (GetUserNameExW(NameDisplay, username, &username_len))
     return QString::fromWCharArray(username);
   return "";
 }
Exemplo n.º 2
0
NS_IMETHODIMP
nsUserInfo::GetFullname(PRUnichar **aFullname)
{
  NS_ENSURE_ARG_POINTER(aFullname);
  *aFullname = nullptr;

  PRUnichar fullName[512];
  DWORD size = mozilla::ArrayLength(fullName);

  if (GetUserNameExW(NameDisplay, fullName, &size)) {
    *aFullname = ToNewUnicode(nsDependentString(fullName));
  } else {
    DWORD getUsernameError = GetLastError();

    // Try to use the net APIs regardless of the error because it may be
    // able to obtain the information.
    PRUnichar username[UNLEN + 1];
    size = mozilla::ArrayLength(username);
    if (!GetUserNameW(username, &size)) {
      // ERROR_NONE_MAPPED means the user info is not filled out on this computer
      return getUsernameError == ERROR_NONE_MAPPED ?
             NS_ERROR_NOT_AVAILABLE : NS_ERROR_FAILURE;
    }

    const DWORD level = 2;
    LPBYTE info;
    // If the NetUserGetInfo function has no full name info it will return
    // success with an empty string.
    NET_API_STATUS status = NetUserGetInfo(nullptr, username, level, &info);
    if (status != NERR_Success) {
      // We have an error with NetUserGetInfo but we know the info is not
      // filled in because GetUserNameExW returned ERROR_NONE_MAPPED.
      return getUsernameError == ERROR_NONE_MAPPED ?
             NS_ERROR_NOT_AVAILABLE : NS_ERROR_FAILURE;
    }

    nsDependentString fullName =
      nsDependentString(reinterpret_cast<USER_INFO_2 *>(info)->usri2_full_name);

    // NetUserGetInfo returns an empty string if the full name is not filled out
    if (fullName.Length() == 0) {
      NetApiBufferFree(info);
      return NS_ERROR_NOT_AVAILABLE;
    }

    *aFullname = ToNewUnicode(fullName);
    NetApiBufferFree(info);
  }

  return (*aFullname) ? NS_OK : NS_ERROR_FAILURE;
}
Exemplo n.º 3
0
NS_IMETHODIMP
nsUserInfo::GetEmailAddress(char **aEmailAddress)
{
  NS_ENSURE_ARG_POINTER(aEmailAddress);
  *aEmailAddress = nullptr;

  // RFC3696 says max length of an email address is 254
  PRUnichar emailAddress[255];
  DWORD size = mozilla::ArrayLength(emailAddress);

  if (!GetUserNameExW(NameUserPrincipal, emailAddress, &size)) {
    DWORD getUsernameError = GetLastError();
    return getUsernameError == ERROR_NONE_MAPPED ?
           NS_ERROR_NOT_AVAILABLE : NS_ERROR_FAILURE;
  }

  *aEmailAddress = ToNewUTF8String(nsDependentString(emailAddress));
  return (*aEmailAddress) ? NS_OK : NS_ERROR_FAILURE;
}
Exemplo n.º 4
0
String System::getEffectiveUserName()
{
#if (_MSC_VER >= 1300) || defined(PEGASUS_WINDOWS_SDK_HOME)

    //Bug 3076 fix
    wchar_t fullUserName[UNLEN+1];
    DWORD userNameSize = sizeof(fullUserName)/sizeof(fullUserName[0]);
    wchar_t computerName[MAX_COMPUTERNAME_LENGTH+1];
    DWORD computerNameSize = sizeof(computerName)/sizeof(computerName[0]);
    wchar_t userName[UNLEN+1];
    wchar_t userDomain[UNLEN+1];
    String userId;

    if (!GetUserNameExW(NameSamCompatible, fullUserName, &userNameSize))
    {
        return String();
    }

    wchar_t* index = wcschr(fullUserName, '\\');
    *index = 0;
    wcscpy(userDomain, fullUserName);
    wcscpy(userName, index + 1);

    //The above function will return the system name as the domain if
    //the user is not on a real domain.  Strip this out so that the rest of
    //our windows user functions work.  What if the system name and the domain
    //name are the same?
    GetComputerNameW(computerName, &computerNameSize);

    if (wcscmp(computerName, userDomain) != 0)
    {
        //userId.append(userDomain);
        Uint32 n = (Uint32)wcslen(userDomain);
        for (unsigned long i = 0; i < n; i++)
        {
            userId.append(Char16(userDomain[i]));
        }
        userId.append("\\");
        //userId.append(userName);
        n = (Uint32)wcslen(userName);
        for (unsigned long i = 0; i < n; i++)
        {
            userId.append(Char16(userName[i]));
        }

    }
    else
    {
        //userId.append(userName);
        Uint32 n = (Uint32)wcslen(userName);
        for (unsigned long i = 0; i < n; i++)
        {
            userId.append(Char16(userName[i]));
        }

    }

    return userId;

#else //original getEffectiveUserName function

    int retcode = 0;

    // UNLEN (256) is the limit, not including null
    wchar_t pUserName[256+1] = {0};
    DWORD nSize = sizeof(pUserName)/sizeof(pUserName[0]);

    retcode = GetUserNameW(pUserName, &nSize);
    if (retcode == 0)
    {
        // zero is failure
        return String();
    }
    String userId;
    Uint32 n = wcslen(pUserName);
    for (unsigned long i = 0; i < n; i++)
    {
        userId.append(Char16(pUserName[i]));
    }

    return userId;
#endif
}
Exemplo n.º 5
0
FskErr FskEnvironmentInitialize(void)
{
	char *appPath;

	gEnvironment = FskAssociativeArrayNew();

	appPath = FskGetApplicationPath();
	FskEnvironmentSet("applicationPath", appPath);
	FskMemPtrDispose(appPath);

#if TARGET_OS_KPL
	KplEnvironmentInitialize(gEnvironment);
#elif TARGET_OS_ANDROID
	FskEnvironmentSet("application", "PLAY");
#elif TARGET_OS_WIN32 || TARGET_OS_MAC || TARGET_OS_LINUX
	FskEnvironmentSet("application", FSK_APPLICATION);
#else
	FskEnvironmentSet("application", "PLAY");
#endif

#if TARGET_OS_WIN32
	{
	char name[256], *nameTemp = NULL;
	UInt16 nameW[256];
	char num[32];
	DWORD nameSize = sizeof(nameW) / sizeof(UInt16);
	EXTENDED_NAME_FORMAT exNameFormat = NameSamCompatible;

	if (GetUserNameExW(exNameFormat, (LPWSTR)nameW, &nameSize)) {
		FskTextUnicode16LEToUTF8(nameW, nameSize * 2, &nameTemp, NULL);
		FskStrCopy(name, nameTemp);
		FskEnvironmentSet("loginName", name);
		FskMemPtrDispose(nameTemp);
	}

	FskEnvironmentSet("OS", "Windows");
	FskStrNumToStr(gWindowsVersionInfo.dwMajorVersion, name, sizeof(name));
	FskStrCat(name, ".");
	FskStrNumToStr(gWindowsVersionInfo.dwMinorVersion, num, sizeof(num));
	FskStrCat(name, num);
	FskEnvironmentSet("OSVersion", name);
	}
#elif TARGET_OS_MAC
	{
		struct utsname un;
		char name[256], *model;
		SInt32 gen;
	#if TARGET_OS_IPHONE
		FskEnvironmentSet("OS", "iPhone");
	#else
		FskEnvironmentSet("OS", "Mac");
	#endif
		FskCocoaSystemGetVersion(name);
		FskEnvironmentSet("OSVersion", name);
		if (uname(&un) == 0) {
			model = un.machine;
			if (FskStrCompareWithLength(model, "iPhone", 6) == 0)
				gen = FskStrToNum(model + 6);
			else if (FskStrCompareWithLength(model, "iPad", 4) == 0) {
				gen = FskStrToNum(model + 4);
				if (gen == 3) {
					SInt32 minor = FskStrToNum(model + 6);
					if (minor == 4)	/* 4th gen */
						gen = 5;
					else
						gen = 4;	/* Only the 3rd gen iPad doesn't follow the numbering system */
				}
				else
					gen += 2;
			}
			else if (FskStrCompareWithLength(model, "iPod", 4) == 0) {
				gen = FskStrToNum(model + 4);
				if (gen > 1)
					--gen;
			}
			else
				gen = 99;
		}
		else {
			model = "unknown";
			gen = 99;
		}
		FskEnvironmentSet("Model", model);
		FskStrNumToStr(gen, name, sizeof(name));
		FskEnvironmentSet("Generation", name);
	}
		
#elif TARGET_OS_LINUX
	{
	struct utsname name;
	uname(&name);

	if (getlogin())
		FskEnvironmentSet("loginName", getlogin());
	else
		FskEnvironmentSet("loginName", "User");
	FskEnvironmentSet("OS", name.sysname);
	FskEnvironmentSet("OSVersion", name.release);		//@@
	}
#endif

	return kFskErrNone;
}