25 #include <QtCore/QMap>
26 #include <QtCore/QMutableMapIterator>
27 #include <QtCore/QFile>
28 #include <QtCore/QRegExp>
29 #include <QtCore/QFileInfo>
30 #include <QtCore/QTextStream>
31 #include <QtCore/QStringList>
43 "/etc/samba/smb.conf",
45 "/usr/local/etc/smb.conf",
46 "/usr/local/samba/lib/smb.conf",
47 "/usr/samba/lib/smb.conf",
49 "/usr/local/lib/smb.conf"
59 , skipUserShare(false)
77 kDebug() <<
"Samba is not installed!";
94 kWarning() <<
"KSambaShare: Could not find smb.conf!";
103 if (fileInfo.
isDir()) {
104 userSharePath = rawString;
145 if ((err.
count() == 2)
146 && err.
at(0).startsWith(
"Load smb config files from")
147 && err.
at(1).startsWith(
"Loaded services file OK.")) {
148 kDebug() <<
"Running testparm" << args;
150 kWarning() <<
"We got some errors while running testparm" << stdErr;
173 runProcess(QLatin1String(
"net"), args, stdOut, stdErr);
176 if (stdErr.
contains(
"You do not have permission to create a usershare")) {
177 skipUserShare =
true;
178 }
else if (stdErr.
contains(
"usershares are currently disabled")) {
179 skipUserShare =
true;
184 kWarning() <<
"We got some errors while running 'net usershare info'";
204 dirs << i.
value().path();
213 return data.
value(shareName);
222 if (i.
value().path() == path) {
234 return (notToMatchRx.
indexIn(name) == -1);
241 if (i.
value().path() == path) {
263 if (!pathInfo.
isDir()) {
276 if (!pathInfo.
permission(QFile::ReadUser | QFile::WriteUser)) {
286 const QRegExp aclRx(
"(?:(?:(\\w+\\s*)\\\\|)(\\w+\\s*):([fFrRd]{1})(?:,|))*");
319 if (data.
value(shareData.
name()).path() != shareData.
path()) {
333 << shareData.
path() << shareData.
comment() << shareData.
acl() << guestok;
341 kWarning() <<
"We got some errors while running 'net usershare add'" << args;
369 "([^%<>*\?|/\\+=;:\",]+)"
380 while (!stream.
atEnd()) {
385 shareList << currentShare;
389 shareData.dd->name = currentShare;
390 data.
insert(currentShare, shareData);
398 shareData.dd->path = value;
400 shareData.dd->comment = value;
402 shareData.dd->acl = value;
404 shareData.dd->guestPermission = value;
406 kWarning() <<
"Something nasty happen while parsing 'net usershare info'"
407 <<
"share:" << currentShare <<
"key:" << key;
430 kDebug() <<
"path changed:" << path;
435 KSambaShare::KSambaShare()
465 return d->isDirectoryShared(path);
471 return d->isShareNameValid(name) && d->isShareNameAvailable(name);
477 return d->shareNames();
483 return d->sharedDirs();
489 return d->getShareByName(name);
495 return d->getSharesByPath(path);
504 #include "moc_ksambashare.cpp"
QStringList shareNames() const
Returns the list of available shares.
QString cap(int nth) const
static KDirWatch * self()
bool contains(const Key &key) const
bool isDirectoryShared(const QString &path) const
Whether or not the given path is shared by Samba.
QList< QByteArray > split(char sep) const
QString readLine(qint64 maxlen)
QByteArray trimmed() const
void _k_slotFileChange(const QString &path)
KSambaSharePrivate(KSambaShare *parent)
#define K_GLOBAL_STATIC(TYPE, NAME)
const_iterator constBegin() const
const T & at(int i) const
bool isShareNameAvailable(const QString &name) const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
bool permission(QFlags< QFile::Permission > permissions) const
This class represents a Samba user share.
static KSambaShare * instance()
void setOutputChannelMode(OutputChannelMode mode)
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QList< Key > keys() const
int indexIn(const QString &str, int offset, CaretMode caretMode) const
int count(const T &value) const
QString fromLocal8Bit(const char *str, int size)
static QStringList allUserNames()
bool isShareNameAvailable(const QString &name) const
Tests that a share name is valid and does not conflict with system users names or shares...
const_iterator constEnd() const
KSambaShareData::UserShareError isAclValid(const QString &acl) const
static QString testparmParamValue(const QString ¶meterName)
QList< KSambaShareData > getSharesByPath(const QString &path) const
static bool isSambaInstalled()
bool isDirectoryShared(const QString &path) const
KSambaShareData::UserShareError remove(const KSambaShareData &shareName) const
KSambaShareData::GuestPermission guestPermission() const
KSambaShareData::UserShareError isPathValid(const QString &path) const
static const int DefaultSambaConfigFilePathListSize
bool isShareNameValid(const QString &name) const
QList< KSambaShareData > getSharesByPath(const QString &path) const
Returns a list of KSambaShareData matching the path.
QByteArray getNetUserShareInfo()
QStringList shareNames() const
QStringList sharedDirs() const
bool contains(char ch) const
int execute(int msecs=-1)
static int runProcess(const QString &progName, const QStringList &args, QByteArray &stdOut, QByteArray &stdErr)
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
void removeDir(const QString &path)
void addDir(const QString &path, WatchModes watchModes=WatchDirOnly)
iterator insert(const Key &key, const T &value)
QStringList sharedDirectories() const
Returns a list of all directories shared by local users in Samba.
KSambaShareData::UserShareError add(const KSambaShareData &shareData)
QString smbConfPath() const
Returns the path to the used smb.conf file or empty string if no file was found.
QString acl() const
Returns a containing a string describing the permission added to the users, such as "[DOMAIN\]usernam...
bool exactMatch(const QString &str) const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
KSambaShareData getShareByName(const QString &name) const
Returns the KSambaShareData object of the share name.
static const char *const DefaultSambaConfigFilePathList[]
KSambaShareData getShareByName(const QString &shareName) const
QByteArray readAllStandardOutput()
QByteArray readAllStandardError()
This class lists Samba user shares and monitors them for addition, update and removal.
KSambaShareData::UserShareError guestsAllowed(const KSambaShareData::GuestPermission &guestok) const
const T value(const Key &key) const
void setProgram(const QString &exe, const QStringList &args=QStringList())
bool waitForFinished(int msecs)