void FGenericCrashContext::AddCrashProperty( const TCHAR* PropertyName, const TCHAR* PropertyValue )
{
	CommonBuffer += TEXT( "<" );
	CommonBuffer += PropertyName;
	CommonBuffer += TEXT( ">" );


	CommonBuffer += EscapeXMLString( PropertyValue );

	CommonBuffer += TEXT( "</" );
	CommonBuffer += PropertyName;
	CommonBuffer += TEXT( ">" );
	CommonBuffer += LINE_TERMINATOR;
}
Esempio n. 2
0
void CXMLObject::CreateXMLTags( vector< XMLTag >& tags ) {
	XMLTag current;
	current.name = EscapeXMLString( GetType() );

	set<string>::iterator optit;
	map<string,string>::iterator parit;

	for ( optit=options.begin(); optit!=options.end(); optit++ ) {
		current.options.push_back( EscapeXMLString( *optit ) );
	}

	for ( parit=parameters.begin(); parit!=parameters.end(); parit++ ) {
		pair<string,string> param = *parit;
		param.first = EscapeXMLString( param.first );
		param.second = EscapeXMLString( param.second, true );
		current.parameters.push_back( param );
	}

	current.end = false;
	if ( GetChildCount() == 0 ) {
		current.empty = true;
		tags.push_back( current );
	} else {
		current.empty = false;
		tags.push_back( current );

		for ( int i=0; i<GetChildCount(); i++ ) {
			GetChild(i)->CreateXMLTags( tags );
		}

		XMLTag finish;
		finish.name = current.name;
		finish.empty = false;
		finish.end = true;
		tags.push_back( finish );
	}
}
BOOL PrintXMLData(_In_ PSCRIPTSINI_FILE_DATA pScriptsIniData)
{
	DWORD dwDataRead = 0;
	HANDLE hXMLFile = INVALID_HANDLE_VALUE;
	TCHAR tLogon[11], tLogoff[11], tStartup[11], tShutdown[11], tUnreferenced[11];
	DWORD dwLogonLen = 0, dwLogoffLen = 0, dwStartupLen = 0, dwShutdownLen = 0, dwUnreferencedLen = 0;
	GPO_FILTER_TARGET dwTarget = GPO_FILTER_UNKNOWN;
	PTCHAR tOutputDirectoryScriptsFile = OUTPUT_DIRECTORY_SCRIPTS_INI;

	// Determine if we need to create user or computer file in case of '[Machine||User]' 
	dwTarget = GetTargetGPO(pScriptsIniData->tFilePath);
	if (dwTarget == GPO_FILTER_TARGET_MACHINE)
		tOutputDirectoryScriptsFile = TEXT(".\\Machine\\");
	else if (dwTarget == GPO_FILTER_TARGET_USER)
		tOutputDirectoryScriptsFile = TEXT(".\\User\\");	
	hXMLFile = GetFileHandle(OUTPUT_FILE_XML, tOutputDirectoryScriptsFile, OUTPUT_NAME_SCRIPTS_INI);

	if (!pScriptsIniData || !(pScriptsIniData->tFilePath))
	{
		DEBUG_LOG(D_WARNING, "PSCRIPTSINI_FILE_DATA invalid for scripts.ini file.\r\n");
		DoExit(D_WARNING);
	}

	if (hXMLFile == INVALID_HANDLE_VALUE)
	{
		DEBUG_LOG(D_WARNING, "Handle to hXMLFile is invalid.\r\nExiting now...");
		DoExit(D_ERROR);
	}

	dwLogonLen = _stprintf_s(tLogon, 11, TEXT("%d"), pScriptsIniData->dwLogonScriptNum);
	dwLogoffLen = _stprintf_s(tLogoff, 11, TEXT("%d"), pScriptsIniData->dwLogoffScriptNum);
	dwStartupLen = _stprintf_s(tStartup, 11, TEXT("%d"), pScriptsIniData->dwStartupScriptNum);
	dwShutdownLen = _stprintf_s(tShutdown, 11, TEXT("%d"), pScriptsIniData->dwShutdownScriptNum);
	dwUnreferencedLen = _stprintf_s(tUnreferenced, 11, TEXT("%d"), pScriptsIniData->dwNumberOfUnReferrencedSections);

	if ((WriteFile(hXMLFile, TEXT("\t<Logon numberofaction=\""), (DWORD)(_tcslen(TEXT("\t<Logon numberofaction=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hXMLFile, tLogon, (DWORD)(dwLogonLen * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hXMLFile, TEXT("\">\r\n"), (DWORD)(_tcslen(TEXT("\">\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE))
		goto writerror;
	for (DWORD i = 0; i < pScriptsIniData->dwLogonScriptNum; ++i)
	{
		PTCHAR tCmdLine = EscapeXMLString(pScriptsIniData->pLogonScripts[i]->tCmdLine);
		PTCHAR tParams = EscapeXMLString(pScriptsIniData->pLogonScripts[i]->tParameters);

		if ((WriteFile(hXMLFile, TEXT("\t\t<Action cmdline=\""), (DWORD)(_tcslen(TEXT("\t\t<Action cmdline=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, tCmdLine, (DWORD)(_tcslen(tCmdLine) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, TEXT("\" parameters=\""), (DWORD)(_tcslen(TEXT("\" parameters=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, tParams, (DWORD)(_tcslen(tParams) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, TEXT("\"/>\r\n"), (DWORD)(_tcslen(TEXT("\"/>\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE))
			goto writerror;

		if (tCmdLine)
			HeapFree(hCrawlerHeap, NULL, tCmdLine);
		if (tParams)
			HeapFree(hCrawlerHeap, NULL, tParams);
	}
	if (WriteFile(hXMLFile, TEXT("\t<Logon/>\r\n"), (DWORD)(_tcslen(TEXT("\t<Logon/>\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		goto writerror;

	if ((WriteFile(hXMLFile, TEXT("\t<Logoff numberofaction=\""), (DWORD)(_tcslen(TEXT("\t<Logoff numberofaction=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hXMLFile, tLogoff, (DWORD)(dwLogoffLen * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hXMLFile, TEXT("\">\r\n"), (DWORD)(_tcslen(TEXT("\">\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE))
		goto writerror;
	for (DWORD i = 0; i < pScriptsIniData->dwLogoffScriptNum; ++i)
	{
		PTCHAR tCmdLine = EscapeXMLString(pScriptsIniData->pLogoffScripts[i]->tCmdLine);
		PTCHAR tParams = EscapeXMLString(pScriptsIniData->pLogoffScripts[i]->tParameters);

		if ((WriteFile(hXMLFile, TEXT("\t\t<Action cmdline=\""), (DWORD)(_tcslen(TEXT("\t\t<Action cmdline=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, tCmdLine, (DWORD)(_tcslen(tCmdLine) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, TEXT("\" parameters=\""), (DWORD)(_tcslen(TEXT("\" parameters=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, tParams, (DWORD)(_tcslen(tParams) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, TEXT("\"/>\r\n"), (DWORD)(_tcslen(TEXT("\"/>\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE))
			goto writerror;
		if (tCmdLine)
			HeapFree(hCrawlerHeap, NULL, tCmdLine);
		if (tParams)
			HeapFree(hCrawlerHeap, NULL, tParams);
	}
	if (WriteFile(hXMLFile, TEXT("\t<Logoff/>\r\n"), (DWORD)(_tcslen(TEXT("\t<Logoff/>\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		goto writerror;

	if ((WriteFile(hXMLFile, TEXT("\t<Startup numberofaction=\""), (DWORD)(_tcslen(TEXT("\t<Startup numberofaction=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hXMLFile, tStartup, (DWORD)(dwStartupLen * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hXMLFile, TEXT("\">\r\n"), (DWORD)(_tcslen(TEXT("\">\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE))
		goto writerror;
	for (DWORD i = 0; i < pScriptsIniData->dwStartupScriptNum; ++i)
	{
		PTCHAR tCmdLine = EscapeXMLString(pScriptsIniData->pStartupScripts[i]->tCmdLine);
		PTCHAR tParams = EscapeXMLString(pScriptsIniData->pStartupScripts[i]->tParameters);

		if ((WriteFile(hXMLFile, TEXT("\t\t<Action cmdline=\""), (DWORD)(_tcslen(TEXT("\t\t<Action cmdline=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, tCmdLine, (DWORD)(_tcslen(tCmdLine) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, TEXT("\" parameters=\""), (DWORD)(_tcslen(TEXT("\" parameters=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, tParams, (DWORD)(_tcslen(tParams) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, TEXT("\"/>\r\n"), (DWORD)(_tcslen(TEXT("\"/>\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE))
			goto writerror;
		if (tCmdLine)
			HeapFree(hCrawlerHeap, NULL, tCmdLine);
		if (tParams)
			HeapFree(hCrawlerHeap, NULL, tParams);
	}
	if (WriteFile(hXMLFile, TEXT("\t<Startup/>\r\n"), (DWORD)(_tcslen(TEXT("\t<Startup/>\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		goto writerror;

	if ((WriteFile(hXMLFile, TEXT("\t<Shutdown numberofaction=\""), (DWORD)(_tcslen(TEXT("\t<Shutdown numberofaction=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hXMLFile, tShutdown, (DWORD)(dwShutdownLen * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hXMLFile, TEXT("\">\r\n"), (DWORD)(_tcslen(TEXT("\">\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE))
		goto writerror;
	for (DWORD i = 0; i < pScriptsIniData->dwShutdownScriptNum; ++i)
	{
		PTCHAR tCmdLine = EscapeXMLString(pScriptsIniData->pShutdownScripts[i]->tCmdLine);
		PTCHAR tParams = EscapeXMLString(pScriptsIniData->pShutdownScripts[i]->tParameters);

		if ((WriteFile(hXMLFile, TEXT("\t\t<Action cmdline=\""), (DWORD)(_tcslen(TEXT("\t\t<Action cmdline=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, tCmdLine, (DWORD)(_tcslen(tCmdLine) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, TEXT("\" parameters=\""), (DWORD)(_tcslen(TEXT("\" parameters=\"")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, tParams, (DWORD)(_tcslen(tParams) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
			|| (WriteFile(hXMLFile, TEXT("\"/>\r\n"), (DWORD)(_tcslen(TEXT("\"/>\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE))
			goto writerror;
		if (tCmdLine)
			HeapFree(hCrawlerHeap, NULL, tCmdLine);
		if (tParams)
			HeapFree(hCrawlerHeap, NULL, tParams);
	}
	if (WriteFile(hXMLFile, TEXT("\t<Shutdown/>\r\n"), (DWORD)(_tcslen(TEXT("\t<Shutdown/>\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		goto writerror;

	for (DWORD i = 0; i < pScriptsIniData->dwNumberOfUnReferrencedSections; ++i)
	{
		PINI_SECTION_DATA pCurrSectionData = pScriptsIniData->pUnReferrencedSections[i];

		if (!pCurrSectionData->tSectionName)
			continue;

		PrintXMLUnreferencedSectionData(pCurrSectionData, hXMLFile);
	}	

	CloseHandle(hXMLFile);
	return TRUE;
writerror:
	DEBUG_LOG(D_WARNING, "Unable to write XML DATA.\r\nExiting now...");
	DoExit(D_ERROR);
	return FALSE;
}