コード例 #1
0
ファイル: win-firewall.cpp プロジェクト: averkhaturau/InEfAn
WindowsFirewall::FirewallStatus WindowsFirewall::getFirewallStatus(std::wstring const& imageName)
{
    FirewallStatus result = UNKNOWN;

    if (!fwProfile) {
        return result;
    }

    _COM_SMARTPTR_TYPEDEF(INetFwAuthorizedApplication,  __uuidof(INetFwAuthorizedApplication));
    _COM_SMARTPTR_TYPEDEF(INetFwAuthorizedApplications, __uuidof(INetFwAuthorizedApplications));

    try {
        _bstr_t procImgFilename(imageName.c_str());
        INetFwAuthorizedApplicationsPtr fwApps;
        INetFwAuthorizedApplicationPtr fwApp;

        _com_util::CheckError(fwProfile->get_AuthorizedApplications(&fwApps));

        if (SUCCEEDED(fwApps->Item(procImgFilename, &fwApp))) {
            VARIANT_BOOL fwEnabled;
            _com_util::CheckError(fwApp->get_Enabled(&fwEnabled));

            result = (fwEnabled == VARIANT_FALSE ? BLOCKED : ALLOWED);
        } else {
            result = DOESNT_EXIST;
        }
    } catch (_com_error&) {
    }

    return result;
}
コード例 #2
0
ファイル: win-firewall.cpp プロジェクト: averkhaturau/InEfAn
bool WindowsFirewall::addApplicationPolicy(std::wstring const& imageName, std::wstring const& applicationName)
{
    auto tryAddApp = [&]() {
        try {
            _COM_SMARTPTR_TYPEDEF(INetFwAuthorizedApplication,  __uuidof(INetFwAuthorizedApplication));
            _COM_SMARTPTR_TYPEDEF(INetFwAuthorizedApplications, __uuidof(INetFwAuthorizedApplications));

            // query authorized firewall applications
            INetFwAuthorizedApplicationsPtr fwApps;
            _com_util::CheckError(fwProfile->get_AuthorizedApplications(&fwApps));

            // add us to this list
            INetFwAuthorizedApplicationPtr fwApp(__uuidof(NetFwAuthorizedApplication), NULL, CLSCTX_INPROC_SERVER);
            _bstr_t imgNameStr(imageName.c_str());
            _com_util::CheckError(fwApp->put_ProcessImageFileName(imgNameStr));
            _bstr_t appNameStr(applicationName.c_str());
            _com_util::CheckError(fwApp->put_Name(appNameStr));
            _com_util::CheckError(fwApps->Add(fwApp));

            return true;
        } catch (_com_error&) {
        }
        // if we are here, we got an exception
        return false;
    };

    return fwProfile && (getFirewallStatus(imageName) == ALLOWED || tryAddApp());
}
コード例 #3
0
ファイル: win-firewall.cpp プロジェクト: averkhaturau/InEfAn
WindowsFirewall::WindowsFirewall()
{
    _COM_SMARTPTR_TYPEDEF(INetFwMgr, __uuidof(INetFwMgr));
    _COM_SMARTPTR_TYPEDEF(INetFwPolicy, __uuidof(INetFwPolicy));
    fwProfile = NULL;
    try {
        INetFwMgrPtr fwMgr(__uuidof(NetFwMgr), NULL, CLSCTX_INPROC_SERVER);
        INetFwPolicyPtr fwPolicy;

        _com_util::CheckError(fwMgr->get_LocalPolicy(&fwPolicy));
        // Retrieve the firewall profile currently in effect.
        _com_util::CheckError(fwPolicy->get_CurrentProfile(&fwProfile));
    } catch (_com_error&) {
    }
}
コード例 #4
0
ファイル: vmsstringshelper.cpp プロジェクト: pedia/raidget
bool vmsStringsHelper::isUtf8String(LPCSTR psz)
{
	if (psz == NULL || *psz == 0)
		return false;

	_COM_SMARTPTR_TYPEDEF(IMultiLanguage2, __uuidof(IMultiLanguage2));
	IMultiLanguage2Ptr spML;

	spML.CreateInstance (CLSID_CMultiLanguage);
	if (spML == NULL)
		return false;

	DetectEncodingInfo enc = {0};
	int iEncLen = 1;
	LPSTR pszBuf = new char [max (strlen (psz), 1024) + 1];
	strcpy (pszBuf, psz);
	while (strlen (pszBuf) < 300)
		strcat (pszBuf, psz);
	int iLen = strlen (pszBuf);
	if (S_OK == spML->DetectInputCodepage (MLDETECTCP_8BIT, 0, pszBuf, &iLen, &enc, &iEncLen) && iEncLen == 1)
	{
		delete [] pszBuf;
		return enc.nCodePage == CP_UTF8;
	}

	delete [] pszBuf;
	return false;
}
コード例 #5
0
bool CShowActiveDirUsers::ShowUserSelectionDialog()
{
	_COM_SMARTPTR_TYPEDEF(IDsObjectPicker, IID_IDsObjectPicker);

	IDsObjectPickerPtr		ptrObjPick (CLSID_DsObjectPicker);	
	// semi-smart pointer to object
	static const int		SCOPE_INIT_COUNT = 2;
	DSOP_SCOPE_INIT_INFO	aScopeInit[SCOPE_INIT_COUNT];
	DSOP_INIT_INFO			InitInfo;
	HRESULT					hr = S_OK;
	CComBSTR				strTitle;
	CComBSTR				strMessage;

	ZeroMemory(&InitInfo, sizeof(InitInfo));

	PCWSTR Attributes[] =
	        {
	            L"objectSid",
	        };


	InitInfo.cbSize = sizeof(InitInfo);
	InitInfo.pwzTargetComputer = (LPCOLESTR)m_pObjPicker->m_bstrComputerName; 
	InitInfo.cDsScopeInfos = SCOPE_INIT_COUNT;
	InitInfo.aDsScopeInfos = aScopeInit;
	InitInfo.cAttributesToFetch = 1; //sizeof(Attributes) / sizeof(Attributes[0]);
	InitInfo.apwzAttributeNames = Attributes; 
	InitInfo.flOptions = m_pObjPicker->m_InitInfoFlags;

	ZeroMemory(aScopeInit, 	sizeof(DSOP_SCOPE_INIT_INFO) * SCOPE_INIT_COUNT);

	// Combine multiple scope types in a single array entry.
	aScopeInit[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
	aScopeInit[0].flType = m_pObjPicker->m_ScopeTypeFlags;
	aScopeInit[0].flScope = m_pObjPicker->m_ScopeFlags;
	aScopeInit[0].FilterFlags.Uplevel.flBothModes = m_pObjPicker->m_UplevelFilterFlags_Both;
	aScopeInit[0].FilterFlags.Uplevel.flMixedModeOnly = m_pObjPicker->m_UplevelFilterFlags_Mixed;
	aScopeInit[0].FilterFlags.Uplevel.flNativeModeOnly = m_pObjPicker->m_UplevelFilterFlags_Native;
	aScopeInit[0].FilterFlags.flDownlevel = m_pObjPicker->m_DownlevelFilterFlags;

	aScopeInit[1].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
	aScopeInit[1].flType = 0x37e;
	aScopeInit[1].flScope = m_pObjPicker->m_ScopeFlags;
	aScopeInit[1].FilterFlags.Uplevel.flBothModes = m_pObjPicker->m_UplevelFilterFlags_Both;
	aScopeInit[1].FilterFlags.Uplevel.flMixedModeOnly = m_pObjPicker->m_UplevelFilterFlags_Mixed;
	aScopeInit[1].FilterFlags.Uplevel.flNativeModeOnly = m_pObjPicker->m_UplevelFilterFlags_Native;
	aScopeInit[1].FilterFlags.flDownlevel = m_pObjPicker->m_DownlevelFilterFlags;

	// bail out if we could not do anything
	if (ptrObjPick == NULL || !IsOSVersionOK())
		return false;


	hr = ptrObjPick->Initialize(&InitInfo);
	if (!SUCCEEDED(hr))
	{
		return false;
	}

	// release memory from possible previous calls
	if (m_stg.hGlobal)
		ReleaseStgMedium(&m_stg);
	m_pDataObject = NULL;

	// make the call to show the dialog that we want
	hr = ptrObjPick->InvokeDialog(m_hWnd, (IDataObject**)&m_pDataObject);

	if (!SUCCEEDED(hr))
	{
		return false;
	}

	if (S_FALSE == hr)
		return false;
	else
		return true;
}