• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ LookupAccountSid函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中LookupAccountSid函数的典型用法代码示例。如果您正苦于以下问题:C++ LookupAccountSid函数的具体用法?C++ LookupAccountSid怎么用?C++ LookupAccountSid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了LookupAccountSid函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: PORT_ACCESS_FROM_ENV

BOOLEAN GetInfo
(JNIEnv * jenv, PSID sid, LPSTR* ppName, LPSTR* ppDomain) 
{
	PORT_ACCESS_FROM_ENV (jenv);

	DWORD dwNameSize = 0;
	DWORD dwDomainNameSize = 0;
	SID_NAME_USE snu;
	if( !LookupAccountSid(NULL, sid, NULL, &dwNameSize, NULL, &dwDomainNameSize, &snu)) {
		if( ERROR_INSUFFICIENT_BUFFER != GetLastError() ) {
			return FALSE;
		}
	}
	*ppName = (LPSTR)hymem_allocate_memory(dwNameSize);
	if( NULL == ppName ) {
		return FALSE;
	}
	*ppDomain = (LPSTR)hymem_allocate_memory(dwDomainNameSize);
	if( NULL == ppName ) {
		DWORD err = GetLastError();
		hymem_free_memory(*ppName);
		SetLastError(err);
		return FALSE;
	}
	if( !LookupAccountSid(NULL, sid, *ppName, &dwNameSize, *ppDomain, &dwDomainNameSize, &snu)) {
		DWORD err = GetLastError();
		hymem_free_memory(*ppName);
		hymem_free_memory(*ppDomain);
		SetLastError(err);
		return FALSE;
	}

	return TRUE;
}
开发者ID:chengkaizone,项目名称:cn1,代码行数:34,代码来源:authwin32.c


示例2: userSID

	std::wstring userSID() const {
		if (pevlr_->UserSidOffset == 0)
			return L" ";
		PSID p = NULL; // = reinterpret_cast<const void*>(reinterpret_cast<const BYTE*>(pevlr_) + + pevlr_->UserSidOffset);
		DWORD userLen = 0;
		DWORD domainLen = 0;
		SID_NAME_USE sidName;

		LookupAccountSid(NULL, p, NULL, &userLen, NULL, &domainLen, &sidName);
		LPTSTR user = new TCHAR[userLen + 10];
		LPTSTR domain = new TCHAR[domainLen + 10];

		LookupAccountSid(NULL, p, user, &userLen, domain, &domainLen, &sidName);
		user[userLen] = 0;
		domain[domainLen] = 0;
		std::wstring ustr = user;
		std::wstring dstr = domain;
		delete[] user;
		delete[] domain;
		if (!dstr.empty())
			dstr = dstr + L"\\";
		if (ustr.empty() && dstr.empty())
			return L"missing";

		return dstr + ustr;
	}
开发者ID:mickem,项目名称:nscp,代码行数:26,代码来源:eventlog_record.hpp


示例3: get_account_sid

int get_account_sid(PSID pSid,char * account,size_t acclen,
		    SID_NAME_USE * peUse)
{
  DWORD dwAccountLen = 0;
  DWORD dwDomainLen = 0;
  char * szAccountName = NULL;
  char * szDomainName = NULL;
  DWORD dwRetLen = 0;
  

  LookupAccountSid(NULL,pSid,
		   szAccountName,&dwAccountLen,
		   szDomainName,&dwDomainLen,
		   peUse);


  szAccountName = (char *) malloc(dwAccountLen);

  if (szAccountName == NULL){
    SetLastError(ERROR_OUTOFMEMORY);
    return (-1);
  }

  szDomainName = (char *) malloc(dwDomainLen);

  if (szDomainName == NULL){
    free(szAccountName);
    SetLastError(ERROR_OUTOFMEMORY);
    return (-1);
  }

  if (0 == LookupAccountSid(NULL,pSid,
			    szAccountName,&dwAccountLen,
			    szDomainName,&dwDomainLen,
			    peUse)){
    if (GetLastError() == ERROR_NONE_MAPPED){
      get_textual_sid(pSid,account,acclen);
      goto free_mem;
    }
    free(szAccountName);
    free(szDomainName);
    return (-1);
  }



  if (dwDomainLen <= 1)
    _snprintf(account,acclen,"%s",szAccountName);
  else
    _snprintf(account,acclen,"%s\\%s",szDomainName,szAccountName);
  
  
 free_mem:
  free(szAccountName);
  free(szDomainName);

  return (0);
}
开发者ID:zaharovmag,项目名称:win-util,代码行数:58,代码来源:win.c


