• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
ksambashare.cpp
1/* This file is part of the KDE project
2 Copyright (c) 2004 Jan Schaefer <j_schaef@informatik.uni-kl.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include <tqdict.h>
20#include <tqfile.h>
21#include <tqtextstream.h>
22
23#include <kdirwatch.h>
24#include <kstaticdeleter.h>
25#include <kdebug.h>
26#include <tdesimpleconfig.h>
27
28#include "ksambashare.h"
29
30class KSambaSharePrivate
31{
32public:
33 KSambaSharePrivate();
34
35 bool readSmbConf();
36 bool findSmbConf();
37 bool load();
38
39 TQDict<bool> sharedPaths;
40 TQString smbConf;
41};
42
43KSambaSharePrivate::KSambaSharePrivate()
44{
45 load();
46}
47
48
49#define FILESHARECONF "/etc/security/fileshare.conf"
50
51bool KSambaSharePrivate::load() {
52 if (!findSmbConf())
53 return false;
54
55 return readSmbConf();
56}
57
64bool KSambaSharePrivate::findSmbConf() {
65 TDESimpleConfig config(TQString::fromLatin1(FILESHARECONF),true);
66 smbConf = config.readEntry("SMBCONF");
67
68 if ( TQFile::exists(smbConf) )
69 return true;
70
71 if ( TQFile::exists("/etc/samba/smb.conf") )
72 smbConf = "/etc/samba/smb.conf";
73 else
74 if ( TQFile::exists("/etc/smb.conf") )
75 smbConf = "/etc/smb.conf";
76 else
77 if ( TQFile::exists("/usr/local/samba/lib/smb.conf") )
78 smbConf = "/usr/local/samba/lib/smb.conf";
79 else
80 if ( TQFile::exists("/usr/samba/lib/smb.conf") )
81 smbConf = "/usr/samba/lib/smb.conf";
82 else
83 if ( TQFile::exists("/usr/lib/smb.conf") )
84 smbConf = "/usr/lib/smb.conf";
85 else
86 if ( TQFile::exists("/usr/local/lib/smb.conf") )
87 smbConf = "/usr/local/lib/smb.conf";
88 else {
89 kdDebug(7000) << "KSambaShare: Could not found smb.conf!" << endl;
90 return false;
91 }
92
93 return true;
94}
95
96
101bool KSambaSharePrivate::readSmbConf() {
102 TQFile f(smbConf);
103
104 kdDebug(7000) << "KSambaShare::readSmbConf " << smbConf << endl;
105
106 if (!f.open(IO_ReadOnly)) {
107 kdError() << "KSambaShare: Could not open " << smbConf << endl;
108 return false;
109 }
110
111 sharedPaths.clear();
112
113 TQTextStream s(&f);
114
115 bool continuedLine = false; // is true if the line before ended with a backslash
116 TQString completeLine;
117
118 while (!s.eof())
119 {
120 TQString currentLine = s.readLine().stripWhiteSpace();
121
122 if (continuedLine) {
123 completeLine += currentLine;
124 continuedLine = false;
125 }
126 else
127 completeLine = currentLine;
128
129 // is the line continued in the next line ?
130 if ( completeLine[completeLine.length()-1] == '\\' )
131 {
132 continuedLine = true;
133 // remove the ending backslash
134 completeLine.truncate( completeLine.length()-1 );
135 continue;
136 }
137
138 // comments or empty lines
139 if (completeLine.isEmpty() ||
140 '#' == completeLine[0] ||
141 ';' == completeLine[0])
142 {
143 continue;
144 }
145
146 // parameter
147 int i = completeLine.find('=');
148
149 if (i>-1)
150 {
151 TQString name = completeLine.left(i).stripWhiteSpace().lower();
152 TQString value = completeLine.mid(i+1).stripWhiteSpace();
153
154 if (name == TDEGlobal::staticQString("path")) {
155 // Handle quotation marks
156 if ( value[0] == '"' )
157 value.remove(0,1);
158
159 if ( value[value.length()-1] == '"' )
160 value.truncate(value.length()-1);
161
162 // Normalize path
163 if ( value[value.length()-1] != '/' )
164 value += '/';
165
166 bool b = true;
167 sharedPaths.insert(value,&b);
168 kdDebug(7000) << "KSambaShare: Found path: " << value << endl;
169 }
170 }
171 }
172
173 f.close();
174
175 return true;
176
177}
178
179KSambaShare::KSambaShare() {
180 d = new KSambaSharePrivate();
181 if (TQFile::exists(d->smbConf)) {
182 KDirWatch::self()->addFile(d->smbConf);
183 KDirWatch::self()->addFile(FILESHARECONF);
184 connect(KDirWatch::self(), TQ_SIGNAL(dirty (const TQString&)),this,
185 TQ_SLOT(slotFileChange(const TQString&)));
186 }
187}
188
189KSambaShare::~KSambaShare() {
190 if (TQFile::exists(d->smbConf)) {
191 KDirWatch::self()->removeFile(d->smbConf);
192 KDirWatch::self()->removeFile(FILESHARECONF);
193 }
194 delete d;
195}
196
197TQString KSambaShare::smbConfPath() const {
198 return d->smbConf;
199}
200
201bool KSambaShare::isDirectoryShared( const TQString & path ) const {
202 TQString fixedPath = path;
203 if ( path[path.length()-1] != '/' )
204 fixedPath += '/';
205
206 return d->sharedPaths.find(fixedPath) != 0;
207}
208
209TQStringList KSambaShare::sharedDirectories() const {
210 TQStringList result;
211 TQDictIterator<bool> it(d->sharedPaths);
212 for( ; it.current(); ++it )
213 result << it.currentKey();
214
215 return result;
216}
217
218void KSambaShare::slotFileChange( const TQString & path ) {
219 if (path == d->smbConf)
220 d->readSmbConf();
221 else
222 if (path == FILESHARECONF)
223 d->load();
224
225 emit changed();
226}
227
228KSambaShare* KSambaShare::_instance = 0L;
229static KStaticDeleter<KSambaShare> ksdSambaShare;
230
231KSambaShare* KSambaShare::instance() {
232 if (! _instance )
233 _instance = ksdSambaShare.setObject(_instance, new KSambaShare());
234
235 return _instance;
236}
237
238#include "ksambashare.moc"
239
KDirWatch::self
static KDirWatch * self()
The KDirWatch instance usually globally used in an application.
Definition: kdirwatch.cpp:1634
KDirWatch::addFile
void addFile(const TQString &file)
Adds a file to be watched.
Definition: kdirwatch.cpp:1696
KDirWatch::removeFile
void removeFile(const TQString &file)
Removes a file from the list of watched files.
Definition: kdirwatch.cpp:1723
KSambaShare
Similar functionality like KFileShare, but works only for Samba and do not need any suid script.
Definition: ksambashare.h:35
KSambaShare::isDirectoryShared
bool isDirectoryShared(const TQString &path) const
Whether or not the given path is shared by Samba.
Definition: ksambashare.cpp:201
KSambaShare::~KSambaShare
virtual ~KSambaShare()
KSambaShare destructor.
Definition: ksambashare.cpp:189
KSambaShare::sharedDirectories
TQStringList sharedDirectories() const
Returns a list of all directories shared by Samba.
Definition: ksambashare.cpp:209
KSambaShare::changed
void changed()
Emitted when the smb.conf file has changed.
KSambaShare::smbConfPath
TQString smbConfPath() const
Returns the path to the used smb.conf file or null if no file was found.
Definition: ksambashare.cpp:197
KSambaShare::instance
static KSambaShare * instance()
Returns the one and only instance of KSambaShare.
Definition: ksambashare.cpp:231

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.4
This website is maintained by Timothy Pearson.