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
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)