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.

69 lines
1.8 KiB

  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <fcntl.h>
  5. #include <stdlib.h>
  6. #include <io.h>
  7. #include <wininet.h>
  8. #include <proxreg.h>
  9. #include <proxymsg.h>
  10. void PrintMessage(DWORD dwMsg, ...);
  11. DWORD SetProxySettings(DWORD Flags, char * ProxyServer, char * BypassList);
  12. DWORD MigrateProxySettings (void)
  13. {
  14. INTERNET_PER_CONN_OPTION_LIST list;
  15. DWORD dwBufSize = sizeof(list);
  16. DWORD dwErr = ERROR_SUCCESS;
  17. // fill out list struct
  18. list.dwSize = sizeof(list);
  19. list.pszConnection = NULL; // NULL == LAN, otherwise connectoid name
  20. list.dwOptionCount = 3; // get three options
  21. list.pOptions = new INTERNET_PER_CONN_OPTION[3];
  22. if(NULL == list.pOptions)
  23. return ERROR_NOT_ENOUGH_MEMORY;
  24. list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
  25. list.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
  26. list.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
  27. // ask wininet
  28. BOOL fRet = InternetQueryOption (NULL,
  29. INTERNET_OPTION_PER_CONNECTION_OPTION,
  30. &list,
  31. &dwBufSize);
  32. // TODO: what if there is no manual proxy setting?
  33. if (!fRet)
  34. {
  35. dwErr = GetLastError();
  36. goto cleanup;
  37. }
  38. else
  39. {
  40. dwErr = SetProxySettings(
  41. list.pOptions[0].Value.dwValue,
  42. list.pOptions[1].Value.pszValue,
  43. list.pOptions[2].Value.pszValue
  44. );
  45. }
  46. cleanup:
  47. GlobalFree (list.pOptions[1].Value.pszValue);
  48. GlobalFree (list.pOptions[2].Value.pszValue);
  49. delete [] list.pOptions;
  50. if (dwErr == ERROR_INTERNET_INVALID_OPTION)
  51. {
  52. PrintMessage(MSG_REQUIRES_IE501);
  53. }
  54. return dwErr;
  55. }