39 |
|
#ifdef OPENBSD |
40 |
|
#include <sys/param.h> |
41 |
|
#endif |
42 |
+ |
#ifndef WIN32 |
43 |
|
#include <utmp.h> |
44 |
+ |
#endif |
45 |
|
#ifdef CYGWIN |
46 |
|
#include <sys/unistd.h> |
47 |
|
#endif |
48 |
|
#ifdef HPUX |
49 |
|
#include <utmp.h> |
50 |
|
#endif |
51 |
+ |
#ifdef WIN32 |
52 |
+ |
#include <windows.h> |
53 |
+ |
#include <lm.h> |
54 |
+ |
#endif |
55 |
|
|
56 |
|
sg_user_stats *sg_get_user_stats(){ |
57 |
|
int num_users = 0, pos = 0, new_pos; |
79 |
|
num_users++; |
80 |
|
} |
81 |
|
fclose(f); |
82 |
+ |
#elif defined (WIN32) |
83 |
+ |
LPWKSTA_USER_INFO_0 buf = NULL; |
84 |
+ |
LPWKSTA_USER_INFO_0 tmp_buf; |
85 |
+ |
unsigned long entries_read = 0; |
86 |
+ |
unsigned long entries_tot = 0; |
87 |
+ |
unsigned long resumehandle = 0; |
88 |
+ |
NET_API_STATUS nStatus; |
89 |
+ |
int i; |
90 |
+ |
char name[256]; |
91 |
+ |
|
92 |
+ |
do { |
93 |
+ |
nStatus = NetWkstaUserEnum(NULL, 0, (LPBYTE*)&buf, |
94 |
+ |
MAX_PREFERRED_LENGTH, &entries_read, |
95 |
+ |
&entries_tot, &resumehandle); |
96 |
+ |
if((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) { |
97 |
+ |
if((tmp_buf = buf) == NULL) { |
98 |
+ |
continue; |
99 |
+ |
} |
100 |
+ |
for (i=0; i<entries_read; i++) { |
101 |
+ |
//assert(tmp_buf != NULL); |
102 |
+ |
if (tmp_buf == NULL) { |
103 |
+ |
sg_set_error(SG_ERROR_PERMISSION, "User list"); |
104 |
+ |
break; |
105 |
+ |
} |
106 |
+ |
/* It's in unicode. We are not. Convert */ |
107 |
+ |
WideCharToMultiByte(CP_ACP, 0, tmp_buf->wkui0_username, -1, name, sizeof(name), NULL, NULL); |
108 |
+ |
|
109 |
+ |
new_pos = pos + strlen(name) + 1; |
110 |
+ |
if(VECTOR_RESIZE(name_list, new_pos) < 0) { |
111 |
+ |
NetApiBufferFree(buf); |
112 |
+ |
return NULL; |
113 |
+ |
} |
114 |
+ |
strcpy(name_list + pos, name); |
115 |
+ |
name_list[new_pos - 1] = ' '; |
116 |
+ |
pos = new_pos; |
117 |
+ |
|
118 |
+ |
tmp_buf++; |
119 |
+ |
num_users++; |
120 |
+ |
} |
121 |
+ |
} else { |
122 |
+ |
sg_set_error(SG_ERROR_PERMISSION, "User enum"); |
123 |
+ |
return NULL; |
124 |
+ |
} |
125 |
+ |
if (buf != NULL) { |
126 |
+ |
NetApiBufferFree(buf); |
127 |
+ |
buf=NULL; |
128 |
+ |
} |
129 |
+ |
} while (nStatus == ERROR_MORE_DATA); |
130 |
+ |
if (buf != NULL) { |
131 |
+ |
NetApiBufferFree(buf); |
132 |
+ |
} |
133 |
|
#else |
134 |
|
/* This works on everything else. */ |
135 |
|
struct utmp *entry; |