Added filename translation to the ui-socker

This commit is contained in:
fedir 2025-05-01 16:17:50 +02:00
parent a1445c5423
commit 5452c3d1d7
Signed by: fedir
GPG Key ID: C959EE85F0C9362C

View File

@ -12,6 +12,7 @@
#include <time.h> #include <time.h>
#define _GNU_SOURCE #define _GNU_SOURCE
#include "perm_permissions_table.h" #include "perm_permissions_table.h"
#include "real_filename.h"
#include "temp_permissions_table.h" #include "temp_permissions_table.h"
#include "ui-socket.h" #include "ui-socket.h"
#include <pthread.h> #include <pthread.h>
@ -70,7 +71,7 @@ access_t ask_access(const char *filename, struct process_info proc_info) {
"zenity --question --extra-button \"Allow this time\" --title " "zenity --question --extra-button \"Allow this time\" --title "
"\"Allow Access?\" --text \"Allow process " "\"Allow Access?\" --text \"Allow process "
"<tt>%s</tt> with PID <tt>%d</tt> to access <tt>%s</tt>\"", "<tt>%s</tt> with PID <tt>%d</tt> to access <tt>%s</tt>\"",
proc_info.name, proc_info.PID, filename); proc_info.name, proc_info.PID, filename, get_mountpoint());
if (ret < 0) { if (ret < 0) {
// If asprintf fails, the contents of command are undefined (see man // If asprintf fails, the contents of command are undefined (see man
@ -126,20 +127,25 @@ access_t ask_access(const char *filename, struct process_info proc_info) {
*/ */
int interactive_access(const char *filename, struct process_info proc_info, int interactive_access(const char *filename, struct process_info proc_info,
int opts) { int opts) {
char *real_path = real_filename(filename);
access_t access = check_temp_access(filename, proc_info); access_t access = check_temp_access(real_path, proc_info);
if (access == ALLOW) { if (access == ALLOW) {
free(real_path);
return 1; return 1;
} }
if (access == DENY) { if (access == DENY) {
free(real_path);
return 0; return 0;
} }
access = check_perm_access(filename, proc_info); access = check_perm_access(real_path, proc_info);
if (access == ALLOW) { if (access == ALLOW) {
free(real_path);
return 1; return 1;
} }
if (access == DENY) { if (access == DENY) {
free(real_path);
return 0; return 0;
} }
@ -147,30 +153,36 @@ int interactive_access(const char *filename, struct process_info proc_info,
// permissions are granted // permissions are granted
if (opts & GRANT_PERM) { if (opts & GRANT_PERM) {
give_perm_access(filename, proc_info); give_perm_access(real_path, proc_info);
free(real_path);
return 1; return 1;
} }
if (opts & GRANT_TEMP) { if (opts & GRANT_TEMP) {
set_temp_access(filename, proc_info, SET_ALLOW); set_temp_access(real_path, proc_info, SET_ALLOW);
free(real_path);
return 1; return 1;
} }
access_t user_response = ask_access(filename, proc_info); access_t user_response = ask_access(real_path, proc_info);
if (user_response == ALLOW) { if (user_response == ALLOW) {
give_perm_access(filename, proc_info); give_perm_access(real_path, proc_info);
free(real_path);
return 1; return 1;
} }
if (user_response == ALLOW_TEMP) { if (user_response == ALLOW_TEMP) {
set_temp_access(filename, proc_info, SET_ALLOW); set_temp_access(real_path, proc_info, SET_ALLOW);
free(real_path);
return 1; return 1;
} }
if (user_response == DENY) { if (user_response == DENY) {
set_temp_access(filename, proc_info, SET_DENY); set_temp_access(real_path, proc_info, SET_DENY);
free(real_path);
return 0; return 0;
} }
free(real_path);
// deny on unknown options. // deny on unknown options.
return 0; return 0;
} }