94 lines
2.9 KiB
C
94 lines
2.9 KiB
C
/*
|
|
FUSE: Filesystem in Userspace
|
|
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
|
Copyright (C) 2011 Sebastian Pipping <sebastian@pipping.org>
|
|
|
|
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 <string.h>
|
|
#define FUSE_USE_VERSION 31
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <fuse3/fuse.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
|
|
#include "fuse_operations.h"
|
|
#include "sourcefs.h"
|
|
#include "ui-socket.h"
|
|
|
|
const char *mountpoint = NULL;
|
|
|
|
int main(int argc, char *argv[]) {
|
|
if (argc < 3) {
|
|
fprintf(stderr, "Usage: icfs <FUSE arguments> [target directory] [path to "
|
|
"the permanent permissions database] <ICFS "
|
|
"arguments>\n\t--no-perm-on-create - do not give any "
|
|
"access permissions on file creation"
|
|
"(incompatible with --temp-on-create)\n\t--perm-on-create "
|
|
"- automatically give permanent access permission to files "
|
|
"a process creates "
|
|
"(incompatible with --no-perm-on-create)\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
if ((0 == strcmp(argv[argc - 1], "--no-perm-on-create") &&
|
|
0 == strcmp(argv[argc - 2], "--temp-on-create")) ||
|
|
(0 == strcmp(argv[argc - 2], "--no-perm-on-create") &&
|
|
0 == strcmp(argv[argc - 1], "--temp-on-create"))) {
|
|
fprintf(stderr, "Usage: icfs <FUSE arguments> [target directory] [path to "
|
|
"the permanent permissions database] <ICFS "
|
|
"arguments>\n\t--no-perm-on-create - do not give any "
|
|
"access permissions on file creation"
|
|
"(incompatible with --temp-on-create)\n\t--perm-on-create "
|
|
"- automatically give permanent access permission to files "
|
|
"a process creates "
|
|
"(incompatible with --no-perm-on-create)\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
// if umask != 0, the filesystem will create files with more restrictive
|
|
// permissions than it's caller reqested
|
|
umask(0);
|
|
|
|
if (0 == strcmp(argv[argc - 1], "--no-perm-on-create")) {
|
|
set_auto_create_perm(0);
|
|
argc--;
|
|
}
|
|
if (0 == strcmp(argv[argc - 1], "--perm-on-create")) {
|
|
set_auto_create_perm(GRANT_PERM);
|
|
argc--;
|
|
}
|
|
|
|
// ui socket should always be initialized before anything else, since it
|
|
// handles the setuid bits!
|
|
int ret = init_ui_socket(argv[argc - 1]);
|
|
if (ret != 0) {
|
|
fprintf(stderr, "[ICFS] Could not initalize ui-socket.\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
mountpoint = realpath(argv[argc - 2], NULL);
|
|
|
|
ret = source_init(mountpoint);
|
|
if (ret != 0) {
|
|
perror("[ICFS] source_init");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
ret = fuse_main(argc - 1, argv, get_fuse_operations(), NULL);
|
|
|
|
free((void *)mountpoint);
|
|
source_destroy();
|
|
destroy_ui_socket();
|
|
return ret;
|
|
}
|