示例4: PrintUserName

static void PrintUserName(PDOKAN_FILE_INFO DokanFileInfo) {
  HANDLE handle;
  UCHAR buffer[1024];
  DWORD returnLength;
  WCHAR accountName[256];
  WCHAR domainName[256];
  DWORD accountLength = sizeof(accountName) / sizeof(WCHAR);
  DWORD domainLength = sizeof(domainName) / sizeof(WCHAR);
  PTOKEN_USER tokenUser;
  SID_NAME_USE snu;

  handle = DokanOpenRequestorToken(DokanFileInfo);
  if (handle == INVALID_HANDLE_VALUE) {
    DbgPrint(L"  DokanOpenRequestorToken failed\n");
    return;
  }

  if (!GetTokenInformation(handle, TokenUser, buffer, sizeof(buffer),
                           &returnLength)) {
    DbgPrint(L"  GetTokenInformaiton failed: %d\n", GetLastError());
    CloseHandle(handle);
    return;
  }

  CloseHandle(handle);

  tokenUser = (PTOKEN_USER)buffer;
  if (!LookupAccountSid(NULL, tokenUser->User.Sid, accountName, &accountLength,
                        domainName, &domainLength, &snu)) {
    DbgPrint(L"  LookupAccountSid failed: %d\n", GetLastError());
    return;
  }

  DbgPrint(L"  AccountName: %s, DomainName: %s\n", accountName, domainName);
}
开发者ID:cnhup,项目名称:dokany,代码行数:35,代码来源:mirror.c


示例5: GetProcessToken

HRESULT GetProcessToken(DWORD dwProcessID, LPHANDLE token, DWORD nUserNameMax, LPWSTR szwUserName, DWORD nUserDomainMax, LPWSTR szwUserDomain) {
	HANDLE hProcess=OpenProcess(PROCESS_DUP_HANDLE|PROCESS_QUERY_INFORMATION,TRUE,dwProcessID); 
	if (!hProcess) throw std::runtime_error("OpenProcess failed");
	HRESULT retval = S_OK;
	HANDLE hToken = INVALID_HANDLE_VALUE;
	if (!OpenProcessToken(hProcess, TOKEN_DUPLICATE | TOKEN_QUERY, &hToken)) retval = HRESULT_FROM_WIN32(GetLastError());
	else {
		BYTE buf[MAX_PATH]; DWORD dwRead = 0;
		if (!GetTokenInformation(hToken, TokenUser, buf, MAX_PATH, &dwRead)) retval = HRESULT_FROM_WIN32(GetLastError());
		else {
			TOKEN_USER *puser = reinterpret_cast<TOKEN_USER*>(buf);
			SID_NAME_USE eUse;
			if (!LookupAccountSid(NULL, puser->User.Sid, szwUserName, &nUserNameMax, szwUserDomain, &nUserDomainMax, &eUse))
				retval = HRESULT_FROM_WIN32(GetLastError());
			}
		if (FAILED(retval)) return retval;
		if (!DuplicateTokenEx(hToken, 
			TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE, 
			NULL, SecurityImpersonation, TokenPrimary,token))
			retval = HRESULT_FROM_WIN32(GetLastError());
		else  retval = S_OK;
		CloseHandle(hToken);
		}
	return retval;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:25,代码来源:ProcessStarter_win.cpp


示例6: GetFileOwner

int GetFileOwner (const char *Computer, const char *Name, char *Owner)
{
    SECURITY_INFORMATION si = OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION;
    SECURITY_DESCRIPTOR *sd;
    char sddata[500];
    *Owner=0;
    sd=(SECURITY_DESCRIPTOR *)sddata;

    char AnsiName[NM];
    OemToChar(Name,AnsiName);
    SetFileApisToANSI();
    DWORD Needed;
    int GetCode=GetFileSecurity(AnsiName,si,sd,sizeof(sddata),&Needed);
    SetFileApisToOEM();

    if (!GetCode || (Needed>sizeof(sddata)))
        return(FALSE);
    PSID pOwner;
    BOOL OwnerDefaulted;
    if (!GetSecurityDescriptorOwner(sd,&pOwner,&OwnerDefaulted))
        return(FALSE);
    char AccountName[200],DomainName[200];
    DWORD AccountLength=sizeof(AccountName),DomainLength=sizeof(DomainName);
    SID_NAME_USE snu;
    if (!LookupAccountSid(Computer,pOwner,AccountName,&AccountLength,DomainName,&DomainLength,&snu))
        return(FALSE);
    CharToOem(AccountName,Owner);
    return(TRUE);
}
开发者ID:BackupTheBerlios,项目名称:far-unlimited-svn,代码行数:29,代码来源:FAR_SF.cpp


示例7: FormatUserName

BOOL FormatUserName(PSID sid, TCHAR *userName, size_t cchMax)
{
    BOOL success = FALSE;

    TCHAR accountName[512];
    DWORD accountNameLength = SIZEOF_ARRAY(accountName);
    TCHAR domainName[512];
    DWORD domainNameLength = SIZEOF_ARRAY(domainName);
    SID_NAME_USE eUse;
    BOOL bRet = LookupAccountSid(NULL, sid, accountName, &accountNameLength,
                                 domainName, &domainNameLength, &eUse);

    if(bRet)
    {
        StringCchPrintf(userName, cchMax, _T("%s\\%s"), domainName, accountName);
        success = TRUE;
    }
    else
    {
        LPTSTR stringSid;
        bRet = ConvertSidToStringSid(sid, &stringSid);

        if(bRet)
        {
            StringCchCopy(userName, cchMax, stringSid);

            LocalFree(stringSid);
            success = TRUE;
        }
    }

    return success;
}
开发者ID:RenniePet,项目名称:explorerplusplus,代码行数:33,代码来源:Helper.cpp


示例8: _tcscpy

CToolDumper::CSelectProcessDialog::CListElement::CListElement(PROCESSENTRY32* pProcess)
{
	//запомнить информацию
	mProcessID=pProcess->th32ProcessID;
	mParentProcessID=pProcess->th32ParentProcessID;
	_tcscpy(mszBaseName,pProcess->szExeFile);

	//получить дополнительную информацию
	HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,mProcessID);
	//флаг успеха получения информации об учётной записи
	BOOL AccountResulted=FALSE;
	if(hProcess)
	{
		//получить полное имя файла процесса
		GetProcessImageFileName(hProcess,mszFullName,(MAX_PATH-1)*sizeof(TCHAR));
		mszFullName[MAX_PATH-1]=0;

		//получить информацию об использовании памяти процессом
		mMemoryInfoExist=GetProcessMemoryInfo(hProcess,&mMemoryInfo,sizeof(mMemoryInfo));

		//получить маркер защиты процесса
		HANDLE hProcessToken;
		if(OpenProcessToken(hProcess,TOKEN_QUERY,&hProcessToken))
		{
			//получить информацию о пользователе
			DWORD NeededSize;
			if(!GetTokenInformation(hProcessToken,TokenUser,NULL,0,&NeededSize))
			{
				TOKEN_USER* pUserInfo=(TOKEN_USER*)new BYTE[NeededSize];
				if(GetTokenInformation(hProcessToken,TokenUser,pUserInfo,NeededSize,&NeededSize))
				{
					//получить имя учётной записи, под которой работает процесс
					DWORD AccountNameLength=MAX_PATH;
					DWORD AccountDomainNameLength=MAX_PATH;
					SID_NAME_USE AccountUse;
					if(LookupAccountSid(NULL,pUserInfo->User.Sid,mszAccountName,&AccountNameLength,mszAccountDomainName,&AccountDomainNameLength,&AccountUse))
						//установить флаг результата
						AccountResulted=TRUE;
				}
				delete [] (BYTE*)pUserInfo;
			}

			CloseHandle(hProcessToken);
		}

		//закрыть описатель процесса
		CloseHandle(hProcess);
	}
	else
	{
		mszFullName[0]=0;
		mMemoryInfoExist=FALSE;
	}
	//если неудача с получением имени учётной записи, очистить строки
	if(!AccountResulted)
	{
		mszAccountName[0]=0;
		mszAccountDomainName[0]=0;
	}
}
开发者ID:revel8n,项目名称:code0,代码行数:60,代码来源:tool_dumper.cpp


