From d7c20a5d5f38247f95d8af782885b3a490147641 Mon Sep 17 00:00:00 2001
From: BritishTeapot <f.kovalyoff@gmail.com>
Date: Mon, 10 Mar 2025 18:09:05 +0100
Subject: [PATCH] Added proper license headers

---
 src/fuse_operations.c | 88 +++++++++++++++++++++----------------------
 src/fuse_operations.h |  8 ++++
 src/main.c            | 27 +++----------
 src/sourcefs.c        |  8 ++++
 src/sourcefs.h        |  6 +++
 src/ui-socket.c       |  8 ++++
 src/ui-socket.h       |  7 ++++
 7 files changed, 86 insertions(+), 66 deletions(-)

diff --git a/src/fuse_operations.c b/src/fuse_operations.c
index 4ba892b..ace3af1 100644
--- a/src/fuse_operations.c
+++ b/src/fuse_operations.c
@@ -1,28 +1,15 @@
+
 /*
   FUSE: Filesystem in Userspace
   Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
   Copyright (C) 2011       Sebastian Pipping <sebastian@pipping.org>
 
-  This program can be distributed under the terms of the GNU GPLv2.
-  See the file COPYING.
-*/
+  ICFS: Interactively Controlled File System
+  Copyright (C) 2024-2025  Fedir Kovalov
 
-/** @file
- *
- * This file system mirrors the existing file system hierarchy of the
- * system, starting at the root file system. This is implemented by
- * just "passing through" all requests to the corresponding user-space
- * libc functions. This implementation is a little more sophisticated
- * than the one in passthrough.c, so performance is not quite as bad.
- *
- * Compile with:
- *
- *     gcc -Wall passthrough_fh.c `pkg-config fuse3 --cflags --libs` -lulockmgr
- * -o passthrough_fh
- *
- * ## Source code ##
- * \include passthrough_fh.c
- */
+  This program can be distributed under the terms of the GNU GPLv2.
+  See the file LICENSE.
+*/
 
 #define FUSE_USE_VERSION 31
 
@@ -52,6 +39,28 @@
 #include "sourcefs.h"
 #include "ui-socket.h"
 
