Ejemplo n.º 1
0
AuthResult AUTHCALL AuthEntry (const char *szCaller,
                               PAUTHUUID pUuid,
                               AuthGuestJudgement guestJudgement,
                               const char *szUser,
                               const char *szPassword,
                               const char *szDomain,
                               int fLogon,
                               unsigned clientId)
{
    if (!fLogon)
    {
        /* Nothing to cleanup. The return code does not matter. */
        return AuthResultAccessDenied;
    }

    LPWSTR lpwszUsername = utf8ToWideChar(szUser);
    LPWSTR lpwszDomain   = utf8ToWideChar(szDomain);
    LPWSTR lpwszPassword = utf8ToWideChar(szPassword);

    DBGAUTH((L"u[%ls], d[%ls], p[%ls]\n", lpwszUsername, lpwszDomain, lpwszPassword));

    AuthResult result = AuthResultAccessDenied;

    if (lpwszUsername && lpwszDomain && lpwszPassword)
    {
        /* LOGON32_LOGON_INTERACTIVE is intended for users who will be interactively using the computer,
         * such as a user being logged on by a terminal server, remote shell, or similar process.
         */
        DWORD dwLogonType     = LOGON32_LOGON_INTERACTIVE;
        DWORD dwLogonProvider = LOGON32_PROVIDER_DEFAULT;

        HANDLE hToken;

        BOOL fSuccess = LogonUserW(lpwszUsername,
                                   lpwszDomain,
                                   lpwszPassword,
                                   dwLogonType,
                                   dwLogonProvider,
                                   &hToken);

        if (fSuccess)
        {
            DBGAUTH((L"LogonUser success. hToken = %p\n", hToken));

            result = AuthResultAccessGranted;

            CloseHandle(hToken);
        }
        else
        {
            DBGAUTH((L"LogonUser failed %08X\n", GetLastError()));
        }
    }

    freeWideChar(lpwszUsername);
    freeWideChar(lpwszDomain);
    freeWideChar(lpwszPassword);

    return result;
}
Ejemplo n.º 2
0
bool AFileUnicode::Open(const char* szFullPath, ADWORD dwFlags)
{
	// If already opened, we must first close it!
	if( m_bHasOpened )
		Close();

	strncpy(m_szFileName, szFullPath, AMAX_PATH);
	// Get a relative path name of this file, may use a little time, but
	// this call is not too often, so this is not matter
	af_GetRelativePath(szFullPath, m_szRelativeName);

	// now this class can only support read music file
	if( 0 == (dwFlags & AFILE_OPENEXIST) )
		goto done;

    std::wstring s = utf8ToWideChar(szFullPath);

	m_hFile = CreateFileW(s.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if( INVALID_HANDLE_VALUE == m_hFile )
		goto done;
	
	m_dwTimeStamp = 0;
	m_bHasOpened = true;

done:

	return m_bHasOpened ;
}
Ejemplo n.º 3
0
bool AFileUnicode::IsFileUnicodeExist(const char * szFullPath)
{
	AHANDLE hFile = NULL;

    std::wstring s = utf8ToWideChar(szFullPath);

	hFile = CreateFileW(s.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if( INVALID_HANDLE_VALUE == hFile )
		return false;

	CloseHandle(hFile);
	return true;
}
Ejemplo n.º 4
0
std::wstring formatFileSize(a_uint64 size)
{
	char strBuffer[50];
	if (size >= 1024 * 1024 * 1024)
	{
		sprintf(strBuffer, "%.1f G", (double)size/(1024 * 1024 * 1024));
	}
	else if (size >= 1024 * 1024)
	{
		sprintf(strBuffer, "%.1f M", (double)size/(1024 * 1024));
	}
	else
	{
		sprintf(strBuffer, "%.1f K", (double)size/1024);
	}

	return utf8ToWideChar(strBuffer);
}