示例9: hToken

void Helpers::GetCurrentUserAndDomain(std::wstring& strUser, std::wstring& strDomain)
{
	std::unique_ptr<void, CloseHandleHelper> hToken(nullptr);

	{
		HANDLE _hToken = nullptr;

		if ( !::OpenProcessToken(
			::GetCurrentProcess(),
			TOKEN_QUERY,
			&_hToken) )
		{
			Win32Exception::ThrowFromLastError("OpenProcessToken");
		}

		hToken.reset(_hToken);
	}

	DWORD dwReturnLength = 0;

	if ( !::GetTokenInformation(
		hToken.get(),
		TokenUser,
		nullptr,
		0,
		&dwReturnLength ) )
	{
		if( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
			Win32Exception::ThrowFromLastError("GetTokenInformation");
	}

	std::unique_ptr<BYTE[]> tu(new BYTE[dwReturnLength]);

	if ( !::GetTokenInformation(
		hToken.get(),
		TokenUser,
		tu.get(),
		dwReturnLength,
		&dwReturnLength ) )
	{
			Win32Exception::ThrowFromLastError("GetTokenInformation");
	}

	wchar_t szUser[CRED_MAX_STRING_LENGTH + 1] = L"";
	wchar_t szDomain[CRED_MAX_STRING_LENGTH + 1] = L"";
	DWORD dwUserLen = static_cast<DWORD>(ARRAYSIZE(szUser));
	DWORD dwDomainLen = static_cast<DWORD>(ARRAYSIZE(szDomain));
	SID_NAME_USE snu;

	// Retrieve user name and domain name based on user's SID.
	if( !LookupAccountSid(NULL, reinterpret_cast<TOKEN_USER*>(tu.get())->User.Sid, szUser, &dwUserLen, szDomain, &dwDomainLen, &snu) )
	{
		Win32Exception::ThrowFromLastError("LookupAccountSid");
	}

	strUser = szUser;
	strDomain = szDomain;
}
开发者ID:MussaratAziz,项目名称:console,代码行数:58,代码来源:Helpers.cpp


示例10: CloseHandle

CString CAppBarManager::GetCurrentUserName(LPTSTR lpstrAppName)
{   
	HANDLE hToken;   

	// 得到shell的token   
	if(!GetTokenByName(hToken, lpstrAppName))   
	{   
		return FALSE;   
	}   
	DWORD cbti = 0;   
	PTOKEN_USER ptiUser = NULL;   
	SID_NAME_USE snu;   

	// 取得所需空间大小   
	if (GetTokenInformation(hToken, TokenUser, NULL, 0, &cbti))     
	{   
		CloseHandle(hToken);   
		return FALSE;   
	}   

	// 分配空间   
	ptiUser = (PTOKEN_USER) HeapAlloc(GetProcessHeap(), 0, cbti);   
	if(!ptiUser)   
	{   
		CloseHandle(hToken);   
		return FALSE;   
	}   

	// 取得token信息   
	if (!GetTokenInformation(hToken, TokenUser, ptiUser, cbti, &cbti))   
	{   
		CloseHandle(hToken);   
		HeapFree(GetProcessHeap(), 0, ptiUser);   
		return FALSE;   
	}   

	TCHAR szUser[MAX_PATH];   
	TCHAR szDomain[MAX_PATH];   
	DWORD nUser = MAX_PATH;   
	DWORD nDomain = MAX_PATH;   

	// 根据用户的sid得到用户名和domain   
	if (!LookupAccountSid(NULL, ptiUser->User.Sid, szUser, &nUser,     
		szDomain, &nDomain, &snu))   
	{   
		CloseHandle(hToken);   
		HeapFree(GetProcessHeap(), 0, ptiUser);   
		return FALSE;   
	}   

	CloseHandle(hToken);   
	HeapFree(GetProcessHeap(), 0, ptiUser);

	CString strUserName(szUser);

	return strUserName;
}   
开发者ID:harrysun2006,项目名称:ag_Client,代码行数:57,代码来源:AppBarManager.cpp


示例11: OpenProcess

bool Win32::ProcessInfo::GetUserAndDomainName(CString& cszUsername, CString& cszRefDomainName)
{
   HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, m_dwProcessId);
   if (hProcess == NULL)
      return false;

   bool bRet = false;
   HANDLE hProcessToken = NULL;
   if (TRUE == OpenProcessToken(hProcess, TOKEN_QUERY, &hProcessToken))
   {
      // get length
      DWORD nLength = 0;
      GetTokenInformation(hProcessToken, TokenUser, NULL, 0, &nLength);

      std::vector<BYTE> vecData(nLength);
      TOKEN_USER* pTokenUser = (TOKEN_USER*)&vecData[0];

      if (TRUE == GetTokenInformation(hProcessToken, TokenUser, pTokenUser, nLength, &nLength))
      {
         DWORD cchName = 0, cchReferencedDomainName = 0;
         LookupAccountSid(NULL, pTokenUser->User.Sid, NULL, &cchName, NULL, &cchReferencedDomainName, NULL);

         // for some unknown reason the direct use of the output parameters don't work, so use
         // local objects here and assign later
         CString cszUsernameL, cszRefDomainNameL;
         SID_NAME_USE eUse;
         LookupAccountSid(NULL, pTokenUser->User.Sid,
            cszUsernameL.GetBuffer(cchName), &cchName,
            cszRefDomainNameL.GetBuffer(cchReferencedDomainName), &cchReferencedDomainName,
            &eUse);

         cszUsernameL.ReleaseBuffer();
         cszRefDomainNameL.ReleaseBuffer();

         cszUsername = cszUsernameL;
         cszRefDomainName = cszRefDomainNameL;
         bRet = true;
      }

      CloseHandle(hProcessToken);
   }

   return bRet;
}
开发者ID:vividos,项目名称:OldStuff,代码行数:44,代码来源:ProcessInfo.cpp


