Compare commits

..

No commits in common. "8cb7721e392b1673ad0c5aef37a44a42f63ccfa0" and "5452c3d1d7ecc810eaac7a66184e34324dfa84f8" have entirely different histories.

4 changed files with 826 additions and 4004 deletions

3719
src/cc.h

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@
#include "sourcefs.h"
#include "ui-socket.h"
char *get_process_name_by_pid(const int pid) {
const char *get_process_name_by_pid(const int pid) {
char path[1024];
sprintf(path, "/proc/%d/exe", pid);

View File

@ -12,7 +12,7 @@
#include <sys/types.h>
struct process_info {
pid_t PID;
char *name;
const char *name;
};
#endif // PROCESS_INFO_H

View File

@ -11,7 +11,6 @@
#include <sys/types.h>
#include <time.h>
#define _GNU_SOURCE
#include "cc.h"
#include "perm_permissions_table.h"
#include "real_filename.h"
#include "temp_permissions_table.h"
@ -24,9 +23,7 @@
#include <sys/un.h>
#include <unistd.h>
#define ZENITY_YES 0
#define ZENITY_NO 1
#define ZENITY_PERM 2
#define ZENITY_TEMP_ALLOW_MESSAGE "Allow this time\n"
int init_ui_socket(const char *perm_permissions_db_filename) {
FILE *fp = NULL;
@ -69,8 +66,12 @@ void destroy_ui_socket(void) {
access_t ask_access(const char *filename, struct process_info proc_info) {
FILE *fp = NULL;
char *command = NULL;
int ret = asprintf(&command, "zenity \"%d\" \"%s\" \"%s\" \"%s\"",
proc_info.PID, proc_info.name, filename, get_mountpoint());
int ret =
asprintf(&command,
"zenity --question --extra-button \"Allow this time\" --title "
"\"Allow Access?\" --text \"Allow process "
"<tt>%s</tt> with PID <tt>%d</tt> to access <tt>%s</tt>\"",
proc_info.name, proc_info.PID, filename, get_mountpoint());
if (ret < 0) {
// If asprintf fails, the contents of command are undefined (see man
@ -91,30 +92,24 @@ access_t ask_access(const char *filename, struct process_info proc_info) {
return DENY;
}
str(char) zenity_output;
init(&zenity_output);
size_t total_read = 0;
char line[1024]; // Buffer to read individual lines
// Read the command output line by line
while (fgets(line, sizeof(line), fp)) {
size_t line_len = strlen(line);
push_fmt(&zenity_output, line);
// if the user clicks the "Allow this time" button, `zenity` will only
// write it to `stdout`, but the exit code will still be `1`. So, we need
// to manually check the output.
char buffer[sizeof(ZENITY_TEMP_ALLOW_MESSAGE) + 1];
while (fgets(buffer, sizeof(buffer), fp)) {
printf("%s", buffer);
if (strcmp(buffer, ZENITY_TEMP_ALLOW_MESSAGE) == 0) {
pclose(fp);
return ALLOW_TEMP;
}
}
int zenity_exit_code = WEXITSTATUS(pclose(fp));
fprintf(stderr, "zenity wrote out %s\n", first(&zenity_output));
fprintf(stderr, "zenity returned %d\n", zenity_exit_code);
cleanup(&zenity_output);
if (zenity_exit_code == (ZENITY_YES | ZENITY_PERM)) {
// zenity returns 1 on "No" >:(
if (zenity_exit_code == 0) {
return ALLOW;
}
if (zenity_exit_code == ZENITY_YES) {
return ALLOW_TEMP;
}
return DENY;
}