mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-09-09 14:48:28 +02:00
opkg_manager: add handling for whitelist
Origin commit data
------------------
Commit: 393cf55eb6
Author: Thilo Graf <dbt@novatux.de>
Date: 2021-04-10 (Sat, 10 Apr 2021)
This commit is contained in:
@@ -76,6 +76,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OPKG_BAD_PATTERN_LIST_FILE CONFIGDIR "/bad_package_pattern.list"
|
#define OPKG_BAD_PATTERN_LIST_FILE CONFIGDIR "/bad_package_pattern.list"
|
||||||
|
#define OPKG_GOOD_PATTERN_LIST_FILE CONFIGDIR "/good_package_pattern.list"
|
||||||
#if 0
|
#if 0
|
||||||
#define OPKG_CONFIG_FILE "/etc/opkg/opkg.conf"
|
#define OPKG_CONFIG_FILE "/etc/opkg/opkg.conf"
|
||||||
#else
|
#else
|
||||||
@@ -150,6 +151,7 @@ void COPKGManager::init(int wizard_mode)
|
|||||||
expert_mode = false;
|
expert_mode = false;
|
||||||
local_dir = &g_settings.update_dir_opkg;
|
local_dir = &g_settings.update_dir_opkg;
|
||||||
v_bad_pattern = getBadPackagePatternList();
|
v_bad_pattern = getBadPackagePatternList();
|
||||||
|
v_good_pattern = getGoodPackagePatternList();
|
||||||
CFileHelpers::createDir(OPKG_TMP_DIR);
|
CFileHelpers::createDir(OPKG_TMP_DIR);
|
||||||
silent = false;
|
silent = false;
|
||||||
num_updates = 0;
|
num_updates = 0;
|
||||||
@@ -376,48 +378,75 @@ static const struct button_label COPKGManagerFooterButtonsExpert[COPKGManagerFoo
|
|||||||
|
|
||||||
vector<string> COPKGManager::getBadPackagePatternList()
|
vector<string> COPKGManager::getBadPackagePatternList()
|
||||||
{
|
{
|
||||||
vector<string> v_ret;
|
return COPKGManager::getPackagePatternList(OPKG_BAD_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
ifstream in (OPKG_BAD_PATTERN_LIST_FILE, ios::in);
|
vector<string> COPKGManager::getGoodPackagePatternList()
|
||||||
|
{
|
||||||
|
return COPKGManager::getPackagePatternList(OPKG_GOOD_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> COPKGManager::getPackagePatternList(opkg_pattern_list_t type)
|
||||||
|
{
|
||||||
|
vector<string> v_ret;
|
||||||
|
std::string list_file = OPKG_BAD_PATTERN_LIST_FILE;
|
||||||
|
|
||||||
|
if (type == OPKG_GOOD_LIST)
|
||||||
|
list_file = OPKG_GOOD_PATTERN_LIST_FILE;
|
||||||
|
|
||||||
|
ifstream in (list_file, ios::in);
|
||||||
if (!in){
|
if (!in){
|
||||||
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] can't open %s, %s\n", __func__, __LINE__, OPKG_BAD_PATTERN_LIST_FILE, strerror(errno));
|
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] can't open %s, %s\n", __func__, __LINE__, OPKG_BAD_PATTERN_LIST_FILE, strerror(errno));
|
||||||
return v_ret;
|
return v_ret;
|
||||||
}
|
}
|
||||||
string line;
|
string line;
|
||||||
|
|
||||||
while(getline(in, line)){
|
while(getline(in, line))
|
||||||
v_ret.push_back(line);
|
v_ret.push_back(line);
|
||||||
}
|
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
return v_ret;
|
return v_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool COPKGManager::isBadPackage(std::string &s)
|
bool COPKGManager::isFilteredPackage(std::string &package_name, opkg_pattern_list_t type)
|
||||||
{
|
{
|
||||||
if(v_bad_pattern.empty())
|
std::vector<std::string> v_patterns;
|
||||||
|
|
||||||
|
if (type == OPKG_BAD_LIST)
|
||||||
|
v_patterns = v_bad_pattern;
|
||||||
|
else if (type == OPKG_GOOD_LIST)
|
||||||
|
v_patterns = v_good_pattern;
|
||||||
|
|
||||||
|
if(v_patterns.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
string st = "";
|
string st = "";
|
||||||
for (i = 0; i < v_bad_pattern.size(); i++)
|
for (i = 0; i < v_patterns.size(); i++)
|
||||||
{
|
{
|
||||||
string p = v_bad_pattern[i];
|
string p = v_patterns[i];
|
||||||
if (p.empty())
|
if (p.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
size_t patlen = p.length() - 1;
|
size_t patlen = p.length() - 1;
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
|
||||||
/* poor man's regex :-) only supported are "^" and "$" */
|
/* poor man's regex :-) only supported are "^" and "$" */
|
||||||
if (p.substr(patlen, 1) == "$") { /* match at end */
|
if (p.substr(patlen, 1) == "$")
|
||||||
size_t pos = s.rfind(p.substr(0, patlen)); /* s.len-patlen can be -1 == npos */
|
{ /* match at end */
|
||||||
if (pos != string::npos && pos == (s.length() - patlen))
|
size_t pos = package_name.rfind(p.substr(0, patlen)); /* package_name.len-patlen can be -1 == npos */
|
||||||
|
if (pos != string::npos && pos == (package_name.length() - patlen))
|
||||||
res = true;
|
res = true;
|
||||||
} else if (p.substr(0, 1) == "^") { /* match at beginning */
|
}
|
||||||
if (s.find(p.substr(1)) == 0)
|
else if (p.substr(0, 1) == "^")
|
||||||
|
{ /* match at beginning */
|
||||||
|
if (package_name.find(p.substr(1)) == 0)
|
||||||
res = true;
|
res = true;
|
||||||
} else { /* match everywhere */
|
}
|
||||||
if (s.find(p) != string::npos)
|
else
|
||||||
|
{ /* match everywhere */
|
||||||
|
if (package_name.find(p) != string::npos)
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
if (res)
|
if (res)
|
||||||
@@ -425,13 +454,41 @@ bool COPKGManager::isBadPackage(std::string &s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!st.empty()){
|
if (!st.empty()){
|
||||||
dprintf(DEBUG_INFO, "[%s] filtered '%s' pattern(s) '%s'\n", __func__, s.c_str(), st.c_str());
|
dprintf(DEBUG_DEBUG, "[%s] filtered '%s' pattern(s) '%s'\n", __func__, package_name.c_str(), st.c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool COPKGManager::isBadPackage(std::string &package_name)
|
||||||
|
{
|
||||||
|
return isFilteredPackage(package_name, OPKG_BAD_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool COPKGManager::isGoodPackage(std::string &package_name)
|
||||||
|
{
|
||||||
|
return isFilteredPackage(package_name, OPKG_GOOD_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool COPKGManager::isPermittedPackage(std::string &package_name)
|
||||||
|
{
|
||||||
|
bool ret = (!isBadPackage(package_name));
|
||||||
|
|
||||||
|
if (isBadPackage(package_name) && !isGoodPackage(package_name))
|
||||||
|
ret = false;
|
||||||
|
|
||||||
|
// if (isGoodPackage(package_name))
|
||||||
|
// ret = true;
|
||||||
|
|
||||||
|
if (isBadPackage(package_name) && isGoodPackage(package_name))
|
||||||
|
ret = true;
|
||||||
|
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void COPKGManager::updateMenu()
|
void COPKGManager::updateMenu()
|
||||||
{
|
{
|
||||||
bool upgradesAvailable = false;
|
bool upgradesAvailable = false;
|
||||||
@@ -439,8 +496,9 @@ void COPKGManager::updateMenu()
|
|||||||
getPkgData(CMD_LIST_UPGRADEABLE);
|
getPkgData(CMD_LIST_UPGRADEABLE);
|
||||||
for (map<string, struct pkg>::iterator it = pkg_map.begin(); it != pkg_map.end(); ++it) {
|
for (map<string, struct pkg>::iterator it = pkg_map.begin(); it != pkg_map.end(); ++it) {
|
||||||
/* this should no longer trigger at all */
|
/* this should no longer trigger at all */
|
||||||
if (isBadPackage(it->second.name))
|
if (!isPermittedPackage(it->second.name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
it->second.forwarder->iconName_Info_right = "";
|
it->second.forwarder->iconName_Info_right = "";
|
||||||
it->second.forwarder->setActive(true);
|
it->second.forwarder->setActive(true);
|
||||||
if (it->second.upgradable) {
|
if (it->second.upgradable) {
|
||||||
@@ -659,8 +717,9 @@ int COPKGManager::showMenu()
|
|||||||
pkg_vec.clear();
|
pkg_vec.clear();
|
||||||
for (map<string, struct pkg>::iterator it = pkg_map.begin(); it != pkg_map.end(); ++it) {
|
for (map<string, struct pkg>::iterator it = pkg_map.begin(); it != pkg_map.end(); ++it) {
|
||||||
/* this should no longer trigger at all */
|
/* this should no longer trigger at all */
|
||||||
if (isBadPackage(it->second.name))
|
if (!isPermittedPackage(it->second.name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
it->second.forwarder = new CMenuForwarder(it->second.desc, true, NULL , this, it->second.name.c_str());
|
it->second.forwarder = new CMenuForwarder(it->second.desc, true, NULL , this, it->second.name.c_str());
|
||||||
it->second.forwarder->setHint("", it->second.desc);
|
it->second.forwarder->setHint("", it->second.desc);
|
||||||
menu->addItem(it->second.forwarder);
|
menu->addItem(it->second.forwarder);
|
||||||
@@ -858,8 +917,9 @@ void COPKGManager::getPkgData(const int pkg_content_id)
|
|||||||
switch (pkg_content_id) {
|
switch (pkg_content_id) {
|
||||||
case CMD_LIST: {
|
case CMD_LIST: {
|
||||||
/* do not even put "bad" packages into the list to save memory */
|
/* do not even put "bad" packages into the list to save memory */
|
||||||
if (isBadPackage(name))
|
if (!isPermittedPackage(name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pkg_map[name] = pkg(name, line, line);
|
pkg_map[name] = pkg(name, line, line);
|
||||||
map<string, struct pkg>::iterator it = pkg_map.find(name);
|
map<string, struct pkg>::iterator it = pkg_map.find(name);
|
||||||
if (it != pkg_map.end())
|
if (it != pkg_map.end())
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
OPKG-Manager Class for Neutrino-GUI
|
OPKG-Manager Class for Neutrino-GUI
|
||||||
|
|
||||||
Implementation:
|
Implementation:
|
||||||
Copyright (C) 2012-2020 T. Graf 'dbt'
|
Copyright (C) 2012-2021 T. Graf 'dbt'
|
||||||
www.dbox2-tuning.net
|
www.dbox2-tuning.net
|
||||||
|
|
||||||
Adaptions:
|
Adaptions:
|
||||||
@@ -71,7 +71,7 @@ class COPKGManager : public CMenuTarget
|
|||||||
std::vector<std::string> config_dest;
|
std::vector<std::string> config_dest;
|
||||||
|
|
||||||
//filter
|
//filter
|
||||||
std::vector<std::string> v_bad_pattern;
|
std::vector<std::string> v_bad_pattern, v_good_pattern;
|
||||||
|
|
||||||
CMenuWidget *menu;
|
CMenuWidget *menu;
|
||||||
CMenuForwarder *upgrade_forwarder;
|
CMenuForwarder *upgrade_forwarder;
|
||||||
@@ -144,12 +144,23 @@ class COPKGManager : public CMenuTarget
|
|||||||
void updateMenu();
|
void updateMenu();
|
||||||
void refreshMenu();
|
void refreshMenu();
|
||||||
|
|
||||||
//!Returns a vector with possible filter entries from OPKG_BAD_PATTERN_LIST_FILE
|
typedef enum
|
||||||
|
{
|
||||||
|
OPKG_BAD_LIST = 0,
|
||||||
|
OPKG_GOOD_LIST = 1
|
||||||
|
}opkg_pattern_list_t;
|
||||||
|
|
||||||
|
static std::vector<std::string> getPackagePatternList(opkg_pattern_list_t type);
|
||||||
|
|
||||||
|
//!Returns a vector with possible filter entries from OPKG_BAD_PATTERN_LIST_FILE or OPKG_GOOD_PATTERN_LIST_FILE
|
||||||
static std::vector<std::string> getBadPackagePatternList();
|
static std::vector<std::string> getBadPackagePatternList();
|
||||||
|
static std::vector<std::string> getGoodPackagePatternList();
|
||||||
|
|
||||||
|
bool isFilteredPackage(std::string &package_name, opkg_pattern_list_t type);
|
||||||
/*!
|
/*!
|
||||||
* Returns true if found a ''bad'' package, Parameter: package name as std::string by rev
|
* Returns true if found a ''bad'' package, Parameter: package name as std::string by rev
|
||||||
* To detect bad packages, it must be exist a matching pattern list file.
|
* To detect bad packages, it must be exist a matching pattern list file.
|
||||||
* Path is defined in OPKG_BAD_PATTERN_LIST_FILE.
|
* Path is defined in OPKG_X_PATTERN_LIST_FILE.
|
||||||
* This provides the option to filter some unwanted entries in the package list menue.
|
* This provides the option to filter some unwanted entries in the package list menue.
|
||||||
* This makes sense eg. to hinder that the user could change important system packages.
|
* This makes sense eg. to hinder that the user could change important system packages.
|
||||||
* NOTE: a sample file you should find here as : "/var/tuxbox/config/bad_package_pattern.list.sample"
|
* NOTE: a sample file you should find here as : "/var/tuxbox/config/bad_package_pattern.list.sample"
|
||||||
@@ -160,7 +171,12 @@ class COPKGManager : public CMenuTarget
|
|||||||
* Also a few place holders should work, see the isBadPackage() function, but this
|
* Also a few place holders should work, see the isBadPackage() function, but this
|
||||||
* can be inaccurately because it could filter innocent packages.
|
* can be inaccurately because it could filter innocent packages.
|
||||||
*/
|
*/
|
||||||
bool isBadPackage(std::string &s);
|
bool isBadPackage(std::string &package_name);
|
||||||
|
/*!
|
||||||
|
The same like isBadPackage() but as whitlist
|
||||||
|
*/
|
||||||
|
bool isGoodPackage(std::string &package_name);
|
||||||
|
bool isPermittedPackage(std::string &package_name);
|
||||||
|
|
||||||
void showError(const char* local_msg, char* err_msg = NULL, const std::string& additional_text = std::string());
|
void showError(const char* local_msg, char* err_msg = NULL, const std::string& additional_text = std::string());
|
||||||
int doUpdate();
|
int doUpdate();
|
||||||
|
Reference in New Issue
Block a user