From bceca723044e9cf5d835e8d732be3ab57906505e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 19 Dec 2005 07:07:11 +0000 Subject: r12361: Add a new function: ldb_binary_encode_string() This is for use on user-supplied arguments to printf style format strings which will become ldb filters. I have used it on LSA, SAMR and the auth/ code so far. Also add comments to cracknames code. Andrew Bartlett (This used to be commit 8308cf6e0472790c1c9d521d19322557907f4418) --- source4/lib/ldb/common/ldb_parse.c | 13 +++++++++++++ source4/lib/ldb/include/ldb.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/common/ldb_parse.c b/source4/lib/ldb/common/ldb_parse.c index 5824a8d003..25e4b727df 100644 --- a/source4/lib/ldb/common/ldb_parse.c +++ b/source4/lib/ldb/common/ldb_parse.c @@ -127,6 +127,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 = 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) { diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 2fdf40b3bc..9c3b033091 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -214,7 +214,7 @@ struct ldb_parse_tree { struct ldb_parse_tree *ldb_parse_tree(void *mem_ctx, const char *s); char *ldb_filter_from_tree(void *mem_ctx, struct ldb_parse_tree *tree); char *ldb_binary_encode(void *ctx, struct ldb_val val); - +char *ldb_binary_encode_string(void *mem_ctx, const char *string); /* functions for controlling attribute handling -- cgit