LCOV - code coverage report
Current view: top level - lib/ldb/tests - sample_module.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 31 39 79.5 %
Date: 2021-08-25 13:27:56 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    Samba utility functions
       4             :    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
       5             : 
       6             :      ** NOTE! The following LGPL license applies to the ldb
       7             :      ** library. This does NOT imply that all of Samba is released
       8             :      ** under the LGPL
       9             :    
      10             :    This library is free software; you can redistribute it and/or
      11             :    modify it under the terms of the GNU Lesser General Public
      12             :    License as published by the Free Software Foundation; either
      13             :    version 3 of the License, or (at your option) any later version.
      14             : 
      15             :    This library is distributed in the hope that it will be useful,
      16             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      17             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      18             :    Lesser General Public License for more details.
      19             : 
      20             :    You should have received a copy of the GNU Lesser General Public
      21             :    License along with this library; if not, see <http://www.gnu.org/licenses/>.
      22             : */
      23             : 
      24             : #include "replace.h"
      25             : #include "ldb_module.h"
      26             : 
      27           2 : static int sample_add_callback(struct ldb_request *down_req,
      28             :                                struct ldb_reply *ares)
      29             : {
      30           2 :         struct ldb_request *req =
      31           2 :                 talloc_get_type_abort(down_req->context,
      32             :                 struct ldb_request);
      33             : 
      34           2 :         if (ares == NULL) {
      35           0 :                 return ldb_module_done(req, NULL, NULL,
      36             :                                        LDB_ERR_OPERATIONS_ERROR);
      37             :         }
      38             : 
      39           2 :         if (ares->type == LDB_REPLY_REFERRAL) {
      40           0 :                 return ldb_module_send_referral(req, ares->referral);
      41             :         }
      42             : 
      43           2 :         if (ares->error != LDB_SUCCESS) {
      44           0 :                 return ldb_module_done(req, ares->controls,
      45             :                                        ares->response, ares->error);
      46             :         }
      47             : 
      48           2 :         if (ares->type != LDB_REPLY_DONE) {
      49           0 :                 return ldb_module_done(req, NULL, NULL,
      50             :                                        LDB_ERR_OPERATIONS_ERROR);
      51             :         }
      52             : 
      53           2 :         return ldb_module_done(req, ares->controls,
      54             :                                ares->response, LDB_SUCCESS);
      55             : }
      56             : 
      57           4 : static int sample_add(struct ldb_module *mod, struct ldb_request *req)
      58             : {
      59           4 :         struct ldb_context *ldb = ldb_module_get_ctx(mod);
      60           4 :         struct ldb_control *control = NULL;
      61           4 :         struct ldb_message *msg = NULL;
      62           4 :         struct ldb_request *down_req = NULL;
      63             :         int ret;
      64             : 
      65             :         /* check if there's a relax control */
      66           4 :         control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID);
      67           4 :         if (control != NULL) {
      68           1 :                 return LDB_ERR_UNWILLING_TO_PERFORM;
      69             :         }
      70             : 
      71           2 :         msg = ldb_msg_copy_shallow(req, req->op.add.message);
      72           2 :         if (msg == NULL) {
      73           0 :                 return LDB_ERR_OPERATIONS_ERROR;
      74             :         }
      75             : 
      76           2 :         ret = ldb_msg_add_fmt(msg, "touchedBy", "sample");
      77           2 :         if (ret != LDB_SUCCESS) {
      78           0 :                 return ret;
      79             :         }
      80             : 
      81           2 :         ret = ldb_build_add_req(&down_req, ldb, req,
      82             :                                 msg,
      83             :                                 req->controls,
      84             :                                 req, sample_add_callback,
      85             :                                 req);
      86           2 :         if (ret != LDB_SUCCESS) {
      87           0 :                 return ret;
      88             :         }
      89             : 
      90           2 :         talloc_steal(down_req, msg);
      91             : 
      92             :         /* go on with the call chain */
      93           2 :         return ldb_next_request(mod, down_req);
      94             : }
      95             : 
      96           2 : static int sample_modify(struct ldb_module *mod, struct ldb_request *req)
      97             : {
      98             :         struct ldb_control *control;
      99             : 
     100             :         /* check if there's a relax control */
     101           2 :         control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID);
     102           2 :         if (control != NULL) {
     103           1 :                 return LDB_ERR_UNWILLING_TO_PERFORM;
     104             :         }
     105             : 
     106             :         /* not found go on */
     107           0 :         return ldb_next_request(mod, req);
     108             : }
     109             : 
     110             : 
     111             : static struct ldb_module_ops ldb_sample_module_ops = {
     112             :         .name              = "sample",
     113             :         .add               = sample_add,
     114             :         .del               = sample_modify,
     115             :         .modify            = sample_modify,
     116             : };
     117             : 
     118        5766 : int ldb_sample_init(const char *version)
     119             : {
     120        5766 :         LDB_MODULE_CHECK_VERSION(version);
     121        5766 :         return ldb_register_module(&ldb_sample_module_ops);
     122             : }

Generated by: LCOV version 1.13