From bcb704366cb5e333a626c18c308c7e0448a8e69f Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- .../kcm_sambaconf/linuxpermissionchecker.cpp | 202 +++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 filesharing/advanced/kcm_sambaconf/linuxpermissionchecker.cpp (limited to 'filesharing/advanced/kcm_sambaconf/linuxpermissionchecker.cpp') diff --git a/filesharing/advanced/kcm_sambaconf/linuxpermissionchecker.cpp b/filesharing/advanced/kcm_sambaconf/linuxpermissionchecker.cpp new file mode 100644 index 00000000..17b782ab --- /dev/null +++ b/filesharing/advanced/kcm_sambaconf/linuxpermissionchecker.cpp @@ -0,0 +1,202 @@ +/*************************************************************************** + begin : Tue May 17 2003 + copyright : (C) 2003 by Jan Sch�er + email : janschaefer@users.sourceforge.net + ***************************************************************************/ + +/****************************************************************************** + * * + * This file is part of KSambaPlugin. * + * * + * KSambaPlugin 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 of the License, or * + * (at your option) any later version. * + * * + * KSambaPlugin 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 KSambaPlugin; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * * + ******************************************************************************/ +#include +#include + +#include +#include +#include + +#include "passwd.h" +#include "sambashare.h" +#include "linuxpermissionchecker.h" + +LinuxPermissionChecker::LinuxPermissionChecker(SambaShare* share,QWidget* parent = 0L) +{ + m_sambaShare = share; + m_parent = parent; + + if (!share) { + kdWarning() << "WARNING: LinuxPermissionChecker: share is null !" << endl; + return; + } + + m_fi = QFileInfo(share->getValue("path")); + + if ( ! m_fi.exists()) { + kdDebug(5009) << "LinuxPermissionChecker: path does not exists !" << endl; + } + +} + + +LinuxPermissionChecker::~LinuxPermissionChecker() +{ +} + +bool LinuxPermissionChecker::checkAllPermissions() { + if (! m_sambaShare ) + return true; + + if ( ! m_fi.exists()) + return true; + + if (! checkPublicPermissions()) + return false; + + if (! checkAllUserPermissions()) + return false; + + return true; +} + +bool LinuxPermissionChecker::checkAllUserPermissions() { + if (! m_sambaShare ) + return true; + + if ( ! m_fi.exists()) + return true; + + QStringList readList = QStringList::split(QRegExp("[,\\s]+"),m_sambaShare->getValue("read list")); + + for ( QStringList::Iterator it = readList.begin(); it != readList.end(); ++it ) + { + if (!checkUserReadPermissions(*it)) + return false; + } + + QStringList writeList = QStringList::split(QRegExp("[,\\s]+"),m_sambaShare->getValue("write list")); + + for ( QStringList::Iterator it = writeList.begin(); it != writeList.end(); ++it ) + { + if (!checkUserWritePermissions(*it)) + return false; + } + + return true; +} + +bool LinuxPermissionChecker::checkPublicPermissions() { + if (! m_sambaShare ) + return true; + + bool isPublic = m_sambaShare->getBoolValue("public"); + if (!isPublic) + return true; + + QString guestAccount = m_sambaShare->getValue("guest account"); + + if ( ! checkUserReadPermissions(guestAccount,false)) + { + if (KMessageBox::Cancel == KMessageBox::warningContinueCancel( + 0L,i18n( + "You have specified public read access for this directory, but " + "the guest account %1 does not have the necessary read permissions;
" + "do you want to continue anyway?
").arg(guestAccount) + ,i18n("Warning") + ,KStdGuiItem::cont() + ,"KSambaPlugin_guestAccountHasNoReadPermissionsWarning")) + return false; + } + + + if ( ! checkUserWritePermissions(guestAccount,false)) + { + if (KMessageBox::Cancel == KMessageBox::warningContinueCancel( + 0L,i18n( + "You have specified public write access for this directory, but " + "the guest account %1 does not have the necessary write permissions;
" + "do you want to continue anyway?
").arg(guestAccount) + ,i18n("Warning") + ,KStdGuiItem::cont() + ,"KSambaPlugin_guestAccountHasNoWritePermissionsWarning")) + return false; + } + + return true; +} + +bool LinuxPermissionChecker::checkUserPermissions(const QString & user) { + if ( ! checkUserReadPermissions(user)) + return false; + + if ( ! checkUserWritePermissions(user)) + return false; + + return true; +} + +bool LinuxPermissionChecker::checkUserWritePermissions(const QString & user, bool showMessageBox) { + // If no write permissions are given, we don't need to check them. + if (m_sambaShare->getBoolValue("read only")) + return true; + + if (! ((m_fi.permission(QFileInfo::WriteOther)) || + (m_fi.permission(QFileInfo::WriteUser) && user == m_fi.owner()) || + (m_fi.permission(QFileInfo::WriteGroup) && isUserInGroup(user, m_fi.group()))) + ) + { + if (!showMessageBox) + return false; + + if (KMessageBox::Cancel == KMessageBox::warningContinueCancel( + 0L,i18n( + "You have specified write access to the user %1 for this directory, but " + "the user does not have the necessary write permissions;
" + "do you want to continue anyway?
").arg(user) + ,i18n("Warning") + ,KStdGuiItem::cont() + ,"KSambaPlugin_userHasNoWritePermissionsWarning")) + return false; + } + + return true; +} + +bool LinuxPermissionChecker::checkUserReadPermissions(const QString & user, bool showMessageBox) { + if (! ((m_fi.permission(QFileInfo::ReadOther)) || + (m_fi.permission(QFileInfo::ReadUser) && user == m_fi.owner()) || + (m_fi.permission(QFileInfo::ReadGroup) && isUserInGroup(user, m_fi.group()))) + ) + { + if (!showMessageBox) + return false; + + if (KMessageBox::Cancel == KMessageBox::warningContinueCancel( + 0L,i18n( + "You have specified read access to the user %1 for this directory, but " + "the user does not have the necessary read permissions;
" + "do you want to continue anyway?
").arg(user) + ,i18n("Warning") + ,KStdGuiItem::cont() + ,"KSambaPlugin_userHasNoReadPermissionsWarning")) + return false; + + } + + return true; +} + -- cgit v1.2.1