Changeset 19513 in vbox
- Timestamp:
- May 8, 2009 8:25:46 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r19374 r19513 31 31 #include <Ntsecapi.h> 32 32 #else 33 # include <errno.h> 33 34 # include <unistd.h> 34 # include < errno.h>35 # include <utmp.h> 35 36 #endif 36 37 … … 106 107 HMODULE hKernel32 = LoadLibrary(_T("kernel32")); 107 108 if (NULL != hKernel32) 108 { 109 { 109 110 g_pfnWTSGetActiveConsoleSessionId = (fnWTSGetActiveConsoleSessionId)GetProcAddress(hKernel32, "WTSGetActiveConsoleSessionId"); 110 111 FreeLibrary(hKernel32); … … 114 115 rc = VbglR3GuestPropConnect(&g_VMInfoGuestPropSvcClientID); 115 116 if (!RT_SUCCESS(rc)) 116 { 117 { 117 118 VBoxServiceError("Failed to connect to the guest property service! Error: %Rrc\n", rc); 118 119 } … … 181 182 182 183 char* pszTemp = NULL; 183 184 184 185 /* This function can report stale or orphaned interactive logon sessions of already logged 185 186 off users (especially in Windows 2000). */ 186 187 r = ::LsaEnumerateLogonSessions(&ulCount, &pSessions); 187 188 VBoxServiceVerbose(3, "Users: Found %ld users.\n", ulCount); 188 189 189 190 if (r != STATUS_SUCCESS) 190 191 { … … 192 193 return 1; 193 194 } 194 195 195 196 PLUID pLuid = NULL; 196 197 DWORD dwNumOfProcLUIDs = VboxServiceVMInfoWinGetLUIDsFromProcesses(&pLuid); 197 198 198 199 VBOXSERVICEVMINFOUSER userInfo; 199 200 ZeroMemory (&userInfo, sizeof(VBOXSERVICEVMINFOUSER)); 200 201 201 202 for (int i = 0; i<(int)ulCount; i++) 202 203 { … … 205 206 if (uiUserCount > 0) 206 207 strcat (szUserList, ","); 207 208 208 209 uiUserCount++; 209 210 … … 213 214 } 214 215 } 215 216 216 217 if (NULL != pLuid) 217 218 ::LocalFree (pLuid); … … 219 220 ::LsaFreeReturnBuffer(pSessions); 220 221 #else 221 /** @todo Nothing here yet - Implement other platforms here. */ 222 utmp* ut_user; 223 rc = utmpname(UTMP_FILE); 224 if (rc != 0) 225 { 226 VBoxServiceError("Could not set UTMP file! Error: %ld", errno); 227 } 228 setutent(); 229 while ((ut_user=getutent())) 230 { 231 /* Make sure we don't add user names which are not 232 * part of type USER_PROCESS and don't add same users twice. */ 233 if ( (ut_user->ut_type == USER_PROCESS) 234 && (strstr(szUserList, ut_user->ut_user) == NULL)) 235 { 236 if (uiUserCount > 0) 237 strcat(szUserList, ","); 238 strcat(szUserList, ut_user->ut_user); 239 uiUserCount++; 240 } 241 } 242 endutent(); 222 243 #endif /* !RT_OS_WINDOWS */ 223 244 … … 246 267 return -1; 247 268 } 248 269 249 270 INTERFACE_INFO InterfaceList[20] = {0}; 250 271 unsigned long nBytesReturned = 0; 251 if (WSAIoctl(sd, 252 SIO_GET_INTERFACE_LIST, 253 0, 254 0, 272 if (WSAIoctl(sd, 273 SIO_GET_INTERFACE_LIST, 274 0, 275 0, 255 276 &InterfaceList, 256 sizeof(InterfaceList), 257 &nBytesReturned, 258 0, 277 sizeof(InterfaceList), 278 &nBytesReturned, 279 0, 259 280 0) == SOCKET_ERROR) 260 281 { … … 262 283 return -1; 263 284 } 264 285 265 286 char szPropPath [_MAX_PATH] = {0}; 266 287 char szTemp [_MAX_PATH] = {0}; 267 288 int nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO); 268 289 int iCurIface = 0; 269 290 270 291 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/Count"); 271 292 VboxServiceWritePropInt(g_VMInfoGuestPropSvcClientID, szPropPath, (nNumInterfaces > 1 ? nNumInterfaces-1 : 0)); 272 293 273 294 /** @todo Use GetAdaptersInfo() and GetAdapterAddresses (IPv4 + IPv6) for more information. */ 274 295 … … 277 298 if (InterfaceList[i].iiFlags & IFF_LOOPBACK) /* Skip loopback device. */ 278 299 continue; 279 300 280 301 sockaddr_in *pAddress; 281 302 pAddress = (sockaddr_in *) & (InterfaceList[i].iiAddress); 282 303 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/V4/IP", iCurIface); 283 304 VboxServiceWriteProp(g_VMInfoGuestPropSvcClientID, szPropPath, inet_ntoa(pAddress->sin_addr)); 284 305 285 306 pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress); 286 307 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/V4/Broadcast", iCurIface); 287 308 VboxServiceWriteProp(g_VMInfoGuestPropSvcClientID, szPropPath, inet_ntoa(pAddress->sin_addr)); 288 309 289 310 pAddress = (sockaddr_in *) & (InterfaceList[i].iiNetmask); 290 311 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/V4/Netmask", iCurIface); 291 312 VboxServiceWriteProp(g_VMInfoGuestPropSvcClientID, szPropPath, inet_ntoa(pAddress->sin_addr)); 292 313 293 314 u_long nFlags = InterfaceList[i].iiFlags; 294 315 if (nFlags & IFF_UP) … … 296 317 else 297 318 RTStrPrintf(szTemp, sizeof(szTemp), "Down"); 298 319 299 320 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestInfo/Net/%d/Status", iCurIface); 300 321 VboxServiceWriteProp(g_VMInfoGuestPropSvcClientID, szPropPath, szTemp); 301 322 302 323 iCurIface++; 303 324 } 304 325 305 326 closesocket(sd); 306 327 #endif /* !RT_OS_WINDOWS */
Note:
See TracChangeset
for help on using the changeset viewer.