mirror of
https://codeberg.org/shufflecake/shufflecake-c.git
synced 2026-01-06 11:05:31 -05:00
Add explicit error message for non-inserted dm-sflc
This commit is contained in:
parent
2a2166cb17
commit
95a72fc8e7
5 changed files with 116 additions and 2 deletions
|
|
@ -27,7 +27,7 @@
|
|||
#### Main files
|
||||
####
|
||||
|
||||
PROJ_SRCS := $(addprefix utils/,crypto.c disk.c dm.c file.c string.c input.c)
|
||||
PROJ_SRCS := $(addprefix utils/,crypto.c disk.c dm.c file.c string.c input.c kernmod.c)
|
||||
PROJ_SRCS += $(addprefix header/,position_map_legacy.c position_map_lite.c volume_master_block_legacy.c volume_master_block_lite.c device_master_block.c)
|
||||
PROJ_SRCS += $(addprefix operations/,volume_header_legacy.c volume_header_lite.c devmapper_legacy.c devmapper_lite.c dmb.c)
|
||||
PROJ_SRCS += $(addprefix commands/,init_legacy.c init_lite.c open_legacy.c open_lite.c close.c test_pwd.c change_pwd.c)
|
||||
|
|
|
|||
42
shufflecake-userland/include/utils/kernmod.h
Normal file
42
shufflecake-userland/include/utils/kernmod.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright The Shufflecake Project Authors (2022)
|
||||
* Copyright The Shufflecake Project Contributors (2022)
|
||||
* Copyright Contributors to the The Shufflecake Project.
|
||||
*
|
||||
* See the AUTHORS file at the top-level directory of this distribution and at
|
||||
* <https://www.shufflecake.net/permalinks/shufflecake-userland/AUTHORS>
|
||||
*
|
||||
* This file is part of the program shufflecake-c, which is part of the
|
||||
* Shufflecake Project. Shufflecake is a plausible deniability (hidden storage)
|
||||
* layer for Linux. See <https://www.shufflecake.net>.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 2 of the License, or (at your option)
|
||||
* any later version. This program is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details. You should have received a copy of the
|
||||
* GNU General Public License along with this program.
|
||||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _UTILS_KERNMOD_H_
|
||||
#define _UTILS_KERNMOD_H_
|
||||
|
||||
|
||||
/*****************************************************
|
||||
* INCLUDE SECTION *
|
||||
*****************************************************/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
/*****************************************************
|
||||
* PUBLIC FUNCTIONS PROTOTYPES *
|
||||
*****************************************************/
|
||||
|
||||
bool sflc_isKernelModuleLoaded(char *module_name);
|
||||
|
||||
|
||||
#endif /* _UTILS_KERNOMD_H_ */
|
||||
|
|
@ -40,6 +40,8 @@
|
|||
|
||||
/* Name of the DM target in the kernel */
|
||||
#define SFLC_DM_TARGET_NAME "shufflecake"
|
||||
/* Name of the kernel module once inserted */
|
||||
#define SFLC_KERNMOD_NAME "dm_sflc"
|
||||
|
||||
/* Modes */
|
||||
#define SFLC_MODE_LEGACY 0
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include "cli.h"
|
||||
#include "utils/sflc.h"
|
||||
#include "utils/disk.h"
|
||||
#include "utils/kernmod.h"
|
||||
#include "utils/log.h"
|
||||
|
||||
|
||||
|
|
@ -185,7 +186,11 @@ int sflc_cli_dispatch(int argc, char **argv) {
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
// TODO check that dm_sflc is loaded
|
||||
/* Check that the kernel module is loaded */
|
||||
if (!sflc_isKernelModuleLoaded(SFLC_KERNMOD_NAME)) {
|
||||
printf("Error: kernel module dm-sflc is not inserted.\n");
|
||||
return EINVAL;
|
||||
}
|
||||
/* Check that input is actually a block device */
|
||||
if (strncmp(args.block_device, "/dev/", 5) != 0 || !sflc_disk_isBlockDevice(args.block_device)) {
|
||||
printf("Error: '%s' is not a valid block device.\n", args.block_device);
|
||||
|
|
|
|||
65
shufflecake-userland/src/utils/kernmod.c
Normal file
65
shufflecake-userland/src/utils/kernmod.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright The Shufflecake Project Authors (2022)
|
||||
* Copyright The Shufflecake Project Contributors (2022)
|
||||
* Copyright Contributors to the The Shufflecake Project.
|
||||
*
|
||||
* See the AUTHORS file at the top-level directory of this distribution and at
|
||||
* <https://www.shufflecake.net/permalinks/shufflecake-userland/AUTHORS>
|
||||
*
|
||||
* This file is part of the program shufflecake-c, which is part of the
|
||||
* Shufflecake Project. Shufflecake is a plausible deniability (hidden storage)
|
||||
* layer for Linux. See <https://www.shufflecake.net>.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 2 of the License, or (at your option)
|
||||
* any later version. This program is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details. You should have received a copy of the
|
||||
* GNU General Public License along with this program.
|
||||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*****************************************************
|
||||
* INCLUDE SECTION *
|
||||
*****************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "utils/kernmod.h"
|
||||
#include "utils/sflc.h"
|
||||
#include "utils/log.h"
|
||||
|
||||
|
||||
/*****************************************************
|
||||
* PUBLIC FUNCTIONS DEFINITIONS *
|
||||
*****************************************************/
|
||||
|
||||
bool sflc_isKernelModuleLoaded(char *module_name) {
|
||||
FILE *fp;
|
||||
char line[SFLC_BIGBUFSIZE];
|
||||
|
||||
// Open /proc/modules to check loaded modules
|
||||
fp = fopen("/proc/modules", "r");
|
||||
if (fp == NULL) {
|
||||
sflc_log_error("Failed to open /proc/modules");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read each line in /proc/modules
|
||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||
// Compare the module name in the current line with the input module name
|
||||
char *current_module = strtok(line, " "); // First token in the line is the module name
|
||||
if (current_module != NULL && strcmp(current_module, module_name) == 0) {
|
||||
fclose(fp);
|
||||
return true; // Module is loaded
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return false; // Module not found
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue