This commit was manufactured by cvs2svn to create branch 'SAMBA_TNG'.
[Samba.git] / source / smbd / connection.c
blobfc025bc826a01403fe3196b1c74b8531b7331f07
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
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.
22 #include "includes.h"
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;
36 TDB_DATA kbuf;
38 if (!tdb) return False;
40 DEBUG(3,("Yielding connection to %s\n",name));
42 ZERO_STRUCT(key);
43 key.pid = getpid();
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);
51 return(True);
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;
62 TDB_DATA kbuf, dbuf;
64 if (max_connections <= 0)
65 return(True);
67 if (!tdb) {
68 tdb = tdb_open(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST,
69 O_RDWR | O_CREAT, 0644);
71 if (!tdb) return False;
73 DEBUG(5,("claiming %s %d\n",name,max_connections));
75 ZERO_STRUCT(key);
76 key.pid = getpid();
77 key.cnum = conn?conn->cnum:-1;
78 fstrcpy(key.name, name);
80 kbuf.dptr = (char *)&key;
81 kbuf.dsize = sizeof(key);
83 /* fill in the crec */
84 ZERO_STRUCT(crec);
85 crec.magic = 0x280267;
86 crec.pid = getpid();
87 crec.cnum = conn?conn->cnum:-1;
88 if (conn) {
89 crec.uid = conn->uid;
90 crec.gid = conn->gid;
91 StrnCpy(crec.name,
92 lp_servicename(SNUM(conn)),sizeof(crec.name)-1);
94 crec.start = time(NULL);
96 StrnCpy(crec.machine,remote_machine,sizeof(crec.machine)-1);
97 StrnCpy(crec.addr,conn?conn->client_address:client_connection_addr(),sizeof(crec.addr)-1);
99 dbuf.dptr = (char *)&crec;
100 dbuf.dsize = sizeof(crec);
102 if (tdb_store(tdb, kbuf, dbuf, TDB_REPLACE) != 0) return False;
104 return True;