5 |
|
// Windows Finger Daemon |
6 |
|
|
7 |
|
#include <windows.h> |
8 |
– |
#include <tchar.h> |
9 |
– |
#include <signal.h> |
10 |
– |
#include <wtsapi32.h> |
8 |
|
#include <lm.h> |
9 |
+ |
#include <signal.h> |
10 |
+ |
#include <tchar.h> |
11 |
|
#include <shlobj.h> |
12 |
+ |
#include <wtsapi32.h> |
13 |
|
|
14 |
|
#include <algorithm> |
15 |
< |
#include <iostream> |
15 |
> |
#include <cctype> |
16 |
> |
#include <cwctype> |
17 |
> |
#include <fstream> |
18 |
|
#include <iomanip> |
19 |
< |
#include <string> |
19 |
> |
#include <iostream> |
20 |
> |
#include <map> |
21 |
|
#include <sstream> |
22 |
+ |
#include <string> |
23 |
|
#include <vector> |
20 |
– |
#include <map> |
21 |
– |
#include <cwctype> |
24 |
|
|
25 |
|
std::ostream &operator<<(std::ostream &out, WTS_CONNECTSTATE_CLASS status) |
26 |
|
{ |
70 |
|
return string; |
71 |
|
} |
72 |
|
|
73 |
+ |
inline std::wstring Utf8(const std::string &string) |
74 |
+ |
{ |
75 |
+ |
std::wstring wstring(::MultiByteToWideChar(CP_UTF8, 0, string.data(), int(string.size()), NULL, 0), '\0'); |
76 |
+ |
|
77 |
+ |
::MultiByteToWideChar(CP_UTF8, 0, string.data(), int(string.size()), const_cast<LPWSTR>(wstring.data()), int(wstring.size())); |
78 |
+ |
|
79 |
+ |
return wstring; |
80 |
+ |
} |
81 |
+ |
|
82 |
|
class Finger |
83 |
|
{ |
84 |
|
class Login |
155 |
|
{ |
156 |
|
for (std::multimap<std::string, Login>::const_iterator login(logins.begin()); login != logins.end(); login = logins.upper_bound(login->first)) |
157 |
|
{ |
158 |
< |
stream << "Login: " << login->first << std::string(33 - login->first.size(), ' ') << "Name: " << login->second.GetName() << "\r\nDirectory: " << login->second.GetDirectory() << "\r\n"; |
158 |
> |
if (login != logins.begin()) |
159 |
> |
stream << "\r\n"; |
160 |
> |
|
161 |
> |
std::string directory(login->second.GetDirectory()); |
162 |
> |
|
163 |
> |
stream << "Login: " << login->first << std::string(33 - login->first.size(), ' ') << "Name: " << login->second.GetName() << "\r\nDirectory: " << directory << "\r\n"; |
164 |
> |
|
165 |
> |
for (std::multimap<std::string, Login>::const_iterator login_(logins.lower_bound(login->first)); login_ != logins.upper_bound(login->first); ++login_) |
166 |
> |
stream << login_->second.status << ' ' << login_->second.session << ' ' << login_->second.id << "\r\n"; |
167 |
> |
|
168 |
> |
std::string files[] = { "\\.project", "\\.plan" }; |
169 |
> |
|
170 |
> |
for (std::string *file(files); file != files + sizeof (files) / sizeof (*file); ++file) |
171 |
> |
{ |
172 |
> |
file->insert(0, directory); |
173 |
> |
|
174 |
> |
std::ifstream in(file->c_str()); |
175 |
> |
|
176 |
> |
if (!in.is_open()) |
177 |
> |
continue; |
178 |
> |
|
179 |
> |
switch (file - files) |
180 |
> |
{ |
181 |
> |
case 0: |
182 |
> |
stream << "Project:\r\n"; |
183 |
> |
|
184 |
> |
break; |
185 |
> |
case 1: |
186 |
> |
stream << "Plan:\r\n"; |
187 |
> |
} |
188 |
> |
|
189 |
> |
std::string buffer; |
190 |
> |
|
191 |
> |
while (std::getline(in, buffer)) |
192 |
> |
stream << buffer << std::endl; |
193 |
> |
} |
194 |
|
} |
195 |
|
} |
196 |
|
|
242 |
|
Full(); |
243 |
|
} |
244 |
|
|
245 |
< |
Finger(const std::string &name) |
245 |
> |
Finger(const std::string &name_) |
246 |
|
{ |
247 |
< |
//NetQueryDisplayInformation |
248 |
< |
//NetUserGetInfo |
247 |
> |
std::wstring name(Utf8(name_)); |
248 |
> |
|
249 |
> |
std::transform(name.begin(), name.end(), name.begin(), std::towlower); |
250 |
> |
|
251 |
> |
DWORD size; |
252 |
> |
PNET_DISPLAY_USER users; |
253 |
> |
|
254 |
> |
::NetQueryDisplayInformation(NULL, 1, 0, 100, MAX_PREFERRED_LENGTH, &size, reinterpret_cast<PVOID *>(&users)); |
255 |
> |
|
256 |
> |
for (PNET_DISPLAY_USER user = users; user != users + size; ++user) |
257 |
> |
{ |
258 |
> |
std::wstring name_(user->usri1_name); |
259 |
> |
|
260 |
> |
std::transform(name_.begin(), name_.end(), name_.begin(), std::towlower); |
261 |
> |
|
262 |
> |
if (name_.find(name) != std::wstring::npos) |
263 |
> |
;//logins.insert(std::make_pair(Utf8(name_), |
264 |
> |
else |
265 |
> |
{ |
266 |
> |
std::wstring full(user->usri1_full_name); |
267 |
> |
|
268 |
> |
std::transform(full.begin(), full.end(), full.begin(), std::towlower); |
269 |
> |
|
270 |
> |
if (full.find(name) != std::wstring::npos) |
271 |
> |
;//logins.insert(std::make_pair(Utf8(name_), |
272 |
> |
} |
273 |
> |
} |
274 |
> |
|
275 |
> |
::NetApiBufferFree(users); |
276 |
> |
|
277 |
> |
if (!logins.empty()) |
278 |
> |
Full(); |
279 |
> |
else |
280 |
> |
stream << "finger: " << name_ << ": no such user\r\n"; |
281 |
|
} |
282 |
|
|
283 |
|
inline operator std::string() |