示例12: GetSidName

/* ask a server to translate a SID into a textual representation */
static gunichar2*
GetSidName (gunichar2 *server, PSID sid, gint32 *size)
{
    gunichar2 *uniname = NULL;
    DWORD cchName = 0;
    DWORD cchDomain = 0;
    SID_NAME_USE peUse; /* out */

    LookupAccountSid (server, sid, NULL, &cchName, NULL,
                      &cchDomain, &peUse);

    if ((cchName > 0) && (cchDomain > 0)) {
        gunichar2 *user = g_malloc0 ((cchName + 1) * 2);
        gunichar2 *domain = g_malloc0 ((cchDomain + 1) * 2);

        LookupAccountSid (server, sid, user, &cchName, domain,
                          &cchDomain, &peUse);

        if (cchName > 0) {
            if (cchDomain > 0) {
                /* domain/machine name included (+ sepearator) */
                *size = cchName + cchDomain + 1;
                uniname = g_malloc0 ((*size + 1) * 2);
                memcpy (uniname, domain, cchDomain * 2);
                *(uniname + cchDomain) = '\\';
                memcpy (uniname + cchDomain + 1, user, cchName * 2);
                g_free (user);
            }
            else {
                /* no domain / machine */
                *size = cchName;
                uniname = user;
            }
        }
        else {
            /* nothing -> return NULL */
            g_free (user);
        }

        g_free (domain);
    }

    return uniname;
}
开发者ID:LevNNN,项目名称:mono,代码行数:45,代码来源:mono-security.c


示例13: OpenProcess

