aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGravatar Gunnar Beutner <gunnar@beutner.name> 2014-04-21 21:51:19 +0200
committerGravatar Holger Weiss <holger@zedat.fu-berlin.de> 2014-04-27 19:59:06 +0200
commit5e03bd8e8cf4ea41aef6cf5d7f115afa7565c861 (patch)
treee3b9e30280782fa171b3e13f1d41cd580e7c1b87 /plugins
parente0af39d7e9fcd084cf7d2d8a57d07ab1f8038150 (diff)
downloadmonitoring-plugins-5e03bd8e8cf4ea41aef6cf5d7f115afa7565c861.tar.gz
Make check_users work on Windows.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Makefile.am2
-rw-r--r--plugins/check_users.c44
2 files changed, 42 insertions, 4 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 6b347fe9..0ddf9bd1 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -107,7 +107,7 @@ check_tcp_LDADD = $(SSLOBJS)
check_time_LDADD = $(NETLIBS)
check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS)
check_ups_LDADD = $(NETLIBS)
-check_users_LDADD = $(BASEOBJS)
+check_users_LDADD = $(BASEOBJS) $(WTSAPI32LIBS)
check_by_ssh_LDADD = $(NETLIBS)
check_ide_smart_LDADD = $(BASEOBJS)
negate_LDADD = $(BASEOBJS)
diff --git a/plugins/check_users.c b/plugins/check_users.c
index 458a7ca6..a009f20b 100644
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
@@ -37,7 +37,12 @@ const char *email = "devel@monitoring-plugins.org";
#include "common.h"
#include "utils.h"
-#if HAVE_UTMPX_H
+#if HAVE_WTSAPI32_H
+# include <windows.h>
+# include <wtsapi32.h>
+# undef ERROR
+# define ERROR -1
+#elif HAVE_UTMPX_H
# include <utmpx.h>
#else
# include "popen.h"
@@ -58,7 +63,11 @@ main (int argc, char **argv)
int users = -1;
int result = STATE_UNKNOWN;
char *perf;
-#if HAVE_UTMPX_H
+#if HAVE_WTSAPI32_H
+ WTS_SESSION_INFO *wtsinfo;
+ DWORD wtscount;
+ DWORD index;
+#elif HAVE_UTMPX_H
struct utmpx *putmpx;
#else
char input_buffer[MAX_INPUT_BUFFER];
@@ -78,7 +87,36 @@ main (int argc, char **argv)
users = 0;
-#if HAVE_UTMPX_H
+#if HAVE_WTSAPI32_H
+ if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE,
+ 0, 1, &wtsinfo, &wtscount)) {
+ printf(_("Could not enumerate RD sessions: %d\n"), GetLastError());
+ return STATE_UNKNOWN;
+ }
+
+ for (index = 0; index < wtscount; index++) {
+ LPTSTR username;
+ DWORD size;
+ int len;
+
+ if (!WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE,
+ wtsinfo[index].SessionId, WTSUserName, &username, &size))
+ continue;
+
+ len = lstrlen(username);
+
+ WTSFreeMemory(username);
+
+ if (len == 0)
+ continue;
+
+ if (wtsinfo[index].State == WTSActive ||
+ wtsinfo[index].State == WTSDisconnected)
+ users++;
+ }
+
+ WTSFreeMemory(wtsinfo);
+#elif HAVE_UTMPX_H
/* get currently logged users from utmpx */
setutxent ();