LCOV - code coverage report
Current view: top level - source3/smbd - connection.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 13 23 56.5 %
Date: 2021-09-23 10:06:22 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    connection claim routines
       4             :    Copyright (C) Andrew Tridgell 1998
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             : 
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "smbd/smbd.h"
      22             : #include "smbd/globals.h"
      23             : #include "dbwrap/dbwrap.h"
      24             : #include "auth.h"
      25             : #include "../lib/tsocket/tsocket.h"
      26             : #include "messages.h"
      27             : 
      28             : struct count_stat {
      29             :         int curr_connections;
      30             :         const char *name;
      31             :         bool verify;
      32             : };
      33             : 
      34             : /****************************************************************************
      35             :  Count the entries belonging to a service in the connection db.
      36             : ****************************************************************************/
      37             : 
      38          58 : static int count_fn(struct smbXsrv_tcon_global0 *tcon,
      39             :                     void *udp)
      40             : {
      41          58 :         struct count_stat *cs = (struct count_stat *)udp;
      42             : 
      43          58 :         if (cs->verify && !process_exists(tcon->server_id)) {
      44           0 :                 return 0;
      45             :         }
      46             : 
      47          58 :         if (strequal(tcon->share_name, cs->name)) {
      48          12 :                 cs->curr_connections++;
      49             :         }
      50             : 
      51          58 :         return 0;
      52             : }
      53             : 
      54             : /****************************************************************************
      55             :  Claim an entry in the connections database.
      56             : ****************************************************************************/
      57             : 
      58          16 : int count_current_connections(const char *sharename, bool verify)
      59             : {
      60             :         struct count_stat cs;
      61             :         NTSTATUS status;
      62             : 
      63          16 :         cs.curr_connections = 0;
      64          16 :         cs.name = sharename;
      65          16 :         cs.verify = verify;
      66             : 
      67             :         /*
      68             :          * This has a race condition, but locking the chain before hand is worse
      69             :          * as it leads to deadlock.
      70             :          */
      71             : 
      72          16 :         status = smbXsrv_tcon_global_traverse(count_fn, &cs);
      73             : 
      74          16 :         if (!NT_STATUS_IS_OK(status)) {
      75           0 :                 DEBUG(0,("count_current_connections: traverse of "
      76             :                          "smbXsrv_tcon_global.tdb failed - %s\n",
      77             :                          nt_errstr(status)));
      78           0 :                 return 0;
      79             :         }
      80             : 
      81          16 :         return cs.curr_connections;
      82             : }
      83             : 
      84           0 : bool connections_snum_used(struct smbd_server_connection *unused, int snum)
      85             : {
      86           0 :         const struct loadparm_substitution *lp_sub =
      87           0 :                 loadparm_s3_global_substitution();
      88             :         int active;
      89             : 
      90           0 :         active = count_current_connections(lp_servicename(talloc_tos(), lp_sub, snum),
      91             :                                            true);
      92           0 :         if (active > 0) {
      93           0 :                 return true;
      94             :         }
      95             : 
      96           0 :         return false;
      97             : }

Generated by: LCOV version 1.13