diff options
author | Andrew Christian <andrew.christian@nokia.com> | 2012-02-08 10:59:44 -0500 |
---|---|---|
committer | Chris Craig <ext-chris.craig@nokia.com> | 2012-02-10 04:00:21 +0100 |
commit | d33cd2c25f6062d51eba713126bbe881021f693b (patch) | |
tree | 2765539ec0a1c7e10fae4521213755c9ea4a906c | |
parent | 1b55e397a94ad39adaaf21276a74605ea999ab1a (diff) |
Updating UID and GID control.
* Removed uid() and gid() functions from process frontend/backend
because these values must be calculated from the /proc filesystem.
* Fixed bug in processinfo that incorrectly set group id.
* Updated test suite so that you can specify UID/GID to run
child processes as. Use TEST_UID=NUM and TEST_GID=num as
environment variables and then execute the test suite with
CAP_SETUID (normally accomplished by running as root)
Change-Id: Ib1c10521bddec19afe7eae1422ffa1f24985756c
Reviewed-by: Chris Craig <ext-chris.craig@nokia.com>
-rw-r--r-- | src/core/processbackend.cpp | 19 | ||||
-rw-r--r-- | src/core/processbackend.h | 2 | ||||
-rw-r--r-- | src/core/processfrontend.cpp | 30 | ||||
-rw-r--r-- | src/core/processfrontend.h | 4 | ||||
-rw-r--r-- | src/core/processinfo.cpp | 2 | ||||
-rw-r--r-- | src/core/unixprocessbackend.cpp | 2 | ||||
-rw-r--r-- | tests/auto/processmanager/tst_processmanager.cpp | 46 |
7 files changed, 44 insertions, 61 deletions
diff --git a/src/core/processbackend.cpp b/src/core/processbackend.cpp index ab220a5..301b5c5 100644 --- a/src/core/processbackend.cpp +++ b/src/core/processbackend.cpp @@ -166,25 +166,6 @@ QString ProcessBackend::errorString() const return QString(); } - -/*! - Return the process UID -*/ - -qint64 ProcessBackend::uid() const -{ - return 0; -} - -/*! - Return the process GID -*/ - -qint64 ProcessBackend::gid() const -{ - return 0; -} - /*! Returns the PID of this process. If the process has not started up yet properly, its PID will be 0. */ diff --git a/src/core/processbackend.h b/src/core/processbackend.h index 77f05a3..eb87fa7 100644 --- a/src/core/processbackend.h +++ b/src/core/processbackend.h @@ -65,8 +65,6 @@ public: virtual QString errorString() const; - virtual qint64 uid() const; - virtual qint64 gid() const; virtual Q_PID pid() const; virtual qint32 actualPriority() const; diff --git a/src/core/processfrontend.cpp b/src/core/processfrontend.cpp index 896d17a..5876f39 100644 --- a/src/core/processfrontend.cpp +++ b/src/core/processfrontend.cpp @@ -91,16 +91,6 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER */ /*! - \property ProcessFrontend::uid - \brief the user id (uid) of the process. -*/ - -/*! - \property ProcessFrontend::gid - \brief the group id (gid) of the process. -*/ - -/*! \property ProcessFrontend::pid \brief the process id (PID) of the process. @@ -233,26 +223,6 @@ QString ProcessFrontend::workingDirectory() const } /*! - Return the process UID -*/ - -qint64 ProcessFrontend::uid() const -{ - Q_ASSERT(m_backend); - return m_backend->uid(); -} - -/*! - Return the process GID -*/ - -qint64 ProcessFrontend::gid() const -{ - Q_ASSERT(m_backend); - return m_backend->gid(); -} - -/*! Returns the PID of this process. If the process has not started up yet properly, its PID will be 0. */ Q_PID ProcessFrontend::pid() const diff --git a/src/core/processfrontend.h b/src/core/processfrontend.h index 644d414..542bbd9 100644 --- a/src/core/processfrontend.h +++ b/src/core/processfrontend.h @@ -60,8 +60,6 @@ class Q_ADDON_PROCESSMANAGER_EXPORT ProcessFrontend : public QObject Q_PROPERTY(QStringList arguments READ arguments CONSTANT) Q_PROPERTY(QVariantMap environment READ environment CONSTANT) Q_PROPERTY(QString workingDirectory READ workingDirectory CONSTANT) - Q_PROPERTY(qint64 uid READ uid NOTIFY started) - Q_PROPERTY(qint64 gid READ gid NOTIFY started) Q_PROPERTY(qint64 pid READ pid NOTIFY started) Q_PROPERTY(qint64 startTime READ startTime NOTIFY started) @@ -81,8 +79,6 @@ public: QVariantMap environment() const; QString workingDirectory() const; - qint64 uid() const; - qint64 gid() const; Q_PID pid() const; qint32 priority() const; diff --git a/src/core/processinfo.cpp b/src/core/processinfo.cpp index 1f16954..4b60ee9 100644 --- a/src/core/processinfo.cpp +++ b/src/core/processinfo.cpp @@ -294,7 +294,7 @@ void ProcessInfo::setUid(qint64 newUid) qint64 ProcessInfo::gid() const { - return m_info.value(ProcessInfoConstants::Priority).toLongLong(); + return m_info.value(ProcessInfoConstants::Gid).toLongLong(); } /*! diff --git a/src/core/unixprocessbackend.cpp b/src/core/unixprocessbackend.cpp index 48b4cc8..286b486 100644 --- a/src/core/unixprocessbackend.cpp +++ b/src/core/unixprocessbackend.cpp @@ -94,7 +94,7 @@ Q_PID UnixProcessBackend::pid() const { if (m_process) return m_process->pid(); - return 0; + return ProcessBackend::pid(); } /*! diff --git a/tests/auto/processmanager/tst_processmanager.cpp b/tests/auto/processmanager/tst_processmanager.cpp index cc35e89..c5119e2 100644 --- a/tests/auto/processmanager/tst_processmanager.cpp +++ b/tests/auto/processmanager/tst_processmanager.cpp @@ -119,12 +119,25 @@ bool canCheckProcessState() return finfo.exists(); } -bool isProcessRunning(Q_PID pid) +static QRegExp gProcessRegex("\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)"); + +bool isProcessRunning(Q_PID pid, qint64 *uid=0, qint64 *gid=0) { QProcess p; - p.start("ps", QStringList() << "-o" << "pid=" << "-p" << QString::number(pid)); - if (p.waitForStarted() && p.waitForFinished()) - return p.readAll().split('\n').at(0).toDouble() == pid; + p.start("/bin/ps", QStringList() << "-o" << "pid=" << "-o" << "uid=" + << "-o" << "gid=" << "-p" << QString::number(pid)); + if (p.waitForStarted() && p.waitForFinished()) { + QList<QByteArray> plist = p.readAll().split('\n'); + if (plist.size() == 2 && gProcessRegex.exactMatch(QString::fromLocal8Bit(plist.at(0)))) { + if (gProcessRegex.cap(1).toLongLong() == pid) { + if (uid) + *uid = gProcessRegex.cap(2).toLongLong(); + if (gid) + *gid = gProcessRegex.cap(3).toLongLong(); + return true; + } + } + } return false; } @@ -333,7 +346,17 @@ static void verifyRunning(ProcessBackend *process) pid_t pgrp = ::getpgid(pid); QVERIFY(pid != 0); QCOMPARE(pgrp, pid); + + qint64 uid, gid; + QVERIFY(isProcessRunning(pid, &uid, &gid)); + QString uidString = qgetenv("TEST_UID"); + QString gidString = qgetenv("TEST_GID"); + if (!uidString.isEmpty()) + QCOMPARE(uid, uidString.toLongLong()); + if (!gidString.isEmpty()) + QCOMPARE(gid, gidString.toLongLong()); } + static void cleanupProcess(ProcessBackend *process) { QVERIFY(process->state() == QProcess::NotRunning); @@ -562,12 +585,23 @@ static void oomChangeAfterClient(ProcessBackendManager *manager, ProcessInfo inf typedef void (*clientFunc)(ProcessBackendManager *, ProcessInfo, CommandFunc); +static void fixUidGid(ProcessInfo& info) +{ + QString uidString = qgetenv("TEST_UID"); + QString gidString = qgetenv("TEST_GID"); + if (!uidString.isEmpty()) + info.setUid(uidString.toLongLong()); + if (!gidString.isEmpty()) + info.setGid(gidString.toLongLong()); +} + static void standardFactoryTest( clientFunc func ) { ProcessBackendManager *manager = new ProcessBackendManager; ProcessInfo info; info.setValue("program", "testClient/testClient"); + fixUidGid(info); manager->addFactory(new StandardProcessBackendFactory); func(manager, info, writeLine); @@ -587,6 +621,7 @@ static void prelaunchFactoryTest( clientFunc func ) waitForInternalProcess(manager); info.setValue("prelaunch", "true"); + fixUidGid(info); func(manager, info, writeJson); delete manager; } @@ -603,6 +638,7 @@ static void prelaunchRestrictedTest( clientFunc func ) QVERIFY(manager->memoryRestricted() == true); info.setValue("prelaunch", "true"); + fixUidGid(info); func(manager, info, writeJson); delete manager; } @@ -621,6 +657,7 @@ static void pipeLauncherTest( clientFunc func ) ProcessInfo info2; info2.setValue("program", "testClient/testClient"); info2.setValue("pipe", "true"); + fixUidGid(info2); func(manager, info2, writeLine); delete manager; } @@ -643,6 +680,7 @@ static void socketLauncherTest( clientFunc func ) ProcessInfo info; info.setValue("program", "testClient/testClient"); + fixUidGid(info); func(manager, info, writeLine); delete manager; |