+// TODO: move this to other file
+const char *get_process_name_by_pid(const int pid) {
+  char *name = (char *)calloc(1024, sizeof(char));
+  if (name) {
+    sprintf(name, "/proc/%d/cmdline", pid);
+    FILE *f = fopen(name, "r");
+    if (f) {
+      size_t size;
+      size = fread(name, sizeof(char), 1024, f);
+      if (size > 0) {
+        if ('\n' == name[size - 1])
+          name[size - 1] = '\0';
+      }
+      fclose(f);
+    }
+  }
+  return name;
+}
+
+// TODO: move this somewhere else
+const char *real_filename(const char *filename) { return filename; }
+
 static void *xmp_init(struct fuse_conn_info *conn, struct fuse_config *cfg) {
   (void)conn;
   cfg->use_ino = 1;
@@ -245,6 +254,21 @@ static int xmp_mkdir(const char *path, mode_t mode) {
 
 static int xmp_unlink(const char *path) {
   int res;
+  struct process_info pi;
+  struct fuse_context *fc = fuse_get_context();
+
+  // ask the user for the permission for deleting the file
+  pi.PID = fc->pid;
+  pi.UID = fc->uid;
+  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)) {
+    free(pi.name);
+    return -EACCES;
+  }
+  free(pi.name);
 
   res = source_unlink(path);
   if (res == -1)
@@ -356,34 +380,10 @@ static int xmp_utimens(const char *path, const struct timespec ts[2],
 }
 #endif
 
-// TODO: move this to other file
-const char *get_process_name_by_pid(const int pid) {
-  char *name = (char *)calloc(1024, sizeof(char));
-  if (name) {
-    sprintf(name, "/proc/%d/cmdline", pid);
-    FILE *f = fopen(name, "r");
-    if (f) {
-      size_t size;
-      size = fread(name, sizeof(char), 1024, f);
-      if (size > 0) {
-        if ('\n' == name[size - 1])
-          name[size - 1] = '\0';
-      }
-      fclose(f);
-    }
-  }
-  return name;
-}
-
-// TODO: move this somewhere else
-const char *real_filename(const char *filename) { return filename; }
-
 static int xmp_create(const char *path, mode_t mode,
                       struct fuse_file_info *fi) {
   int fd;
-
   struct process_info pi;
-
   struct fuse_context *fc = fuse_get_context();
 
   pi.PID = fc->pid;
@@ -409,9 +409,7 @@ static int xmp_create(const char *path, mode_t mode,
 
 static int xmp_open(const char *path, struct fuse_file_info *fi) {
   int fd;
-
   struct process_info pi;
-
   struct fuse_context *fc = fuse_get_context();
 
   pi.PID = fc->pid;
diff --git a/src/fuse_operations.h b/src/fuse_operations.h
index 8d1fec5..6413586 100644
--- a/src/fuse_operations.h
+++ b/src/fuse_operations.h
@@ -1,3 +1,11 @@
+/*
+  ICFS: Interactively Controlled File System
+  Copyright (C) 2024-2025  Fedir Kovalov
+
+  This program can be distributed under the terms of the GNU GPLv2.
+  See the file LICENSE.
+*/
+
 #ifndef FUSE_OPERATIONS
 #define FUSE_OPERATIONS
 
diff --git a/src/main.c b/src/main.c
index b9a9afb..4bc5faa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,26 +3,12 @@
   Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
   Copyright (C) 2011       Sebastian Pipping <sebastian@pipping.org>
 
-  This program can be distributed under the terms of the GNU GPLv2.
-  See the file COPYING.
-*/
+  ICFS: Interactively Controlled File System
+  Copyright (C) 2024-2025  Fedir Kovalov
 
-/** @file
- *
- * This file system mirrors the existing file system hierarchy of the
- * system, starting at the root file system. This is implemented by
- * just "passing through" all requests to the corresponding user-space
- * libc functions. This implementation is a little more sophisticated
- * than the one in passthrough.c, so performance is not quite as bad.
- *
- * Compile with:
- *
- *     gcc -Wall passthrough_fh.c `pkg-config fuse3 --cflags --libs` -lulockmgr
- * -o passthrough_fh
- *
- * ## Source code ##
- * \include passthrough_fh.c
- */
+  This program can be distributed under the terms of the GNU GPLv2.
+  See the file LICENSE.
+*/
 
 #define FUSE_USE_VERSION 31
 
@@ -42,8 +28,6 @@ const char *mountpoint = NULL;
 int main(int argc, char *argv[]) {
   umask(0);
 
-  // FUSE won't tell us the mountpoint on it's own, so we need to extract it
-  // ourselves.
   mountpoint = realpath(argv[argc - 1], NULL);
 
   int ret = source_init(mountpoint);
@@ -59,6 +43,7 @@ int main(int argc, char *argv[]) {
   }
 
   ret = fuse_main(argc, argv, get_fuse_operations(), NULL);
+
   free(mountpoint);
   return ret;
 }
diff --git a/src/sourcefs.c b/src/sourcefs.c
index b34fa8b..35dce28 100644
--- a/src/sourcefs.c
+++ b/src/sourcefs.c
@@ -1,3 +1,11 @@
+/*
+  ICFS: Interactively Controlled File System
+  Copyright (C) 2024-2025  Fedir Kovalov
+
+  This program can be distributed under the terms of the GNU GPLv2.
+  See the file LICENSE.
+*/
+
 #define _GNU_SOURCE
 
 #include "sourcefs.h"
diff --git a/src/sourcefs.h b/src/sourcefs.h
index 0f30551..cd2dd4a 100644
--- a/src/sourcefs.h
+++ b/src/sourcefs.h
@@ -1,4 +1,10 @@
+/*
+  ICFS: Interactively Controlled File System
+  Copyright (C) 2024-2025  Fedir Kovalov
 
+  This program can be distributed under the terms of the GNU GPLv2.
+  See the file LICENSE.
+*/
 
 #ifndef SOURCEFS_H
 #define SOURCEFS_H
diff --git a/src/ui-socket.c b/src/ui-socket.c
index 3f1c6dc..ac1b9d4 100644
--- a/src/ui-socket.c
+++ b/src/ui-socket.c
@@ -1,3 +1,11 @@
+/*
+  ICFS: Interactively Controlled File System
+  Copyright (C) 2024-2025  Fedir Kovalov
+
+  This program can be distributed under the terms of the GNU GPLv2.
+  See the file LICENSE.
+*/
+
 #include <stddef.h>
 #include <sys/types.h>
 #define _GNU_SOURCE
diff --git a/src/ui-socket.h b/src/ui-socket.h
index 3bb8e92..c199668 100644
--- a/src/ui-socket.h
+++ b/src/ui-socket.h
@@ -1,3 +1,10 @@
+/*
+  ICFS: Interactively Controlled File System
+  Copyright (C) 2024-2025  Fedir Kovalov
+
+  This program can be distributed under the terms of the GNU GPLv2.
+  See the file LICENSE.
+*/
 
 /*
  * Interface for controlling communication with the UI.