LCOV - code coverage report
Current view: top level - source4/torture/ldap - uptodatevector.c (source / functions) Hit Total Coverage
Test: coverage report for fix-15632 9995c5c2 Lines: 48 85 56.5 %
Date: 2024-04-13 12:30:31 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS Implementation.
       3             :    LDAP replUpToDateVector tests
       4             :    
       5             :    Copyright (C) Stefan Metzmacher 2007
       6             :    
       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.
      11             :    
      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.
      16             :    
      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/>.
      19             :    
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "libcli/ldap/ldap_client.h"
      24             : #include "lib/cmdline/cmdline.h"
      25             : #include "ldb_wrap.h"
      26             : #include "dsdb/samdb/samdb.h"
      27             : 
      28             : #include "torture/torture.h"
      29             : #include "torture/ldap/proto.h"
      30             : 
      31             : #include "librpc/gen_ndr/ndr_drsblobs.h"
      32             : 
      33             : #include "param/param.h"
      34             : 
      35           3 : static bool test_check_uptodatevector(struct torture_context *torture,
      36             :                                       struct ldb_context *ldb,
      37             :                                       struct ldb_dn *partition_dn)
      38             : {
      39           3 :         bool ok = true;
      40           0 :         uint32_t i;
      41           0 :         int ret;
      42           0 :         enum ndr_err_code ndr_err;
      43           0 :         struct ldb_result *r;
      44           0 :         const struct ldb_val *utdv_val1;
      45           0 :         struct replUpToDateVectorBlob utdv1;
      46           0 :         static const char *attrs[] = {
      47             :                 "uSNChanged",
      48             :                 "replUpToDateVector",
      49             :                 "description",
      50             :                 NULL
      51             :         };
      52             : 
      53           3 :         torture_comment(torture, "Check replUpToDateVector on partition[%s]\n",
      54             :                                  ldb_dn_get_linearized(partition_dn));
      55             : 
      56           3 :         ret = ldb_search(ldb, torture, &r, partition_dn, LDB_SCOPE_BASE, attrs,
      57             :                          "(objectClass=*)");
      58           3 :         if (ret != LDB_SUCCESS) {
      59           0 :                 return false;
      60           3 :         } else if (r->count != 1) {
      61           0 :                 talloc_free(r);
      62           0 :                 return false;
      63             :         }
      64             : 
      65           3 :         ZERO_STRUCT(utdv1);
      66           3 :         utdv_val1 = ldb_msg_find_ldb_val(r->msgs[0], "replUpToDateVector");
      67           3 :         if (utdv_val1) {
      68           0 :                 ndr_err = ndr_pull_struct_blob_all(utdv_val1, torture, 
      69             :                                                    &utdv1,
      70             :                                                    (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob);
      71           0 :                 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
      72           0 :                         return false;
      73             :                 }
      74             :         }
      75             : 
      76           9 :         for (i=0; i < 2; i++) {
      77           0 :                 const struct ldb_val *utdv_val;
      78           0 :                 struct replUpToDateVectorBlob utdv;
      79           0 :                 struct ldb_message *msg;
      80           0 :                 char *description;
      81           0 :                 uint32_t j;
      82           6 :                 bool no_match = false;
      83             : 
      84             :                 /* make a 'modify' msg, and only for serverReference */
      85           6 :                 msg = ldb_msg_new(torture);
      86           6 :                 if (!msg) return false;
      87           6 :                 msg->dn = partition_dn;
      88             : 
      89           6 :                 description = talloc_asprintf(msg, "torture replUpToDateVector[%u]", i);
      90           6 :                 if (!description) return false;
      91             : 
      92           6 :                 ret = ldb_msg_add_string(msg, "description", description);
      93           6 :                 if (ret != 0) return false;
      94             : 
      95          12 :                 for (j=0;j<msg->num_elements;j++) {
      96           6 :                         msg->elements[j].flags = LDB_FLAG_MOD_REPLACE;
      97             :                 }
      98             : 
      99           6 :                 ret = ldb_modify(ldb, msg);
     100           6 :                 if (ret != LDB_SUCCESS) return false;
     101             : 
     102           6 :                 ret = ldb_search(ldb, msg, &r, partition_dn, LDB_SCOPE_BASE,
     103             :                                  attrs, "(objectClass=*)");
     104           6 :                 if (ret != LDB_SUCCESS) {
     105           0 :                         return false;
     106           6 :                 } else if (r->count != 1) {
     107           0 :                         talloc_free(r);
     108           0 :                         return false;
     109             :                 }
     110             : 
     111           6 :                 ZERO_STRUCT(utdv);
     112           6 :                 utdv_val = ldb_msg_find_ldb_val(r->msgs[0], "replUpToDateVector");
     113           6 :                 if (utdv_val) {
     114           0 :                         ndr_err = ndr_pull_struct_blob_all(utdv_val, torture, 
     115             :                                                            &utdv,
     116             :                                                            (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob);
     117           0 :                         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     118           0 :                                 return false;
     119             :                         }
     120             :                 }
     121             : 
     122           6 :                 if (!utdv_val1 && utdv_val) {
     123           0 :                         no_match = true;
     124           6 :                 } else if (utdv_val1 && !utdv_val) {
     125           0 :                         no_match = true;
     126           6 :                 } else if (!utdv_val1 && !utdv_val) {
     127           0 :                 } else if (utdv_val1->length != utdv_val->length) {
     128           0 :                         no_match = true;
     129           0 :                 } else if (utdv_val1->length && memcmp(utdv_val1->data, utdv_val->data, utdv_val->length) != 0) {
     130           0 :                         no_match = true;
     131             :                 }
     132             : 
     133          12 :                 torture_comment(torture, "[%u]: uSNChanged[%llu] description[%s] replUpToDateVector[%s]\n", i,
     134           6 :                                 (unsigned long long)ldb_msg_find_attr_as_uint64(r->msgs[0], "uSNChanged", 0),
     135           6 :                                 ldb_msg_find_attr_as_string(r->msgs[0], "description", NULL),
     136             :                                 (no_match ? "changed!: not ok" : "not changed: ok"));
     137             : 
     138           6 :                 if (no_match) {
     139           0 :                         NDR_PRINT_DEBUG(replUpToDateVectorBlob, &utdv1);
     140           0 :                         NDR_PRINT_DEBUG(replUpToDateVectorBlob, &utdv);
     141           0 :                         ok = false;
     142             :                 }
     143             : 
     144           6 :                 talloc_free(msg);
     145             :         }
     146             : 
     147           3 :         return ok;
     148             : }
     149             : 
     150           1 : bool torture_ldap_uptodatevector(struct torture_context *torture)
     151             : {
     152           0 :         struct ldb_context *ldb;
     153           1 :         bool ret = true;
     154           1 :         const char *host = torture_setting_string(torture, "host", NULL);
     155           0 :         char *url;
     156             : 
     157           1 :         url = talloc_asprintf(torture, "ldap://%s/", host);
     158           1 :         if (!url) goto failed;
     159             : 
     160           1 :         ldb = ldb_wrap_connect(torture, torture->ev, torture->lp_ctx, url,
     161             :                                NULL,
     162             :                                samba_cmdline_get_creds(),
     163             :                                0);
     164           1 :         if (!ldb) goto failed;
     165             : 
     166           1 :         ret &= test_check_uptodatevector(torture, ldb, ldb_get_default_basedn(ldb));
     167           1 :         ret &= test_check_uptodatevector(torture, ldb, ldb_get_config_basedn(ldb));
     168           1 :         ret &= test_check_uptodatevector(torture, ldb, ldb_get_schema_basedn(ldb));
     169             : 
     170           1 :         return ret;
     171           0 : failed:
     172           0 :         return false;
     173             : }

Generated by: LCOV version 1.14