who_list fixes/cleanup

This commit is contained in:
Doug MacEachern 2005-10-02 05:52:33 +00:00
parent b22f20c335
commit 8cd8f0f8bd
1 changed files with 27 additions and 17 deletions

View File

@ -278,6 +278,11 @@ int sigar_os_open(sigar_t **sigar)
(*sigar)->ps_handle = NULL; (*sigar)->ps_handle = NULL;
} }
(*sigar)->wts_enum_sessions = NULL;
(*sigar)->wts_free = NULL;
(*sigar)->wts_query_session = NULL;
(*sigar)->query_station = NULL;
if ((h = LoadLibrary("wtsapi32.dll"))) { if ((h = LoadLibrary("wtsapi32.dll"))) {
(*sigar)->wts_handle = h; (*sigar)->wts_handle = h;
} }
@ -2096,18 +2101,6 @@ SIGAR_DECLARE(int) sigar_proc_port_get(sigar_t *sigar,
return ENOENT; return ENOENT;
} }
int sigar_who_list_get_win32(sigar_t *sigar,
sigar_who_list_t *wholist)
{
sigar_who_net_sessions(sigar, wholist);
sigar_who_registry(sigar, wholist);
sigar_who_wts(sigar, wholist);
return SIGAR_OK;
}
#include <lm.h> #include <lm.h>
static int sigar_who_net_sessions(sigar_t *sigar, static int sigar_who_net_sessions(sigar_t *sigar,
@ -2225,7 +2218,7 @@ static int sigar_who_registry(sigar_t *sigar,
sigar_who_list_t *wholist) sigar_who_list_t *wholist)
{ {
HKEY users; HKEY users;
DWORD index=-1, status; DWORD index=0, status;
status = RegOpenKey(HKEY_USERS, NULL, &users); status = RegOpenKey(HKEY_USERS, NULL, &users);
if (status != ERROR_SUCCESS) { if (status != ERROR_SUCCESS) {
@ -2242,8 +2235,6 @@ static int sigar_who_registry(sigar_t *sigar,
PSID sid; PSID sid;
SID_NAME_USE type; SID_NAME_USE type;
index++;
status = RegEnumKeyEx(users, index, subkey, &subkey_len, status = RegEnumKeyEx(users, index, subkey, &subkey_len,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
@ -2251,6 +2242,12 @@ static int sigar_who_registry(sigar_t *sigar,
break; break;
} }
index++;
if ((subkey[0] == '.') || strstr(subkey, "_Classes")) {
continue;
}
if (!ConvertStringSidToSidA(subkey, &sid)) { if (!ConvertStringSidToSidA(subkey, &sid)) {
continue; continue;
} }
@ -2269,6 +2266,7 @@ static int sigar_who_registry(sigar_t *sigar,
SIGAR_SSTRCPY(who->user, username); SIGAR_SSTRCPY(who->user, username);
SIGAR_SSTRCPY(who->host, domain); SIGAR_SSTRCPY(who->host, domain);
SIGAR_SSTRCPY(who->device, "console"); SIGAR_SSTRCPY(who->device, "console");
get_logon_info(users, subkey, who); get_logon_info(users, subkey, who);
} }
@ -2283,7 +2281,7 @@ static int sigar_who_registry(sigar_t *sigar,
static int sigar_who_wts(sigar_t *sigar, static int sigar_who_wts(sigar_t *sigar,
sigar_who_list_t *wholist) sigar_who_list_t *wholist)
{ {
DWORD count, i; DWORD count=0, i;
WTS_SESSION_INFO *sessions = NULL; WTS_SESSION_INFO *sessions = NULL;
if (!sigar->wts_enum_sessions && sigar->wts_handle) { if (!sigar->wts_enum_sessions && sigar->wts_handle) {
@ -2426,3 +2424,15 @@ static int sigar_who_wts(sigar_t *sigar,
return SIGAR_OK; return SIGAR_OK;
} }
int sigar_who_list_get_win32(sigar_t *sigar,
sigar_who_list_t *wholist)
{
sigar_who_net_sessions(sigar, wholist);
sigar_who_registry(sigar, wholist);
sigar_who_wts(sigar, wholist);
return SIGAR_OK;
}