r12829: fix ldb headers, to not include '<...>' files in .c files
[kamenim/samba.git] / source4 / lib / ldb / common / ldb_utf8.c
index dc25d6cf13e6763fee0548d0f56b839f05688fe9..4a29ac45f7b50cc265001d58e8553849df573b42 100644 (file)
@@ -33,9 +33,7 @@
  */
 
 #include "includes.h"
-#include "ldb/include/ldb.h"
-#include "ldb/include/ldb_private.h"
-#include <ctype.h>
+#include "ldb/include/includes.h"
 
 /*
   TODO:
@@ -50,7 +48,7 @@ char *ldb_casefold(void *mem_ctx, const char *s)
                return NULL;
        }
        for (i=0;ret[i];i++) {
-               ret[i] = toupper(ret[i]);
+               ret[i] = toupper((unsigned char)ret[i]);
        }
        return ret;
 }
@@ -59,11 +57,12 @@ char *ldb_casefold(void *mem_ctx, const char *s)
   a caseless compare, optimised for 7 bit
   TODO: doesn't yet handle UTF8
 */
-static int ldb_caseless_cmp(const char *s1, const char *s2)
+int ldb_caseless_cmp(const char *s1, const char *s2)
 {
        int i;
        for (i=0;s1[i] != 0;i++) {
-               int c1 = toupper(s1[i]), c2 = toupper(s2[i]);
+               int c1 = toupper((unsigned char)s1[i]),
+                   c2 = toupper((unsigned char)s2[i]);
                if (c1 != c2) {
                        return c1 - c2;
                }
@@ -72,96 +71,22 @@ static int ldb_caseless_cmp(const char *s1, const char *s2)
 }
 
 /*
-  compare two basedn fields
+  compare two attribute names
   return 0 for match
 */
-int ldb_dn_cmp(const char *dn1, const char *dn2)
+int ldb_attr_cmp(const char *attr1, const char *attr2)
 {
-       return ldb_caseless_cmp(dn1, dn2);
+       return ldb_caseless_cmp(attr1, attr2);
 }
 
 /*
-  compare two attributes
-  return 0 for match
-*/
-int ldb_attr_cmp(const char *dn1, const char *dn2)
-{
-       return ldb_caseless_cmp(dn1, dn2);
-}
-
-
-/*
-  casefold a dn. We need to uppercase the attribute names, and the 
-  attribute values of case insensitive attributes. We also need to remove
-  extraneous spaces between elements
+  we accept either 'dn' or 'distinguishedName' for a distinguishedName
 */
-char *ldb_dn_fold(struct ldb_module *module, const char *dn, int (*case_fold_attr_fn)(struct ldb_module * module, char * attr))
+int ldb_attr_dn(const char *attr)
 {
-       const char *dn_orig = dn;
-       struct ldb_context *ldb = module->ldb;
-       TALLOC_CTX *tmp_ctx = talloc_new(ldb);
-       char *ret;
-       size_t len;
-
-       ret = talloc_strdup(tmp_ctx, "");
-       if (ret == NULL) goto failed;
-
-       while ((len = strcspn(dn, ",")) > 0) {
-               char *p = strchr(dn, '=');
-               char *attr, *value;
-               int case_fold_required;
-
-               if (p == NULL || (p-dn) > len) goto failed;
-
-               attr = talloc_strndup(tmp_ctx, dn, p-dn);
-               if (attr == NULL) goto failed;
-
-               /* trim spaces from the attribute name */
-               while (' ' == *attr) attr++;
-               while (' ' == attr[strlen(attr)-1]) {
-                       attr[strlen(attr)-1] = 0;
-               }
-               if (*attr == 0) goto failed;
-
-               value = talloc_strndup(tmp_ctx, p+1, len-(p+1-dn));
-               if (value == NULL) goto failed;
-
-               /* trim spaces from the value */
-               while (' ' == *value) value++;
-               while (' ' == value[strlen(value)-1]) {
-                       value[strlen(value)-1] = 0;
-               }
-               if (*value == 0) goto failed;
-
-               case_fold_required = (* case_fold_attr_fn)(module, attr);
-
-               attr = ldb_casefold(ldb, attr);
-               if (attr == NULL) goto failed;
-               talloc_steal(tmp_ctx, attr);
-
-               if (case_fold_required) {
-                       value = ldb_casefold(ldb, value);
-                       if (value == NULL) goto failed;
-                       talloc_steal(tmp_ctx, value);
-               }               
-
-               if (dn[len] == ',') {
-                       ret = talloc_asprintf_append(ret, "%s=%s,", attr, value);
-               } else {
-                       ret = talloc_asprintf_append(ret, "%s=%s", attr, value);
-               }
-               if (ret == NULL) goto failed;
-
-               dn += len;
-               if (*dn == ',') dn++;
+       if (ldb_attr_cmp(attr, "dn") == 0 ||
+           ldb_attr_cmp(attr, "distinguishedName") == 0) {
+               return 0;
        }
-
-       talloc_steal(ldb, ret);
-       talloc_free(tmp_ctx);
-       return ret;
-
-failed:
-       talloc_free(tmp_ctx);
-       return ldb_casefold(ldb, dn_orig);
+       return -1;
 }
-