ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/CCSFinger/CCSFinger.cpp
(Generate patch)

Comparing CCSFinger/CCSFinger.cpp (file contents):
Revision 613 by douglas, 2005-12-12T18:30:01-08:00 vs.
Revision 615 by douglas, 2005-12-12T19:26:43-08:00

# Line 8 | Line 8
8   #include <tchar.h>
9   #include <signal.h>
10   #include <wtsapi32.h>
11 + #include <lm.h>
12  
13   #include <iostream>
14 + #include <iomanip>
15   #include <string>
16   #include <sstream>
17   #include <vector>
18   #include <set>
19  
20 + std::ostream &operator<<(std::ostream &out, WTS_CONNECTSTATE_CLASS status)
21 + {
22 +        switch (status)
23 +        {
24 +        case WTSActive:
25 +                return out << "Active";
26 +
27 +        case WTSConnected:
28 +                return out << "Connected";
29 +
30 +        case WTSConnectQuery:
31 +                return out << "Connecting";
32 +
33 +        case WTSShadow:
34 +                return out << "Shadowing";
35 +
36 +        case WTSDisconnected:
37 +                return out << "Disconnected";
38 +
39 +        case WTSIdle:
40 +                return out << "Idle";
41 +
42 +        case WTSListen:
43 +                return out << "Listening";
44 +
45 +        case WTSReset:
46 +                return out << "Reseting";
47 +
48 +        case WTSDown:
49 +                return out << "Down";
50 +
51 +        case WTSInit:
52 +                return out << "Initializing";
53 +
54 +        default:
55 +                return out << "Unknown";
56 +        }
57 + }
58 +
59   inline std::string Utf8(const std::wstring &wstring)
60   {
61          std::string string(::WideCharToMultiByte(CP_UTF8, 0, wstring.data(), int(wstring.size()), NULL, 0, NULL, NULL), '\0');
# Line 30 | Line 71 | private:
71          struct Login
72          {
73                  std::string login, name, session;
74 <                Login(const std::string &login, const std::string &session) : login(login), session(session)
74 >                DWORD id;
75 >                WTS_CONNECTSTATE_CLASS status;
76 >                Login(const std::wstring &login, DWORD id, const std::wstring &session, WTS_CONNECTSTATE_CLASS status) : login(Utf8(login)), id(id), session(Utf8(session)), status(status)
77                  {
78 +                        USER_INFO_11 *info;
79 +
80 +                        ::NetUserGetInfo(NULL, login.c_str(), 11, reinterpret_cast<LPBYTE *>(&info));
81 +
82 +                        name = Utf8(std::wstring(info->usri11_full_name).substr(0, 20));
83 +
84 +                        ::NetApiBufferFree(info);
85                  }
86 +
87                  bool operator<(const Login &login) const
88                  {
89                          if (this->login == login.login)
90 <                                return session < login.session;
90 >                                return id < login.id;
91                          else
92                                  return this->login < login.login;
93                  }
# Line 65 | Line 116 | public:
116  
117                                  ::WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, session->SessionId, WTSWinStationName, &session_, &size);
118  
119 <                                Login login(Utf8(name), Utf8(session_));
119 >                                Login login(name, session->SessionId, session_, session->State);
120  
121                                  ::WTSFreeMemory(session_);
122  
# Line 79 | Line 130 | public:
130  
131                  if (!full)
132                  {
133 <                        stream << "Login\t\tName" << std::string(17, ' ') << "Session\r\n";
133 >                        stream << "Login\t\tName" << std::string(17, ' ') << "Id     Session       Status\r\n";
134  
135                          for (std::set<Login>::const_iterator login(logins.begin()); login != logins.end(); ++login)
136 <                                stream << login->login << std::string(16 - login->login.size(), ' ') << login->name << std::string(21 - login->name.size(), ' ') << login->session << "\r\n";
136 >                                stream << login->login << std::string(16 - login->login.size(), ' ') << login->name << std::string(21 - login->name.size(), ' ') << std::setw(5) << std::left << login->id << "  " << login->session << std::string(14 - login->session.size(), ' ') << login->status << "\r\n";
137                  }
138          }
139  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines