From feb4cc904df602fad2689492db3d227bb57f2708 Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Mon, 8 Apr 2019 17:38:30 +0200 Subject: #51 output process that has 'Secure Keyboard Entry' enabled if detected during startup --- src/carbon.c | 8 ++++++++ src/carbon.h | 1 + src/skhd.c | 30 ++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/carbon.c b/src/carbon.c index c6fddef..dcfc2d8 100644 --- a/src/carbon.c +++ b/src/carbon.c @@ -17,6 +17,14 @@ find_process_name_for_psn(ProcessSerialNumber *psn) return NULL; } +inline char * +find_process_name_for_pid(pid_t pid) +{ + ProcessSerialNumber psn; + GetProcessForPID(pid, &psn); + return find_process_name_for_psn(&psn); +} + internal inline char * find_active_process_name(void) { diff --git a/src/carbon.h b/src/carbon.h index d98792a..8ef9ed4 100644 --- a/src/carbon.h +++ b/src/carbon.h @@ -12,6 +12,7 @@ struct carbon_event char * volatile process_name; }; +char *find_process_name_for_pid(pid_t pid); bool carbon_event_init(struct carbon_event *carbon); #endif diff --git a/src/skhd.c b/src/skhd.c index b89f9f1..fb04e0e 100644 --- a/src/skhd.c +++ b/src/skhd.c @@ -35,7 +35,8 @@ #include "hotkey.c" #include "synthesize.c" -extern bool CGSIsSecureEventInputSet(); +extern CFDictionaryRef CGSCopyCurrentSessionDictionary(void); +extern bool CGSIsSecureEventInputSet(void); #define secure_keyboard_entry_enabled CGSIsSecureEventInputSet #define internal static @@ -290,6 +291,31 @@ use_default_config_path(void) config_file[length] = '\0'; } +internal void +dump_secure_keyboard_entry_process_info(void) +{ + CFDictionaryRef session; + CFNumberRef pid_ref; + char *process_name; + pid_t pid; + + session = CGSCopyCurrentSessionDictionary(); + if (!session) goto err; + + pid_ref = (CFNumberRef) CFDictionaryGetValue(session, CFSTR("kCGSSessionSecureInputPID")); + if (!pid_ref) goto err; + + CFNumberGetValue(pid_ref, CFNumberGetType(pid_ref), &pid); + process_name = find_process_name_for_pid(pid); + + if (process_name) { + error("skhd: secure keyboard entry is enabled by (%lld) '%s'! abort..\n", pid, process_name); + } + +err: + error("skhd: secure keyboard entry is enabled! abort..\n"); +} + int main(int argc, char **argv) { if (getuid() == 0 || geteuid() == 0) { @@ -305,7 +331,7 @@ int main(int argc, char **argv) create_pid_file(); if (secure_keyboard_entry_enabled()) { - error("skhd: secure keyboard entry is enabled! abort..\n"); + dump_secure_keyboard_entry_process_info(); } if (!check_privileges()) { -- cgit v1.2.3