summaryrefslogtreecommitdiff
path: root/source3/smbd/session.c
diff options
context:
space:
mode:
authorJim McDonough <jmcd@samba.org>2002-06-03 22:15:46 +0000
committerJim McDonough <jmcd@samba.org>2002-06-03 22:15:46 +0000
commitb1eaa2f17e0afbe864482fe4eb2d24a9a98d1b4a (patch)
tree99bbe45e2445850c58702d31871f95a5b1be4ffe /source3/smbd/session.c
parente142b4b324db501ec6a0d078c541aa3f5d9e185b (diff)
downloadsamba-b1eaa2f17e0afbe864482fe4eb2d24a9a98d1b4a.tar.gz
samba-b1eaa2f17e0afbe864482fe4eb2d24a9a98d1b4a.tar.bz2
samba-b1eaa2f17e0afbe864482fe4eb2d24a9a98d1b4a.zip
Move session gathering routine back into session.c so it can be called either
in RAP or RPC environment. (This used to be commit 3eec0d64c7c4592d4f0d74108fb0be2b7a22bde6)
Diffstat (limited to 'source3/smbd/session.c')
-rw-r--r--source3/smbd/session.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/source3/smbd/session.c b/source3/smbd/session.c
index 05a7b24da2..dade953ec1 100644
--- a/source3/smbd/session.c
+++ b/source3/smbd/session.c
@@ -163,16 +163,54 @@ void session_yield(user_struct *vuser)
tdb_delete(tdb, key);
}
-BOOL session_traverse(int (*fn)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *), void *state)
+static BOOL session_traverse(int (*fn)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *), void *state)
{
- if (!tdb) {
- DEBUG(3, ("No tdb opened\n"));
- return False;
- }
+ if (!tdb) {
+ DEBUG(3, ("No tdb opened\n"));
+ return False;
+ }
- tdb_traverse(tdb, fn, state);
- return True;
+ tdb_traverse(tdb, fn, state);
+ return True;
}
+struct session_list {
+ int count;
+ struct sessionid *sessions;
+};
+
+static int gather_sessioninfo(TDB_CONTEXT *stdb, TDB_DATA kbuf, TDB_DATA dbuf,
+ void *state)
+{
+ struct session_list *sesslist = (struct session_list *) state;
+ const struct sessionid *current = (const struct sessionid *) dbuf.dptr;
+
+ sesslist->count += 1;
+ sesslist->sessions = REALLOC(sesslist->sessions, sesslist->count *
+ sizeof(struct sessionid));
+
+ memcpy(&sesslist->sessions[sesslist->count - 1], current,
+ sizeof(struct sessionid));
+ DEBUG(7,("gather_sessioninfo session from %s@%s\n",
+ current->username, current->remote_machine));
+ return 0;
+}
+int list_sessions(struct sessionid **session_list)
+{
+ struct session_list sesslist;
+
+ sesslist.count = 0;
+ sesslist.sessions = NULL;
+
+ if (!session_traverse(gather_sessioninfo, (void *) &sesslist)) {
+ DEBUG(3, ("Session traverse failed\n"));
+ SAFE_FREE(sesslist.sessions);
+ *session_list = NULL;
+ return 0;
+ }
+ *session_list = sesslist.sessions;
+ return sesslist.count;
+}
+