openbsd-ports/x11/kde/libs3/patches/patch-kdesu_su_cpp
espie c3e047e90b KDE 3.5.0, the beginning...
(samba/cups subpackages to fix library issues)
2005-11-29 14:00:11 +00:00

110 lines
2.8 KiB
Plaintext

$OpenBSD: patch-kdesu_su_cpp,v 1.7 2005/11/29 14:00:12 espie Exp $
--- kdesu/su.cpp.orig Sat Sep 10 10:27:02 2005
+++ kdesu/su.cpp Mon Nov 21 12:27:29 2005
@@ -41,19 +41,35 @@
#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)
{
return exec(password, Install);
@@ -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)
@@ -75,12 +91,20 @@ int SuProcess::exec(const char *password
QCStringList args;
+ if (d->m_useSudo)
+ {
+ args += "-S";
+ args += "-p";
+ args += "Password:";
+ 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";
args += "-";
@@ -93,7 +117,7 @@ int SuProcess::exec(const char *password
}
// kdDebug(900) << k_lineinfo << "Call StubProcess::exec()" << endl;
- if (StubProcess::exec(command, args) < 0)
+ if (StubProcess::exec(d->m_useSudo ? __PATH_SUDO : __PATH_SU, args) < 0)
{
return check ? SuNotFound : -1;
}
@@ -105,7 +129,8 @@ int SuProcess::exec(const char *password
if (ret == error)
{
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 == NeedPassword)
@@ -211,6 +236,9 @@ int SuProcess::ConverseSU(const char *pa
kdDebug(900) << k_lineinfo << "Read line <" << more << ">" << endl;
}
+ if (d->m_useSudo && line != "Password:")
+ break;
+
// Match "Password: " with the regex ^[^:]+:[\w]*$.
const uint len = line.length();
for (i=0,j=0,colon=0; i<len; i++)
@@ -265,6 +293,9 @@ int SuProcess::ConverseSU(const char *pa
}
//////////////////////////////////////////////////////////////////////////
case HandleStub:
+ if (d->m_useSudo && line == "Password:")
+ return -1;
+
// Read till we get "kdesu_stub"
if (line == "kdesu_stub")
{