21 #include <tqtextstream.h>
23 #include <kdirwatch.h>
24 #include <kstaticdeleter.h>
26 #include <ksimpleconfig.h>
28 #include "ksambashare.h"
30 class KSambaSharePrivate
39 TQDict<bool> sharedPaths;
43 KSambaSharePrivate::KSambaSharePrivate()
49 #define FILESHARECONF "/etc/security/fileshare.conf"
51 bool KSambaSharePrivate::load() {
64 bool KSambaSharePrivate::findSmbConf() {
65 KSimpleConfig config(TQString::fromLatin1(FILESHARECONF),
true);
66 smbConf = config.readEntry(
"SMBCONF");
68 if ( TQFile::exists(smbConf) )
71 if ( TQFile::exists(
"/etc/samba/smb.conf") )
72 smbConf =
"/etc/samba/smb.conf";
74 if ( TQFile::exists(
"/etc/smb.conf") )
75 smbConf =
"/etc/smb.conf";
77 if ( TQFile::exists(
"/usr/local/samba/lib/smb.conf") )
78 smbConf =
"/usr/local/samba/lib/smb.conf";
80 if ( TQFile::exists(
"/usr/samba/lib/smb.conf") )
81 smbConf =
"/usr/samba/lib/smb.conf";
83 if ( TQFile::exists(
"/usr/lib/smb.conf") )
84 smbConf =
"/usr/lib/smb.conf";
86 if ( TQFile::exists(
"/usr/local/lib/smb.conf") )
87 smbConf =
"/usr/local/lib/smb.conf";
89 kdDebug(7000) <<
"KSambaShare: Could not found smb.conf!" << endl;
101 bool KSambaSharePrivate::readSmbConf() {
104 kdDebug(7000) <<
"KSambaShare::readSmbConf " << smbConf << endl;
106 if (!f.open(IO_ReadOnly)) {
107 kdError() <<
"KSambaShare: Could not open " << smbConf << endl;
115 bool continuedLine =
false;
116 TQString completeLine;
120 TQString currentLine = s.readLine().stripWhiteSpace();
123 completeLine += currentLine;
124 continuedLine =
false;
127 completeLine = currentLine;
130 if ( completeLine[completeLine.length()-1] ==
'\\' )
132 continuedLine =
true;
134 completeLine.truncate( completeLine.length()-1 );
139 if (completeLine.isEmpty() ||
140 '#' == completeLine[0] ||
141 ';' == completeLine[0])
147 int i = completeLine.find(
'=');
151 TQString name = completeLine.left(i).stripWhiteSpace().lower();
152 TQString value = completeLine.mid(i+1).stripWhiteSpace();
154 if (name == TDEGlobal::staticQString(
"path")) {
156 if ( value[0] ==
'"' )
159 if ( value[value.length()-1] ==
'"' )
160 value.truncate(value.length()-1);
163 if ( value[value.length()-1] !=
'/' )
167 sharedPaths.insert(value,&b);
168 kdDebug(7000) <<
"KSambaShare: Found path: " << value << endl;
179 KSambaShare::KSambaShare() {
180 d =
new KSambaSharePrivate();
181 if (TQFile::exists(d->smbConf)) {
185 TQ_SLOT(slotFileChange(
const TQString&)));
190 if (TQFile::exists(d->smbConf)) {
202 TQString fixedPath = path;
203 if ( path[path.length()-1] !=
'/' )
206 return d->sharedPaths.find(fixedPath) != 0;
211 TQDictIterator<bool> it(d->sharedPaths);
212 for( ; it.current(); ++it )
213 result << it.currentKey();
218 void KSambaShare::slotFileChange(
const TQString & path ) {
219 if (path == d->smbConf)
222 if (path == FILESHARECONF)
229 static KStaticDeleter<KSambaShare> ksdSambaShare;
233 _instance = ksdSambaShare.setObject(_instance,
new KSambaShare());
238 #include "ksambashare.moc"
static KDirWatch * self()
The KDirWatch instance usually globally used in an application.
void addFile(const TQString &file)
Adds a file to be watched.
void removeFile(const TQString &file)
Removes a file from the list of watched files.
Similar functionality like KFileShare, but works only for Samba and do not need any suid script.
bool isDirectoryShared(const TQString &path) const
Whether or not the given path is shared by Samba.
virtual ~KSambaShare()
KSambaShare destructor.
TQStringList sharedDirectories() const
Returns a list of all directories shared by Samba.
void changed()
Emitted when the smb.conf file has changed.
TQString smbConfPath() const
Returns the path to the used smb.conf file or null if no file was found.
static KSambaShare * instance()
Returns the one and only instance of KSambaShare.