ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/user_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/user_stats.c (file contents):
Revision 1.27 by tdb, Mon Nov 1 18:30:17 2004 UTC vs.
Revision 1.29 by tdb, Sat Feb 20 17:55:04 2010 UTC

# Line 39 | Line 39
39   #ifdef OPENBSD
40   #include <sys/param.h>
41   #endif
42 + #ifndef WIN32
43 + #ifdef HAVE_UTMPX
44 + #include <utmpx.h>
45 + #else
46   #include <utmp.h>
47 + #endif
48 + #endif
49   #ifdef CYGWIN
50   #include <sys/unistd.h>
51   #endif
52   #ifdef HPUX
53   #include <utmp.h>
54   #endif
55 + #ifdef WIN32
56 + #include <windows.h>
57 + #include <lm.h>
58 + #endif
59  
60   sg_user_stats *sg_get_user_stats(){
61          int num_users = 0, pos = 0, new_pos;
62          VECTOR_DECLARE_STATIC(name_list, char, 128, NULL, NULL);
63          static sg_user_stats user_stats;
64 < #ifdef ALLBSD
64 > #if defined(ALLBSD) && !defined(HAVE_UTMPX)
65          struct utmp entry;
66          FILE *f;
67  
# Line 73 | Line 83 | sg_user_stats *sg_get_user_stats(){
83                  num_users++;
84          }
85          fclose(f);
86 + #elif defined (WIN32)
87 +        LPWKSTA_USER_INFO_0 buf = NULL;
88 +        LPWKSTA_USER_INFO_0 tmp_buf;
89 +        unsigned long entries_read = 0;
90 +        unsigned long entries_tot = 0;
91 +        unsigned long resumehandle = 0;
92 +        NET_API_STATUS nStatus;
93 +        int i;
94 +        char name[256];
95 +
96 +        do {
97 +                nStatus = NetWkstaUserEnum(NULL, 0, (LPBYTE*)&buf,
98 +                                MAX_PREFERRED_LENGTH, &entries_read,
99 +                                &entries_tot, &resumehandle);
100 +                if((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) {
101 +                        if((tmp_buf = buf) == NULL) {
102 +                                continue;
103 +                        }
104 +                        for (i=0; i<entries_read; i++) {
105 +                                //assert(tmp_buf != NULL);
106 +                                if (tmp_buf == NULL) {
107 +                                        sg_set_error(SG_ERROR_PERMISSION, "User list");
108 +                                        break;
109 +                                }
110 +                                /* It's in unicode. We are not. Convert */
111 +                                WideCharToMultiByte(CP_ACP, 0, tmp_buf->wkui0_username, -1, name, sizeof(name), NULL, NULL);
112 +
113 +                                new_pos = pos + strlen(name) + 1;
114 +                                if(VECTOR_RESIZE(name_list, new_pos) < 0) {
115 +                                        NetApiBufferFree(buf);
116 +                                        return NULL;
117 +                                }
118 +                                strcpy(name_list + pos, name);
119 +                                name_list[new_pos - 1] = ' ';
120 +                                pos = new_pos;
121 +
122 +                                tmp_buf++;
123 +                                num_users++;
124 +                        }
125 +                } else {
126 +                        sg_set_error(SG_ERROR_PERMISSION, "User enum");
127 +                        return NULL;
128 +                }
129 +                if (buf != NULL) {
130 +                        NetApiBufferFree(buf);
131 +                        buf=NULL;
132 +                }
133 +        } while (nStatus == ERROR_MORE_DATA);
134 +        if (buf != NULL) {
135 +                NetApiBufferFree(buf);
136 +        }
137   #else
138          /* This works on everything else. */
139 + #ifdef HAVE_UTMPX
140 +        struct utmpx *entry;
141 +        setutxent();
142 +        while((entry=getutxent()) != NULL) {
143 + #else
144          struct utmp *entry;
79
145          setutent();
146          while((entry=getutent()) != NULL) {
147 + #endif
148                  if (entry->ut_type != USER_PROCESS) continue;
149  
150                  new_pos = pos + strlen(entry->ut_user) + 1;
# Line 91 | Line 157 | sg_user_stats *sg_get_user_stats(){
157                  pos = new_pos;
158                  num_users++;
159          }
160 + #ifdef HAVE_UTMPX
161 +        endutxent();
162 + #else
163          endutent();
164 + #endif
165   #endif
166  
167          /* Remove the extra space at the end, and append a \0. */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines