From 51404f4b2c5b0dd6666d7c79084583c55c48abb9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Wed, 17 Apr 2013 12:35:46 +0200
Subject: [PATCH 5/6] add sss_ldap_filter_binary_value

Converts uint32 to a string value that is suitable for octed
string attributes.
---
 src/util/sss_ldap.c | 15 +++++++++++++++
 src/util/sss_ldap.h |  2 ++
 2 files changed, 17 insertions(+)

diff --git a/src/util/sss_ldap.c b/src/util/sss_ldap.c
index f7834d94073464eae06917c75ffaf75aac0f832f..378dec67882b10e766dbed11902209701a8a0f5b 100644
--- a/src/util/sss_ldap.c
+++ b/src/util/sss_ldap.c
@@ -587,3 +587,18 @@ done:
     talloc_free(filter);
     return ret;
 }
+
+char *sss_ldap_filter_binary_value(TALLOC_CTX *mem_ctx, uint32_t flags)
+{
+    char hex[9]; /* 4 bytes in hex + terminating zero */
+    errno_t ret;
+
+    ret = snprintf(hex, 9, "%08x", flags);
+    if (ret != 8) {
+        return NULL;
+    }
+
+    return talloc_asprintf(mem_ctx, "\\%c%c\\%c%c\\%c%c\\%c%c",
+                           hex[6], hex[7], hex[4], hex[5],
+                           hex[2], hex[3], hex[0], hex[1]);
+}
diff --git a/src/util/sss_ldap.h b/src/util/sss_ldap.h
index 7399c4d0ac0749cfaf57d42c2fe0465a0bdd4a41..5793b6c7f921e7821ced58c5724c608ae5d8b101 100644
--- a/src/util/sss_ldap.h
+++ b/src/util/sss_ldap.h
@@ -74,4 +74,6 @@ bool sss_ldap_dn_in_search_bases(TALLOC_CTX *mem_ctx,
                                  struct sdap_search_base **search_bases,
                                  char **_filter);
 
+char *sss_ldap_filter_binary_value(TALLOC_CTX *mem_ctx, uint32_t flags);
+
 #endif /* __SSS_LDAP_H__ */
-- 
1.7.11.7

