diff options
author | Andrew Bartlett <abartlet@samba.org> | 2009-11-05 16:56:05 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2009-11-12 16:34:02 +1100 |
commit | 3abc3e7a3a4e3833c8c08cc21deeaae174887f7f (patch) | |
tree | 1fdde18bb6612442d697a241aed62f5197a1f525 /source4/lib/ldb/common | |
parent | fd5174e88ca1727a91d6dc9bf9bd898ff9087fe8 (diff) | |
download | samba-3abc3e7a3a4e3833c8c08cc21deeaae174887f7f.tar.gz samba-3abc3e7a3a4e3833c8c08cc21deeaae174887f7f.tar.bz2 samba-3abc3e7a3a4e3833c8c08cc21deeaae174887f7f.zip |
s4:ldb Add a helper function for 'canonicalise' both strings base compares
This will help simplify boilerplate comparison functions where we
don't have a shortcut way to compare.
Andrew Bartlett
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r-- | source4/lib/ldb/common/attrib_handlers.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index ba21fcac9b..1c08741f7d 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -2,6 +2,7 @@ ldb database library Copyright (C) Andrew Tridgell 2005 + Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006-2009 ** NOTE! The following LGPL license applies to the ldb ** library. This does NOT imply that all of Samba is released @@ -430,3 +431,29 @@ const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context * } return NULL; } + +int ldb_any_comparison(struct ldb_context *ldb, void *mem_ctx, + ldb_attr_handler_t canonicalise_fn, + const struct ldb_val *v1, + const struct ldb_val *v2) +{ + int ret, ret1, ret2; + struct ldb_val v1_canon, v2_canon; + TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); + + /* I could try and bail if tmp_ctx was NULL, but what return + * value would I use? + * + * It seems easier to continue on the NULL context + */ + ret1 = canonicalise_fn(ldb, tmp_ctx, v1, &v1_canon); + ret2 = canonicalise_fn(ldb, tmp_ctx, v2, &v2_canon); + + if (ret1 == LDB_SUCCESS && ret2 == LDB_SUCCESS) { + ret = ldb_comparison_binary(ldb, mem_ctx, &v1_canon, &v2_canon); + } else { + ret = ldb_comparison_binary(ldb, mem_ctx, v1, v2); + } + talloc_free(tmp_ctx); + return ret; +} |