Пример #1
0
HRESULT TCUserAccount::HasRight(LPTSTR pszPrivilege) const
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Fail if Init has not been called successfully
  if (!m_hPolicy || m_spSIDPrincipal.IsNull())
    return E_UNEXPECTED;

  // Fail if the specified pointer is NULL
  if (!pszPrivilege)
    return E_POINTER;

  // Get the array of user rights
  PLSA_UNICODE_STRING pUserRights = NULL;
  ULONG cRights = 0;
  RETURN_FAILED(LsaEnumerateAccountRights(m_hPolicy, m_spSIDPrincipal,
    &pUserRights, &cRights));

  // Get a pointer to a UNICODE version of the specified privilege
  USES_CONVERSION;
  LPCWSTR pszWidePrivilege = T2CW(pszPrivilege);

  // Loop through the array of privileges
  for (ULONG i = 0; i < cRights; ++i)
    if (0 == _wcsicmp(pUserRights[i].Buffer, pszWidePrivilege))
      return S_OK;

  // Specified privilege wasnt' found
  return S_FALSE;
}
Пример #2
0
HRESULT TCUserAccount::RemoveRight(LPTSTR pszPrivilege)
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Fail if Init has not been called successfully
  if (!m_hPolicy || m_spSIDPrincipal.IsNull())
    return E_UNEXPECTED;

  // Fail if the specified pointer is NULL
  if (!pszPrivilege)
    return E_POINTER;

  // Get a pointer to a UNICODE version of the specified privilege
  USES_CONVERSION;
  LPWSTR pszWidePrivilege = T2W(pszPrivilege);

  // Create an LSA_UNICODE_STRING for the specified privilege name
  LSA_UNICODE_STRING lsaString;
  lsaString.Length        = (USHORT)(wcslen(pszWidePrivilege) * sizeof(WCHAR));
  lsaString.MaximumLength = (USHORT)(lsaString.Length + sizeof(WCHAR));
  lsaString.Buffer        = pszWidePrivilege;

  // Attempt to remove the specified privilege from the current user
  RETURN_FAILED(LsaRemoveAccountRights(m_hPolicy, m_spSIDPrincipal, false,
    &lsaString, 1));

  // Indicate success
  return S_OK;
}
Пример #3
0
/*-------------------------------------------------------------------------
 * IsInstalledAsService()
 *-------------------------------------------------------------------------
 * Returns:
 *    TRUE iff AllSrv is installed as an NT service.
 *
 */
