Compare commits
No commits in common. "93588036aa580214313a04828f417c9ca43b4eff" and "1646b2fe3fafa890db6310f2fe7174038f2537d1" have entirely different histories.
93588036aa
...
1646b2fe3f
7
Makefile
7
Makefile
@ -19,10 +19,10 @@ else
|
|||||||
LDFLAGS +=
|
LDFLAGS +=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SOURCES_DIR := ./src
|
SOURCES_DIR := ./sources
|
||||||
BUILD_DIR := ./build
|
BUILD_DIR := ./build
|
||||||
|
|
||||||
build: $(BUILD_DIR)/main.o $(BUILD_DIR)/sourcefs.o $(BUILD_DIR)/ui-socket.o
|
build: $(BUILD_DIR)/main.o $(BUILD_DIR)/sourcefs.o
|
||||||
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $(BUILD_DIR)/icfs
|
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $(BUILD_DIR)/icfs
|
||||||
|
|
||||||
$(BUILD_DIR)/main.o: $(SOURCES_DIR)/main.c
|
$(BUILD_DIR)/main.o: $(SOURCES_DIR)/main.c
|
||||||
@ -31,8 +31,5 @@ $(BUILD_DIR)/main.o: $(SOURCES_DIR)/main.c
|
|||||||
$(BUILD_DIR)/sourcefs.o: $(SOURCES_DIR)/sourcefs.c $(SOURCES_DIR)/sourcefs.h
|
$(BUILD_DIR)/sourcefs.o: $(SOURCES_DIR)/sourcefs.c $(SOURCES_DIR)/sourcefs.h
|
||||||
$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
|
$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
|
||||||
|
|
||||||
$(BUILD_DIR)/ui-socket.o: $(SOURCES_DIR)/ui-socket.c $(SOURCES_DIR)/ui-socket.h
|
|
||||||
$(CC) $(CFLAGS) -c $< $(LDFLAGS) -o $@
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(BUILD_DIR)/*
|
rm $(BUILD_DIR)/*
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
#include <sys/file.h> /* flock(2) */
|
#include <sys/file.h> /* flock(2) */
|
||||||
|
|
||||||
#include "sourcefs.h"
|
#include "sourcefs.h"
|
||||||
#include "ui-socket.h"
|
|
||||||
|
|
||||||
const char *mountpoint = NULL;
|
const char *mountpoint = NULL;
|
||||||
|
|
||||||
@ -357,49 +356,10 @@ static int xmp_utimens(const char *path, const struct timespec ts[2],
|
|||||||
}
|
}
|
||||||
#endif
|
#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,
|
static int xmp_create(const char *path, mode_t mode,
|
||||||
struct fuse_file_info *fi) {
|
struct fuse_file_info *fi) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
struct process_info pi;
|
|
||||||
|
|
||||||
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 (ask_access(real_filename(path), pi)) {
|
|
||||||
free(pi.name);
|
|
||||||
return -EACCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(pi.name);
|
|
||||||
|
|
||||||
fd = source_create(path, fi->flags, mode);
|
fd = source_create(path, fi->flags, mode);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
@ -411,22 +371,6 @@ static int xmp_create(const char *path, mode_t mode,
|
|||||||
static int xmp_open(const char *path, struct fuse_file_info *fi) {
|
static int xmp_open(const char *path, struct fuse_file_info *fi) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
struct process_info pi;
|
|
||||||
|
|
||||||
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 (ask_access(real_filename(path), pi)) {
|
|
||||||
free(pi.name);
|
|
||||||
return -EACCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(pi.name);
|
|
||||||
|
|
||||||
fd = source_open(path, fi->flags);
|
fd = source_open(path, fi->flags);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
@ -719,17 +663,9 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
int ret = source_init(mountpoint);
|
int ret = source_init(mountpoint);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
perror("source_init");
|
perror("Failed to initialize filesystem.");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = init_ui_socket("/home/fedir/.icfs-sock");
|
return fuse_main(argc, argv, &xmp_oper, NULL);
|
||||||
if (ret != 0) {
|
|
||||||
perror("init_ui_socket");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = fuse_main(argc, argv, &xmp_oper, NULL);
|
|
||||||
free(mountpoint);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ static struct source_files_handle {
|
|||||||
int root_fd;
|
int root_fd;
|
||||||
} handle;
|
} handle;
|
||||||
|
|
||||||
const char *source_filename_translate(const char *filename) {
|
const char *source_fname_translate(const char *filename) {
|
||||||
if (strcmp("/", filename) == 0) {
|
if (strcmp("/", filename) == 0) {
|
||||||
return ".";
|
return ".";
|
||||||
} else {
|
} else {
|
||||||
@ -34,32 +34,32 @@ int source_init(const char *root_path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int source_mkdir(const char *filename, mode_t mode) {
|
int source_mkdir(const char *filename, mode_t mode) {
|
||||||
const char *relative_filename = source_filename_translate(filename);
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
return mkdirat(handle.root_fd, relative_filename, mode);
|
return mkdirat(handle.root_fd, relative_filename, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int source_unlink(const char *filename) {
|
int source_unlink(const char *filename) {
|
||||||
const char *relative_filename = source_filename_translate(filename);
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
return unlinkat(handle.root_fd, relative_filename, 0);
|
return unlinkat(handle.root_fd, relative_filename, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int source_stat(const char *restrict filename, struct stat *restrict statbuf) {
|
int source_stat(const char *restrict filename, struct stat *restrict statbuf) {
|
||||||
const char *relative_filename = source_filename_translate(filename);
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
return fstatat(handle.root_fd, relative_filename, statbuf, 0);
|
return fstatat(handle.root_fd, relative_filename, statbuf, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int source_rmdir(const char *filename) {
|
int source_rmdir(const char *filename) {
|
||||||
const char *relative_filename = source_filename_translate(filename);
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
return unlinkat(handle.root_fd, relative_filename, AT_REMOVEDIR);
|
return unlinkat(handle.root_fd, relative_filename, AT_REMOVEDIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
int source_symlink(const char *target, const char *linkpath) {
|
int source_symlink(const char *target, const char *linkpath) {
|
||||||
const char *relative_linkpath = source_filename_translate(linkpath);
|
const char *relative_linkpath = source_fname_translate(linkpath);
|
||||||
return symlinkat(target, handle.root_fd, relative_linkpath);
|
return symlinkat(target, handle.root_fd, relative_linkpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
DIR *source_opendir(const char *filename) {
|
DIR *source_opendir(const char *filename) {
|
||||||
const char *relative_filename = source_filename_translate(filename);
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
int fd = openat(handle.root_fd, relative_filename, NULL);
|
int fd = openat(handle.root_fd, relative_filename, NULL);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("Openat failed");
|
perror("Openat failed");
|
||||||
@ -70,33 +70,33 @@ DIR *source_opendir(const char *filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int source_rename(const char *oldpath, const char *newpath) {
|
int source_rename(const char *oldpath, const char *newpath) {
|
||||||
const char *relative_oldpath = source_filename_translate(oldpath);
|
const char *relative_oldpath = source_fname_translate(oldpath);
|
||||||
const char *relative_newpath = source_filename_translate(newpath);
|
const char *relative_newpath = source_fname_translate(newpath);
|
||||||
return renameat(handle.root_fd, relative_oldpath, handle.root_fd,
|
return renameat(handle.root_fd, relative_oldpath, handle.root_fd,
|
||||||
relative_newpath);
|
relative_newpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
int source_link(const char *oldpath, const char *newpath) {
|
int source_link(const char *oldpath, const char *newpath) {
|
||||||
const char *relative_oldpath = source_filename_translate(oldpath);
|
const char *relative_oldpath = source_fname_translate(oldpath);
|
||||||
const char *relative_newpath = source_filename_translate(newpath);
|
const char *relative_newpath = source_fname_translate(newpath);
|
||||||
return linkat(handle.root_fd, relative_oldpath, handle.root_fd,
|
return linkat(handle.root_fd, relative_oldpath, handle.root_fd,
|
||||||
relative_newpath, 0);
|
relative_newpath, 0);
|
||||||
// NOTE: perhaps the flags here need to be reevaluated.
|
// NOTE: perhaps the flags here need to be reevaluated.
|
||||||
}
|
}
|
||||||
|
|
||||||
int source_chmod(const char *filename, mode_t mode) {
|
int source_chmod(const char *filename, mode_t mode) {
|
||||||
const char *relative_filename = source_filename_translate(filename);
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
return fchmodat(handle.root_fd, relative_filename, mode, 0);
|
return fchmodat(handle.root_fd, relative_filename, mode, 0);
|
||||||
// NOTE: perhaps the flags here need to be reevaluated.
|
// NOTE: perhaps the flags here need to be reevaluated.
|
||||||
}
|
}
|
||||||
|
|
||||||
int source_chown(const char *filename, uid_t owner, gid_t group) {
|
int source_chown(const char *filename, uid_t owner, gid_t group) {
|
||||||
const char *relative_filename = source_filename_translate(filename);
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
return fchownat(handle.root_fd, filename, owner, group, AT_SYMLINK_NOFOLLOW);
|
return fchownat(handle.root_fd, filename, owner, group, AT_SYMLINK_NOFOLLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
int source_truncate(const char *filename, off_t length) {
|
int source_truncate(const char *filename, off_t length) {
|
||||||
const char *relative_filename = source_filename_translate(filename);
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
int fd = openat(handle.root_fd, relative_filename, NULL);
|
int fd = openat(handle.root_fd, relative_filename, NULL);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("Openat failed");
|
perror("Openat failed");
|
||||||
@ -106,11 +106,11 @@ int source_truncate(const char *filename, off_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int source_open(const char *filename, int flags) {
|
int source_open(const char *filename, int flags) {
|
||||||
const char *relative_filename = source_filename_translate(filename);
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
return openat(handle.root_fd, relative_filename, flags);
|
return openat(handle.root_fd, relative_filename, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int source_create(const char *filename, int flags, mode_t mode) {
|
int source_create(const char *filename, int flags, mode_t mode) {
|
||||||
const char *relative_filename = source_filename_translate(filename);
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
return openat(handle.root_fd, relative_filename, flags, mode);
|
return openat(handle.root_fd, relative_filename, flags, mode);
|
||||||
}
|
}
|
@ -1,37 +0,0 @@
|
|||||||
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
|
|
||||||
<!DOCTYPE cambalache-project SYSTEM "cambalache-project.dtd">
|
|
||||||
<cambalache-project version="0.94.0" target_tk="gtk-4.0">
|
|
||||||
<ui>
|
|
||||||
(1,None,"icfs.ui","start_window.ui",None,None,None,None,None,None,None),
|
|
||||||
(3,None,None,"open-dialog.ui",None,None,None,None,None,None,None)
|
|
||||||
</ui>
|
|
||||||
<object>
|
|
||||||
(1,1,"AdwApplicationWindow",None,None,None,None,None,0,None,None),
|
|
||||||
(1,2,"AdwToolbarView",None,1,None,None,None,0,None,None),
|
|
||||||
(1,3,"AdwHeaderBar",None,2,None,"top",None,0,None,None),
|
|
||||||
(1,4,"AdwPreferencesPage",None,2,None,None,None,1,None,None),
|
|
||||||
(1,5,"AdwPreferencesGroup",None,4,None,None,None,0,None,None),
|
|
||||||
(1,6,"AdwEntryRow",None,5,None,None,None,0,None,None),
|
|
||||||
(1,7,"GtkButton",None,6,None,None,None,0,None,None),
|
|
||||||
(1,8,"GtkButton",None,3,None,"start",None,0,None,None),
|
|
||||||
(3,1,"AdwMessageDialog",None,None,None,None,None,0,None,None)
|
|
||||||
</object>
|
|
||||||
<object_property>
|
|
||||||
(1,1,"AdwApplicationWindow","content","2",None,None,None,None,2,None,None,None,None),
|
|
||||||
(1,1,"GtkWindow","title","ICFS",None,None,None,None,None,None,None,None,None),
|
|
||||||
(1,2,"AdwToolbarView","content",None,None,None,None,None,4,None,None,None,None),
|
|
||||||
(1,6,"AdwEntryRow","input-hints","no-spellcheck",None,None,None,None,None,None,None,None,None),
|
|
||||||
(1,6,"AdwEntryRow","input-purpose","url",None,None,None,None,None,None,None,None,None),
|
|
||||||
(1,6,"AdwPreferencesRow","title","Mountpoint",None,None,None,None,None,None,None,None,None),
|
|
||||||
(1,7,"GtkButton","has-frame","False",None,None,None,None,None,None,None,None,None),
|
|
||||||
(1,7,"GtkButton","icon-name","folder-open-symbolic",None,None,None,None,None,None,None,None,None),
|
|
||||||
(1,8,"GtkButton","label","Start",None,None,None,None,None,None,None,None,None),
|
|
||||||
(3,1,"AdwMessageDialog","body","Allow this process to open the file?",None,None,None,None,None,None,None,None,None),
|
|
||||||
(3,1,"AdwMessageDialog","default-response","deny",None,None,None,None,None,None,None,None,None),
|
|
||||||
(3,1,"AdwMessageDialog","heading","Allow Access?",None,None,None,None,None,None,None,None,None)
|
|
||||||
</object_property>
|
|
||||||
<object_data>
|
|
||||||
(1,8,"GtkWidget",2,2,None,1,None,None,None,None),
|
|
||||||
(1,8,"GtkWidget",2,3,None,1,None,None,None,None)
|
|
||||||
</object_data>
|
|
||||||
</cambalache-project>
|
|
@ -1,44 +0,0 @@
|
|||||||
<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<!-- Created with Cambalache 0.94.1 -->
|
|
||||||
<interface>
|
|
||||||
<!-- interface-name icfs.ui -->
|
|
||||||
<requires lib="gtk" version="4.12"/>
|
|
||||||
<requires lib="libadwaita" version="1.6"/>
|
|
||||||
<object class="AdwApplicationWindow">
|
|
||||||
<property name="content">
|
|
||||||
<object class="AdwToolbarView">
|
|
||||||
<property name="content">
|
|
||||||
<object class="AdwPreferencesPage">
|
|
||||||
<child>
|
|
||||||
<object class="AdwPreferencesGroup">
|
|
||||||
<child>
|
|
||||||
<object class="AdwEntryRow">
|
|
||||||
<property name="input-hints">no-spellcheck</property>
|
|
||||||
<property name="input-purpose">url</property>
|
|
||||||
<property name="title">Mountpoint</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton">
|
|
||||||
<property name="has-frame">False</property>
|
|
||||||
<property name="icon-name">folder-open-symbolic</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
<child type="top">
|
|
||||||
<object class="AdwHeaderBar">
|
|
||||||
<child type="start">
|
|
||||||
<object class="GtkButton">
|
|
||||||
<property name="label">Start</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
<property name="title">ICFS</property>
|
|
||||||
</object>
|
|
||||||
</interface>
|
|
@ -1,56 +0,0 @@
|
|||||||
#include <stddef.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include "ui-socket.h"
|
|
||||||
#include <errno.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int init_ui_socket(const char *filename) {
|
|
||||||
char line[256];
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
// Test if Zenity is installed (get version)
|
|
||||||
fp = popen("zenity --version", "r");
|
|
||||||
if (fp == NULL) {
|
|
||||||
perror("Pipe returned a error");
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
while (fgets(line, sizeof(line), fp))
|
|
||||||
printf("%s", line);
|
|
||||||
pclose(fp);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This function is called from the FUSE operations functions. Those are called
|
|
||||||
* from separate threads. Therefore, there can be multiple threads that try to
|
|
||||||
* ask for access at the same time, but we have to
|
|
||||||
*/
|
|
||||||
|
|
||||||
int ask_access(const char *filename, struct process_info pi) {
|
|
||||||
|
|
||||||
FILE *fp;
|
|
||||||
size_t command_len =
|
|
||||||
139 + sizeof(pid_t) * 8 + strlen(pi.name) + strlen(filename);
|
|
||||||
char *command = (char *)malloc(command_len);
|
|
||||||
snprintf(command, command_len,
|
|
||||||
"zenity --question --title \"Allow Access?\" --text \"Allow process "
|
|
||||||
"<tt>%s</tt> with PID <tt>%d</tt> to access <tt>%s</tt>\"",
|
|
||||||
pi.name, pi.PID, filename);
|
|
||||||
// Zenity Question Message Popup
|
|
||||||
fp = popen(command, "r");
|
|
||||||
free(command);
|
|
||||||
if (fp == NULL) {
|
|
||||||
perror("Pipe returned a error");
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return WEXITSTATUS(pclose(fp));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* Interface for controlling communication with the UI.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef UI_SOCKET_H
|
|
||||||
#define UI_SOCKET_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
struct process_info {
|
|
||||||
pid_t PID;
|
|
||||||
const char *name;
|
|
||||||
uid_t UID;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
#endif // !UI_SOCKET_H
|
|
Loading…
x
Reference in New Issue
Block a user