/* vi: ts=8 sts=4 sw=4 * * This file is part of the KDE project, module kdesu. * SPDX-FileCopyrightText: 2000 Geert Jansen * SPDX-License-Identifier: Artistic-2.0 */ #include "sudlg.h" #include #include #include KDEsuDialog::KDEsuDialog(QByteArray user, QByteArray authUser, bool enableKeep, const QString &icon, bool withIgnoreButton) : KPasswordDialog(nullptr, enableKeep ? ShowKeepPassword : NoFlags) { if (!icon.isEmpty()) { setIcon(QIcon::fromTheme(icon)); } if (withIgnoreButton) { buttonBox()->addButton(QDialogButtonBox::Ignore); } proc.setUser(authUser); setWindowTitle(i18n("Run as %1", QString::fromLatin1(user))); QString prompt; if (proc.useUsersOwnPassword()) { prompt = i18n("Please enter your password below."); } else { if (authUser == "root") { if (withIgnoreButton) { prompt = QStringLiteral("") + i18n("The action you requested needs root privileges. " "Please enter root's password below or click " "Ignore to continue with your current privileges.") + QStringLiteral(""); } else { prompt = QStringLiteral("") + i18n("The action you requested needs root privileges. " "Please enter root's password below.") + QStringLiteral(""); } } else { if (withIgnoreButton) { prompt = QStringLiteral("") + i18n("The action you requested needs additional privileges. " "Please enter the password for %1 below or click " "Ignore to continue with your current privileges.", QString::fromLatin1(authUser)) + QStringLiteral(""); } else { prompt = QStringLiteral("") + i18n("The action you requested needs additional privileges. " "Please enter the password for %1 below.", QString::fromLatin1(authUser)) + QStringLiteral(""); } } } setPrompt(prompt); if (withIgnoreButton) { connect(buttonBox()->button(QDialogButtonBox::Ignore), &QAbstractButton::clicked, this, &KDEsuDialog::slotUser1); } } KDEsuDialog::~KDEsuDialog() { } bool KDEsuDialog::checkPassword() { int status = proc.checkInstall(password().toLocal8Bit().constData()); switch (status) { case -1: showErrorMessage(i18n("Conversation with su failed."), UsernameError); return false; case 0: return true; case SuProcess::SuNotFound: showErrorMessage(i18n("The program 'su' could not be found.
" "Ensure your PATH is set correctly."), FatalError); return false; case SuProcess::SuNotAllowed: // This is actually never returned, as kdesu cannot tell the difference. showErrorMessage(QLatin1String("The impossible happened."), FatalError); return false; case SuProcess::SuIncorrectPassword: showErrorMessage(i18n("Permission denied.
" "Possibly incorrect password, please try again.
" "On some systems, you need to be in a special " "group (often: wheel) to use this program."), PasswordError); return false; default: showErrorMessage(i18n("Internal error: illegal return from " "SuProcess::checkInstall()"), FatalError); done(Rejected); return false; } } void KDEsuDialog::slotUser1() { done(AsUser); } #include "moc_sudlg.cpp"