kdecore: drop standard directories KIOSK support

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-06-05 14:46:22 +03:00
parent 997a8df465
commit b9186c0327
8 changed files with 10 additions and 296 deletions

View file

@ -623,8 +623,6 @@ void KConfigPrivate::parseConfigFiles()
if (bFileImmutable)
break;
}
if (componentData.dirs()->isRestrictedResource(resourceType, fileName))
bFileImmutable = true;
}
}

View file

@ -39,8 +39,6 @@
#include <qmetaobject.h>
#include <qregexp.h>
extern bool kde_kiosk_exception;
static QByteArray lookup(const KConfigIniBackend::BufferFragment& fragment, QHash<KConfigIniBackend::BufferFragment, QByteArray>* cache)
{
QHash<KConfigIniBackend::BufferFragment, QByteArray>::iterator it = cache->find(fragment);
@ -141,9 +139,9 @@ KConfigIniBackend::parseConfig(const QByteArray& currentLocale, KEntryMap& entry
line.at(start) == '$' && line.at(start + 1) == 'i')
{
if (newGroup.isEmpty())
fileOptionImmutable = !kde_kiosk_exception;
fileOptionImmutable = true;
else
groupOptionImmutable = !kde_kiosk_exception;
groupOptionImmutable = true;
}
else {
if (!newGroup.isEmpty())
@ -201,8 +199,7 @@ KConfigIniBackend::parseConfig(const QByteArray& currentLocale, KEntryMap& entry
while (i < end) {
switch (aKey.at(i)) {
case 'i':
if (!kde_kiosk_exception)
entryOptions |= KEntryMap::EntryImmutable;
entryOptions |= KEntryMap::EntryImmutable;
break;
case 'e':
if (allowExecutableValues)

View file

@ -26,6 +26,7 @@
#include <QCoreApplication>
#include <QMutex>
#include <kglobal.h>
#include <ksharedconfig.h>
#include <kprotocolinfo.h>
@ -36,13 +37,6 @@
#include <kurl.h>
#include <kconfiggroup.h>
#include <QMutex>
#include <QtCore/qmutex.h>
#include <QtCore/qglobal.h>
extern bool kde_kiosk_exception;
class URLActionRule
{
public:
@ -195,7 +189,7 @@ public:
blockEverything=true;
return;
}
actionRestrictions = config->hasGroup("KDE Action Restrictions" ) && !kde_kiosk_exception;
actionRestrictions = config->hasGroup("KDE Action Restrictions" );
}
~KAuthorizedPrivate()
@ -236,7 +230,7 @@ bool KAuthorized::authorizeKAction(const QString& action)
bool KAuthorized::authorizeControlModule(const QString &menuId)
{
if (menuId.isEmpty() || kde_kiosk_exception)
if (menuId.isEmpty())
return true;
KConfigGroup cg(KGlobal::config(), "KDE Control Module Restrictions");
return cg.readEntry(menuId, true);

View file

@ -138,9 +138,6 @@ void KComponentDataPrivate::lazyInit(const KComponentData &component)
dirs->addResourceType("appdata", "data", aboutData.appName() + QLatin1Char('/'), true);
configInit(component);
if (dirs->addCustomized(sharedConfig.data()))
sharedConfig->reparseConfiguration();
}
// the first KComponentData sets the KDE Qt plugin paths
@ -153,35 +150,17 @@ void KComponentDataPrivate::lazyInit(const KComponentData &component)
}
}
bool kde_kiosk_exception = false; // flag to disable kiosk restrictions
bool kde_kiosk_admin = false;
void KComponentDataPrivate::configInit(const KComponentData &component)
{
Q_ASSERT(!sharedConfig);
if (!configName.isEmpty()) {
sharedConfig = KSharedConfig::openConfig(component, configName);
//FIXME: this is broken and I don't know how to repair it
// Check whether custom config files are allowed.
KConfigGroup cg(sharedConfig, "KDE Action Restrictions");
QString kioskException = cg.readEntry("kiosk_exception");
if (!cg.readEntry("custom_config", true)) {
sharedConfig = 0;
}
}
if (!sharedConfig) {
sharedConfig = KSharedConfig::openConfig(component);
}
// Check if we are excempt from kiosk restrictions
if (kde_kiosk_admin && !kde_kiosk_exception && !qgetenv("KDE_KIOSK_NO_RESTRICTIONS").isEmpty()) {
kde_kiosk_exception = true;
sharedConfig = 0;
configInit(component); // Reread...
}
}
KStandardDirs *KComponentData::dirs() const

View file

@ -60,7 +60,6 @@
#include <QtCore/QFileInfo>
#include <QtCore/QSettings>
#include <QtCore/QStandardPaths>
#include <QtNetwork/QHostInfo>
#include <mutex>
@ -74,21 +73,14 @@ class KStandardDirs::KStandardDirsPrivate
{
public:
KStandardDirsPrivate(KStandardDirs* qq)
: m_restrictionsActive(false),
m_checkRestrictions(true),
q(qq)
: q(qq)
{ }
bool hasDataRestrictions(const QString &relPath) const;
QStringList resourceDirs(const char* type, const QString& subdirForRestrictions);
void createSpecialResource(const char*);
bool exists(const QString &fullPath);
QString realPath(const QString &dirname);
bool m_restrictionsActive : 1;
bool m_checkRestrictions : 1;
QMap<QByteArray, bool> m_restrictions;
QStringList xdgdata_prefixes;
QStringList xdgconf_prefixes;
QStringList m_prefixes;
@ -227,33 +219,6 @@ KStandardDirs::~KStandardDirs()
delete d;
}
bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const
{
if (!d->m_restrictionsActive)
return false;
if (d->m_restrictions.value(type, false))
return true;
if (strcmp(type, "data")==0 && d->hasDataRestrictions(relPath))
return true;
return false;
}
bool KStandardDirs::KStandardDirsPrivate::hasDataRestrictions(const QString &relPath) const
{
QString key;
const int i = relPath.indexOf(QLatin1Char('/'));
if (i != -1)
key = QString::fromLatin1("data_") + relPath.left(i);
else
key = QString::fromLatin1("data_") + relPath;
return m_restrictions.value(key.toLatin1(), false);
}
QStringList KStandardDirs::allTypes() const
{
QStringList list;
@ -882,15 +847,12 @@ QStringList KStandardDirs::resourceDirs(const char *type) const
QStringList KStandardDirs::KStandardDirsPrivate::resourceDirs(const char* type, const QString& subdirForRestrictions)
{
std::lock_guard<std::recursive_mutex> lock(m_cacheMutex);
const bool dataRestrictionActive = m_restrictionsActive
&& (strcmp(type, "data") == 0)
&& hasDataRestrictions(subdirForRestrictions);
QMap<QByteArray, QStringList>::const_iterator dirCacheIt = m_dircache.constFind(type);
QStringList candidates;
if (dirCacheIt != m_dircache.constEnd() && !dataRestrictionActive) {
if (dirCacheIt != m_dircache.constEnd()) {
//qDebug() << this << "resourceDirs(" << type << "), in cache already";
candidates = *dirCacheIt;
}
@ -902,16 +864,6 @@ QStringList KStandardDirs::KStandardDirsPrivate::resourceDirs(const char* type,
QDir testdir;
bool restrictionActive = false;
if (m_restrictionsActive) {
if (dataRestrictionActive)
restrictionActive = true;
if (m_restrictions.value("all", false))
restrictionActive = true;
else if (m_restrictions.value(type, false))
restrictionActive = true;
}
const QStringList dirs = m_relatives.value(type);
const QString typeInstallPath = installPath(type); // could be empty
const QString installdir = typeInstallPath.isEmpty() ? QString() : realPath(typeInstallPath);
@ -962,8 +914,6 @@ QStringList KStandardDirs::KStandardDirsPrivate::resourceDirs(const char* type,
continue;
const QString path = realPath( *pit + *it );
testdir.setPath(path);
if (local && restrictionActive)
continue;
if ((local || testdir.exists()) && !candidates.contains(path, case_sensitivity))
candidates.append(path);
}
@ -1006,11 +956,8 @@ QStringList KStandardDirs::KStandardDirsPrivate::resourceDirs(const char* type,
}
// Insert result into the cache for next time.
// Exception: data_subdir restrictions are per-subdir, so we can't store such results
if (!dataRestrictionActive) {
//kDebug() << this << "Inserting" << type << candidates << "into dircache";
m_dircache.insert(type, candidates);
}
//kDebug() << this << "Inserting" << type << candidates << "into dircache";
m_dircache.insert(type, candidates);
}
#if 0
@ -1590,126 +1537,6 @@ static QStringList lookupProfiles(const QString &mapFile)
return profiles;
}
extern bool kde_kiosk_admin;
bool KStandardDirs::addCustomized(KConfig *config)
{
if (!d->m_checkRestrictions) // there are already customized entries
return false; // we just quit and hope they are the right ones
// save the numbers of config directories. If this changes,
// we will return true to give KConfig a chance to reparse
const int configdirs = resourceDirs("config").count();
// reading the prefixes in
QString group = QLatin1String("Directories");
KConfigGroup cg(config, group);
QString kioskAdmin = cg.readEntry("kioskAdmin");
if (!kioskAdmin.isEmpty() && !kde_kiosk_admin)
{
int i = kioskAdmin.indexOf(QLatin1Char(':'));
QString user = kioskAdmin.left(i);
QString host = kioskAdmin.mid(i+1);
KUser thisUser;
if ((user == thisUser.loginName()) &&
(host.isEmpty() || (host == QHostInfo::localHostName())))
{
kde_kiosk_admin = true;
}
}
bool readProfiles = true;
if (kde_kiosk_admin && !qgetenv("KDE_KIOSK_NO_PROFILES").isEmpty())
readProfiles = false;
QString userMapFile = cg.readEntry("userProfileMapFile");
QString profileDirsPrefix = cg.readEntry("profileDirsPrefix");
if (!profileDirsPrefix.isEmpty() && !profileDirsPrefix.endsWith(QLatin1Char('/')))
profileDirsPrefix.append(QLatin1Char('/'));
QStringList profiles;
if (readProfiles)
profiles = lookupProfiles(userMapFile);
QString profile;
bool priority = false;
while(true)
{
KConfigGroup cg(config, group);
const QStringList list = cg.readEntry("prefixes", QStringList());
foreach (const QString it, list) {
addPrefix(it, priority);
addXdgConfigPrefix(it + QLatin1String("/etc/xdg"), priority);
addXdgDataPrefix(it + QLatin1String("/share"), priority);
}
// If there are no prefixes defined, check if there is a directory
// for this profile under <profileDirsPrefix>
if (list.isEmpty() && !profile.isEmpty() && !profileDirsPrefix.isEmpty())
{
QString dir = profileDirsPrefix + profile;
addPrefix(dir, priority);
addXdgConfigPrefix(dir + QLatin1String("/etc/xdg"), priority);
addXdgDataPrefix(dir + QLatin1String("/share"), priority);
}
// iterating over all entries in the group Directories
// to find entries that start with dir_$type
const QMap<QString, QString> entries = config->entryMap(group);
for (QMap<QString, QString>::ConstIterator it2 = entries.begin();
it2 != entries.end(); ++it2)
{
const QString key = it2.key();
if (key.startsWith(QLatin1String("dir_"))) {
// generate directory list, there may be more than 1.
const QStringList dirs = (*it2).split(QString(QLatin1Char(',')));
QStringList::ConstIterator sIt(dirs.begin());
QString resType = key.mid(4);
for (; sIt != dirs.end(); ++sIt)
{
const QByteArray latin1ResType = resType.toLatin1();
addResourceDir(latin1ResType.constData(), *sIt, priority);
}
}
}
if (profiles.isEmpty())
break;
profile = profiles.back();
group = QString::fromLatin1("Directories-%1").arg(profile);
profiles.pop_back();
priority = true;
}
// Process KIOSK restrictions.
if (!kde_kiosk_admin || qgetenv("KDE_KIOSK_NO_RESTRICTIONS").isEmpty())
{
KConfigGroup cg(config, "KDE Resource Restrictions");
const QMap<QString, QString> entries = cg.entryMap();
for (QMap<QString, QString>::ConstIterator it2 = entries.begin();
it2 != entries.end(); ++it2)
{
const QString key = it2.key();
if (!cg.readEntry(key, true))
{
d->m_restrictionsActive = true;
const QByteArray cKey = key.toLatin1();
d->m_restrictions.insert(cKey, true);
d->m_dircache.remove(cKey);
d->m_savelocations.remove(cKey);
}
}
}
// check if the number of config dirs changed
const bool configDirsChanged = (resourceDirs("config").count() != configdirs);
// If the config dirs changed, we check kiosk restrictions again.
d->m_checkRestrictions = configDirsChanged;
// return true if the number of config dirs changed: reparse config file
return configDirsChanged;
}
QString KStandardDirs::localkdedir() const
{
// Return the prefix to use for saving

View file

@ -295,23 +295,6 @@ public:
QString findResource( const char *type,
const QString& filename ) const;
/**
* Checks whether a resource is restricted as part of the KIOSK
* framework. When a resource is restricted it means that user-
* specific files in the resource are ignored.
*
* E.g. by restricting the @c "wallpaper" resource, only system-wide
* installed wallpapers will be found by this class. Wallpapers
* installed under the @c $KDEHOME directory will be ignored.
*
* @param type The type of the resource to check
* @param relPath A relative path in the resource.
*
* @return True if the resource is restricted.
*/
bool isRestrictedResource( const char *type,
const QString& relPath=QString() ) const;
/**
* Returns a number that identifies this version of the resource.
* When a change is made to the resource this number will change.
@ -512,17 +495,6 @@ public:
const QString& pathstr=QString(),
SearchOptions options = NoSearchOptions );
/**
* Reads customized entries out of the given config object and add
* them via addResourceDirs().
*
* @param config The object the entries are read from. This should
* contain global config files
* @return @c true if new config paths have been added
* from @p config.
**/
bool addCustomized(KConfig *config);
/**
* This function is used internally by almost all other function as
* it serves and fills the directories cache.

View file

@ -357,58 +357,6 @@ void KStandarddirsTest::testSetXdgDataDirs()
QVERIFY(newDirs.contains(localApps, PATH_SENSITIVITY));
}
void KStandarddirsTest::testRestrictedResources()
{
// Ensure we have a local xdgdata-apps dir
QFile localFile(KStandardDirs::locateLocal("xdgdata-apps", "foo.desktop"));
localFile.open(QIODevice::WriteOnly|QIODevice::Text);
localFile.write("foo");
localFile.close();
const QString localAppsDir = KGlobal::dirs()->realPath(QFileInfo(localFile).absolutePath() + '/');
QVERIFY(!localAppsDir.contains("foo.desktop"));
// Ensure we have a local share/apps/qttest dir
const QString localDataDir = KStandardDirs::locateLocal("data", "qttest/");
QVERIFY(!localDataDir.isEmpty());
QVERIFY(QDir(localDataDir).exists());
const QString localOtherDataDir = KStandardDirs::locateLocal("data", "other/");
QVERIFY(!localOtherDataDir.isEmpty());
// Check unrestricted results first
const QStringList appsDirs = KGlobal::dirs()->resourceDirs("xdgdata-apps");
const QString kdeDataApps = KGlobal::dirs()->realPath(KDEDIR "/share/applications/");
QCOMPARE_PATHS(appsDirs.first(), localAppsDir);
QVERIFY(appsDirs.contains(kdeDataApps, PATH_SENSITIVITY));
const QStringList dataDirs = KGlobal::dirs()->findDirs("data", "qttest");
QCOMPARE_PATHS(dataDirs.first(), localDataDir);
const QStringList otherDataDirs = KGlobal::dirs()->findDirs("data", "other");
QCOMPARE_PATHS(otherDataDirs.first(), localOtherDataDir);
// Initialize restrictions.
// Need a new componentdata to trigger restricted-resource initialization
// And we need to write the config _before_ creating the KComponentData.
KConfig foorc("foorc");
KConfigGroup restrictionsGroup(&foorc, "KDE Resource Restrictions");
restrictionsGroup.writeEntry("xdgdata-apps", false);
restrictionsGroup.writeEntry("data_qttest", false);
restrictionsGroup.sync();
// Check restrictions.
KComponentData cData("foo");
QVERIFY(cData.dirs()->isRestrictedResource("xdgdata-apps"));
QVERIFY(cData.dirs()->isRestrictedResource("data", "qttest"));
const QStringList newAppsDirs = cData.dirs()->resourceDirs("xdgdata-apps");
QVERIFY(newAppsDirs.contains(kdeDataApps, PATH_SENSITIVITY));
QVERIFY(!newAppsDirs.contains(localAppsDir, PATH_SENSITIVITY)); // restricted!
const QStringList newDataDirs = cData.dirs()->findDirs("data", "qttest");
QVERIFY(!newDataDirs.contains(localDataDir, PATH_SENSITIVITY)); // restricted!
const QStringList newOtherDataDirs = cData.dirs()->findDirs("data", "other");
QVERIFY(newOtherDataDirs.contains(localOtherDataDir, PATH_SENSITIVITY)); // not restricted!
restrictionsGroup.deleteGroup();
localFile.remove();
}
void KStandarddirsTest::testSymlinkResolution()
{
// This makes the save location for the david resource, "$HOME/.kde-unit-test/symlink/test/"

View file

@ -41,7 +41,6 @@ private Q_SLOTS:
void testAddResourceType();
void testAddResourceDir();
void testSetXdgDataDirs();
void testRestrictedResources();
void testSymlinkResolution();
void testThreads();