From 810b411783a6c4a50d8b63b9a34d11912e0a0291 Mon Sep 17 00:00:00 2001 From: tpearson Date: Fri, 16 Sep 2011 01:56:21 +0000 Subject: Add tsak Trinity now has full GUI SAK support, a first for any Linux DE! git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1253878 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- CMakeLists.txt | 1 + kdm/kfrontend/kgapp.cpp | 7 +- tsak/CMakeLists.txt | 27 +++++ tsak/main.cpp | 280 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 313 insertions(+), 2 deletions(-) create mode 100644 tsak/CMakeLists.txt create mode 100644 tsak/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 917062e5d..8a72af9c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,6 +194,7 @@ tde_conditional_add_subdirectory( BUILD_KSYSTRAYCMD ksystraycmd ) tde_conditional_add_subdirectory( BUILD_NSPLUGINS nsplugins ) tde_conditional_add_subdirectory( BUILD_KSYSGUARD ksysguard ) tde_conditional_add_subdirectory( BUILD_KXKB kxkb ) +add_subdirectory( tsak ) add_subdirectory( krootbacking ) ##### install startkde & related stuff ########## diff --git a/kdm/kfrontend/kgapp.cpp b/kdm/kfrontend/kgapp.cpp index ac99a4bc3..5e1581fb2 100644 --- a/kdm/kfrontend/kgapp.cpp +++ b/kdm/kfrontend/kgapp.cpp @@ -185,6 +185,11 @@ kg_main( const char *argv0 ) KApplication::disableAutoDcopRegistration(); KCrash::setSafer( true ); + trinity_desktop_lock_use_sak = _useSAK; + if (trinity_desktop_lock_use_sak) { + system(TQString(TQCString( argv0, strrchr( argv0, '/' ) - argv0 + 2 ) + "tsak &").ascii()); + } + #ifdef HAVE_XCOMPOSITE // Begin ARGB initialization XSetErrorHandler( ignoreXError ); @@ -298,8 +303,6 @@ kg_main( const char *argv0 ) has_kwin = true; } - trinity_desktop_lock_use_sak = _useSAK; - GSendInt( G_Ready ); kdDebug() << timestamp() << " main1" << endl; diff --git a/tsak/CMakeLists.txt b/tsak/CMakeLists.txt new file mode 100644 index 000000000..6aa5b4973 --- /dev/null +++ b/tsak/CMakeLists.txt @@ -0,0 +1,27 @@ +################################################# +# +# (C) 2010-2011 Timothy Pearson +# kb9vqf (AT) pearsoncomputing.net +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### tsak (executable) ####################### + +tde_add_executable( tsak + SOURCES main.cpp + DESTINATION ${BIN_INSTALL_DIR} +) diff --git a/tsak/main.cpp b/tsak/main.cpp new file mode 100644 index 000000000..0cbfa3751 --- /dev/null +++ b/tsak/main.cpp @@ -0,0 +1,280 @@ +/* +Copyright 2010 Adam Marchetti +Copyright 2011 Timothy Pearson + +This file is part of tsak. + +tsak is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 +of the License, or (at your option) any later version. + +tsak is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public +License along with tsak. If not, see http://www.gnu.org/licenses/. + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define FIFO_DIR "/tmp/ksocket-global" +#define FIFO_FILE_OUT "/tmp/ksocket-global/tsak" + +#define TestBit(bit, array) (array[(bit) / 8] & (1 << ((bit) % 8))) + +typedef unsigned char byte; + +bool mPipeOpen_out; +int mPipe_fd_out; + +struct sigaction usr_action; +sigset_t block_mask; + +const char *keycode[256] = +{ + "", "", "1", "2", "3", "4", "5", "6", "7", "8", + "9", "0", "−", "=", "", "", "q", "w", "e", "r", + "t", "y", "u", "i", "o", "p", "[", "]", "\n", "", + "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", + "'", "", "", "\\", "z", "x", "c", "v", "b", "n", + "m", ",", ".", "/", "", "", "", " ", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "\\", "f11", "f12", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "" +}; + +/* returns 1 if bit number i is set, otherwise returns 0 */ +int bit_set(size_t i, const byte* a) +{ + return a[i/CHAR_BIT] & (1 << i%CHAR_BIT); +} + +/* Assign features (supported axes and keys) of the physical input device (devin) + * to the virtual input device (devout) */ +static void copy_features(int devin, int devout) +{ + byte evtypes[EV_MAX/CHAR_BIT + 1] = {0}; + byte codes[KEY_MAX/CHAR_BIT + 1]; + unsigned i,code; + int op; + if (ioctl(devin, EVIOCGBIT(0, sizeof(evtypes)), evtypes) < 0) return; + for(i=0;i -1) { + mPipeOpen_out = true; + } +} + +class PipeHandler +{ +public: + PipeHandler(); + ~PipeHandler(); +}; + +PipeHandler::PipeHandler() +{ + setupPipe(); +} + +PipeHandler::~PipeHandler() +{ + tearDownPipe(); +} + +int main (int argc, char *argv[]) +{ + struct input_event ev[64]; + struct input_event event; + struct uinput_user_dev devinfo={0}; + int fd, devout, rd, value, size = sizeof (struct input_event); + char name[256] = "Unknown"; + bool ctrl_down = false; + bool alt_down = false; + bool hide_event = false; + + // Create the output pipe + PipeHandler controlpipe; + + if ((getuid ()) != 0) { + printf ("You are not root! This WILL NOT WORK!\nDO NOT attempt to bypass security restrictions, e.g. by changing keyboard permissions or owner, if you want the SAK system to remain secure...\n"); + return 5; + } + + // Open Device + fd = find_keyboard(); + if (fd == -1) { + printf ("Could not find your keyboard!\n"); + } + + // Print Device Name + ioctl (fd, EVIOCGNAME (sizeof (name)), name); + printf ("Reading From : (%s)\n", name); + + // Create filtered virtual output device + devout=open("/dev/misc/uinput",O_WRONLY|O_NONBLOCK); + if (devout<0) { + devout=open("/dev/uinput",O_WRONLY|O_NONBLOCK); + if (devout<0) { + fprintf(stderr,"Unable to open /dev/uinput or /dev/misc/uinput (char device 10:223).\nPossible causes: Device node inexistent or kernel not compiled with evdev user level driver support or permission denied.\n"); + perror("open(\"/dev/misc/uinput\")"); + return 3; + } + } + ioctl(fd, EVIOCGNAME(UINPUT_MAX_NAME_SIZE), devinfo.name); + strncat(devinfo.name, "+tsak", UINPUT_MAX_NAME_SIZE-1); + fprintf(stderr, "%s\n", devinfo.name); + ioctl(fd, EVIOCGID, &devinfo.id); + + copy_features(fd, devout); + write(devout,&devinfo,sizeof(devinfo)); + if (ioctl(devout,UI_DEV_CREATE)<0) { + fprintf(stderr,"Unable to create input device with UI_DEV_CREATE\n"); + return 2; + } + else { + fprintf(stderr,"Device created.\n"); + } + + if(ioctl(fd, EVIOCGRAB, 2) < 0) { + close(fd); + fprintf(stderr, "Failed to grab exclusive input device lock"); + return 1; + } + + while (1) { + + if ((rd = read (fd, ev, size * 2)) < size) { + fprintf(stderr,"Read failed.\n"); + return 1; + } + + value = ev[0].value; + + if (value != ' ' && ev[1].value == 0 && ev[1].type == 1){ // Read the key release event + if (keycode[(ev[1].code)]) { + if (strcmp(keycode[(ev[1].code)], "") == 0) ctrl_down = false; + if (strcmp(keycode[(ev[1].code)], "") == 0) alt_down = false; + } + } + if (value != ' ' && ev[1].value == 1 && ev[1].type == 1){ // Read the key press event + if (keycode[(ev[1].code)]) { + if (strcmp(keycode[(ev[1].code)], "") == 0) ctrl_down = true; + if (strcmp(keycode[(ev[1].code)], "") == 0) alt_down = true; + } + } + + hide_event = false; + if (keycode[(ev[1].code)]) { + if (alt_down && ctrl_down && (strcmp(keycode[(ev[1].code)], "") == 0)) { + hide_event = true; + } + } + + if (hide_event == false) { + // Pass the event on... + event = ev[0]; + write(devout, &event, sizeof event); + event = ev[1]; + write(devout, &event, sizeof event); + } + if (hide_event == true) { + // Let anyone listening to our interface know that an SAK keypress was received + write(mPipe_fd_out, "SAK\n\r", 6); + } + } + + return 0; +} -- cgit v1.2.1