Skip to content

Commit 36cc0f7

Browse files
committed
confdb: Add UsrEtc support
Vendor provided configuration is installed in /usr/etc/sssd/sssd.conf. Users can override it creating /etc/sssd/sssd.conf, or override defaults dropping config snippets to /etc/sssd/conf.d/ Doc: https://en.opensuse.org/openSUSE:Packaging_UsrEtc Doc: https://github.com/uapi-group/specifications/blob/main/specs/configuration_files_specification.md Signed-off-by: Samuel Cabrero <scabrero@suse.com>
1 parent 18d615a commit 36cc0f7

File tree

9 files changed

+95
-9
lines changed

9 files changed

+95
-9
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,7 @@ libsss_util_la_SOURCES = \
12921292
src/util/sss_chain_id.c \
12931293
src/util/sss_time.c \
12941294
src/util/sss_prctl.c \
1295+
src/util/sss_config.c \
12951296
$(NULL)
12961297
libsss_util_la_CFLAGS = \
12971298
$(AM_CFLAGS) \

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ WITH_TMPFILES_DIR
201201
WITH_UDEV_RULES_DIR
202202
WITH_SYSTEMD_SYSUSERS_DIR
203203
WITH_LDB_MODULES_PATH
204+
WITH_VENDOR_DIR
204205

205206
m4_include([src/external/pkg.m4])
206207
m4_include([src/external/libpopt.m4])

src/conf_macros.m4

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,3 +963,16 @@ AS_IF([test x$enable_gss_spnego_for_zero_maxssf = xyes],
963963
[whether to use GSS-SPNEGO if maxssf is 0 (zero)]))
964964

965965
AC_DEFINE_UNQUOTED(KRB5_KDC_RUNDIR, RUNDIR "/krb5kdc", [Path to KRB5 KDC run directory])
966+
967+
AC_DEFUN([WITH_VENDOR_DIR],
968+
[ AC_ARG_WITH([vendordir],
969+
[AS_HELP_STRING([--with-vendordir=DIR],
970+
[Directory for distribution provided configuration files])],
971+
[vendordir=$withval],
972+
[with_vendordir=no])
973+
AS_IF([test x"$with_vendordir" != xno],
974+
[
975+
AC_DEFINE([USE_VENDORDIR], 1, [whether to use distribution provided configuration files]),
976+
AC_DEFINE_UNQUOTED([SSSD_VENDOR_DIR], "$with_vendordir", [Directory for distribution provided configuration files])
977+
])
978+
])

src/confdb/confdb.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#define CONFDB_DEFAULT_CONFIG_DIR SSSD_CONF_DIR"/"CONFDB_DEFAULT_CONFIG_DIR_NAME
4848
#define SSSD_MIN_ID 1
4949
#define CONFDB_DEFAULT_SHELL_FALLBACK "/bin/sh"
50+
#if defined(USE_VENDORDIR)
51+
#define SSSD_VENDOR_CONFIG_FILE SSSD_VENDOR_DIR"/"SSSD_CONFIG_FILE_NAME
52+
#endif
5053

5154
/* Configuration options */
5255

