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;
27 extern int DEBUGLEVEL;
29 /****************************************************************************
30 delete a connection record
31 ****************************************************************************/
32 BOOL yield_connection(connection_struct *conn,char *name,int max_connections)
34 struct connections_key key;
38 tdb = tdb_open(lock_path("connections.tdb"), 0, O_RDWR | O_CREAT, 0644);
39 if (!tdb) return False;
41 DEBUG(3,("Yielding connection to %s\n",name));
45 if (conn) key.cnum = conn->cnum;
46 fstrcpy(key.name, name);
48 kbuf.dptr = (char *)&key;
49 kbuf.dsize = sizeof(key);
51 tdb_delete(tdb, kbuf);
57 /****************************************************************************
58 claim an entry in the connections database
59 ****************************************************************************/
60 int delete_dead(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf)
62 struct connections_key key;
63 memcpy(&key, kbuf.dptr, sizeof(key));
64 if (!process_exists(key.pid)) tdb_delete(tdb, kbuf);
69 /****************************************************************************
70 claim an entry in the connections database
71 ****************************************************************************/
72 BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOOL Clear)
74 struct connections_key key;
75 struct connections_data crec;
80 if (max_connections <= 0)
83 tdb = tdb_open(lock_path("connections.tdb"), 0, O_RDWR | O_CREAT, 0644);
84 if (!tdb) return False;
86 DEBUG(5,("claiming %s %d\n",name,max_connections));
90 key.cnum = conn?conn->cnum:-1;
91 fstrcpy(key.name, name);
93 kbuf.dptr = (char *)&key;
94 kbuf.dsize = sizeof(key);
97 tdb_traverse(tdb, delete_dead);
100 /* fill in the crec */
102 crec.magic = 0x280267;
104 crec.cnum = conn?conn->cnum:-1;
106 crec.uid = conn->uid;
107 crec.gid = conn->gid;
109 lp_servicename(SNUM(conn)),sizeof(crec.name)-1);
111 crec.start = time(NULL);
113 StrnCpy(crec.machine,remote_machine,sizeof(crec.machine)-1);
114 StrnCpy(crec.addr,conn?conn->client_address:client_addr(Client),sizeof(crec.addr)-1);
116 dbuf.dptr = (char *)&crec;
117 dbuf.dsize = sizeof(crec);
119 if (tdb_store(tdb, kbuf, dbuf, TDB_REPLACE) != 0) return False;