xlock hack
The below patch adds code to check an attached usb memory stick for a matching random key (matching against a copy of the key stored in a user's home dir).
requirements
When the USB key is inserted, it should auto mount to /usb
Change the path in the code fopen("/home/mduller/.xlockcode", "r+") to your own home directory.
- Create the file /usb/.xlockcode containing 4 characters, copy this file to the path you chose above.
--- xlock.c 2008-07-08 04:08:11.000000000 +0100
+++ xlockhack.c 2009-04-04 12:35:23.000000000 +0100
@@ -2641,6 +2641,47 @@
XFlush(dsp);
done = checkPasswd(buffer);
+
+ /* added security hack */
+ /* only do additional security check if password is correct */
+ int iLocalCode = 0;
+ int iUsbCode = 0;
+ int iUsbChk = 0;
+ int iNewCode = 0;
+ iUsbChk = 0;
+ if (done) {
+ /* open .xlockcode file on usb memory for rw,
+ read in code */
+ FILE *usbFile;
+ if ((usbFile = (FILE *) fopen("/usb/.xlockcode", "r+"))) {
+ int nRead = fread(&iUsbCode, sizeof(int), 1, usbFile);
+
+ /* open .xlockcode file in user dir for rw,
+ read in code */
+ FILE *userFile;
+ if ((userFile = (FILE *) fopen("/home/mduller/.xlockcode", "r+"))) {
+ int nRead = fread(&iLocalCode, sizeof(int), 1, userFile);
+ if (iLocalCode == iUsbCode)
+ iUsbChk = 1;
+
+ /* usb security passed, generate new random
+ code for next time */
+
+ srandomdev();
+ iNewCode = random();
+
+ rewind(userFile);
+ rewind(usbFile);
+ int nwrite1 = fwrite(&iNewCode, sizeof(int), 1, userFile);
+ int nwrite2 = fwrite(&iNewCode, sizeof(int), 1, usbFile);
+
+ (void) fclose(userFile);
+ (void) fclose(usbFile);
+ }
+ }
+
+ }
+ /* !added security hack */
if (!done && !*buffer) {
/* just hit return, and it was not his password */
@@ -2680,7 +2721,7 @@
/dev/kmem */
(void) memset((char *) buffer, 0, sizeof (buffer));
- if (done) {
+ if (done && iUsbChk == 1) {
#ifdef USE_SOUND
if (sound)
playSound(validsound, verbose);