diff options
author | Stefan Metzmacher <metze@samba.org> | 2004-09-29 12:20:59 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:59:30 -0500 |
commit | 525dc6f089837456b0fff1d44d50aed4a7ef52ec (patch) | |
tree | 3dc25f9f119e9febadc84e7dd4baba938a7cc8e7 /source4 | |
parent | 88ead90b1d6f7e32181b5e9bf2b48cf0ef0b7c95 (diff) | |
download | samba-525dc6f089837456b0fff1d44d50aed4a7ef52ec.tar.gz samba-525dc6f089837456b0fff1d44d50aed4a7ef52ec.tar.bz2 samba-525dc6f089837456b0fff1d44d50aed4a7ef52ec.zip |
r2748: implement sldb_Compare()
Simo: this commit should not conflict much with your changes:-)
metze
(This used to be commit 6825e78e01a220bc837ea51aa6afbf3f26a02c49)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/ldap_server/ldap_simple_ldb.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/source4/ldap_server/ldap_simple_ldb.c b/source4/ldap_server/ldap_simple_ldb.c index 4d6062cd10..d3e516bf28 100644 --- a/source4/ldap_server/ldap_simple_ldb.c +++ b/source4/ldap_server/ldap_simple_ldb.c @@ -448,11 +448,73 @@ invalid_input: return ldapsrv_queue_reply(call, modify_reply); } +static NTSTATUS sldb_Compare(struct ldapsrv_partition *partition, struct ldapsrv_call *call, + struct ldap_CompareRequest *r) +{ + struct ldap_Result *compare; + struct ldapsrv_reply *compare_r; + int result = 80; + struct samdb_context *samdb; + struct ldb_message **res; + struct ldb_context *ldb; + const char *attrs[1]; + const char *errstr; + const char *dn; + const char *filter; + int count; + + samdb = samdb_connect(call); + ldb = samdb->ldb; + dn = sldb_trim_dn(samdb, r->dn); + + DEBUG(10, ("sldb_Compare: dn: [%s]\n", dn)); + filter = talloc_asprintf(samdb, "(%s=%*s)", r->attribute, r->value.length, r->value.data); + ALLOC_CHECK(filter); + DEBUGADD(10, ("sldb_Compare: attribute: [%s]\n", filter)); + + attrs[0] = NULL; + + ldb_set_alloc(ldb, talloc_ldb_alloc, samdb); + count = ldb_search(ldb, dn, LDB_SCOPE_BASE, filter, attrs, &res); + + compare_r = ldapsrv_init_reply(call, LDAP_TAG_CompareResponse); + ALLOC_CHECK(compare_r); + + if (count == 1) { + DEBUG(10,("sldb_Compare: matched\n")); + result = 0; + errstr = NULL; + } else if (count == 0) { + result = 32; + errstr = talloc_strdup(compare_r, ldb_errstring(ldb)); + DEBUG(10,("sldb_Compare: no results: %s\n", errstr)); + } else if (count > 1) { + result = 80; + errstr = talloc_strdup(compare_r, "too many objects match"); + DEBUG(10,("sldb_Compare: %d results: %s\n", count, errstr)); + } else if (count == -1) { + result = 1; + errstr = talloc_strdup(compare_r, ldb_errstring(ldb)); + DEBUG(10,("sldb_Compare: error: %s\n", errstr)); + } + + compare = &compare_r->msg.r.CompareResponse; + compare->resultcode = result; + compare->dn = NULL; + compare->errormessage = errstr; + compare->referral = NULL; + + talloc_free(samdb); + + return ldapsrv_queue_reply(call, compare_r); +} + static const struct ldapsrv_partition_ops sldb_ops = { .Search = sldb_Search, .Add = sldb_Add, .Del = sldb_Del, - .Modify = sldb_Modify + .Modify = sldb_Modify, + .Compare = sldb_Compare }; const struct ldapsrv_partition_ops *ldapsrv_get_sldb_partition_ops(void) |