Droped support for kernel mode Overlayfs

This commit is contained in:
Marc
2022-10-07 10:12:34 +02:00
parent 67a68011ed
commit b6d11aa9ee
3 changed files with 52 additions and 102 deletions
+21 -64
View File
@@ -45,16 +45,6 @@ static GList * listFilesInFolder(const char * path) {
return list; return list;
} }
static int noRoot() {
fprintf(stderr, "Don't run this argument as root\n");
return EXIT_FAILURE;
}
static int needRoot() {
fprintf(stderr, "Root is needed to bind with the game files\n");
return EXIT_FAILURE;
}
static int usage() { static int usage() {
printf("Use --list-games or -l to list compatible games\n"); printf("Use --list-games or -l to list compatible games\n");
printf("Use --add or -a <APPID> <FILENAME> to add a mod to a game\n"); printf("Use --add or -a <APPID> <FILENAME> to add a mod to a game\n");
@@ -320,15 +310,15 @@ static int deploy(int argc, char ** argv) {
//it might crash / corrupt game file if the user do it while the game is running //it might crash / corrupt game file if the user do it while the game is running
//but it's still very unlikely //but it's still very unlikely
while(umount2(steamGameFolder, MNT_FORCE | MNT_DETACH) == 0); while(umount2(steamGameFolder, MNT_FORCE | MNT_DETACH) == 0);
int status = overlayMount(modsToInstall, steamGameFolder, gameUpperDir, gameWorkDir); enum overlayErrors status = overlayMount(modsToInstall, steamGameFolder, gameUpperDir, gameWorkDir);
if(status == 0) { if(status == SUCESS) {
printf("Everything is ready, just launch the game\n"); printf("Everything is ready, just launch the game\n");
} else if(status == -1) { } else if(status == FAILURE) {
fprintf(stderr, "Could not mount the mods overlay, try to install fuse-overlay\n");
return EXIT_FAILURE;
} else if(status == -2) {
fprintf(stderr, "Could not mount the mods overlay\n"); fprintf(stderr, "Could not mount the mods overlay\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} else if(status == NOT_INSTALLED) {
fprintf(stderr, "Please install fuse-overlayfs\n");
return EXIT_FAILURE;
} else { } else {
fprintf(stderr, "%d bug detected, please report this.\n", __LINE__); fprintf(stderr, "%d bug detected, please report this.\n", __LINE__);
return EXIT_FAILURE; return EXIT_FAILURE;
@@ -531,8 +521,8 @@ static int swapMod(int argc, char ** argv) {
int main(int argc, char ** argv) { int main(int argc, char ** argv) {
if(argc < 2 ) return usage(); if(argc < 2 ) return usage();
if(audit_getloginuid() == 0) { if(audit_getloginuid() == 0 || isRoot()) {
fprintf(stderr, "The root user should not be using this\n"); fprintf(stderr, "Please don't run this software as root\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@@ -571,72 +561,40 @@ int main(int argc, char ** argv) {
} }
if(strcmp(argv[1], "--list-games") == 0 || strcmp(argv[1], "-l") == 0) { if(strcmp(argv[1], "--list-games") == 0 || strcmp(argv[1], "-l") == 0)
if(isRoot())
returnValue = noRoot();
else
returnValue = listGames(argc, argv); returnValue = listGames(argc, argv);
} else if(strcmp(argv[1], "--add") == 0 || strcmp(argv[1], "-a") == 0) { else if(strcmp(argv[1], "--add") == 0 || strcmp(argv[1], "-a") == 0)
if(isRoot())
returnValue = noRoot();
else
returnValue = add(argc, argv); returnValue = add(argc, argv);
} else if(strcmp(argv[1], "--list-mods") == 0 || strcmp(argv[1], "-m") == 0) { else if(strcmp(argv[1], "--list-mods") == 0 || strcmp(argv[1], "-m") == 0)
if(isRoot())
returnValue = noRoot();
else
returnValue = listAllMods(argc, argv); returnValue = listAllMods(argc, argv);
} else if(strcmp(argv[1], "--install") == 0 || strcmp(argv[1], "-i") == 0) { else if(strcmp(argv[1], "--install") == 0 || strcmp(argv[1], "-i") == 0)
if(isRoot())
returnValue = noRoot();
else
returnValue = installAndUninstallMod(argc, argv, true); returnValue = installAndUninstallMod(argc, argv, true);
} else if(strcmp(argv[1], "--uninstall") == 0 || strcmp(argv[1], "-u") == 0) { else if(strcmp(argv[1], "--uninstall") == 0 || strcmp(argv[1], "-u") == 0)
if(isRoot())
returnValue = noRoot();
else
returnValue = installAndUninstallMod(argc, argv, false); returnValue = installAndUninstallMod(argc, argv, false);
} else if(strcmp(argv[1], "--deploy") == 0 || strcmp(argv[1], "-d") == 0) { else if(strcmp(argv[1], "--deploy") == 0 || strcmp(argv[1], "-d") == 0)
if(!isRoot())
returnValue = needRoot();
else
returnValue = deploy(argc, argv); returnValue = deploy(argc, argv);
} else if(strcmp(argv[1], "--unbind") == 0){ else if(strcmp(argv[1], "--unbind") == 0)
if(!isRoot())
returnValue = needRoot();
else
returnValue = unbind(argc, argv); returnValue = unbind(argc, argv);
} else if(strcmp(argv[1], "--setup") == 0) { else if(strcmp(argv[1], "--setup") == 0)
if(isRoot())
returnValue = noRoot();
else
returnValue = setup(argc, argv); returnValue = setup(argc, argv);
} else if(strcmp(argv[1], "--fomod") == 0){
if(isRoot()) else if(strcmp(argv[1], "--fomod") == 0)
returnValue = noRoot();
else
returnValue = fomod(argc, argv); returnValue = fomod(argc, argv);
} else if(strcmp(argv[1], "--remove") == 0 || strcmp(argv[1], "-r") == 0) { else if(strcmp(argv[1], "--remove") == 0 || strcmp(argv[1], "-r") == 0)
if(isRoot())
returnValue = noRoot();
else
returnValue = removeMod(argc, argv); returnValue = removeMod(argc, argv);
} else if(strcmp(argv[1], "--swap") == 0 || strcmp(argv[1], "-s") == 0) { else if(strcmp(argv[1], "--swap") == 0 || strcmp(argv[1], "-s") == 0)
if(isRoot())
returnValue = noRoot();
else
returnValue = swapMod(argc, argv); returnValue = swapMod(argc, argv);
} else if(strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0) { else if(strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0) {
returnValue = EXIT_SUCCESS; returnValue = EXIT_SUCCESS;
#ifdef __clang__ #ifdef __clang__
printf("%s: Clang: %d.%d.%d\n", VERSION, __clang_major__, __clang_minor__, __clang_patchlevel__); printf("%s: Clang: %d.%d.%d\n", VERSION, __clang_major__, __clang_minor__, __clang_patchlevel__);
@@ -645,7 +603,6 @@ int main(int argc, char ** argv) {
#else #else
printf("%s: unknown compiler\n", VERSION); printf("%s: unknown compiler\n", VERSION);
#endif #endif
} else { } else {
usage(); usage();
returnValue = EXIT_FAILURE; returnValue = EXIT_FAILURE;
+7 -17
View File
@@ -6,16 +6,13 @@
#include "overlayfs.h" #include "overlayfs.h"
#include <stdio.h> #include <stdio.h>
int overlayMount(char ** sources, const char * dest, const char * upperdir, const char * workdir) { enum overlayErrors overlayMount(char ** sources, const char * dest, const char * upperdir, const char * workdir) {
char * lowerdir = g_strjoinv(":", sources); char * lowerdir = g_strjoinv(":", sources);
char * mountData = g_strjoin("", "lowerdir=", lowerdir, ",workdir=", workdir, ",upperdir=", upperdir, NULL); char * mountData = g_strjoin("", "lowerdir=", lowerdir, ",workdir=", workdir, ",upperdir=", upperdir, NULL);
int result = mount("overlay", "none", "overlay", MS_RDONLY, mountData);
if(result < 0) {
//this is very important for a lot of filesystems
//even ext4 can be incompatible with the kernel's implementation
//with some flags such as casefold
if(access("/usr/bin/fuse-overlayfs", F_OK) == 0) {
enum overlayErrors result = SUCESS;
if(access("/usr/bin/fuse-overlayfs", F_OK) == 0) {
int pid = fork(); int pid = fork();
if(pid == 0) { if(pid == 0) {
//exit is used to get the return value when using waitpid //exit is used to get the return value when using waitpid
@@ -24,21 +21,14 @@ int overlayMount(char ** sources, const char * dest, const char * upperdir, cons
int returnValue = 0; int returnValue = 0;
waitpid(pid, &returnValue, 0); waitpid(pid, &returnValue, 0);
free(lowerdir);
free(mountData);
if(returnValue != 0) { if(returnValue != 0) {
return -2; result = FAILURE;
} }
return 0;
} }
} else { } else {
free(lowerdir); result = NOT_INSTALLED;
free(mountData);
return -1;
}
} }
free(lowerdir); free(lowerdir);
free(mountData); free(mountData);
return 0; return result;
} }
+4 -1
View File
@@ -1,6 +1,9 @@
#ifndef __OVERLAY_H__ #ifndef __OVERLAY_H__
#define __OVERLAY_H__ #define __OVERLAY_H__
enum overlayErrors { SUCESS, NOT_INSTALLED, FAILURE };
/** /**
* @brief Overlayfs is what make it possible to deploy to the game files without altering anything. * @brief Overlayfs is what make it possible to deploy to the game files without altering anything.
* it allows us to overlay multiple folder over the game files. like appling filters to an image. * it allows us to overlay multiple folder over the game files. like appling filters to an image.
@@ -10,6 +13,6 @@
* @param workdir a directory that will contains only temporary files. * @param workdir a directory that will contains only temporary files.
* @return int error code * @return int error code
*/ */
int overlayMount(char ** sources, const char * dest, const char * upperdir, const char * workdir); enum overlayErrors overlayMount(char ** sources, const char * dest, const char * upperdir, const char * workdir);
#endif #endif