aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkoekeishiya <aasvi93@hotmail.com>2019-04-08 17:38:30 +0200
committerkoekeishiya <aasvi93@hotmail.com>2019-04-08 17:38:30 +0200
commitfeb4cc904df602fad2689492db3d227bb57f2708 (patch)
tree2037272092a25959de08ea9f162b5f979819fa90
parent3aac6931638a8d5da8563e179d71218354e908a6 (diff)
downloadskhd-feb4cc904df602fad2689492db3d227bb57f2708.tar.gz
skhd-feb4cc904df602fad2689492db3d227bb57f2708.zip
#51 output process that has 'Secure Keyboard Entry' enabled if detected during startup
-rw-r--r--src/carbon.c8
-rw-r--r--src/carbon.h1
-rw-r--r--src/skhd.c30
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()) {