2 Unix SMB/Netbios implementation.
4 connection claim routines
5 Copyright (C) Andrew Tridgell 1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 extern fstring remote_machine;
26 static TDB_CONTEXT *tdb;
28 extern int DEBUGLEVEL;
30 /****************************************************************************
31 delete a connection record
32 ****************************************************************************/
33 BOOL yield_connection(connection_struct *conn,char *name,int max_connections)
35 struct connections_key key;
38 if (!tdb) return False;
40 DEBUG(3,("Yielding connection to %s\n",name));
44 if (conn) key.cnum = conn->cnum;
45 fstrcpy(key.name, name);
47 kbuf.dptr = (char *)&key;
48 kbuf.dsize = sizeof(key);
50 tdb_delete(tdb, kbuf);
55 /****************************************************************************
56 claim an entry in the connections database
57 ****************************************************************************/
58 BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOOL Clear)
60 struct connections_key key;
61 struct connections_data crec;
65 if (max_connections <= 0)
69 tdb = tdb_open(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST,
70 O_RDWR | O_CREAT, 0644);
72 if (!tdb) return False;
74 DEBUG(5,("claiming %s %d\n",name,max_connections));
78 key.cnum = conn?conn->cnum:-1;
79 fstrcpy(key.name, name);
81 kbuf.dptr = (char *)&key;
82 kbuf.dsize = sizeof(key);
84 /* fill in the crec */
86 crec.magic = 0x280267;
88 crec.cnum = conn?conn->cnum:-1;
93 lp_servicename(SNUM(conn)),sizeof(crec.name)-1);
95 crec.start = time(NULL);
97 StrnCpy(crec.machine,remote_machine,sizeof(crec.machine)-1);
98 StrnCpy(crec.addr,conn?conn->client_address:client_addr(Client),sizeof(crec.addr)-1);
100 dbuf.dptr = (char *)&crec;
101 dbuf.dsize = sizeof(crec);
103 if (tdb_store(tdb, kbuf, dbuf, TDB_REPLACE) != 0) return False;