20 #include "tdefileshare.h"
24 #include <tdeprocess.h>
25 #include <tdeprocio.h>
26 #include <tdelocale.h>
27 #include <kstaticdeleter.h>
28 #include <kstandarddirs.h>
30 #include <kdirwatch.h>
34 #include <kdirnotify_stub.h>
35 #include <ksimpleconfig.h>
38 KFileShare::Authorization KFileShare::s_authorization = NotInitialized;
41 TQMap<TQString,TQString>* KFileShare::s_shareMap = 0L;
42 static KStaticDeleter<TQMap<TQString,TQString> > sdShareMap;
45 bool KFileShare::s_sambaEnabled;
46 bool KFileShare::s_nfsEnabled;
47 bool KFileShare::s_restricted;
48 TQString KFileShare::s_fileShareGroup;
49 bool KFileShare::s_sharingEnabled;
52 #define FILESHARECONF "/etc/security/fileshare.conf"
54 KFileSharePrivate::KFileSharePrivate()
58 TQ_SLOT(slotFileChange(
const TQString &)));
60 TQ_SLOT(slotFileChange(
const TQString &)));
62 TQ_SLOT(slotFileChange(
const TQString &)));
65 KFileSharePrivate::~KFileSharePrivate()
70 KFileSharePrivate *KFileSharePrivate::_self=0L;
72 static KStaticDeleter<KFileSharePrivate> kstFileShare;
74 KFileSharePrivate* KFileSharePrivate::self()
77 _self = kstFileShare.setObject(_self,
new KFileSharePrivate());
81 void KFileSharePrivate::slotFileChange(
const TQString &file)
83 if(file==FILESHARECONF) {
92 KFileSharePrivate::self();
93 KSimpleConfig config(TQString::fromLatin1(FILESHARECONF),
true);
95 s_sharingEnabled = config.readEntry(
"FILESHARING",
"yes") ==
"yes";
96 s_restricted = config.readEntry(
"RESTRICT",
"yes") ==
"yes";
97 s_fileShareGroup = config.readEntry(
"FILESHAREGROUP",
"fileshare");
100 if (!s_sharingEnabled)
101 s_authorization = UserNotAllowed;
104 s_authorization = Authorized;
107 KUserGroup shareGroup(s_fileShareGroup);
108 if (shareGroup.users().findIndex(KUser()) > -1 )
109 s_authorization = Authorized;
111 s_authorization = UserNotAllowed;
114 if (config.readEntry(
"SHARINGMODE",
"simple") ==
"simple")
115 s_shareMode = Simple;
117 s_shareMode = Advanced;
120 s_sambaEnabled = config.readEntry(
"SAMBA",
"yes") ==
"yes";
121 s_nfsEnabled = config.readEntry(
"NFS",
"yes") ==
"yes";
125 if ( s_authorization == NotInitialized )
132 if ( s_authorization == NotInitialized )
135 return s_sharingEnabled;
139 if ( s_authorization == NotInitialized )
146 if ( s_authorization == NotInitialized )
149 return s_fileShareGroup;
154 if ( s_authorization == NotInitialized )
157 return s_sambaEnabled;
161 if ( s_authorization == NotInitialized )
170 KFileSharePrivate::self();
172 sdShareMap.setObject( s_shareMap,
new TQMap<TQString,TQString> );
177 TQString exe = findExe(
"filesharelist" );
179 s_authorization = ErrorNotFound;
184 if ( !proc.start( TDEProcess::Block ) ) {
185 kdError() <<
"Can't run " << exe << endl;
186 s_authorization = ErrorNotFound;
195 TQRegExp rx_line(
"([^\\s]+)\\s+(.*)");
197 length = proc.readln(line,
true);
200 if ( line[length-1] !=
'/' )
202 if( rx_line.search( line ) != -1 ) {
203 options = rx_line.cap(1);
204 path = rx_line.cap(2);
205 (*s_shareMap)[path] = options;
207 kdDebug(7000) <<
"Shared dir:" << line << endl;
209 }
while (length > -1);
220 TQString path( _path );
221 if ( path[path.length()-1] !=
'/' )
224 if( (*s_shareMap).contains(path) && !((*s_shareMap)[path].isEmpty()) ) {
226 if( (*s_shareMap)[path].find(
"readwrite") != -1 )
236 if ( s_authorization == NotInitialized )
238 return s_authorization;
241 TQString KFileShare::findExe(
const char* exeName )
244 TQString path = TQString::fromLocal8Bit(getenv(
"PATH")) + TQString::fromLatin1(
":/usr/sbin");
245 TQString exe = TDEStandardDirs::findExe( exeName, path );
247 kdError() << exeName <<
" not found in " << path << endl;
253 return SuSEsetShared( path, shared,
false );
256 bool KFileShare::SuSEsetShared(
const TQString& path,
bool shared,
bool rw )
262 TQString exe = KFileShare::findExe(
"fileshareset" );
271 proc.start( TDEProcess::Block );
272 proc.clearArguments();
282 proc.start( TDEProcess::Block );
283 bool ok = proc.normalExit() && (proc.exitStatus() == 0);
284 kdDebug(7000) <<
"KFileSharePropsPlugin::setShared normalExit="
285 << proc.normalExit() << endl;
286 kdDebug(7000) <<
"KFileSharePropsPlugin::setShared exitStatus="
287 << proc.exitStatus() << endl;
288 if ( proc.normalExit() ) {
289 switch( proc.exitStatus() ) {
329 int status = system(
"/sbin/checkproc -p /var/run/samba/smbd.pid /usr/sbin/smbd" );
330 return status != -1 && WIFEXITED( status ) && WEXITSTATUS( status ) == 0;
336 int status = system(
"/sbin/checkproc /usr/sbin/rpc.mountd" );
337 if( status != -1 && WIFEXITED( status ) && WEXITSTATUS( status ) == 0 )
339 status = system(
"/sbin/checkproc -n nfsd" );
340 if( status != -1 && WIFEXITED( status ) && WEXITSTATUS( status ) == 0 )
346 #include "tdefileshare.moc"