summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2013-10-24 11:44:11 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-10-25 15:31:15 +0200
commit3cbbfb4b05d0eb0a0809704e83589d0075e117a0 (patch)
treec536c69260e2dc6829882649b0933e80264984dc
parent939246537b0b9a4af6862c513d3919501ad57d92 (diff)
downloadsssd-3cbbfb4b05d0eb0a0809704e83589d0075e117a0.tar.gz
sssd-3cbbfb4b05d0eb0a0809704e83589d0075e117a0.tar.xz
sssd-3cbbfb4b05d0eb0a0809704e83589d0075e117a0.zip
idmap: add sss_idmap_domain_by_name_has_algorithmic_mapping()
-rw-r--r--Makefile.am2
-rw-r--r--src/lib/idmap/sss_idmap.c33
-rw-r--r--src/lib/idmap/sss_idmap.h44
-rw-r--r--src/tests/cmocka/test_sss_idmap.c41
4 files changed, 115 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index 1b35d0586..8d548e2bd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -623,7 +623,7 @@ libsss_idmap_la_SOURCES = \
src/lib/idmap/sss_idmap_conv.c \
src/util/murmurhash3.c
libsss_idmap_la_LDFLAGS = \
- -version-info 1:0:1
+ -version-info 2:0:2
dist_pkgconfig_DATA += src/sss_client/idmap/sss_nss_idmap.pc
libsss_nss_idmap_la_SOURCES = \
diff --git a/src/lib/idmap/sss_idmap.c b/src/lib/idmap/sss_idmap.c
index 17bd5779e..9278e10d2 100644
--- a/src/lib/idmap/sss_idmap.c
+++ b/src/lib/idmap/sss_idmap.c
@@ -953,3 +953,36 @@ sss_idmap_domain_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
return IDMAP_SID_UNKNOWN;
}
+
+enum idmap_error_code
+sss_idmap_domain_by_name_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
+ const char *dom_name,
+ bool *has_algorithmic_mapping)
+{
+ struct idmap_domain_info *idmap_domain_info;
+
+ if (dom_name == NULL) {
+ return IDMAP_ERROR;
+ }
+
+ CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
+
+ if (ctx->idmap_domain_info == NULL) {
+ return IDMAP_NO_DOMAIN;
+ }
+
+ idmap_domain_info = ctx->idmap_domain_info;
+
+ while (idmap_domain_info != NULL) {
+ if (idmap_domain_info->name != NULL
+ && strcmp(dom_name, idmap_domain_info->name) == 0) {
+
+ *has_algorithmic_mapping = !idmap_domain_info->external_mapping;
+ return IDMAP_SUCCESS;
+ }
+
+ idmap_domain_info = idmap_domain_info->next;
+ }
+
+ return IDMAP_NAME_UNKNOWN;
+}
diff --git a/src/lib/idmap/sss_idmap.h b/src/lib/idmap/sss_idmap.h
index 91e5d0bf3..4101fb9a5 100644
--- a/src/lib/idmap/sss_idmap.h
+++ b/src/lib/idmap/sss_idmap.h
@@ -81,7 +81,10 @@ enum idmap_error_code {
IDMAP_COLLISION,
/** External source should be consulted for idmapping */
- IDMAP_EXTERNAL
+ IDMAP_EXTERNAL,
+
+ /** The provided name was not found */
+ IDMAP_NAME_UNKNOWN
};
/**
@@ -524,11 +527,21 @@ bool is_domain_sid(const char *str);
/**
* @brief Check if a domain is configured with algorithmic mapping
*
- * @param[in] ctx Idmap context
- * @param[in] dom_sid SID string, can be either a domain SID or an object SID
+ * @param[in] ctx Idmap context
+ * @param[in] dom_sid SID string, can be either a domain SID
+ * or an object SID
+ * @param[out] has_algorithmic_mapping Boolean value indicating if the given
+ * domain is configured for algorithmic
+ * mapping or not.
*
* @return
- * TODO ....
+ * - #IDMAP_SUCCESS: Domain for the given SID was found and
+ * has_algorithmic_mapping is set accordingly
+ * - #IDMAP_SID_INVALID: Provided SID is invalid
+ * - #IDMAP_CONTEXT_INVALID: Provided idmap context is invalid
+ * - #IDMAP_NO_DOMAIN: No domains are available in the idmap context
+ * - #IDMAP_SID_UNKNOWN: No domain with the given SID was found in the
+ * idmap context
*/
enum idmap_error_code
sss_idmap_domain_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
@@ -536,6 +549,29 @@ sss_idmap_domain_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
bool *has_algorithmic_mapping);
/**
+ * @brief Check if a domain is configured with algorithmic mapping
+ *
+ * @param[in] ctx Idmap context
+ * @param[in] dom_name Name of the domain
+ * @param[out] has_algorithmic_mapping Boolean value indicating if the given
+ * domain is configured for algorithmic
+ * mapping or not.
+ *
+ * @return
+ * - #IDMAP_SUCCESS: Domain for the given name was found and
+ * has_algorithmic_mapping is set accordingly
+ * - #IDMAP_ERROR: Provided name is invalid
+ * - #IDMAP_CONTEXT_INVALID: Provided idmap context is invalid
+ * - #IDMAP_NO_DOMAIN: No domains are available in the idmap context
+ * - #IDMAP_NAME_UNKNOWN: No domain with the given name was found in the
+ * idmap context
+ */
+enum idmap_error_code
+sss_idmap_domain_by_name_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
+ const char *dom_name,
+ bool *has_algorithmic_mapping);
+
+/**
* @brief Convert binary SID to SID structure
*
* @param[in] ctx Idmap context
diff --git a/src/tests/cmocka/test_sss_idmap.c b/src/tests/cmocka/test_sss_idmap.c
index 2f6a67d7d..53ed35a97 100644
--- a/src/tests/cmocka/test_sss_idmap.c
+++ b/src/tests/cmocka/test_sss_idmap.c
@@ -367,6 +367,44 @@ void test_has_algorithmic(void **state)
assert_false(use_id_mapping);
}
+void test_has_algorithmic_by_name(void **state)
+{
+ struct test_ctx *test_ctx;
+ bool use_id_mapping;
+ enum idmap_error_code err;
+
+ test_ctx = talloc_get_type(*state, struct test_ctx);
+
+ assert_non_null(test_ctx);
+
+ err = sss_idmap_domain_by_name_has_algorithmic_mapping(NULL, NULL, &use_id_mapping);
+ assert_int_equal(err, IDMAP_ERROR);
+
+ err = sss_idmap_domain_by_name_has_algorithmic_mapping(NULL, TEST_DOM_SID,
+ &use_id_mapping);
+ assert_int_equal(err, IDMAP_CONTEXT_INVALID);
+
+ err = sss_idmap_domain_by_name_has_algorithmic_mapping(test_ctx->idmap_ctx, NULL,
+ &use_id_mapping);
+ assert_int_equal(err, IDMAP_ERROR);
+
+ err = sss_idmap_domain_by_name_has_algorithmic_mapping(test_ctx->idmap_ctx,
+ TEST_DOM_NAME"1",
+ &use_id_mapping);
+ assert_int_equal(err, IDMAP_NAME_UNKNOWN);
+
+ err = sss_idmap_domain_by_name_has_algorithmic_mapping(test_ctx->idmap_ctx,
+ TEST_DOM_NAME,
+ &use_id_mapping);
+ assert_int_equal(err, IDMAP_SUCCESS);
+ assert_true(use_id_mapping);
+
+ err = sss_idmap_domain_by_name_has_algorithmic_mapping(test_ctx->idmap_ctx,
+ TEST_2_DOM_NAME,
+ &use_id_mapping);
+ assert_int_equal(err, IDMAP_SUCCESS);
+ assert_false(use_id_mapping);
+}
int main(int argc, const char *argv[])
{
@@ -396,6 +434,9 @@ int main(int argc, const char *argv[])
unit_test_setup_teardown(test_has_algorithmic,
test_sss_idmap_setup_with_both,
test_sss_idmap_teardown),
+ unit_test_setup_teardown(test_has_algorithmic_by_name,
+ test_sss_idmap_setup_with_both,
+ test_sss_idmap_teardown),
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */