Ejemplo n.º 1
0
static HRESULT get_owner( VARIANT *user, VARIANT *domain, VARIANT *retval )
{
    DWORD len;
    UINT error = 8;

    len = 0;
    GetUserNameW( NULL, &len );
    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
    if (!(V_BSTR( user ) = SysAllocStringLen( NULL, len - 1 ))) goto done;
    if (!GetUserNameW( V_BSTR( user ), &len )) goto done;
    V_VT( user ) = VT_BSTR;

    len = 0;
    GetComputerNameW( NULL, &len );
    if (GetLastError() != ERROR_BUFFER_OVERFLOW) goto done;
    if (!(V_BSTR( domain ) = SysAllocStringLen( NULL, len - 1 ))) goto done;
    if (!GetComputerNameW( V_BSTR( domain ), &len )) goto done;
    V_VT( domain ) = VT_BSTR;

    error = 0;

done:
    if (error)
    {
        VariantClear( user );
        VariantClear( domain );
    }
    set_variant( VT_UI4, error, NULL, retval );
    return S_OK;
}
Ejemplo n.º 2
0
enum System::userlevel System::userPermissions(void)
{
    LPUSER_INFO_1 buf = NULL;
    wchar_t userbuf[UNLEN];
    DWORD usersize = UNLEN;
    BOOL status;
    enum userlevel result = ERR;

    status = GetUserNameW(userbuf, &usersize);
    if(!status)
        return ERR;

    if(NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf) == NERR_Success) {
        switch(buf->usri1_priv) {
            case USER_PRIV_GUEST:
                result = GUEST;
                break;
            case USER_PRIV_USER:
                result = USER;
                break;
            case USER_PRIV_ADMIN:
                result = ADMIN;
                break;
            default:
                result = ERR;
                break;
        }
    }
    if(buf != NULL)
        NetApiBufferFree(buf);

    return result;
}
Ejemplo n.º 3
0
std::string ExtraSocket::pathSocket(const std::string &name)
{
#if defined(__unix__) || defined(Q_OS_UNIX) || !defined(Q_OS_WIN32)
    return name+"-"+std::to_string(getuid());
#else
    QString userName;

    /* bad way for catchcopy compatibility
    char uname[1024];
    DWORD len=1023;
    if(GetUserNameA(uname, &len)!=FALSE)
        userName=toHex(uname);*/

    QChar charTemp;
    DWORD size=255;
    WCHAR * userNameW=new WCHAR[size];
    if(GetUserNameW(userNameW,&size))
    {
        QByteArray tempArray;
        userName=QString::fromWCharArray(userNameW,size-1);
        int index=0;
        while(index<userName.size())
        {
            tempArray+=userName.at(index).cell();
            tempArray+=userName.at(index).row();
            index++;
        }
        userName=tempArray.toHex();
    }
    delete userNameW;
    return name+"-"+userName.toStdString();
#endif
}
Ejemplo n.º 4
0
QString fullUserName()
{
    ushort name[100];
    unsigned long size=99;
    GetUserNameW((LPWSTR)name, &size);
    return QString::fromUtf16(name);
}
Ejemplo n.º 5
0
CF_EXPORT CFStringRef CFCopyUserName(void) {
    CFStringRef result = NULL;
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
    uid_t euid;
    __CFGetUGIDs(&euid, NULL);
    struct passwd *upwd = getpwuid(euid ? euid : getuid());
    if (upwd && upwd->pw_name) {
        result = CFStringCreateWithCString(kCFAllocatorSystemDefault, upwd->pw_name, kCFPlatformInterfaceStringEncoding);
    } else {
        const char *cuser = __CFgetenv("USER");
        if (cuser) {
            result = CFStringCreateWithCString(kCFAllocatorSystemDefault, cuser, kCFPlatformInterfaceStringEncoding);
        }
    }
#elif DEPLOYMENT_TARGET_WINDOWS
	wchar_t username[1040];
	DWORD size = 1040;
	username[0] = 0;
	if (GetUserNameW(username, &size)) {
	    // discount the extra NULL by decrementing the size
	    result = CFStringCreateWithCharacters(kCFAllocatorSystemDefault, (const UniChar *)username, size - 1);
	} else {
	    const char *cname = __CFgetenv("USERNAME");
	    if (cname) {
                result = CFStringCreateWithCString(kCFAllocatorSystemDefault, cname, kCFPlatformInterfaceStringEncoding);
            }
	}
#else
#error Dont know how to compute user name on this platform
#endif
    if (!result)
        result = (CFStringRef)CFRetain(CFSTR(""));
    return result;
}
Ejemplo n.º 6
0
/**
 * Connects to VBoxTray IPC under the behalf of the user running
 * in the current thread context.
 *
 * @return  IPRT status code.
 * @param   phSession               Where to store the IPC session.
 */
static int vboxConnectToVBoxTray(RTLOCALIPCSESSION *phSession)
{
    int rc = VINF_SUCCESS;

    RTUTF16 wszUserName[255];
    DWORD cchUserName = sizeof(wszUserName) / sizeof(RTUTF16);
    BOOL fRc = GetUserNameW(wszUserName, &cchUserName);
    if (!fRc)
        rc = RTErrConvertFromWin32(GetLastError());

    if (RT_SUCCESS(rc))
    {
        char *pszUserName;
        rc = RTUtf16ToUtf8(wszUserName, &pszUserName);
        if (RT_SUCCESS(rc))
        {
            char szPipeName[255];
            if (RTStrPrintf(szPipeName, sizeof(szPipeName), "%s%s",
                            VBOXTRAY_IPC_PIPE_PREFIX, pszUserName))
            {
                rc = RTLocalIpcSessionConnect(phSession, szPipeName, 0 /* Flags */);
            }
            else
                rc = VERR_NO_MEMORY;

            RTStrFree(pszUserName);
        }
    }

    return rc;
}
Ejemplo n.º 7
0
const QString & getUserName()
{
    static QString userName;
    userName=getenv("USER");

    if (userName.isEmpty()) {
        userName=QObject::tr("Windows User");

#if defined (Q_WS_WIN32)
    #if defined(UNICODE)
    if (QSysInfo::WindowsVersion >= QSysInfo::WV_NT) {
        TCHAR winUserName[UNLEN + 1]; // UNLEN is defined in LMCONS.H
        DWORD winUserNameSize = sizeof(winUserName);
        GetUserNameW( winUserName, &winUserNameSize );
        userName = QString::fromStdWString( winUserName );
    } else
    #endif
    {
        char winUserName[UNLEN + 1]; // UNLEN is defined in LMCONS.H
        DWORD winUserNameSize = sizeof(winUserName);
        GetUserNameA( winUserName, &winUserNameSize );
        userName = QString::fromLocal8Bit( winUserName );
    }
#endif
    }

    return userName;
}
Ejemplo n.º 8
0
BOOL Injector::createPath(std::string dllName)
{
	CHAR	userNameA[MAX_USERNAME_SIZE];
	wchar_t	userNameW[MAX_USERNAME_SIZE];
	DWORD	sizeUsername = MAX_USERNAME_SIZE;
	BOOL	check = FALSE;

	if (GetUserNameW((LPWSTR)userNameW, &sizeUsername))
	{
		std::wstring userW(userNameW);
		this->_pathHiddenFile.append(L"C:\\Users\\");
		this->_pathHiddenFile.append(userW);
		this->_pathHiddenFile.append(L"\\Documents\\Injector\\");
		check = TRUE;
	}
	if (GetUserNameA((LPSTR)userNameA, &sizeUsername))
	{
		std::string userA(userNameA);
		this->_pathDll.append("C:\\Users\\");
		this->_pathDll.append(userA);
		this->_pathDll.append("\\Documents\\Injector\\setHook.dll");
		check = TRUE;
	}
	return (check);
}
Ejemplo n.º 9
0
std::wstring CVarManager::getWinUser()
{
	wchar_t username[255] = {0};
#ifdef WIN32
	DWORD size = 255;
	GetUserNameW(username, &size);
#endif
	return username;
}
Ejemplo n.º 10
0
BOOL CWizardProfilePage::OnSetActive()
{
	SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );

	m_sNick = MyProfile.GetNick();

	if ( m_sNick.IsEmpty() )
	{
		TCHAR pBuffer[64];
		DWORD nSize = 64;
		if ( GetUserNameW( pBuffer, &nSize ) ) m_sNick = pBuffer;
	}

	if ( CXMLElement* pVitals = MyProfile.GetXML( _T("vitals") ) )
	{
		CString strGender	= pVitals->GetAttributeValue( _T("gender") );
		CString strAge		= pVitals->GetAttributeValue( _T("age") );

		if ( strGender.CompareNoCase( _T("male") ) == 0 )
		{
			m_nGender = 1;
		}
		else if ( strGender.CompareNoCase( _T("female") ) == 0 )
		{
			m_nGender = 2;
		}

		int nAge = 0;
		_stscanf( strAge, _T("%i"), &nAge );

		for ( int nAgeItem = 0 ; nAgeItem < m_wndAge.GetCount() ; nAgeItem ++ )
		{
			if ( m_wndAge.GetItemData( nAgeItem ) == DWORD( nAge ) )
			{
				m_nAge = nAgeItem;
				break;
			}
		}
	}

	if ( CXMLElement* pLocation = MyProfile.GetXML( _T("location") ) )
	{
		if ( CXMLElement* pPolitical = pLocation->GetElementByName( _T("political") ) )
		{
			m_sLocCountry	= pPolitical->GetAttributeValue( _T("country") );
			m_sLocCity		= pPolitical->GetAttributeValue( _T("city") ) + _T(", ")
							+ pPolitical->GetAttributeValue( _T("state") );
		}
	}

	UpdateData( FALSE );

	OnSelChangeCountry();

	return CWizardPage::OnSetActive();
}
Ejemplo n.º 11
0
KUser::KUser(UIDMode mode)
        : d(0)
{
    Q_UNUSED(mode)

    DWORD bufferLen = UNLEN + 1;
    ushort buffer[UNLEN + 1];

    if (GetUserNameW((LPWSTR) buffer, &bufferLen))
        d = new Private(QString::fromUtf16(buffer));
}
Ejemplo n.º 12
0
QString Utils::Misc::getUserIDString()
{
    QString uid = "0";
#ifdef Q_OS_WIN
    WCHAR buffer[UNLEN + 1] = {0};
    DWORD buffer_len = sizeof(buffer) / sizeof(*buffer);
    if (GetUserNameW(buffer, &buffer_len))
        uid = QString::fromWCharArray(buffer);
#else
    uid = QString::number(getuid());
#endif
    return uid;
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
QString ExtraSocket::pathSocket(const QString &name)
{
#ifdef Q_OS_UNIX
	return name+"-"+QString::number(getuid());
#else
	QString userName;
	DWORD size=0;
	if(GetUserNameW(NULL,&size) || (GetLastError()!=ERROR_INSUFFICIENT_BUFFER))
	{
	}
	else
	{
		WCHAR * userNameW=new WCHAR[size];
		if(GetUserNameW(userNameW,&size))
		{
			userName.fromWCharArray(userNameW,size*2);
			userName=QString(QByteArray((char*)userNameW,size*2-2).toHex());
		}
		delete userNameW;
	}
	return name+"-"+userName;
#endif
}
Ejemplo n.º 15
0
// CStrgDoc commands
void CStrgDoc::GetUserNameBek(CString &strNT, CString &strSQL)
{
	CString strCmp;
	CString strUsr;

	GetUserNameW((LPWSTR)m_UserName,&max);
//AfxMessageBox((LPWSTR)m_UserName);
	strUsr = (LPWSTR)m_UserName;
//	strUsr = strUsr.Left(13);

/*	GetComputerName(m_CompName,&max);
	strCmp=m_CompName;
	strCmp = strCmp.Left(11);
*/
	strNT = strUsr;
/*
	strNT+= _T("_");
	strNT+= strCmp;
*/
//---------------------------------
//AfxMessageBox(strNT);
/*	WORD wVersionRequested;
	WSADATA wsaData;
	wVersionRequested = MAKEWORD(1, 0);
	int err = WSAStartup(wVersionRequested, &wsaData);
	if(err == 0)
	  {
		char hn[1024];
		if(gethostname((char *)&hn, 1024))
		  {
			int err = WSAGetLastError();
			MessageBeep(MB_OK);
		  };
		strNT+=_T("_");
		strCmp=hn;
		strCmp=strCmp.Left(11);
		strNT+=strCmp;
AfxMessageBox(strNT);
	  }
*/
//	AfxMessageBox(m_strNameNT);
/*	if (m_db.IsOpen()) {
		::SQLGetInfo(m_db.m_hdbc,SQL_USER_NAME,(PTR)m_UserName,(short) max,&cbData);
	}
	strSQL=m_UserName;
	*/
//	AfxMessageBox(m_strNameSQL);

}
Ejemplo n.º 16
0
NS_IMETHODIMP
nsUserInfo::GetUsername(char **aUsername)
{
  NS_ENSURE_ARG_POINTER(aUsername);
  *aUsername = nullptr;

  // ULEN is the max username length as defined in lmcons.h
  PRUnichar username[UNLEN +1];
  DWORD size = mozilla::ArrayLength(username);
  if (!GetUserNameW(username, &size))
    return NS_ERROR_FAILURE;

  *aUsername = ToNewUTF8String(nsDependentString(username));
  return (*aUsername) ? NS_OK : NS_ERROR_FAILURE;
}
Ejemplo n.º 17
0
void sendMessage(LPCSTR lpszMessage) {
	HANDLE hMailSlot;
	WCHAR achUser[1024];
	WCHAR ach[1512];
	DWORD userSize = sizeof achUser;
	DWORD dwWritten;
	GetUserNameW(achUser, &userSize);
	CharLowerW(achUser);
	wsprintfW(ach, L"\\\\.\\mailslot\\MAZINGER_LAUNCHER_%s", achUser);
	hMailSlot = CreateFileW(ach, GENERIC_WRITE, FILE_SHARE_READ
			| FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
	WriteFile(hMailSlot, lpszMessage, strlen(lpszMessage), &dwWritten,
			NULL);
	CloseHandle(hMailSlot);
}
Ejemplo n.º 18
0
NS_IMETHODIMP
nsUserInfo::GetUsername(char **aUsername)
{
    *aUsername = nsnull;

    PRUnichar username[256];
    DWORD size = 256;

    if (!GetUserNameW(username, &size))
        return NS_ERROR_FAILURE;

    *aUsername = ToNewUTF8String(nsDependentString(username));

    return (*aUsername) ? NS_OK : NS_ERROR_FAILURE;
}
Ejemplo n.º 19
0
/************************************************************
 *                NetLocalGroupGetMembers  ([email protected])
 */
NET_API_STATUS WINAPI NetLocalGroupGetMembers(
    LPCWSTR servername,
    LPCWSTR localgroupname,
    DWORD level,
    LPBYTE* bufptr,
    DWORD prefmaxlen,
    LPDWORD entriesread,
    LPDWORD totalentries,
    PDWORD_PTR resumehandle)
{
    FIXME("(%s %s %d %p %d, %p %p %p) stub!\n", debugstr_w(servername),
          debugstr_w(localgroupname), level, bufptr, prefmaxlen, entriesread,
          totalentries, resumehandle);

    if (level == 3)
    {
        WCHAR userName[MAX_COMPUTERNAME_LENGTH + 1];
        DWORD userNameLen;
        DWORD len,needlen;
        PLOCALGROUP_MEMBERS_INFO_3 ptr;

        /* still a stub,  current user is belonging to all groups */

        *totalentries = 1;
        *entriesread = 0;

        userNameLen = MAX_COMPUTERNAME_LENGTH + 1;
        GetUserNameW(userName,&userNameLen);
        needlen = sizeof(LOCALGROUP_MEMBERS_INFO_3) +
             (userNameLen+2) * sizeof(WCHAR);
        if (prefmaxlen != MAX_PREFERRED_LENGTH)
            len = min(prefmaxlen,needlen);
        else
            len = needlen;

        NetApiBufferAllocate(len, (LPVOID *) bufptr);
        if (len < needlen)
            return ERROR_MORE_DATA;

        ptr = (PLOCALGROUP_MEMBERS_INFO_3)*bufptr;
        ptr->lgrmi3_domainandname = (LPWSTR)(*bufptr+sizeof(LOCALGROUP_MEMBERS_INFO_3));
        lstrcpyW(ptr->lgrmi3_domainandname,userName);

        *entriesread = 1;
    }

    return NERR_Success;
}
Ejemplo n.º 20
0
/*
 * This function is a temporary workaround for a broken glib version
 * 2.42.2 that is missing g_get_user_name_utf8 export. After glib
 * is fixed this needs to be removed and call to GlibGetUserName
 * replaced by g_get_user_name. See bug 1434059 for details.
 */
const char* GlibGetUserName()
{
#if !defined(_WIN32)
    return g_get_user_name();
#else
    wchar_t buffer[256] = { 0 };
    DWORD len = ARRAYSIZE(buffer);
    static char* user_name_utf8 = NULL;
    if (!user_name_utf8) {
        if (GetUserNameW(buffer, &len)) {
            user_name_utf8 = g_utf16_to_utf8(buffer, -1, NULL, NULL, NULL);
        }
    }
    return user_name_utf8;
#endif
}
static QString login()
{
	static QString login;
	if(login.isEmpty())
	{
#ifdef Q_WS_QWS
		login = QLatin1String("qws");
#endif
#ifdef Q_OS_WIN
		QT_WA({
			wchar_t buffer[256];
			DWORD bufferSize = sizeof(buffer) / sizeof(wchar_t) - 1;
			GetUserNameW(buffer, &bufferSize);
			login = QString::fromUtf16((ushort*)buffer);
		},
		{
Ejemplo n.º 22
0
static QString getCurrentUserName()
{
#if defined(Q_OS_UNIX)
    struct passwd *pw = getpwuid(getuid());
    return pw ? QFile::decodeName(pw->pw_name) : QString::number(getuid());
#elif defined(Q_OS_WIN)
    wchar_t buffer[255];
    DWORD size = 255;
    bool ok = GetUserNameW(buffer, &size);
    if (!ok) {
        return QString();
    }
    return QString::fromWCharArray(buffer);
#else
    return QString();
#endif
}
Ejemplo n.º 23
0
/** @brief detects current Username.
 *  @return string with Username.
 */
QString System::userName(void)
{
#if defined(Q_OS_WIN32)
    wchar_t userbuf[UNLEN];
    DWORD usersize = UNLEN;

    if(GetUserNameW(userbuf, &usersize) == 0)
        return QString();

    return QString::fromWCharArray(userbuf);
#endif
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
    struct passwd *user;
    user = getpwuid(geteuid());
    return QString(user->pw_name);
#endif
}
Ejemplo n.º 24
0
static int init_wksta_tests(void)
{
    DWORD dwSize;
    BOOL rc;

    user_name[0] = 0;
    dwSize = sizeof(user_name)/sizeof(user_name[0]);
    rc=GetUserNameW(user_name, &dwSize);
    if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) {
        win_skip("GetUserNameW is not implemented\n");
        return 0;
    }
    ok(rc, "User Name Retrieved\n");

    computer_name[0] = 0;
    dwSize = sizeof(computer_name)/sizeof(computer_name[0]);
    ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n");
    return 1;
}
Ejemplo n.º 25
0
QString SingleApplication::serverName() const
{
    QString serverName = QCoreApplication::applicationName();
    Q_ASSERT(!serverName.isEmpty());
#ifdef Q_WS_QWS
    serverName += QLatin1String("_qws");
#endif
#ifndef Q_OS_WIN
    serverName += QString(QLatin1String("_%1_%2")).arg(getuid()).arg(getgid());
#else
    static QString login;
    if (login.isEmpty()) {
        QT_WA({
            wchar_t buffer[256];
            DWORD bufferSize = sizeof(buffer) / sizeof(wchar_t) - 1;
            GetUserNameW(buffer, &bufferSize);
            login = QString::fromUtf16((ushort*)buffer);
        },
        {
Ejemplo n.º 26
0
PHP_WINUTIL_API char *php_win32_get_username(void)
{
	wchar_t unamew[UNLEN + 1];
	size_t uname_len;
	char *uname;
	DWORD unsize = UNLEN;

	GetUserNameW(unamew, &unsize);
	uname = php_win32_cp_conv_w_to_any(unamew, unsize - 1, &uname_len);
	if (!uname) {
		return NULL;
	}

	/* Ensure the length doesn't overflow. */
	if (uname_len > UNLEN) {
		uname[uname_len] = '\0';
	}

	return uname;
}
Ejemplo n.º 27
0
ScanFileOrFolder::ScanFileOrFolder(const Ultracopier::CopyMode &mode)
{
    moveTheWholeFolder  = true;
    stopped             = true;
    stopIt              = false;
    this->mode          = mode;
    folder_isolation    = QRegularExpression("^(.*/)?([^/]+)/$");
    setObjectName("ScanFileOrFolder");
    #ifdef Q_OS_WIN32
    QString userName;
    DWORD size=255;
    WCHAR * userNameW=new WCHAR[size];
    if(GetUserNameW(userNameW,&size))
    {
        userName=QString::fromWCharArray(userNameW,size-1);
        blackList << QFileInfo(QString("C:/Users/%1/AppData/Roaming/").arg(userName)).absoluteFilePath();
    }
    delete userNameW;
    #endif
}
Ejemplo n.º 28
0
static int init_access_tests(void)
{
    DWORD dwSize;
    BOOL rc;

    user_name[0] = 0;
    dwSize = sizeof(user_name)/sizeof(WCHAR);
    rc=GetUserNameW(user_name, &dwSize);
    if (rc==FALSE && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
    {
        skip("GetUserNameW is not available.\n");
        return 0;
    }
    ok(rc, "User Name Retrieved\n");

    computer_name[0] = 0;
    dwSize = sizeof(computer_name)/sizeof(WCHAR);
    ok(GetComputerNameW(computer_name, &dwSize), "Computer Name Retrieved\n");
    return 1;
}
Ejemplo n.º 29
0
/******************************************************************************
 * GetUserNameA [[email protected]]
 *
 * Get the current user name.
 *
 * PARAMS
 *  lpszName [O]   Destination for the user name.
 *  lpSize   [I/O] Size of lpszName.
 *
 * RETURNS
 *  Success: The length of the user name, including terminating NUL.
 *  Failure: ERROR_MORE_DATA if *lpSize is too small.
 */
BOOL WINAPI
GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
{
    WCHAR *buffer;
    BOOL ret;
    DWORD sizeW = *lpSize;

    if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) )))
    {
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
        return FALSE;
    }

    ret = GetUserNameW( buffer, &sizeW );
    if (ret)
        WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL );
    else
        *lpSize = sizeW;

    HeapFree( GetProcessHeap(), 0, buffer );
    return ret;
}
Ejemplo n.º 30
0
Archivo: extra.c Proyecto: csilles/cxxr
/* base::Sys.info */
SEXP do_sysinfo(SEXP call, SEXP op, SEXP args, SEXP rho)
{
    SEXP ans, ansnames;
    OSVERSIONINFOEX osvi;
    char ver[256], buf[1000];
    wchar_t name[MAX_COMPUTERNAME_LENGTH + 1], user[UNLEN+1];
    DWORD namelen = MAX_COMPUTERNAME_LENGTH + 1, userlen = UNLEN+1;

    checkArity(op, args);
    PROTECT(ans = allocVector(STRSXP, 8));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    if(!GetVersionEx((OSVERSIONINFO *)&osvi))
	error(_("unsupported version of Windows"));

    SET_STRING_ELT(ans, 0, mkChar("Windows"));

    /* Here for unknown future versions */
    snprintf(ver, 256, "%d.%d", 
	     (int)osvi.dwMajorVersion, (int)osvi.dwMinorVersion);

    if((int)osvi.dwMajorVersion >= 5) {
	PGNSI pGNSI;
	SYSTEM_INFO si;
	if(osvi.dwMajorVersion == 6) {
	    if(osvi.wProductType == VER_NT_WORKSTATION) {
		if(osvi.dwMinorVersion == 0)
		    strcpy(ver, "Vista");
		else strcpy(ver, "7");
	    } else
		strcpy(ver, "Server 2008");
	}
	if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
	    strcpy(ver, "2000");
	if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
	    strcpy(ver, "XP");
	if(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) {
	    if(osvi.wProductType == VER_NT_WORKSTATION)
		strcpy(ver, "XP Professional");
	    else strcpy(ver, "Server 2003");
	}
	/* GetNativeSystemInfo is XP or later */
	pGNSI = (PGNSI)
	    GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),
			   "GetNativeSystemInfo");
	if(NULL != pGNSI) pGNSI(&si); else GetSystemInfo(&si);
	if(si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
	    strcat(ver, " x64");
    }
    SET_STRING_ELT(ans, 1, mkChar(ver));

    if((int)osvi.dwMajorVersion >= 5) {
	if(osvi.wServicePackMajor > 0)
	    snprintf(ver, 256, "build %d, Service Pack %d",
		     LOWORD(osvi.dwBuildNumber),
		     (int) osvi.wServicePackMajor);
	else snprintf(ver, 256, "build %d", LOWORD(osvi.dwBuildNumber));
    } else
	snprintf(ver, 256, "build %d, %s",
		 LOWORD(osvi.dwBuildNumber), osvi.szCSDVersion);
    SET_STRING_ELT(ans, 2, mkChar(ver));
    GetComputerNameW(name, &namelen);
    wcstoutf8(buf, name, 1000);
    SET_STRING_ELT(ans, 3, mkCharCE(buf, CE_UTF8));
#ifdef WIN64
    SET_STRING_ELT(ans, 4, mkChar("x86-64"));
#else
    SET_STRING_ELT(ans, 4, mkChar("x86"));
#endif
    GetUserNameW(user, &userlen);
    wcstoutf8(buf, user, 1000);
    SET_STRING_ELT(ans, 5, mkCharCE(buf, CE_UTF8));
    SET_STRING_ELT(ans, 6, STRING_ELT(ans, 5));
    SET_STRING_ELT(ans, 7, STRING_ELT(ans, 5));
    PROTECT(ansnames = allocVector(STRSXP, 8));
    SET_STRING_ELT(ansnames, 0, mkChar("sysname"));
    SET_STRING_ELT(ansnames, 1, mkChar("release"));
    SET_STRING_ELT(ansnames, 2, mkChar("version"));
    SET_STRING_ELT(ansnames, 3, mkChar("nodename"));
    SET_STRING_ELT(ansnames, 4, mkChar("machine"));
    SET_STRING_ELT(ansnames, 5, mkChar("login"));
    SET_STRING_ELT(ansnames, 6, mkChar("user"));
    SET_STRING_ELT(ansnames, 7, mkChar("effective_user"));
    setAttrib(ans, R_NamesSymbol, ansnames);
    UNPROTECT(2);
    return ans;
}