BOOL CServiceModule::IsInstalledAsService()
{
	if (IsWin9x())
		return false;

	// Are we Service or Local Server
	CRegKey keyAppID;
	LONG lRes = keyAppID.Open(HKEY_CLASSES_ROOT, _T("AppID"), KEY_READ);
	if (lRes != ERROR_SUCCESS)
		return FALSE;

	CRegKey key;
	lRes = key.Open(keyAppID, c_szAPPID_AllSrv, KEY_READ);
	if (lRes != ERROR_SUCCESS)
		return FALSE;

	TCHAR szValue[_MAX_PATH];
	DWORD dwLen = _MAX_PATH;
	// mdvalley: QueryStringValue isn't in my ATL, so edited slightly
	lRes = key.QueryValue(szValue, _T("LocalService"), &dwLen);

	if (lRes == ERROR_SUCCESS)
		return TRUE;

	return FALSE;
}
Пример #4
0
// Security ID (SID) Lookup
HRESULT TCUserAccount::GetSID(LPCWSTR szUserName, PSID* ppSID, LPWSTR* ppszDomain)
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Initialize the [out] parameters
  if (ppSID)
    *ppSID = NULL;
  if (ppszDomain)
    *ppszDomain = NULL;

  // Skip past "\" or ".\", if the specified name begins with that
  if (L'\\' == szUserName[0])
    szUserName += 1;
  else if (L'.' == szUserName[0] && L'\\' == szUserName[1])
    szUserName += 2;

  // Get the needed size of the buffers
  SID_NAME_USE eUse;
  DWORD cbSID = 0, cchDomain = 0;
  if (!LookupAccountNameW(NULL, szUserName, NULL, &cbSID, NULL, &cchDomain, &eUse))
  {
    DWORD dwLastError = GetLastError();
    if (ERROR_INSUFFICIENT_BUFFER != dwLastError)
      return HRESULT_FROM_WIN32(dwLastError);
  }

  // Allocate domain name buffer on the task allocation, since we return it
  DWORD cbDomain = cchDomain * sizeof(WCHAR);
  TCCoTaskPtr<WCHAR*> spszDomain = (WCHAR*)CoTaskMemAlloc(cbDomain);
  if (spszDomain.IsNull())
    return E_OUTOFMEMORY;

  // Allocate the SID buffer on the task allocator, since we return it
  TCCoTaskPtr<PSID> spSID = (PSID)CoTaskMemAlloc(cbSID);
  if (spSID.IsNull())
    return E_OUTOFMEMORY;

  // Lookup the account name
  if (!LookupAccountNameW(NULL, szUserName, spSID, &cbSID, spszDomain,
    &cchDomain, &eUse))
      return HRESULT_FROM_WIN32(GetLastError());

  // Copy the SID to the [out] parameter
  if (ppSID)
    *ppSID = spSID.Detach();

  // Copy the domain string to the [out] parameter
  if (ppszDomain)
    *ppszDomain = spszDomain.Detach();

  // Indicate success
  return S_OK;
}
Пример #5
0
HRESULT TCUserAccount::SetRunAsUser(LPCTSTR szAppID, LPCTSTR szPassword)
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Fail if Init has not been called successfully
  if (!m_hPolicy || m_spSIDPrincipal.IsNull())
    return E_UNEXPECTED;

  // Concatenate the user name onto the domain name
  USES_CONVERSION;
  UINT cch = wcslen(m_spszDomainName) + wcslen(m_spszUserName) + 2;
  LPTSTR pszUserName = (LPTSTR)_alloca(cch * sizeof(TCHAR));
  _tcscpy(pszUserName, W2CT(m_spszDomainName));
  _tcscat(pszUserName, TEXT("\\"));
  _tcscat(pszUserName, W2CT(m_spszUserName));

  // Delegate to the static method
  return SetRunAsUser(szAppID, pszUserName, szPassword);
}
Пример #6
0
/*-------------------------------------------------------------------------
 * IsInServiceControlManager()
 *-------------------------------------------------------------------------
 * Returns:
 *    TRUE iff AllSrv is an NT service (by checking the Service Control
 *    Manager).
 *
 */
