1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
commit d3a9d56143cf668c7d29b26a324a424d02036371
Author: Timothy Pearson <kb9vqf@pearsoncomputing.net>
Date: 1337109016 -0500
Add the ability to force read-only configuration file access in a TDE application
Force kde-config to use read-only access
This closes Bug 293
diff --git a/kdecore/kconfigbackend.cpp b/kdecore/kconfigbackend.cpp
index 9ee9dd6..4ad0e5f 100644
--- a/kdecore/kconfigbackend.cpp
+++ b/kdecore/kconfigbackend.cpp
@@ -247,17 +247,22 @@ void KConfigBackEnd::changeFileName(const TQString &_fileName,
mfileName = _fileName;
resType = _resType;
useKDEGlobals = _useKDEGlobals;
- if (mfileName.isEmpty())
+ if (mfileName.isEmpty()) {
mLocalFileName = TQString::null;
- else if (!TQDir::isRelativePath(mfileName))
+ }
+ else if (!TQDir::isRelativePath(mfileName)) {
mLocalFileName = mfileName;
- else
- mLocalFileName = KGlobal::dirs()->saveLocation(resType) + mfileName;
+ }
+ else {
+ mLocalFileName = KGlobal::dirs()->saveLocation(resType, TQString(), false) + mfileName;
+ }
- if (useKDEGlobals)
+ if (useKDEGlobals) {
mGlobalFileName = KGlobal::dirs()->saveLocation("config", TQString(), false) + TQString::fromLatin1("kdeglobals");
- else
+ }
+ else {
mGlobalFileName = TQString::null;
+ }
d->localLastModified = TQDateTime();
d->localLastSize = 0;
diff --git a/kdecore/kconfigbase.cpp b/kdecore/kconfigbase.cpp
index 9ad6600..c5c0a4e 100644
--- a/kdecore/kconfigbase.cpp
+++ b/kdecore/kconfigbase.cpp
@@ -1139,16 +1139,18 @@ static TQString translatePath( TQString path )
// return original path, if it refers to another type of URL (e.g. http:/), or
// if the path is already relative to another directory
- if (!startsWithFile && path[0] != '/' ||
- startsWithFile && path[5] != '/')
+ if (((!startsWithFile) && (path[0] != '/')) || (startsWithFile && (path[5] != '/'))) {
return path;
+ }
- if (startsWithFile)
+ if (startsWithFile) {
path.remove(0,5); // strip leading "file:/" off the string
+ }
// keep only one single '/' at the beginning - needed for cleanHomeDirPath()
- while (path[0] == '/' && path[1] == '/')
+ while (path[0] == '/' && path[1] == '/') {
path.remove(0,1);
+ }
// we can not use KGlobal::dirs()->relativeLocation("home", path) here,
// since it would not recognize paths without a trailing '/'.
diff --git a/kdecore/kinstance.cpp b/kdecore/kinstance.cpp
index fe0a515..5b3aa86 100644
--- ./kdecore/kinstance.cpp.orig 2011-08-11 04:30:15.000000000 +0200
+++ ./kdecore/kinstance.cpp 2012-06-19 21:14:21.569741870 +0200
@@ -70,7 +70,7 @@
: _dirs (0L),
_config (0L),
_iconLoader (0L),
- _name( name ), _aboutData( new KAboutData( name, "", 0 ) )
+ _name( name ), _aboutData( new KAboutData( name, "", 0 ) ), m_configReadOnly(false)
{
DEBUG_ADD
Q_ASSERT(!name.isEmpty());
@@ -88,7 +88,7 @@
: _dirs (0L),
_config (0L),
_iconLoader (0L),
- _name( aboutData->appName() ), _aboutData( aboutData )
+ _name( aboutData->appName() ), _aboutData( aboutData ), m_configReadOnly(false)
{
DEBUG_ADD
Q_ASSERT(!_name.isEmpty());
@@ -107,7 +107,7 @@
: _dirs ( src->_dirs ),
_config ( src->_config ),
_iconLoader ( src->_iconLoader ),
- _name( src->_name ), _aboutData( src->_aboutData )
+ _name( src->_name ), _aboutData( src->_aboutData ), m_configReadOnly(false)
{
DEBUG_ADD
Q_ASSERT(!_name.isEmpty());
@@ -174,6 +174,11 @@
extern bool kde_kiosk_exception;
extern bool kde_kiosk_admin;
+void KInstance::setConfigReadOnly(bool ro)
+{
+ m_configReadOnly = ro;
+}
+
KConfig *KInstance::config() const
{
DEBUG_CHECK_ALIVE
@@ -198,10 +203,12 @@
if ( d->sharedConfig == 0 )
{
- if ( !_name.isEmpty() )
- d->sharedConfig = KSharedConfig::openConfig( _name + "rc");
- else
+ if ( !_name.isEmpty() ) {
+ d->sharedConfig = KSharedConfig::openConfig( _name + "rc", m_configReadOnly );
+ }
+ else {
d->sharedConfig = KSharedConfig::openConfig( TQString::null );
+ }
}
// Check if we are excempt from kiosk restrictions
@@ -211,7 +218,7 @@
d->sharedConfig = 0;
return config(); // Reread...
}
-
+
_config = d->sharedConfig;
if (_dirs)
if (_dirs->addCustomized(_config))
diff --git a/kdecore/kinstance.h b/kdecore/kinstance.h
index 75cc4b4..444a2d8 100644
--- a/kdecore/kinstance.h
+++ b/kdecore/kinstance.h
@@ -69,7 +69,7 @@ class kdecore_EXPORT KInstance
* Only for K(Unique)Application
* Initialize from src and delete it.
*/
-
+
KInstance( KInstance* src );
/**
@@ -96,6 +96,14 @@ class kdecore_EXPORT KInstance
KSharedConfig *sharedConfig() const;
/**
+ * Set a read-only flag on the configuration files
+ * This must be called before config() or dirs() to have any effect
+ * Defaults to FALSE
+ * @param ro read only if TRUE
+ */
+ void setConfigReadOnly(bool ro);
+
+ /**
* Returns an iconloader object.
* @return the iconloader object.
*/
@@ -162,6 +170,7 @@ protected:
virtual void virtual_hook( int id, void* data );
private:
KInstancePrivate *d;
+ bool m_configReadOnly;
};
#endif
diff --git a/kdecore/kstandarddirs.cpp b/kdecore/kstandarddirs.cpp
index bce4bf4..bb8ae97 100644
--- a/kdecore/kstandarddirs.cpp.orig 2011-08-21 06:15:32.000000000 +0200
+++ b/kdecore/kstandarddirs.cpp 2012-06-19 21:17:34.550007910 +0200
@@ -451,13 +450,17 @@
bool KStandardDirs::exists(const TQString &fullPath)
{
KDE_struct_stat buff;
- if (access(TQFile::encodeName(fullPath), R_OK) == 0 && KDE_stat( TQFile::encodeName(fullPath), &buff ) == 0)
+ if ((access(TQFile::encodeName(fullPath), R_OK) == 0) && (KDE_stat( TQFile::encodeName(fullPath), &buff ) == 0)) {
if (fullPath.tqat(fullPath.length() - 1) != QChar('/')) {
if (S_ISREG( buff.st_mode ))
return true;
- } else
- if (S_ISDIR( buff.st_mode ))
+ }
+ else {
+ if (S_ISDIR( buff.st_mode )) {
return true;
+ }
+ }
+ }
return false;
}
@@ -767,17 +770,23 @@
srv = findExe(TQString::tqfromLatin1("lnusertemp"));
if (!srv.isEmpty())
{
- system(TQFile::encodeName(srv)+" "+type);
- result = readlink(TQFile::encodeName(dir).data(), link, 1023);
+ if (system(TQFile::encodeName(srv)+" "+type) < 0 ) {
+ result = readlink(TQFile::encodeName(dir).data(), link, 1023);
+ }
+ else {
+ result = -1;
+ }
}
}
if (result > 0)
{
link[result] = 0;
- if (link[0] == TQChar('/').latin1())
+ if (link[0] == TQChar('/').latin1()) {
dir = TQFile::decodeName(link);
- else
+ }
+ else {
dir = TQDir::cleanDirPath(dir+TQFile::decodeName(link));
+ }
}
#endif
addResourceDir(type, dir+QChar('/'));
@@ -1139,8 +1148,9 @@
}
dircache.remove(type);
}
- if (!fullPath.endsWith("/"))
+ if (!fullPath.endsWith("/")) {
fullPath += "/";
+ }
return fullPath;
}
diff --git a/kdecore/kde-config.cpp.in b/kdecore/kde-config.cpp.in
index 90c5dae..c988b00 100644
--- a/kdecore/kde-config.cpp.in
+++ b/kdecore/kde-config.cpp.in
@@ -120,6 +120,7 @@ int main(int argc, char **argv)
KCmdLineArgs::addCmdLineOptions( options ); // Add my own options.
KInstance a("kde-config");
+ a.setConfigReadOnly(TRUE);
(void)KGlobal::dirs(); // trigger the creation
(void)KGlobal::config();
|