summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorGunnar Beutner <gunnar@beutner.name>2014-04-21 19:51:19 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2014-04-27 17:59:06 (GMT)
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 6b347fe..0ddf9bd 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -107,7 +107,7 @@ check_tcp_LDADD = $(SSLOBJS)
107check_time_LDADD = $(NETLIBS) 107check_time_LDADD = $(NETLIBS)
108check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS) 108check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS)
109check_ups_LDADD = $(NETLIBS) 109check_ups_LDADD = $(NETLIBS)
110check_users_LDADD = $(BASEOBJS) 110check_users_LDADD = $(BASEOBJS) $(WTSAPI32LIBS)
111check_by_ssh_LDADD = $(NETLIBS) 111check_by_ssh_LDADD = $(NETLIBS)
112check_ide_smart_LDADD = $(BASEOBJS) 112check_ide_smart_LDADD = $(BASEOBJS)
113negate_LDADD = $(BASEOBJS) 113negate_LDADD = $(BASEOBJS)
diff --git a/plugins/check_users.c b/plugins/check_users.c
index 458a7ca..a009f20 100644
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
@@ -37,7 +37,12 @@ const char *email = "devel@monitoring-plugins.org";
37#include "common.h" 37#include "common.h"
38#include "utils.h" 38#include "utils.h"
39 39
40#if HAVE_UTMPX_H 40#if HAVE_WTSAPI32_H
41# include <windows.h>
42# include <wtsapi32.h>
43# undef ERROR
44# define ERROR -1
45#elif HAVE_UTMPX_H
41# include <utmpx.h> 46# include <utmpx.h>
42#else 47#else
43# include "popen.h" 48# include "popen.h"
@@ -58,7 +63,11 @@ main (int argc, char **argv)
58 int users = -1; 63 int users = -1;
59 int result = STATE_UNKNOWN; 64 int result = STATE_UNKNOWN;
60 char *perf; 65 char *perf;
61#if HAVE_UTMPX_H 66#if HAVE_WTSAPI32_H
67 WTS_SESSION_INFO *wtsinfo;
68 DWORD wtscount;
69 DWORD index;
70#elif HAVE_UTMPX_H
62 struct utmpx *putmpx; 71 struct utmpx *putmpx;
63#else 72#else
64 char input_buffer[MAX_INPUT_BUFFER]; 73 char input_buffer[MAX_INPUT_BUFFER];
@@ -78,7 +87,36 @@ main (int argc, char **argv)
78 87
79 users = 0; 88 users = 0;
80 89
81#if HAVE_UTMPX_H 90#if HAVE_WTSAPI32_H
91 if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE,
92 0, 1, &wtsinfo, &wtscount)) {
93 printf(_("Could not enumerate RD sessions: %d\n"), GetLastError());
94 return STATE_UNKNOWN;
95 }
96
97 for (index = 0; index < wtscount; index++) {
98 LPTSTR username;
99 DWORD size;
100 int len;
101
102 if (!WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE,
103 wtsinfo[index].SessionId, WTSUserName, &username, &size))
104 continue;
105
106 len = lstrlen(username);
107
108 WTSFreeMemory(username);
109
110 if (len == 0)
111 continue;
112
113 if (wtsinfo[index].State == WTSActive ||
114 wtsinfo[index].State == WTSDisconnected)
115 users++;
116 }
117
118 WTSFreeMemory(wtsinfo);
119#elif HAVE_UTMPX_H
82 /* get currently logged users from utmpx */ 120 /* get currently logged users from utmpx */
83 setutxent (); 121 setutxent ();
84 122