forked from jackburton79/ocs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoggedUsers.cpp
62 lines (48 loc) · 956 Bytes
/
LoggedUsers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* LoggedUsers.cpp
*
* Created on: 15/lug/2013
* Author: stefano
*/
#include "LoggedUsers.h"
#include "Support.h"
#include <ctime>
#include <istream>
#include <utmpx.h>
LoggedUsers::LoggedUsers()
{
setutxent();
struct utmpx* record = NULL;
while ((record = getutxent()) != NULL) {
if (record->ut_type == USER_PROCESS) {
user_entry entry;
entry.login = record->ut_user;
time_t loginTime = record->ut_tv.tv_sec;
entry.logintime = loginTime;
struct tm* timeinfo = localtime(&loginTime);
char timeString[64];
strftime(timeString, sizeof(timeString), "%a %b %d %R", timeinfo);
entry.logintimestring = timeString;
fUsers.push_back(entry);
}
}
endutxent();
}
LoggedUsers::~LoggedUsers()
{
}
int
LoggedUsers::Count() const
{
return fUsers.size();
}
user_entry
LoggedUsers::UserEntryAt(int i) const
{
return fUsers[i];
}
std::string
LoggedUsers::LoginNameAt(int i) const
{
return fUsers[i].login;
}