Ejemplo n.º 1
0
/*! \return 1 on failure otherwise 0 */
static int do_video(cmd_tbl_t* cmdtp, int flag, int argc, char* argv[])
{
	int ret = 1;
	const char *s;

	if (argc != 1)
		return ret;

	ret = run_menu(select_vif_menu, ARRAY_SIZE(select_vif_menu));
	if (!ret) {
		puts("\n");
#ifdef CONFIG_DISPLAY1_ENABLE
		if ((s = GetEnvVar(VIDEO_VAR, 1)) != NULL)
			printf("%s=%s\n", VIDEO_VAR, s);
#endif
#ifdef CONFIG_DISPLAY2_ENABLE
		if ((s = GetEnvVar(VIDEO2_VAR, 1)) != NULL)
			printf("%s=%s\n", VIDEO2_VAR, s);
#endif
#ifdef CONFIG_DISPLAY_LVDS_ENABLE
		if ((s = GetEnvVar(LDB_VAR, 1)) != NULL)
			printf("%s=%s\n", LDB_VAR, s);
#endif
#if defined(CONFIG_DISPLAY1_ENABLE) && defined(CONFIG_DISPLAY2_ENABLE)
		if ((s = GetEnvVar(FBPRIMARY_VAR, 1)) != NULL)
			printf("%s=%s\n", FBPRIMARY_VAR, s);
#endif
		puts("\nRemember to save the configuration with 'saveenv'\n\n");
	} else if (ret == USER_CANCEL)
		ret = 0;	/* Selection cancelled by user, not error */

	return ret;
}
Ejemplo n.º 2
0
bool BakSysInfo()
{
	string backupDir = GetEnvVar("BACKUPDIR");
	if(backupDir.empty())
		backupDir = BACKUPDIR;

	DIR *dir;
	if(NULL == (dir = opendir(backupDir.c_str())))
	{
		if(mkdir(backupDir.c_str(),0775) != 0)
			return false;
	}
	closedir(dir);

	backupDir = AddSlash(backupDir);
	backupDir.append("sysuser-backup.zip > /dev/null");
	
	chdir("/etc/");
	string cmd = "zip -qu ";
	cmd.append(backupDir);
	cmd.append(" ");
	cmd.append("passwd shadow group gshadow");
	int ret = system(cmd.c_str());
	chdir("/");

	if(ret != -1 && WIFEXITED(ret) && (WEXITSTATUS(ret) == 0 || WEXITSTATUS(ret) == 12))
	{
		return true;
	}
	else
	{
		return false;
	}
}
Ejemplo n.º 3
0
bool BakConf()
{
	string dirPath = GetEnvVar("CONF_DIR");
	if(dirPath.empty())
	{
		dirPath = CONF_DIR;
	}
	if(chdir(dirPath.c_str()) != 0)
		return false;

	string backupDir = GetEnvVar("BACKUPDIR");
	if(backupDir.empty())
		backupDir = BACKUPDIR;
	
	DIR *dir;
	if(NULL == (dir = opendir(backupDir.c_str())))
	{
		if(mkdir(backupDir.c_str(),0775) != 0)
		{
			chdir("/");
			return false;
		}
	}
	else
		closedir(dir);	

	backupDir = AddSlash(backupDir);
	backupDir.append("vhost-conf.zip > /dev/null");

	string cmd;
	cmd = "zip -qu ";
	cmd.append(backupDir);
	cmd.append(" ");
	//改为备份所有
	string backupWhat = "./*";
	cmd.append(backupWhat);
	int ret = system(cmd.c_str());
	chdir("/");
	if(ret != -1 && WIFEXITED(ret) && (WEXITSTATUS(ret) == 0 || WEXITSTATUS(ret) == 12))
	{
		return true;
	}
	else
	{
		return false;
	}
}
Ejemplo n.º 4
0
string MakeConfPath(string ftpName)
{
	string dirPath = GetEnvVar("CONF_DIR");
	if(dirPath.empty())
		dirPath = CONF_DIR;
	AddSlash(dirPath);
	string path = dirPath + ftpName + ".conf";
	return path;

}
Ejemplo n.º 5
0
string MakeUserRoot(string &userName)
{
	string path = GetEnvVar("USER_ROOT");
	if(path.empty())
	{
		path = USER_ROOT;
	}
	MakePath(path,userName);
	MakePath(path,"/home/wwwroot");
	return path;
}
Ejemplo n.º 6
0
wstring GetApiKey(int argc, _TCHAR* argv[])
{
    if (g_isConsoleApp == false)
    {
        return GetEnvVar(L"apiKey");
    }

    if (cmdOptionExists(argv, argv + argc, L"-key") == true)
    {
        return getCmdOption(argv, argv + argc, L"-key");
    }

    return L"";
}
Ejemplo n.º 7
0
BOOL GetDebugMode(int argc, _TCHAR* argv[])
{
    if (g_isConsoleApp == false)
    {
        return GetEnvVar(L"debug") == L"1";
    }

    if (cmdOptionExists(g_argv, g_argv + g_argc, L"-debug") == true)
    {
        return TRUE;
    }

    return FALSE;
}
Ejemplo n.º 8
0
void ManSearchPath::Print()
{
    printf("%s:\n", GetEnvVar());
    CString sp(GetSearchPath());
    if (!sp.isNull()) {
	CTokenizedString path (sp,Separator().data());
	CString subpath = path.next();
	while (!subpath.isNull()) {
	    printf("\t%s\n",subpath.data());
	    subpath = path.next();
	}
        printf("\n");
    }
}
Ejemplo n.º 9
0
bool RestoreConf(string &userName)
{
	string dirPath = GetEnvVar("CONF_DIR");
	if(dirPath.empty())
	{
		dirPath = CONF_DIR;
	}

	string backupDir = GetEnvVar("BACKUPDIR");
	if(backupDir.empty())
		backupDir = BACKUPDIR; 

	string restoreWhat = userName;
	restoreWhat.append(".conf");

	AddSlash(backupDir);
	AddSlash(dirPath);

	backupDir.append("vhost-conf.zip");
	string cmd = "unzip -qo ";
	cmd.append(backupDir);
	cmd.append(" ");
	cmd.append(restoreWhat);
	cmd.append(" ");
	cmd.append("-d ");
	cmd.append(dirPath);
	cmd.append(" > /dev/null");
	int ret = system(cmd.c_str());

	if(ret != -1 && WIFEXITED(ret) && WEXITSTATUS(ret) == 0)
	{
		return true;
	}
	else
		return false;
}
Ejemplo n.º 10
0
void    CGMemFini( void )
/***********************/
{
#if _MEMORY_TRACKING & _FULL_TRACKING
    char        buff[80];

    if( !GetEnvVar( "TRQUIET", buff, 7 ) ) {
        _trmem_prt_list( Handle );
    }
    _trmem_close( Handle );
#elif _MEMORY_TRACKING & _CHUNK_TRACKING
    if( Chunks != 0 ) {
        _Zoiks( ZOIKS_002 );
    }
#endif
    MemFini();
}
Ejemplo n.º 11
0
BOOL CFilePath::EnvUnsubstRoot(CString &sString, LPCTSTR psEnvVar)
{
    CString sEnvValue = GetEnvVar(psEnvVar);
    if (!sEnvValue.GetLength())
        return FALSE;

    if (sString.GetLength() >= sEnvValue.GetLength() && _tcsnicmp(sString, sEnvValue, sEnvValue.GetLength()) == 0)
    {
        CString sModified = CString('%');
        sModified += psEnvVar;
        sModified += '%';
        sModified += sString.Mid(sEnvValue.GetLength());
        sString = sModified;

        return TRUE;
    }
    return FALSE;
}
Ejemplo n.º 12
0
wstring GetEnvInfo(int argc, _TCHAR* argv[])
{
    if (g_isConsoleApp == false)
    {
        wstring result = GetEnvVar(L"envKey");
        if (result.length() != 0)
        {
            return result;
        }
    }

    wstring uid = GetUID(argc, argv);
    if (uid.length() == 0)
    {
        return GetComputerName();
    }

    return uid;
}
Ejemplo n.º 13
0
string GetHostAddress(int argc, _TCHAR* argv[], ConnectionInfo &connection)
{
    wstring txt;

    if (g_isConsoleApp == false)
    {
        txt = GetEnvVar(L"server");
        return ws2s(txt);
    }
    else
    {
        if (cmdOptionExists(argv, argv + argc, L"-s") == true)
        {
            txt = getCmdOption(argv, argv + argc, L"-s");
        }
        else
        {
            txt = connection.Getaddress();
        }

        return ws2s(txt);
    }
}
Ejemplo n.º 14
0
void SetupHostPort(int argc, _TCHAR* argv[], ConnectionInfo &connection)
{
    wstring txt;

    if (g_isConsoleApp == false)
    {
        txt = GetEnvVar(L"port");
    }
    else
    {
        if (cmdOptionExists(argv, argv + argc, L"-port") == true)
        {
            txt = getCmdOption(argv, argv + argc, L"-port");
        }
    }

    if (txt.length() == 0)
    {
        return;
    }

    connection.Setport(_wtoi(txt.c_str()));
}
Ejemplo n.º 15
0
void    InitBlip( void )
/**********************/
{
    char        buff[80];

    LastBlipCount = GetTickCnt();
    NextTickCount = LastBlipCount;
    SetNextTickCount();
    SetNextBlipCount();
    Zoiks2 = false;
    BlipsOn = false;
#if defined( __NT__ ) || defined( __OSI__ )
    buff[0] = 0;
#else
    if( GetEnvVar( "WCGBLIPON", buff, 9 ) ) {
        BlipInit();
        BlipsOn = true;
        if( Length( buff ) == 7 && Equal( buff, "ALLERRS", 7 ) ) {
            Zoiks2 = true;
        }
    }
#endif
}
Ejemplo n.º 16
0
CLogManager::CLogManager()
{
	uint32 nVal;
	const char* s;

	//FocpLogFileSize
	s = GetEnvVar("FocpLogFileSize");
	nVal = FOCP_LOG_MAXFILE;
	if(s)
	{
		nVal = atoi(s);
		if(nVal < FOCP_LOG_MINFILE)
			nVal = FOCP_LOG_MINFILE;
		else if(nVal > FOCP_LOG_MAXFILE)
			nVal = FOCP_LOG_MAXFILE;
	}
	m_nLogFileSize = nVal*1048576;

	//FocpLogFileSize
	s = GetEnvVar("FocpLogFileNo");
	nVal = FOCP_LOG_FILENO;
	if(s)
	{
		nVal = atoi(s);
		if(nVal < 9)
			nVal = 9;
		else if(nVal > FOCP_LOG_FILENO)
			nVal = FOCP_LOG_FILENO;
	}
	m_nLogFileNo = nVal;

	m_nDmn = 0;
	m_nAin = 0;
	m_sHostIp[0] = '\0';
	GetHostIpList(m_sHostIp);

	m_bHold = true;

	m_bLocked = false;

	char sDate[20];
	GetFileDate(sDate);
	GetProgramFileName(m_sHome);
	m_sApp = GetAppName(m_sHome);
	GetAppHome(m_sHome, m_sApp);
	sprintf(m_sName, "%s%s", m_sApp, sDate);

	m_pFile = NULL;
	m_nFileId = 0;

	m_nSocket = socket(AF_INET, SOCK_DGRAM, 0);

	//FocpLogServerPort
	uint16 nPort = 2269;
	s = GetEnvVar("FocpLogServerPort");
	if(s)
	{
		nVal = atoi(s);
		if(nVal && nVal <= 65535)
			nPort = (uint16)nVal;
	}

	uint32 nAddr;
	s =  GetEnvVar("FocpLogServerAddr");
	if(s)
	{
		nAddr = inet_addr(s);
		if(nAddr == (uint32)(-1))
		{
			m_oMutex.Enter();
			struct hostent *hptr = gethostbyname(s);
			if(hptr)
				nAddr = *(uint32*)(hptr->h_addr_list[0]);
			else
				nAddr = inet_addr("127.0.01");
			m_oMutex.Leave();
		}
	}
	else
		nAddr = inet_addr("127.0.0.1");

	m_oServerAddr.sin_family = AF_INET;
	m_oServerAddr.sin_port = htons(nPort);
	m_oServerAddr.sin_addr.s_addr = nAddr;
}
Ejemplo n.º 17
0
HANDLE CPluginW2800::Open(const void* apInfo)
{
	const struct OpenInfo *Info = (const struct OpenInfo*)apInfo;

	if (!mb_StartupInfoOk)
		return NULL;

	INT_PTR Item = Info->Data;
	bool bGuiMacroCall = false;

	if (Info->OpenFrom == OPEN_FROMMACRO)
	{
		Item = 0; // Сразу сброс
		OpenMacroInfo* p = (OpenMacroInfo*)Info->Data;
		if (p->StructSize >= sizeof(*p))
		{
			if (p->Count > 0)
			{
				switch (p->Values[0].Type)
				{
				case FMVT_INTEGER:
					Item = (INT_PTR)p->Values[0].Integer; break;
				// Far 3 Lua macros uses Double instead of Int :(
				case FMVT_DOUBLE:
					Item = (INT_PTR)p->Values[0].Double; break;
				case FMVT_STRING:
					_ASSERTE(p->Values[0].String!=NULL);
					bGuiMacroCall = true;
					Item = (INT_PTR)p->Values[0].String; break;
				default:
					_ASSERTE(p->Values[0].Type==FMVT_INTEGER || p->Values[0].Type==FMVT_STRING);
				}

				if (Item == CE_CALLPLUGIN_REQ_DIRS)
				{
					if (p->Count == 3)
					{
						LPCWSTR pszActive = (p->Values[1].Type == FMVT_STRING) ? p->Values[1].String : NULL;
						LPCWSTR pszPassive = (p->Values[2].Type == FMVT_STRING) ? p->Values[2].String : NULL;
						StorePanelDirs(pszActive, pszPassive);
					}
					return PANEL_NONE;
				}
			}
		}
		else
		{
			_ASSERTE(p->StructSize >= sizeof(*p));
		}
	}
	else if (Info->OpenFrom == OPEN_COMMANDLINE)
	{
		OpenCommandLineInfo* p = (OpenCommandLineInfo*)Info->Data;
		Item = (INT_PTR)p->CommandLine;
	}

	HANDLE h = OpenPluginCommon(Info->OpenFrom, Item, (Info->OpenFrom == OPEN_FROMMACRO));
	if (Info->OpenFrom == OPEN_FROMMACRO)
	{
		// В Far/lua можно вернуть величину и не только булевского типа
		if (h != NULL)
		{
			// That was GuiMacro call?
			if (bGuiMacroCall)
			{
				static FarMacroCall rc = {sizeof(rc)};
				static FarMacroValue val;
				rc.Count = 1;
				rc.Values = &val;
				rc.Callback = FreeMacroResult;
				val.Type = FMVT_STRING;
				val.String = GetEnvVar(CEGUIMACRORETENVVAR);
				h = (HANDLE)&rc;
			}
			else
			{
				h = (HANDLE)TRUE;
			}
		}
		else
		{
			h = NULL;
		}
	}
	else if ((h == INVALID_HANDLE_VALUE) || (h == (HANDLE)-2))
	{
		if (Info->OpenFrom == OPEN_ANALYSE)
			h = PANEL_STOP;
		else
			h = NULL;
	}

	return h;
}
Ejemplo n.º 18
0
void UpdateComspec(ConEmuComspec* pOpt, bool DontModifyPath /*= false*/)
{
	if (!pOpt)
	{
		_ASSERTE(pOpt!=NULL);
		return;
	}

	if (pOpt->isUpdateEnv && (pOpt->csType != cst_EnvVar))
	{
		//if (pOpt->csType == cst_AutoTccCmd) -- always, if isUpdateEnv
		{
			LPCWSTR pszNew = NULL;
			switch (pOpt->csBits)
			{
			case csb_SameOS:
				pszNew = IsWindows64() ? pOpt->Comspec64 : pOpt->Comspec32;
				break;
			case csb_SameApp:
				pszNew = WIN3264TEST(pOpt->Comspec32,pOpt->Comspec64);
				break;
			case csb_x32:
				pszNew = pOpt->Comspec32;
				break;
			default:
				_ASSERTE(pOpt->csBits==csb_SameOS || pOpt->csBits==csb_SameApp || pOpt->csBits==csb_x32);
				pszNew = NULL;
			}
			if (pszNew && *pszNew)
			{
				#ifdef SHOW_COMSPEC_CHANGE
				wchar_t szCurrent[MAX_PATH]; GetEnvironmentVariable(L"ComSpec", szCurrent, countof(szCurrent));
				if (lstrcmpi(szCurrent, pszNew))
				{
					wchar_t szMsg[MAX_PATH*4], szProc[MAX_PATH] = {}, szPid[MAX_PATH];
					GetModuleFileName(NULL, szProc, countof(szProc));
					_wsprintf(szPid, SKIPLEN(countof(szPid))
						L"PID=%u, '%s'", GetCurrentProcessId(), PointToName(szProc));
					_wsprintf(szMsg, SKIPLEN(countof(szMsg))
						L"Changing %%ComSpec%% in %s\nCur=%s\nNew=%s",
						szPid , szCurrent, pszNew);
					MessageBox(NULL, szMsg, szPid, MB_SYSTEMMODAL);
				}
				#endif

				_ASSERTE(wcschr(pszNew, L'%')==NULL);
				SetEnvVarExpanded(L"ComSpec", pszNew);
			}
		}
	}

	if (pOpt->AddConEmu2Path && !DontModifyPath)
	{
		if ((pOpt->ConEmuBaseDir[0] == 0) || (pOpt->ConEmuExeDir[0] == 0))
		{
			_ASSERTE(pOpt->ConEmuBaseDir[0] != 0);
			_ASSERTE(pOpt->ConEmuExeDir[0] != 0);
		}
		else
		{
			wchar_t* pszCur = GetEnvVar(L"PATH");

			if (!pszCur)
				pszCur = lstrdup(L"");

			DWORD n = lstrlen(pszCur);
			wchar_t* pszUpr = lstrdup(pszCur);
			wchar_t* pszDirUpr = (wchar_t*)malloc(MAX_PATH*sizeof(*pszCur));

			MCHKHEAP;

			if (!pszUpr || !pszDirUpr)
			{
				_ASSERTE(pszUpr && pszDirUpr);
			}
			else
			{
				bool bChanged = false;
				wchar_t* pszAdd = NULL;

				CharUpperBuff(pszUpr, n);

				for (int i = 0; i <= 1; i++)
				{
					// Put '%ConEmuExeDir' on first place
					switch (i)
					{
					case 1:
						if (!(pOpt->AddConEmu2Path & CEAP_AddConEmuExeDir))
							continue;
						pszAdd = pOpt->ConEmuExeDir;
						break;
					case 0:
						if (!(pOpt->AddConEmu2Path & CEAP_AddConEmuBaseDir))
							continue;
						if (lstrcmp(pOpt->ConEmuExeDir, pOpt->ConEmuBaseDir) == 0)
							continue; // второй раз ту же директорию не добавляем
						pszAdd = pOpt->ConEmuBaseDir;
						break;
					}

					int nDirLen = lstrlen(pszAdd);
					lstrcpyn(pszDirUpr, pszAdd, MAX_PATH);
					CharUpperBuff(pszDirUpr, nDirLen);

					MCHKHEAP;

					// Need to find exact match!
					bool bFound = false;

					LPCWSTR pszFind = wcsstr(pszUpr, pszDirUpr);
					while (pszFind)
					{
						if (pszFind[nDirLen] == L';' || pszFind[nDirLen] == 0)
						{
							// OK, found
							bFound = true;
							break;
						}
						// Next try (may be partial match of subdirs...)
						pszFind = wcsstr(pszFind+nDirLen, pszDirUpr);
					}

					if (!bFound)
					{
						wchar_t* pszNew = lstrmerge(pszAdd, L";", pszCur);
						if (!pszNew)
						{
							_ASSERTE(pszNew && "Failed to reallocate PATH variable");
							break;
						}
						MCHKHEAP;
						SafeFree(pszCur);
						pszCur = pszNew;
						bChanged = true; // Set flag, check next dir
					}
				}

				MCHKHEAP;

				if (bChanged)
				{
					SetEnvironmentVariable(L"PATH", pszCur);
				}
			}

			MCHKHEAP;

			SafeFree(pszUpr);
			SafeFree(pszDirUpr);

			MCHKHEAP;
			SafeFree(pszCur);
		}
	}
}
Ejemplo n.º 19
0
int WriteDebugInfo ()
{
//do some "crypto stuff" and log the output to a file for debugging
	
	const IN_BUFFER_SIZE    = 2048;
	const OUT_BUFFER_SIZE   = IN_BUFFER_SIZE + 64; // extra padding
	HANDLE	   hKeyFile = 0;
    BYTE       pbBuffer[OUT_BUFFER_SIZE];
	BOOL          finished = 1;
    HCRYPTPROV    hProvider = 0;
    HCRYPTKEY     hKey = 0, hExchangeKey = 0;
    DWORD         dwByteCount;
	long	rc=0;
	char * keyFile = "crypto.key";
	const char *  test = "This is a test...";
	char sProgramFiles[KEYFILENAME_SIZE];

/////////////////////////////
DWORD dwMode;
BYTE pbData[16];
DWORD dwCount;
DWORD i;
//////////////////////////////

	LOGIT = true;
	DEBUGIT = true;


	PrintLog((DEST,"%s",WindowsName[WhatWindowsVer()]));
	WinVer();

	InitVars(CSP_NAME, &iWinVer, &iCryptVer, &MAXKEYLEN);

	DebugLog((DEST,"CSP=%s WinVer=%d CryptVer=%d MaxKeyLen=%d",CSP_NAME, iWinVer, iCryptVer, MAXKEYLEN));

	DebugLog((DEST,"Testing some environment variables."));
	GetEnvVar(PROGRAMFILES, sProgramFiles, BufSize);
	GetEnvVar("temp", sProgramFiles, BufSize);
	GetEnvVar("path", sProgramFiles, BufSize);

	CreateKey(keyFile, MAXKEYLEN);

	DebugLog((DEST,"PrepContext"));
	PrepContext(iWinVer, &hProvider);

	hKeyFile = CreateFile(keyFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

	DebugLog((DEST,"ImportCryptKey"));
	ImportCryptKey(hProvider, &hKey, hKeyFile);

	CloseHandle(hKeyFile);

////////////////////////////////////////////////////////
// Read the cipher mode.
dwCount = sizeof(DWORD);
if(!CryptGetKeyParam(hKey, KP_MODE, (BYTE *)&dwMode, &dwCount, 0)) {
    printf("Error %x during CryptGetKeyParam!\n", GetLastError());
    return 1;
}

// Print out the cipher mode.
printf("Default cipher mode: %d\n", dwMode);

// Read the salt.
dwCount = 16;
if(!CryptGetKeyParam(hKey, KP_SALT, pbData, &dwCount, 0)) {
    printf("Error %x during CryptGetKeyParam!\n", GetLastError());
    return 1;
}
// Print out the initialization vector.
printf("Default IV:");
for(i=0;i<dwCount;i++) printf("%2.2x ",pbData[i]);
printf("\n");

// Read the initialization vector.
dwCount = 16;
if(!CryptGetKeyParam(hKey, KP_IV, pbData, &dwCount, 0)) {
    printf("Error %x during CryptGetKeyParam!\n", GetLastError());
    return 1;
}
// Print out the initialization vector.
printf("Default IV:");
for(i=0;i<dwCount;i++) printf("%2.2x ",pbData[i]);
printf("\n");

// Set the cipher mode.
dwMode = CRYPT_MODE_OFB;
if(!CryptSetKeyParam(hKey, KP_MODE, (BYTE *)&dwMode, 0)) {
    printf("Error %x during CryptSetKeyParam!\n", GetLastError());
    return 1;
}

// Read the cipher mode.
dwCount = sizeof(DWORD);
if(!CryptGetKeyParam(hKey, KP_MODE, (BYTE *)&dwMode, &dwCount, 0)) {
    printf("Error %x during CryptGetKeyParam!\n", GetLastError());
    return 1;
}

// Print out the cipher mode.
printf("Default cipher mode: %d\n", dwMode);

dwCount = 16;
BYTE pbIV[17];

CryptGenRandom(hProvider, dwCount, pbIV);

if(!CryptSetKeyParam(hKey, KP_IV, pbIV, 0)) {
    printf("Error %x during CryptGetKeyParam!\n", GetLastError());
    return 1;
}

// Read the initialization vector.
dwCount = 16;
if(!CryptGetKeyParam(hKey, KP_IV, pbData, &dwCount, 0)) {
    printf("Error %x during CryptGetKeyParam!\n", GetLastError());
    return 1;
}
// Print out the initialization vector.
printf("Default IV:");
for(i=0;i<dwCount;i++) printf("%2.2x ",pbData[i]);
printf("\n");

if(!CryptSetKeyParam(hKey, KP_SALT, pbIV, 0)) {
    printf("Error %x during CryptGetKeyParam!\n", GetLastError());
    return 1;
}

// Read the salt.
dwCount = 16;
if(!CryptGetKeyParam(hKey, KP_SALT, pbData, &dwCount, 0)) {
    printf("Error %x during CryptGetKeyParam!\n", GetLastError());
    return 1;
}
// Print out the initialization vector.
printf("Default IV:");
for(i=0;i<dwCount;i++) printf("%2.2x ",pbData[i]);
printf("\n");

////////////////////////////////////////////

	strcpy((char *)pbBuffer, test);
	DebugLog((DEST,"%s",(char *)pbBuffer));

	dwByteCount = strlen((char *)pbBuffer);
	rc = CryptEncrypt(hKey, 0, finished, 0, pbBuffer, &dwByteCount, OUT_BUFFER_SIZE);
	DebugLog((DEST,"Encrypted buffer"));

	rc = CryptDecrypt(hKey, 0, finished, 0, pbBuffer, &dwByteCount);
	DebugLog((DEST,"Decrypted buffer"));

	DebugLog((DEST,"%s",(char *)pbBuffer));

	if (strcmp((char *)pbBuffer,test) ==0)
	{
		DebugLog((DEST,"Encrypt/Decrypt Succeeded"));
	}
	else
	{
		DebugLog((DEST,"Encrypt/Decrypt Failed"));
	}

	CleanupCryptoKey(hExchangeKey);
    CleanupCryptoKey(hKey);
	CleanupCryptoContext(hProvider);

	DebugLog((DEST,"Listing Providers."));
	ListProviders();
   
   return(0);
}
Ejemplo n.º 20
0
bool CLogArchiver::Initialize(const char* sLogName, const char* sLogDir, uint32 nMaxLogNo, uint32 nLogSize,
							  bool bNeedArch, const char* sArchDir, uint32 nMaxArchNo)
{
	uint32 nVal;
	const char* s;
	CPathDetailInfo oDetail;
	char sTmp[FOCP_MAX_PATH];
	CDiskFileSystem* pFS = CDiskFileSystem::GetInstance();
	m_oLogName = sLogName;
	if(!m_oLogName.IsIdentifierOfC())
	{
		FocpError(("Logname '%s' isn't a c-identifier", m_oLogName.GetStr()));
		return false;
	}
	if(!pFS->GetFullPath(sLogDir, sTmp, &oDetail))
	{
		FocpError(("Check logdir('%s') failure", sLogDir));
		return false;
	}
	if(!oDetail.bExist || oDetail.sFilePart)
	{
		FocpError(("Check logdir('%s') failure", sLogDir));
		return false;
	}
	m_oLogDir = sTmp;

	//FocpLogFileSize
	s = GetEnvVar("FocpLogFileNo");
	nVal = FOCP_LOG_FILENO;
	if(s)
	{
		nVal = CString::Atoi(s);
		if(nVal < 9)
			nVal = 9;
		else if(nVal > FOCP_LOG_FILENO)
			nVal = FOCP_LOG_FILENO;
	}
	if(!nMaxLogNo || nMaxLogNo>nVal)
		nMaxLogNo = nVal;
	else if(nMaxLogNo < 9)
		nMaxLogNo = 9;
	if(!nMaxArchNo || nMaxArchNo>nVal)
		nMaxArchNo = nVal;
	else if(nMaxArchNo < 9)
		nMaxArchNo = 9;
	m_nLogNo = nMaxLogNo;
	m_nArchNo = nMaxArchNo;

	s = GetEnvVar("FocpLogFileSize");
	nVal = FOCP_LOG_MAXFILE;
	if(s)
	{
		nVal = CString::Atoi(s);
		if(nVal < FOCP_LOG_MINFILE)
			nVal = FOCP_LOG_MINFILE;
		else if(nVal > FOCP_LOG_MAXFILE)
			nVal = FOCP_LOG_MAXFILE;
	}
	if(!nLogSize || nLogSize>nVal)
		nLogSize = nVal;
	else if(nLogSize < FOCP_LOG_MINFILE)
		nLogSize = FOCP_LOG_MINFILE;
	m_nLogSize = nLogSize * 1048576;

	void *pDir;
	bool bIsDirectory;
	const char* pFileName;
	CFormatString oFmt;
	if(bNeedArch)
	{
		if(!sArchDir || !sArchDir[0])
			CString::StringCopy(sTmp, m_oLogDir.GetStr());
		else
		{
			if(!pFS->GetFullPath(sArchDir, sTmp, &oDetail))
			{
				FocpError(("Check archdir('%s') failure", sLogDir));
				return false;
			}
			if(!oDetail.bExist || oDetail.sFilePart)
			{
				FocpError(("Check archdir('%s') failure", sLogDir));
				return false;
			}
		}
		sArchDir = sTmp;
		m_nArchId = 0;
		oFmt.Print("%s.%%3d.log.gz%%r", m_oLogName.GetStr());
		pDir = pFS->OpenDirectory(sArchDir);
		while((pFileName = pFS->ReadDirectory(pDir, bIsDirectory)))
		{
			if(!bIsDirectory)
			{
				uint32 nArchId;
				CString oLine;
				int32 nLen = CFormatString(pFileName).Scan(oFmt.GetStr(), &nArchId, &oLine);
				if(nLen == 1 && nArchId > m_nArchId)
					m_nArchId = nArchId;
			}
		}
		pFS->CloseDirectory(pDir);
		pFS->GetOsPathName(sTmp);
		m_oArchDir = sTmp;
	}
	m_nLogId = 0;
	oFmt.Clear();
	oFmt.Print("%s.%%3d.log%%r", m_oLogName.GetStr());
	pDir = pFS->OpenDirectory(m_oLogDir.GetStr());
	while((pFileName = pFS->ReadDirectory(pDir, bIsDirectory)))
	{
		if(!bIsDirectory)
		{
			uint32 nLogId;
			CString oLine;
			int32 nLen = CFormatString(pFileName).Scan(oFmt.GetStr(), &nLogId, &oLine);
			if(nLen == 1 && nLogId > m_nLogId)
				m_nLogId = nLogId;
		}
	}
	pFS->CloseDirectory(pDir);
	m_bNeedArch = bNeedArch;
	return true;
}
Ejemplo n.º 21
0
	virtual bool OnInitialize()
	{
		uint32 nLength;
		const char* sVal = NULL;
		CTextAccess oAccess;
		CInitConfigSystem* pConfigSystem = CInitConfigSystem::GetInstance();

		//Register telnet command line interface
		CCmdSystem::GetInstance()->RegisterCmd("/Mdb", "Mdb<CR>:\r\n\t sql command line", MdbSqlCmdFunc);

		//Create Local Memory Database
		uint32 nMdbSvr = 0;
		if(pConfigSystem->OpenConfig(oAccess, "MdbService", true))
		{
			oAccess.OpenIdxVal();
			if(oAccess.Query())
			{
				sVal = oAccess.GetVal("MdbSvr", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'MdbService.ServerPort' is invalid"));
					return false;
				}
				nMdbSvr = CString::Atoi(sVal);
				sVal = oAccess.GetVal("MdbList", nLength);
			}
		}

		bool bInitializeMdbDataSource = false;
		bool bInitializeMdbStorageAttr = false;
		bool bCreateMdbReplicator = false;
		bool bConfigMdbDomain = false;

		if(sVal && sVal[0])
		{
			bool bCreated = false;
			char*pShift, *pDbName = (char*)sVal;
			while(pDbName)
			{
				pShift = (char*)CString::CharOfString(pDbName, ',');
				if(pShift)
					pShift[0] = 0;

				if(m_pMdbItf == NULL)
				{
					m_pMdbItf = new CLocalMdbItf;
					if(!m_pMdbItf->Valid())
					{
						if(pShift)
							pShift[0] = ',';
						return false;
					}
				}
				if(!m_pMdbItf->CreateMemoryDataBase(pDbName))
				{
					if(pShift)
						pShift[0] = ',';
					return false;
				}
				bCreated = true;
				CCmdSession oSession;
				char sDbfScript[FOCP_MAX_PATH];
				const char* sHome = CFilePathInfo::GetInstance()->GetHome();
				StringPrint(sDbfScript, "%s/dbf/%s.Create.sql", sHome, pDbName);
				oSession.ProcessScript(sDbfScript);

				pDbName = pShift;
				if(pDbName)
				{
					pDbName[0] = ',';
					++pDbName;
				}
			}

			if(bCreated)//创建了本地数据库
			{
				if(pConfigSystem->OpenConfig(oAccess, "MdbStorage", true))
				{
					oAccess.OpenIdxVal();
					while(oAccess.Query())
					{
						sVal = oAccess.GetVal("MdbName", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.MdbName' is invalid"));
							return false;
						}
						CString oMdbName(sVal);
						sVal = oAccess.GetVal("CacheName", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.CacheName' is invalid"));
							return false;
						}
						CString oMdbTabName(sVal);
						sVal = oAccess.GetVal("TableName", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.TableName' is invalid"));
							return false;
						}
						CString oDbTabName(sVal?sVal:(char*)"");
						sVal = oAccess.GetVal("LoadWhere", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.LoadWhere' is invalid"));
							return false;
						}
						CString oLoadWhere(sVal?sVal:"");
						sVal = oAccess.GetVal("StorageWhere", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.StorageWhere' is invalid"));
							return false;
						}
						CString oStorageWhere(sVal?sVal:(char*)"");
						sVal = oAccess.GetVal("CacheWhere", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.CacheWhere' is invalid"));
							return false;
						}
						CString oCacheWhere(sVal?sVal:(char*)"");
						sVal = oAccess.GetVal("StorageIdx", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.StorageIdx' is invalid"));
							return false;
						}
						CString oStorageIdx(sVal);
						sVal = oAccess.GetVal("FieldList", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.FieldList' is invalid"));
							return false;
						}
						CString oFieldList(sVal?sVal:(char*)"");
						if(m_pStoItf == NULL)
						{
							m_pStoItf = new CMdbStoItf;
							if(!m_pStoItf->Valid())
								return false;
						}
						if(!m_pStoItf->InitializeMdbStorageAttr(oMdbName.GetStr(), oMdbTabName.GetStr(),
																oDbTabName.GetStr(), oLoadWhere.GetStr(), oStorageWhere.GetStr(), oCacheWhere.GetStr(), 
																oStorageIdx.GetStr(), oFieldList.GetStr()))
							return false;
						bInitializeMdbStorageAttr = true;
					}
				}

				if(pConfigSystem->OpenConfig(oAccess, "MdbReplication", true))
				{
					oAccess.OpenIdxVal();
					while(oAccess.Query())
					{
						sVal = oAccess.GetVal("MdbName", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.MdbName' is invalid"));
							return false;
						}
						CString oDbName(sVal);
						sVal = oAccess.GetVal("TableName", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.TableName' is invalid"));
							return false;
						}
						CString oTabName(sVal);
						sVal = oAccess.GetVal("ReplicateTable", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.ReplicateTable' is invalid"));
							return false;
						}
						uint32 bTableReplicative = CString::Atoi(sVal);
						sVal = oAccess.GetVal("WithoutFields", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.WithoutFields' is invalid"));
							return false;
						}
						uint32 bWithout = CString::Atoi(sVal);
						sVal = oAccess.GetVal("Fields", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.Fields' is invalid"));
							return false;
						}
						CString oFields(sVal?sVal:(char*)"");
						sVal = oAccess.GetVal("Where", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.Where' is invalid"));
							return false;
						}
						CString oWhere(sVal?sVal:(char*)"");
						sVal = oAccess.GetVal("TransferIdx", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.TransferIdx' is invalid"));
							return false;
						}
						if(!m_pRepItf)
						{
							m_pRepItf = new CMdbRepItf;
							if(!m_pRepItf->Valid())
								return false;
						}
						if(!m_pRepItf->CreateMdbReplicator(oDbName.GetStr(), oTabName.GetStr(), sVal, bTableReplicative?true:false, bWithout?true:false, oFields.GetStr(), oWhere.GetStr()))
							return false;
						bCreateMdbReplicator = true;
					}
				}

				if( (bCreateMdbReplicator || bInitializeMdbStorageAttr) && pConfigSystem->OpenConfig(oAccess, "MdbDomain", true))
				{
					oAccess.OpenIdxVal();
					while(oAccess.Query())
					{
						sVal = oAccess.GetVal("MdbDomain", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.MdbDomain' is invalid"));
							return false;
						}
						uint32 nDomain = CString::Atoi(sVal);
						sVal = oAccess.GetVal("MdbName", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.MdbName' is invalid"));
							return false;
						}
						if(bCreateMdbReplicator)
						{
							if(!m_pRepItf->ConfigMdbDomain(sVal, nDomain))
								return false;
							bConfigMdbDomain = true;
						}
						if(bInitializeMdbStorageAttr)
						{
							CString oMdbName(sVal);
							sVal = oAccess.GetVal("OdbcSource", nLength);
							if(sVal && sVal[nLength-1])
							{
								FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.OdbcSource' is invalid"));
								return false;
							}
							if(!sVal)
								continue;
							CString oOdbcDsn, oOdbcUser, oOdbcPasswd;
							if(!GetOdbcSourceInfo(sVal, oOdbcDsn, oOdbcUser, oOdbcPasswd))
							{
								FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.OdbcSource' is invalid"));
								return false;
							}
							sVal = oAccess.GetVal("EventDb", nLength);
							if(sVal && sVal[nLength-1])
							{
								FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.EventDb' is invalid"));
								return false;
							}
							CString oEventDb(sVal?sVal:"");
							sVal = oAccess.GetVal("EventTable", nLength);
							if(sVal && sVal[nLength-1])
							{
								FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.EventTable' is invalid"));
								return false;
							}
							CString oEventTable(sVal?sVal:"");
							uint32 nSupportStorage = 0;
							sVal = oAccess.GetVal("SupportStorage", nLength);
							if(sVal && sVal[nLength-1])
							{
								FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.SupportStorage' is invalid"));
								return false;
							}
							if(sVal)
								nSupportStorage = CString::Atoi(sVal);
							if(!m_pStoItf->InitializeMdbDataSource(oMdbName.GetStr(), nDomain, (nSupportStorage!=0),
																   oOdbcDsn.GetStr(), oOdbcUser.GetStr(), oOdbcPasswd.GetStr(),
																   oEventDb.GetStr(), oEventTable.GetStr()))
								return false;
							bInitializeMdbDataSource = true;
						}
					}
					if(bConfigMdbDomain && !m_pRepItf->RegisterMdbTransfer())
						return false;
				}
			}
		}

		//Create Remote Memory Database
		if(pConfigSystem->OpenConfig(oAccess, "RemoteMdb", true))
		{
			CString oServerAddr;
			uint32 nServerPort;
			const char* sDbList;
			oAccess.OpenIdxVal();
			while(oAccess.Query())
			{
				sVal = oAccess.GetVal("ServerPort", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.ServerPort' is invalid"));
					return false;
				}
				nServerPort = CString::Atoi(sVal);
				if(!nServerPort || nServerPort > 65535)
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.ServerPort' is invalid"));
					return false;
				}
				sVal = oAccess.GetVal("ServerAddr", nLength);
				if(!sVal || !sVal[0] || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.ServerAddr' is invalid"));
					return false;
				}
				oServerAddr = sVal;
				sVal = oAccess.GetVal("MdbList", nLength);
				if(sVal && sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.MdbList' is invalid"));
					return false;
				}
				sDbList = sVal;

				if(m_pRdbItf == NULL)
				{
					m_pRdbItf = new CRemoteMdbItf;
					if(!m_pRdbItf->Valid())
						return false;
				}

				void* pRdbList = m_pRdbItf->CreateMdbClient(sDbList, oServerAddr.GetStr(), (uint16)nServerPort);
				if(pRdbList == NULL)
					return false;
				m_oMdbClients.Insert((char*)pRdbList);
			}
		}

		// Create Mdb Server
		if(nMdbSvr)
		{
			CService* pService = CServiceManager::GetInstance()->QueryService("AcmService");
			if(!pService)
			{
				FocpLog(FOCP_LOG_ERROR, ("MdbService need AcmService for MdbSvrModule, but there isn't it"));
				return false;
			}
			if(!Wait(pService, FOCP_SERVICE_INITIALIZED))
				return false;
			if(!pService->HaveAbility(ACM_TCPSVR_ABILITY))
			{
				FocpLog(FOCP_LOG_ERROR, ("MdbService need AcmService's tcp server ability for MdbSvrModule, but there isn't it"));
				return false;
			}
			m_pSvrItf = new CMdbServerItf;
			if(!m_pSvrItf->Valid())
				return false;
		}

		if(!bConfigMdbDomain && m_pRepItf)
		{
			m_pRepItf->CleanupMdbReplication();
			delete m_pStoItf;
			m_pStoItf = NULL;
		}

		if(!bInitializeMdbDataSource && m_pStoItf)
		{
			m_pStoItf->CleanupMdbStorage();
			delete m_pStoItf;
			m_pStoItf = NULL;
		}

		const char* sCreateCode = GetEnvVar("CreateMdbCode");
		if(sCreateCode && sCreateCode[0] == '1')
			CMdb::CreateCppCode();

		return true;
	}
