Changeset View
Changeset View
Standalone View
Standalone View
sddmauthhelper.cpp
Show All 11 Lines | 1 | /* | |||
---|---|---|---|---|---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. | ||
14 | 14 | | |||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | 17 | */ | ||
18 | #include "sddmauthhelper.h" | 18 | #include "sddmauthhelper.h" | ||
19 | 19 | | |||
20 | #include <unistd.h> | ||||
21 | | ||||
20 | #include <QDebug> | 22 | #include <QDebug> | ||
21 | #include <QDir> | 23 | #include <QDir> | ||
22 | #include <QFile> | 24 | #include <QFile> | ||
23 | #include <QFileInfo> | 25 | #include <QFileInfo> | ||
24 | #include <QMimeDatabase> | 26 | #include <QMimeDatabase> | ||
25 | #include <QMimeType> | 27 | #include <QMimeType> | ||
26 | #include <QSharedPointer> | 28 | #include <QSharedPointer> | ||
27 | 29 | | |||
28 | #include <KArchive> | 30 | #include <KArchive> | ||
29 | #include <KConfig> | 31 | #include <KConfig> | ||
30 | #include <KConfigGroup> | 32 | #include <KConfigGroup> | ||
31 | #include <KLocalizedString> | 33 | #include <KLocalizedString> | ||
32 | #include <KTar> | 34 | #include <KTar> | ||
35 | #include <KUser> | ||||
33 | #include <KZip> | 36 | #include <KZip> | ||
34 | 37 | | |||
35 | static QSharedPointer<KConfig> openConfig(const QString &filePath) | 38 | static QSharedPointer<KConfig> openConfig(const QString &filePath) | ||
36 | { | 39 | { | ||
37 | QFile file(filePath); | 40 | QFile file(filePath); | ||
38 | if(!file.exists()) { | 41 | if(!file.exists()) { | ||
39 | // If we are creating the config file, ensure it is world-readable: if | 42 | // If we are creating the config file, ensure it is world-readable: if | ||
40 | // we don't do that, KConfig will create a file which is only readable | 43 | // we don't do that, KConfig will create a file which is only readable | ||
41 | // by root | 44 | // by root | ||
42 | file.open(QIODevice::WriteOnly); | 45 | file.open(QIODevice::WriteOnly); | ||
43 | file.close(); | 46 | file.close(); | ||
44 | file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther); | 47 | file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther); | ||
45 | } | 48 | } | ||
46 | return QSharedPointer<KConfig>(new KConfig(file.fileName(), KConfig::SimpleConfig)); | 49 | return QSharedPointer<KConfig>(new KConfig(file.fileName(), KConfig::SimpleConfig)); | ||
47 | } | 50 | } | ||
48 | 51 | | |||
52 | void SddmAuthHelper::copyFile(const QString &source, const QString &destination) | ||||
53 | { | ||||
54 | KUser sddmUser(QStringLiteral("sddm")); | ||||
davidedmundson: Task for another day, we don't need to pass this in every time.
We can set this at compile… | |||||
filipf: +1 | |||||
55 | | ||||
56 | if (QFile::exists(destination)) { | ||||
57 | QFile::remove(destination); | ||||
58 | } | ||||
59 | | ||||
60 | QFile::copy(source, destination); | ||||
61 | const char* destinationConverted = destination.toLocal8Bit().data(); | ||||
62 | if (chown(destinationConverted, sddmUser.userId().nativeId(), sddmUser.groupId().nativeId())) { | ||||
63 | return; | ||||
64 | } | ||||
65 | } | ||||
66 | | ||||
67 | ActionReply SddmAuthHelper::sync(const QVariantMap &args) | ||||
68 | { | ||||
69 | QDir sddmConfigLocation(args[QStringLiteral("sddmUserConfig")].toString()); | ||||
70 | if (!sddmConfigLocation.exists()) { | ||||
71 | QDir().mkpath(sddmConfigLocation.path()); | ||||
72 | } | ||||
73 | | ||||
74 | // copy fontconfig (font, font rendering) | ||||
75 | if (!args[QStringLiteral("fontconfig")].isNull()) { | ||||
76 | QDir fontconfigSource(args[QStringLiteral("fontconfig")].toString()); | ||||
77 | QStringList sourceFileEntries = fontconfigSource.entryList (QDir::Files); | ||||
78 | QStringList sourceDirEntries = fontconfigSource.entryList (QDir::AllDirs); | ||||
79 | QDir fontconfigDestination(sddmConfigLocation.path() + QStringLiteral("/fontconfig")); | ||||
80 | | ||||
81 | if (!fontconfigDestination.exists()) { | ||||
82 | QDir().mkpath(fontconfigDestination.path()); | ||||
83 | } | ||||
84 | | ||||
85 | if (sourceDirEntries.count() != 0) { | ||||
86 | for (int i = 0; i<sourceDirEntries.count(); i++) { | ||||
87 | QString directoriesSource = fontconfigSource.path() + QDir::separator() + sourceDirEntries[i]; | ||||
88 | QString directoriesDestination = fontconfigDestination.path() + QDir::separator() + sourceDirEntries[i]; | ||||
89 | fontconfigSource.mkpath(directoriesDestination); | ||||
90 | copyFile(directoriesSource, directoriesDestination); | ||||
91 | } | ||||
92 | } | ||||
93 | | ||||
94 | if (sourceFileEntries.count() != 0) { | ||||
95 | for (int i = 0; i<sourceFileEntries.count(); i++) { | ||||
96 | QString filesSource = fontconfigSource.path() + QDir::separator() + sourceFileEntries[i]; | ||||
97 | QString filesDestination = fontconfigDestination.path() + QDir::separator() + sourceFileEntries[i]; | ||||
98 | copyFile(filesSource, filesDestination); | ||||
99 | } | ||||
100 | } | ||||
101 | } | ||||
102 | | ||||
103 | // copy kdeglobals (color scheme) | ||||
104 | if (!args[QStringLiteral("kdeglobals")].isNull()) { | ||||
105 | QDir kdeglobalsSource(args[QStringLiteral("kdeglobals")].toString()); | ||||
106 | QDir kdeglobalsDestination(sddmConfigLocation.path() + QStringLiteral("/kdeglobals")); | ||||
107 | copyFile(kdeglobalsSource.path(), kdeglobalsDestination.path()); | ||||
108 | } | ||||
109 | | ||||
110 | // copy plasmarc (icons, UI style) | ||||
111 | if (!args[QStringLiteral("plasmarc")].isNull()) { | ||||
112 | QDir plasmarcSource(args[QStringLiteral("plasmarc")].toString()); | ||||
113 | QDir plasmarcDestination(sddmConfigLocation.path() + QStringLiteral("/plasmarc")); | ||||
114 | copyFile(plasmarcSource.path(), plasmarcDestination.path()); | ||||
115 | } | ||||
116 | | ||||
117 | // write cursor theme to config file | ||||
118 | ActionReply reply = ActionReply::HelperErrorReply(); | ||||
119 | QSharedPointer<KConfig> sddmConfig = openConfig(args[QStringLiteral("kde_settings.conf")].toString()); | ||||
120 | QSharedPointer<KConfig> sddmOldConfig = openConfig(args[QStringLiteral("sddm.conf")].toString()); | ||||
121 | | ||||
122 | QMap<QString, QVariant>::const_iterator iterator; | ||||
123 | | ||||
124 | for (iterator = args.constBegin() ; iterator != args.constEnd() ; ++iterator) { | ||||
125 | if (iterator.key() == QLatin1String("kde_settings.conf")) | ||||
126 | continue; | ||||
127 | | ||||
128 | QStringList configFields = iterator.key().split(QLatin1Char('/')); | ||||
129 | if (configFields.size() != 3) { | ||||
130 | continue; | ||||
131 | } | ||||
132 | | ||||
133 | QSharedPointer<KConfig> config; | ||||
134 | QString fileName = configFields[0]; | ||||
135 | QString groupName = configFields[1]; | ||||
136 | QString keyName = configFields[2]; | ||||
137 | | ||||
138 | if (fileName == QLatin1String("kde_settings.conf")) { | ||||
139 | sddmConfig->group(groupName).writeEntry(keyName, iterator.value()); | ||||
140 | sddmOldConfig->group(groupName).deleteEntry(keyName); | ||||
141 | } | ||||
142 | } | ||||
143 | | ||||
144 | sddmOldConfig->sync(); | ||||
145 | sddmConfig->sync(); | ||||
146 | | ||||
147 | return ActionReply::SuccessReply(); | ||||
148 | } | ||||
149 | | ||||
150 | ActionReply SddmAuthHelper::reset(const QVariantMap &args) | ||||
151 | { | ||||
152 | QDir sddmConfigLocation(args[QStringLiteral("sddmUserConfig")].toString()); | ||||
153 | QDir fontconfigDir(args[QStringLiteral("sddmUserConfig")].toString() + QStringLiteral("/fontconfig")); | ||||
154 | | ||||
155 | fontconfigDir.removeRecursively(); | ||||
156 | QFile::remove(sddmConfigLocation.path() + QStringLiteral("/kdeglobals")); | ||||
157 | QFile::remove(sddmConfigLocation.path() + QStringLiteral("/plasmarc")); | ||||
158 | | ||||
159 | // remove cursor theme from config file | ||||
160 | ActionReply reply = ActionReply::HelperErrorReply(); | ||||
161 | QSharedPointer<KConfig> sddmConfig = openConfig(args[QStringLiteral("kde_settings.conf")].toString()); | ||||
162 | QSharedPointer<KConfig> sddmOldConfig = openConfig(args[QStringLiteral("sddm.conf")].toString()); | ||||
163 | | ||||
164 | QMap<QString, QVariant>::const_iterator iterator; | ||||
165 | | ||||
166 | for (iterator = args.constBegin() ; iterator != args.constEnd() ; ++iterator) { | ||||
167 | if (iterator.key() == QLatin1String("kde_settings.conf")) | ||||
168 | continue; | ||||
169 | | ||||
170 | QStringList configFields = iterator.key().split(QLatin1Char('/')); | ||||
171 | if (configFields.size() != 3) { | ||||
172 | continue; | ||||
173 | } | ||||
174 | | ||||
175 | QSharedPointer<KConfig> config; | ||||
176 | QString fileName = configFields[0]; | ||||
177 | QString groupName = configFields[1]; | ||||
178 | QString keyName = configFields[2]; | ||||
179 | | ||||
180 | if (fileName == QLatin1String("kde_settings.conf")) { | ||||
181 | sddmConfig->group(groupName).deleteEntry(keyName); | ||||
182 | sddmOldConfig->group(groupName).deleteEntry(keyName); | ||||
183 | } | ||||
184 | } | ||||
185 | | ||||
186 | sddmOldConfig->sync(); | ||||
187 | sddmConfig->sync(); | ||||
188 | | ||||
189 | return ActionReply::SuccessReply(); | ||||
190 | } | ||||
191 | | ||||
49 | ActionReply SddmAuthHelper::save(const QVariantMap &args) | 192 | ActionReply SddmAuthHelper::save(const QVariantMap &args) | ||
50 | { | 193 | { | ||
51 | ActionReply reply = ActionReply::HelperErrorReply(); | 194 | ActionReply reply = ActionReply::HelperErrorReply(); | ||
52 | QSharedPointer<KConfig> sddmConfig = openConfig(args[QStringLiteral("kde_settings.conf")].toString()); | 195 | QSharedPointer<KConfig> sddmConfig = openConfig(args[QStringLiteral("kde_settings.conf")].toString()); | ||
53 | QSharedPointer<KConfig> sddmOldConfig = openConfig(args[QStringLiteral("sddm.conf")].toString()); | 196 | QSharedPointer<KConfig> sddmOldConfig = openConfig(args[QStringLiteral("sddm.conf")].toString()); | ||
54 | QSharedPointer<KConfig> themeConfig; | 197 | QSharedPointer<KConfig> themeConfig; | ||
55 | QString themeConfigFile = args[QStringLiteral("theme.conf.user")].toString(); | 198 | QString themeConfigFile = args[QStringLiteral("theme.conf.user")].toString(); | ||
56 | 199 | | |||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 354 | { | |||
225 | 368 | | |||
226 | if (!dir.removeRecursively()) { | 369 | if (!dir.removeRecursively()) { | ||
227 | return ActionReply::HelperErrorReply(); | 370 | return ActionReply::HelperErrorReply(); | ||
228 | } | 371 | } | ||
229 | 372 | | |||
230 | return ActionReply::SuccessReply(); | 373 | return ActionReply::SuccessReply(); | ||
231 | } | 374 | } | ||
232 | 375 | | |||
233 | | ||||
234 | KAUTH_HELPER_MAIN("org.kde.kcontrol.kcmsddm", SddmAuthHelper) | 376 | KAUTH_HELPER_MAIN("org.kde.kcontrol.kcmsddm", SddmAuthHelper) | ||
235 | 377 | | |||
236 | #include "moc_sddmauthhelper.cpp" | 378 | #include "moc_sddmauthhelper.cpp" | ||
237 | |
Task for another day, we don't need to pass this in every time.
We can set this at compile time, using the same values from config.h as the KCM would use