KDEsu
Go to the documentation of this file.
20 #include <config-prefix.h>
31 #include <sys/types.h>
34 #include <QtCore/QFile>
50 #define __PATH_SU "false"
54 #define __PATH_SUDO "false"
57 #ifdef KDESU_USE_SUDO_DEFAULT
58 # define DEFAULT_SUPER_USER_COMMAND "sudo"
60 # define DEFAULT_SUPER_USER_COMMAND "su"
64 using namespace KDESuPrivate;
66 class SuProcess::SuProcessPrivate
69 QString m_superUserCommand;
73 : d( new SuProcessPrivate )
82 if ( d->m_superUserCommand !=
"sudo" && d->m_superUserCommand !=
"su" ) {
83 kWarning() <<
"unknown super user command.";
96 return d->m_superUserCommand;
131 d->m_superUserCommand =
"su";
135 if (d->m_superUserCommand ==
"sudo") {
144 if (d->m_superUserCommand ==
"su") {
147 args += QByteArray(LIBEXEC_INSTALL_DIR) +
"/kdesu_stub";
151 if (d->m_superUserCommand ==
"sudo") {
157 if (::
access(command, X_OK) != 0)
159 command = QFile::encodeName(
KGlobal::dirs()->findExe(d->m_superUserCommand.toLatin1()) );
160 if (command.isEmpty())
171 SuErrors ret = (SuErrors) ConverseSU(password);
184 if ( d->m_superUserCommand ==
"sudo" ) {
188 if (kill(
m_Pid, SIGKILL) < 0) {
198 if (iret < 0) ret=error;
206 memset(
const_cast<char *
>(password), 0, qstrlen(password));
210 kill(
m_Pid, SIGKILL);
211 if (d->m_superUserCommand !=
"sudo") {
226 kill(
m_Pid, SIGKILL);
246 int SuProcess::ConverseSU(
const char *password)
248 enum { WaitForPrompt, CheckStar, HandleStub } state = WaitForPrompt;
258 return ( state == HandleStub ? notauthorized : error);
261 if (line ==
"kdesu_stub")
272 if (waitMS(
fd(),100)>0)
282 const uint len = line.length();
283 for (i=0,j=0,colon=0; i<len; ++i)
293 if ((colon == 1) && (line[j] ==
':'))
299 write(
fd(), password, strlen(password));
300 write(
fd(),
"\n", 1);
308 QByteArray s = line.trimmed();
314 const uint len = line.length();
315 for (i=0; i< len; ++i)
#define DEFAULT_SUPER_USER_COMMAND
int WaitSlave()
Waits until the pty has cleared the ECHO flag.
virtual void virtual_hook(int id, void *data)
Standard hack to add virtual methods in a BC way.
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
int checkNeedPassword()
Checks if a password is needed.
QByteArray readLine(bool block=true)
Reads a line from the program's standard out.
int exec(const QByteArray &command, const QList< QByteArray > &args)
Forks off and execute a command.
int waitForChild()
Waits for the child to exit.
int m_Pid
PID of child process.
KSharedConfigPtr config()
QString loginName() const
int exec(const char *password, int check=NoCheck)
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static int registerArea(const QByteArray &areaName, bool enabled=true)
int ConverseStub(int check)
Exchange all parameters with kdesu_stub.
int checkInstall(const char *password)
Checks if the stub is installed and the password is correct.
SuProcess(const QByteArray &user=0, const QByteArray &command=0)
void setTerminal(bool terminal)
Enables/disables terminal output.
bool useUsersOwnPassword()
Checks whether or not the user's password is being asked for or another user's password.
int fd() const
Returns the filedescriptor of the process.
virtual void virtual_hook(int id, void *data)
Standard hack to add virtual methods in a BC way.
QString superUserCommand()
Checks what the default super user command is, e.g.
void unreadLine(const QByteArray &line, bool addNewline=true)
Puts back a line of input.
int access(const QString &path, int mode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jan 30 2020 00:00:00 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.