Browse Source

make yubilock compatible with gnome-screensaver

master
Marijn Kuijpers 3 years ago
parent
commit
423d290a77
  1. 1
      bin/config_system.ini
  2. 5
      bin/loginctl-unlock.sh
  3. 18
      bin/xscreensaver_yubilock.py
  4. 12
      install.sh

1
bin/config_system.ini

@ -4,3 +4,4 @@ remove_sudo_timestamp_when_locking = true
[HOSTCONFIG] [HOSTCONFIG]
logfile = log.log logfile = log.log
loglevel = 10 loglevel = 10
screensaver = gnome-screensaver

5
bin/loginctl-unlock.sh

@ -0,0 +1,5 @@
#! /bin/bash
session_id=`loginctl list-sessions --no-legend | while read id rest; do loginctl show-session $id; done | grep 'Id=\|Type=' | sed -z 's/\nType=/ /g' | grep wayland | awk -F '[= ]' '{print $2}'`
loginctl unlock-session "$session_id"

18
bin/xscreensaver_yubilock.py

@ -24,6 +24,8 @@ home_dir = os.path.expanduser("~")
config = ConfigParser() config = ConfigParser()
config.read([f"{script_dir}/config.ini", f"{home_dir}/.yubilock"]) config.read([f"{script_dir}/config.ini", f"{home_dir}/.yubilock"])
screensaver = config.get("HOSTCONFIG", "screensaver", fallback="xscreensaver"))
yubikey_serials = config["USERCONFIG"]["yubikey_serial"].split(',') yubikey_serials = config["USERCONFIG"]["yubikey_serial"].split(',')
# Convert stringlist to intlist # Convert stringlist to intlist
for i, serial in enumerate(yubikey_serials): for i, serial in enumerate(yubikey_serials):
@ -50,9 +52,14 @@ def execute(command: str, shell_on: bool = False, background: bool = False):
return '' if out == b'' else out.decode('utf-8') return '' if out == b'' else out.decode('utf-8')
def screensaver_running(): def screensaver_running():
if screensaver == 'xscreensaver':
graphic_program_instances = execute(f"{script_dir}/kill_screensaver_graphic_program.sh -d | grep graphic_processes | wc -l", shell_on=True) graphic_program_instances = execute(f"{script_dir}/kill_screensaver_graphic_program.sh -d | grep graphic_processes | wc -l", shell_on=True)
if int(graphic_program_instances) > 0: return True if int(graphic_program_instances) > 0: return True
if execute(f"DISPLAY=:0 xscreensaver-command -time | grep 'screen locked' >/dev/null 2>&1", shell_on=True): return True if execute(f"DISPLAY=:0 xscreensaver-command -time | grep 'screen locked' >/dev/null 2>&1", shell_on=True): return True
elif screensaver == 'gnome-screensaver':
screensaver_state = execute("gnome-screensaver-command -q | tr -d '\n'", shell_on=True)
if screensaver_state == 'The screensaver is active': return True
if screensaver_state == 'The screensaver is inactive': return False
return False return False
def lock_screen(): def lock_screen():
@ -60,13 +67,18 @@ def lock_screen():
return return
if config.getboolean('USERCONFIG', 'remove_sudo_timestamp_when_locking', fallback=True): if config.getboolean('USERCONFIG', 'remove_sudo_timestamp_when_locking', fallback=True):
execute('sudo -K', shell_on=True) execute('sudo -K', shell_on=True)
if screensaver == 'xscreensaver':
execute('DISPLAY=:0 xscreensaver-command -lock', shell_on=True) execute('DISPLAY=:0 xscreensaver-command -lock', shell_on=True)
elif screensaver == 'gnome-screensaver':
execute('gnome-screensaver-command -l', shell_on=True)
return return
def unlock_screen(): def unlock_screen():
if args.dummy : if args.dummy :
return return
if screensaver == 'xscreensaver':
logger.info('xscreen process to be killed:') logger.info('xscreen process to be killed:')
xscreensaver_pid = execute(r'ps -A | grep -oPm 1 "\d{2,}(?=\s.+xscreensaver)" || echo null', xscreensaver_pid = execute(r'ps -A | grep -oPm 1 "\d{2,}(?=\s.+xscreensaver)" || echo null',
shell_on=True) shell_on=True)
@ -77,6 +89,8 @@ def unlock_screen():
# restart xscreensaver process # restart xscreensaver process
execute('DISPLAY=:0 xscreensaver -no-splash&', shell_on=True, background = True) execute('DISPLAY=:0 xscreensaver -no-splash&', shell_on=True, background = True)
elif screensaver == 'gnome-screensaver':
execute(f"{script_dir}/loginctl-unlock.sh", shell_on=True, background = True)
return return
def get_yubikey_serials() -> int: def get_yubikey_serials() -> int:
@ -170,6 +184,8 @@ if __name__ == "__main__":
setup_logger(config.get("HOSTCONFIG", "logfile", setup_logger(config.get("HOSTCONFIG", "logfile",
fallback="log.log")) fallback="log.log"))
if screensaver == 'xscreensaver':
# start xscreensaver process # start xscreensaver process
execute('DISPLAY=:0 xscreensaver -no-splash&', shell_on=True, background = True) execute('DISPLAY=:0 xscreensaver -no-splash&', shell_on=True, background = True)
@ -178,8 +194,10 @@ if __name__ == "__main__":
daemon(get_hid_event_monitor()) daemon(get_hid_event_monitor())
if screensaver == 'xscreensaver':
# restart xscreensaver process before leaving # restart xscreensaver process before leaving
execute('DISPLAY=:0 xscreensaver -no-splash&', shell_on=True, background = True) execute('DISPLAY=:0 xscreensaver -no-splash&', shell_on=True, background = True)
sleep(0.2) sleep(0.2)
sys.exit(0) sys.exit(0)

