Exemplo n.º 1
0
void PrivilegeDb::GetPrivilegesMappings(const std::string &version_from,
                                        const std::string &version_to,
                                        const std::vector<std::string> &privileges,
                                        std::vector<std::string> &mappings)
{
    try_catch<void>([&] {
        auto deleteCmd = getStatement(StmtType::EDeletePrivilegesToMap);
        deleteCmd->Step();

        auto insertCmd = getStatement(StmtType::EInsertPrivilegeToMap);
        for (auto &privilege : privileges) {
            if (privilege.empty())
                continue;
            insertCmd->BindString(1, privilege);
            insertCmd->Step();
            insertCmd->Reset();
        }

        insertCmd->BindNull(1);
        insertCmd->Step();

        auto queryCmd = getStatement(StmtType::EGetPrivilegesMappings);
        queryCmd->BindString(1, version_from);
        queryCmd->BindString(2, version_to);

        mappings.clear();
        while (queryCmd->Step()) {
            std::string mapping = queryCmd->GetColumnString(0);
            LogDebug("Privilege set  in version " << version_from
                     <<" has mapping " << mapping << " in version " << version_to);
             mappings.push_back(mapping);
        }
    });
}
void CManageBookmarksDialog::SetupListView()
{
	HWND hListView = GetDlgItem(m_hDlg,IDC_MANAGEBOOKMARKS_LISTVIEW);

	m_pBookmarkListView = new CBookmarkListView(hListView);

	int iColumn = 0;

	for each(auto ci in m_pmbdps->m_vectorColumnInfo)
	{
		if(ci.bActive)
		{
			LVCOLUMN lvCol;
			TCHAR szTemp[128];

			GetColumnString(ci.ColumnType,szTemp,SIZEOF_ARRAY(szTemp));
			lvCol.mask		= LVCF_TEXT|LVCF_WIDTH;
			lvCol.pszText	= szTemp;
			lvCol.cx		= ci.iWidth;
			ListView_InsertColumn(hListView,iColumn,&lvCol);

			++iColumn;
		}
	}

	m_pBookmarkListView->InsertBookmarksIntoListView(m_AllBookmarks);

	int iItem = 0;

	/* Update the data for each of the sub-items. */
	/* TODO: This needs to be done by CBookmarkListView. */
	for(auto itr = m_AllBookmarks.begin();itr != m_AllBookmarks.end();++itr)
	{
		int iSubItem = 1;

		for each(auto ci in m_pmbdps->m_vectorColumnInfo)
		{
			/* The name column will always appear first in
			the set of columns and can be skipped here. */
			if(ci.bActive && ci.ColumnType != CManageBookmarksDialogPersistentSettings::COLUMN_TYPE_NAME)
			{
				TCHAR szColumn[256];
				GetBookmarkItemColumnInfo(*itr,ci.ColumnType,szColumn,SIZEOF_ARRAY(szColumn));
				ListView_SetItemText(hListView,iItem,iSubItem,szColumn);

				++iSubItem;
			}
		}

		++iItem;
	}

	ListView_SortItems(hListView,NManageBookmarksDialog::SortBookmarksStub,reinterpret_cast<LPARAM>(this));

	NListView::ListView_SelectItem(hListView,0,TRUE);

	m_bListViewInitialized = true;
}
Exemplo n.º 3
0
void PrivilegeDb::GetGroups(std::vector<std::string> &groups)
{
   try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetGroups);

        while (command->Step()) {
            std::string groupName = command->GetColumnString(0);
            LogDebug("Group " << groupName);
            groups.push_back(groupName);
        };
    });
}
Exemplo n.º 4
0
void PrivilegeDb::GetUserApps(uid_t uid, std::vector<std::string> &apps)
{
   try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetUserApps);
        command->BindInteger(1, static_cast<unsigned int>(uid));
        apps.clear();
        while (command->Step()) {
            std::string app = command->GetColumnString(0);
            LogDebug("User " << uid << " has app " << app << " installed");
            apps.push_back(app);
        };
    });
}
Exemplo n.º 5
0
void PrivilegeDb::GetPrivilegeGroups(const std::string &privilege,
        std::vector<std::string> &groups)
{
   try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetPrivilegeGroups);
        command->BindString(1, privilege);

        while (command->Step()) {
            std::string groupName = command->GetColumnString(0);
            LogDebug("Privilege " << privilege << " gives access to group: " << groupName);
            groups.push_back(groupName);
        };
    });
}
Exemplo n.º 6
0
void PrivilegeDb::GetPkgPrivileges(const std::string &pkgId, uid_t uid,
        std::vector<std::string> &currentPrivileges)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetPkgPrivileges);
        command->BindString(1, pkgId);
        command->BindInteger(2, static_cast<unsigned int>(uid));

        while (command->Step()) {
            std::string privilege = command->GetColumnString(0);
            LogDebug("Got privilege: " << privilege);
            currentPrivileges.push_back(privilege);
        };
    });
}
Exemplo n.º 7
0
void PrivilegeDb::GetAppIdsForPkgId(const std::string &pkgId,
        std::vector<std::string> &appIds)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetAppsInPkg);

        command->BindString(1, pkgId);
        appIds.clear();

        while (command->Step()) {
            std::string appId = command->GetColumnString (0);
            LogDebug ("Got appid: " << appId << " for pkgId " << pkgId);
            appIds.push_back(appId);
        };
    });
}
Exemplo n.º 8
0
bool PrivilegeDb::GetAppPkgId(const std::string &appId, std::string &pkgId)
{
    return try_catch<bool>([&] {
        auto command = getStatement(StmtType::EGetPkgId);
        command->BindString(1, appId);

        if (!command->Step()) {
            // No application with such appId
            return false;
        }

        // application package found in the database, get it
        pkgId = command->GetColumnString(0);

        return true;
    });
}
Exemplo n.º 9
0
void PrivilegeDb::GetDefaultMapping(const std::string &version_from,
                                    const std::string &version_to,
                                    std::vector<std::string> &mappings)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetDefaultMappings);
        command->BindString(1, version_from);
        command->BindString(2, version_to);

        mappings.clear();
        while (command->Step()) {
            std::string mapping = command->GetColumnString(0);
            LogDebug("Default Privilege from version " << version_from
                    <<" to version " << version_to << " is " << mapping);
            mappings.push_back(mapping);
        }
    });
}
Exemplo n.º 10
0
void PrivilegeDb::GetPrivilegeMappings(const std::string &version_from,
                                       const std::string &version_to,
                                       const std::string &privilege,
                                       std::vector<std::string> &mappings)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetPrivilegeMappings);
        command->BindString(1, version_from);
        command->BindString(2, version_to);
        command->BindString(3, privilege);

        mappings.clear();
        while (command->Step()) {
            std::string mapping = command->GetColumnString(0);
            LogDebug("Privilege " << privilege << " in version " << version_from
                    <<" has mapping " << mapping << " in version " << version_to);
            mappings.push_back(mapping);
        }
    });
}
void CManageBookmarksDialog::OnListViewHeaderRClick()
{
	DWORD dwCursorPos = GetMessagePos();

	POINT ptCursor;
	ptCursor.x = GET_X_LPARAM(dwCursorPos);
	ptCursor.y = GET_Y_LPARAM(dwCursorPos);

	HMENU hMenu = CreatePopupMenu();
	int iItem = 0;

	for each(auto ci in m_pmbdps->m_vectorColumnInfo)
	{
		TCHAR szColumn[128];
		GetColumnString(ci.ColumnType,szColumn,SIZEOF_ARRAY(szColumn));

		MENUITEMINFO mii;
		mii.cbSize		= sizeof(mii);
		mii.fMask		= MIIM_ID|MIIM_STRING|MIIM_STATE;
		mii.wID			= ci.ColumnType;
		mii.dwTypeData	= szColumn;
		mii.fState		= 0;

		if(ci.bActive)
		{
			mii.fState |= MFS_CHECKED;
		}

		/* The name column cannot be removed. */
		if(ci.ColumnType == CManageBookmarksDialogPersistentSettings::COLUMN_TYPE_NAME)
		{
			mii.fState |= MFS_DISABLED;
		}

		InsertMenuItem(hMenu,iItem,TRUE,&mii);

		++iItem;
	}

	int iCmd = TrackPopupMenu(hMenu,TPM_LEFTALIGN|TPM_RETURNCMD,ptCursor.x,ptCursor.y,0,m_hDlg,NULL);
	DestroyMenu(hMenu);

	int iColumn = 0;

	for(auto itr = m_pmbdps->m_vectorColumnInfo.begin();itr != m_pmbdps->m_vectorColumnInfo.end();++itr)
	{
		if(itr->ColumnType == iCmd)
		{
			HWND hListView = GetDlgItem(m_hDlg,IDC_MANAGEBOOKMARKS_LISTVIEW);

			if(itr->bActive)
			{
				itr->iWidth = ListView_GetColumnWidth(hListView,iColumn);
				ListView_DeleteColumn(hListView,iColumn);
			}
			else
			{
				LVCOLUMN lvCol;
				TCHAR szTemp[128];

				GetColumnString(itr->ColumnType,szTemp,SIZEOF_ARRAY(szTemp));
				lvCol.mask		= LVCF_TEXT|LVCF_WIDTH;
				lvCol.pszText	= szTemp;
				lvCol.cx		= itr->iWidth;
				ListView_InsertColumn(hListView,iColumn,&lvCol);

				HWND hTreeView = GetDlgItem(m_hDlg,IDC_MANAGEBOOKMARKS_TREEVIEW);
				HTREEITEM hSelected = TreeView_GetSelection(hTreeView);
				CBookmarkFolder &BookmarkFolder = m_pBookmarkTreeView->GetBookmarkFolderFromTreeView(hSelected);

				int iItem = 0;

				for(auto itrBookmarks = BookmarkFolder.begin();itrBookmarks != BookmarkFolder.end();++itrBookmarks)
				{
					TCHAR szColumn[256];
					GetBookmarkItemColumnInfo(*itrBookmarks,itr->ColumnType,szColumn,SIZEOF_ARRAY(szColumn));
					ListView_SetItemText(hListView,iItem,iColumn,szColumn);

					++iItem;
				}
			}

			itr->bActive = !itr->bActive;

			break;
		}
		else
		{
			if(itr->bActive)
			{
				++iColumn;
			}
		}
	}
}