2003-07-30 08:59:21 -04:00
|
|
|
$OpenBSD: patch-kdesu_su_cpp,v 1.4 2003/07/30 12:59:23 espie Exp $
|
|
|
|
--- kdesu/su.cpp.orig Sun Jul 13 21:27:55 2003
|
|
|
|
+++ kdesu/su.cpp Tue Jul 15 19:25:14 2003
|
2002-05-15 13:19:44 -04:00
|
|
|
@@ -41,17 +41,33 @@
|
|
|
|
#ifndef __PATH_SU
|
|
|
|
#define __PATH_SU "false"
|
|
|
|
#endif
|
|
|
|
+#ifndef __PATH_SUDO
|
|
|
|
+#define __PATH_SUDO "false"
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
+class SuProcess::SuProcessPrivate
|
|
|
|
+{
|
|
|
|
+public:
|
|
|
|
+ bool m_useSudo;
|
|
|
|
+};
|
|
|
|
|
|
|
|
SuProcess::SuProcess(const QCString &user, const QCString &command)
|
|
|
|
{
|
|
|
|
m_User = user;
|
|
|
|
m_Command = command;
|
|
|
|
+ d = new SuProcess::SuProcessPrivate();
|
|
|
|
+ d->m_useSudo = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SuProcess::~SuProcess()
|
|
|
|
{
|
|
|
|
+ delete d;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void SuProcess::setUseSudo(bool use_sudo)
|
|
|
|
+{
|
|
|
|
+ d->m_useSudo = use_sudo;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SuProcess::checkInstall(const char *password)
|
|
|
|
@@ -65,7 +81,7 @@ int SuProcess::checkNeedPassword()
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
- * Execute a command with su(1).
|
|
|
|
+ * Execute a command with su(1) or sudo
|
|
|
|
*/
|
|
|
|
|
|
|
|
int SuProcess::exec(const char *password, int check)
|
2003-07-30 08:59:21 -04:00
|
|
|
@@ -74,11 +90,19 @@ int SuProcess::exec(const char *password
|
2002-05-15 13:19:44 -04:00
|
|
|
setTerminal(true);
|
|
|
|
|
|
|
|
QCStringList args;
|
|
|
|
+ if (d->m_useSudo)
|
|
|
|
+ {
|
|
|
|
+ args += "-S";
|
2003-01-06 17:46:02 -05:00
|
|
|
+ args += "-p";
|
|
|
|
+ args += "Password:";
|
2002-05-15 13:19:44 -04:00
|
|
|
+ args += "-u";
|
|
|
|
+ }
|
|
|
|
if ((m_Scheduler != SchedNormal) || (m_Priority > 50))
|
|
|
|
args += "root";
|
|
|
|
else
|
|
|
|
args += m_User;
|
|
|
|
- args += "-c";
|
|
|
|
+ if (!d->m_useSudo)
|
|
|
|
+ args += "-c";
|
|
|
|
args += QCString(__KDE_BINDIR) + "/kdesu_stub";
|
|
|
|
|
2003-07-30 08:59:21 -04:00
|
|
|
QCString command = __PATH_SU;
|
|
|
|
@@ -89,7 +113,7 @@ int SuProcess::exec(const char *password
|
|
|
|
return check ? SuNotFound : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (StubProcess::exec(command, args) < 0)
|
2002-05-15 13:19:44 -04:00
|
|
|
+ if (StubProcess::exec(d->m_useSudo ? __PATH_SUDO : __PATH_SU, args) < 0)
|
|
|
|
{
|
|
|
|
return check ? SuNotFound : -1;
|
|
|
|
}
|
2003-07-30 08:59:21 -04:00
|
|
|
@@ -98,7 +122,8 @@ int SuProcess::exec(const char *password
|
2002-05-15 13:19:44 -04:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
if (!check)
|
|
|
|
- kdError(900) << k_lineinfo << "Conversation with su failed\n";
|
|
|
|
+ kdError(900) << k_lineinfo << "Conversation with " <<
|
|
|
|
+ (d->m_useSudo ? "sudo" : "su") << " failed\n";
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (check == 2)
|
2003-07-30 08:59:21 -04:00
|
|
|
@@ -181,6 +206,9 @@ int SuProcess::ConverseSU(const char *pa
|
2003-01-06 17:46:02 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if (d->m_useSudo && line != "Password:")
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
// Match "Password: " with the regex ^[^:]+:[\w]*$.
|
|
|
|
for (i=0,j=0,colon=0; i<line.length(); i++)
|
|
|
|
{
|
2003-07-30 08:59:21 -04:00
|
|
|
@@ -221,6 +249,9 @@ int SuProcess::ConverseSU(const char *pa
|
2003-01-06 17:46:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
+ if (d->m_useSudo && line == "Password:")
|
|
|
|
+ return -1;
|
|
|
|
+
|
|
|
|
// Read till we get "kdesu_stub"
|
|
|
|
if (line == "kdesu_stub")
|
|
|
|
{
|