12
install.sh

@ -14,7 +14,7 @@ if [ `id -u` -ne 0 ]; then
fi fi
# Ask for user parameters # Ask for user parameters
echo "This installer is meant to install the yubilock service for one user. Please specifiy for wich user you want to install xscreensaver-yubilock" echo "This installer is meant to install the yubilock service for one user. Please specifiy for wich user you want to install yubilock"
read -p 'Username: ' username read -p 'Username: ' username
userid=`id -u "$username" 2>/dev/null` || ( echo "$username is not a user on this system" && exit 1 ) userid=`id -u "$username" 2>/dev/null` || ( echo "$username is not a user on this system" && exit 1 )
[ "$userid" -lt 1000 ] && echo "User $username seems to be a systemuser (uid: $userid). Please specify a normal user." && exit 1 [ "$userid" -lt 1000 ] && echo "User $username seems to be a systemuser (uid: $userid). Please specify a normal user." && exit 1
@ -95,8 +95,18 @@ cp "$script_dir/bin/xscreensaver_yubilock.py" "$install_dir"
cp "$script_dir/bin/uninstall.sh" "$install_dir" cp "$script_dir/bin/uninstall.sh" "$install_dir"
cp "$script_dir/bin/kill_screensaver_graphic_program.sh" "$install_dir" cp "$script_dir/bin/kill_screensaver_graphic_program.sh" "$install_dir"
cp "$script_dir/bin/seconds_since_wakeup.sh" "$install_dir" cp "$script_dir/bin/seconds_since_wakeup.sh" "$install_dir"
cp "$script_dir/bin/loginctl-unlock.sh" "$install_dir"
cp "$script_dir/bin/config_system.ini" "$install_dir/config.ini" cp "$script_dir/bin/config_system.ini" "$install_dir/config.ini"
if dpkg -l xscreensaver | grep 'ii.*xscreensaver' >/dev/null; then
screensaver='xscreensaver'
elif dpkg -l gnome-screensaver | grep 'ii.*gnome-screensaver' >/dev/null; then
screensaver='gnome-screensaver'
else
screensaver='none'
fi
sed -i "s+^screensaver.*+screensaver\ =\ $screensaver+g" "$install_dir/config.ini"
chown -R root:yubilock "$install_dir" chown -R root:yubilock "$install_dir"
chmod 771 "$install_dir" chmod 771 "$install_dir"

Loading…
Cancel
Save