ldb: Add more data test data for one level test cases
[Samba/gebeck_regimport.git] / source3 / smbd / connection.c
blob0b78b9e2dbb2fbda165cd3a44470f8fe6f8204cf
1 /*
2 Unix SMB/CIFS implementation.
3 connection claim routines
4 Copyright (C) Andrew Tridgell 1998
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.
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.
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/>.
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 #include "lib/conn_tdb.h"
29 struct count_stat {
30 int curr_connections;
31 const char *name;
32 bool verify;
35 /****************************************************************************
36 Count the entries belonging to a service in the connection db.
37 ****************************************************************************/
39 static int count_fn(struct smbXsrv_tcon_global0 *tcon,
40 void *udp)
42 struct count_stat *cs = (struct count_stat *)udp;
44 if (cs->verify && !process_exists(tcon->server_id)) {
45 return 0;
48 if (strequal(tcon->share_name, cs->name)) {
49 cs->curr_connections++;
52 return 0;
55 /****************************************************************************
56 Claim an entry in the connections database.
57 ****************************************************************************/
59 int count_current_connections(const char *sharename, bool verify)
61 struct count_stat cs;
62 NTSTATUS status;
64 cs.curr_connections = 0;
65 cs.name = sharename;
66 cs.verify = verify;
69 * This has a race condition, but locking the chain before hand is worse
70 * as it leads to deadlock.
73 status = smbXsrv_tcon_global_traverse(count_fn, &cs);
75 if (!NT_STATUS_IS_OK(status)) {
76 DEBUG(0,("count_current_connections: traverse of "
77 "smbXsrv_tcon_global.tdb failed - %s\n",
78 nt_errstr(status)));
79 return 0;
82 return cs.curr_connections;
85 bool connections_snum_used(struct smbd_server_connection *unused, int snum)
87 int active;
89 active = count_current_connections(lp_servicename(talloc_tos(), snum),
90 true);
91 if (active > 0) {
92 return true;
95 return false;