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
;
64 if (max_connections
<= 0)
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
));
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 */
85 crec
.magic
= 0x280267;
87 crec
.cnum
= conn
?conn
->cnum
:-1;
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
;