summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/lib/util_status.c83
-rw-r--r--source3/rpc_server/srv_srvsvc.c42
2 files changed, 111 insertions, 14 deletions
diff --git a/source3/lib/util_status.c b/source3/lib/util_status.c
index 74ffc62c34..836388a1bd 100644
--- a/source3/lib/util_status.c
+++ b/source3/lib/util_status.c
@@ -47,7 +47,7 @@ BOOL get_connection_status(struct connect_record **crec,
trim_string(fname,"","/");
pstrcat(fname,"/STATUS..LCK");
-fd = sys_open(fname,O_RDONLY, 0);
+ fd = sys_open(fname,O_RDONLY, 0);
if (fd == -1)
{
@@ -65,10 +65,11 @@ fd = sys_open(fname,O_RDONLY, 0);
{
(*crec) = Realloc((*crec), (conn+1) * sizeof((*crec)[conn]));
if ((*crec) == NULL)
- {
- DEBUG(0,("Realloc failed in get_connection_status\n"));
- return False;
- }
+ {
+ DEBUG(0,("Realloc failed in get_connection_status\n"));
+ return False;
+ }
+
c = &((*crec)[conn]);
if (sys_lseek(fd,i*sizeof(*c),SEEK_SET) != i*sizeof(*c) ||
read(fd,c,sizeof(*c)) != sizeof(*c))
@@ -82,12 +83,78 @@ fd = sys_open(fname,O_RDONLY, 0);
/* valid connection, smbd process still going, connection still going */
if ( c->magic == 0x280267 && process_exists(c->pid) && c->cnum != -1 )
{
- conn++;
+ conn++;
}
+
}
-
close(fd);
(*connection_count)=conn;
-
return True;
}
+
+/*******************************************************************
+Get the number of open Sessions. Not optimal yet. Has at least O(n*log(n)).
+ ********************************************************************/
+BOOL get_session_count(struct connect_record **srec,uint32 *session_count)
+{
+ struct connect_record *crec = NULL;
+ struct connect_record *c;
+
+ uint32 connection_count;
+ uint32 conn;
+ int *pid;
+ int i;
+ int MaxPid;
+ BOOL found;
+
+ (*srec) = NULL;
+ pid = NULL;
+ if (get_connection_status(&crec, &connection_count))
+ {
+ MaxPid = 0;
+ for (conn = 0; conn < connection_count; conn++)
+ {
+ DEBUG(10,("Connection nr : %u\n",conn));
+ found=False;
+ for (i = 0; i < MaxPid; i++)
+ {
+ if (crec[conn].pid == pid[i])
+ {
+ found = True;
+ i=MaxPid;
+ }
+ }
+ if (!found) {
+ (*srec) = Realloc((*srec), (MaxPid+1) * sizeof((*srec)[MaxPid]));
+ if ((*srec) == NULL)
+ {
+ DEBUG(0,("Realloc failed in get_connection_status\n"));
+ return False;
+ }
+ pid = Realloc(pid, (MaxPid+1) * sizeof(int));
+ if (pid == NULL)
+ {
+ DEBUG(0,("Realloc failed in get_session_count\n"));
+ free(crec);
+ return False;
+ }
+ c = &((*srec)[MaxPid]);
+ pid[MaxPid]=crec[conn].pid;
+ pstrcpy(c->machine,crec[conn].machine);
+ c->uid = crec[conn].uid;
+ c->pid = crec[conn].pid;
+ c->cnum = crec[conn].cnum;
+ pstrcpy(c->name,crec[conn].name);
+
+ MaxPid++;
+ }
+ }
+ } else {
+/* crec is not valid, so no need to free it here */
+ return False;
+ }
+ free(crec);
+ (*session_count) = MaxPid;
+ return True;
+}
+
diff --git a/source3/rpc_server/srv_srvsvc.c b/source3/rpc_server/srv_srvsvc.c
index 834c95615a..35f1676232 100644
--- a/source3/rpc_server/srv_srvsvc.c
+++ b/source3/rpc_server/srv_srvsvc.c
@@ -300,23 +300,36 @@ static void make_srv_sess_0_info(SESS_INFO_0 *se0, SESS_INFO_0_STR *str0,
static void make_srv_sess_info_0(SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *stot)
{
uint32 num_entries = 0;
- (*stot) = 1;
+ struct connect_record *crec;
+ uint32 session_count;
- if (ss0 == NULL)
+ if (!get_session_count(&crec, &session_count))
{
(*snum) = 0;
+ (*stot) = 0;
return;
}
- DEBUG(5,("make_srv_sess_0_ss0\n"));
+ (*stot) = session_count;
+
+ DEBUG(0,("Session Count : %u\n",session_count));
+
+ if (ss0 == NULL)
+ {
+ (*snum) = 0;
+ free(crec);
+ return;
+ }
if (snum)
{
+ DEBUG(0,("snum ok\n"));
for (; (*snum) < (*stot) && num_entries < MAX_SESS_ENTRIES; (*snum)++)
{
make_srv_sess_0_info(&(ss0->info_0 [num_entries]),
- &(ss0->info_0_str[num_entries]), "MACHINE");
+ &(ss0->info_0_str[num_entries]), crec[num_entries].machine);
+ DEBUG(0,("make_srv_sess_0_info\n"));
/* move on to creating next session */
/* move on to creating next sess */
num_entries++;
@@ -337,6 +350,7 @@ static void make_srv_sess_info_0(SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *sto
ss0->ptr_sess_info = 0;
ss0->num_entries_read2 = 0;
}
+ free(crec);
}
/*******************************************************************
@@ -368,11 +382,23 @@ static void make_srv_sess_1_info(SESS_INFO_1 *se1, SESS_INFO_1_STR *str1,
static void make_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *stot)
{
uint32 num_entries = 0;
- (*stot) = 1;
+ struct connect_record *crec;
+ uint32 session_count;
+
+ if (!get_session_count(&crec, &session_count))
+ {
+ (*snum) = 0;
+ (*stot) = 0;
+ return;
+ }
+ (*stot) = session_count;
+
+ DEBUG(0,("Session Count (info1) : %u\n",session_count));
if (ss1 == NULL)
{
(*snum) = 0;
+ free(crec);
return;
}
@@ -382,9 +408,12 @@ static void make_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *sto
{
for (; (*snum) < (*stot) && num_entries < MAX_SESS_ENTRIES; (*snum)++)
{
+ DEBUG(0,("sess1 machine: %s, uid : %u\n",crec[num_entries].machine,crec[num_entries].uid));
make_srv_sess_1_info(&(ss1->info_1 [num_entries]),
&(ss1->info_1_str[num_entries]),
- "MACHINE", "dummy_user", 1, 10, 5, 0);
+ crec[num_entries].machine,
+ uidtoname(crec[num_entries].uid), 1, 10, 5, 0);
+/* What are these on the End ??? */
/* move on to creating next session */
/* move on to creating next sess */
@@ -408,6 +437,7 @@ static void make_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *sto
(*stot) = 0;
}
+ free(crec);
}
/*******************************************************************