2 Unix SMB/CIFS mplementation.
3 LDAP replUpToDateVector tests
5 Copyright (C) Stefan Metzmacher 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/ldap/ldap_client.h"
24 #include "lib/cmdline/popt_common.h"
26 #include "dsdb/samdb/samdb.h"
28 #include "torture/torture.h"
29 #include "torture/ldap/proto.h"
31 #include "librpc/gen_ndr/ndr_drsblobs.h"
33 #include "param/param.h"
35 static bool test_check_uptodatevector(struct torture_context *torture,
36 struct ldb_context *ldb,
37 struct ldb_dn *partition_dn)
42 enum ndr_err_code ndr_err;
44 const struct ldb_val *utdv_val1;
45 struct replUpToDateVectorBlob utdv1;
46 static const char *attrs[] = {
53 torture_comment(torture, "Check replUpToDateVector on partition[%s]\n",
54 ldb_dn_get_linearized(partition_dn));
56 ret = ldb_search(ldb, torture, &r, partition_dn, LDB_SCOPE_BASE, attrs,
58 if (ret != LDB_SUCCESS) {
60 } else if (r->count != 1) {
66 utdv_val1 = ldb_msg_find_ldb_val(r->msgs[0], "replUpToDateVector");
68 ndr_err = ndr_pull_struct_blob_all(utdv_val1, torture,
70 (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob);
71 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
76 for (i=0; i < 2; i++) {
77 const struct ldb_val *utdv_val;
78 struct replUpToDateVectorBlob utdv;
79 struct ldb_message *msg;
82 bool no_match = false;
84 /* make a 'modify' msg, and only for serverReference */
85 msg = ldb_msg_new(torture);
86 if (!msg) return false;
87 msg->dn = partition_dn;
89 description = talloc_asprintf(msg, "torture replUpToDateVector[%u]", i);
90 if (!description) return false;
92 ret = ldb_msg_add_string(msg, "description", description);
93 if (ret != 0) return false;
95 for (j=0;j<msg->num_elements;j++) {
96 msg->elements[j].flags = LDB_FLAG_MOD_REPLACE;
99 ret = ldb_modify(ldb, msg);
100 if (ret != LDB_SUCCESS) return false;
102 ret = ldb_search(ldb, msg, &r, partition_dn, LDB_SCOPE_BASE,
103 attrs, "(objectClass=*)");
104 if (ret != LDB_SUCCESS) {
106 } else if (r->count != 1) {
112 utdv_val = ldb_msg_find_ldb_val(r->msgs[0], "replUpToDateVector");
114 ndr_err = ndr_pull_struct_blob_all(utdv_val, torture,
116 (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob);
117 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
122 if (!utdv_val1 && utdv_val) {
124 } else if (utdv_val1 && !utdv_val) {
126 } else if (!utdv_val1 && !utdv_val) {
127 } else if (utdv_val1->length != utdv_val->length) {
129 } else if (utdv_val1->length && memcmp(utdv_val1->data, utdv_val->data, utdv_val->length) != 0) {
133 torture_comment(torture, "[%u]: uSNChanged[%llu] description[%s] replUpToDateVector[%s]\n", i,
134 (unsigned long long)ldb_msg_find_attr_as_uint64(r->msgs[0], "uSNChanged", 0),
135 ldb_msg_find_attr_as_string(r->msgs[0], "description", NULL),
136 (no_match ? "changed!: not ok" : "not changed: ok"));
139 NDR_PRINT_DEBUG(replUpToDateVectorBlob, &utdv1);
140 NDR_PRINT_DEBUG(replUpToDateVectorBlob, &utdv);
150 bool torture_ldap_uptodatevector(struct torture_context *torture)
152 struct ldb_context *ldb;
154 const char *host = torture_setting_string(torture, "host", NULL);
157 url = talloc_asprintf(torture, "ldap://%s/", host);
158 if (!url) goto failed;
160 ldb = ldb_wrap_connect(torture, torture->ev, torture->lp_ctx, url,
164 if (!ldb) goto failed;
166 ret &= test_check_uptodatevector(torture, ldb, ldb_get_default_basedn(ldb));
167 ret &= test_check_uptodatevector(torture, ldb, ldb_get_config_basedn(ldb));
168 ret &= test_check_uptodatevector(torture, ldb, ldb_get_schema_basedn(ldb));