LCOV - code coverage report
Current view: top level - lib/ldb/tests - sample_module.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 31 41 75.6 %
Date: 2024-04-21 15:09:00 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           1 : static int sample_add_callback(struct ldb_request *down_req,
      28             :                                struct ldb_reply *ares)
      29             : {
      30           1 :         struct ldb_request *req =
      31           1 :                 talloc_get_type_abort(down_req->context,
      32             :                 struct ldb_request);
      33             : 
      34           1 :         if (ares == NULL) {
      35           0 :                 return ldb_module_done(req, NULL, NULL,
      36             :                                        LDB_ERR_OPERATIONS_ERROR);
      37             :         }
      38             : 
      39           1 :         if (ares->type == LDB_REPLY_REFERRAL) {
      40           0 :                 return ldb_module_send_referral(req, ares->referral);
      41             :         }
      42             : 
      43           1 :         if (ares->error != LDB_SUCCESS) {
      44           0 :                 return ldb_module_done(req, ares->controls,
      45             :                                        ares->response, ares->error);
      46             :         }
      47             : 
      48           1 :         if (ares->type != LDB_REPLY_DONE) {
      49           0 :                 return ldb_module_done(req, NULL, NULL,
      50             :                                        LDB_ERR_OPERATIONS_ERROR);
      51             :         }
      52             : 
      53           1 :         return ldb_module_done(req, ares->controls,
      54             :                                ares->response, LDB_SUCCESS);
      55             : }
      56             : 
      57           2 : static int sample_add(struct ldb_module *mod, struct ldb_request *req)
      58             : {
      59           2 :         struct ldb_context *ldb = ldb_module_get_ctx(mod);
      60           2 :         struct ldb_control *control = NULL;
      61           2 :         struct ldb_message *msg = NULL;
      62           2 :         struct ldb_request *down_req = NULL;
      63           2 :         int ret;
      64             : 
      65             :         /* check if there's a relax control */
      66           2 :         control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID);
      67           2 :         if (control != NULL) {
      68           0 :                 return LDB_ERR_UNWILLING_TO_PERFORM;
      69             :         }
      70             : 
      71           1 :         msg = ldb_msg_copy_shallow(req, req->op.add.message);
      72           1 :         if (msg == NULL) {
      73           0 :                 return LDB_ERR_OPERATIONS_ERROR;
      74             :         }
      75             : 
      76           1 :         ret = ldb_msg_add_fmt(msg, "touchedBy", "sample");
      77           1 :         if (ret != LDB_SUCCESS) {
      78           0 :                 return ret;
      79             :         }
      80             : 
      81           1 :         ret = ldb_build_add_req(&down_req, ldb, req,
      82             :                                 msg,
      83             :                                 req->controls,
      84             :                                 req, sample_add_callback,
      85             :                                 req);
      86           1 :         if (ret != LDB_SUCCESS) {
      87           0 :                 return ret;
      88             :         }
      89             : 
      90           1 :         talloc_steal(down_req, msg);
      91             : 
      92             :         /* go on with the call chain */
      93           1 :         return ldb_next_request(mod, down_req);
      94             : }
      95             : 
      96           1 : static int sample_modify(struct ldb_module *mod, struct ldb_request *req)
      97             : {
      98           1 :         struct ldb_control *control;
      99             : 
     100             :         /* check if there's a relax control */
     101           1 :         control = ldb_request_get_control(req, LDB_CONTROL_RELAX_OID);
     102           1 :         if (control != NULL) {
     103           0 :                 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        6091 : int ldb_sample_init(const char *version)
     119             : {
     120        6091 :         LDB_MODULE_CHECK_VERSION(version);
     121        6091 :         return ldb_register_module(&ldb_sample_module_ops);
     122             : }

Generated by: LCOV version 1.14