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,10 +184,19 @@ int main (int argc, char *argv[])
bool ctrl_down = false;
bool alt_down = false;
bool hide_event = false;
bool established = false;
bool testrun = false;
if (argc == 2) {
if (strcmp(argv[1], "checkactive") == 0) {
testrun = true;
}
}
// Create the output pipe
PipeHandler controlpipe;
while (1) {
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;
@ -197,8 +206,12 @@ int main (int argc, char *argv[])
fd = find_keyboard();
if (fd == -1) {
printf ("Could not find your keyboard!\n");
if (established)
sleep(1);
else
return 4;
}
else {
// Print Device Name
ioctl (fd, EVIOCGNAME (sizeof (name)), name);
printf ("Reading From : (%s)\n", name);
@ -207,12 +220,16 @@ int main (int argc, char *argv[])
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\")");
if (established)
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);
@ -222,23 +239,34 @@ int main (int argc, char *argv[])
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 {
while (1) {
established = true;
if (testrun == true) {
return 0;
}
while (1) {
if ((rd = read (fd, ev, size * 2)) < size) {
fprintf(stderr,"Read failed.\n");
return 1;
break;
}
value = ev[0].value;
@ -275,6 +303,11 @@ int main (int argc, char *argv[])
write(mPipe_fd_out, "SAK\n\r", 6);
}
}
}
}
}
}
}
return 0;
return 6;
}

Loading…
Cancel
Save