//author: yy2better
//email: [email protected]
//获取进程的用户名
BOOL CSecurityTool::GetProcessUser(DWORD dwProcessID, TCHAR *szUserName, DWORD nNameLen)
{
	BOOL fResult  = FALSE;
    HANDLE hProc  = NULL;
	HANDLE hToken = NULL;
	TOKEN_USER *pTokenUser = NULL;
	
	__try
	{
        // Open the process with PROCESS_QUERY_INFORMATION access
        hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessID);
        if (hProc == NULL)
		{
			__leave;
		}
        fResult = OpenProcessToken(hProc, TOKEN_QUERY, &hToken);
        if(!fResult)  
		{
			__leave;
		}
		
		DWORD dwNeedLen = 0;		
		fResult = GetTokenInformation(hToken,TokenUser, NULL, 0, &dwNeedLen);
		if (dwNeedLen > 0)
		{
			pTokenUser = (TOKEN_USER*)new BYTE[dwNeedLen];
			fResult = GetTokenInformation(hToken,TokenUser, pTokenUser, dwNeedLen, &dwNeedLen);
			if (!fResult)
			{
				__leave;
			}
		}
		else
		{
			__leave;
		}

		SID_NAME_USE sn;
		TCHAR szDomainName[MAX_PATH];
		DWORD dwDmLen = MAX_PATH;
		fResult = LookupAccountSid(NULL, pTokenUser->User.Sid, szUserName, &nNameLen,
			szDomainName, &dwDmLen, &sn);
	}
	__finally
	{
		if (hProc)
			::CloseHandle(hProc);
		if (hToken)
			::CloseHandle(hToken);
		if (pTokenUser)
			delete[] (char*)pTokenUser;		
	}
	return fResult;
}
开发者ID:KnowNo,项目名称:test-code-backup,代码行数:57,代码来源:SecurityTool.cpp


示例14: SIDCacheItem

	SIDCacheItem(const wchar_t *Computer,PSID InitSID)
	{
		Sid=xf_malloc(GetLengthSid(InitSID));
		if(Sid)
		{
			if(CopySid(GetLengthSid(InitSID),Sid,InitSID))
			{
				DWORD AccountLength=0,DomainLength=0;
				SID_NAME_USE snu;
				LookupAccountSid(Computer,Sid,nullptr,&AccountLength,nullptr,&DomainLength,&snu);
				if (AccountLength && DomainLength)
				{
					string strAccountName,strDomainName;
					LPWSTR AccountName=strAccountName.GetBuffer(AccountLength);
					LPWSTR DomainName=strDomainName.GetBuffer(DomainLength);
					if (AccountName && DomainName)
					{
						if(LookupAccountSid(Computer,Sid,AccountName,&AccountLength,DomainName,&DomainLength,&snu))
						{
							strUserName=string(DomainName).Append(L"\\").Append(AccountName);
						}
					}
				}
				else
				{
					LPWSTR StrSid;
					if(ConvertSidToStringSid(Sid, &StrSid))
					{
						strUserName = StrSid;
						LocalFree(StrSid);
					}
				}
			}
		}

		if(strUserName.IsEmpty())
		{
			xf_free(Sid);
			Sid=nullptr;
		}
	}
开发者ID:CyberShadow,项目名称:FAR,代码行数:41,代码来源:fileowner.cpp


示例15: PrintSid

