summaryrefslogtreecommitdiffstats
path: root/src/input/pvsPrivInputHandler.cpp
diff options
context:
space:
mode:
authorFabian Schillinger2010-11-01 17:35:27 +0100
committerFabian Schillinger2010-11-01 17:35:27 +0100
commitea3fb17345e5f82db9f2e98a8062e95797700ace (patch)
tree1da0d1a8ec9455364386af78762d0f6fed187824 /src/input/pvsPrivInputHandler.cpp
parentProcess start/stop/view functionality (diff)
parent[PVSGUI] No X required for --help and --version (diff)
downloadpvs-ea3fb17345e5f82db9f2e98a8062e95797700ace.tar.gz
pvs-ea3fb17345e5f82db9f2e98a8062e95797700ace.tar.xz
pvs-ea3fb17345e5f82db9f2e98a8062e95797700ace.zip
Merge branch 'master' of openslx.org:pvs
Conflicts: CMakeLists.txt src/core/pvsConnectionManager.cpp src/pvs.cpp src/pvs.h
Diffstat (limited to 'src/input/pvsPrivInputHandler.cpp')
-rw-r--r--src/input/pvsPrivInputHandler.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/input/pvsPrivInputHandler.cpp b/src/input/pvsPrivInputHandler.cpp
new file mode 100644
index 0000000..70ed1bc
--- /dev/null
+++ b/src/input/pvsPrivInputHandler.cpp
@@ -0,0 +1,108 @@
+/*
+ # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
+ #
+ # This program is free software distributed under the GPL version 2.
+ # See http://openslx.org/COPYING
+ #
+ # If you have any feedback please consult http://openslx.org/feedback and
+ # send your suggestions, praise, or complaints to feedback@openslx.org
+ #
+ # General information about OpenSLX can be found at http://openslx.org/
+ # --------------------------------------------------------------------------
+ # pvsPrivInputHandler.h
+ # - Handle privileged input connection requests - implementation
+ # --------------------------------------------------------------------------
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <cerrno>
+#include <QtDebug>
+#include <QSocketNotifier>
+#include "inputEvent.h"
+#include "inputEventHandler.h"
+#include "pvsPrivInputSocket.h"
+#include "pvsPrivInputHandler.h"
+
+using namespace std;
+
+class PrivInputContext : public InputEventContext
+{
+public:
+ PrivInputContext(pid_t pid, uid_t uid, gid_t gid)
+ : _pid(pid), _uid(uid), _gid(gid)
+ {
+ }
+
+ pid_t getSenderPid() const
+ {
+ return _pid;
+ }
+
+ uid_t getSenderUid() const
+ {
+ return _uid;
+ }
+
+ gid_t getSenderGid() const
+ {
+ return _gid;
+ }
+
+private:
+ pid_t _pid;
+ uid_t _uid;
+ gid_t _gid;
+};
+
+PVSPrivInputHandler::PVSPrivInputHandler(int fd, QObject* parent) :
+ QObject(parent)
+{
+ _fd = fd;
+ _notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
+ _notifier->setEnabled(true);
+ connect(_notifier, SIGNAL(activated(int)), this, SLOT(canRead()));
+}
+
+PVSPrivInputHandler::~PVSPrivInputHandler()
+{
+ delete _notifier;
+}
+
+void PVSPrivInputHandler::canRead()
+{
+ _notifier->setEnabled(false);
+
+ // We need to retrieve the credentials of the process:
+ size_t siz = 8;
+ _messageAssembly.clear();
+ _messageAssembly.resize(8);
+ pid_t pid;
+ uid_t uid;
+ gid_t gid;
+ int err;
+
+ if(!pvsPrivInputRecvMessage(_fd, _messageAssembly.data(), siz, pid, uid, gid, &err))
+ {
+ close(_fd);
+ deleteLater();
+ return;
+ }
+ else
+ {
+ if(siz != 8)
+ {
+ qWarning("Malformed PVS Input Event packet");
+ return;
+ }
+ QDataStream strm(&_messageAssembly, QIODevice::ReadOnly);
+ InputEvent evt;
+ strm.setByteOrder(QDataStream::BigEndian);
+ strm >> evt;
+ PrivInputContext ctx(pid, uid, gid);
+ _handlerChain.handle(evt, &ctx);
+ }
+
+ _notifier->setEnabled(true);
+}