diff --git a/src/fuse_operations.c b/src/fuse_operations.c index ace3af1..5e56661 100644 --- a/src/fuse_operations.c +++ b/src/fuse_operations.c @@ -264,7 +264,7 @@ static int xmp_unlink(const char *path) { // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); - if (ask_access(real_filename(path), pi)) { + if (interactive_access(real_filename(path), pi)) { free(pi.name); return -EACCES; } @@ -392,7 +392,7 @@ static int xmp_create(const char *path, mode_t mode, // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); - if (ask_access(real_filename(path), pi)) { + if (interactive_access(real_filename(path), pi)) { free(pi.name); return -EACCES; } @@ -417,7 +417,7 @@ static int xmp_open(const char *path, struct fuse_file_info *fi) { pi.name = get_process_name_by_pid(pi.PID); // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); - if (ask_access(real_filename(path), pi)) { + if (interactive_access(real_filename(path), pi)) { free(pi.name); return -EACCES; } diff --git a/src/ui-socket.c b/src/ui-socket.c index ac1b9d4..157ad96 100644 --- a/src/ui-socket.c +++ b/src/ui-socket.c @@ -37,6 +37,9 @@ int init_ui_socket(const char *filename) { } /** + * Asks the user if the process should be allowed to access the file using the + * GUI + * * @param filename: The file that the process is trying to access * @pram pi: The process information * @return: 0 if access is denied, 1 if access is allowed, 2 if access is allwed @@ -77,3 +80,66 @@ int ask_access(const char *filename, struct process_info pi) { int zenity_exit_code = WEXITSTATUS(pclose(fp)); return zenity_exit_code; } + +/** + * Checks if the process has a temporary access to the file. + * + * @param filename: The file that the process is trying to access + * @pram pi: The process information + * @return: 0 if access is denied, 1 if access is allowed + */ +int check_temp_access(const char *filename, struct process_info pi) { + perror("Not implemented"); + return 0; +} + +/** + * Checks if the process has a permanent access to the file. + * + * @param filename: The file that the process is trying to access + * @pram pi: The process information + * @return: 0 if access is denied, 1 if access is allowed + */ +int check_perm_access(const char *filename, struct process_info pi) { + perror("Not implemented"); + return 0; +} + +void give_temp_access(const char *filename, struct process_info pi) { + perror("Not implemented"); +} +void give_perm_access(const char *filename, struct process_info pi) { + perror("Not implemented"); +} + +/** + * Check access according to: + * 1. temp permission table + * 2. permanent permission table + * 3. user descision + * + * @param filename: The file that the process is trying to access + * @pram pi: The process information + * @return: 0 if access is denied, 1 if access is allowed + */ +int interactive_access(const char *filename, struct process_info pi) { + + if (check_temp_access(filename, pi) || check_perm_access(filename, pi)) { + // access was already granted before + return 1; + } + + int user_response = ask_access(filename, pi); + if (user_response == 1) { + // user said "yes" + give_perm_access(filename, pi); + return 1; + } else if (user_response == 2) { + // user said "yes, but only this time" + give_temp_access(filename, pi); + return 1; + } + + // otherwise "no" + return 0; +} diff --git a/src/ui-socket.h b/src/ui-socket.h index c199668..399bc7d 100644 --- a/src/ui-socket.h +++ b/src/ui-socket.h @@ -24,6 +24,6 @@ struct process_info { // For default socket location, set socket_path = NULL. int init_ui_socket(const char *socket_path); -int ask_access(const char *filename, struct process_info pi); +int interactive_access(const char *filename, struct process_info pi); #endif // !UI_SOCKET_H