File indexing completed on 2025-01-26 05:06:35

0001 #!/bin/bash
0002 #
0003 # /etc/hotplug/usb/consoleUserPerms
0004 #
0005 # Sets up newly plugged in USB device so that the user who owns
0006 # the console according to pam_console can access it from user space
0007 #
0008 # Note that for this script to work, you'll need all of the following:
0009 # a) a line in the file /etc/hotplug/usb.usermap or another usermap file
0010 #    in /etc/hotplug/usb/ that corresponds to the device you are using.
0011 # b) a setup using pam_console creates the respective lock files
0012 #    containing the name of the respective user. You can check for that
0013 #    by executing "echo `cat /var/{run,lock}/console.lock`" and
0014 #    verifying the appropriate user is mentioned somewhere there.
0015 # c) a Linux kernel supporting hotplug and usbdevfs
0016 # d) the hotplug package (http://linux-hotplug.sourceforge.net/)
0017 #
0018 # In the usermap file, the first field "usb module" should be named
0019 # "consoleUserPerms" to invoke this script.
0020 #
0021 
0022 if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
0023 then
0024     # New code, using lock files instead of copying /dev/console permissions
0025     # This also works with non-kdm logins (e.g. on a virtual terminal)
0026     # Idea and code from Nalin Dahyabhai <nalin@redhat.com>
0027     if [ -f /var/run/console.lock ]
0028     then
0029         CONSOLEOWNER=`cat /var/run/console.lock`
0030     elif [ -f /var/lock/console.lock ]
0031     then
0032         CONSOLEOWNER=`cat /var/lock/console.lock`
0033     else
0034         CONSOLEOWNER=
0035     fi
0036     if [ -n "$CONSOLEOWNER" ]
0037     then
0038         chmod 0000 "${DEVICE}"
0039         chown "$CONSOLEOWNER" "${DEVICE}"
0040         chmod 0600 "${DEVICE}"
0041     fi
0042 fi