summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2014-09-24 09:23:58 +0200
committerKarolin Seeger <kseeger@samba.org>2014-10-09 21:23:05 +0200
commitf42d65e94d4aeebc7471187a85905fba83a17ace (patch)
treed72a860c0a5b437bb8cbfdce59e4723038b05dfb
parent5923c9a228870bee2818cdc740598fd708d063f8 (diff)
downloadsamba-f42d65e94d4aeebc7471187a85905fba83a17ace.tar.gz
s3-libads: Add function to search for an element in an array.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=9984 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Guenther Deschner <gd@samba.org> (cherry picked from commit e1ee4c8bc7018db7787dd9a0be6d3aa40a477ee2)
-rw-r--r--source3/libads/ads_proto.h2
-rw-r--r--source3/libads/ldap.c31
2 files changed, 33 insertions, 0 deletions
diff --git a/source3/libads/ads_proto.h b/source3/libads/ads_proto.h
index 6a2280734d..1e34247e2f 100644
--- a/source3/libads/ads_proto.h
+++ b/source3/libads/ads_proto.h
@@ -88,6 +88,8 @@ ADS_STATUS ads_add_strlist(TALLOC_CTX *ctx, ADS_MODLIST *mods,
uint32 ads_get_kvno(ADS_STRUCT *ads, const char *account_name);
uint32_t ads_get_machine_kvno(ADS_STRUCT *ads, const char *machine_name);
+bool ads_element_in_array(const char **el_array, size_t num_el, const char *el);
+
ADS_STATUS ads_get_service_principal_names(TALLOC_CTX *mem_ctx,
ADS_STRUCT *ads,
const char *machine_name,
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index 51a08835d2..8d104c2f59 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -1927,6 +1927,37 @@ ADS_STATUS ads_clear_service_principal_names(ADS_STRUCT *ads, const char *machin
}
/**
+ * @brief Search for an element in a string array.
+ *
+ * @param[in] el_array The string array to search.
+ *
+ * @param[in] num_el The number of elements in the string array.
+ *
+ * @param[in] el The string to search.
+ *
+ * @return True if found, false if not.
+ */
+bool ads_element_in_array(const char **el_array, size_t num_el, const char *el)
+{
+ size_t i;
+
+ if (el_array == NULL || num_el == 0 || el == NULL) {
+ return false;
+ }
+
+ for (i = 0; i < num_el && el_array[i] != NULL; i++) {
+ int cmp;
+
+ cmp = strcasecmp_m(el_array[i], el);
+ if (cmp == 0) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/**
* @brief This gets the service principal names of an existing computer account.
*
* @param[in] mem_ctx The memory context to use to allocate the spn array.