summaryrefslogtreecommitdiffstats
path: root/src/confdb
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2016-04-19 11:58:35 -0400
committerJakub Hrozek <jhrozek@redhat.com>2016-05-11 11:34:14 +0200
commit59744cff6edb106ae799b2321cb8731edadf409a (patch)
treebe17c08de80495f9e9e3043552979cea9803dd1c /src/confdb
parent98dbaea0a00c60972b991755a44c51964dfb7877 (diff)
downloadsssd-59744cff6edb106ae799b2321cb8731edadf409a.tar.gz
sssd-59744cff6edb106ae799b2321cb8731edadf409a.tar.xz
sssd-59744cff6edb106ae799b2321cb8731edadf409a.zip
CONFIG: Use default config when none provided
This patch makes SSSD possibly useful "out of the box" by allowing packagers to provide a default config file located in $LIBDIR/sssd/conf that will be copied by the monitor to /etc/sssd if no file already exists in that location. This will make it possible to have SSSD set up to have distribution-specific default configuration, such as enabling the proxy provider to cache /etc/passwd (such as in the provided example in this patch). Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/confdb')
-rw-r--r--src/confdb/confdb.h1
-rw-r--r--src/confdb/confdb_setup.c40
2 files changed, 37 insertions, 4 deletions
diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
index b90ced2bb..a9b1c4362 100644
--- a/src/confdb/confdb.h
+++ b/src/confdb/confdb.h
@@ -40,6 +40,7 @@
#define CONFDB_DEFAULT_CFG_FILE_VER 2
#define CONFDB_FILE "config.ldb"
+#define SSSD_DEFAULT_CONFIG_FILE SSSD_DEFAULT_CONF_DIR"/sssd.conf"
#define SSSD_CONFIG_FILE SSSD_CONF_DIR"/sssd.conf"
#define SSSD_MIN_ID 1
#define SSSD_LOCAL_MINID 1000
diff --git a/src/confdb/confdb_setup.c b/src/confdb/confdb_setup.c
index 694a7f016..dfdcae566 100644
--- a/src/confdb/confdb_setup.c
+++ b/src/confdb/confdb_setup.c
@@ -21,12 +21,14 @@
#include "config.h"
#include <sys/stat.h>
+#include <unistd.h>
#include "util/util.h"
#include "db/sysdb.h"
#include "confdb.h"
#include "confdb_private.h"
#include "confdb_setup.h"
#include "util/sss_ini.h"
+#include "tools/tools_util.h"
int confdb_test(struct confdb_ctx *cdb)
@@ -159,11 +161,41 @@ int confdb_init_db(const char *config_file, struct confdb_ctx *cdb)
DEBUG(SSSDBG_TRACE_FUNC,
"sss_ini_config_file_open failed: %s [%d]\n", strerror(ret),
ret);
- if (ret == ENOENT) {
- /* sss specific error denoting missing configuration file */
- ret = ERR_MISSING_CONF;
+ if (ret != ENOENT) {
+ /* Anything other than ENOENT is unrecoverable */
+ goto done;
+ } else {
+ /* Copy the default configuration file to the standard location
+ * and then retry
+ */
+ ret = copy_file_secure(SSSD_DEFAULT_CONFIG_FILE,
+ SSSD_CONFIG_FILE,
+ 0600,
+ getuid(),
+ getgid(),
+ false);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_FATAL_FAILURE,
+ "Could not copy default configuration: %s",
+ sss_strerror(ret));
+ /* sss specific error denoting missing configuration file */
+ ret = ERR_MISSING_CONF;
+ goto done;
+ }
+
+ /* Try again */
+ ret = sss_ini_config_file_open(init_data, config_file);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_TRACE_FUNC,
+ "sss_ini_config_file_open(default) failed: %s [%d]\n",
+ strerror(ret), ret);
+ if (ret == ENOENT) {
+ /* sss specific error denoting missing configuration file */
+ ret = ERR_MISSING_CONF;
+ }
+ goto done;
+ }
}
- goto done;
}
ret = sss_ini_config_access_check(init_data);