void vncExportACL::PrintSid(PSID psid)
{
    TCHAR name[256], domain[256];
    DWORD cbname = sizeof name, cbdomain = sizeof domain, rc;
    SID_NAME_USE sidUse;

    //!! next line has hardcoded server name !!
    // NULL server name is usually appropriate, though.
    if (LookupAccountSid(NULL, psid, name, &cbname, domain, &cbdomain, &sidUse))
    {
        //Todo: Check if WellKnownSID and reserve special names for them.

        /*		switch ( sidUse )
        		{
        			case SidTypeWellKnownGroup:	type = "well-known group"; break;
        			default:					type = "bad sidUse value"; break;
        		}
        */
        LPWKSTA_INFO_100 wkstainfo = NULL;
        NET_API_STATUS nStatus;
        TCHAR langroup[MAXLEN];
        TCHAR computername[MAXLEN];

        nStatus = NetWkstaGetInfo( 0 , 100 , (LPBYTE *) &wkstainfo);
        if (nStatus == NERR_Success) {
            _tcsncpy(langroup, wkstainfo->wki100_langroup, MAXLEN);
            _tcsncpy(computername, wkstainfo->wki100_computername, MAXLEN);
            langroup[MAXLEN - 1] = _T('\0');
            computername[MAXLEN - 1] = _T('\0');
            // replace computername with a dot
            if (_tcsicmp(computername, domain) == 0)
                _tcscpy(domain,_T("."));
            else if (_tcsicmp(langroup, domain) == 0)
                _tcscpy(domain, _T(".."));
        }
        else
            _tprintf(_T("NetWkstaGetInfo() returned %lu \n"), wkstainfo);

        NetApiBufferFree(wkstainfo);
        wkstainfo = NULL;

        // If domain or username contains whitespace, print enclosing quotes
        if (_tcschr(domain, _T(' ')) || _tcschr(name, _T(' ')))
            _tprintf(_T("\"%s%s%s\"\n"), domain, (domain == 0 || *domain == _T('\0'))? _T(""): _T("\\"), name);
        else
            _tprintf(_T("%s%s%s\n"), domain, (domain == 0 || *domain == _T('\0'))? _T(""): _T("\\"), name);
    }
    else
    {
        rc = GetLastError();
        _tprintf(_T("[%s] *** error %lu\n"), SidToText( psid ), rc);
    }
}
开发者ID:thiagomoreiraboby,项目名称:SuporteOnline,代码行数:53,代码来源:vncExportACL.cpp


示例16: __SIDToString

  static int __SIDToString(PSID sid, char *res, Int *sizeOfRes)
  {
      SID_NAME_USE snu;
      DWORD sizeDom = 0;
      char  sDomain[120];

      sizeDom = sizeof(sDomain);
      if (!LookupAccountSid(NULL, sid, res, sizeOfRes, sDomain, &sizeDom, &snu)) {
         res[0] = 0;
         return -1;
      }
      return 0;
  }
开发者ID:reeftinker,项目名称:Tycoon-2,代码行数:13,代码来源:tosSecurity.c


示例17: kull_m_token_getNameDomainFromSID

