From c501700ee0e3f8c683d9fdd56e99e58671ad26cb Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Thu, 11 Jul 2019 16:12:27 +0300 Subject: [PATCH] Add auto screen lock on yubikey remove --- .config/pam_pkcs11/card_eventmgr.conf | 43 +++++++++++++++++++++++++++ .config/sway/config | 9 ++---- 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 .config/pam_pkcs11/card_eventmgr.conf diff --git a/.config/pam_pkcs11/card_eventmgr.conf b/.config/pam_pkcs11/card_eventmgr.conf new file mode 100644 index 0000000..02fef02 --- /dev/null +++ b/.config/pam_pkcs11/card_eventmgr.conf @@ -0,0 +1,43 @@ +card_eventmgr { + + # Run in background? Implies debug=false if set to true + daemon = false; + + # show debug messages? + debug = false; + + # polling time in milliseconds + timeout = 1000; + + # + # list of events and actions + + # Card inserted + event card_insert { + # what to do if an action fail? + # ignore : continue to next action + # return : end action sequence + # quit : end program + on_error = return ; + + # You can enter several, comma-separated action entries + # they will be executed in turn + action = + "gpg-connect-agent 'SCD SERIALNO' /bye | grep -q 'S SERIALNO'", + "pacat --volume=65536 --file-format=oga /usr/share/sounds/freedesktop/stereo/device-added.oga", + "swaymsg 'output * dpms on'", "echo UNLOCK"; + } + + # Card has been removed + event card_remove { + on_error = return ; + action = + "if gpg-connect-agent 'SCD SERIALNO' /bye | grep -q 'S SERIALNO'; then sleep 1; if gpg-connect-agent 'SCD SERIALNO' /bye | grep -q 'S SERIALNO'; then exit 1; else exit 0; fi; fi", + "pacat --volume=65536 --file-format=oga /usr/share/sounds/freedesktop/stereo/device-removed.oga", + "loginctl lock-sessions", "echo LOCK"; + } + + # Too much time locked session + event timeout { + } +} diff --git a/.config/sway/config b/.config/sway/config index 2db7e3b..10b6258 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -21,12 +21,7 @@ font pango:xos4 Terminus 12 set $bg "~/Pildid/background.png" # Uses forked swaylock https://github.com/mortie/swaylock-effects -set $lockcmd swaylock --clock --datestr "%Y-%m-%d" --indicator \ - --image ~/Pildid/background.png --tiling \ - --hide-keyboard-layout --font 'xos4 Terminus' --font-size 28 \ - --text-color ffffff \ - --inside-color 435366 --separator-color 435366 --ring-color 435366 \ - --line-uses-ring +set $lockcmd swaylock --clock --datestr "%Y-%m-%d" --indicator --image $bg --tiling --hide-keyboard-layout --font "xos4 Terminus" --font-size 28 --text-color ffffff --inside-color 435366 --separator-color 435366 --ring-color 435366 --line-uses-ring # Your preferred terminal emulator set $term gnome-terminal @@ -61,6 +56,8 @@ exec ~/.bin/polkit-agent # Dropbox exec ~/code/dropbox-filesystem-fix/dropbox_start.py +# React to smart card events +exec card_eventmgr config_file=.config/pam_pkcs11/card_eventmgr.conf ### Idle configuration exec swayidle \