void XmlDocumentUnitTests::testGetAttributeBoolValue()
{
	struct testGetAttributeBoolValue_TestData
	{
		LPCWSTR xpath;
		LPCWSTR name;
		bool result;
	};

	std::wstring xmlfile = GetLocalFileLocation(L"store.xml");
	std::wcout << std::endl << L"Xml: " << xmlfile.c_str();
	AppSecInc::Xml::XmlDocument xml;
	xml.Load(xmlfile, CLSID_DOMDocument);

    testGetAttributeBoolValue_TestData testdata[] = 
    {
        { L"/bookstore/book[@id=1]", L"returned", false },
        { L"/bookstore/book[@id=2]", L"returned", true },
    };

    for (int i = 0; i < ARRAYSIZE(testdata); i++)
    {
		MSXML2::IXMLDOMNodePtr node = xml.SelectNode(testdata[i].xpath);
		// value
		bool result_value = xml.GetAttributeBoolValue(testdata[i].name, node);
		std::wcout << std::endl << L"Value: " << result_value;
		CPPUNIT_ASSERT(testdata[i].result == result_value);
    }
}
Exemple #2
-3
CA_API UINT __stdcall LocalGroupMembers_Deferred(MSIHANDLE hInstall)
{
	MSI_EXCEPTION_HANDLER_PROLOG;
    MsiInstall msiInstall(hInstall);

    AppSecInc::Xml::XmlDocument xmlDocument;
    xmlDocument.LoadXml(msiInstall.GetActionData());

    MSXML2::IXMLDOMNodeListPtr rows = xmlDocument.SelectNodes(L"/LocalGroupMembers/LocalGroupMember");
    MSXML2::IXMLDOMNodePtr row = NULL;
    while (NULL != (row = rows->nextNode()))
    {
        std::wstring id = xmlDocument.GetAttributeValue(L"id", row);
        std::wstring username = xmlDocument.GetNodeValue(L"Username", row);
        std::wstring groupname = xmlDocument.GetNodeValue(L"Group", row, L"");
        bool add_member = xmlDocument.GetAttributeBoolValue(L"add", row);
        bool remove_member = xmlDocument.GetAttributeBoolValue(L"remove", row);
        bool check = xmlDocument.GetAttributeBoolValue(L"check", row);

        if (remove_member && (! check || AppSecInc::LSA::LocalGroup::IsMember(groupname, username)))
        {
            msiInstall.LogInfo(_T(__FUNCTION__), L"Removing \"" + username + L"\" from \"" + groupname + L"\"");
            AppSecInc::LSA::LocalGroup::DeleteMember(groupname, username);
        }

        if (add_member && (! check || ! AppSecInc::LSA::LocalGroup::IsMember(groupname, username)))
        {
            msiInstall.LogInfo(_T(__FUNCTION__), L"Adding \"" + username + L"\" to \"" + groupname + L"\"");
            AppSecInc::LSA::LocalGroup::AddMember(groupname, username);
        }
    }

	MSI_EXCEPTION_HANDLER_EPILOG;
    return ERROR_SUCCESS;
}