MCPcopy Create free account
hub / github.com/Icinga/icinga2 / check_users

Function check_users

plugins/check_users.cpp:154–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154static int check_users(printInfoStruct& printInfo)
155{
156 DOUBLE users = 0;
157 WTS_SESSION_INFOW *pSessionInfo = NULL;
158 DWORD count;
159 DWORD index;
160
161 if (l_Debug)
162 std::wcout << L"Trying to enumerate terminal sessions" << '\n';
163
164 if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &count)) {
165 std::wcout << L"Failed to enumerate terminal sessions" << '\n';
166 printErrorInfo();
167 if (pSessionInfo)
168 WTSFreeMemory(pSessionInfo);
169 return 3;
170 }
171
172 if (l_Debug)
173 std::wcout << L"Got all sessions (" << count << L"), traversing and counting active ones" << '\n';
174
175 for (index = 0; index < count; index++) {
176 LPWSTR name;
177 DWORD size;
178 int len;
179
180 if (l_Debug)
181 std::wcout << L"Querrying session number " << index << '\n';
182
183 if (!WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, pSessionInfo[index].SessionId,
184 WTSUserName, &name, &size))
185 continue;
186
187 if (l_Debug)
188 std::wcout << L"Found \"" << name << L"\". Checking whether it's a real session" << '\n';
189
190 len = lstrlenW(name);
191
192 WTSFreeMemory(name);
193
194 if (!len)
195 continue;
196
197 if (pSessionInfo[index].State == WTSActive || pSessionInfo[index].State == WTSDisconnected) {
198 users++;
199 if (l_Debug)
200 std::wcout << L"\"" << name << L"\" is a real session, counting it. Now " << users << '\n';
201 }
202 }
203
204 if (l_Debug)
205 std::wcout << "Finished coutning user sessions (" << users << "). Freeing memory and returning" << '\n';
206
207 WTSFreeMemory(pSessionInfo);
208 printInfo.users = users;
209 return -1;
210}
211

Callers 1

wmainFunction · 0.85

Calls 1

printErrorInfoFunction · 0.85

Tested by

no test coverage detected