src/monitor/monitor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ int main(int argc, const char *argv[])
17241724
int opt_version = 0;
17251725
char *opt_config_file = NULL;
17261726
const char *opt_logger = NULL;
1727-
char *config_file = NULL;
1727+
const char *config_file = NULL;
17281728
int flags = FLAGS_NO_WATCHDOG;
17291729
struct main_context *main_ctx;
17301730
TALLOC_CTX *tmp_ctx;
@@ -1812,7 +1812,7 @@ int main(int argc, const char *argv[])
18121812
if (opt_config_file) {
18131813
config_file = talloc_strdup(tmp_ctx, opt_config_file);
18141814
} else {
1815-
config_file = talloc_strdup(tmp_ctx, SSSD_CONFIG_FILE);
1815+
config_file = sss_get_default_config_file(tmp_ctx);
18161816
}
18171817
if (config_file == NULL) {
18181818
ret = 2;

src/responder/kcm/kcm.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,14 @@ int main(int argc, const char *argv[])
395395
debug_log_file = "sssd_kcm";
396396
DEBUG_INIT(debug_level, opt_logger);
397397

398-
if (opt_config_file == NULL) {
399-
config_file = SSSD_CONFIG_FILE;
398+
if (opt_config_file) {
399+
config_file = talloc_strdup(tmp_ctx, opt_config_file);
400400
} else {
401-
config_file = opt_config_file;
401+
config_file = sss_get_default_config_file(tmp_ctx);
402+
}
403+
if (config_file == NULL) {
404+
TALLOC_FREE(tmp_ctx);
405+
return 2;
402406
}
403407

404408
/* Parse config file, fail if cannot be done */

src/tools/sssctl/sssctl_config.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ errno_t sssctl_config_check(struct sss_cmdline *cmdline,
4545
TALLOC_CTX *tmp_ctx = NULL;
4646
const char *config_path = NULL;
4747
const char *config_snippet_path = NULL;
48+
const char *config_file = NULL;
4849
struct poptOption long_options[] = {
4950
SSSD_CONFIG_OPTS(config_path)
5051
{"snippet", 's', POPT_ARG_STRING, &config_snippet_path,
@@ -69,20 +70,26 @@ errno_t sssctl_config_check(struct sss_cmdline *cmdline,
6970
goto done;
7071
}
7172

72-
if (config_path == NULL) {
73-
config_path = SSSD_CONFIG_FILE;
73+
if (config_path) {
74+
config_file = talloc_strdup(tmp_ctx, config_path);
75+
} else {
76+
config_file = sss_get_default_config_file(tmp_ctx);
77+
}
78+
if (config_file == NULL) {
79+
ret = ENOMEM;
80+
goto done;
7481
}
7582

7683
if (config_snippet_path == NULL) {
7784
config_snippet_path = CONFDB_DEFAULT_CONFIG_DIR;
7885
}
7986

8087
ret = sss_ini_read_sssd_conf(init_data,
81-
config_path,
88+
config_file,
8289
config_snippet_path);
8390

8491
if (ret == ERR_INI_EMPTY_CONFIG) {
85-
PRINT("File %1$s does not exist.\n", config_path);
92+
PRINT("File %1$s does not exist.\n", config_file);
8693
PRINT("There is no configuration.\n");
8794
ret = ERR_INI_OPEN_FAILED;
8895
goto done;

src/util/sss_config.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
SSSD
3+
4+
sss_config.c
5+
6+
Authors:
7+
Samuel Cabrero <scabrero@suse.com>
8+
9+
Copyright (C) 2026 SUSE LINUX GmbH, Nuernberg, Germany.
10+
11+
This program is free software; you can redistribute it and/or modify
12+
it under the terms of the GNU General Public License as published by
13+
the Free Software Foundation; either version 3 of the License, or
14+
(at your option) any later version.
15+
16+
This program is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
GNU General Public License for more details.
20+
21+
You should have received a copy of the GNU General Public License
22+
along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
25+
#include "util/util.h"
26+
27+
#ifdef USE_VENDORDIR
28+
#include <sys/stat.h>
29+
#endif
30+
31+
const char *sss_get_default_config_file(TALLOC_CTX *mem_ctx) {
32+
char *config_file = NULL;
33+
#if defined(USE_VENDORDIR)
34+
struct stat stats = {0};
35+
#endif /* USE_VENDORDIR */
36+
37+
config_file = talloc_strdup(mem_ctx, SSSD_CONFIG_FILE);
38+
if (config_file == NULL) {
39+
return NULL;
40+
}
41+
42+
#if defined(USE_VENDORDIR)
43+
if (stat(config_file, &stats) < 0 && errno == ENOENT) {
44+
TALLOC_FREE(config_file);
45+
config_file = talloc_strdup(mem_ctx, SSSD_VENDOR_CONFIG_FILE);
46+
if (config_file == NULL) {
47+
return NULL;
48+
}
49+
DEBUG(SSSDBG_CONF_SETTINGS, "Using vendor config file %s\n", config_file);
50+
}
51+
#endif /* USE_VENDORDIR */
52+
53+
return config_file;
54+
}

src/util/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,4 +866,7 @@ errno_t sss_parse_dns_uri(TALLOC_CTX *ctx,
866866
const char *uri,
867867
struct sss_parsed_dns_uri **_parsed_uri);
868868

869+
/* from sss_config.c */
870+
const char *sss_get_default_config_file(TALLOC_CTX *mem_ctx);
871+
869872
#endif /* __SSSD_UTIL_H__ */

0 commit comments

Comments
 (0)