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,
|
access_t check_perm_access_noparent(const char *filename,
|
||||||
struct process_info pi) {
|
struct process_info pi) {
|
||||||
if (pi.name == NULL)
|
|
||||||
return NDEF;
|
|
||||||
|
|
||||||
access_t ret = NDEF;
|
access_t ret = NDEF;
|
||||||
sqlite3_stmt *stmt = NULL;
|
sqlite3_stmt *stmt = NULL;
|
||||||
const char *sql = "SELECT mode FROM permissions WHERE executable = ?1 "
|
const char *sql = "SELECT mode FROM permissions WHERE executable = ?1 "
|
||||||
|
@ -8,10 +8,8 @@
|
|||||||
|
|
||||||
#include "proc_operations.h"
|
#include "proc_operations.h"
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the PID of the main thread (i.e., the process ID) of the
|
* @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];
|
char path[1024];
|
||||||
sprintf(path, "/proc/%d/exe", pid);
|
sprintf(path, "/proc/%d/exe", pid);
|
||||||
|
|
||||||
size_t size = 128;
|
char *name = realpath(path, NULL);
|
||||||
char *name = malloc(size);
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
fprintf(stderr, "Could not get process name by pid %d", pid);
|
fprintf(stderr, "Could not get process name by pid %d", pid);
|
||||||
perror("");
|
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;
|
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,
|
int set_temp_access(const char *filename, struct process_info pi,
|
||||||
set_mode_t mode) {
|
set_mode_t mode) {
|
||||||
if (pi.PID == 0)
|
|
||||||
return NDEF;
|
|
||||||
pthread_rwlock_wrlock(&temp_permissions_table_lock);
|
pthread_rwlock_wrlock(&temp_permissions_table_lock);
|
||||||
struct temp_process_permissions *permission_entry =
|
struct temp_process_permissions *permission_entry =
|
||||||
get(&temp_permissions_table, pi.PID);
|
get(&temp_permissions_table, pi.PID);
|
||||||
|
@ -30,8 +30,6 @@
|
|||||||
#define DIALOGUE_NO 1
|
#define DIALOGUE_NO 1
|
||||||
#define DIALOGUE_PERM 2
|
#define DIALOGUE_PERM 2
|
||||||
|
|
||||||
pthread_mutex_t access_check_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
|
|
||||||
struct dialogue_response {
|
struct dialogue_response {
|
||||||
access_t decision;
|
access_t decision;
|
||||||
char *filename;
|
char *filename;
|
||||||
@ -129,7 +127,6 @@ struct dialogue_response ask_access(const char *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int dialogue_exit_code = WEXITSTATUS(pclose(fp));
|
int dialogue_exit_code = WEXITSTATUS(pclose(fp));
|
||||||
|
|
||||||
fprintf(stderr, "dialogue wrote out %s\n", first(&dialogue_output));
|
fprintf(stderr, "dialogue wrote out %s\n", first(&dialogue_output));
|
||||||
fprintf(stderr, "dialogue returned %d\n", dialogue_exit_code);
|
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 interactive_access(const char *filename, struct process_info proc_info,
|
||||||
int opts) {
|
int opts) {
|
||||||
char *real_path = real_filename(filename);
|
char *real_path = real_filename(filename);
|
||||||
pthread_mutex_lock(&access_check_mutex);
|
|
||||||
|
|
||||||
access_t access = check_temp_access(real_path, proc_info);
|
access_t access = check_temp_access(real_path, proc_info);
|
||||||
if (access == ALLOW) {
|
if (access == ALLOW) {
|
||||||
@ -184,7 +180,6 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
|||||||
"permission table.\n",
|
"permission table.\n",
|
||||||
proc_info.name);
|
proc_info.name);
|
||||||
free(real_path);
|
free(real_path);
|
||||||
pthread_mutex_unlock(&access_check_mutex);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (access == DENY) {
|
if (access == DENY) {
|
||||||
@ -193,7 +188,6 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
|||||||
"permission table.\n",
|
"permission table.\n",
|
||||||
proc_info.name);
|
proc_info.name);
|
||||||
free(real_path);
|
free(real_path);
|
||||||
pthread_mutex_unlock(&access_check_mutex);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +198,6 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
|||||||
"permission table.\n",
|
"permission table.\n",
|
||||||
proc_info.name);
|
proc_info.name);
|
||||||
free(real_path);
|
free(real_path);
|
||||||
pthread_mutex_unlock(&access_check_mutex);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (access == DENY) {
|
if (access == DENY) {
|
||||||
@ -213,7 +206,6 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
|||||||
"permission table.\n",
|
"permission table.\n",
|
||||||
proc_info.name);
|
proc_info.name);
|
||||||
free(real_path);
|
free(real_path);
|
||||||
pthread_mutex_unlock(&access_check_mutex);
|
|
||||||
return 0;
|
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);
|
fprintf(stderr, "Permission granted permanently to %s.\n", proc_info.name);
|
||||||
set_perm_access(real_path, proc_info, SET_ALLOW);
|
set_perm_access(real_path, proc_info, SET_ALLOW);
|
||||||
free(real_path);
|
free(real_path);
|
||||||
pthread_mutex_unlock(&access_check_mutex);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (opts & GRANT_TEMP) {
|
if (opts & GRANT_TEMP) {
|
||||||
fprintf(stderr, "Permission granted temporarily to %s.\n", proc_info.name);
|
fprintf(stderr, "Permission granted temporarily to %s.\n", proc_info.name);
|
||||||
set_temp_access(real_path, proc_info, SET_ALLOW);
|
set_temp_access(real_path, proc_info, SET_ALLOW);
|
||||||
free(real_path);
|
free(real_path);
|
||||||
pthread_mutex_unlock(&access_check_mutex);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,36 +245,43 @@ int interactive_access(const char *filename, struct process_info proc_info,
|
|||||||
real_path = real_filename(response.filename);
|
real_path = real_filename(response.filename);
|
||||||
free(response.filename);
|
free(response.filename);
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (response.decision == ALLOW) {
|
if (response.decision == ALLOW) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Permission granted permanently to %s based on zenty response.\n",
|
"Permission granted permanently to %s based on zenty response.\n",
|
||||||
proc_info.name);
|
proc_info.name);
|
||||||
set_perm_access(real_path, proc_info, SET_ALLOW);
|
set_perm_access(real_path, proc_info, SET_ALLOW);
|
||||||
ret = 1;
|
free(real_path);
|
||||||
} else if (response.decision == ALLOW_TEMP) {
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.decision == ALLOW_TEMP) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Permission granted temporarily to %s based on zenty response.\n",
|
"Permission granted temporarily to %s based on zenty response.\n",
|
||||||
proc_info.name);
|
proc_info.name);
|
||||||
set_temp_access(real_path, proc_info, SET_ALLOW);
|
set_temp_access(real_path, proc_info, SET_ALLOW);
|
||||||
ret = 1;
|
free(real_path);
|
||||||
} else if (response.decision == DENY_TEMP) {
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.decision == DENY_TEMP) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Permission denied temporarily to %s based on zenty response.\n",
|
"Permission denied temporarily to %s based on zenty response.\n",
|
||||||
proc_info.name);
|
proc_info.name);
|
||||||
set_temp_access(real_path, proc_info, SET_DENY);
|
set_temp_access(real_path, proc_info, SET_DENY);
|
||||||
ret = 0;
|
free(real_path);
|
||||||
} else if (response.decision == DENY) {
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.decision == DENY) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Permission denied permanently to %s based on zenty response.\n",
|
"Permission denied permanently to %s based on zenty response.\n",
|
||||||
proc_info.name);
|
proc_info.name);
|
||||||
set_perm_access(real_path, proc_info, SET_DENY);
|
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);
|
free(real_path);
|
||||||
// deny on unknown options.
|
// deny on unknown options.
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user