BOOL CServiceModule::IsInServiceControlManager()
{
	if (IsWin9x())
		return false;

	BOOL bResult = FALSE;

	SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, GENERIC_READ);

	if (hSCM != NULL)
	{
		SC_HANDLE hService = ::OpenServiceA(hSCM, c_szSvcName, SERVICE_QUERY_CONFIG);
		if (hService != NULL)
		{
			bResult = TRUE;
			::CloseServiceHandle(hService);
		}
		::CloseServiceHandle(hSCM);
	}
	return bResult;
}
Пример #7
0
//
// 从网上邻居的名字得到IP
//
BOOL GetNameFromIp(DWORD dwIp, char* pBuffer)
{
	BOOL bIsFind = FALSE;
	if(IsWin9x())
	{
		PNAME_LIST pList = m_pFirstNameList;
		if(pList == NULL)
			pList = XF_GetNameList();

		while(pList != NULL)
		{
			if(dwIp == pList->Address)
			{
				strcpy(pBuffer, pList->Name);
				bIsFind = TRUE;
				break;
			}
			pList = pList->pNext;
		}
		if(!bIsFind)
		{
			BYTE *pIp = (BYTE*)&dwIp;
			sprintf(pBuffer, "%u.%u.%u.%u", pIp[3], pIp[2], pIp[1], pIp[0]);
		}
	}
	else
	{
		pBuffer[0] = 0;
		XF_GetNameFromIp(dwIp, pBuffer);
		if(pBuffer[0] == 0)
			bIsFind = FALSE;
		else 
			bIsFind = TRUE;
	}
	return bIsFind;
}
Пример #8
0
static AutoStartProduct::SetResult SetGUIAutoStart (bool bAutoStart)
{
	TCHAR szAVPCCUPath[_MAX_PATH];
	TCHAR szAVPCCUCmdLine[_MAX_PATH + max (sizeof (szAutoRunCommandLine9x), sizeof (szAutoRunCommandLineNt))  + 4] = {0};  //2(\"\")+1(space)+1(NULL)

	if (!GetModuleFileName (NULL, szAVPCCUPath, _MAX_PATH))
		return AutoStartProduct::asGeneralFail;

	if(szAVPCCUPath[0]!=_T('\"'))
		_tcscat (szAVPCCUCmdLine, _T("\""));

	_tcscat (szAVPCCUCmdLine, szAVPCCUPath);

	if(szAVPCCUPath[0]!=_T('\"'))
		_tcscat (szAVPCCUCmdLine, _T("\""));

	_tcscat (szAVPCCUCmdLine, _T(" "));
	_tcscat (szAVPCCUCmdLine, IsWin9x () ? szAutoRunCommandLine9x : szAutoRunCommandLineNt);
	
	return AddRemoveAppPathToRegistry (bAutoStart, 
								_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
								szAutoRunKeyName,
								szAVPCCUCmdLine);
}
__ptr_t
__mmap64 (__ptr_t addr, size_t len, int prot, int flags, int fd,
		__off64_t offset)
{
	__ptr_t map = (__ptr_t) NULL;
	caddr_t gran_addr = (caddr_t) addr;
	HANDLE handle = INVALID_HANDLE_VALUE;
	DWORD cfm_flags = 0, mvf_flags = 0, sysgran = getgranularity ();
	__off64_t gran_offset = offset, filelen = _filelengthi64(fd);
	int mmlen = len;
	
	switch (prot) {
		case PROT_READ | PROT_WRITE | PROT_EXEC:
		case PROT_WRITE | PROT_EXEC:
			cfm_flags = PAGE_EXECUTE_READWRITE;
			mvf_flags = FILE_MAP_ALL_ACCESS;
			break;
		case PROT_READ | PROT_WRITE:
			cfm_flags = PAGE_READWRITE;
			mvf_flags = FILE_MAP_ALL_ACCESS;
			break;
		case PROT_WRITE:
			cfm_flags = PAGE_READWRITE;
			mvf_flags = FILE_MAP_WRITE;
			break;
		case PROT_READ:
			cfm_flags = PAGE_READONLY;
			mvf_flags = FILE_MAP_READ;
			break;
		case PROT_NONE:
			cfm_flags = PAGE_NOACCESS;
			mvf_flags = FILE_MAP_READ;
			break;
		case PROT_EXEC:
			cfm_flags = PAGE_EXECUTE;
			mvf_flags = FILE_MAP_READ;
			break;
	}
	if (flags & MAP_PRIVATE) {
		if (IsWin9x ())
			cfm_flags = PAGE_WRITECOPY;
		mvf_flags = FILE_MAP_COPY;
	}
	fprintf (stderr, "Addr before:   %p\n", gran_addr);
	fprintf (stderr, "Offset before: %#I64X\n", gran_offset);
	if (flags & MAP_FIXED) {
		gran_offset = offset;
		gran_addr = addr;
	}
	else {
		gran_offset = offset & ~(sysgran - 1);
		gran_addr = (caddr_t) (((DWORD) gran_addr / sysgran) * sysgran);
	}
	fprintf (stderr, "Addr after:    %p\n", gran_addr);
	fprintf (stderr, "Offset after:  %#I64X\n", gran_offset);
	mmlen = (filelen < gran_offset + len ? filelen - gran_offset : len);

	handle = CreateFileMapping ((HANDLE) _get_osfhandle(fd), NULL, cfm_flags,
		0, mmlen, NULL);
	if (!handle) {
		set_werrno;
		WinErr ("CreateFileMapping");
		return MAP_FAILED;
	}
	map = (__ptr_t) MapViewOfFileEx (handle, mvf_flags, HIDWORD(gran_offset),
		LODWORD(gran_offset), (SIZE_T) mmlen, (LPVOID) gran_addr);
	if (map == NULL && (flags & MAP_FIXED) ) {
		fprintf (stderr, "Starting address: %p\n", (LPVOID) gran_addr);
		WinErr ("First try of MapViewOfFileEx failed");
		map = (__ptr_t) MapViewOfFileEx (handle, mvf_flags, HIDWORD(gran_offset),
			LODWORD(gran_offset), (SIZE_T) mmlen, (LPVOID) NULL);
	}
	CloseHandle(handle);
	if (map == NULL) {
		set_werrno;
		WinErr ("MapViewOfFileEx");
		return MAP_FAILED;
	}
	return map;
}
Пример #10
0
void CExeModule::DisplaySyntax()
{
    Echo(IsWin9x()? IDS_SYNTAX_9X : IDS_SYNTAX_NT);
    EchoFlush();
}
Пример #11
0
HRESULT TCUserAccount::SetRunAsUser(LPCTSTR szAppID, LPCTSTR szUserName, LPCTSTR szPassword)
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Copy the specified AppID string to a non-const wide string
  USES_CONVERSION;
  UINT cchAppID = max(_tcslen(szAppID), 48) + 1;
  LPWSTR pszAppID = (LPWSTR)_alloca(cchAppID * sizeof(WCHAR));
  wcscpy(pszAppID, T2CW(szAppID));

  // Resolve the specified string to an AppID
  HKEY hkey = NULL;
  RETURN_FAILED(ResolveAppID(pszAppID, &hkey));
  CRegKey key;
  key.Attach(hkey);

  // Ensure that we have a domain name
  LPCTSTR pszUserName = szUserName;
  LPCTSTR pszWhack = _tcschr(szUserName, TEXT('\\'));
  if (!pszWhack || pszWhack == szUserName ||
    (pszWhack == (szUserName + 1) && TEXT('.') == *szUserName))
  {
    // Get the domain name and user name
    TCCoTaskPtr<LPTSTR> spszDomainName;
    RETURN_FAILED(GetSID(szUserName, NULL, &spszDomainName));
    LPCTSTR pszUserOnly = pszWhack ? pszWhack + 1 : szUserName;

    // Concatenate the user name onto the domain name
    UINT cch = _tcslen(spszDomainName) + _tcslen(pszUserOnly) + 2;
    LPTSTR pszUserNameTemp = (LPTSTR)_alloca(cch * sizeof(TCHAR));
    _tcscpy(pszUserNameTemp, spszDomainName);
    _tcscat(pszUserNameTemp, TEXT("\\"));
    _tcscat(pszUserNameTemp, pszUserOnly);
    pszUserName = pszUserNameTemp;
  }

  // Open the local security policy
  TCLsaHandle           hPolicy;
  LSA_OBJECT_ATTRIBUTES oa = {sizeof(oa)};
  RETURN_FAILED(LsaOpenPolicy(NULL, &oa, POLICY_CREATE_SECRET, &hPolicy));

  // Format the key string
  WCHAR szKey[48] = L"SCM:";
  wcscat(szKey, pszAppID);

  // Create an LSA_UNICODE_STRING for the key name
  LSA_UNICODE_STRING lsaKeyString;
  lsaKeyString.Length        = (wcslen(szKey) + 1) * sizeof(WCHAR);
  lsaKeyString.MaximumLength = lsaKeyString.Length;
  lsaKeyString.Buffer        = szKey;

  // Copy the specified password string to a non-const wide string
  UINT cchPassword = _tcslen(szPassword);
  LPWSTR pszPassword = (LPWSTR)_alloca((cchPassword + 1) * sizeof(WCHAR));
  wcscpy(pszPassword, T2CW(szPassword));

  // Create an LSA_UNICODE_STRING for the password string
  LSA_UNICODE_STRING lsaPasswordString;
  lsaPasswordString.Length        = (cchPassword + 1) * sizeof(WCHAR);
  lsaPasswordString.MaximumLength = lsaPasswordString.Length;
  lsaPasswordString.Buffer        = pszPassword;

  // Store the specified password
  RETURN_FAILED(LsaStorePrivateData(hPolicy, &lsaKeyString,
    &lsaPasswordString));

  // Set the specified user name as the RunAs user for the AppID
  // mdvalley: Another former SetStringValue
  LONG lr = key.SetValue(TEXT("RunAs"), pszUserName);
  if (lr)
    return HRESULT_FROM_WIN32(lr);

  // Indicate success
  return S_OK;
}
Пример #12
0
HRESULT TCUserAccount::Init(LPCWSTR szUserName)
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Delete any previous user name
  m_spszUserName = NULL;

  // Delete any previous SID
  m_spSIDPrincipal = NULL;

  // Get the SID and domain name of the specified user
  RETURN_FAILED(GetSID(szUserName, &m_spSIDPrincipal, &m_spszDomainName));

  // Get a pointer to just the user name (no domain)
  LPCWSTR pszWhack = wcschr(szUserName, L'\\');
  LPCWSTR pszUserOnly = pszWhack ? pszWhack + 1 : szUserName;

  // Save the user name
  int cchUserName = wcslen(pszUserOnly) + 1;
  m_spszUserName = (LPWSTR)CoTaskMemAlloc(cchUserName * sizeof(WCHAR));
  wcscpy(m_spszUserName, pszUserOnly);

  // Get the server information of the local machine
  TCNetApiPtr<SERVER_INFO_101*> si101;
  DWORD dw = NetServerGetInfo(NULL, 101, (LPBYTE*)&si101);
  if (NERR_Success != dw)
    return HRESULT_FROM_WIN32(dw);

  // Declare and initialize an LSA_OBJECT_ATTRIBUTES structure
  LSA_OBJECT_ATTRIBUTES oa = {sizeof(oa)};

  // Special processing when the local computer is a backup domain controller
  TCNetApiPtr<WCHAR*> domainController;
  if (si101->sv101_type & SV_TYPE_DOMAIN_BAKCTRL)
  {
    // Get the server name of the primary domain controller
    TCNetApiPtr<USER_MODALS_INFO_2*> umi2;
    if (0 == (dw = NetUserModalsGet(NULL, 2, (LPBYTE*)&umi2)))
    {
      // Get the domain name of the primary domain controller
      NetGetDCName(NULL, umi2->usrmod2_domain_name, (LPBYTE*)&domainController);

      // Create an LSA_UNICODE_STRING for the name of the PDC
      LSA_UNICODE_STRING lsaPDC;
      lsaPDC.Length        = (USHORT)((wcslen(domainController) * sizeof(WCHAR))-2);
      lsaPDC.MaximumLength = (USHORT)(lsaPDC.Length + sizeof(WCHAR));
      lsaPDC.Buffer        = &domainController[2];

      // Open the policy of the primary domain controller
      RETURN_FAILED(LsaOpenPolicy(&lsaPDC, &oa,
        POLICY_CREATE_ACCOUNT | POLICY_LOOKUP_NAMES, &m_hPolicy));
    }
  }

  // Open the policy of the local computer if not a BDC or if anything failed
  if (domainController.IsNull())
  {
    RETURN_FAILED(LsaOpenPolicy(NULL, &oa,
      POLICY_CREATE_ACCOUNT | POLICY_LOOKUP_NAMES, &m_hPolicy));
  }

  // Indicate success
  return S_OK;
}
Пример #13
0
HRESULT CServiceModule::RegisterServer(BOOL bReRegister, BOOL bRegTypeLib, BOOL bService, int argc, char * argv[])
{
	// Enter the COM MTA
	TCCoInit init(COINIT_MULTITHREADED);
	if (init.Failed())
		return init;

	// Initialize the ATL module
	HRESULT hr = _Module.Init(g.hInst); // init COM and/or NT service stuff
	ZSucceeded(hr);

	if (IsWin9x())
		bService = false; // Windows 9x doesn't support services

	  // Remove any previous service since it may point to
	  // the incorrect file
	if (IsInServiceControlManager() && !bReRegister)
		RemoveService();

	// Add service entries
	_Module.UpdateRegistryFromResource(IDR_AllSrv, true,
		_AGCModule.GetRegMapEntries());

#ifdef MONOLITHIC_DPLAY
	// Register custom dplay bits
	RegisterMonolithicDPlay();
#endif

	// Create the component category manager
	CComPtr<ICatRegister> spCatReg;
	hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_ALL,
		IID_ICatRegister, (void**)&spCatReg);
	ZSucceeded(hr);

	if (SUCCEEDED(hr))
	{
		// Determine the LCID for US English
		const LANGID langid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
		const LCID lcid = MAKELCID(langid, SORT_DEFAULT);

		// Register the component category
		CATEGORYINFO catinfo;
		catinfo.catid = CATID_AllegianceAdmin;
		catinfo.lcid = lcid;
		wcscpy(catinfo.szDescription, L"Allegiance Admin Objects");
		hr = spCatReg->RegisterCategories(1, &catinfo);
		ZSucceeded(hr);

		// Explicitly release the smart pointer
		spCatReg = NULL;
	}

	if (!bReRegister)
	{
		// Adjust the AppID for Local Server or Service
		CRegKey keyAppID;

		DWORD lRes = keyAppID.Open(HKEY_CLASSES_ROOT, _T("AppID"), KEY_WRITE);
		if (lRes != ERROR_SUCCESS)
			return lRes;

		CRegKey key;
		lRes = key.Open(keyAppID, _T("{E4E8767E-DFDB-11d2-8B46-00C04F681633}"), KEY_WRITE);
		if (lRes != ERROR_SUCCESS)
			return lRes;

		key.DeleteValue(_T("LocalService"));

		if (bService)
		{
			// mdvalley: I hate my ATL libraries sometimes (SetStringValue)
			key.SetValue(_T(__MODULE__), _T("LocalService"));
			key.SetValue(_T("-Service"), _T("ServiceParameters"));
			// Create service
			InstallService(argc, argv);
		}
	}

	// Add object entries
	hr = _Module.CComModule::RegisterServer(bRegTypeLib);

	// Terminate the ATL module
	_Module.Term();
	return hr;
}
Пример #14
0
HGLOBAL MainWindow::CreateFileCollection(SelectionSet* pSelSet)
{
    SelectionEntry* pSelEntry;
    GenericEntry* pEntry;
    HGLOBAL hGlobal = NULL;
    HGLOBAL hResult = NULL;
    LPVOID pGlobal;
    size_t totalLength, numFiles;
    long priorLength;

    /* get len of text version(s), with kluge to avoid close & reopen */
    priorLength = GetClipboardContentLen() * kClipTextMult;
    /* add some padding -- textmult doesn't work for fixed-size CF_LOCALE */
    priorLength += kWin98NeutralZone;

    totalLength = sizeof(FileCollection);
    numFiles = 0;

    /*
     * Compute the amount of space required to hold it all.
     */
    pSelSet->IterReset();
    pSelEntry = pSelSet->IterNext();
    while (pSelEntry != NULL) {
        pEntry = pSelEntry->GetEntry();
        ASSERT(pEntry != NULL);

        //LOGI("+++ Examining '%s'", pEntry->GetDisplayName());

        if (pEntry->GetRecordKind() != GenericEntry::kRecordKindVolumeDir) {
            totalLength += sizeof(FileCollectionEntry);
            totalLength += (wcslen(pEntry->GetPathNameUNI()) +1) * sizeof(WCHAR);
            numFiles++;
            if (pEntry->GetRecordKind() != GenericEntry::kRecordKindDirectory) {
                totalLength += (long) pEntry->GetDataForkLen();
                totalLength += (long) pEntry->GetRsrcForkLen();
            }
        }

        if (totalLength < 0) {
            DebugBreak();
            LOGI("Overflow");    // pretty hard to do right now!
            return NULL;
        }

        pSelEntry = pSelSet->IterNext();
    }

#if 0
    {
        CString msg;
        msg.Format("totalLength is %ld+%ld = %ld",
            totalLength, priorLength, totalLength+priorLength);
        if (MessageBox(msg, NULL, MB_OKCANCEL) == IDCANCEL)
            goto bail;
    }
#endif

    LOGI("Total length required is %ld + %ld = %ld",
        totalLength, priorLength, totalLength+priorLength);
    if (IsWin9x() && totalLength+priorLength >= kWin98ClipboardMax) {
        CString errMsg;
        errMsg.Format(IDS_CLIPBOARD_WIN9XMAX,
            kWin98ClipboardMax / (1024*1024),
            ((float) (totalLength+priorLength)) / (1024.0*1024.0));
        ShowFailureMsg(this, errMsg, IDS_MB_APP_NAME);
        goto bail;
    }

    /*
     * Create a big buffer to hold it all.
     */
    hGlobal = ::GlobalAlloc(GHND | GMEM_SHARE, totalLength);
    if (hGlobal == NULL) {
        CString errMsg;
        errMsg.Format(L"ERROR: unable to allocate %ld bytes for copy",
            totalLength);
        LOGI("%ls", (LPCWSTR) errMsg);
        ShowFailureMsg(this, errMsg, IDS_FAILED);
        goto bail;
    }
    pGlobal = ::GlobalLock(hGlobal);

    ASSERT(pGlobal != NULL);
    ASSERT(GlobalSize(hGlobal) >= (DWORD) totalLength);
    LOGI("hGlobal=0x%08lx pGlobal=0x%08lx size=%ld",
        (long) hGlobal, (long) pGlobal, GlobalSize(hGlobal));

    /*
     * Set up a progress dialog to track it.
     */
    ASSERT(fpActionProgress == NULL);
    fpActionProgress = new ActionProgressDialog;
    fpActionProgress->Create(ActionProgressDialog::kActionExtract, this);
    fpActionProgress->SetFileName(L"Clipboard");

    /*
     * Extract the data into the buffer.
     */
    long remainingLen;
    void* buf;

    remainingLen = totalLength - sizeof(FileCollection);
    buf = (uint8_t*) pGlobal + sizeof(FileCollection);
    pSelSet->IterReset();
    pSelEntry = pSelSet->IterNext();
    while (pSelEntry != NULL) {
        CString errStr;

        pEntry = pSelEntry->GetEntry();
        ASSERT(pEntry != NULL);

        fpActionProgress->SetArcName(pEntry->GetDisplayName());

        errStr = CopyToCollection(pEntry, &buf, &remainingLen);
        if (!errStr.IsEmpty()) {
            ShowFailureMsg(fpActionProgress, errStr, IDS_MB_APP_NAME);
            goto bail;
        }
        //LOGI("remainingLen now %ld", remainingLen);

        pSelEntry = pSelSet->IterNext();
    }

    ASSERT(remainingLen == 0);
    ASSERT(buf == (uint8_t*) pGlobal + totalLength);

    /*
     * Write the header.
     */
    FileCollection fileColl;
    fileColl.version = kClipVersion;
    fileColl.dataOffset = sizeof(FileCollection);
    fileColl.length = totalLength;
    fileColl.count = numFiles;
    memcpy(pGlobal, &fileColl, sizeof(fileColl));

    /*
     * Success!
     */
    ::GlobalUnlock(hGlobal);

    hResult = hGlobal;
    hGlobal = NULL;

bail:
    if (hGlobal != NULL) {
        ASSERT(hResult == NULL);
        ::GlobalUnlock(hGlobal);
        ::GlobalFree(hGlobal);
    }
    if (fpActionProgress != NULL) {
        fpActionProgress->Cleanup(this);
        fpActionProgress = NULL;
    }
    return hResult;
}
Пример #15
-1
HRESULT TCUserAccount::SetRunAsInteractiveUser(LPCTSTR szAppID)
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Copy the specified AppID string to a non-const wide string
  USES_CONVERSION;
  UINT cchAppID = max(_tcslen(szAppID), 48) + 1;
  LPWSTR pszAppID = (LPWSTR)_alloca(cchAppID * sizeof(WCHAR));
  wcscpy(pszAppID, T2CW(szAppID));

  // Resolve the specified string to an AppID
  HKEY hkey = NULL;
  RETURN_FAILED(ResolveAppID(pszAppID, &hkey));
  CRegKey key;
  key.Attach(hkey);

  // Set "Interactive User" as the RunAs user for the AppID
  // mdvalley: it used to be SetStringValue, but that ain't in my ATL.
  LONG lr = key.SetValue(TEXT("RunAs"), TEXT("Interactive User"));
  if (lr)
    return HRESULT_FROM_WIN32(lr);

  // Indicate success
  return S_OK;
}