generic: drop support for storing passwords in kcfg files

use KPasswdStore instead

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-10-16 19:04:24 +03:00
parent 03c804d902
commit 9c6ba7e9e2
14 changed files with 33 additions and 104 deletions

View file

@ -25,7 +25,6 @@
#include "kstandarddirs.h"
#include "kglobal.h"
#include "kdebug.h"
#include "kstringhandler.h"
KConfigSkeletonItem::KConfigSkeletonItem(const QString & _group,
const QString & _key)
@ -139,8 +138,6 @@ void KCoreConfigSkeleton::ItemString::writeConfig( KConfig *config )
cg.revertToDefault( mKey );
else if ( mType == Path )
cg.writePathEntry( mKey, mReference );
else if ( mType == Password )
cg.writeEntry( mKey, KStringHandler::obscure( mReference ) );
else
cg.writeEntry( mKey, mReference );
}
@ -155,11 +152,6 @@ void KCoreConfigSkeleton::ItemString::readConfig( KConfig *config )
{
mReference = cg.readPathEntry( mKey, mDefault );
}
else if ( mType == Password )
{
QString val = cg.readEntry( mKey, KStringHandler::obscure( mDefault ) );
mReference = KStringHandler::obscure( val );
}
else
{
mReference = cg.readEntry( mKey, mDefault );
@ -185,13 +177,6 @@ QVariant KCoreConfigSkeleton::ItemString::property() const
return QVariant(mReference);
}
KCoreConfigSkeleton::ItemPassword::ItemPassword( const QString &_group, const QString &_key,
QString &reference,
const QString &defaultValue)
: ItemString( _group, _key, reference, defaultValue, Password )
{
}
KCoreConfigSkeleton::ItemPath::ItemPath( const QString &_group, const QString &_key,
QString &reference,
const QString &defaultValue)
@ -1104,16 +1089,6 @@ KCoreConfigSkeleton::ItemString *KCoreConfigSkeleton::addItemString( const QStri
return item;
}
KCoreConfigSkeleton::ItemPassword *KCoreConfigSkeleton::addItemPassword( const QString &name, QString &reference,
const QString &defaultValue, const QString &key )
{
KCoreConfigSkeleton::ItemPassword *item;
item = new KCoreConfigSkeleton::ItemPassword( d->mCurrentGroup, key.isNull() ? name : key,
reference, defaultValue );
addItem( item, name );
return item;
}
KCoreConfigSkeleton::ItemPath *KCoreConfigSkeleton::addItemPath( const QString &name, QString &reference,
const QString &defaultValue, const QString &key )
{

View file

@ -368,7 +368,7 @@ public:
class KDECORE_EXPORT ItemString:public KConfigSkeletonGenericItem < QString >
{
public:
enum Type { Normal, Password, Path };
enum Type { Normal, Path };
/** @enum Type
The type of string that is held in this item
@ -376,9 +376,6 @@ public:
@var ItemString::Type ItemString::Normal
A normal string
@var ItemString::Type ItemString::Password
A password string
@var ItemString::Type ItemString::Path
A path to a file or directory
*/
@ -411,18 +408,6 @@ public:
Type mType;
};
/**
* Class for handling a password preferences item.
*/
class KDECORE_EXPORT ItemPassword:public ItemString
{
public:
/** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
ItemPassword(const QString & _group, const QString & _key,
QString & reference,
const QString & defaultValue = QLatin1String("")); // NOT QString() !!
};
/**
* Class for handling a path preferences item.
*/
@ -1035,23 +1020,6 @@ public:
const QString & defaultValue = QLatin1String(""), // NOT QString() !!
const QString & key = QString());
/**
* Register a password item of type QString. The string value is written
* encrypted to the config file. Note that the current encryption scheme
* is very weak.
*
* @param name Name used to identify this setting. Names must be unique.
* @param reference Pointer to the variable, which is set by readConfig()
* calls and read by writeConfig() calls.
* @param defaultValue Default value, which is used when the config file
* does not yet contain the key of this item.
* @param key Key used in config file. If key is null, name is used as key.
* @return The created item
*/
ItemPassword *addItemPassword(const QString & name, QString & reference,
const QString & defaultValue = QLatin1String(""),
const QString & key = QString());
/**
* Register a path item of type QString. The string value is interpreted
* as a path. This means, dollar expension is activated for this value, so

View file

@ -178,7 +178,6 @@
<xsd:enumeration value="Enum"/>
<xsd:enumeration value="Path"/>
<xsd:enumeration value="PathList"/>
<xsd:enumeration value="Password"/>
<xsd:enumeration value="Url"/>
<xsd:enumeration value="UrlList"/>
</xsd:restriction>

View file

@ -899,12 +899,12 @@ QString param( const QString &t )
else if ( type == "enum" ) return "int";
else if ( type == "path" ) return "const QString &";
else if ( type == "pathlist" ) return "const QStringList &";
else if ( type == "password" ) return "const QString &";
else if ( type == "url" ) return "const KUrl &";
else if ( type == "urllist" ) return "const KUrl::List &";
else {
cerr <<"kconfig_compiler does not support type \""<< type <<"\""<<endl;
return "QString"; //For now, but an assert would be better
exit(1);
return "QString";
}
}

View file

@ -19,8 +19,8 @@ Test3::Test3( )
addItem( mBlubbItem, QLatin1String( "Blubb" ) );
mBlahBlahItem = new KConfigSkeleton::ItemString( currentGroup(), QLatin1String( "BlahBlah" ), mBlahBlah, QLatin1String( "a string" ) );
addItem( mBlahBlahItem, QLatin1String( "BlahBlah" ) );
mMyPasswordItem = new KConfigSkeleton::ItemPassword( currentGroup(), QLatin1String( "MyPassword" ), mMyPassword );
addItem( mMyPasswordItem, QLatin1String( "MyPassword" ) );
mMyPathItem = new KConfigSkeleton::ItemPath( currentGroup(), QLatin1String( "MyPath" ), mMyPath );
addItem( mMyPathItem, QLatin1String( "MyPath" ) );
}
Test3::~Test3()

View file

@ -92,28 +92,28 @@ class Test3 : public KConfigSkeleton
}
/**
Set MyPassword
Set MyPath
*/
void setMyPassword( const QString & v )
void setMyPath( const QString & v )
{
if (!isImmutable( QString::fromLatin1( "MyPassword" ) ))
mMyPassword = v;
if (!isImmutable( QString::fromLatin1( "MyPath" ) ))
mMyPath = v;
}
/**
Get MyPassword
Get MyPath
*/
QString myPassword() const
QString myPath() const
{
return mMyPassword;
return mMyPath;
}
/**
Get Item object corresponding to MyPassword()
Get Item object corresponding to MyPath()
*/
ItemPassword *myPasswordItem()
ItemPath *myPathItem()
{
return mMyPasswordItem;
return mMyPathItem;
}
protected:
@ -124,13 +124,13 @@ class Test3 : public KConfigSkeleton
// Blah
int mBlubb;
QString mBlahBlah;
QString mMyPassword;
QString mMyPath;
private:
ItemBool *mAutoSaveItem;
ItemInt *mBlubbItem;
ItemString *mBlahBlahItem;
ItemPassword *mMyPasswordItem;
ItemPath *mMyPathItem;
};
}

