Compare commits

...

2 Commits

Author SHA1 Message Date
c8f19fe30d
Fixed invalid pi bug 2025-05-13 17:59:32 +02:00
4febeb7a82
Added a logfile 2025-05-13 17:59:00 +02:00
4 changed files with 27 additions and 15 deletions

View File

@ -11,6 +11,7 @@
See the file LICENSE. See the file LICENSE.
*/ */
#include "process_info.h"
#include "real_filename.h" #include "real_filename.h"
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
@ -267,8 +268,7 @@ static int xmp_unlink(const char *path) {
struct fuse_context *fc = fuse_get_context(); struct fuse_context *fc = fuse_get_context();
// ask the user for the permission for deleting the file // ask the user for the permission for deleting the file
pi.PID = fc->pid; pi = get_process_info(fc->pid);
pi.name = get_process_name_by_pid(pi.PID);
// fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
@ -315,8 +315,7 @@ static int xmp_rename(const char *from, const char *to, unsigned int flags) {
struct process_info pi; struct process_info pi;
struct fuse_context *fc = fuse_get_context(); struct fuse_context *fc = fuse_get_context();
pi.PID = fc->pid; pi = get_process_info(fc->pid);
pi.name = get_process_name_by_pid(pi.PID);
// fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
@ -346,8 +345,7 @@ static int xmp_link(const char *from, const char *to) {
struct process_info pi; struct process_info pi;
struct fuse_context *fc = fuse_get_context(); struct fuse_context *fc = fuse_get_context();
pi.PID = fc->pid; pi = get_process_info(fc->pid);
pi.name = get_process_name_by_pid(pi.PID);
// fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
if (!interactive_access(from, pi, 0)) { if (!interactive_access(from, pi, 0)) {
@ -371,8 +369,7 @@ static int xmp_chmod(const char *path, mode_t mode, struct fuse_file_info *fi) {
struct process_info pi; struct process_info pi;
struct fuse_context *fc = fuse_get_context(); struct fuse_context *fc = fuse_get_context();
pi.PID = fc->pid; pi = get_process_info(fc->pid);
pi.name = get_process_name_by_pid(pi.PID);
// fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
if (!interactive_access(path, pi, 0)) { if (!interactive_access(path, pi, 0)) {
@ -402,8 +399,7 @@ static int xmp_chown(const char *path, uid_t uid, gid_t gid,
struct process_info pi; struct process_info pi;
struct fuse_context *fc = fuse_get_context(); struct fuse_context *fc = fuse_get_context();
pi.PID = fc->pid; pi = get_process_info(fc->pid);
pi.name = get_process_name_by_pid(pi.PID);
// fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
if (!interactive_access(path, pi, 0)) { if (!interactive_access(path, pi, 0)) {
@ -461,8 +457,7 @@ static int xmp_create(const char *path, mode_t mode,
struct process_info pi; struct process_info pi;
struct fuse_context *fc = fuse_get_context(); struct fuse_context *fc = fuse_get_context();
pi.PID = fc->pid; pi = get_process_info(fc->pid);
pi.name = get_process_name_by_pid(pi.PID);
// fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
@ -486,8 +481,7 @@ static int xmp_open(const char *path, struct fuse_file_info *fi) {
struct process_info pi; struct process_info pi;
struct fuse_context *fc = fuse_get_context(); struct fuse_context *fc = fuse_get_context();
pi.PID = fc->pid; pi = get_process_info(fc->pid);
pi.name = get_process_name_by_pid(pi.PID);
// fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi));
if (!interactive_access(path, pi, 0)) { if (!interactive_access(path, pi, 0)) {

View File

@ -258,7 +258,7 @@ access_t check_perm_access_noparent(const char *filename,
* false negatives, though. * false negatives, though.
*/ */
access_t check_perm_access(const char *filename, struct process_info pi) { access_t check_perm_access(const char *filename, struct process_info pi) {
if (pi.PID == 0) { if (pi.PID == 0 || pi.name == NULL) {
return NDEF; return NDEF;
} }

View File

@ -9,10 +9,21 @@
#ifndef PROCESS_INFO_H #ifndef PROCESS_INFO_H
#define PROCESS_INFO_H #define PROCESS_INFO_H
#include "proc_operations.h"
#include <sys/types.h> #include <sys/types.h>
struct process_info { struct process_info {
pid_t PID; pid_t PID;
char *name; char *name;
}; };
static inline struct process_info get_process_info(pid_t pid) {
struct process_info pi;
pi.PID = pid;
pi.name = get_process_name_by_pid(pi.PID);
if (pi.name == NULL) {
pi.PID = 0;
}
return pi;
}
#endif // PROCESS_INFO_H #endif // PROCESS_INFO_H

View File

@ -35,9 +35,13 @@ struct dialogue_response {
char *filename; char *filename;
}; };
FILE *access_log;
int init_ui_socket(const char *perm_permissions_db_filename) { int init_ui_socket(const char *perm_permissions_db_filename) {
FILE *fp = NULL; FILE *fp = NULL;
access_log = fopen("/etc/icfs-log", "a+");
if (init_temp_permissions_table()) { if (init_temp_permissions_table()) {
fprintf(stderr, "Could not initialize temporary permissions table.\n"); fprintf(stderr, "Could not initialize temporary permissions table.\n");
return 1; return 1;
@ -60,6 +64,7 @@ int init_ui_socket(const char *perm_permissions_db_filename) {
} }
void destroy_ui_socket(void) { void destroy_ui_socket(void) {
fclose(access_log);
destroy_temp_permissions_table(); destroy_temp_permissions_table();
destroy_perm_permissions_table(); destroy_perm_permissions_table();
} }
@ -137,6 +142,8 @@ struct dialogue_response ask_access(const char *filename,
// assert(0 == strcmp(response.filename, first(&dialogue_output))); // assert(0 == strcmp(response.filename, first(&dialogue_output)));
cleanup(&dialogue_output); cleanup(&dialogue_output);
time_t now = time(0);
fprintf(access_log, "%ld\n", now);
if (dialogue_exit_code == (DIALOGUE_YES | DIALOGUE_PERM)) { if (dialogue_exit_code == (DIALOGUE_YES | DIALOGUE_PERM)) {
response.decision = ALLOW; response.decision = ALLOW;