Compare commits
	
		
			3 Commits
		
	
	
		
			57091bf0ce
			...
			creation_p
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					40ca81d744 | ||
| 
						 | 
					d4e86c8620 | ||
| 
						 | 
					845c264989 | 
@@ -36,7 +36,6 @@
 | 
			
		||||
#include <sys/file.h> /* flock(2) */
 | 
			
		||||
 | 
			
		||||
#include "fuse_operations.h"
 | 
			
		||||
#include "perm_permissions_table.h"
 | 
			
		||||
#include "sourcefs.h"
 | 
			
		||||
#include "ui-socket.h"
 | 
			
		||||
 | 
			
		||||
@@ -117,12 +116,11 @@ static int xmp_access(const char *path, int mask) {
 | 
			
		||||
    struct fuse_context *fc = fuse_get_context();
 | 
			
		||||
 | 
			
		||||
    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 (!interactive_access(real_filename(path), pi)) {
 | 
			
		||||
    if (!interactive_access(real_filename(path), pi, 0)) {
 | 
			
		||||
      free(pi.name);
 | 
			
		||||
      return -EACCES;
 | 
			
		||||
    }
 | 
			
		||||
@@ -282,12 +280,11 @@ static int xmp_unlink(const char *path) {
 | 
			
		||||
 | 
			
		||||
  // 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 (!interactive_access(real_filename(path), pi)) {
 | 
			
		||||
  if (!interactive_access(real_filename(path), pi, 0)) {
 | 
			
		||||
    free(pi.name);
 | 
			
		||||
    return -EACCES;
 | 
			
		||||
  }
 | 
			
		||||
@@ -331,12 +328,11 @@ static int xmp_rename(const char *from, const char *to, unsigned int flags) {
 | 
			
		||||
  struct fuse_context *fc = fuse_get_context();
 | 
			
		||||
 | 
			
		||||
  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 (!interactive_access(real_filename(from), pi)) {
 | 
			
		||||
  if (!interactive_access(real_filename(from), pi, 0)) {
 | 
			
		||||
    free(pi.name);
 | 
			
		||||
    return -EACCES;
 | 
			
		||||
  }
 | 
			
		||||
@@ -344,7 +340,7 @@ static int xmp_rename(const char *from, const char *to, unsigned int flags) {
 | 
			
		||||
  // the "to" file may exist and the process needs to get persmission to modify
 | 
			
		||||
  // it
 | 
			
		||||
  if (source_access(to, F_OK) == 0 &&
 | 
			
		||||
      !interactive_access(real_filename(to), pi)) {
 | 
			
		||||
      !interactive_access(real_filename(to), pi, 0)) {
 | 
			
		||||
    free(pi.name);
 | 
			
		||||
    return -EACCES;
 | 
			
		||||
  }
 | 
			
		||||
@@ -364,11 +360,10 @@ static int xmp_link(const char *from, const char *to) {
 | 
			
		||||
  struct fuse_context *fc = fuse_get_context();
 | 
			
		||||
 | 
			
		||||
  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 (!interactive_access(real_filename(from), pi)) {
 | 
			
		||||
  if (!interactive_access(real_filename(from), pi, 0)) {
 | 
			
		||||
    free(pi.name);
 | 
			
		||||
    return -EACCES;
 | 
			
		||||
  }
 | 
			
		||||
@@ -390,11 +385,10 @@ static int xmp_chmod(const char *path, mode_t mode, struct fuse_file_info *fi) {
 | 
			
		||||
  struct fuse_context *fc = fuse_get_context();
 | 
			
		||||
 | 
			
		||||
  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 (!interactive_access(real_filename(path), pi)) {
 | 
			
		||||
  if (!interactive_access(real_filename(path), pi, 0)) {
 | 
			
		||||
    free(pi.name);
 | 
			
		||||
    return -EACCES;
 | 
			
		||||
  }
 | 
			
		||||
@@ -422,11 +416,10 @@ static int xmp_chown(const char *path, uid_t uid, gid_t gid,
 | 
			
		||||
  struct fuse_context *fc = fuse_get_context();
 | 
			
		||||
 | 
			
		||||
  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 (!interactive_access(real_filename(path), pi)) {
 | 
			
		||||
  if (!interactive_access(real_filename(path), pi, 0)) {
 | 
			
		||||
    free(pi.name);
 | 
			
		||||
    return -EACCES;
 | 
			
		||||
  }
 | 
			
		||||
@@ -482,19 +475,14 @@ static int xmp_create(const char *path, mode_t mode,
 | 
			
		||||
  struct fuse_context *fc = fuse_get_context();
 | 
			
		||||
 | 
			
		||||
  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 (!interactive_access(real_filename(path), pi)) {
 | 
			
		||||
  if (!interactive_access(real_filename(path), pi, GRANT_PERM)) {
 | 
			
		||||
    free(pi.name);
 | 
			
		||||
    return -EACCES;
 | 
			
		||||
  }
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
  give_perm_access(real_filename(path), pi);
 | 
			
		||||
 | 
			
		||||
  free(pi.name);
 | 
			
		||||
 | 
			
		||||
@@ -512,11 +500,10 @@ static int xmp_open(const char *path, struct fuse_file_info *fi) {
 | 
			
		||||
  struct fuse_context *fc = fuse_get_context();
 | 
			
		||||
 | 
			
		||||
  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 (!interactive_access(real_filename(path), pi)) {
 | 
			
		||||
  if (!interactive_access(real_filename(path), pi, 0)) {
 | 
			
		||||
    free(pi.name);
 | 
			
		||||
    return -EACCES;
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,6 @@
 | 
			
		||||
struct process_info {
 | 
			
		||||
  pid_t PID;
 | 
			
		||||
  const char *name;
 | 
			
		||||
  uid_t UID;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // PROCESS_INFO_H
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,6 @@
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#define _GNU_SOURCE
 | 
			
		||||
#include "cc.h"
 | 
			
		||||
#include "perm_permissions_table.h"
 | 
			
		||||
#include "temp_permissions_table.h"
 | 
			
		||||
#include "ui-socket.h"
 | 
			
		||||
@@ -61,9 +60,9 @@ void destroy_ui_socket() {
 | 
			
		||||
 * 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
 | 
			
		||||
 * for the runtime of the process
 | 
			
		||||
 * @param pi: The process information
 | 
			
		||||
 * @return: 0 if access is denied, 1 if access is allowed, 2 if access is
 | 
			
		||||
 * allowed for the runtime of the process
 | 
			
		||||
 */
 | 
			
		||||
int ask_access(const char *filename, struct process_info pi) {
 | 
			
		||||
  FILE *fp;
 | 
			
		||||
@@ -115,15 +114,28 @@ int ask_access(const char *filename, struct process_info pi) {
 | 
			
		||||
 *
 | 
			
		||||
 * @param filename: The file that the process is trying to access
 | 
			
		||||
 * @pram pi: The process information
 | 
			
		||||
 * @param opts: options (GRANT_TEMP, GRANT_PERM)
 | 
			
		||||
 * @return: 0 if access is denied, 1 if access is allowed
 | 
			
		||||
 */
 | 
			
		||||
int interactive_access(const char *filename, struct process_info pi) {
 | 
			
		||||
int interactive_access(const char *filename, struct process_info pi, int opts) {
 | 
			
		||||
 | 
			
		||||
  if (check_temp_access(filename, pi) || check_perm_access(filename, pi)) {
 | 
			
		||||
    // access was already granted before
 | 
			
		||||
    return 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // if noth GRANT_TEMP and GRANT_PERM are selected, then only permanent
 | 
			
		||||
  // permissions are granted
 | 
			
		||||
 | 
			
		||||
  if (opts & GRANT_PERM) {
 | 
			
		||||
    give_perm_access(filename, pi);
 | 
			
		||||
    return 1;
 | 
			
		||||
  }
 | 
			
		||||
  if (opts & GRANT_TEMP) {
 | 
			
		||||
    give_temp_access(filename, pi);
 | 
			
		||||
    return 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int user_response = ask_access(filename, pi);
 | 
			
		||||
  if (user_response == 1) {
 | 
			
		||||
    // user said "yes"
 | 
			
		||||
 
 | 
			
		||||
@@ -36,8 +36,13 @@ void destroy_ui_socket(void);
 | 
			
		||||
 *
 | 
			
		||||
 * @param filename: The file that the process is trying to access
 | 
			
		||||
 * @pram pi: The process information
 | 
			
		||||
 * @param opts: options (GRANT_TEMP, GRANT_PERM)
 | 
			
		||||
 * @return: 0 if access is denied, 1 if access is allowed
 | 
			
		||||
 */
 | 
			
		||||
int interactive_access(const char *filename, struct process_info pi);
 | 
			
		||||
int interactive_access(const char *filename, struct process_info pi, int opts);
 | 
			
		||||
 | 
			
		||||
#define GRANT_TEMP 1
 | 
			
		||||
#define GRANT_PERM 2
 | 
			
		||||
// #define TABLE_ONLY 4 // NOTE: Add this in the future?
 | 
			
		||||
 | 
			
		||||
#endif // !UI_SOCKET_H
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user