summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/smbd/lanman.c54
-rw-r--r--source3/smbd/session.c52
2 files changed, 53 insertions, 53 deletions
diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c
index bb9aea4c5a..b3ee9b5737 100644
--- a/source3/smbd/lanman.c
+++ b/source3/smbd/lanman.c
@@ -3436,38 +3436,6 @@ static BOOL api_WPrintPortEnum(connection_struct *conn,uint16 vuid, char *param,
return(True);
}
-struct session_info {
- char machine[31];
- char username[24];
- char clitype[24];
- int opens;
- int time;
-};
-
-struct sessions_info {
- int count;
- struct session_info *session_list;
-};
-
-static int gather_sessioninfo(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
-{
- struct sessions_info *sinfo = state;
- struct session_info *curinfo = NULL;
- const struct sessionid *sessid = (const struct sessionid *) dbuf.dptr;
-
- sinfo->count += 1;
- sinfo->session_list = REALLOC(sinfo->session_list, sinfo->count * sizeof(struct session_info));
-
- curinfo = &(sinfo->session_list[sinfo->count - 1]);
-
- safe_strcpy(curinfo->machine, sessid->remote_machine,
- sizeof(curinfo->machine));
- safe_strcpy(curinfo->username, uidtoname(sessid->uid),
- sizeof(curinfo->username));
- DEBUG(7,("gather_sessioninfo session from %s@%s\n",
- curinfo->username, curinfo->machine));
- return 0;
-}
/****************************************************************************
List open sessions
@@ -3483,8 +3451,8 @@ static BOOL api_RNetSessionEnum(connection_struct *conn,uint16 vuid, char *param
char *p = skip_string(str2,1);
int uLevel;
struct pack_desc desc;
- struct sessions_info sinfo;
- int i;
+ struct sessionid *session_list;
+ int i, num_sessions;
memset((char *)&desc,'\0',sizeof(desc));
@@ -3498,26 +3466,20 @@ static BOOL api_RNetSessionEnum(connection_struct *conn,uint16 vuid, char *param
if (strcmp(str1,RAP_NetSessionEnum_REQ) != 0) return False;
if (uLevel != 2 || strcmp(str2,RAP_SESSION_INFO_L2) != 0) return False;
- sinfo.count = 0;
- sinfo.session_list = NULL;
-
- if (!session_traverse(gather_sessioninfo, &sinfo)) {
- DEBUG(4,("RNetSessionEnum session_traverse failed\n"));
- return False;
- }
+ num_sessions = list_sessions(&session_list);
if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
memset((char *)&desc,'\0',sizeof(desc));
desc.base = *rdata;
desc.buflen = mdrcnt;
desc.format = str2;
- if (!init_package(&desc,sinfo.count,0)) {
+ if (!init_package(&desc,num_sessions,0)) {
return False;
}
- for(i=0; i<sinfo.count; i++) {
- PACKS(&desc, "z", sinfo.session_list[i].machine);
- PACKS(&desc, "z", sinfo.session_list[i].username);
+ for(i=0; i<num_sessions; i++) {
+ PACKS(&desc, "z", session_list[i].remote_machine);
+ PACKS(&desc, "z", session_list[i].username);
PACKI(&desc, "W", 1); /* num conns */
PACKI(&desc, "W", 0); /* num opens */
PACKI(&desc, "W", 1); /* num users */
@@ -3533,7 +3495,7 @@ static BOOL api_RNetSessionEnum(connection_struct *conn,uint16 vuid, char *param
*rparam = REALLOC(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0); /* converter */
- SSVAL(*rparam,4,sinfo.count); /* count */
+ SSVAL(*rparam,4,num_sessions); /* count */
DEBUG(4,("RNetSessionEnum: errorcode %d\n",desc.errcode));
return True;
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;
+}
+