Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ else()
message(STATUS "Threads type: disabled")
endif()

set(WARNING_FLAGS "-Wall -Wextra -Wconversion -Werror=uninitialized -Werror=return-type -Werror=vla")
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
set(WARNING_FLAGS "-Wall -Wextra -Wconversion -Werror=uninitialized -Werror=return-type -Werror=vla")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Werror=int-conversion")
else()
set(WARNING_FLAGS "")
endif()

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Werror=int-conversion")

if(WIN32 OR Haiku OR ENABLE_DIRECTX_HEADERS)
enable_language(CXX)
Expand All @@ -161,20 +165,27 @@ if(WIN32 OR Haiku OR ENABLE_DIRECTX_HEADERS)
endif()

if(WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--tsaware -Wl,--build-id -Wl,--subsystem,console:6.1,--major-os-version,6,--minor-os-version,1")
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--tsaware -Wl,--build-id -Wl,--subsystem,console:6.1,--major-os-version,6,--minor-os-version,1")
else()
# MSVC linker flags
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE,6.1")
endif()
elseif(APPLE AND CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fobjc-arc")
endif()

set(FASTFETCH_FLAGS_DEBUG "-fno-omit-frame-pointer")
if(ENABLE_ASAN)
message(STATUS "Address sanitizer enabled (DEBUG only)")
set(FASTFETCH_FLAGS_DEBUG "${FASTFETCH_FLAGS_DEBUG} -fsanitize=address")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG} -fstack-protector-all -fno-delete-null-pointer-checks")
if(NOT WIN32)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -rdynamic")
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
set(FASTFETCH_FLAGS_DEBUG "-fno-omit-frame-pointer")
if(ENABLE_ASAN)
message(STATUS "Address sanitizer enabled (DEBUG only)")
set(FASTFETCH_FLAGS_DEBUG "${FASTFETCH_FLAGS_DEBUG} -fsanitize=address")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG} -fstack-protector-all -fno-delete-null-pointer-checks")
if(NOT WIN32)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -rdynamic")
endif()
endif()