View file

@ -20,7 +20,7 @@
<entry type="String" name="BlahBlah">
<default>a string</default>
</entry>
<entry type="Password" name="MyPassword"/>
<entry type="Path" name="MyPath"/>
</group>
</kcfg>

View file

@ -19,8 +19,8 @@ Test3a::Test3a( )
addItem( mBlubbItem, QLatin1String( "Blubb" ) );
mBlahBlahItem = new KConfigSkeleton::ItemString( currentGroup(), QLatin1String( "BlahBlah" ), mBlahBlah, QLatin1String( "a string" ) );
addItem( mBlahBlahItem, QLatin1String( "BlahBlah" ) );
mMyPasswordItem = new KConfigSkeleton::ItemPassword( currentGroup(), QLatin1String( "MyPassword" ), mMyPassword );
addItem( mMyPasswordItem, QLatin1String( "MyPassword" ) );
mMyPathItem = new KConfigSkeleton::ItemPath( currentGroup(), QLatin1String( "MyPath" ), mMyPath );
addItem( mMyPathItem, QLatin1String( "MyPath" ) );
}
Test3a::~Test3a()

View file

@ -93,28 +93,28 @@ class Test3a : public KConfigSkeleton
}
/**
Set MyPassword
Set MyPath
*/
void setMyPassword( const QString & v )
void setMyPath( const QString & v )
{
if (!isImmutable( QString::fromLatin1( "MyPassword" ) ))
mMyPassword = v;
if (!isImmutable( QString::fromLatin1( "MyPath" ) ))
mMyPath = v;
}
/**
Get MyPassword
Get MyPath
*/
QString myPassword() const
QString myPath() const
{
return mMyPassword;
return mMyPath;
}
/**
Get Item object corresponding to MyPassword()
Get Item object corresponding to MyPath()
*/
ItemPassword *myPasswordItem()
ItemPath *myPathItem()
{
return mMyPasswordItem;
return mMyPathItem;
}
protected:
@ -125,13 +125,13 @@ class Test3a : public KConfigSkeleton
// Blah
int mBlubb;
QString mBlahBlah;
QString mMyPassword;
QString mMyPath;
private:
ItemBool *mAutoSaveItem;
ItemInt *mBlubbItem;
ItemString *mBlahBlahItem;
ItemPassword *mMyPasswordItem;
ItemPath *mMyPathItem;
};
}

View file

@ -20,7 +20,7 @@
<entry type="String" name="BlahBlah">
<default>a string</default>
</entry>
<entry type="Password" name="MyPassword"/>
<entry type="Path" name="/home/blah/blah"/>
</group>
</kcfg>

View file

@ -235,8 +235,6 @@ void ConfigLoaderHandler::addItem()
}
item = intItem;
} else if (m_type == "password") {
item = m_config->addItemPassword(m_name, *d->newString(), m_default, m_key);
} else if (m_type == "path") {
item = m_config->addItemPath(m_name, *d->newString(), m_default, m_key);
} else if (m_type == "string") {

View file

@ -101,13 +101,6 @@ void ConfigLoaderTest::intDefaultValue()
QVERIFY(typeItem->isEqual(27));
}
void ConfigLoaderTest::passwordDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPassword*, "DefaultPasswordItem");
QVERIFY(typeItem->isEqual(QString::fromLatin1("h4x.")));
}
void ConfigLoaderTest::pathDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPath*, "DefaultPathItem");

View file

@ -45,7 +45,6 @@ private Q_SLOTS:
void enumDefaultValue();
void fontDefaultValue();
void intDefaultValue();
void passwordDefaultValue();
void pathDefaultValue();
void stringDefaultValue();
void stringListDefaultValue();

View file

@ -31,9 +31,6 @@
<entry name="DefaultIntItem" type="Int">
<default>27</default>
</entry>
<entry name="DefaultPasswordItem" type="Password">
<default>h4x.</default>
</entry>
<entry name="DefaultPathItem" type="Path">
<default>/dev/null</default>
</entry>