Beispiel #1
0
SYSLIBFUNC(HANDLE) IPC_CreateServerW(LPCWSTR lpName,BOOL bSecure)
{
    HANDLE hServer=NULL;
    LPWSTR lpPipe=SYSLIB::IPC_FormatPipeName(lpName);
    if (lpPipe)
    {
        HANDLE hPipe=CreateNamedPipeW(lpPipe,PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED|WRITE_DAC|WRITE_OWNER,PIPE_TYPE_MESSAGE|PIPE_WAIT|PIPE_READMODE_MESSAGE,PIPE_UNLIMITED_INSTANCES,sizeof(IPC_PIPE_CONNECTION_INFO),sizeof(IPC_PIPE_CONNECTION_INFO),NMPWAIT_USE_DEFAULT_WAIT,NULL);
        if (hPipe != INVALID_HANDLE_VALUE)
        {
            SetObjectToLowIntegrity(hPipe);

            IPC_HANDLE *lpServer=SYSLIB::IPC_CreateHandle(IPC_SERVER_HANDLE);
            if (lpServer)
            {
                lpServer->Srv.hPipe=hPipe;
                lpServer->Srv.bSecure=bSecure;
                lpServer->Srv.hStopEvent=CreateEvent(NULL,true,false,NULL);
                lpServer->Srv.hServerInitEvent=CreateEvent(NULL,true,false,NULL);
                lpServer->Srv.hServerThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)IPC_PipeServerThread,&lpServer->Srv,0,NULL);
                WaitForSingleObject(lpServer->Srv.hServerInitEvent,INFINITE);
                SysCloseHandle(lpServer->Srv.hServerInitEvent);
                lpServer->Srv.hServerInitEvent=NULL;

                hServer=(HANDLE)lpServer;
            }
            else
                SysCloseHandle(hPipe);
        }
        MemFree(lpPipe);
    }
    return hServer;
}
bool HttpRequestFilter::Enable(bool enable, unsigned short listen_port)
{
	XMLib::CriticalSectionLockGuard lck(this->cs);
	this->m_enable = enable;
	if(this->m_hIPCFileMapping == NULL) {
		this->m_hIPCFileMapping = ::CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4 * 1024, L"Local\\{ED30EC84-F8F0-4D7E-83B5-942E4E3DD5DA}WebEarserFilterEnable");
		if(this->m_hIPCFileMapping == NULL) {
			return false;
		}
		SetObjectToLowIntegrity(this->m_hIPCFileMapping);
	}
	char* sharedMemoryBuffer = reinterpret_cast<char*>(::MapViewOfFile(this->m_hIPCFileMapping, FILE_MAP_WRITE, 0, 0, 256));
	if(sharedMemoryBuffer == NULL) {
		return false;
	}

	// ×Ô¶¯Unmap
	ScopeResourceHandle<HANDLE, BOOL(WINAPI*)(LPCVOID)> autoUnmapViewOfFile(sharedMemoryBuffer, ::UnmapViewOfFile);

	if(enable) {
		sharedMemoryBuffer[3] = '\x01';
	}
	else {
		sharedMemoryBuffer[3] = '\x00';
	}

	// 4~5±£Áô
	sharedMemoryBuffer[4] = '\x00';
	sharedMemoryBuffer[5] = '\x00';

	// ¶Ë¿Ú
	assert(sizeof(unsigned short) == 2);
	if(enable) {
		union {
			unsigned short from;
			char to[2];
		}cvt;

		cvt.from = listen_port;

		sharedMemoryBuffer[6] = cvt.to[0];
		sharedMemoryBuffer[7] = cvt.to[1];
	}

	sharedMemoryBuffer[2] = 'C';
	sharedMemoryBuffer[1] = 'D';
	sharedMemoryBuffer[0] = 'A';
	return true;
}
Beispiel #3
0
BOOL KProcessPerfCacheMgr::OpenCacheFile()
{
	BOOL	bRes = FALSE;
	HANDLE hFile = NULL;

	kws_log(TEXT("KProcessPerfCacheMgr::OpenCacheFile begin"));

	DWORD nWriteSize = 0;
	HANDLE hFileMap = NULL;
	BYTE* pMapBuf = NULL;
	KSecurityDesAcessByAnyone secByAny;

	hFile = ::CreateFile(m_strCacheFile,
		GENERIC_READ | GENERIC_WRITE,
		0, //FILE_SHARE_READ|FILE_SHARE_WRITE, 
		secByAny, 
		OPEN_EXISTING, 
		FILE_ATTRIBUTE_NORMAL, 
		NULL);

	if (hFile == INVALID_HANDLE_VALUE)
	{
		kws_log(TEXT("create file error :%d: %s"), ::GetLastError(), (LPCWSTR)m_strCacheFile);
		goto exit0;
	}

	if (!VerifyCacheFile(hFile))
	{
		kws_log(TEXT("VerifyCacheFile failed:"));
		goto exit0;
	}

	hFileMap = ::CreateFileMapping(hFile, secByAny, PAGE_READWRITE | SEC_COMMIT, 
		0, ::GetFileSize(hFile, NULL), m_strUrlMapName);

	if (NULL == hFileMap)
	{
		kws_log(TEXT("CreateFileMapping failed: %d"), ::GetLastError());
		goto exit0;
	}

	pMapBuf = (BYTE*)::MapViewOfFile(hFileMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);

	m_hFile = hFile;
	m_hFileMap = hFileMap;
	m_pData = pMapBuf;

	SetObjectToLowIntegrity(m_hFile);
	SetObjectToLowIntegrity(m_hFileMap);

	kws_log(TEXT("KProcessPerfCacheMgr::OpenCacheFile end sucess"));
	return TRUE;

exit0:
	if (pMapBuf)
	{
		UnmapViewOfFile(pMapBuf);
		pMapBuf = NULL;
	}
	if (hFileMap)
	{
		::CloseHandle(hFileMap);
		hFileMap = NULL;
	}
	if (hFile)
	{
		::CloseHandle(hFile);
		hFile = NULL;
	}
	return FALSE;
}