From a443dea5d1f6b63c464711a16fbea87541621394 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Mon, 22 Oct 2001 18:14:42 +0000 Subject: server support for RAP session list function (This used to be commit d42c28fbadf577a23fb8c1da9e1c64a2f34fe133) --- source3/smbd/lanman.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ source3/smbd/session.c | 13 ++++++ 2 files changed, 118 insertions(+) diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c index d4d7683855..3150253dab 100644 --- a/source3/smbd/lanman.c +++ b/source3/smbd/lanman.c @@ -3415,6 +3415,110 @@ 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; + struct sessionid *sessid = (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 + ****************************************************************************/ +static BOOL api_RNetSessionEnum(connection_struct *conn,uint16 vuid, char *param, char *data, + int mdrcnt,int mprcnt, + char **rdata,char **rparam, + int *rdata_len,int *rparam_len) + +{ + char *str1 = param+2; + char *str2 = skip_string(str1,1); + char *p = skip_string(str2,1); + int uLevel; + struct pack_desc desc; + struct sessions_info sinfo; + int i; + + memset((char *)&desc,'\0',sizeof(desc)); + + uLevel = SVAL(p,0); + + DEBUG(3,("RNetSessionEnum uLevel=%d\n",uLevel)); + DEBUG(7,("RNetSessionEnum req string=%s\n",str1)); + DEBUG(7,("RNetSessionEnum ret string=%s\n",str2)); + + /* check it's a supported varient */ + 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; + } + + 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)) { + return False; + } + + for(i=0; i