LCOV - code coverage report
Current view: top level - source4/dsdb/common/tests - dsdb.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 28 37 75.7 %
Date: 2023-11-21 12:31:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Test DSDB search
       5             : 
       6             :    Copyright (C) Andrew Bartlet <abartlet@samba.org> 2019
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include <ldb_module.h>
      24             : #include "ldb_wrap.h"
      25             : #include "param/param.h"
      26             : #include "param/loadparm.h"
      27             : #include "torture/smbtorture.h"
      28             : #include "torture/dsdb_proto.h"
      29             : #include "auth/auth.h"
      30             : 
      31           2 : bool torture_ldb_no_attrs(struct torture_context *torture)
      32             : {
      33           0 :         struct ldb_context *ldb;
      34           0 :         int ret;
      35           0 :         struct ldb_request *req;
      36           0 :         struct ldb_result *ctx;
      37           0 :         struct ldb_dn *dn;
      38           2 :         const char *attrs[] = { NULL };
      39             : 
      40           0 :         struct auth_session_info *session;
      41           0 :         struct dom_sid domain_sid;
      42           0 :         const char *path;
      43             : 
      44           2 :         path = lpcfg_private_path(NULL, torture->lp_ctx, "sam.ldb");
      45           2 :         torture_assert(torture, path != NULL,
      46             :                        "Couldn't find sam.ldb. Run with -s $SERVERCONFFILE");
      47             : 
      48           2 :         domain_sid = global_sid_Builtin;
      49           2 :         session = admin_session(NULL, torture->lp_ctx, &domain_sid);
      50           2 :         ldb = ldb_wrap_connect(torture, torture->ev, torture->lp_ctx,
      51             :                                path, session, NULL, 0);
      52           2 :         torture_assert(torture, ldb, "Failed to connect to LDB target");
      53             : 
      54           2 :         ctx = talloc_zero(ldb, struct ldb_result);
      55             : 
      56           2 :         dn = ldb_get_default_basedn(ldb);
      57           2 :         ldb_dn_add_child_fmt(dn, "cn=users");
      58           2 :         ret = ldb_build_search_req(&req, ldb, ctx, dn, LDB_SCOPE_SUBTREE,
      59             :                                    "(objectClass=*)", attrs, NULL,
      60             :                                    ctx, ldb_search_default_callback, NULL);
      61           2 :         torture_assert(torture, ret == LDB_SUCCESS,
      62             :                        "Failed to build search request");
      63           2 :         ldb_req_mark_untrusted(req);
      64             : 
      65           2 :         ret = ldb_request(ldb, req);
      66           2 :         torture_assert(torture, ret == LDB_SUCCESS, ldb_errstring(ldb));
      67             : 
      68           2 :         ret = ldb_wait(req->handle, LDB_WAIT_ALL);
      69           2 :         torture_assert(torture, ret == LDB_SUCCESS, ldb_errstring(ldb));
      70             : 
      71           2 :         torture_assert(torture, ctx->count > 0, "Users container empty");
      72           2 :         torture_assert_int_equal(torture, ctx->msgs[0]->num_elements, 0,
      73             :                                  "Attributes returned for request "
      74             :                                  "with empty attribute list");
      75             : 
      76           2 :         return true;
      77             : }
      78             : 
      79        2358 : NTSTATUS torture_dsdb_init(TALLOC_CTX *mem_ctx)
      80             : {
      81        2358 :         struct torture_suite *suite = torture_suite_create(mem_ctx, "dsdb");
      82             : 
      83        2358 :         if (suite == NULL) {
      84           0 :                 return NT_STATUS_NO_MEMORY;
      85             :         }
      86        2358 :         torture_suite_add_simple_test(suite, "no_attrs", torture_ldb_no_attrs);
      87             : 
      88        2358 :         suite->description = talloc_strdup(suite, "DSDB tests");
      89             : 
      90        2358 :         torture_register_suite(mem_ctx, suite);
      91             : 
      92        2358 :         return NT_STATUS_OK;
      93             : }

Generated by: LCOV version 1.14