2 Unix SMB/CIFS implementation.
3 Low-level connections.tdb access functions
4 Copyright (C) Volker Lendecke 2007
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 TDB_CONTEXT *conn_tdb_ctx(BOOL rw)
25 static TDB_CONTEXT *tdb;
32 tdb = tdb_open_log(lock_path("connections.tdb"), 0,
33 TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
34 O_RDWR | O_CREAT, 0644);
37 tdb = tdb_open_log(lock_path("connections.tdb"), 0,
38 TDB_DEFAULT, O_RDONLY, 0);
42 DEBUG(0, ("Could not open connections.tdb: %s\n",
49 struct conn_traverse_state {
50 int (*fn)(TDB_CONTEXT *tdb,
51 const struct connections_key *key,
52 const struct connections_data *data,
57 static int conn_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key,
58 TDB_DATA data, void *private_data)
60 struct conn_traverse_state *state =
61 (struct conn_traverse_state *)private_data;
63 if ((key.dsize != sizeof(struct connections_key))
64 || (data.dsize != sizeof(struct connections_data))) {
69 tdb, (const struct connections_key *)key.dptr,
70 (const struct connections_data *)data.dptr,
74 int connections_traverse(int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key,
75 TDB_DATA data, void *private_data),
78 TDB_CONTEXT *tdb = conn_tdb_ctx(True);
81 DEBUG(5, ("Could not open connections.tdb r/w, trying r/o\n"));
82 tdb = conn_tdb_ctx(False);
89 return tdb_traverse(tdb, fn, private_data);
92 int connections_forall(int (*fn)(TDB_CONTEXT *tdb,
93 const struct connections_key *key,
94 const struct connections_data *data,
98 struct conn_traverse_state state;
101 state.private_data = private_data;
103 return connections_traverse(conn_traverse_fn, (void *)&state);
106 BOOL connections_init(BOOL rw)
108 return (conn_tdb_ctx(rw) != NULL);