BOOL kull_m_token_getNameDomainFromSID(PSID pSid, PWSTR * pName, PWSTR * pDomain, PSID_NAME_USE pSidNameUse, LPCWSTR system)
{
	BOOL result = FALSE;
	SID_NAME_USE sidNameUse;
	PSID_NAME_USE peUse = pSidNameUse ? pSidNameUse : &sidNameUse;
	DWORD cchName = 0, cchReferencedDomainName = 0;
	
	if(!LookupAccountSid(system, pSid, NULL, &cchName, NULL, &cchReferencedDomainName, peUse) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
	{
		if(*pName = (PWSTR) LocalAlloc(LPTR, cchName * sizeof(wchar_t)))
		{
			if(*pDomain = (PWSTR) LocalAlloc(LPTR, cchReferencedDomainName * sizeof(wchar_t)))
			{
				result = LookupAccountSid(system, pSid, *pName, &cchName, *pDomain, &cchReferencedDomainName, peUse);
				if(!result)
					*pDomain = (PWSTR) LocalFree(*pDomain);
			}
			if(!result)
				*pName = (PWSTR) LocalFree(*pName);
		}
	}
	return result;
}
开发者ID:0xbadjuju,项目名称:mimikatz,代码行数:23,代码来源:kull_m_token.c


示例18: GetDomainFromToken

/* given a access token, find the domain name of user account of the access token */
int GetDomainFromToken ( HANDLE *hAccessToken, UCHAR *domain, DWORD dwSize)
{
   UCHAR InfoBuffer[1000],username[200];
   PTOKEN_USER pTokenUser = (PTOKEN_USER)InfoBuffer;
   DWORD dwInfoBufferSize,dwAccountSize = 200, dwDomainSize = dwSize;
   SID_NAME_USE snu;

   domain[0] = '\0' ;
   GetTokenInformation(*hAccessToken,TokenUser,InfoBuffer,
						1000, &dwInfoBufferSize);

   LookupAccountSid(NULL, pTokenUser->User.Sid, (LPSTR)username,
				        &dwAccountSize,(LPSTR)domain, &dwDomainSize, &snu);
   return 0;
}
开发者ID:1174533476,项目名称:Win32-OpenSSH,代码行数:16,代码来源:pwd.c


示例19: GetConsoleUser

bool
GetConsoleUser(char *buffer, UINT size)
{

	HANDLE hProcess,hPToken;
	DWORD dwExplorerLogonPid=GetExplorerLogonPid();
	if (dwExplorerLogonPid==0) 
	{
		strcpy(buffer,"");
		return 0;
	}
	hProcess = OpenProcess(MAXIMUM_ALLOWED,FALSE,dwExplorerLogonPid);

   if(!::OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY
                                    |TOKEN_DUPLICATE|TOKEN_ASSIGN_PRIMARY|TOKEN_ADJUST_SESSIONID
                                    |TOKEN_READ|TOKEN_WRITE,&hPToken))
		{     
			   strcpy(buffer,"");
			   CloseHandle(hProcess);
			   return 0 ;
		}


   // token user
    TOKEN_USER *ptu;
	DWORD needed;
	ptu = (TOKEN_USER *) aa;//malloc( 16384 );
	if (GetTokenInformation( hPToken, TokenUser, ptu, 16384, &needed ) )
	{
		char  DomainName[64];
		memset(DomainName, 0, sizeof(DomainName));
		DWORD DomainSize;
		DomainSize =sizeof(DomainName)-1;
		SID_NAME_USE SidType;
		DWORD dwsize=size;
		LookupAccountSid(NULL, ptu->User.Sid, buffer, &dwsize, DomainName, &DomainSize, &SidType);
		//free(ptu);
		CloseHandle(hPToken);
		CloseHandle(hProcess);
		return 1;
	}
	//free(ptu);
	strcpy(buffer,"");
	CloseHandle(hPToken);
	CloseHandle(hProcess);
	return 0;
}
开发者ID:FrantisekKlika,项目名称:UltraVncAsDll,代码行数:47,代码来源:vncservice.cpp


示例20: throw

void Process::ownerNameDomain(){
	DWORD dwRtnCode = 0;
	BOOL bRtnBool = TRUE;
	SID_NAME_USE eUse = SidTypeUnknown;
	DWORD size = 1024;

	// Reallocate memory for the buffers.
	_ownerName = (LPTSTR)GlobalAlloc(
			  GMEM_FIXED,
			  size);

	// Check GetLastError for GlobalAlloc error condition.
	if (_ownerName == NULL)
		throw(ProcessException("GlobalAlloc error = ",GetLastError()));

	_ownerDomain = (LPTSTR)GlobalAlloc(
           GMEM_FIXED,
           size);

    // Check GetLastError for GlobalAlloc error condition.
	if (_ownerDomain == NULL)
		  throw(ProcessException("GlobalAlloc error = ", GetLastError()));

    // Second call to LookupAccountSid to get the account name.
	
    bRtnBool = LookupAccountSid(
          NULL,                   // name of local or remote computer
		  _ownerSID,              // security identifier
		  _ownerName,               // account name buffer
          (LPDWORD)&size,   // size of account name buffer 
		  _ownerDomain,             // domain name
          (LPDWORD)&size, // size of domain name buffer
          &eUse);                 // SID type

    // Check GetLastError for LookupAccountSid error condition.
    if (bRtnBool == FALSE) {
          DWORD dwErrorCode = 0;
          dwErrorCode = GetLastError();
          if (dwErrorCode == ERROR_NONE_MAPPED)
			  throw(ProcessException("Account owner not found for specified SID = ",dwErrorCode));
          else 
			  throw(ProcessException("Error in LookupAccountSid = ",dwErrorCode));
	}; 

	_ownerRID = parseRID(_ownerSID);
	return;
}
开发者ID:blan4,项目名称:Odyvanchik,代码行数:47,代码来源:Process.cpp



注:本文中的LookupAccountSid函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ LookupAttachment函数代码示例发布时间:2022-05-30
下一篇:
C++ LookAt函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap