Leaked source code of windows server 2003
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.

227 lines
5.0 KiB

  1. // File : ATK_INET.CPP
  2. // Author : Suresh Krishnan
  3. // Date : 08/05/97
  4. // Wrapper for INetCFG.DLL exported functions
  5. // related function declarations
  6. //
  7. //
  8. #include <windows.h>
  9. #include <tchar.h>
  10. #include <winnt.h>
  11. #include <wininet.h>
  12. #include <stdio.h>
  13. #include "rw_common.h"
  14. typedef HRESULT (WINAPI *INETGETPROXY)(LPBOOL lpfEnable, LPSTR lpszServer, DWORD cbServer, LPSTR lpszOverride, DWORD cbOverride);
  15. typedef HRESULT (WINAPI *INETCONFIGSYSTEM) ( HWND hWndParent, DWORD dwfOptions, LPBOOL lpfNeedsRestart);
  16. typedef HRESULT (WINAPI *INETGETAUTODIAL) (LPBOOL lpEnable, LPSTR lpszEntryName, DWORD cbEntryName);
  17. typedef HRESULT (WINAPI *INETSETAUTODIAL) (BOOL fEnable, LPCSTR lpszEntryName);
  18. #define ERROR_IN_SET -1
  19. #define INET_DLL_FAILURE -1
  20. static HINSTANCE hINetCfg= NULL;
  21. static INETGETPROXY fpGetProxy=NULL;
  22. static INETCONFIGSYSTEM fpGetConfigSystem=NULL;
  23. static INETGETAUTODIAL fpGetAutoDial=NULL;
  24. static INETSETAUTODIAL fpSetAutoDial=NULL;
  25. static INETCONFIGSYSTEM fpInetConfig =NULL;
  26. typedef struct {
  27. char szActiveConnection[256];
  28. BOOL fStatus;
  29. enum ISPStateFlag {NotValidState,ValidState } iState ;
  30. } ISPState;
  31. static ISPState gIspState = { "",
  32. 0,
  33. ISPState::NotValidState};
  34. int INetCfgSetup()
  35. {
  36. if(hINetCfg) {
  37. return 1;
  38. }
  39. hINetCfg = LoadLibrary( _T("INETCFG.DLL") ); // Load INetCfg.DLL and store globally
  40. if( !hINetCfg )
  41. {
  42. // return if the DLL can not loaded
  43. //
  44. return 0;
  45. }
  46. fpGetProxy = (INETGETPROXY) GetProcAddress(hINetCfg,"InetGetProxy");
  47. fpGetAutoDial = ( INETGETAUTODIAL) GetProcAddress(hINetCfg, "InetGetAutodial");
  48. fpSetAutoDial = ( INETSETAUTODIAL) GetProcAddress(hINetCfg, "InetSetAutodial");
  49. fpInetConfig = (INETCONFIGSYSTEM) GetProcAddress(hINetCfg, "InetConfigSystem");
  50. return 1;
  51. }
  52. HRESULT ATK_InetGetAutoDial(LPBOOL lpEnable, LPSTR lpszEntryName, DWORD cbEntryName)
  53. {
  54. if(INetCfgSetup()) {
  55. return (*fpGetAutoDial)(lpEnable, lpszEntryName, cbEntryName);
  56. }else {
  57. return INET_DLL_FAILURE;
  58. }
  59. }
  60. HRESULT ATK_InetSetAutoDial(BOOL fEnable, LPCSTR lpszEntryName)
  61. {
  62. if(INetCfgSetup()) {
  63. return (*fpSetAutoDial)(fEnable, lpszEntryName);
  64. }else{
  65. return INET_DLL_FAILURE;
  66. }
  67. }
  68. HRESULT ATK_InetConfigSystem( HWND hwndParent,
  69. DWORD dwfOptions,
  70. LPBOOL lpfNeedsRestart)
  71. {
  72. if(INetCfgSetup()) {
  73. return (*fpInetConfig)( hwndParent,dwfOptions,
  74. lpfNeedsRestart);
  75. }else{
  76. return INET_DLL_FAILURE;
  77. }
  78. }
  79. HRESULT ATK_InetGetProxy( LPBOOL lpfEnable,
  80. LPSTR lpszServer,
  81. DWORD cbServer,
  82. LPSTR lpszOverride,
  83. DWORD cbOverride)
  84. {
  85. if(INetCfgSetup()) {
  86. return (*fpGetProxy)( lpfEnable,
  87. lpszServer,
  88. cbServer,
  89. lpszOverride,
  90. cbOverride);
  91. }else{
  92. return INET_DLL_FAILURE;
  93. }
  94. }
  95. void GetAutoDialConfiguration()
  96. {
  97. DWORD dwError;
  98. DWORD dwSz=256;
  99. HRESULT hr;
  100. ISPState *pS= &gIspState;
  101. hr = ATK_InetGetAutoDial(&pS->fStatus,
  102. pS->szActiveConnection,
  103. dwSz);
  104. if(hr) {
  105. dwError = GetLastError();
  106. RW_DEBUG << "\nGet AutoDial :***Error " <<hr << ":"<< dwError << flush;
  107. pS->iState = ISPState::NotValidState;
  108. }else {
  109. pS->iState = ISPState::ValidState;
  110. }
  111. }
  112. DWORD SetAutoDialStateThread(void *vp)
  113. {
  114. ISPState *pState;
  115. pState = (ISPState *) vp;
  116. ATK_InetSetAutoDial(pState->fStatus,
  117. pState->szActiveConnection);
  118. RW_DEBUG <<"\nSet Auto Dial Configuration" << pState->szActiveConnection << " =>" << pState->fStatus << flush;
  119. ExitThread(0);
  120. return 0;
  121. }
  122. //
  123. // This function calls the ICW function InetSetAutoDial()
  124. // this function waits for the above function to be over by 10 seconds
  125. // if it does not complete then it calls terminate thread and abondens the operation
  126. int ChangeInterNetAutoDial(ISPState *pStatus )
  127. {
  128. int iReturn;
  129. DWORD dwTimeOut = 10*1000;
  130. DWORD dwCreationFlags=0; // Start without CREATE_SUSPENDED
  131. DWORD ThreadId;
  132. iReturn = NO_ERROR;
  133. HANDLE hParent = CreateThread(NULL,
  134. 0,
  135. (LPTHREAD_START_ROUTINE) SetAutoDialStateThread,
  136. (void *) pStatus,
  137. dwCreationFlags,
  138. &ThreadId );
  139. iReturn = NO_ERROR;
  140. DWORD dwRet = WaitForSingleObject(hParent,
  141. dwTimeOut);
  142. switch(dwRet) {
  143. case WAIT_ABANDONED :
  144. break;
  145. case WAIT_OBJECT_0 :
  146. CloseHandle(hParent);
  147. break;
  148. case WAIT_TIMEOUT :
  149. //TerminateThread(hParent,0);
  150. iReturn = ERROR_IN_SET;
  151. break;
  152. default:
  153. break;
  154. }
  155. return iReturn;
  156. }
  157. int ResetAutoDialConfiguration()
  158. {
  159. int iRet;
  160. iRet = NO_ERROR;
  161. if(gIspState.iState == ISPState::NotValidState ){
  162. //
  163. // Not alid So No need to Reset
  164. return iRet;
  165. }
  166. return ChangeInterNetAutoDial(&gIspState);
  167. }
  168. int DisableAutoDial()
  169. {
  170. ISPState IspState = { "",
  171. 0,
  172. ISPState::NotValidState};
  173. return ChangeInterNetAutoDial(&IspState);
  174. }
  175. void UnLoadInetCfgLib()
  176. {
  177. if(hINetCfg){
  178. FreeLibrary(hINetCfg); // Load INetCfg.DLL and store globally
  179. hINetCfg = NULL;
  180. }
  181. }