summaryrefslogtreecommitdiffstats
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
parente0af39d7e9fcd084cf7d2d8a57d07ab1f8038150 (diff)
downloadmonitoring-plugins-5e03bd8e8cf4ea41aef6cf5d7f115afa7565c861.tar.gz
Make check_users work on Windows.
-rw-r--r--configure.ac10
-rw-r--r--plugins/Makefile.am2
-rw-r--r--plugins/check_users.c44
3 files changed, 51 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index f405cce..244df42 100644
--- a/configure.ac
+++ b/configure.ac
@@ -364,8 +364,16 @@ dnl Check for headers used by check_users
364AC_CHECK_HEADERS(utmpx.h) 364AC_CHECK_HEADERS(utmpx.h)
365AM_CONDITIONAL([HAVE_UTMPX], [test "$ac_cv_header_utmpx_h" = "yes"]) 365AM_CONDITIONAL([HAVE_UTMPX], [test "$ac_cv_header_utmpx_h" = "yes"])
366 366
367AC_CHECK_HEADERS(wtsapi32.h, [], [], [#include <windows.h>])
368AM_CONDITIONAL([HAVE_WTS32API], [test "$ac_cv_header_wtsapi32_h" = "yes"])
369
370if test "$ac_cv_header_wtsapi32_h" = "yes"; then
371 WTSAPI32LIBS="-lwtsapi32"
372 AC_SUBST(WTSAPI32LIBS)
373fi
374
367dnl Fallback to who(1) if the system doesn't provide an utmpx(5) interface 375dnl Fallback to who(1) if the system doesn't provide an utmpx(5) interface
368if test "$ac_cv_header_utmpx_h" = "no" 376if test "$ac_cv_header_utmpx_h" = "no" -a "$ac_cv_header_wtsapi32_h" = "no"
369then 377then
370 AC_PATH_PROG(PATH_TO_WHO,who) 378 AC_PATH_PROG(PATH_TO_WHO,who)
371 379
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