On (01/05/14 19:20), Pavel Březina wrote:
On 04/22/2014 11:21 AM, Lukas Slebodnik wrote:
>On (22/04/14 10:29), Pavel Březina wrote:
>>Hi,
>>I'm sending some patches that I'll use for OpenLMI provider. It
>>supports few modifications of sssd.conf through augeas.
>>
>>For the moment, I think we should not bound to any particular API so
>>even though I made it a separate object, I don't have any intentions
>>to make it publicly usable library.
>>
>>This code will be used from D-Bus responder. I may extend the API if needed.
>>
>>Unit tests are attached.
>
>
>src/util/sss_config.c:203:9: error: variable 'ret' is used uninitialized
whenever 'if' condition
> is true [-Werror,-Wsometimes-uninitialized]
> if (option_path == NULL) {
> ^~~~~~~~~~~~~~~~~~~
>src/util/sss_config.c:233:12: note: uninitialized use occurs here
> return ret;
> ^~~
>>+ goto done;
>>+ }
>You added new build time dependency, but spec file was not change.
>
>Could be this optional dependency like a cifs-idmap-plugin?
> src/external/cifsidmap.m4
>
>You created new dynamic library(module) but it was not added into dlopen tests.
>
>LS
Hi,
I'm sending new version with augeas as optional dependency. The
config lib is build by default and can be disabled by
--disable-config-lib.
From 06a8e861c28b311e629bc425bb603b9f3205256d Mon Sep 17 00:00:00
2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina(a)redhat.com>
Date: Fri, 18 Apr 2014 17:23:16 +0200
Subject: [PATCH 1/3] sss_config: the code
---
src/util/sss_config.c | 509 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/util/sss_config.h | 71 +++++++
2 files changed, 580 insertions(+)
create mode 100644 src/util/sss_config.c
create mode 100644 src/util/sss_config.h
diff --git a/src/util/sss_config.c b/src/util/sss_config.c
new file mode 100644
index 0000000000000000000000000000000000000000..9654db535cf50e2bc6ec39c66b04af757318d345
--- /dev/null
+++ b/src/util/sss_config.c
@@ -0,0 +1,509 @@
+/*
+ Authors:
+ Pavel Březina <pbrezina(a)redhat.com>
+
+ Copyright (C) 2014 Red Hat
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <
http://www.gnu.org/licenses/>.
+*/
+
+#include <augeas.h>
+#include <talloc.h>
+#include <string.h>
+#include "util/sss_config.h"
+
+#define PATH_SECTION "/files/%s/target[. = \"%s\"]"
+#define PATH_OPTION PATH_SECTION "/%s"
+
+#define build_section_path(mem_ctx, config_ctx, section) \
+ talloc_asprintf(mem_ctx, PATH_SECTION, config_ctx->file, section)
+
+#define build_option_path(mem_ctx, config_ctx, section, option) \
+ talloc_asprintf(mem_ctx, PATH_OPTION, config_ctx->file, section, option)
+
+struct sss_config_ctx
+{
+ augeas *auges_ctx;
+ const char *file;
+};
+
+static errno_t
+sss_config_set_option(struct sss_config_ctx *ctx,
+ const char *section,
+ const char *option,
+ const char *value)
+{
+ TALLOC_CTX *tmp_ctx = NULL;
+ char *target_path = NULL;
+ char *option_path = NULL;
+ errno_t ret;
+ int aug_ret;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ target_path = build_section_path(tmp_ctx, ctx, section);
+ if (target_path == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ option_path = build_option_path(tmp_ctx, ctx, section, option);
+ if (option_path == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ /* Set configuration option:
+ *
+ * # make sure the section exists
+ * set /files/$file/target[. = "$section"] $section
+ *
+ * # set value
+ * set /files/$file/target[. = "$section"]/$option $value
+ */
+
+ aug_ret = aug_set(ctx->auges_ctx, target_path, section);
+ if (aug_ret != 0) {
+ ret = EIO;
+ goto done;
+ }
+
+ aug_ret = aug_set(ctx->auges_ctx, option_path, value);
+ if (aug_ret != 0) {
+ ret = EIO;
+ goto done;
+ }
+
+ ret = EOK;
+
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
+static errno_t
+sss_config_rm_option(struct sss_config_ctx *ctx,
+ const char *section,
+ const char *option)
+{
+ TALLOC_CTX *tmp_ctx = NULL;
+ char *option_path = NULL;
+ errno_t ret;
+ int aug_ret;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ option_path = build_option_path(tmp_ctx, ctx, section, option);
+ if (option_path == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ /* Remove configuration option:
+ *
+ * rm /files/$file/target[. = "$section"]/$option
+ */
+
+ aug_ret = aug_rm(ctx->auges_ctx, option_path);
+ if (aug_ret != 1) {
+ ret = EIO;
+ goto done;
+ }
+
+ ret = EOK;
+
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
+static errno_t
+sss_config_set_list(struct sss_config_ctx *ctx,
+ const char *section,
+ const char *option,
+ char **list)
+{
+ TALLOC_CTX *tmp_ctx = NULL;
+ char *value = NULL;
+ errno_t ret;
+ int i;
+
+ if (list == NULL) {
+ return EOK;
Could you explain why is EOK returned?
+ }
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ if (list[0] == NULL) {
+ ret = sss_config_rm_option(ctx, section, option);
+ goto done;
+ }
+
+ value = talloc_strdup(tmp_ctx, list[0]);
+ if (value == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ for (i = 1; list[i] != NULL; i++) {
+ value = talloc_asprintf_append(value, ", %s", list[i]);
+ if (value == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+ }
+
+ ret = sss_config_set_option(ctx, section, option, value);
+
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
+static errno_t
+sss_config_get_list(TALLOC_CTX *mem_ctx,
+ struct sss_config_ctx *ctx,
+ const char *section,
+ const char *option,
+ char ***_list)
+{
+ TALLOC_CTX *tmp_ctx = NULL;
+ char *option_path = NULL;
+ const char *value = NULL;
+ char **list = NULL;
+ errno_t ret;
+ int aug_ret;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ option_path = build_option_path(tmp_ctx, ctx, section, option);
+ if (option_path == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ aug_ret = aug_get(ctx->auges_ctx, option_path, &value);
+ if (aug_ret == 0 || (aug_ret == 1 && (value == NULL || *value ==
'\0'))) {
+ /* option is not present, return empty list */
+ list = talloc_zero_array(tmp_ctx, char*, 1);
+ if (list == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = EOK;
+ goto done;
+ } else if (aug_ret != 1) {
+ /* error: more than one value found */
+ ret = EINVAL;
+ goto done;
+ }
+
+ ret = split_on_separator(tmp_ctx, value, ',', true, true, &list, NULL);
+ if (ret != EOK) {
+ goto done;
+ }
+
+ *_list = talloc_steal(mem_ctx, list);
+ ret = EOK;
+
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
+static errno_t
+sss_config_is_in_list(struct sss_config_ctx *ctx,
+ const char *section,
+ const char *option,
+ const char *value,
+ bool *_result)
+{
+ char **list = NULL;
+ errno_t ret;
+
+ ret = sss_config_get_list(ctx, ctx, section, option, &list);
+ if (ret != EOK) {
+ goto done;
+ }
+
+ *_result = string_in_list(value, list, true);
+
+done:
+ talloc_free(list);
+ return ret;
+}
+
+static errno_t
+sss_config_add_to_list(struct sss_config_ctx *ctx,
+ const char *section,
+ const char *option,
+ const char *value)
+{
+ TALLOC_CTX *tmp_ctx = NULL;
+ char **list = NULL;
+ errno_t ret;
+ bool result = false;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ ret = sss_config_get_list(tmp_ctx, ctx, section, option, &list);
+ if (ret != EOK) {
+ goto done;
+ }
+
+ result = string_in_list(value, list, true);
+ if (result == true) {
+ ret = EOK;
+ goto done;
+ }
+
+ ret = add_string_to_list(tmp_ctx, value, &list);
+ if (ret != EOK) {
+ goto done;
+ }
+
+ ret = sss_config_set_list(ctx, section, option, list);
+
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
+static errno_t
+sss_config_del_from_list(struct sss_config_ctx *ctx,
+ const char *section,
+ const char *option,
+ const char *value)
+{
+ TALLOC_CTX *tmp_ctx = NULL;
+ char **list = NULL;
+ errno_t ret;
+ bool found;
+ int i;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ ret = sss_config_get_list(tmp_ctx, ctx, section, option, &list);
+ if (ret != EOK) {
+ goto done;
+ }
+
+ if (list == NULL) {
+ goto done;
+ }
+
+ found = false;
+ for (i = 0; list[i] != NULL; i++) {
+ if (strcmp(list[i], value) == 0) {
+ found = true;
+ }
+
+ if (found) {
+ list[i] = list[i + 1];
+ }
+ }
+
+ ret = sss_config_set_list(ctx, section, option, list);
+
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
+static int sss_config_ctx_destructor(struct sss_config_ctx *ctx)
+{
+ if (ctx->auges_ctx != NULL) {
+ aug_close(ctx->auges_ctx);
+ ctx->auges_ctx = NULL;
+ }
+
+ return 0;
+}
+
+struct sss_config_ctx *
+sss_config_open(TALLOC_CTX *mem_ctx,
+ const char *root,
+ const char *file)
+{
+ struct sss_config_ctx *ctx = NULL;
+ errno_t ret;
+ int aug_ret;
+
+ ctx = talloc_zero(mem_ctx, struct sss_config_ctx);
+ if (ctx == NULL) {
+ return NULL;
+ }
+
+ talloc_set_destructor(ctx, sss_config_ctx_destructor);
+
+ ctx->auges_ctx = aug_init(root, NULL, AUG_NO_LOAD | AUG_NO_MODL_AUTOLOAD
+ | AUG_SAVE_BACKUP);
+ if (ctx->auges_ctx == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ctx->file = talloc_strdup(ctx, file);
+ if (ctx->file == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ /* Load configuration file
+ *
+ * set /augeas/load/sssd/lens sssd.lns
+ * set /augeas/load/sssd/incl $file
+ * load
+ */
+
+ aug_ret = aug_set(ctx->auges_ctx, "/augeas/load/sssd/lens",
"sssd.lns");
+ if (aug_ret != 0) {
+ ret = EIO;
+ goto done;
+ }
+
+ aug_ret = aug_set(ctx->auges_ctx, "/augeas/load/sssd/incl",
ctx->file);
+ if (aug_ret != 0) {
+ ret = EIO;
+ goto done;
+ }
+
+ aug_ret = aug_load(ctx->auges_ctx);
+ if (aug_ret != 0) {
+ ret = EIO;
+ goto done;
+ }
+
+ ret = EOK;
+
+done:
+ if (ret != EOK) {
+ talloc_free(ctx);
+ }
+
+ return ctx;
+}
+
+errno_t
+sss_config_save(struct sss_config_ctx *ctx)
+{
+ int aug_ret;
+
+ aug_ret = aug_save(ctx->auges_ctx);
+ if (aug_ret != 0) {
+ return EIO;
+ }
+
+ return EOK;
+}
+
+void
+sss_config_close(struct sss_config_ctx **_ctx)
+{
+ if (_ctx == NULL || *_ctx == NULL) {
+ return;
+ }
+
+ talloc_free(*_ctx);
+ *_ctx = NULL;
+}
+
+errno_t
+sss_config_set_debug_level(struct sss_config_ctx *ctx,
+ const char *section,
+ uint32_t level)
+{
+ char *level_str = NULL;
+ errno_t ret;
+
+ level_str = talloc_asprintf(ctx, "%#.4x", level);
+ if (level_str == NULL) {
+ return ENOMEM;
+ }
+
+ ret = sss_config_set_option(ctx, section, CONFDB_SERVICE_DEBUG_LEVEL,
+ level_str);
+
+ talloc_free(level_str);
+ return ret;
+}
+
+errno_t
+sss_config_service_is_enabled(struct sss_config_ctx *ctx,
+ const char *service,
+ bool *_result)
+{
+ return sss_config_is_in_list(ctx, "sssd", CONFDB_MONITOR_ACTIVE_SERVICES,
+ service, _result);
+}
+
+errno_t
+sss_config_service_enable(struct sss_config_ctx *ctx,
+ const char *service)
+{
+ return sss_config_add_to_list(ctx, "sssd", CONFDB_MONITOR_ACTIVE_SERVICES,
+ service);
+}
+
+errno_t
+sss_config_service_disable(struct sss_config_ctx *ctx,
+ const char *service)
+{
+ return sss_config_del_from_list(ctx, "sssd",
CONFDB_MONITOR_ACTIVE_SERVICES,
+ service);
+}
+
+errno_t
+sss_config_domain_is_enabled(struct sss_config_ctx *ctx,
+ const char *domain,
+ bool *_result)
+{
+ return sss_config_is_in_list(ctx, "sssd", CONFDB_MONITOR_ACTIVE_DOMAINS,
+ domain, _result);
+}
+
+errno_t
+sss_config_domain_enable(struct sss_config_ctx *ctx,
+ const char *domain)
+{
+ return sss_config_add_to_list(ctx, "sssd", CONFDB_MONITOR_ACTIVE_DOMAINS,
+ domain);
+}
+
+errno_t
+sss_config_domain_disable(struct sss_config_ctx *ctx,
+ const char *domain)
+{
+ return sss_config_del_from_list(ctx, "sssd",
CONFDB_MONITOR_ACTIVE_DOMAINS,
+ domain);
+}
diff --git a/src/util/sss_config.h b/src/util/sss_config.h
new file mode 100644
index 0000000000000000000000000000000000000000..b59f5fcf0e23e7a6c8543346c52fa06ae6041a3d
--- /dev/null
+++ b/src/util/sss_config.h
@@ -0,0 +1,71 @@
+/*
+ Authors:
+ Pavel Březina <pbrezina(a)redhat.com>
+
+ Copyright (C) 2014 Red Hat
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <
http://www.gnu.org/licenses/>.
+*/
+
+#ifndef SSS_CONFIG_H_
+#define SSS_CONFIG_H_
+
+#include <talloc.h>
+#include "util/util.h"
+
+struct sss_config_ctx;
+
+struct sss_config_ctx *
+sss_config_open(TALLOC_CTX *mem_ctx,
+ const char *root,
+ const char *file);
+
+errno_t
+sss_config_save(struct sss_config_ctx *ctx);
+
+void
+sss_config_close(struct sss_config_ctx **_ctx);
+
+errno_t
+sss_config_set_debug_level(struct sss_config_ctx *ctx,
+ const char *section,
+ uint32_t level);
+
+errno_t
+sss_config_service_is_enabled(struct sss_config_ctx *ctx,
+ const char *service,
+ bool *_result);
+
+errno_t
+sss_config_service_enable(struct sss_config_ctx *ctx,
+ const char *service);
+
+errno_t
+sss_config_service_disable(struct sss_config_ctx *ctx,
+ const char *service);
+
+errno_t
+sss_config_domain_is_enabled(struct sss_config_ctx *ctx,
+ const char *domain,
+ bool *_result);
+
+errno_t
+sss_config_domain_enable(struct sss_config_ctx *ctx,
+ const char *domain);
+
+errno_t
+sss_config_domain_disable(struct sss_config_ctx *ctx,
+ const char *domain);
+
+#endif /* SSS_CONFIG_H_ */
--
1.7.11.7
From 9dbc0dee60bff938fe03993c4953f9b76834815a Mon Sep 17 00:00:00
2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina(a)redhat.com>
Date: Mon, 21 Apr 2014 12:17:53 +0200
Subject: [PATCH 2/3] sss_config: build
---
Makefile.am | 15 +++++++++++++++
configure.ac | 5 +++++
contrib/sssd.spec.in | 2 ++
src/external/configlib.m4 | 12 ++++++++++++
src/external/libaugeas.m4 | 9 +++++++++
5 files changed, 43 insertions(+)
create mode 100644 src/external/configlib.m4
create mode 100644 src/external/libaugeas.m4
diff --git a/Makefile.am b/Makefile.am
index e58b9afd26bdc660b57039148de4bc2f56fde5d7..bdc399e17ec2961ac5c5d4f1e42cf5fc0f09711a
100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -437,6 +437,7 @@ dist_noinst_HEADERS = \
src/util/sss_ssh.h \
src/util/sss_ini.h \
src/util/sss_format.h \
+ src/util/sss_config.h \
src/util/refcount.h \
src/util/find_uid.h \
src/util/user_info_msg.h \
@@ -651,6 +652,20 @@ SSSD_INTERNAL_LTLIBS = \
libsss_debug.la \
libsss_child.la
+if BUILD_CONFIG_LIB
+pkglib_LTLIBRARIES += libsss_config.la
+libsss_config_la_SOURCES = \
+ src/util/sss_config.c
+libsss_config_la_CFLAGS = \
+ $(AM_CFLAGS) \
+ $(AUGEAS_CFLAGS)
+libsss_config_la_LIBADD = \
+ $(AUGEAS_LIBS) \
+ $(SSSD_INTERNAL_LTLIBS)
This library use talloc, it would be nice to link with
talloc directly and do
not rely on other libraries (libsss_util.so)
+libsss_config_la_LDFLAGS = \
+ avoid-version
+endif
+
lib_LTLIBRARIES = libipa_hbac.la libsss_idmap.la libsss_nss_idmap.la
pkgconfig_DATA += src/providers/ipa/ipa_hbac.pc
libipa_hbac_la_SOURCES = \
diff --git a/configure.ac b/configure.ac
index 41fa6496553336c73338459eaff639f10fde74f1..65008d41f55aa4e3c6a4b374ec907e729ab92c2e
100644
--- a/configure.ac
+++ b/configure.ac
@@ -159,6 +159,11 @@ m4_include([src/external/signal.m4])
m4_include([src/external/inotify.m4])
m4_include([src/external/libndr_nbt.m4])
m4_include([src/external/sasl.m4])
+m4_include([src/external/configlib.m4])
+
+if test x$build_config_lib = xyes; then
+ m4_include([src/external/libaugeas.m4])
+fi
WITH_UNICODE_LIB
if test x$unicode_lib = xlibunistring; then
diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in
index ef29970d08cc212eee58392a04f73bbaa5734d2d..7ad67acf2f29d498831ea71ef7fa0324bc2e9d5b
100644
--- a/contrib/sssd.spec.in
+++ b/contrib/sssd.spec.in
@@ -138,6 +138,7 @@ BuildRequires: systemd-devel
%if (0%{?with_cifs_utils_plugin} == 1)
BuildRequires: cifs-utils-devel
%endif
+BuildRequires: augeas-devel
# RHEL 5 is too old to support samba4 and the PAC responder
%if !0%{?is_rhel5}
@@ -574,6 +575,7 @@ rm -rf $RPM_BUILD_ROOT
%{_libdir}/%{name}/libsss_debug.so
%{_libdir}/%{name}/libsss_ldap_common.so
%{_libdir}/%{name}/libsss_util.so
+%{_libdir}/%{name}/libsss_config.so
# 3rd party application libraries
%{_libdir}/sssd/modules/libsss_autofs.so
diff --git a/src/external/configlib.m4 b/src/external/configlib.m4
new file mode 100644
index 0000000000000000000000000000000000000000..ad6c1a943e8d7bf0c38e9163241f0eb11792d82f
--- /dev/null
+++ b/src/external/configlib.m4
@@ -0,0 +1,12 @@
+AC_ARG_ENABLE([config-lib],
+ [AS_HELP_STRING([--disable-config-lib],
+ [do not build internal config library])],
+ [build_config_lib=$enableval],
+ [build_config_lib=yes])
+
+AM_CONDITIONAL([BUILD_CONFIG_LIB],
+ [test x$build_config_lib = xyes])
+
+AM_COND_IF([BUILD_CONFIG_LIB],
+ [AC_DEFINE_UNQUOTED(HAVE_CONFIG_LIB, 1,
+ [Build with internal config library])])
\ No newline at end of file
diff --git a/src/external/libaugeas.m4 b/src/external/libaugeas.m4
new file mode 100644
index 0000000000000000000000000000000000000000..6f8072e9ac2ad9ee968b4b935430dd73ac7e48f6
--- /dev/null
+++ b/src/external/libaugeas.m4
@@ -0,0 +1,9 @@
+AC_SUBST(AUGEAS_OBJ)
+AC_SUBST(AUGEAS_CFLAGS)
+AC_SUBST(AUGEAS_LIBS)
+
+PKG_CHECK_MODULES(AUGEAS,
+ augeas >= 1.0.0,
+ ,
+ AC_MSG_ERROR("Please install augeas-devel")
+ )
Could you change error message. It is not clear that this dependency is
optional. You should write some hint that this chcek can be disabled with
argument --disable-config-lib
checking for NDR_NBT... yes
checking for SASL... yes
checking for AUGEAS... no
configure: error: "Please install augeas-devel"
--
1.7.11.7
From 3bf71bd1f89a2888ceb23e63193f0cee2787a09d Mon Sep 17 00:00:00
2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina(a)redhat.com>
Date: Mon, 21 Apr 2014 19:44:52 +0200
Subject: [PATCH 3/3] sss_config: unit tests
---
Makefile.am | 18 +-
src/tests/sss_config-tests.c | 806 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 823 insertions(+), 1 deletion(-)
create mode 100644 src/tests/sss_config-tests.c
diff --git a/Makefile.am b/Makefile.am
index bdc399e17ec2961ac5c5d4f1e42cf5fc0f09711a..47b6b8e4f2e805c489ce4793946cda15c265ce5e
100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -149,7 +149,8 @@ if HAVE_CHECK
responder_socket_access-tests \
safe-format-tests \
sbus_tests \
- sbus_codegen_tests
+ sbus_codegen_tests \
+ sss_config-tests
if BUILD_SSH
non_interactive_check_based_tests += sysdb_ssh-tests
@@ -1414,6 +1415,21 @@ sbus_codegen_tests_LDADD = \
$(SSSD_LIBS) \
$(CHECK_LIBS)
+sss_config_tests_SOURCES = \
+ src/tests/sss_config-tests.c \
+ src/tests/common.c
+sss_config_tests_CFLAGS = \
+ $(AM_CFLAGS) \
+ $(CHECK_CFLAGS) \
this test do not use any augeas header files
+ $(AUGEAS_CFLAGS)
+sss_config_tests_LDADD = \
+ $(SSSD_LIBS) \
+ $(CHECK_LIBS) \
+ $(AUGEAS_LIBS) \
the same here
+ $(SSSD_INTERNAL_LTLIBS) \
+ libsss_config.la \
+ libsss_test_common.la
+
if HAVE_CMOCKA
TEST_MOCK_RESP_OBJ = \
diff --git a/src/tests/sss_config-tests.c b/src/tests/sss_config-tests.c
new file mode 100644
index 0000000000000000000000000000000000000000..c0c80591e1441c2c5cc7fe3b181d94eee78e5ec8
--- /dev/null
+++ b/src/tests/sss_config-tests.c
@@ -0,0 +1,806 @@
+/*
+ Authors:
+ Pavel Březina <pbrezina(a)redhat.com>
+
+ Copyright (C) 2014 Red Hat
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <
http://www.gnu.org/licenses/>.
+*/
+
+#include <check.h>
+#include <stdio.h>
+#include <talloc.h>
+#include <errno.h>
+#include <string.h>
+#include "util/util.h"
+#include "util/sss_config.h"
+#include "tests/common.h"
+#include "tests/common_check.h"
+
+#define TEST_FILE "sss_config_test.conf"
+#define TEST_FILE_BACKUP TEST_FILE ".augsave"
+
+/* input files */
+
+const char *test_orig =
+"[sssd]\n\
+services = nss, pam\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *test_svc_one =
+"[sssd]\n\
+services = nss\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *test_svc_empty =
+"[sssd]\n\
+services =\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *test_svc_missing =
+"[sssd]\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *test_dom_empty =
+"[sssd]\n\
+services = nss, pam\n\
+domains =\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *test_dom_missing =
+"[sssd]\n\
+services = nss, pam\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *test_dom_two =
+"[sssd]\n\
+services = nss, pam\n\
+domains = LDAP, IPA\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+/* expected */
+
+const char *exp_debug_level_exist =
+"[sssd]\n\
+services = nss, pam\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0330\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_debug_level_notexist =
+"[sssd]\n\
+services = nss, pam\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n\
+[nss]\n\
+debug_level=0x0330\n";
+
+const char *exp_svc =
+"[sssd]\n\
+services = nss, pam, pac\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_svc_empty =
+"[sssd]\n\
+services =pac\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_svc_missing =
+"[sssd]\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+services=pac\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_svc_disable =
+"[sssd]\n\
+services = pam\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_svc_disable_one =
+"[sssd]\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_svc_disable_empty =
+"[sssd]\n\
+services =\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_svc_disable_missing =
+"[sssd]\n\
+domains = LDAP\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_dom =
+"[sssd]\n\
+services = nss, pam\n\
+domains = LDAP, IPA\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_dom_empty =
+"[sssd]\n\
+services = nss, pam\n\
+domains =IPA\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_dom_missing =
+"[sssd]\n\
+services = nss, pam\n\
+debug_level = 0x0ff0\n\
+domains=IPA\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_dom_disable =
+"[sssd]\n\
+services = nss, pam\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_dom_disable_two =
+"[sssd]\n\
+services = nss, pam\n\
+domains = IPA\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+const char *exp_dom_disable_empty =
+"[sssd]\n\
+services = nss, pam\n\
+domains =\n\
+debug_level = 0x0ff0\n\
+[domain/LDAP]\n\
+debug_level = 0x0ff0\n\
+[domain/IPA]\n\
+debug_level = 0x0ff0\n";
+
+struct sss_config_ctx *config_ctx;
+
+static bool
+check_file_content(const char *filename, const char *expected)
+{
+ FILE *file = NULL;
+ size_t i;
+ char c;
+ bool result;
+
+ file = fopen(filename, "r");
+ fail_if(file == NULL, "unable to open test file");
+
+ i = 0;
+ while ((c = fgetc(file)) != EOF) {
+ if (c != expected[i]) {
+ printf("\nnot match: %d %c == %d %c\n", c, c, expected[i],
expected[i]);
+ result = false;
+ goto done;
+ }
+
+ i++;
+ }
+
+ if (expected[i] != '\0') {
+ printf("\nnot end: %d %c == %d %c\n", c, c, expected[i], expected[i]);
+ result = false;
+ goto done;
+ }
+
+ result = true;
+
+done:
+ fclose(file);
+ return result;
+}
+
+static void test_setup(const char *configuration)
+{
+ FILE *file = NULL;
+ size_t ret;
+
+ file = fopen(TEST_FILE, "w+");
+ fail_if(file == NULL, "unable to create test file");
+
+ ret = fputs(configuration, file);
+ fail_if(ret == EOF, "unable to write test file");
+
+ fail_if(fclose(file) != 0, "unable to close test file");
+
+ config_ctx = sss_config_open(NULL, TEST_DIR, "sss_config_test.conf");
^^^^^^^^^^^^^^^^^^^^^^
Could you use defined macro here?
It think you should call function sss_config_open in main function and here you
should use some subdirectory (test_sss_config?)
+ fail_if(config_ctx == NULL, "config_ctx is NULL");
+}
+
+static void setup(void)
+{
+ ck_leak_check_setup();
+}
+
+static void teardown(void)
+{
+ sss_config_close(&config_ctx);
+ fail_if(config_ctx != NULL, "config_ctx is not NULL");
+
+ //unlink(TEST_FILE);
Why is this line commented out?
+ unlink(TEST_FILE_BACKUP);
+
+ ck_leak_check_teardown();
+}
+
+START_TEST(test_sss_config_set_debug_level_exist)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_orig);
+
+ ret = sss_config_set_debug_level(config_ctx, "domain/LDAP", 0x0330);
+ fail_if(ret != EOK, "unable change configuration");
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration");
+
+ result = check_file_content(TEST_FILE, exp_debug_level_exist);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_orig);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_set_debug_level_notexist)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_orig);
+
+ ret = sss_config_set_debug_level(config_ctx, "nss", 0x0330);
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_debug_level_notexist);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_orig);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_service_enabled)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_orig);
+
+ ret = sss_config_service_is_enabled(config_ctx, "nss", &result);
+ fail_if(ret != EOK, "unable to read configuration [%d]: %s",
+ ret, strerror(ret));
+
+ fail_if(result == false, "wrong result");
+}
+END_TEST
+
+START_TEST(test_sss_config_service_disabled)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_orig);
+
+ ret = sss_config_service_is_enabled(config_ctx, "pac", &result);
+ fail_if(ret != EOK, "unable to read configuration [%d]: %s",
+ ret, strerror(ret));
+
+ fail_if(result == true, "wrong result");
+}
+END_TEST
+
+START_TEST(test_sss_config_service_disabled_empty)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_svc_empty);
+
+ ret = sss_config_service_is_enabled(config_ctx, "pac", &result);
+ fail_if(ret != EOK, "unable to read configuration [%d]: %s",
+ ret, strerror(ret));
+
+ fail_if(result == true, "wrong result");
+}
+END_TEST
+
+START_TEST(test_sss_config_service_disabled_missing)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_svc_missing);
+
+ ret = sss_config_service_is_enabled(config_ctx, "pac", &result);
+ fail_if(ret != EOK, "unable to read configuration [%d]: %s",
+ ret, strerror(ret));
+
+ fail_if(result == true, "wrong result");
+}
+END_TEST
+
+START_TEST(test_sss_config_service_enable)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_orig);
+
+ ret = sss_config_service_enable(config_ctx, "pac");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_svc);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_orig);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_service_enable_empty)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_svc_empty);
+
+ ret = sss_config_service_enable(config_ctx, "pac");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_svc_empty);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_svc_empty);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_service_enable_missing)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_svc_missing);
+
+ ret = sss_config_service_enable(config_ctx, "pac");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_svc_missing);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_svc_missing);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_service_disable)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_orig);
+
+ ret = sss_config_service_disable(config_ctx, "nss");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_svc_disable);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_orig);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_service_disable_one)
+{
+ return;
Why is this test disabled? It passed on my machine.
+
+ errno_t ret;
+ bool result;
+
+ test_setup(test_svc_one);
+
+ ret = sss_config_service_disable(config_ctx, "nss");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_svc_disable_one);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_svc_one);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_service_disable_empty)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_svc_empty);
+
+ ret = sss_config_service_disable(config_ctx, "nss");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_svc_disable_empty);
+ fail_if(result == false, "file does not match");
+
+ /* no backup file created */
+}
+END_TEST
+
+START_TEST(test_sss_config_service_disable_missing)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_svc_missing);
+
+ ret = sss_config_service_disable(config_ctx, "nss");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_svc_disable_missing);
+ fail_if(result == false, "file does not match");
+
+ /* no backup file created */
+}
+END_TEST
+
+START_TEST(test_sss_config_domain_enable)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_orig);
+
+ ret = sss_config_domain_enable(config_ctx, "IPA");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_dom);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_orig);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_domain_enable_empty)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_dom_empty);
+
+ ret = sss_config_domain_enable(config_ctx, "IPA");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_dom_empty);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_dom_empty);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_domain_enable_missing)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_dom_missing);
+
+ ret = sss_config_domain_enable(config_ctx, "IPA");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_dom_missing);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_dom_missing);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_domain_disable)
+{
+ errno_t ret;
+ bool result;
+
+ test_setup(test_orig);
+
+ ret = sss_config_domain_disable(config_ctx, "LDAP");
+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
+ ret, strerror(ret));
+
+ ret = sss_config_save(config_ctx);
+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
+ ret, strerror(ret));
+
+ result = check_file_content(TEST_FILE, exp_dom_disable);
+ fail_if(result == false, "file does not match");
+
+ result = check_file_content(TEST_FILE_BACKUP, test_orig);
+ fail_if(result == false, "backup file does not match");
+}
+END_TEST
+
+START_TEST(test_sss_config_domain_disable_two)
+{
+ return;
The same here.
>+
>+ errno_t ret;
>+ bool result;
>+
>+ test_setup(test_dom_two);
>+
>+ ret = sss_config_domain_disable(config_ctx, "LDAP");
>+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
>+ ret, strerror(ret));
>+
>+ ret = sss_config_save(config_ctx);
>+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
>+ ret, strerror(ret));
>+
>+ result = check_file_content(TEST_FILE, exp_dom_disable_two);
>+ fail_if(result == false, "file does not match");
>+
>+ result = check_file_content(TEST_FILE_BACKUP, test_dom_two);
>+ fail_if(result == false, "backup file does not match");
>+}
>+END_TEST
>+
>+START_TEST(test_sss_config_domain_disable_empty)
>+{
>+ errno_t ret;
>+ bool result;
>+
>+ test_setup(test_dom_empty);
>+
>+ ret = sss_config_domain_disable(config_ctx, "LDAP");
>+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
>+ ret, strerror(ret));
>+
>+ ret = sss_config_save(config_ctx);
>+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
>+ ret, strerror(ret));
>+
>+ result = check_file_content(TEST_FILE, exp_dom_disable_empty);
>+ fail_if(result == false, "file does not match");
>+
>+ /* no backup file created */
>+}
>+END_TEST
>+
>+START_TEST(test_sss_config_domain_disable_missing)
>+{
>+ errno_t ret;
>+ bool result;
>+
>+ test_setup(test_dom_missing);
>+
>+ ret = sss_config_domain_disable(config_ctx, "LDAP");
>+ fail_if(ret != EOK, "unable change configuration [%d]: %s",
>+ ret, strerror(ret));
>+
>+ ret = sss_config_save(config_ctx);
>+ fail_if(ret != EOK, "unable save configuration [%d]: %s",
>+ ret, strerror(ret));
>+
>+ result = check_file_content(TEST_FILE, exp_dom_disable);
>+ fail_if(result == false, "file does not match");
>+
>+ /* no backup file created */
>+}
>+END_TEST
>+
>+Suite *sss_config_suite(void)
>+{
>+ Suite *s = suite_create("sss_config");
>+ TCase *tc = tcase_create("sss_config");
>+
>+ tcase_add_checked_fixture(tc, setup, teardown);
>+
>+ tcase_add_test(tc, test_sss_config_set_debug_level_exist);
>+ tcase_add_test(tc, test_sss_config_set_debug_level_notexist);
>+ tcase_add_test(tc, test_sss_config_service_enabled);
>+ tcase_add_test(tc, test_sss_config_service_disabled);
>+ tcase_add_test(tc, test_sss_config_service_disabled_empty);
>+ tcase_add_test(tc, test_sss_config_service_disabled_missing);
>+ tcase_add_test(tc, test_sss_config_service_enable);
>+ tcase_add_test(tc, test_sss_config_service_enable_empty);
>+ tcase_add_test(tc, test_sss_config_service_enable_missing);
>+ tcase_add_test(tc, test_sss_config_service_disable);
>+ tcase_add_test(tc, test_sss_config_service_disable_one);
>+ tcase_add_test(tc, test_sss_config_service_disable_empty);
>+ tcase_add_test(tc, test_sss_config_service_disable_missing);
>+ tcase_add_test(tc, test_sss_config_domain_enable);
>+ tcase_add_test(tc, test_sss_config_domain_enable_empty);
>+ tcase_add_test(tc, test_sss_config_domain_enable_missing);
>+ tcase_add_test(tc, test_sss_config_domain_disable);
>+ tcase_add_test(tc, test_sss_config_domain_disable_two);
>+ tcase_add_test(tc, test_sss_config_domain_disable_empty);
>+ tcase_add_test(tc, test_sss_config_domain_disable_missing);
>+
>+
>+
>+ tcase_set_timeout(tc, 60);
>+
>+ suite_add_tcase(s, tc);
>+
>+ return s;
>+}
>+
>+int main(int argc, const char *argv[])
>+{
>+ int number_failed;
>+
>+ tests_set_cwd();
>+
>+ Suite *s = sss_config_suite();
>+ SRunner *sr = srunner_create(s);
>+
>+ srunner_run_all(sr, CK_NORMAL);
>+ number_failed = srunner_ntests_failed(sr);
>+ srunner_free(sr);
>+
>+ if (number_failed == 0) {
>+ return EXIT_SUCCESS;
>+ }
>+
>+ return EXIT_FAILURE;
>+}
--
1.7.11.7
Could you also add simple test for function sss_config_domain_is_enabled.
It will be very simillar to the test test_sss_config_service_disabled
Add line to dlopen test with some if condition HAVE_CONFIG_LIB
+ { "libsss_config.so", { LIBPFX"libsss_config.so", NULL } },
LS