File usr_etc.patch of Package udisks2
diff -ur a/configure.ac b/configure.ac
--- a/configure.ac 2023-09-07 14:25:58.000000000 +0200
+++ b/configure.ac 2025-06-13 15:14:59.846832219 +0200
@@ -246,6 +246,37 @@
AC_SUBST([tmpfilesdir], [$with_tmpfilesdir])
fi
+# libeconf
+AC_ARG_WITH([econf],
+ AS_HELP_STRING([--without-econf], [do not use libeconf]),
+ [], [with_econf=check]
+)
+
+have_econf=no
+AS_IF([test "x$with_econf" != xno], [
+ PKG_CHECK_MODULES([ECONF], [libeconf], [have_econf=yes], [have_econf=no])
+ AS_CASE([$with_econf:$have_econf],
+ [yes:no],
+ [AC_MSG_ERROR([libeconf expected but libeconf not found])],
+ [*:yes],
+ AC_DEFINE([HAVE_LIBECONF], [1], [Define if libeconf is available])
+ )
+])
+AM_CONDITIONAL([HAVE_ECONF], [test "x$have_econf" = xyes])
+
+AC_ARG_WITH([vendordir],
+ AS_HELP_STRING([--with-vendordir=DIR], [Directory for distribution provided configuration files (libeconf is needed for it)]),
+ [], []
+)
+AC_SUBST([vendordir], [$with_vendordir])
+AM_CONDITIONAL([USE_VENDORDIR], [test "x$with_vendordir" != x])
+AS_IF([test "x$with_vendordir" != x], [
+ AC_DEFINE([USE_VENDORDIR], [1], [Define to 1 to use vendordir])
+ AS_IF([test "x$with_econf" == xno], [
+ AC_MSG_ERROR([libeconf is needed for using vendordir])
+ ])
+])
+
# kernel modules
AC_ARG_WITH([modloaddir],
[AS_HELP_STRING([--with-modloaddir=DIR], [Directory for configuring kernel modules to load at boot])],
@@ -673,6 +704,7 @@
sbindir: ${sbindir}
datadir: ${datadir}
sysconfdir: ${sysconfdir}
+ vendordir: ${with_vendordir}
localstatedir: ${localstatedir}
docdir: ${docdir}
introspection: ${found_introspection}
@@ -684,6 +716,7 @@
using libelogind: ${have_libelogind}
use /media for mounting: ${fhs_media}
acl support: ${have_acl}
+ libeconf support: ${have_econf}
compiler: ${CC}
cflags: ${CFLAGS}
diff -ur a/doc/man/Makefile.am b/doc/man/Makefile.am
--- a/doc/man/Makefile.am 2023-09-07 14:11:56.000000000 +0200
+++ b/doc/man/Makefile.am 2025-06-13 15:14:59.858832219 +0200
@@ -22,6 +22,12 @@
endif # HAVE_LSM
endif # ENABLE_MAN
+if USE_VENDORDIR
+VENDORDIR_COND = with_vendordir
+else
+VENDORDIR_COND = without_vendordir
+endif
+
udisksctl.1 : udisksctl.xml
$(XSLTPROC) -path "$(builddir)/.." -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
@@ -40,7 +46,8 @@
$(SED) "s|\$${prefix}|${prefix}|" $< > $@
udisks2.conf.5 : udisks2.conf.5.xml
- $(XSLTPROC) -path "$(builddir)/.." -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
+ $(XSLTPROC) --stringparam profile.condition "$(VENDORDIR_COND)" -path "$(builddir)/.." \
+ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
if HAVE_LSM
# Hack: Autotools expand @sysconfdir@ as %{prefix}/etc; that's why we sed this
@@ -49,7 +56,8 @@
$(SED) "s|\$${prefix}|${prefix}|" $< > $@
udisks2_lsm.conf.5 : udisks2_lsm.conf.5.xml
- $(XSLTPROC) -path "$(builddir)/.." -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
+ $(XSLTPROC) --stringparam profile.condition "$(VENDORDIR_COND)" -path "$(builddir)/.." \
+ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
endif # HAVE_LSM
EXTRA_DIST = \
diff -ur a/doc/man/udisks2.conf.5.xml.in.in b/doc/man/udisks2.conf.5.xml.in.in
--- a/doc/man/udisks2.conf.5.xml.in.in 2023-09-07 14:11:56.000000000 +0200
+++ b/doc/man/udisks2.conf.5.xml.in.in 2025-06-13 15:14:59.858832219 +0200
@@ -37,6 +37,16 @@
the configuration file placed at
<emphasis>@sysconfdir@/udisks2/udisks2.conf</emphasis>.
</para>
+
+ <para condition="with_vendordir">
+ If this file does not exist, the definitions are taken from the files
+ <emphasis>@vendordir@/udisks2/udisks2.conf</emphasis>,
+ <emphasis>@vendordir@/udisks2/udisks2.d/*</emphasis> and
+ <emphasis>@sysconfdir@/udisks2/udisks2.d/*</emphasis> in that order.
+ If <emphasis>@sysconfdir@/udisks2/udisks2.d/@filename@</emphasis> exists, then
+ <emphasis>@vendordir@/udisks2/udisks2.d/@filename@</emphasis> will not be used.
+ </para>
+
</refsect1>
<refsect1>
diff -ur a/doc/man/udisks2_lsm.conf.5.xml.in.in b/doc/man/udisks2_lsm.conf.5.xml.in.in
--- a/doc/man/udisks2_lsm.conf.5.xml.in.in 2023-09-07 14:11:56.000000000 +0200
+++ b/doc/man/udisks2_lsm.conf.5.xml.in.in 2025-06-13 15:14:59.858832219 +0200
@@ -35,6 +35,12 @@
Some storage systems require extra configuration in
<emphasis>@sysconfdir@/udisks2/modules.conf.d/udisks2_lsm.conf</emphasis>.
</para>
+
+ <para condition="with_vendordir">
+ If this file does not exist, the definitions are taken from the files
+ <emphasis>@vendordir@/udisks2/modules.conf.d/udisks2_lsm.conf</emphasis>.
+ </para>
+
</refsect1>
<refsect1>
diff -ur a/modules/lsm/lsm_data.c b/modules/lsm/lsm_data.c
--- a/modules/lsm/lsm_data.c 2023-09-07 14:11:56.000000000 +0200
+++ b/modules/lsm/lsm_data.c 2025-06-13 15:14:59.862832219 +0200
@@ -33,6 +33,7 @@
#include <libconfig.h>
#include <string.h>
#include <stdint.h>
+#include <sys/stat.h>
#define _STD_LSM_SIM_URI "sim://"
#define _STD_LSM_HPSA_URI "hpsa://"
@@ -177,8 +178,21 @@
}
}
+#ifdef USE_VENDORDIR
static char *
-_lsm_get_conf_path (UDisksDaemon *daemon)
+_lsm_get_vendor_conf_path (void)
+{
+ /* This should give us '<vendordir>/modules.conf.d/udisks2_lsm.conf' */
+ return g_build_filename (_PATH_VENDORDIR,
+ PROJECT_SYSCONF_DIR,
+ _STD_LSM_CONF_PATH,
+ _STD_LSM_CONF_FILE,
+ NULL);
+}
+#endif
+
+static char *
+_lsm_get_sys_conf_path (UDisksDaemon *daemon)
{
UDisksConfigManager *config_manager;
@@ -211,6 +225,9 @@
char *conf_path;
int i;
gboolean ret = TRUE;
+#ifdef USE_VENDORDIR
+ struct stat st;
+#endif
udisks_debug ("LSM: loading config file");
@@ -221,7 +238,16 @@
}
/* Get the abs config file path. */
- conf_path = _lsm_get_conf_path (daemon);
+ conf_path = _lsm_get_sys_conf_path (daemon);
+
+#ifdef USE_VENDORDIR
+ if (stat(conf_path, &st) != 0)
+ {
+ /* Trying if there is a vendor defined configuration file */
+ g_free (conf_path);
+ conf_path = _lsm_get_vendor_conf_path();
+ }
+#endif
config_init (&cfg);
if (config_read_file (&cfg, conf_path) != CONFIG_TRUE)
diff -ur a/modules/lsm/Makefile.am b/modules/lsm/Makefile.am
--- a/modules/lsm/Makefile.am 2023-09-07 14:11:56.000000000 +0200
+++ b/modules/lsm/Makefile.am 2025-06-13 15:14:59.862832219 +0200
@@ -20,8 +20,13 @@
$(GIO_CFLAGS) \
$(GUDEV_CFLAGS) \
$(BLOCKDEV_CFLAGS) \
- $(WARN_CFLAGS) \
- $(NULL)
+ $(WARN_CFLAGS)
+if USE_VENDORDIR
+CPPFLAGS += \
+ -D_PATH_VENDORDIR=\"${vendordir}\"
+endif
+
+CPPFLAGS += $(NULL)
if ENABLE_DAEMON
diff -ur a/src/Makefile.am b/src/Makefile.am
--- a/src/Makefile.am 2023-09-07 14:11:56.000000000 +0200
+++ b/src/Makefile.am 2025-06-13 15:14:59.874832218 +0200
@@ -27,8 +27,13 @@
$(GIO_CFLAGS) \
$(GMODULE_CFLAGS) \
$(BLOCKDEV_CFLAGS) \
- $(WARN_CFLAGS) \
- $(NULL)
+ $(WARN_CFLAGS)
+if USE_VENDORDIR
+CPPFLAGS += \
+ -D_PATH_VENDORDIR=\"${vendordir}\"
+endif
+
+CPPFLAGS += $(NULL)
# ------------------------------------------------------------------------------
@@ -148,8 +153,13 @@
$(LIBELOGIND_LIBS) \
$(PART_LDFLAGS) \
$(SWAP_LIBS) \
- $(top_builddir)/udisks/libudisks2.la \
- $(NULL)
+ $(top_builddir)/udisks/libudisks2.la
+
+if HAVE_ECONF
+libudisks_daemon_la_LIBADD += -leconf
+endif
+
+libudisks_daemon_la_LIBADD += $(NULL)
# ------------------------------------------------------------------------------
diff -ur a/src/udisksconfigmanager.c b/src/udisksconfigmanager.c
--- a/src/udisksconfigmanager.c 2023-09-07 14:11:56.000000000 +0200
+++ b/src/udisksconfigmanager.c 2025-06-13 15:14:59.874832218 +0200
@@ -22,6 +22,10 @@
#include <string.h>
#include <ctype.h>
+#include <stdio.h>
+#if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR)
+#include <libeconf.h>
+#endif
#include "udiskslogging.h"
#include "udisksdaemontypes.h"
@@ -91,6 +95,43 @@
}
}
+static void
+set_module_list (GList **out_modules, gchar **modules)
+{
+ gchar **modules_tmp = modules;
+
+ for (gchar * module_i = *modules_tmp; module_i; module_i = *++modules_tmp)
+ {
+ g_strstrip (module_i);
+ if (! udisks_module_validate_name (module_i) && !g_str_equal (module_i, MODULES_ALL_ARG))
+ {
+ g_warning ("Invalid module name '%s' specified in the config file.",
+ module_i);
+ continue;
+ }
+ *out_modules = g_list_append (*out_modules, g_strdup (module_i));
+ }
+}
+
+static void
+set_load_preference (UDisksModuleLoadPreference *out_load_preference, const gchar *load_preference)
+{
+ /* Check the key value */
+ if (g_ascii_strcasecmp (load_preference, "ondemand") == 0)
+ {
+ *out_load_preference = UDISKS_MODULE_LOAD_ONDEMAND;
+ }
+ else if (g_ascii_strcasecmp (load_preference, "onstartup") == 0)
+ {
+ *out_load_preference = UDISKS_MODULE_LOAD_ONSTARTUP;
+ }
+ else
+ {
+ udisks_warning ("Unknown value used for 'modules_load_preference': %s; defaulting to 'ondemand'",
+ load_preference);
+ }
+}
+
static const gchar *
get_encryption_config (const gchar *encryption)
{
@@ -138,6 +179,136 @@
}
}
+#if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR)
+
+static void
+parse_config_file (UDisksConfigManager *manager,
+ UDisksModuleLoadPreference *out_load_preference,
+ const gchar **out_encryption,
+ GList **out_modules)
+{
+ gchar *conf_dir;
+ gchar *conf_filename;
+ gchar *load_preference;
+ gchar *encryption;
+ gchar **modules;
+ econf_err econf_ret = ECONF_SUCCESS;
+ econf_file *key_file = NULL;
+ gchar *val;
+
+ /* Get modules and means of loading */
+ conf_dir = g_build_path (G_DIR_SEPARATOR_S,
+ PACKAGE_SYSCONF_DIR,
+ PROJECT_SYSCONF_DIR,
+ NULL);
+
+ if (manager->uninstalled || !g_str_equal(conf_dir,manager->config_dir))
+ {
+ /* Taking this file only and not parsing e.g. vendor files */
+ conf_filename = g_build_filename (G_DIR_SEPARATOR_S,
+ manager->config_dir,
+ PACKAGE_NAME_UDISKS2 ".conf",
+ NULL);
+ udisks_debug ("Loading configuration file: %s", conf_filename);
+ if ((econf_ret = econf_readFile (&key_file, conf_filename, "=", "#")))
+ {
+ udisks_warning ("Error cannot read file %s: %s", conf_filename, econf_errString(econf_ret));
+ }
+ g_free (conf_filename);
+ }
+ else
+ {
+ /* Parsing vendor, run and syscconf dir */
+ udisks_debug ("Loading configuration files (%s.conf)", PACKAGE_NAME_UDISKS2);
+
+ if (econf_ret == ECONF_SUCCESS)
+ {
+ econf_ret = econf_readConfig(&key_file,
+ PROJECT_SYSCONF_DIR,
+ _PATH_VENDORDIR,
+ PACKAGE_NAME_UDISKS2,
+ ".conf",
+ "=",
+ "#");
+ }
+ else
+ {
+ udisks_warning ("Error cannot read file %s.conf: %s",
+ PACKAGE_NAME_UDISKS2, econf_errString(econf_ret));
+ }
+ }
+
+ if (econf_ret != ECONF_SUCCESS)
+ return;
+
+ if (out_modules != NULL)
+ {
+ /* Read the list of modules to load. */
+ econf_ret = econf_getStringValue (key_file, MODULES_GROUP_NAME, MODULES_KEY, &val);
+ if (econf_ret != ECONF_SUCCESS)
+ {
+ if (econf_ret != ECONF_NOKEY) {
+ udisks_warning ("Error cannot read value %s/%s: %s",
+ MODULES_GROUP_NAME, MODULES_KEY, econf_errString(econf_ret));
+ }
+ }
+ else
+ {
+ modules = g_strsplit (val, ",", -1);
+ if (modules)
+ {
+ set_module_list (out_modules, modules);
+ g_strfreev (modules);
+ }
+ g_free(val);
+ }
+ }
+
+ if (out_load_preference != NULL)
+ {
+ /* Read the load preference configuration option. */
+ econf_ret = econf_getStringValue (key_file, MODULES_GROUP_NAME, MODULES_LOAD_PREFERENCE_KEY,
+ &load_preference);
+ if (econf_ret != ECONF_SUCCESS) {
+ if (econf_ret != ECONF_NOKEY)
+ udisks_warning ("Error cannot read value%s/%s: %s",
+ MODULES_GROUP_NAME, MODULES_LOAD_PREFERENCE_KEY, econf_errString(econf_ret));
+ }
+ else
+ {
+ if (load_preference)
+ {
+ set_load_preference (out_load_preference, load_preference);
+ g_free (load_preference);
+ }
+ }
+ }
+
+ if (out_encryption != NULL)
+ {
+ /* Read the encryption option. */
+ econf_ret = econf_getStringValue (key_file, DEFAULTS_GROUP_NAME, DEFAULTS_ENCRYPTION_KEY,
+ &encryption);
+ if (econf_ret != ECONF_SUCCESS) {
+ if (econf_ret != ECONF_NOKEY)
+ udisks_warning ("Error cannot read value %s/%s: %s",
+ DEFAULTS_GROUP_NAME, DEFAULTS_ENCRYPTION_KEY, econf_errString(econf_ret));
+ }
+ else
+ {
+ if (encryption)
+ {
+ *out_encryption = get_encryption_config (encryption);
+ g_free (encryption);
+ }
+ }
+ }
+
+ econf_free (key_file);
+}
+
+#else /* using vendordir and libeconf */
+
static void
parse_config_file (UDisksConfigManager *manager,
UDisksModuleLoadPreference *out_load_preference,
@@ -148,9 +319,7 @@
gchar *conf_filename;
gchar *load_preference;
gchar *encryption;
- gchar *module_i;
gchar **modules;
- gchar **modules_tmp;
/* Get modules and means of loading */
conf_filename = g_build_filename (G_DIR_SEPARATOR_S,
@@ -171,18 +340,7 @@
/* Read the list of modules to load. */
if (modules)
{
- modules_tmp = modules;
- for (module_i = *modules_tmp; module_i; module_i = *++modules_tmp)
- {
- g_strstrip (module_i);
- if (! udisks_module_validate_name (module_i) && !g_str_equal (module_i, MODULES_ALL_ARG))
- {
- g_warning ("Invalid module name '%s' specified in the %s config file.",
- module_i, conf_filename);
- continue;
- }
- *out_modules = g_list_append (*out_modules, g_strdup (module_i));
- }
+ set_module_list (out_modules, modules);
g_strfreev (modules);
}
}
@@ -193,28 +351,14 @@
load_preference = g_key_file_get_string (config_file, MODULES_GROUP_NAME, MODULES_LOAD_PREFERENCE_KEY, NULL);
if (load_preference)
{
- /* Check the key value */
- if (g_ascii_strcasecmp (load_preference, "ondemand") == 0)
- {
- *out_load_preference = UDISKS_MODULE_LOAD_ONDEMAND;
- }
- else if (g_ascii_strcasecmp (load_preference, "onstartup") == 0)
- {
- *out_load_preference = UDISKS_MODULE_LOAD_ONSTARTUP;
- }
- else
- {
- udisks_warning ("Unknown value used for 'modules_load_preference': %s; defaulting to 'ondemand'",
- load_preference);
- }
-
+ set_load_preference (out_load_preference, load_preference);
g_free (load_preference);
}
}
if (out_encryption != NULL)
{
- /* Read the load preference configuration option. */
+ /* Read the encryption option. */
encryption = g_key_file_get_string (config_file, DEFAULTS_GROUP_NAME, DEFAULTS_ENCRYPTION_KEY, NULL);
if (encryption)
{
@@ -231,6 +375,7 @@
g_key_file_free (config_file);
g_free (conf_filename);
}
+#endif
static void
udisks_config_manager_constructed (GObject *object)
diff -ur a/udisks/Makefile.am b/udisks/Makefile.am
--- a/udisks/Makefile.am 2023-09-07 14:11:56.000000000 +0200
+++ b/udisks/Makefile.am 2025-06-13 15:15:29.930832035 +0200
@@ -5,7 +5,11 @@
NULL =
if ENABLE_DAEMON
+if USE_VENDORDIR
+moduleconfdir = $(vendordir)/udisks2/
+else
moduleconfdir = $(sysconfdir)/udisks2/
+endif
moduleconf_DATA = udisks2.conf mount_options.conf
endif
diff -ur a/udisks/modules.conf.d/Makefile.am b/udisks/modules.conf.d/Makefile.am
--- a/udisks/modules.conf.d/Makefile.am 2023-09-07 14:11:56.000000000 +0200
+++ b/udisks/modules.conf.d/Makefile.am 2025-06-13 15:15:14.250832131 +0200
@@ -1,6 +1,9 @@
## Process this file with automake to produce Makefile.in
-
+if USE_VENDORDIR
+moduleconfdir = $(vendordir)/udisks2/modules.conf.d
+else
moduleconfdir = $(sysconfdir)/udisks2/modules.conf.d
+endif
if ENABLE_DAEMON