Compare commits
No commits in common. "8e1c325f98c8c14bfb41bbc7ee6026a7786f6dfc" and "90d94c76156677bb3afe2d7b5dc6d25262d0eecb" have entirely different histories.
8e1c325f98
...
90d94c7615
@ -207,9 +207,6 @@ void destroy_perm_permissions_table(void) { sqlite3_close(perm_database); }
|
||||
*/
|
||||
access_t check_perm_access_noparent(const char *filename,
|
||||
struct process_info pi) {
|
||||
if (pi.name == NULL)
|
||||
return NDEF;
|
||||
|
||||
access_t ret = NDEF;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
const char *sql = "SELECT mode FROM permissions WHERE executable = ?1 "
|
||||
|
@ -8,10 +8,8 @@
|
||||
|
||||
#include "proc_operations.h"
|
||||
#include <linux/limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/**
|
||||
* @brief Returns the PID of the main thread (i.e., the process ID) of the
|
||||
@ -56,38 +54,11 @@ char *get_process_name_by_pid(const int pid) {
|
||||
char path[1024];
|
||||
sprintf(path, "/proc/%d/exe", pid);
|
||||
|
||||
size_t size = 128;
|
||||
char *name = malloc(size);
|
||||
char *name = realpath(path, NULL);
|
||||
if (name == NULL) {
|
||||
fprintf(stderr, "Could not get process name by pid %d", pid);
|
||||
perror("");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
ssize_t len = readlink(path, name, size);
|
||||
|
||||
if (len == -1) {
|
||||
fprintf(stderr, "Could not get process name by pid %d", pid);
|
||||
perror("");
|
||||
free(name);
|
||||
return NULL;
|
||||
}
|
||||
if ((size_t)len >= size) {
|
||||
size *= 2;
|
||||
char *new_name = realloc(name, size);
|
||||
if (!new_name) {
|
||||
free(name);
|
||||
return NULL;
|
||||
}
|
||||
name = new_name;
|
||||
} else {
|
||||
// readlink does not set the null character
|
||||
name[len] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -254,8 +254,6 @@ access_t check_temp_access(const char *filename, struct process_info pi) {
|
||||
*/
|
||||
int set_temp_access(const char *filename, struct process_info pi,
|
||||
set_mode_t mode) {
|
||||
if (pi.PID == 0)
|
||||
return NDEF;
|
||||
pthread_rwlock_wrlock(&temp_permissions_table_lock);
|
||||
struct temp_process_permissions *permission_entry =
|
||||
get(&temp_permissions_table, pi.PID);
|
||||
|
@ -30,8 +30,6 @@
|
||||
#define DIALOGUE_NO 1
|
||||
#define DIALOGUE_PERM 2
|
||||
|
||||
pthread_mutex_t access_check_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
struct dialogue_response {
|
||||
access_t decision;
|
||||
char *filename;
|
||||
@ -129,7 +127,6 @@ struct dialogue_response ask_access(const char *filename,
|
||||
}
|
||||
|
||||
int dialogue_exit_code = WEXITSTATUS(pclose(fp));
|
||||
|
||||
fprintf(stderr, "dialogue wrote out %s\n", first(&dialogue_output));
|
||||
fprintf(stderr, "dialogue returned %d\n", dialogue_exit_code);
|
||||
|
||||
@ -175,7 +172,6 @@ struct dialogue_response ask_access(const char *filename,
|
||||
int interactive_access(const char *filename, struct process_info proc_info,
|
||||
int opts) {
|
||||
char *real_path = real_filename(filename);
|
||||
pthread_mutex_lock(&access_check_mutex);
|
||||
|
||||
access_t access = check_temp_access(real_path, proc_info);
|
||||
if (access == ALLOW) {
|
||||
@ -184,7 +180,6 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
||||
"permission table.\n",
|
||||
proc_info.name);
|
||||
free(real_path);
|
||||
pthread_mutex_unlock(&access_check_mutex);
|
||||
return 1;
|
||||
}
|
||||
if (access == DENY) {
|
||||
@ -193,7 +188,6 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
||||
"permission table.\n",
|
||||
proc_info.name);
|
||||
free(real_path);
|
||||
pthread_mutex_unlock(&access_check_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -204,7 +198,6 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
||||
"permission table.\n",
|
||||
proc_info.name);
|
||||
free(real_path);
|
||||
pthread_mutex_unlock(&access_check_mutex);
|
||||
return 1;
|
||||
}
|
||||
if (access == DENY) {
|
||||
@ -213,7 +206,6 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
||||
"permission table.\n",
|
||||
proc_info.name);
|
||||
free(real_path);
|
||||
pthread_mutex_unlock(&access_check_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -224,14 +216,12 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
||||
fprintf(stderr, "Permission granted permanently to %s.\n", proc_info.name);
|
||||
set_perm_access(real_path, proc_info, SET_ALLOW);
|
||||
free(real_path);
|
||||
pthread_mutex_unlock(&access_check_mutex);
|
||||
return 1;
|
||||
}
|
||||
if (opts & GRANT_TEMP) {
|
||||
fprintf(stderr, "Permission granted temporarily to %s.\n", proc_info.name);
|
||||
set_temp_access(real_path, proc_info, SET_ALLOW);
|
||||
free(real_path);
|
||||
pthread_mutex_unlock(&access_check_mutex);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -255,36 +245,43 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
||||
real_path = real_filename(response.filename);
|
||||
free(response.filename);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (response.decision == ALLOW) {
|
||||
fprintf(stderr,
|
||||
"Permission granted permanently to %s based on zenty response.\n",
|
||||
proc_info.name);
|
||||
set_perm_access(real_path, proc_info, SET_ALLOW);
|
||||
ret = 1;
|
||||
} else if (response.decision == ALLOW_TEMP) {
|
||||
free(real_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (response.decision == ALLOW_TEMP) {
|
||||
fprintf(stderr,
|
||||
"Permission granted temporarily to %s based on zenty response.\n",
|
||||
proc_info.name);
|
||||
set_temp_access(real_path, proc_info, SET_ALLOW);
|
||||
ret = 1;
|
||||
} else if (response.decision == DENY_TEMP) {
|
||||
free(real_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (response.decision == DENY_TEMP) {
|
||||
fprintf(stderr,
|
||||
"Permission denied temporarily to %s based on zenty response.\n",
|
||||
proc_info.name);
|
||||
set_temp_access(real_path, proc_info, SET_DENY);
|
||||
ret = 0;
|
||||
} else if (response.decision == DENY) {
|
||||
free(real_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (response.decision == DENY) {
|
||||
fprintf(stderr,
|
||||
"Permission denied permanently to %s based on zenty response.\n",
|
||||
proc_info.name);
|
||||
set_perm_access(real_path, proc_info, SET_DENY);
|
||||
ret = 0;
|
||||
free(real_path);
|
||||
return 0;
|
||||
}
|
||||
pthread_mutex_unlock(&access_check_mutex);
|
||||
|
||||
free(real_path);
|
||||
// deny on unknown options.
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user