svn commit: samba r7515 - in branches/SAMBA_4_0/source/lib/ldb:
common include
tridge at samba.org
tridge at samba.org
Mon Jun 13 05:33:55 GMT 2005
Author: tridge
Date: 2005-06-13 05:33:55 +0000 (Mon, 13 Jun 2005)
New Revision: 7515
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7515
Log:
merge in the binary encode/decode enhancements from the libcli/ldap/
code into the ldb parse code
Modified:
branches/SAMBA_4_0/source/lib/ldb/common/ldb_parse.c
branches/SAMBA_4_0/source/lib/ldb/include/ldb_parse.h
Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_parse.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_parse.c 2005-06-13 05:18:17 UTC (rev 7514)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_parse.c 2005-06-13 05:33:55 UTC (rev 7515)
@@ -126,7 +126,74 @@
return s;
}
+/*
+ decode a RFC2254 binary string representation of a buffer.
+ Used in LDAP filters.
+*/
+struct ldb_val ldb_binary_decode(TALLOC_CTX *ctx, const char *str)
+{
+ int i, j;
+ struct ldb_val ret;
+ int slen = strlen(str);
+ ret.data = talloc_size(ctx, slen);
+ ret.length = 0;
+ if (ret.data == NULL) return ret;
+
+ for (i=j=0;i<slen;i++) {
+ if (str[i] == '\\') {
+ unsigned c;
+ if (sscanf(&str[i+1], "%02X", &c) != 1) {
+ talloc_free(ret.data);
+ memset(&ret, 0, sizeof(ret));
+ return ret;
+ }
+ ((uint8_t *)ret.data)[j++] = c;
+ i += 2;
+ } else {
+ ((uint8_t *)ret.data)[j++] = str[i];
+ }
+ }
+ ret.length = j;
+
+ return ret;
+}
+
+
+/*
+ encode a blob as a RFC2254 binary string, escaping any
+ non-printable or '\' characters
+*/
+const char *ldb_binary_encode(TALLOC_CTX *ctx, struct ldb_val val)
+{
+ int i;
+ char *ret;
+ int len = val.length;
+ unsigned char *buf = val.data;
+
+ for (i=0;i<val.length;i++) {
+ if (!isprint(buf[i]) || strchr(" *()\\&|!", buf[i])) {
+ len += 2;
+ }
+ }
+ ret = talloc_array(ctx, char, len+1);
+ if (ret == NULL) return NULL;
+
+ len = 0;
+ for (i=0;i<val.length;i++) {
+ if (!isprint(buf[i]) || strchr(" *()\\&|!", buf[i])) {
+ snprintf(ret+len, 4, "\\%02X", buf[i]);
+ len += 3;
+ } else {
+ ret[len++] = buf[i];
+ }
+ }
+
+ ret[len] = 0;
+
+ return ret;
+}
+
static struct ldb_parse_tree *ldb_parse_filter(TALLOC_CTX *ctx, const char **s);
/*
@@ -169,8 +236,7 @@
ret->operation = LDB_OP_SIMPLE;
ret->u.simple.attr = l;
- ret->u.simple.value.data = val?val:discard_const_p(char, "");
- ret->u.simple.value.length = val?strlen(val):0;
+ ret->u.simple.value = ldb_binary_decode(ret, val);
return ret;
}
Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb_parse.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb_parse.h 2005-06-13 05:18:17 UTC (rev 7514)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb_parse.h 2005-06-13 05:33:55 UTC (rev 7515)
@@ -55,5 +55,6 @@
};
struct ldb_parse_tree *ldb_parse_tree(TALLOC_CTX *mem_ctx, const char *s);
+const char *ldb_binary_encode(TALLOC_CTX *ctx, struct ldb_val val);
#endif
More information about the samba-cvs
mailing list