summaryrefslogtreecommitdiffstats
path: root/kdm/kfrontend/sakdlg.cc
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-09-22 17:53:08 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-09-22 17:53:08 +0000
commit0f05883544c6b698ce76b524da4d13d77529eb31 (patch)
treed314cefd405ba01ad12ea8c393d3731ff98a00ab /kdm/kfrontend/sakdlg.cc
parent60de68e5c083d6b504912461505de5dee1e0afb1 (diff)
downloadtdebase-0f05883544c6b698ce76b524da4d13d77529eb31.tar.gz
tdebase-0f05883544c6b698ce76b524da4d13d77529eb31.zip
Add remote control socket to kdm
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1255013 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdm/kfrontend/sakdlg.cc')
-rw-r--r--kdm/kfrontend/sakdlg.cc97
1 files changed, 96 insertions, 1 deletions
diff --git a/kdm/kfrontend/sakdlg.cc b/kdm/kfrontend/sakdlg.cc
index 2db602409..b19e18ed0 100644
--- a/kdm/kfrontend/sakdlg.cc
+++ b/kdm/kfrontend/sakdlg.cc
@@ -38,7 +38,9 @@
#include <tqlistview.h>
#include <tqheader.h>
#include <tqcheckbox.h>
+#include <tqtimer.h>
+#include <fcntl.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
@@ -52,12 +54,29 @@
#include <X11/Xatom.h>
#include <fixx11h.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <termios.h>
+#include <signal.h>
+
#include "kfdialog.h"
#ifndef AF_LOCAL
# define AF_LOCAL AF_UNIX
#endif
+#define FIFO_DIR "/tmp/ksocket-global/kdm"
+#define FIFO_FILE "/tmp/ksocket-global/kdm/kdmctl-%1"
+#define FIFO_SAK_FILE "/tmp/ksocket-global/kdm/kdmctl-sak-%1"
+
bool trinity_desktop_lock_use_system_modal_dialogs = TRUE;
extern bool trinity_desktop_lock_use_sak;
@@ -67,7 +86,7 @@ extern bool trinity_desktop_lock_use_sak;
//
SAKDlg::SAKDlg(TQWidget *parent)
: TQDialog(parent, "information dialog", true, (trinity_desktop_lock_use_system_modal_dialogs?((WFlags)WStyle_StaysOnTop):((WFlags)WX11BypassWM))),
- mUnlockingFailed(false)
+ mUnlockingFailed(false), mPipe_fd(-1), closingDown(false)
{
if (trinity_desktop_lock_use_system_modal_dialogs) {
// Signal that we do not want any window controls to be shown at all
@@ -109,21 +128,97 @@ SAKDlg::SAKDlg(TQWidget *parent)
*mSAKProcess << "kdmtsak" << "dm";
connect(mSAKProcess, TQT_SIGNAL(processExited(KProcess*)), this, TQT_SLOT(slotSAKProcessExited()));
mSAKProcess->start();
+
+ TQTimer::singleShot( 0, this, TQT_SLOT(handleInputPipe()) );
}
void SAKDlg::slotSAKProcessExited()
{
int retcode = mSAKProcess->exitStatus();
if (retcode != 0) trinity_desktop_lock_use_sak = false;
+ closingDown = true;
hide();
}
+void SAKDlg::handleInputPipe(void) {
+ if (closingDown) {
+ ::unlink(mPipeFilename.ascii());
+ return;
+ }
+
+ if (isShown() == false) {
+ TQTimer::singleShot( 100, this, TQT_SLOT(handleInputPipe()) );
+ return;
+ }
+
+ char readbuf[2048];
+ int displayNumber;
+ TQString currentDisplay;
+ currentDisplay = TQString(getenv("DISPLAY"));
+ currentDisplay = currentDisplay.replace(":", "");
+ displayNumber = currentDisplay.toInt();
+ mPipeFilename = TQString(FIFO_SAK_FILE).tqarg(displayNumber);
+ ::unlink((TQString(FIFO_FILE).tqarg(displayNumber)).ascii());
+
+ /* Create the FIFOs if they do not exist */
+ umask(0);
+ struct stat buffer;
+ int status;
+ status = stat(FIFO_DIR, &buffer);
+ if (status == 0) {
+ int file_mode = ((buffer.st_mode & S_IRWXU) >> 6) * 100;
+ file_mode = file_mode + ((buffer.st_mode & S_IRWXG) >> 3) * 10;
+ file_mode = file_mode + ((buffer.st_mode & S_IRWXO) >> 0) * 1;
+ if ((file_mode != 600) || (buffer.st_uid != 0) || (buffer.st_gid != 0)) {
+ ::unlink(mPipeFilename.ascii());
+ printf("[WARNING] Possible security breach! Please check permissions on " FIFO_DIR " (must be 600 and owned by root/root, got %d %d/%d). Not listening for login credentials on remote control socket.\n", file_mode, buffer.st_uid, buffer.st_gid); fflush(stdout);
+ return;
+ }
+ }
+ mkdir(FIFO_DIR,0600);
+ mknod(mPipeFilename.ascii(), S_IFIFO|0600, 0);
+ chmod(mPipeFilename.ascii(), 0600);
+
+ mPipe_fd = ::open(mPipeFilename.ascii(), O_RDONLY | O_NONBLOCK);
+ int numread;
+ TQString inputcommand = "";
+ while ((!inputcommand.contains('\n')) && (!closingDown)) {
+ numread = ::read(mPipe_fd, readbuf, 2048);
+ readbuf[numread] = 0;
+ readbuf[2047] = 0;
+ inputcommand += readbuf;
+ tqApp->processEvents();
+ }
+ if (closingDown) {
+ ::unlink(mPipeFilename.ascii());
+ return;
+ }
+ inputcommand = inputcommand.replace('\n', "");
+ TQStringList commandList = TQStringList::split('\t', inputcommand, false);
+ if ((*(commandList.at(0))) == "CLOSE") {
+ mSAKProcess->kill();
+ }
+ if (!closingDown) {
+ TQTimer::singleShot( 0, this, TQT_SLOT(handleInputPipe()) );
+ ::close(mPipe_fd);
+ ::unlink(mPipeFilename.ascii());
+ }
+ else {
+ ::unlink(mPipeFilename.ascii());
+ }
+}
+
SAKDlg::~SAKDlg()
{
if ((mSAKProcess) && (mSAKProcess->isRunning())) {
mSAKProcess->kill(SIGTERM);
delete mSAKProcess;
}
+ if (mPipe_fd != -1) {
+ closingDown = true;
+ ::close(mPipe_fd);
+ ::unlink(mPipeFilename.ascii());
+ }
hide();
}