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 Return the connection tdb context (used for message send all).
32 ****************************************************************************/
34 TDB_CONTEXT *conn_tdb_ctx(void)
39 /****************************************************************************
40 delete a connection record
41 ****************************************************************************/
42 BOOL yield_connection(connection_struct *conn,char *name,int max_connections)
44 struct connections_key key;
47 if (!tdb) return False;
49 DEBUG(3,("Yielding connection to %s\n",name));
52 key.pid = sys_getpid();
53 key.cnum = conn?conn->cnum:-1;
54 fstrcpy(key.name, name);
55 dos_to_unix(key.name, True); /* Convert key to unix-codepage */
57 kbuf.dptr = (char *)&key;
58 kbuf.dsize = sizeof(key);
60 tdb_delete(tdb, kbuf);
66 /****************************************************************************
67 claim an entry in the connections database
68 ****************************************************************************/
69 BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOOL Clear)
71 struct connections_key key;
72 struct connections_data crec;
76 tdb = tdb_open(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST,
77 O_RDWR | O_CREAT, 0644);
79 if (!tdb) return False;
81 DEBUG(5,("claiming %s %d\n",name,max_connections));
84 key.pid = sys_getpid();
85 key.cnum = conn?conn->cnum:-1;
86 fstrcpy(key.name, name);
87 dos_to_unix(key.name, True); /* Convert key to unix-codepage */
89 kbuf.dptr = (char *)&key;
90 kbuf.dsize = sizeof(key);
92 /* fill in the crec */
94 crec.magic = 0x280267;
95 crec.pid = sys_getpid();
96 crec.cnum = conn?conn->cnum:-1;
101 lp_servicename(SNUM(conn)),sizeof(crec.name)-1);
103 crec.start = time(NULL);
105 StrnCpy(crec.machine,remote_machine,sizeof(crec.machine)-1);
106 StrnCpy(crec.addr,conn?conn->client_address:client_addr(),sizeof(crec.addr)-1);
108 dbuf.dptr = (char *)&crec;
109 dbuf.dsize = sizeof(crec);
111 if (tdb_store(tdb, kbuf, dbuf, TDB_REPLACE) != 0) return False;