LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-26-2005, 07:30 PM   #1
statman
LQ Newbie
 
Registered: Jun 2005
Posts: 9

Rep: Reputation: 0
Locking keyboard and mouse from a bash script


I need a simple way to lock the keyboard and mouse from a bash script. So, basically, I want to stop I/O from the keyboard and mouse. I also want to be able to turn it back on.

I have been surfing around looking for specific methods to achieve this, but all I am finding are software programs that can help do this. Isnt there a simple command or small script that will turn off keyboard and mouse I/O?

TIA
 
Old 06-28-2005, 03:45 AM   #2
plusminus
LQ Newbie
 
Registered: Mar 2004
Distribution: Slackware 10
Posts: 15

Rep: Reputation: 0
Are you doing this in X or at a terminal window? In X I imagine you could do it easily with the setxkbmap and xsetpointer commands. From a terminal I really don't know...
 
Old 06-28-2005, 04:25 AM   #3
statman
LQ Newbie
 
Registered: Jun 2005
Posts: 9

Original Poster
Rep: Reputation: 0
This is from a desktop. There will be no terminal sessions running. I want to enable and disable IO after x minutes of usage time. I am going to control it from a bash script. Thanks for your help. Ill give those commands a try.
 
Old 06-28-2005, 05:42 AM   #4
plusminus
LQ Newbie
 
Registered: Mar 2004
Distribution: Slackware 10
Posts: 15

Rep: Reputation: 0
Hmm, instead of setxkbmap I should've suggested xmodmap. Anyhow, in case you don't have it going yet, here's my solution which I'm sure you can adapt to your needs:

**DISCLAIMER**: I am not a security expert by any means, I don't know what kind of set up you're using or how secure a system you need, use at your own risk

First, the keyboard. Doable entirely in a shell script:
Code:
#!/bin/bash

# ***********************************************************************
# ** This method requires write permissions and generates any files it **
# ** needs automatically. To use in a dir without write permissions,   **
# ** generate xmodmap.blank and xmodmap.orig first and keep them where **
# ** you can point to them in the script, and go straight to step two. **
# ***********************************************************************


# step one: write files for use with xmodmap

if [ -f ./xmodmap.blank ]	#remove xmodmap.blank if it exists
then
   rm xmodmap.blank
fi
if [ -f ./xmodmap.orig ]        #remove xmodmap.orig if it exists
then
   rm xmodmap.orig
fi

xmodmap -pke > xmodmap.orig	#backup current keyboard config

touch xmodmap.blank		#write a blank keyboard config
for i in `seq 8 255`; do	
   echo "keycode  $i = " >> xmodmap.blank
done



#step two: switch the keyboard to "off" then back

xmodmap xmodmap.blank		#set keyboard to blank

sleep 20 			#do stuff here. right now all we do
				#is pause for 20 seconds to test that
				#the keyboard is indeed "off".

xmodmap xmodmap.orig		#restore keyboard functionality

rm xmodmap.blank		#cleanup from step one
rm xmodmap.orig
Now, the mouse. First you have to add these lines to your xorg.conf (or equivalent) file right after the Core Pointer InputDevice section (i.e., the regular mouse):
Code:
Section "InputDevice"
    Identifier  "Void1"
    Driver      "void"
EndSection
and here near the bottom of the file, in the ServerLayout section:
Code:
    InputDevice "Void1" "SendCoreEvents"
now restart X and you should be able to type xsetpointer Void1 and the mouse will stop working. Unfortunately the cursor stays on the screen, your WM might have a way to hide the cursor if it doesn't move for awhile or something. To restore mouse functionality type xsetpointer Mouse1 , assuming Mouse1 is the Identifier you used for your mouse in xorg.conf

Now that I think about it actually, it should be possible to set the CoreKeyboard to Void1 also, bypassing that script entirely... however, I'm not sure of any command to do so...

Hope this does it for you!

Last edited by plusminus; 06-28-2005 at 05:55 AM.
 
Old 06-28-2005, 07:32 AM   #5
statman
LQ Newbie
 
Registered: Jun 2005
Posts: 9

Original Poster
Rep: Reputation: 0
You rock! Thanks for the help. I will let ya know how it turns out.
Cheers
 
Old 06-28-2005, 09:50 AM   #6
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
As I see it, there are three ways to do that.

1/ The cleanest is to lock all consoles. A utility is available in the "open" package I believe to do that.

2/ Still simple: unload the I/O modules, eg: usbmouse, usb-ehci (I don't remember exactly).

3/ Scramble everything to render the mouse and keyboards useless, as suggested above.

Note that only the first solution has any chance of having any effect on incoming connections (Well, with the 2nd solution, you could also unload your network card module...).

Yves.
 
Old 06-28-2005, 05:31 PM   #7
statman
LQ Newbie
 
Registered: Jun 2005
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks YinYeti.

What is the "open" package?

Ideally, here is what I want to happen with as little code as possible:
A timer signals that the user cannot use the account anymore.
The keyboard and mouse are locked to signal to the user that he is done.
The xscreensaver is invoked.
All processes running on the account are killed
A bash script waits for a signal that the account can be used again.
The bash screen restores keyboard and mouse control
The user starts using the account.

Ideally, I wanted to use xscreensaver's screenlock feature, but there is no unlock command to allow a new user to start using the account without typing in the account password, which I do not want the user to know. You can think of the situation as logging into an account once and allowing multiple people to use the account after they notify a sysadmin and the sysadmin sends the appropriate signal.

I wanted all of this to be controlled from a bash script that is constantly looking for the sysadmin signal and tracking the account users time, taking action after time has expired.

I want to do this with the least amount of code and use bash if possible. I guess I could modify the xscreensaver source code to add an unlock feature. That would be the most elegant solution. Barring that, I can try the various methods suggested in this thread and select the most efficient one.

Thanks again all for your help!
 
Old 06-29-2005, 02:48 AM   #8
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
The "open" package (at least in Mandrake) is a package with the open command for opening a new virtual console with a command in it. If I remember correctly it also contains a command for locking virtual consoles. Now that I rethink of it though, I wonder if the name of the package that you want is not "vlock" instead...

I think you can use xscreensaver. With the appropriate rights, you should be able to kill and restart it in the background, hence (because of the kill) removing the password step. Just an idea, though. I did not test.

Yves.
 
Old 06-29-2005, 03:03 AM   #9
statman
LQ Newbie
 
Registered: Jun 2005
Posts: 9

Original Poster
Rep: Reputation: 0
Ya, I thought of just killing xscreensaver as well, but it seems like such a hack :-) Ill spend some time on Friday playing around with what people have suggested in this thread.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB mouse locking up system n0xvb Slackware 2 10-04-2005 09:50 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM
my mouse input is takes as keyboard input in BASH e1000 Slackware 5 12-08-2003 04:00 PM
Unwanted keyboard shift locking stunji Slackware 1 12-03-2003 11:53 PM
USB mouse, keyboard, hid, console mouse problems jqcaducifer Linux - General 1 08-05-2003 10:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration