Backport of TDE GIT commit

Make tsak a bit more robust


git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1253890 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 13 years ago
parent 810b411783
commit 94ee9219dd

@ -184,97 +184,130 @@ int main (int argc, char *argv[])
bool ctrl_down = false; bool ctrl_down = false;
bool alt_down = false; bool alt_down = false;
bool hide_event = false; bool hide_event = false;
bool established = false;
bool testrun = false;
// Create the output pipe if (argc == 2) {
PipeHandler controlpipe; if (strcmp(argv[1], "checkactive") == 0) {
testrun = true;
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 // Create the output pipe
fd = find_keyboard(); PipeHandler controlpipe;
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 while (1) {
devout=open("/dev/misc/uinput",O_WRONLY|O_NONBLOCK); if ((getuid ()) != 0) {
if (devout<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");
devout=open("/dev/uinput",O_WRONLY|O_NONBLOCK); return 5;
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); // Open Device
write(devout,&devinfo,sizeof(devinfo)); fd = find_keyboard();
if (ioctl(devout,UI_DEV_CREATE)<0) { if (fd == -1) {
fprintf(stderr,"Unable to create input device with UI_DEV_CREATE\n"); printf ("Could not find your keyboard!\n");
return 2; if (established)
} sleep(1);
else { else
fprintf(stderr,"Device created.\n"); return 4;
}
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;
} }
else {
// Print Device Name
ioctl (fd, EVIOCGNAME (sizeof (name)), name);
printf ("Reading From : (%s)\n", name);
value = ev[0].value; // Create filtered virtual output device
devout=open("/dev/misc/uinput",O_WRONLY|O_NONBLOCK);
if (value != ' ' && ev[1].value == 0 && ev[1].type == 1){ // Read the key release event if (devout<0) {
if (keycode[(ev[1].code)]) { devout=open("/dev/uinput",O_WRONLY|O_NONBLOCK);
if (strcmp(keycode[(ev[1].code)], "<control>") == 0) ctrl_down = false;
if (strcmp(keycode[(ev[1].code)], "<alt>") == 0) alt_down = false;
} }
} if (devout<0) {
if (value != ' ' && ev[1].value == 1 && ev[1].type == 1){ // Read the key press event 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");
if (keycode[(ev[1].code)]) { perror("open(\"/dev/misc/uinput\")");
if (strcmp(keycode[(ev[1].code)], "<control>") == 0) ctrl_down = true; if (established)
if (strcmp(keycode[(ev[1].code)], "<alt>") == 0) alt_down = true; sleep(1);
else
return 3;
} }
} else {
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");
if (established)
sleep(1);
else
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");
if (established)
sleep(1);
else
return 1;
}
else {
hide_event = false; established = true;
if (keycode[(ev[1].code)]) {
if (alt_down && ctrl_down && (strcmp(keycode[(ev[1].code)], "<del>") == 0)) {
hide_event = true;
}
}
if (hide_event == false) { if (testrun == true) {
// Pass the event on... return 0;
event = ev[0]; }
write(devout, &event, sizeof event);
event = ev[1]; while (1) {
write(devout, &event, sizeof event); if ((rd = read (fd, ev, size * 2)) < size) {
} fprintf(stderr,"Read failed.\n");
if (hide_event == true) { break;
// Let anyone listening to our interface know that an SAK keypress was received }
write(mPipe_fd_out, "SAK\n\r", 6);
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)], "<control>") == 0) ctrl_down = false;
if (strcmp(keycode[(ev[1].code)], "<alt>") == 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)], "<control>") == 0) ctrl_down = true;
if (strcmp(keycode[(ev[1].code)], "<alt>") == 0) alt_down = true;
}
}
hide_event = false;
if (keycode[(ev[1].code)]) {
if (alt_down && ctrl_down && (strcmp(keycode[(ev[1].code)], "<del>") == 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; return 6;
} }

Loading…
Cancel
Save