예제 #1
0
파일: utility.cpp 프로젝트: jrmuizel/KStack
// returns the path to the windows directory
std::wstring GetWindowsDirectoryString()
{
	std::wstring winDir(GetSystemWindowsDirectory(NULL, 0), 0);
	GetSystemWindowsDirectory(&winDir[0], static_cast<UINT>(winDir.size()));
	// remove the terminating null
	winDir.resize(winDir.size() - 1);
	// lowercase it
	//std::transform(winDir.begin(), winDir.end(), winDir.begin(), std::ptr_fun(towlower));
	return winDir;
}
예제 #2
0
파일: Utils.cpp 프로젝트: Ocerus/Ocerus
tstring CWin32Utils::GetSystemRootDirectory()
{
	TCHAR dir[MAX_PATH];
	if(GetSystemWindowsDirectory(dir, MAX_PATH))
		return dir;
	return _T("unknown");
}
예제 #3
0
LPTSTR CCmdLineParser::ExpandMacro(LPCTSTR lpCmdBegin)
{
	size_t nMacroLen, nExpandMacroLen;
	LPTSTR lpCmdBuff = NULL;

	if ( _tcsnicmp(lpCmdBegin, _T("%SystemRoot%"), nMacroLen = sizeof ("%SystemRoot%") - 1) == 0 ||
		_tcsnicmp(lpCmdBegin, _T("%windir%"), nMacroLen = sizeof ("%windir%") - 1) == 0
		)
	{
		nExpandMacroLen = GetSystemWindowsDirectory(m_szCmd, MAX_PATH);
	}
	else if ( _tcsnicmp(lpCmdBegin, _T("%ProgramFiles%"), nMacroLen = sizeof ("%ProgramFiles%") - 1) == 0 )
	{
		if ( SHGetSpecialFolderPath(NULL, m_szCmd, CSIDL_PROGRAM_FILES, FALSE) )
		{
			nExpandMacroLen = _tcslen(m_szCmd);
		}
	}
	else if ( _tcsnicmp(lpCmdBegin, _T("%CommonProgramFiles%"), nMacroLen = sizeof ("%CommonProgramFiles%") - 1) == 0 )
	{
		if ( SHGetSpecialFolderPath(NULL, m_szCmd, CSIDL_PROGRAM_FILES_COMMON, FALSE) )
		{
			nExpandMacroLen = _tcslen(m_szCmd);
		}
	}
	else if ( _tcsnicmp(lpCmdBegin, _T("%Temp%"), nMacroLen = sizeof ("%Temp%") - 1) == 0 ||
		_tcsnicmp(lpCmdBegin, _T("%Tmp%"), nMacroLen = sizeof ("%Tmp%") - 1) == 0
		)
	{
		nExpandMacroLen = GetTempPath(MAX_PATH, m_szCmd);
	}
	else 
	{
		// 不支持的宏路径
		goto _Failed_Exit;
	}

	if ( nExpandMacroLen != 0 )
	{
		size_t dwBuffLen = nExpandMacroLen + _tcslen(lpCmdBegin + nMacroLen) + 2;

		lpCmdBuff = new TCHAR[dwBuffLen];
		if ( lpCmdBuff != NULL )
		{
			_tcscpy(lpCmdBuff, m_szCmd);
			if ( lpCmdBuff[nExpandMacroLen - 1] == _T('\\') )
			{
				nExpandMacroLen--;
			}

			_tcscpy(lpCmdBuff + nExpandMacroLen, lpCmdBegin + nMacroLen);
		}
	}

_Failed_Exit:
	return lpCmdBuff;
}
예제 #4
0
BOOL ExecuteFile( LPCTSTR lpszFilename, LPCTSTR lpszInstallParam, DWORD &dwExitCode, BOOL &bHijacked )
{
	if (!lpszFilename || !lpszInstallParam || !PathFileExists(lpszFilename))
		return FALSE;

	CString strCmdline;
	LPCTSTR pExt = _tcsrchr(lpszFilename, _T('.'));
	if( pExt && _tcsicmp( pExt, _T(".msu") ) == 0 )
	{
		TCHAR szWusaPath[MAX_PATH];
		GetSystemWindowsDirectory(szWusaPath, MAX_PATH);
		_tcscat(szWusaPath, _T("\\system32\\wusa.exe"));
		strCmdline.Format( _T("%s \"%s\" %s"), szWusaPath, lpszFilename, lpszInstallParam );
	}
	else
		strCmdline.Format( _T("\"%s\" %s"), lpszFilename, lpszInstallParam );
	
	TCHAR szCmdline[MAX_PATH] = {0};
	_tcscpy(szCmdline, strCmdline);

    STARTUPINFO si = { 0 };
	PROCESS_INFORMATION pi={0};
	
    ZeroMemory(&si, sizeof( si ));
	ZeroMemory(&pi, sizeof(pi));
    si.cb = sizeof(STARTUPINFO);
	BOOL processCreated = CreateProcess(NULL, szCmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
	if(!processCreated)
		return FALSE;
	WaitForSingleObject(pi.hProcess, INFINITE);
	
	bHijacked = FALSE;
	// 检查是否被360 拦截
	union MFILETIME
	{
		FILETIME ft;
		__int64 i64;
	};
	MFILETIME tmCreate, tmExit, tmKernel, tmUser;
	GetProcessTimes(pi.hProcess, &tmCreate.ft, &tmExit.ft, &tmKernel.ft, &tmUser.ft);
	if( tmKernel.i64==0 || tmUser.i64==0 )
		bHijacked = TRUE;
	
	dwExitCode = 0;
	GetExitCodeProcess(pi.hProcess, &dwExitCode);	
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);
	
#ifdef _DEBUG
	_tcprintf(_T("%s %s -> %d(%s)\n"), lpszFilename, lpszInstallParam, dwExitCode, bHijacked ? _T("Hijacked"):_T("OK") );
#endif
	return TRUE;
}
예제 #5
0
/*
 * Class:     sun_security_krb5_Config
 * Method:    getWindowsDirectory
 * Signature: (Z)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_sun_security_krb5_Config_getWindowsDirectory(
        JNIEnv* env, jclass configClass, jboolean isSystem) {
    TCHAR lpPath[MAX_PATH+1];
    UINT len;
    if (isSystem) {
        len = GetSystemWindowsDirectory(lpPath, MAX_PATH);
    } else {
        len = GetWindowsDirectory(lpPath, MAX_PATH);
    }
    if (len) {
        return (*env)->NewString(env, lpPath, len);
    } else {
        return NULL;
    }
}
예제 #6
0
파일: hfserver.cpp 프로젝트: AlexS2172/IVRM
bool CHFServer::Kill(DWORD dwID)
{
	_bstr_t bsKill(" -f ");
	_bstr_t bsProcID(dwID);
	bsKill+=bsProcID;
	STARTUPINFO si;
	PROCESS_INFORMATION pi;

	ZeroMemory( &si, sizeof(si) );
	si.cb = sizeof(si);
	ZeroMemory( &pi, sizeof(pi) );

	TCHAR buffPath[MAX_PATH*20];
	ZeroMemory(buffPath, sizeof(buffPath));
	GetSystemWindowsDirectory(buffPath, sizeof(buffPath));
	_bstr_t bsPath(buffPath);
	bsPath +="\\Kill.exe";

	return CreateProcess(bsPath, const_cast<LPSTR>((LPCSTR)bsKill), NULL,NULL,FALSE,0,NULL,NULL,&si, &pi)?true:false;
}
예제 #7
0
LPTSTR CCmdLineParser::ExpandMacro2(LPCTSTR lpCmdBegin)
{
	size_t nMacroLen, nExpandMacroLen;
	LPTSTR lpCmdBuff = NULL;

	if ( _tcsnicmp(lpCmdBegin, _T("SystemRoot"), nMacroLen = sizeof ("SystemRoot") - 1) == 0 )
	{
		nExpandMacroLen = GetSystemWindowsDirectory(m_szCmd, MAX_PATH);
	}
	else if ( _tcsnicmp(lpCmdBegin, _T("system32"), nMacroLen = sizeof ("system32") - 1) == 0 )
	{
		nExpandMacroLen = GetSystemDirectory(m_szCmd, MAX_PATH);
	}
	else
	{
		goto _Failed_Exit;
	}

	if ( nExpandMacroLen != 0 )
	{
		size_t dwBuffLen = nExpandMacroLen + _tcslen(lpCmdBegin + nMacroLen) + 2;

		lpCmdBuff = new TCHAR[dwBuffLen];
		if ( lpCmdBuff != NULL )
		{
			_tcscpy(lpCmdBuff, m_szCmd);
			if ( lpCmdBuff[nExpandMacroLen - 1] == _T('\\') )
			{
				nExpandMacroLen--;
			}

			_tcscpy(lpCmdBuff + nExpandMacroLen, lpCmdBegin + nMacroLen);
		}
	}

_Failed_Exit:
	return lpCmdBuff;
}
예제 #8
0
VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgInfUninstallAllF(LPCWSTR lpszClassName, LPCWSTR lpszPnPId, DWORD Flags)
{
    static WCHAR const s_wszFilter[] = L"\\inf\\oem*.inf";
    HRESULT hr;
    WCHAR wszInfDirPath[MAX_PATH];
    UINT cwcInput = RT_ELEMENTS(wszInfDirPath) - RT_ELEMENTS(s_wszFilter);
    UINT cwcWindows = GetSystemWindowsDirectory(wszInfDirPath, cwcInput);
    if (cwcWindows > 0 && cwcWindows < cwcInput)
    {
        wcscpy(&wszInfDirPath[cwcWindows], s_wszFilter);

        INFENUM_CONTEXT Context;
        Context.InfInfo.lpszClassName = lpszClassName;
        Context.InfInfo.lpszPnPId = lpszPnPId;
        Context.Flags = Flags;
        Context.hr = S_OK;
        NonStandardLogRelCrap((__FUNCTION__": Calling vboxDrvCfgEnumFiles(wszInfDirPath, vboxDrvCfgInfEnumerationCallback, &Context)"));
        hr = vboxDrvCfgEnumFiles(wszInfDirPath, vboxDrvCfgInfEnumerationCallback, &Context);
        NonStandardAssert(hr == S_OK);
        if (hr == S_OK)
        {
            hr = Context.hr;
        }
        else
        {
            NonStandardLogRelCrap((__FUNCTION__": vboxDrvCfgEnumFiles failed, hr=0x%x\n", hr));
        }
    }
    else
    {
        NonStandardLogRelCrap((__FUNCTION__": GetSystemWindowsDirectory failed, cwcWindows=%u lasterr=%u\n", cwcWindows, GetLastError()));
        NonStandardAssertFailed();
        hr = E_FAIL;
    }

    return hr;

}
예제 #9
0
static void save_font_list()
{
	std::ofstream fout("data/fontlist.txt", std::ios_base::trunc);

	font_folder_list(fout, "data");
	font_folder_list(fout, "data/font");

#if (defined _WIN32 || defined WINDOWS)
	char buf[256];
	GetSystemWindowsDirectory(buf, 256);
	strcat(buf, "\\fonts");
	font_folder_list(fout, buf);
#elif (defined _APPLE_ && defined _MACH_)

	/*
	// Well I don't know how osx actually works ....
	font_folder_list(fout, "/System/Library/Fonts");
	font_folder_list(fout, "/Library/Fonts");

	wordexp_t exp;
	wordexp("~/Library/Fonts", &exp, 0);
	font_folder_list(fout, exp.we_wordv[0]);
	wordfree(&exp);*/