if(ENABLE_LTO AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down Expand Up @@ -467,6 +478,7 @@ set(LIBFASTFETCH_SRC
src/modules/publicip/publicip.c
src/modules/display/display.c
src/modules/separator/separator.c
src/modules/security/security.c
src/modules/shell/shell.c
src/modules/sound/sound.c
src/modules/swap/swap.c
Expand Down Expand Up @@ -514,6 +526,7 @@ if(LINUX)
src/detection/board/board_linux.c
src/detection/bootmgr/bootmgr_linux.c
src/detection/brightness/brightness_linux.c
src/detection/security/security_linux.c
src/detection/btrfs/btrfs_linux.c
src/detection/chassis/chassis_linux.c
src/detection/cpu/cpu_linux.c
Expand Down Expand Up @@ -600,6 +613,7 @@ elseif(ANDROID)
src/detection/board/board_android.c
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/security/security_nosupport.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_nosupport.c
src/detection/cpu/cpu_linux.c
Expand Down Expand Up @@ -1002,6 +1016,7 @@ elseif(WIN32)
src/detection/board/board_windows.c
src/detection/bootmgr/bootmgr_windows.c
src/detection/brightness/brightness_windows.cpp
src/detection/security/security_windows.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_windows.c
Expand Down Expand Up @@ -1073,6 +1088,7 @@ elseif(SunOS)
src/detection/board/board_windows.c
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/security/security_nosupport.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_sunos.c
Expand Down Expand Up @@ -1154,6 +1170,7 @@ elseif(Haiku)
src/detection/board/board_windows.c
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/security/security_nosupport.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_haiku.c
Expand Down Expand Up @@ -1223,6 +1240,7 @@ elseif(GNU)
src/detection/board/board_nosupport.c
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/security/security_nosupport.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_nosupport.c
src/detection/cpu/cpu_linux.c
Expand Down
1 change: 1 addition & 0 deletions src/common/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ static FFModuleBaseInfo* R[] = {

static FFModuleBaseInfo* S[] = {
&ffSeparatorModuleInfo,
&ffSecurityModuleInfo,
&ffShellModuleInfo,
&ffSoundModuleInfo,
&ffSwapModuleInfo,
Expand Down
2 changes: 1 addition & 1 deletion src/data/structure.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Title:Separator:OS:Host:Kernel:Uptime:Packages:Shell:Display:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:GPU:Memory:Swap:Disk:LocalIp:Battery:PowerAdapter:Locale:Break:Colors
Title:Separator:OS:Host:Bios:Board:Security:Kernel:Uptime:Packages:Shell:Display:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:GPU:Memory:Swap:Disk:LocalIp:Battery:PowerAdapter:Locale:Break:Colors
12 changes: 12 additions & 0 deletions src/detection/security/security.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "fastfetch.h"
#include "modules/security/option.h"

typedef struct FFSecurityResult
{
FFstrbuf tpmStatus;
FFstrbuf secureBootStatus;
} FFSecurityResult;

const char* ffDetectSecurity(FFSecurityResult* result);
53 changes: 53 additions & 0 deletions src/detection/security/security_linux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "security.h"
#include "detection/tpm/tpm.h"
#include "detection/bootmgr/bootmgr.h"

const char* ffDetectSecurity(FFSecurityResult* result)
{
ffStrbufInit(&result->tpmStatus);
ffStrbufInit(&result->secureBootStatus);

// Detect TPM
FFTPMResult tpm = {
.version = ffStrbufCreate(),
.description = ffStrbufCreate()
};
const char* tpmError = ffDetectTPM(&tpm);
if (tpmError == NULL)
{
if (tpm.version.length > 0)
ffStrbufSetF(&result->tpmStatus, "TPM %s", tpm.version.chars);
else
ffStrbufSetStatic(&result->tpmStatus, "TPM OK");
}
else
{
ffStrbufSetStatic(&result->tpmStatus, "TPM Not Available");
}
ffStrbufDestroy(&tpm.version);
ffStrbufDestroy(&tpm.description);

// Detect Secure Boot
FFBootmgrResult bootmgr = {
.name = ffStrbufCreate(),
.firmware = ffStrbufCreate(),
.order = 0,
.secureBoot = false
};
const char* bootmgrError = ffDetectBootmgr(&bootmgr);
if (bootmgrError == NULL)
{
if (bootmgr.secureBoot)
ffStrbufSetStatic(&result->secureBootStatus, "Secure Boot Enabled");
else
ffStrbufSetStatic(&result->secureBootStatus, "Secure Boot Disabled");
}
else
{
ffStrbufSetStatic(&result->secureBootStatus, "Secure Boot Unknown");
}
ffStrbufDestroy(&bootmgr.name);
ffStrbufDestroy(&bootmgr.firmware);

return NULL;
}
10 changes: 10 additions & 0 deletions src/detection/security/security_nosupport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "security.h"

const char* ffDetectSecurity(FFSecurityResult* result)
{
ffStrbufInit(&result->tpmStatus);
ffStrbufInit(&result->secureBootStatus);
ffStrbufSetStatic(&result->tpmStatus, "TPM Not Available");
ffStrbufSetStatic(&result->secureBootStatus, "Secure Boot Unknown");
return NULL;
}
47 changes: 47 additions & 0 deletions src/detection/security/security_windows.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "security.h"
#include "detection/tpm/tpm.h"
#include "util/windows/registry.h"

#include <windows.h>

const char* ffDetectSecurity(FFSecurityResult* result)
{
ffStrbufInit(&result->tpmStatus);
ffStrbufInit(&result->secureBootStatus);

// Detect TPM
FFTPMResult tpm = {
.version = ffStrbufCreate(),
.description = ffStrbufCreate()
};
const char* tpmError = ffDetectTPM(&tpm);
if (tpmError == NULL)
{
if (tpm.version.length > 0)
ffStrbufSetF(&result->tpmStatus, "TPM %s", tpm.version.chars);
else
ffStrbufSetStatic(&result->tpmStatus, "TPM OK");
}
else
{
ffStrbufSetStatic(&result->tpmStatus, "TPM Not Available");
}
ffStrbufDestroy(&tpm.version);
ffStrbufDestroy(&tpm.description);

// Detect Secure Boot directly from registry
DWORD uefiSecureBootEnabled = 0, bufSize = sizeof(uefiSecureBootEnabled);
if (RegGetValueW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\SecureBoot\\State", L"UEFISecureBootEnabled", RRF_RT_REG_DWORD, NULL, &uefiSecureBootEnabled, &bufSize) == ERROR_SUCCESS)
{
if (uefiSecureBootEnabled)
ffStrbufSetStatic(&result->secureBootStatus, "Secure Boot Enabled");
else
ffStrbufSetStatic(&result->secureBootStatus, "Secure Boot Disabled");
}
else
{
ffStrbufSetStatic(&result->secureBootStatus, "Secure Boot Unknown");
}

return NULL;
}
10 changes: 6 additions & 4 deletions src/modules/bios/bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ bool ffPrintBios(FFBiosOptions* options)
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
if (bios.vendor.length > 0)
{
ffStrbufWriteTo(&bios.vendor, stdout);
putchar(' ');
}
ffStrbufWriteTo(&bios.version, stdout);
if (bios.release.length)
printf(" (%s)\n", bios.release.chars);
else
putchar('\n');
putchar('\n');
}
else
{
Expand Down
16 changes: 13 additions & 3 deletions src/modules/board/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@ bool ffPrintBoard(FFBoardOptions* options)
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_BOARD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&result.name, stdout);
if (result.version.length)
printf(" (%s)", result.version.chars);
if (result.vendor.length > 0)
{
ffStrbufWriteTo(&result.vendor, stdout);
putchar(' ');
}
if (result.version.length > 0)
{
ffStrbufWriteTo(&result.version, stdout);
}
else if (result.name.length > 0)
{
ffStrbufWriteTo(&result.name, stdout);
}
putchar('\n');
}
else
Expand Down
1 change: 1 addition & 0 deletions src/modules/modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "modules/processes/processes.h"
#include "modules/publicip/publicip.h"
#include "modules/separator/separator.h"
#include "modules/security/security.h"
#include "modules/shell/shell.h"
#include "modules/sound/sound.h"
#include "modules/swap/swap.h"
Expand Down
10 changes: 10 additions & 0 deletions src/modules/security/option.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "common/option.h"

typedef struct FFSecurityOptions
{
FFModuleArgs moduleArgs;
} FFSecurityOptions;

static_assert(sizeof(FFSecurityOptions) <= FF_OPTION_MAX_SIZE, "FFSecurityOptions size exceeds maximum allowed size");
Loading