Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
4.0 KiB

  1. /*
  2. File: client.c
  3. Support for netsh commands that manipulate ras clients.
  4. */
  5. #include "precomp.h"
  6. #pragma hdrstop
  7. //
  8. // Callback function for enumerating clients
  9. //
  10. typedef
  11. DWORD
  12. (*CLIENT_ENUM_CB_FUNC)(
  13. IN DWORD dwLevel,
  14. IN LPBYTE pbClient,
  15. IN HANDLE hData);
  16. //
  17. // Client enumerate callback that displays the connection
  18. //
  19. DWORD
  20. ClientShow(
  21. IN DWORD dwLevel,
  22. IN LPBYTE pbClient,
  23. IN HANDLE hData)
  24. {
  25. RAS_CONNECTION_0 * pClient = (RAS_CONNECTION_0*)pbClient;
  26. DWORD dwDays, dwHours, dwMins, dwSecs, dwTime, dwTemp;
  27. dwTime = pClient->dwConnectDuration;
  28. dwDays = dwTime / (24*60*60);
  29. dwTemp = dwTime - (dwDays * 24*60*60); // temp is # of secs in cur day
  30. dwHours = dwTemp / (60*60);
  31. dwTemp = dwTemp - (dwHours * 60*60); // temp is # of secs in cur min
  32. dwMins = dwTemp / 60;
  33. dwSecs = dwTemp % 60;
  34. DisplayMessage(
  35. g_hModule,
  36. MSG_CLIENT_SHOW,
  37. pClient->wszUserName,
  38. pClient->wszLogonDomain,
  39. pClient->wszRemoteComputer,
  40. dwDays,
  41. dwHours,
  42. dwMins,
  43. dwSecs);
  44. return NO_ERROR;
  45. }
  46. //
  47. // Enumerates the client connections
  48. //
  49. DWORD
  50. ClientEnum(
  51. IN CLIENT_ENUM_CB_FUNC pEnum,
  52. IN DWORD dwLevel,
  53. IN HANDLE hData)
  54. {
  55. DWORD dwErr = NO_ERROR;
  56. HANDLE hAdmin = NULL;
  57. LPBYTE pbBuffer = NULL;
  58. DWORD dwRead, dwTot, dwResume = 0, i;
  59. RAS_CONNECTION_0 * pCur;
  60. BOOL bContinue = FALSE;
  61. do
  62. {
  63. // Connection to mpr api server
  64. //
  65. dwErr = MprAdminServerConnect(
  66. g_pServerInfo->pszServer,
  67. &hAdmin);
  68. BREAK_ON_DWERR(dwErr);
  69. do
  70. {
  71. // Enumerate
  72. //
  73. dwErr = MprAdminConnectionEnum(
  74. hAdmin,
  75. dwLevel,
  76. &pbBuffer,
  77. 4096,
  78. &dwRead,
  79. &dwTot,
  80. &dwResume);
  81. if (dwErr == ERROR_MORE_DATA)
  82. {
  83. dwErr = NO_ERROR;
  84. bContinue = TRUE;
  85. }
  86. else
  87. {
  88. bContinue = FALSE;
  89. }
  90. if (dwErr != NO_ERROR)
  91. {
  92. break;
  93. }
  94. // Call the callback for each connection as long
  95. // as we're instructed to keep going
  96. //
  97. pCur = (RAS_CONNECTION_0*)pbBuffer;
  98. for (i = 0; (i < dwRead) && (dwErr == NO_ERROR); i++)
  99. {
  100. if (pCur->dwInterfaceType == ROUTER_IF_TYPE_CLIENT)
  101. {
  102. dwErr = (*pEnum)(
  103. dwLevel,
  104. (LPBYTE)pCur,
  105. hData);
  106. }
  107. pCur++;
  108. }
  109. if (dwErr != NO_ERROR)
  110. {
  111. break;
  112. }
  113. // Free up the interface list buffer
  114. //
  115. if (pbBuffer)
  116. {
  117. MprAdminBufferFree(pbBuffer);
  118. pbBuffer = NULL;
  119. }
  120. // Keep this loop going until there are
  121. // no more connections
  122. //
  123. } while (bContinue);
  124. } while (FALSE);
  125. // Cleanup
  126. {
  127. if (hAdmin)
  128. {
  129. MprAdminServerDisconnect(hAdmin);
  130. }
  131. }
  132. return dwErr;
  133. }
  134. //
  135. // Shows whether HandleRasflagSet has been called on the
  136. // given domain.
  137. //
  138. DWORD
  139. HandleClientShow(
  140. IN LPCWSTR pwszMachine,
  141. IN OUT LPWSTR *ppwcArguments,
  142. IN DWORD dwCurrentIndex,
  143. IN DWORD dwArgCount,
  144. IN DWORD dwFlags,
  145. IN LPCVOID pvData,
  146. OUT BOOL *pbDone
  147. )
  148. {
  149. DWORD dwErr = NO_ERROR;
  150. // Make sure no arguments were passed in
  151. //
  152. if (dwArgCount - dwCurrentIndex != 0)
  153. {
  154. return ERROR_INVALID_SYNTAX;
  155. }
  156. dwErr = ClientEnum(ClientShow, 0, NULL);
  157. return dwErr;
  158. }