#elif (defined linux || defined __linux)
	font_folder_list(fout, "/usr/share/fonts");
	font_folder_list(fout, "/usr/local/share/fonts");
	wordexp_t exp;
	wordexp("~/.fonts", &exp, 0);
	font_folder_list(fout, exp.we_wordv[0]);
	wordfree(&exp);
#endif
	//TODO: other systems

	fout << "end of list" << std::endl;

}
예제 #10
0
BOOL CCmdLineParser::ExpandEnvVars(LPTSTR lpFilePath, LPCTSTR lpEnvVars, LPCTSTR lpExtNames)
{
	TCHAR szTempBuff[MAX_PATH + 10];

	GetSystemDirectory(szTempBuff, MAX_PATH);
	append_file_name(szTempBuff, lpFilePath);
	if ( ExpandExtNames(szTempBuff, lpExtNames) )
	{
		MyGetLongPathName(szTempBuff, lpFilePath, MAX_PATH);
		return TRUE;
	}

	GetSystemWindowsDirectory(szTempBuff, MAX_PATH);
	append_file_name(szTempBuff, lpFilePath);
	if ( ExpandExtNames(szTempBuff, lpExtNames) )
	{
		MyGetLongPathName(szTempBuff, lpFilePath, MAX_PATH);
		return TRUE;
	}

	if ( (m_dwFlag & DEF_ENV_VAR) && lpEnvVars == NULL )
	{
		lpEnvVars = GetDefaultPathVar();
	}

	if ( lpEnvVars != NULL )
	{
		//
		// 展开环境变量
		//
		LPCTSTR lpVar = lpEnvVars;
		while ( !is_empty_str(lpVar)  )
		{
			size_t nVarLen;
			TCHAR c;

			while ( (c = *lpVar) != 0 )
			{
				if ( c != _T(';') && c != _T(' ') && c != _T('\t') )
				{
					break;
				}

				lpVar++;
			}

			if ( c == 0 )
			{
				break;
			}

			LPCTSTR lpNextVar = _tcschr(lpVar, _T(';'));
			if ( lpNextVar != NULL )
			{
				nVarLen = lpNextVar - lpVar;
				lpNextVar++;
			}
			else
			{
				nVarLen = _tcslen(lpVar);
			}

			if ( fix_path_separator(szTempBuff, MAX_PATH, lpVar, nVarLen) &&
				append_file_name(szTempBuff, lpFilePath) &&
				ExpandExtNames(szTempBuff, lpExtNames) )
			{
				MyGetLongPathName(szTempBuff, lpFilePath, MAX_PATH);
				return TRUE;
			}

			lpVar = lpNextVar;
		}
	}

	return FALSE;
}
예제 #11
0
// ----------------------------------------------------------------------
// File Shot Engine
// ----------------------------------------------------------------------
VOID FileShot(LPSNAPSHOT lpShot) 
{
	UINT cchExtDir;
	// Determine the Windows directory for file system scanning
	lpszExtDir = MYALLOC0(MAX_PATH * sizeof(TCHAR));
	lpszWindowsDirName = MYALLOC0(MAX_PATH * sizeof(TCHAR));
	GetSystemWindowsDirectory(lpszWindowsDirName, MAX_PATH);  // length incl. NULL character
	GetVolumePathName(lpszWindowsDirName, lpszExtDir, MAX_PATH);
	lpszExtDir[MAX_PATH] = (TCHAR)'\0';
	// Set the length of the Windows directory
	cchExtDir = _tcslen(lpszExtDir);

	//printf("%ws\n", lpszExtDir);

	if (0 < cchExtDir) {
		LPHEADFILE *lplpHFPrev;
		LPTSTR lpszSubExtDir;
		size_t i;

		lplpHFPrev = &lpShot->lpHF;
		lpszSubExtDir = lpszExtDir;
		for (i = 0; i <= cchExtDir; i++) {
			// Split each directory in string
			if (((TCHAR)';' == lpszExtDir[i]) || ((TCHAR)'\0' == lpszExtDir[i])) {
				LPHEADFILE lpHF;
				size_t j;

				lpszExtDir[i] = (TCHAR)'\0';
				j = i;

				// remove all trailing spaces and backslashes
				while (0 < j) {
					--j;
					if (((TCHAR)'\\' == lpszExtDir[j]) || ((TCHAR)' ' == lpszExtDir[j])) {
						lpszExtDir[j] = (TCHAR)'\0';
					}
					else {
						break;
					}
				}

				// if anything is left then process this directory
				if ((0 < j) && ((TCHAR)'\0' != lpszExtDir[j])) {
					lpHF = MYALLOC0(sizeof(HEADFILE));

					*lplpHFPrev = lpHF;
					lplpHFPrev = &lpHF->lpBrotherHF;

					GetFilesSnap(lpShot, lpszSubExtDir, NULL, &lpHF->lpFirstFC);
				}

				lpszSubExtDir = &lpszExtDir[i + 1];
			}
		}
	}

	// Update total count of all items
	lpShot->stCounts.cAll = lpShot->stCounts.cDirs + lpShot->stCounts.cFiles;
	// Print final file system shot count
	if ((dwBlacklist == 2 && performDynamicBlacklisting) || (performStaticBlacklisting)) {
		printf("  > Dirs: %d  Files: %d  Blacklisted Dirs: %d  Blacklisted Files: %d\n", lpShot->stCounts.cDirs,
			lpShot->stCounts.cFiles,
			lpShot->stCounts.cDirsBlacklist,
			lpShot->stCounts.cFilesBlacklist);
	}
	else {
		printf("  > Dirs: %d  Files: %d\n", lpShot->stCounts.cDirs, lpShot->stCounts.cFiles);
	}
}
예제 #12
0
파일: php_ini.c 프로젝트: Tyrael/php-src
/* {{{ php_init_config
 */
int php_init_config(void)
{
	char *php_ini_file_name = NULL;
	char *php_ini_search_path = NULL;
	int php_ini_scanned_path_len;
	char *open_basedir;
	int free_ini_search_path = 0;
	zend_file_handle fh;

	zend_hash_init(&configuration_hash, 8, NULL, config_zval_dtor, 1);

	if (sapi_module.ini_defaults) {
		sapi_module.ini_defaults(&configuration_hash);
	}

	zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
	zend_llist_init(&extension_lists.functions, sizeof(char *), (llist_dtor_func_t) free_estring, 1);

	open_basedir = PG(open_basedir);

	if (sapi_module.php_ini_path_override) {
		php_ini_file_name = sapi_module.php_ini_path_override;
		php_ini_search_path = sapi_module.php_ini_path_override;
		free_ini_search_path = 0;
	} else if (!sapi_module.php_ini_ignore) {
		int search_path_size;
		char *default_location;
		char *env_location;
		static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
#ifdef PHP_WIN32
		char *reg_location;
		char phprc_path[MAXPATHLEN];
#endif

		env_location = getenv("PHPRC");

#ifdef PHP_WIN32
		if (!env_location) {
			char dummybuf;
			int size;

			SetLastError(0);

			/*If the given bugger is not large enough to hold the data, the return value is 
			the buffer size,  in characters, required to hold the string and its terminating 
			null character. We use this return value to alloc the final buffer. */
			size = GetEnvironmentVariableA("PHPRC", &dummybuf, 0);
			if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
				/* The environment variable doesn't exist. */
				env_location = "";
			} else {
				if (size == 0) {
					env_location = "";
				} else {
					size = GetEnvironmentVariableA("PHPRC", phprc_path, size);
					if (size == 0) {
						env_location = "";
					} else {
						env_location = phprc_path;
					}
				}
			}
		}
#else
		if (!env_location) {
			env_location = "";
		}
#endif
		/*
		 * Prepare search path
		 */

		search_path_size = MAXPATHLEN * 4 + (int)strlen(env_location) + 3 + 1;
		php_ini_search_path = (char *) emalloc(search_path_size);
		free_ini_search_path = 1;
		php_ini_search_path[0] = 0;

		/* Add environment location */
		if (env_location[0]) {
			if (*php_ini_search_path) {
				strlcat(php_ini_search_path, paths_separator, search_path_size);
			}
			strlcat(php_ini_search_path, env_location, search_path_size);
			php_ini_file_name = env_location;
		}

#ifdef PHP_WIN32
		/* Add registry location */
		reg_location = GetIniPathFromRegistry();
		if (reg_location != NULL) {
			if (*php_ini_search_path) {
				strlcat(php_ini_search_path, paths_separator, search_path_size);
			}
			strlcat(php_ini_search_path, reg_location, search_path_size);
			efree(reg_location);
		}
#endif

		/* Add cwd (not with CLI) */
		if (!sapi_module.php_ini_ignore_cwd) {
			if (*php_ini_search_path) {
				strlcat(php_ini_search_path, paths_separator, search_path_size);
			}
			strlcat(php_ini_search_path, ".", search_path_size);
		}

		if (PG(php_binary)) {
			char *separator_location, *binary_location;

			binary_location = estrdup(PG(php_binary));
			separator_location = strrchr(binary_location, DEFAULT_SLASH);

			if (separator_location && separator_location != binary_location) {
				*(separator_location) = 0;
			}
			if (*php_ini_search_path) {
				strlcat(php_ini_search_path, paths_separator, search_path_size);
			}
			strlcat(php_ini_search_path, binary_location, search_path_size);
			efree(binary_location);
		}

		/* Add default location */
#ifdef PHP_WIN32
		default_location = (char *) emalloc(MAXPATHLEN + 1);

		if (0 < GetWindowsDirectory(default_location, MAXPATHLEN)) {
			if (*php_ini_search_path) {
				strlcat(php_ini_search_path, paths_separator, search_path_size);
			}
			strlcat(php_ini_search_path, default_location, search_path_size);
		}

		/* For people running under terminal services, GetWindowsDirectory will
		 * return their personal Windows directory, so lets add the system
		 * windows directory too */
		if (0 < GetSystemWindowsDirectory(default_location, MAXPATHLEN)) {
			if (*php_ini_search_path) {
				strlcat(php_ini_search_path, paths_separator, search_path_size);
			}
			strlcat(php_ini_search_path, default_location, search_path_size);
		}
		efree(default_location);

#else
		default_location = PHP_CONFIG_FILE_PATH;
		if (*php_ini_search_path) {
			strlcat(php_ini_search_path, paths_separator, search_path_size);
		}
		strlcat(php_ini_search_path, default_location, search_path_size);
#endif
	}

	PG(open_basedir) = NULL;

	/*
	 * Find and open actual ini file
	 */

	memset(&fh, 0, sizeof(fh));

	/* If SAPI does not want to ignore all ini files OR an overriding file/path is given.
	 * This allows disabling scanning for ini files in the PHP_CONFIG_FILE_SCAN_DIR but still
	 * load an optional ini file. */
	if (!sapi_module.php_ini_ignore || sapi_module.php_ini_path_override) {

		/* Check if php_ini_file_name is a file and can be opened */
		if (php_ini_file_name && php_ini_file_name[0]) {
			zend_stat_t statbuf;

			if (!VCWD_STAT(php_ini_file_name, &statbuf)) {
				if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
					fh.handle.fp = VCWD_FOPEN(php_ini_file_name, "r");
					if (fh.handle.fp) {
						fh.filename = php_ini_opened_path = expand_filepath(php_ini_file_name, NULL);
					}
				}
			}
		}

		/* Otherwise search for php-%sapi-module-name%.ini file in search path */
		if (!fh.handle.fp) {
			const char *fmt = "php-%s.ini";
			char *ini_fname;
			spprintf(&ini_fname, 0, fmt, sapi_module.name);
			fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path);
			efree(ini_fname);
			if (fh.handle.fp) {
				fh.filename = php_ini_opened_path;
			}
		}

		/* If still no ini file found, search for php.ini file in search path */
		if (!fh.handle.fp) {
			fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path);
			if (fh.handle.fp) {
				fh.filename = php_ini_opened_path;
			}
		}
	}

	if (free_ini_search_path) {
		efree(php_ini_search_path);
	}

	PG(open_basedir) = open_basedir;

	if (fh.handle.fp) {
		fh.type = ZEND_HANDLE_FP;
		RESET_ACTIVE_INI_HASH();

		zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash);

		{
			zval tmp;

			ZVAL_NEW_STR(&tmp, zend_string_init(fh.filename, strlen(fh.filename), 1));
			zend_hash_str_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path")-1, &tmp);
			if (php_ini_opened_path) {
				efree(php_ini_opened_path);
			}
			php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
		}
	}

	/* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */
	php_ini_scanned_path = getenv("PHP_INI_SCAN_DIR");
	if (!php_ini_scanned_path) {
		/* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */
		php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR;
	}
	php_ini_scanned_path_len = (int)strlen(php_ini_scanned_path);

	/* Scan and parse any .ini files found in scan path if path not empty. */
	if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) {
		struct dirent **namelist;
		int ndir, i;
		zend_stat_t sb;
		char ini_file[MAXPATHLEN];
		char *p;
		zend_file_handle fh2;
		zend_llist scanned_ini_list;
		zend_llist_element *element;
		int l, total_l = 0;
		char *bufpath, *debpath, *endpath;
		int lenpath;

		zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
		memset(&fh2, 0, sizeof(fh2));

		bufpath = estrdup(php_ini_scanned_path);
		for (debpath = bufpath ; debpath ; debpath=endpath) {
			endpath = strchr(debpath, DEFAULT_DIR_SEPARATOR);
			if (endpath) {
				*(endpath++) = 0;
			}
			if (!debpath[0]) {
				/* empty string means default builtin value
				   to allow "/foo/phd.d:" or ":/foo/php.d" */
				debpath = PHP_CONFIG_FILE_SCAN_DIR;
			}
			lenpath = (int)strlen(debpath);

			if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_alphasort)) > 0) {

				for (i = 0; i < ndir; i++) {

					/* check for any file with .ini extension */
					if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
						free(namelist[i]);
						continue;
					}
					/* Reset active ini section */
					RESET_ACTIVE_INI_HASH();

					if (IS_SLASH(debpath[lenpath - 1])) {
						snprintf(ini_file, MAXPATHLEN, "%s%s", debpath, namelist[i]->d_name);
					} else {
						snprintf(ini_file, MAXPATHLEN, "%s%c%s", debpath, DEFAULT_SLASH, namelist[i]->d_name);
					}
					if (VCWD_STAT(ini_file, &sb) == 0) {
						if (S_ISREG(sb.st_mode)) {
							if ((fh2.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
								fh2.filename = ini_file;
								fh2.type = ZEND_HANDLE_FP;

								if (zend_parse_ini_file(&fh2, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash) == SUCCESS) {
									/* Here, add it to the list of ini files read */
									l = (int)strlen(ini_file);
									total_l += l + 2;
									p = estrndup(ini_file, l);
									zend_llist_add_element(&scanned_ini_list, &p);
								}
							}
						}
					}
					free(namelist[i]);
				}
				free(namelist);
			}
		}
		efree(bufpath);

		if (total_l) {
			int php_ini_scanned_files_len = (php_ini_scanned_files) ? (int)strlen(php_ini_scanned_files) + 1 : 0;
			php_ini_scanned_files = (char *) realloc(php_ini_scanned_files, php_ini_scanned_files_len + total_l + 1);
			if (!php_ini_scanned_files_len) {
				*php_ini_scanned_files = '\0';
			}
			total_l += php_ini_scanned_files_len;
			for (element = scanned_ini_list.head; element; element = element->next) {
				if (php_ini_scanned_files_len) {
					strlcat(php_ini_scanned_files, ",\n", total_l);
				}
				strlcat(php_ini_scanned_files, *(char **)element->data, total_l);
				strlcat(php_ini_scanned_files, element->next ? ",\n" : "\n", total_l);
			}
		}
		zend_llist_destroy(&scanned_ini_list);
	} else {
		/* Make sure an empty php_ini_scanned_path ends up as NULL */
		php_ini_scanned_path = NULL;
	}

	if (sapi_module.ini_entries) {
		/* Reset active ini section */
		RESET_ACTIVE_INI_HASH();
		zend_parse_ini_string(sapi_module.ini_entries, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash);
	}

	return SUCCESS;
}