kio: remove unused file sharing API

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-06-08 01:10:41 +03:00
parent 99f7264aae
commit 32872f16d5
14 changed files with 6 additions and 1252 deletions

View file

@ -49,7 +49,7 @@ find_package(Perl)
set_package_properties(Perl PROPERTIES
URL "http://www.perl.org"
TYPE RUNTIME
PURPOSE "Needed for KIO fileshareset and KDEUI preparetips scripts"
PURPOSE "Needed for KDEUI preparetips script"
)
find_package(ZLIB)

View file

@ -137,8 +137,6 @@ install(
KFileMetaInfoGroup
KFileMetaInfoItem
KFilePlacesModel
KFileShare
KFileSharePropsPlugin
KFileTreeView
KFilterBase
KFilterDev

View file

@ -1 +0,0 @@
#include "../kfileshare.h"

View file

@ -1 +0,0 @@
#include "../kfilesharedialog.h"

View file

@ -79,7 +79,6 @@ set(kiocore_STAT_SRCS
kio/kfileitemdelegate.cpp
kio/kfilemetainfo.cpp
kio/kfilemetainfoitem.cpp
kio/kfileshare.cpp
kio/kfilewriteplugin.cpp
kio/kimageio.cpp
kio/kmimetypechooser.cpp
@ -114,6 +113,10 @@ set(kiocore_STAT_SRCS
kio/kpasswdserverloop.cpp
kio/usernotificationhandler.cpp
kio/clipboardupdater.cpp
kio/kautomount.cpp
kio/knfsshare.cpp
kio/ksambashare.cpp
kio/ksambasharedata.cpp
)
qt4_add_dbus_adaptor(kiocore_STAT_SRCS
@ -136,15 +139,6 @@ qt4_add_dbus_interface(kiocore_STAT_SRCS
kpasswdserver_interface
)
if(UNIX)
set(kiocore_STAT_SRCS ${kiocore_STAT_SRCS}
kio/kautomount.cpp
kio/knfsshare.cpp
kio/ksambashare.cpp
kio/ksambasharedata.cpp
)
endif(UNIX)
set(kbookmarks_STAT_SRCS
bookmarks/kbookmark.cc
bookmarks/kbookmarkimporter.cc
@ -184,7 +178,6 @@ set(kfile_STAT_SRCS
kfile/kurlrequester.cpp
kfile/kurlrequesterdialog.cpp
kfile/kfilemetadataprovider.cpp
kfile/kfilesharedialog.cpp
)
qt4_add_resources(kfile_STAT_SRCS kfile/kacleditwidget.qrc)
@ -327,7 +320,6 @@ install(
kio/kfileitemdelegate.h
kio/kfilemetainfo.h
kio/kfilemetainfoitem.h
kio/kfileshare.h
kio/kfilewriteplugin.h
kio/kimageio.h
kio/kmimetypechooser.h
@ -360,7 +352,6 @@ install(
kfile/kurlcombobox.h
kfile/kurlrequester.h
kfile/kurlrequesterdialog.h
kfile/kfilesharedialog.h
bookmarks/kbookmark.h
bookmarks/kbookmarkexporter.h
bookmarks/kbookmarkimporter.h

View file

@ -1,285 +0,0 @@
/* This file is part of the KDE project
Copyright (c) 2001 David Faure <faure@kde.org>
Copyright (c) 2001 Laurent Montel <lmontel@mandrakesoft.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kfilesharedialog.h"
#include <QtCore/QDir>
#include <QtCore/QProcess>
#include <QtGui/QLabel>
#include <QtGui/QRadioButton>
#include <QtGui/QButtonGroup>
#include <QtGui/QLayout>
#include <QtGui/QPushButton>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <kio/kfileshare.h>
#include <kseparator.h>
#include <kmessagebox.h>
#include <kvbox.h>
class KFileSharePropsPlugin::Private
{
public:
KVBox *m_vBox;
QProcess *m_configProc;
bool m_bAllShared;
bool m_bAllUnshared;
QWidget *m_widget;
QRadioButton *m_rbShare;
QRadioButton *m_rbUnShare;
QPushButton *m_pbConfig;
};
KFileSharePropsPlugin::KFileSharePropsPlugin( KPropertiesDialog *_props )
: KPropertiesDialogPlugin( _props ),d(new Private)
{
d->m_vBox = new KVBox();
_props->addPage( d->m_vBox, i18n("&Share") );
d->m_configProc = 0;
properties->setFileSharingPage(d->m_vBox);
d->m_widget = 0L;
init();
}
KFileSharePropsPlugin::~KFileSharePropsPlugin()
{
delete d;
}
bool KFileSharePropsPlugin::supports( const KFileItemList& items )
{
// Do not show dialog if in advanced mode,
// because the advanced dialog is shown already.
if (KFileShare::shareMode() == KFileShare::Advanced) {
kDebug() << "KFileSharePropsPlugin::supports: false because sharemode is advanced";
return false;
}
KFileItemList::const_iterator kit = items.begin();
const KFileItemList::const_iterator kend = items.end();
for ( ; kit != kend; ++kit )
{
bool isLocal = (*kit).isLocalFile();
// We only support local dirs
if ( !(*kit).isDir() || !isLocal )
return false;
}
return true;
}
void KFileSharePropsPlugin::init()
{
// We store the main widget, so that it's possible (later) to call init()
// more than once, to update the page if something changed (e.g. after
// the user has been authorized)
delete d->m_widget;
d->m_rbShare = 0L;
d->m_rbUnShare = 0L;
d->m_widget = new QWidget( d->m_vBox );
QVBoxLayout * vbox = new QVBoxLayout( d->m_widget );
switch ( KFileShare::authorization() ) {
case KFileShare::Authorized:
{
// Check if all selected dirs are in $HOME
QString home = QDir::homePath();
if ( home[home.length()-1] != '/' )
home += '/';
bool ok = true;
const KFileItemList items = properties->items();
// We have 3 possibilities: all shared, all unshared, or mixed.
d->m_bAllShared = true;
d->m_bAllUnshared = true;
KFileItemList::const_iterator kit = items.begin();
const KFileItemList::const_iterator kend = items.end();
for ( ; kit != kend && ok; ++kit )
{
// We know it's local, see supports()
const QString path = (*kit).url().toLocalFile();
if ( !path.startsWith( home ) )
ok = false;
if ( KFileShare::isDirectoryShared( path ) )
d->m_bAllUnshared = false;
else
d->m_bAllShared = false;
}
if ( !ok )
{
vbox->addWidget( new QLabel( i18n( "Only folders in your home folder can be shared."),
d->m_widget ), 0 );
}
else
{
// Everything ok, show the share/unshare GUI
QButtonGroup *rbGroup = new QButtonGroup( d->m_widget );
d->m_rbUnShare = new QRadioButton( i18n("Not shared"), d->m_widget );
connect( d->m_rbUnShare, SIGNAL(toggled(bool)), SIGNAL(changed()) );
vbox->addWidget( d->m_rbUnShare, 0 );
rbGroup->addButton( d->m_rbUnShare );
d->m_rbShare = new QRadioButton( i18n("Shared"), d->m_widget );
connect( d->m_rbShare, SIGNAL(toggled(bool)), SIGNAL(changed()) );
vbox->addWidget( d->m_rbShare, 0 );
rbGroup->addButton( d->m_rbShare );
// Activate depending on status
if ( d->m_bAllShared )
d->m_rbShare->setChecked(true);
if ( d->m_bAllUnshared )
d->m_rbUnShare->setChecked(true);
// Some help text
QLabel *label = new QLabel( i18n("Sharing this folder makes it available under Linux/UNIX (NFS) and Windows (Samba).") , d->m_widget );
label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter);
label->setWordWrap(true);
vbox->addWidget( label, 0 );
KSeparator* sep=new KSeparator(d->m_widget);
vbox->addWidget( sep, 0 );
label = new QLabel( i18n("You can also reconfigure file sharing authorization.") , d->m_widget );
label->setAlignment( Qt::AlignLeft | Qt::AlignVCenter);
label->setWordWrap(true);
vbox->addWidget( label, 0 );
d->m_pbConfig = new QPushButton( i18n("Configure File Sharing..."), d->m_widget );
connect( d->m_pbConfig, SIGNAL(clicked()), SLOT(slotConfigureFileSharing()) );
vbox->addWidget( d->m_pbConfig, 0, Qt::AlignHCenter );
vbox->addStretch( 10 );
}
}
break;
case KFileShare::ErrorNotFound:
vbox->addWidget( new QLabel( i18n("Error running 'filesharelist'. Check if installed and in $PATH or /usr/sbin."),
d->m_widget ), 0 );
break;
case KFileShare::UserNotAllowed:
{
vbox->setSpacing( 10 );
if (KFileShare::sharingEnabled()) {
vbox->addWidget( new QLabel( i18n("You need to be authorized to share folders."),
d->m_widget ), 0 );
} else {
vbox->addWidget( new QLabel( i18n("File sharing is disabled."),
d->m_widget ), 0 );
}
QHBoxLayout* hBox = new QHBoxLayout( (QWidget *)0L );
vbox->addLayout( hBox, 0 );
d->m_pbConfig = new QPushButton( i18n("Configure File Sharing..."), d->m_widget );
connect( d->m_pbConfig, SIGNAL(clicked()), SLOT(slotConfigureFileSharing()) );
hBox->addWidget( d->m_pbConfig, 0, Qt::AlignHCenter );
vbox->addStretch( 10 ); // align items on top
break;
}
case KFileShare::NotInitialized:
kWarning() << "KFileShare Authorization still NotInitialized after calling authorization() - impossible";
break;
}
d->m_widget->show(); // In case the dialog was shown already.
}
void KFileSharePropsPlugin::slotConfigureFileSharing()
{
if (d->m_configProc) return;
d->m_configProc = new QProcess(this);
if (!d->m_configProc->startDetached(KStandardDirs::findExe("kdesudo"), QStringList() << "kcmshell4" << "fileshare"))
{
delete d->m_configProc;
d->m_configProc = 0;
return;
}
connect(d->m_configProc, SIGNAL(processExited(int,QProcess::ExitStatus)),
this, SLOT(slotConfigureFileSharingDone(int,QProcess::ExitStatus)));
d->m_pbConfig->setEnabled(false);
}
void KFileSharePropsPlugin::slotConfigureFileSharingDone(int exitCode, QProcess::ExitStatus exitStatus)
{
Q_UNUSED(exitCode);
Q_UNUSED(exitStatus);
delete d->m_configProc;
d->m_configProc = 0;
KFileShare::readConfig();
KFileShare::readShareList();
init();
}
void KFileSharePropsPlugin::applyChanges()
{
kDebug() << "KFileSharePropsPlugin::applyChanges";
if ( d->m_rbShare && d->m_rbUnShare )
{
bool share = d->m_rbShare->isChecked();
if (share && d->m_bAllShared)
return; // Nothing to do
if (!share && d->m_bAllUnshared)
return; // Nothing to do
const KFileItemList items = properties->items();
bool ok = true;
KFileItemList::const_iterator kit = items.begin();
const KFileItemList::const_iterator kend = items.end();
for ( ; kit != kend && ok; ++kit )
{
const QString path = (*kit).url().toLocalFile();
ok = setShared( path, share );
if (!ok) {
if (share)
KMessageBox::detailedError(properties,
i18n("Sharing folder '%1' failed.", path),
i18n("An error occurred while trying to share folder '%1'. "
"Make sure that the Perl script 'fileshareset' is set suid root.",
path));
else
KMessageBox::error(properties,
i18n("Unsharing folder '%1' failed.", path),
i18n("An error occurred while trying to unshare folder '%1'. "
"Make sure that the Perl script 'fileshareset' is set suid root.",
path));
properties->abortApplying();
break;
}
}
// Get the change back into our cached info
KFileShare::readShareList();
}
}
bool KFileSharePropsPlugin::setShared( const QString& path, bool shared )
{
kDebug() << "KFileSharePropsPlugin::setShared " << path << "," << shared;
return KFileShare::setShared( path, shared );
}
QWidget* KFileSharePropsPlugin::page() const
{
return d->m_vBox;
}
#include "moc_kfilesharedialog.cpp"
//TODO: do we need to monitor /etc/security/fileshare.conf ?
// if the user is added to the 'fileshare' group, we wouldn't be notified
// Of course the config module can notify us.
// TODO: listen to such notifications ;)

View file

@ -1,62 +0,0 @@
/* This file is part of the KDE project
Copyright (c) 2001 David Faure <faure@kde.org>
Copyright (c) 2001 Laurent Montel <lmontel@mandrakesoft.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KFILESHAREDIALOG_H
#define KFILESHAREDIALOG_H
#include <kpropertiesdialog.h>
#include <QProcess>
#include <QRadioButton>
#include <QPushButton>
/**
* This plugin provides a page to KProperiessDialog, showing the "file sharing" options
* @author David Faure <faure@kde.org>
*/
class KIO_EXPORT KFileSharePropsPlugin : public KPropertiesDialogPlugin
{
Q_OBJECT
public:
KFileSharePropsPlugin( KPropertiesDialog *_props );
virtual ~KFileSharePropsPlugin();
/**
* Apply all changes to the file.
* This function is called when the user presses 'Ok'. The last plugin inserted
* is called first.
*/
virtual void applyChanges();
static bool supports( const KFileItemList& items );
QWidget* page() const;
protected Q_SLOTS:
void slotConfigureFileSharing();
void slotConfigureFileSharingDone(int exitCode, QProcess::ExitStatus exitStatus);
private:
void init();
bool setShared( const QString&path, bool shared );
class Private;
Private* const d;
};
#endif

View file

@ -122,8 +122,6 @@ extern "C" {
#include <kcapacitybar.h>
#include <kfileitemlistproperties.h>
#include "kfilesharedialog.h"
#include "ui_kpropertiesdesktopbase.h"
#include "ui_kpropertiesdesktopadvbase.h"
#ifdef HAVE_POSIX_ACL

View file

@ -1,285 +0,0 @@
/* This file is part of the KDE project
Copyright (c) 2001 David Faure <faure@kde.org>
Copyright (c) 2001 Laurent Montel <lmontel@mandrakesoft.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kfileshare.h"
#include "kfileshare_p.h"
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/qprocess.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <kdirwatch.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kuser.h>
static KFileShare::Authorization s_authorization = KFileShare::NotInitialized;
K_GLOBAL_STATIC(QStringList, s_shareList)
static KFileShare::ShareMode s_shareMode;
static bool s_sambaEnabled;
static bool s_nfsEnabled;
static bool s_restricted;
static QString s_fileShareGroup;
static bool s_sharingEnabled;
#define FILESHARECONF "/etc/security/fileshare.conf"
static QString findExe( const char* exeName )
{
// Normally fileshareset and filesharelist are installed in kde4/libexec;
// allow distributions to move it somewhere else in the PATH or in /usr/sbin.
QString exe = KStandardDirs::findRootExe( exeName );
if (exe.isEmpty())
kError() << exeName << "not found";
return exe;
}
KFileSharePrivate::KFileSharePrivate()
{
KDirWatch::self()->addFile(FILESHARECONF);
connect(KDirWatch::self(), SIGNAL(dirty(QString)),this,
SLOT(slotFileChange(QString)));
}
KFileSharePrivate::~KFileSharePrivate()
{
KDirWatch::self()->removeFile(FILESHARECONF);
}
KFileSharePrivate* KFileSharePrivate::self()
{
K_GLOBAL_STATIC(KFileSharePrivate, _self)
return _self;
}
void KFileSharePrivate::slotFileChange(const QString &file)
{
if(file==FILESHARECONF) {
KFileShare::readConfig();
KFileShare::readShareList();
}
}
KFileShare::ShareMode readEntry(const KConfigGroup &cg, const char* key,
const KFileShare::ShareMode& aDefault)
{
const QByteArray data=cg.readEntry(key, QByteArray());
if (!data.isEmpty()) {
if (data.toLower() == "simple")
return KFileShare::Simple;
else if (data.toLower() == "advanced")
return KFileShare::Advanced;
}
return aDefault;
}
void KFileShare::readConfig() // static
{
// Create KFileSharePrivate instance
KFileSharePrivate::self();
KConfig config(QLatin1String(FILESHARECONF));
KConfigGroup group( &config, QString() );
s_sharingEnabled = group.readEntry("FILESHARING", true);
s_restricted = group.readEntry("RESTRICT", true);
s_fileShareGroup = group.readEntry("FILESHAREGROUP", "fileshare");
if (!s_sharingEnabled)
s_authorization = UserNotAllowed;
else
if (!s_restricted )
s_authorization = Authorized;
else {
// check if current user is in fileshare group
KUserGroup shareGroup(s_fileShareGroup);
if (shareGroup.users().contains(KUser()) )
s_authorization = Authorized;
else
s_authorization = UserNotAllowed;
}
s_shareMode = readEntry(group, "SHARINGMODE", Simple);
s_sambaEnabled = group.readEntry("SAMBA", true);
s_nfsEnabled = group.readEntry("NFS", true);
}
KFileShare::ShareMode KFileShare::shareMode() {
if ( s_authorization == NotInitialized )
readConfig();
return s_shareMode;
}
bool KFileShare::sharingEnabled() {
if ( s_authorization == NotInitialized )
readConfig();
return s_sharingEnabled;
}
bool KFileShare::isRestricted() {
if ( s_authorization == NotInitialized )
readConfig();
return s_restricted;
}
QString KFileShare::fileShareGroup() {
if ( s_authorization == NotInitialized )
readConfig();
return s_fileShareGroup;
}
bool KFileShare::sambaEnabled() {
if ( s_authorization == NotInitialized )
readConfig();
return s_sambaEnabled;
}
bool KFileShare::nfsEnabled() {
if ( s_authorization == NotInitialized )
readConfig();
return s_nfsEnabled;
}
void KFileShare::readShareList()
{
KFileSharePrivate::self();
s_shareList->clear();
QString exe = ::findExe( "filesharelist" );
if (exe.isEmpty()) {
s_authorization = ErrorNotFound;
return;
}
QProcess proc;
proc.start( exe, QStringList() );
if ( !proc.waitForFinished() ) {
kError() << "Can't run" << exe;
s_authorization = ErrorNotFound;
return;
}
// Reading code shamelessly stolen from khostname.cpp ;)
while (!proc.atEnd()) {
QString line = proc.readLine().trimmed();
int length = line.length();
if ( length > 0 )
{
if ( line[length-1] != '/' )
line += '/';
s_shareList->append(line);
kDebug(7000) << "Shared dir:" << line;
}
}
}
bool KFileShare::isDirectoryShared( const QString& _path )
{
if ( ! s_shareList.exists() )
readShareList();
QString path( _path );
if ( path[path.length()-1] != '/' )
path += '/';
return s_shareList->contains( path );
}
KFileShare::Authorization KFileShare::authorization()
{
// The app should do this on startup, but if it doesn't, let's do here.
if ( s_authorization == NotInitialized )
readConfig();
return s_authorization;
}
bool KFileShare::setShared( const QString& path, bool shared )
{
if (! KFileShare::sharingEnabled() ||
KFileShare::shareMode() == Advanced)
return false;
kDebug(7000) << path << "," << shared;
QString exe = ::findExe( "fileshareset" );
if (exe.isEmpty())
return false;
QStringList args;
if ( shared )
args << "--add";
else
args << "--remove";
args << path ;
int ec = QProcess::execute( exe, args ); // should be ok, the perl script terminates fast
kDebug(7000) << "exitCode=" << ec;
bool ok = !ec;
switch (ec) {
case 1:
// User is not authorized
break;
case 3:
// Called script with --add, but path was already shared before.
// Result is nevertheless what the client wanted, so
// this is alright.
ok = true;
break;
case 4:
// Invalid mount point
break;
case 5:
// Called script with --remove, but path was not shared before.
// Result is nevertheless what the client wanted, so
// this is alright.
ok = true;
break;
case 6:
// There is no export method
break;
case 7:
// file sharing is disabled
break;
case 8:
// advanced sharing is enabled
break;
case 255:
// Abitrary error
break;
}
return ok;
}
//#include "kfileshare.moc"
#include "moc_kfileshare_p.cpp"

View file

@ -1,111 +0,0 @@
/* This file is part of the KDE project
Copyright (c) 2001 David Faure <faure@kde.org>
Copyright (c) 2001 Laurent Montel <lmontel@mandrakesoft.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KFILESHARE_H
#define KFILESHARE_H
#include <kio/kio_export.h>
#include <QString>
/**
* Common functionality for the file sharing
* (communication with the backend)
*/
namespace KFileShare
{
/**
* Reads the file share configuration file
*/
KIO_EXPORT void readConfig();
/**
* Reads the list of shared folders
*/
KIO_EXPORT void readShareList();
/**
* Call this to know if a directory is currently shared
*/
KIO_EXPORT bool isDirectoryShared( const QString& path );
enum Authorization { NotInitialized, ErrorNotFound, Authorized, UserNotAllowed };
/**
* Call this to know if the current user is authorized to share directories
*/
KIO_EXPORT Authorization authorization();
/**
* Uses a suid perl script to share the given path
* with NFS and Samba
* @param path the path to share
* @param shared whether the path should be shared or not
* @returns whether the perl script was successful
*/
KIO_EXPORT bool setShared( const QString& path, bool shared );
/**
* The used share mode.
* Simple means that the simple sharing dialog is used and
* users can share only folders from there HOME folder.
* Advanced means that the advanced sharing dialog is used and
* users can share any folder.
*/
enum ShareMode { Simple, Advanced };
/**
* Returns whether sharing is enabled
* If this is false, file sharing is disabled and
* nobody can share files.
*/
KIO_EXPORT bool sharingEnabled();
/**
* Returns whether file sharing is restricted.
* If it is not restricted every user can shar files.
* If it is restricted only users in the configured
* file share group can share files.
*/
KIO_EXPORT bool isRestricted();
/**
* Returns the group that is used for file sharing.
* That is, all users in that group are allowed to
* share files if file sharing is restricted.
*/
KIO_EXPORT QString fileShareGroup();
/**
* Returns the configured share mode
*/
KIO_EXPORT ShareMode shareMode();
/**
* Returns whether Samba is enabled
*/
KIO_EXPORT bool sambaEnabled();
/**
* Returns whether NFS is enabled
*/
KIO_EXPORT bool nfsEnabled();
}
#endif

View file

@ -1,42 +0,0 @@
/* This file is part of the KDE project
Copyright (c) 2001 David Faure <faure@kde.org>
Copyright (c) 2001 Laurent Montel <lmontel@mandrakesoft.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KFILESHAREPRIVATE_H
#define KFILESHAREPRIVATE_H
#include <QObject>
/**
* @internal
* Do not use, ever.
*/
class KFileSharePrivate : public QObject
{
Q_OBJECT
public:
KFileSharePrivate();
~KFileSharePrivate();
static KFileSharePrivate *self();
protected Q_SLOTS: // this is why this class needs to be in the .h
void slotFileChange(const QString &);
};
#endif

View file

@ -24,9 +24,7 @@
#include <kio/kio_export.h>
/**
* Similar functionality like KFileShare,
* but works only for NFS and do not need
* any suid script.
* Similar functionality like KSambaShare but works only for NFS.
* It parses the /etc/exports file to get its information.
* Singleton class, call instance() to get an instance.
*/

View file

@ -49,22 +49,3 @@ install(
rtspu.protocol
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)
install(
PROGRAMS fileshareset
DESTINATION ${KDE4_LIBEXEC_INSTALL_DIR}
)
install(CODE "
set(FILESHARESET_PATH \"\$ENV{DESTDIR}${KDE4_LIBEXEC_INSTALL_DIR}/fileshareset\")
EXECUTE_PROCESS(COMMAND sh -c \"chown 0 '\${FILESHARESET_PATH}' && chmod u+s '\${FILESHARESET_PATH}'\")
")
# write a cmake script file which creates the symlink
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/make_fileshare_symlink.cmake
"EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink ${KDE4_LIBEXEC_INSTALL_DIR}/fileshareset \"\$ENV{DESTDIR}${KDE4_LIBEXEC_INSTALL_DIR}/filesharelist\")\n"
)
# and add it as post-install script for fileshareset
set_target_properties(ktelnetservice PROPERTIES
POST_INSTALL_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/make_fileshare_symlink.cmake
)

View file

@ -1,425 +0,0 @@
#!/usr/bin/perl -T
use strict;
########################################
# config files
$nfs_exports::default_options = '*(ro,all_squash)';
$nfs_exports::conf_file = '/etc/exports';
$smb_exports::conf_file = '/etc/samba/smb.conf';
my $authorisation_file = '/etc/security/fileshare.conf';
my $authorisation_group = 'fileshare';
########################################
# Copyright (C) 2001-2002 MandrakeSoft (pixel@mandriva.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
########################################
my $uid = $<;
my $username = getpwuid($uid);
########################################
# errors
my $usage =
"usage: fileshareset --add <dir>
fileshareset --remove <dir>";
my $not_enabled =
qq(File sharing is not enabled.
To enable file sharing put
"FILESHARING=yes" in $authorisation_file);
my $not_simple_enabled =
qq(Simple file sharing is not enabled.
To enable simple file sharing put
"SHARINGMODE=simple" in $authorisation_file);
my $non_authorised =
qq(You are not authorised to use file sharing
To grant you the rights:
- put "RESTRICT=no" in $authorisation_file
- or put user "$username" in group "$authorisation_group");
my $no_export_method = "can't export anything: no nfs, no smb";
my %exit_codes = reverse (
1 => $non_authorised,
2 => $usage,
# when adding
3 => "already exported",
4 => "invalid mount point",
# when removing
5 => "not exported",
6 => $no_export_method,
7 => $not_enabled,
8 => $not_simple_enabled,
255 => "various",
);
################################################################################
# correct PATH needed to call /etc/init.d/... ? seems not, but...
%ENV = ();#(PATH => '/bin:/sbin:/usr/bin:/usr/sbin');
my $modify = $0 =~ /fileshareset/;
authorisation::check($modify);
my @exports = (
-e $nfs_exports::conf_file ? nfs_exports::read() : (),
-e $smb_exports::conf_file ? smb_exports::read() : (),
);
@exports or error($no_export_method);
if ($modify) {
my ($cmd, $dir) = @ARGV;
$< = $>;
@ARGV == 2 && ($cmd eq '--add' || $cmd eq '--remove') or error($usage);
verify_mntpoint($dir);
if ($cmd eq '--add') {
my @errs = map { eval { $_->add($dir) }; $@ } @exports;
grep { !$_ } @errs or error("already exported");
} else {
my @errs = map { eval { $_->remove($dir) }; $@ } @exports;
grep { !$_ } @errs or error("not exported");
}
foreach my $export (@exports) {
$export->write;
$export->update_server;
}
}
my @mntpoints = grep {$_} uniq(map { map { $_->{mntpoint} } @$_ } @exports);
print "$_\n" foreach grep { own($_) } @mntpoints;
sub own { $uid == 0 || (stat($_[0]))[4] == $uid }
sub verify_mntpoint {
local ($_) = @_;
my $ok = 1;
$ok &&= m|^/|;
$ok &&= !m|/\.\./|;
$ok &&= !m|[\0\n\r]|;
$ok &&= -d $_;
$ok &&= own($_);
$ok or error("invalid mount point");
}
sub error {
my ($string) = @_;
print STDERR "$string\n";
exit($exit_codes{$string} || 255);
}
sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 }
sub uniq { my %l; $l{$_} = 1 foreach @_; grep { delete $l{$_} } @_ }
################################################################################
package authorisation;
sub read_conf {
my ($exclusive_lock) = @_;
open F_lock, $authorisation_file; # don't care if it's missing
flock(F_lock, $exclusive_lock ? 2 : 1) or die "can't lock $authorisation_file";
my %conf;
foreach (<F_lock>) {
s/#.*//; # remove comments
s/^\s+//;
s/\s+$//;
/^$/ and next;
my ($cmd, $value) = split('=', $_, 2);
$conf{$cmd} = $value || warn qq(suspicious line "$_" in $authorisation_file\n);
}
# no close F_lock, keep it locked
\%conf
}
sub check {
my ($exclusive_lock) = @_;
my $conf = read_conf($exclusive_lock);
if (lc($conf->{FILESHARING}) eq 'no') {
::error($not_enabled);
}
if (lc($conf->{SHARINGMODE}) eq 'advanced') {
::error($not_simple_enabled);
}
if (lc($conf->{FILESHAREGROUP} ne '')) {
$authorisation_group = lc($conf->{FILESHAREGROUP});
}
if (lc($conf->{RESTRICT}) eq 'no') {
# ok, access granted for everybody
} else {
my @l;
while (@l = getgrent) {
last if $l[0] eq $authorisation_group;
}
::member($username, split(' ', $l[3])) or ::error($non_authorised);
}
}
################################################################################
package exports;
sub find {
my ($exports, $mntpoint) = @_;
foreach (@$exports) {
$_->{mntpoint} eq $mntpoint and return $_;
}
undef;
}
sub add {
my ($exports, $mntpoint) = @_;
foreach (@$exports) {
$_->{mntpoint} eq $mntpoint and die 'add';
}
push @$exports, my $e = { mntpoint => $mntpoint };
$e;
}
sub remove {
my ($exports, $mntpoint) = @_;
my @l = grep { $_->{mntpoint} ne $mntpoint } @$exports;
@l < @$exports or die 'remove';
@$exports = @l;
}
################################################################################
package nfs_exports;
use vars qw(@ISA $conf_file $default_options);
BEGIN { @ISA = 'exports' }
sub read {
my $file = $conf_file;
local *F;
open F, $file or return [];
my ($prev_raw, $prev_line, %e, @l);
my $line_nb = 0;
foreach my $raw (<F>) {
$line_nb++;
local $_ = $raw;
$raw .= "\n" if !/\n/;
s/#.*//; # remove comments
s/^\s+//;
s/\s+$//; # remove unuseful spaces to help regexps
if (/^$/) {
# blank lines ignored
$prev_raw .= $raw;
next;
}
if (/\\$/) {
# line continue across lines
chop; # remove the backslash
$prev_line .= "$_ ";
$prev_raw .= $raw;
next;
}
my $line = $prev_line . $_;
my $raw_line = $prev_raw . $raw;
($prev_line, $prev_raw) = ('', '');
my ($mntpoint, $options) = $line =~ /("[^"]*"|\S+)\s+(.*)/ or die "$file:$line_nb: bad line $line\n";
# You can also specify spaces or any other unusual characters in the
# export path name using a backslash followed by the character code as
# 3 octal digits.
$mntpoint =~ s/\\(\d{3})/chr(oct $1)/ge;
# not accepting weird characters that would break the output
$mntpoint =~ m/[\0\n\r]/ and die "i won't handle this";
push @l, { mntpoint => $mntpoint, option => $options, raw => $raw_line };
}
bless \@l, 'nfs_exports';
}
sub write {
my ($nfs_exports) = @_;
foreach (@$nfs_exports) {
if (!exists $_->{options}) {
$_->{options} = $default_options;
}
if (!exists $_->{raw}) {
my $mntpoint = $_->{mntpoint} =~ /\s/ ? qq("$_->{mntpoint}") : $_->{mntpoint};
$_->{raw} = sprintf("%s %s\n", $mntpoint, $_->{options});
}
}
local *F;
open F, ">$conf_file" or die "can't write $conf_file";
print F $_->{raw} foreach @$nfs_exports;
}
sub update_server {
if (fork) {
system('/usr/sbin/exportfs', '-r');
if (system('PATH=/bin:/sbin pidof rpc.mountd >/dev/null') != 0 ||
system('PATH=/bin:/sbin pidof nfsd >/dev/null') != 0) {
# trying to start the server...
system('/etc/init.d/portmap start') if system('/etc/init.d/portmap status') != 0;
system('/etc/init.d/nfs', $_) foreach 'stop', 'start';
}
exit 0;
}
}
################################################################################
package smb_exports;
use vars qw(@ISA $conf_file);
BEGIN { @ISA = 'exports' }
sub read {
my ($s, @l);
local *F;
open F, $conf_file;
local $_;
while (<F>) {
if (/^\s*\[.*\]/ || eof F) {
#- first line in the category
my ($label) = $s =~ /^\s*\[(.*)\]/;
my ($mntpoint) = $s =~ /^\s*path\s*=\s*(.*)/m;
push @l, { mntpoint => $mntpoint, raw => $s, label => $label };
$s = '';
}
$s .= $_;
}
bless \@l, 'smb_exports';
}
sub write {
my ($smb_exports) = @_;
foreach (@$smb_exports) {
if (!exists $_->{raw}) {
$_->{raw} = <<EOF;
[$_->{label}]
path = $_->{mntpoint}
comment = $_->{mntpoint}
public = yes
guest ok = yes
writable = no
wide links = no
EOF
}
}
local *F;
open F, ">$conf_file" or die "can't write $conf_file";
print F $_->{raw} foreach @$smb_exports;
}
sub add {
my ($exports, $mntpoint) = @_;
my $e = $exports->exports::add($mntpoint);
$e->{label} = name_mangle($mntpoint, map { $_->{label} } @$exports);
}
sub name_mangle {
my ($input, @others) = @_;
local $_ = $input;
# 1. first only keep legal characters. "/" is also kept for the moment
tr|a-z|A-Z|;
s|[^A-Z0-9#\-_!/]|_|g; # "$" is allowed except at the end, remove it in any case
# 2. removing non-interesting parts
s|^/||;
s|^home/||;
s|_*/_*|/|g;
s|_+|_|g;
# 3. if size is too small (!), make it bigger
$_ .= "_" while length($_) < 3;
# 4. if size is too big, shorten it
while (length > 12) {
my ($s) = m|.*?/(.*)|;
if (length($s) > 8 && !grep { /\Q$s/ } @others) {
# dropping leading directories when the resulting is still long and meaningful
$_ = $s;
next;
}
s|(.*)[0-9#\-_!/]|$1| and next;
# inspired by "Christian Brolin" "Long names are doom" on comp.lang.functional
s|(.+)[AEIOU]|$1| and next; # allButFirstVowels
s|(.*)(.)\2|$1$2| and next; # adjacentDuplicates
s|(.*).|$1|; # booh, :'-(
}
# 5. remove "/"s still there
s|/|_|g;
# 6. resolving conflicts
my $l = join("|", map { quotemeta } @others);
my $conflicts = qr|^($l)$|;
if (/$conflicts/) {
A: while (1) {
for (my $nb = 1; length("$_$nb") <= 12; $nb++) {
if ("$_$nb" !~ /$conflicts/) {
$_ = "$_$nb";
last A;
}
}
$_ or die "can't find a unique name";
# can't find a unique name, dropping the last letter
s|(.*).|$1|;
}
}
# 7. done
$_;
}
sub update_server {
if (fork) {
system('/usr/bin/killall -HUP smbd 2>/dev/null');
if (system('PATH=/bin:/sbin pidof smbd >/dev/null') != 0 ||
system('PATH=/bin:/sbin pidof nmbd >/dev/null') != 0) {
# trying to start the server...
if ( -f '/etc/init.d/smb' ) {
system('/etc/init.d/smb', $_) foreach 'stop', 'start';
}
elsif ( -f '/etc/init.d/samba' ) {
system('/etc/init.d/samba', $_) foreach 'stop', 'start';
}
elsif ( -f '/etc/rc.d/rc.samba' ) {
system('/etc/rc.d/rc.samba', $_) foreach 'stop', 'start';
}
else {
print STDERR "Error: Can't find the samba init script \n";
}
}
exit 0;
}
}