From f7c22228d62cbe00515081cb6d430f699c4cbfb1 Mon Sep 17 00:00:00 2001 From: Piotr Rogoza Date: Wed, 12 Nov 2025 13:01:43 +0100 Subject: [PATCH 1/2] Add reading /etc/libtrash.conf --- configure.ac | 5 +++-- src/helpers.c | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index f2aee20..ee0848a 100644 --- a/configure.ac +++ b/configure.ac @@ -42,6 +42,7 @@ AC_DEFINE([NO],[0],[Default for NO]) AC_DEFINE([ALLOW_DESTRUCTION],[1],[Default for ALLOW_DESTRUCTION]) AC_DEFINE([PROTECT],[0],[Default for PROTECT]) AC_DEFINE([PERSONAL_CONF_FILE],".libtrash",[Personal Configuration File]) +AC_DEFINE([SYSCONFDIR],"/etc","System Configuration Directory") AC_DEFINE([WARNING_STRING],"Remember that libtrash is disabled.",[Disabled Warning String]) AC_DEFINE([INTERCEPT_UNLINK],[YES],[Trap unlink]) AC_DEFINE([INTERCEPT_RENAME],[YES],[Trap rename]) @@ -150,7 +151,7 @@ for TMPVAR in creat creat64 fopen fopen64 freopen freopen64 open open64 rename u do VERSIONVAR=$(grep -m1 $TMPVAR@ glibc_symbols | cut -d@ -f2) FUNCVAR=$(echo $TMPVAR | tr a-z A-Z)_VERSION - + if test "x$VERSIONVAR" != "x" ; then AC_DEFINE_UNQUOTED([$FUNCVAR],"$VERSIONVAR",[$TMPVAR Define for dlvsym call]) else @@ -163,7 +164,7 @@ for TMPVAR in openat openat64 renameat unlinkat do VERSIONVAR=$(grep -m1 $TMPVAR@ glibc_symbols | cut -d@ -f2) FUNCVAR=$(echo $TMPVAR | tr a-z A-Z)_VERSION - + if test "x$VERSIONVAR" != "x" ; then AC_DEFINE_UNQUOTED([$FUNCVAR],"$VERSIONVAR",[$TMPVAR Define for dlvsym call]) else diff --git a/src/helpers.c b/src/helpers.c index 74da8db..1d094f1 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "trash.h" @@ -1437,12 +1438,41 @@ void get_config_from_file(config *cfg) "IGNORE_RE", "PRESERVE_FILES_LARGER_THAN"); - /* Did read_config_from_file() fail? If it did, we quit and leave the compile-time defaults unchanged: */ + if (!config_values) { + char sysconf_path[PATH_MAX]; + snprintf(sysconf_path, sizeof(sysconf_path), "%s/libtrash.conf", SYSCONFDIR); + config_values = read_config_from_file(sysconf_path, NUMBER_OF_CONFIG_OPTIONS, cfg, + "TRASH_CAN", + "IN_CASE_OF_FAILURE", + "SHOULD_WARN", + "IGNORE_HIDDEN", + "IGNORE_EDITOR_BACKUP", + "PROTECT_TRASH", + "GLOBAL_PROTECTION", + "TRASH_SYSTEM_ROOT", + "TEMPORARY_DIRS", + "USER_TEMPORARY_DIRS", + "UNREMOVABLE_DIRS", + "IGNORE_EXTENSIONS", + "INTERCEPT_UNLINK", + "INTERCEPT_RENAME", + "INTERCEPT_FOPEN", + "INTERCEPT_FREOPEN", + "INTERCEPT_OPEN", + "LIBTRASH_CONFIG_FILE_UNREMOVABLE", + "REMOVABLE_MEDIA_MOUNT_POINTS", + "IGNORE_EDITOR_TEMPORARY", + "EXCEPTIONS", + "IGNORE_RE", + "PRESERVE_FILES_LARGER_THAN"); + + /* Did read_config_from_file() fail? If it did, we quit and leave the compile-time defaults unchanged: */ - if (!config_values) - return; + if (!config_values) + return; + } - /* If we managed to read the configuration file in the user's home directory, + /* If we managed to read the configuration file in the user's home directory, * we now proceed to set the configuration variables to the values read_config_from_file() returned to us: */ /* Configuration variables which are integers used as "flags" are set by the From f518298714932a9ad6c3530081d5e5f14d179525 Mon Sep 17 00:00:00 2001 From: Piotr Rogoza Date: Thu, 13 Nov 2025 10:14:42 +0100 Subject: [PATCH 2/2] Add definition of sysconfdir/SYSCONFDIR --- configure.ac | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ee0848a..c77ca7b 100644 --- a/configure.ac +++ b/configure.ac @@ -42,7 +42,6 @@ AC_DEFINE([NO],[0],[Default for NO]) AC_DEFINE([ALLOW_DESTRUCTION],[1],[Default for ALLOW_DESTRUCTION]) AC_DEFINE([PROTECT],[0],[Default for PROTECT]) AC_DEFINE([PERSONAL_CONF_FILE],".libtrash",[Personal Configuration File]) -AC_DEFINE([SYSCONFDIR],"/etc","System Configuration Directory") AC_DEFINE([WARNING_STRING],"Remember that libtrash is disabled.",[Disabled Warning String]) AC_DEFINE([INTERCEPT_UNLINK],[YES],[Trap unlink]) AC_DEFINE([INTERCEPT_RENAME],[YES],[Trap rename]) @@ -77,6 +76,14 @@ if test x"$debug" = xyes; then AC_DEFINE([DEBUG], [1], [Debug Flag]) fi +if test "x$sysconfdir" = 'x${prefix}/etc'; then + if test "x$prefix" = 'xNONE'; then + sysconfdir=$ac_default_prefix/etc + else + sysconfdir=$prefix/etc + fi +fi +AC_DEFINE_UNQUOTED([SYSCONFDIR], ["$sysconfdir"], [System Configuration Directory]) # Checks for programs. AC_PROG_CC