r22681: Fix standalone ldb build when parent directory name != ldb.
[kamenim/samba.git] / source4 / lib / ldb / common / ldb_parse.c
index 5824a8d003d1ed891c48e95a7949eb96e62a0cd1..b0baaa2f7b8c8edf8fcf9e92c58e5d6bcb559cd8 100644 (file)
 
 */
 
-#include "includes.h"
-#include "ldb/include/ldb.h"
-#include <ctype.h>
-
+#include "ldb_includes.h"
+#include "system/locale.h"
 
 /*
 a filter is defined by:
@@ -68,7 +66,7 @@ struct ldb_val ldb_binary_decode(void *mem_ctx, const char *str)
        struct ldb_val ret;
        int slen = str?strlen(str):0;
 
-       ret.data = talloc_size(mem_ctx, slen+1);
+       ret.data = (uint8_t *)talloc_size(mem_ctx, slen+1);
        ret.length = 0;
        if (ret.data == NULL) return ret;
 
@@ -127,6 +125,19 @@ char *ldb_binary_encode(void *mem_ctx, struct ldb_val val)
        return ret;     
 }
 
+/*
+   encode a string as a RFC2254 binary string, escaping any
+   non-printable or '\' characters.  This routine is suitable for use
+   in escaping user data in ldap filters.
+*/
+char *ldb_binary_encode_string(void *mem_ctx, const char *string)
+{
+       struct ldb_val val;
+       val.data = discard_const_p(uint8_t, string);
+       val.length = strlen(string);
+       return ldb_binary_encode(mem_ctx, val);
+}
+
 /* find the first matching wildcard */
 static char *ldb_parse_find_wildcard(char *value)
 {
@@ -182,7 +193,9 @@ static struct ldb_val **ldb_wildcard_decode(void *mem_ctx, const char *string)
                val++;
        }
 
-       ret[val] = NULL;
+       if (ret != NULL) {
+               ret[val] = NULL;
+       }
 
        return ret;
 }
@@ -271,7 +284,7 @@ static enum ldb_parse_op ldb_parse_filtertype(void *mem_ctx, char **type, char *
        }
 
        /* save name */
-       name = talloc_memdup(mem_ctx, t, t1 - t + 1);
+       name = (char *)talloc_memdup(mem_ctx, t, t1 - t + 1);
        if (name == NULL) return 0;
        name[t1 - t] = '\0';
 
@@ -312,7 +325,7 @@ static enum ldb_parse_op ldb_parse_filtertype(void *mem_ctx, char **type, char *
 
        while (*p && ((*p != ')') || ((*p == ')') && (*(p - 1) == '\\')))) p++;
 
-       val = talloc_memdup(mem_ctx, t, p - t + 1);
+       val = (char *)talloc_memdup(mem_ctx, t, p - t + 1);
        if (val == NULL) {
                talloc_free(name);
                return 0;