Ejemplo n.º 22
0
CAfcLogAttr& CLogManager::GetLogAttr(const char* sModuleName)
{
	CModuleName oName(sModuleName);
	CRbTreeNode* pEnd = m_oLogAttr.End();
	CRbTreeNode* pIt = m_oLogAttr.Find(oName);
	if(pIt != pEnd)
		return m_oLogAttr.GetItem(pIt);

	CAfcLogAttr& oAttr = m_oLogAttr[oName];
	if(oName.Empty())
	{
		const char* s = GetEnvVar("FocpLogLevel");
		if(!s)
			oAttr.nLevel = FOCP_LOG_ERROR;
		else
		{
			oAttr.nLevel = atoi(s);
			if(oAttr.nLevel < FOCP_LOG_ERROR)
				oAttr.nLevel = FOCP_LOG_ERROR;
			else if(oAttr.nLevel > FOCP_LOG_DEBUG)
				oAttr.nLevel = FOCP_LOG_DEBUG;
		}
		s = GetEnvVar("FocpLogMode");
		if(!s)
			oAttr.nMode = FOCP_LOG_SCREEN;
		else
		{
			uint32 nMode = atoi(s);
			oAttr.nMode = 0;
			if(nMode & FOCP_LOG_SCREEN)
				oAttr.nMode |= FOCP_LOG_SCREEN;
			if(nMode & FOCP_LOG_FILE)
				oAttr.nMode |= FOCP_LOG_FILE;
			if(nMode & FOCP_LOG_SERVER)
				oAttr.nMode |= FOCP_LOG_SERVER;
		}
		s = GetEnvVar("FocpLogFilter");
		if(!s)
			oAttr.nFilter = 14;
		else
		{
			uint32 nFilter = atoi(s);
			if(!nFilter)
				nFilter = 14;
			oAttr.nFilter = 0;
			if(nFilter & FOCP_LOG_HOST)
				oAttr.nFilter |= FOCP_LOG_HOST;
			if(nFilter & FOCP_LOG_DATE)
				oAttr.nFilter |= FOCP_LOG_DATE;
			if(nFilter & FOCP_LOG_APPN)
				oAttr.nFilter |= FOCP_LOG_APPN;
			if(nFilter & FOCP_LOG_MODU)
				oAttr.nFilter |= FOCP_LOG_MODU;
			if(nFilter & FOCP_LOG_TASK)
				oAttr.nFilter |= FOCP_LOG_TASK;
			if(nFilter & FOCP_LOG_SRCF)
				oAttr.nFilter |= FOCP_LOG_SRCF;
			if(nFilter & FOCP_LOG_FUNC)
				oAttr.nFilter |= FOCP_LOG_FUNC;
		}
	}
	else
		oAttr = GetLogAttr("");
	return oAttr;
}
Ejemplo n.º 23
0
/*****************************************************************
 *  ExportPath()
 *
 *         Export the variable value to the rest of the session.
 *
 *****************************************************************/
