diff options
Diffstat (limited to 'plugins/check_users.c')
| -rw-r--r-- | plugins/check_users.c | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/plugins/check_users.c b/plugins/check_users.c index ff2aedd2..a009f20b 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | /***************************************************************************** | 1 | /***************************************************************************** |
| 2 | * | 2 | * |
| 3 | * Nagios check_users plugin | 3 | * Monitoring check_users plugin |
| 4 | * | 4 | * |
| 5 | * License: GPL | 5 | * License: GPL |
| 6 | * Copyright (c) 2000-2012 Nagios Plugins Development Team | 6 | * Copyright (c) 2000-2012 Monitoring Plugins Development Team |
| 7 | * | 7 | * |
| 8 | * Description: | 8 | * Description: |
| 9 | * | 9 | * |
| @@ -32,12 +32,17 @@ | |||
| 32 | 32 | ||
| 33 | const char *progname = "check_users"; | 33 | const char *progname = "check_users"; |
| 34 | const char *copyright = "2000-2007"; | 34 | const char *copyright = "2000-2007"; |
| 35 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 35 | const char *email = "devel@monitoring-plugins.org"; |
| 36 | 36 | ||
| 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 | ||