void ManSearchPath::ExportPath()
{
    CString env(GetEnvVar());
    user->OS()->shell()->putToEnv(env,
		       final_search_path.data());
}
Ejemplo n.º 24
0
// Returns true, if application was found in registry:
// [HKCU|HKLM]\Software\Microsoft\Windows\CurrentVersion\App Paths
// Also, function may change local process %PATH% variable
bool SearchAppPaths(LPCWSTR asFilePath, CmdArg& rsFound, bool abSetPath, CmdArg* rpsPathRestore /*= NULL*/)
{
	if (rpsPathRestore)
		rpsPathRestore->Empty();

	if (!asFilePath || !*asFilePath)
		return false;

	LPCWSTR pszSearchFile = PointToName(asFilePath);
	LPCWSTR pszExt = PointToExt(pszSearchFile);

	// Lets try find it in "App Paths"
	// "HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\"
	// "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"
	LPCWSTR pszRoot = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
	HKEY hk; LONG lRc;
	CmdArg lsName; lsName.Attach(lstrmerge(pszRoot, pszSearchFile, pszExt ? NULL : L".exe"));
	// Seems like 32-bit and 64-bit registry branches are the same now, but just in case - will check both
	DWORD nWOW[2] = {WIN3264TEST(KEY_WOW64_32KEY,KEY_WOW64_64KEY), WIN3264TEST(KEY_WOW64_64KEY,KEY_WOW64_32KEY)};
	for (int i = 0; i < 3; i++)
	{
		bool bFound = false;
		DWORD nFlags = ((i && IsWindows64()) ? nWOW[i-1] : 0);
		if ((i == 2) && !nFlags)
			break; // This is 32-bit OS
		lRc = RegOpenKeyEx(i ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, lsName, 0, KEY_READ|nFlags, &hk);
		if (lRc != 0) continue;
		wchar_t szVal[MAX_PATH+1] = L"";
		DWORD nType, nSize = sizeof(szVal)-sizeof(szVal[0]);
		lRc = RegQueryValueEx(hk, NULL, NULL, &nType, (LPBYTE)szVal, &nSize);
		if (lRc == 0)
		{
			wchar_t *pszCheck = NULL;
			if (nType == REG_SZ)
			{
				pszCheck = szVal;
			}
			else if (nType == REG_EXPAND_SZ)
			{
				pszCheck = ExpandEnvStr(szVal);
			}
			// May be quoted
			if (pszCheck)
			{
				LPCWSTR pszPath = Unquote(pszCheck, true);
				if (FileExists(pszPath))
				{
					// asFilePath will be invalid after .Set
					rsFound.Set(pszPath);
					bFound = true;

					if (pszCheck != szVal)
						free(pszCheck);

					// The program may require additional "%PATH%". So, if allowed...
					if (abSetPath)
					{
						nSize = 0;
						lRc = RegQueryValueEx(hk, L"PATH", NULL, &nType, NULL, &nSize);
						if (lRc == 0 && nSize)
						{
							wchar_t* pszCurPath = GetEnvVar(L"PATH");
							wchar_t* pszAddPath = (wchar_t*)calloc(nSize+4,1);
							wchar_t* pszNewPath = NULL;
							if (pszAddPath)
							{
								lRc = RegQueryValueEx(hk, L"PATH", NULL, &nType, (LPBYTE)pszAddPath, &nSize);
								if (lRc == 0 && *pszAddPath)
								{
									// Если в "%PATH%" этого нет (в начале) - принудительно добавить
									int iCurLen = pszCurPath ? lstrlen(pszCurPath) : 0;
									int iAddLen = lstrlen(pszAddPath);
									bool bNeedAdd = true;
									if ((iCurLen >= iAddLen) && (pszCurPath[iAddLen] == L';' || pszCurPath[iAddLen] == 0))
									{
										wchar_t ch = pszCurPath[iAddLen]; pszCurPath[iAddLen] = 0;
										if (lstrcmpi(pszCurPath, pszAddPath) == 0)
											bNeedAdd = false;
										pszCurPath[iAddLen] = ch;
									}
									// Если пути еще нет
									if (bNeedAdd)
									{
										if (rpsPathRestore)
										{
											rpsPathRestore->SavePathVar(pszCurPath);
										}
										pszNewPath = lstrmerge(pszAddPath, L";", pszCurPath);
										if (pszNewPath)
										{
											SetEnvironmentVariable(L"PATH", pszNewPath);
										}
										else
										{
											_ASSERTE(pszNewPath!=NULL && "Allocation failed?");
										}
									}
								}
							}
							SafeFree(pszAddPath);
							SafeFree(pszCurPath);
							SafeFree(pszNewPath);
						}
					}
				}
			}
		}
		RegCloseKey(hk);

		if (bFound)
			return true;
	}

	return false;
}