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.

188 lines
4.8 KiB

  1. //****************************************************************************
  2. //
  3. // Module: INETCFG.DLL
  4. // File: ienews.c
  5. // Content: This file contains all the functions that handle importing
  6. // connection information.
  7. // History:
  8. // Sat 10-Mar-1996 23:50:40 -by- Mark MacLin [mmaclin]
  9. // this code started its life as ixport.c in RNAUI.DLL
  10. // my thanks to viroont
  11. //
  12. // Copyright (c) Microsoft Corporation 1991-1996
  13. //
  14. //****************************************************************************
  15. #include "inetreg.h"
  16. #include "obcomglb.h"
  17. #pragma data_seg(".rdata")
  18. #define REGSTR_PATH_IE_SERVICES REGSTR_PATH_IEXPLORER L"\\Services"
  19. static const WCHAR cszRegPathIEServices[] = REGSTR_PATH_IE_SERVICES;
  20. static const WCHAR cszRegValNNTPEnabled[] = L"NNTP_Enabled";
  21. static const WCHAR cszRegValNNTPUseAuth[] = L"NNTP_Use_Auth";
  22. static const WCHAR cszRegValNNTPServer[] = L"NNTP_Server";
  23. static const WCHAR cszRegValNNTPMailName[] = L"NNTP_MailName";
  24. static const WCHAR cszRegValNNTPMailAddress[] = L"NNTP_MailAddr";
  25. static const WCHAR cszYes[] = L"yes";
  26. static const WCHAR cszNo[] = L"no";
  27. #pragma data_seg()
  28. #define PCE_WWW_BASIC 0x13
  29. WCHAR szNNTP_Resource[] = L"NNTP";
  30. typedef DWORD (APIENTRY *PFNWNETGETCACHEDPASSWORD)(LPSTR, WORD, LPSTR, LPWORD,BYTE);
  31. DWORD MyWNetGetCachedPassword(LPWSTR pbResource, WORD cbResource, LPWSTR pbPassword,
  32. LPWORD pcchPassword, BYTE nType)
  33. {
  34. USES_CONVERSION;
  35. HINSTANCE hInst = NULL;
  36. FARPROC fp = NULL;
  37. DWORD dwRet = 0;
  38. hInst = LoadLibrary(L"MPR.DLL");
  39. if (hInst)
  40. {
  41. fp = GetProcAddress(hInst, "WNetGetCachedPassword");
  42. if (fp)
  43. dwRet = ((PFNWNETGETCACHEDPASSWORD)fp) (W2A(pbResource), cbResource, W2A(pbPassword), pcchPassword, nType);
  44. else
  45. dwRet = GetLastError();
  46. FreeLibrary(hInst);
  47. hInst = NULL;
  48. } else {
  49. dwRet = GetLastError();
  50. }
  51. return dwRet;
  52. }
  53. typedef DWORD (APIENTRY *PFNWNETCACHEPASSWORD)(LPSTR, WORD, LPSTR, WORD,BYTE,UINT);
  54. DWORD MyWNetCachePassword
  55. (
  56. LPWSTR szResource,
  57. WORD cchResource,
  58. LPWSTR szPassword,
  59. WORD cchPassword,
  60. BYTE nType,
  61. UINT fnFlags
  62. )
  63. {
  64. HINSTANCE hInst = NULL;
  65. FARPROC fp = NULL;
  66. DWORD dwRet = 0;
  67. hInst = LoadLibrary(L"MPR.DLL");
  68. if (hInst)
  69. {
  70. USES_CONVERSION;
  71. fp = GetProcAddress(hInst, "WNetCachePassword");
  72. if (fp)
  73. dwRet = ((PFNWNETCACHEPASSWORD)fp)(W2A(szResource), cchResource, W2A(szPassword), cchPassword,nType,fnFlags);
  74. else
  75. dwRet = GetLastError();
  76. FreeLibrary(hInst);
  77. hInst = NULL;
  78. fp = NULL;
  79. } else {
  80. dwRet = GetLastError();
  81. }
  82. return dwRet;
  83. }
  84. BOOL
  85. SetAuthInfo( WCHAR *szUsername, WCHAR *szPassword)
  86. {
  87. int wnet_status;
  88. WCHAR szUserInfo[256];
  89. WORD cchUserInfo = MAX_CHARS_IN_BUFFER(szUserInfo);
  90. if (wcschr(szUsername, L':')) {
  91. return(FALSE);
  92. }
  93. lstrcpy( szUserInfo, szUsername );
  94. lstrcat( szUserInfo, L":" );
  95. lstrcat( szUserInfo, szUsername );
  96. wnet_status = MyWNetCachePassword (szNNTP_Resource, (USHORT )lstrlen(szNNTP_Resource), szUserInfo, (USHORT)lstrlen( szUserInfo ), PCE_WWW_BASIC, 0);
  97. return( wnet_status == WN_SUCCESS );
  98. }
  99. DWORD SetIEClientInfo(LPINETCLIENTINFO lpClientInfo)
  100. {
  101. HKEY hKey;
  102. DWORD dwRet;
  103. DWORD dwSize;
  104. DWORD dwType;
  105. dwRet = RegCreateKey(HKEY_CURRENT_USER, cszRegPathIEServices, &hKey);
  106. if (ERROR_SUCCESS != dwRet)
  107. {
  108. return dwRet;
  109. }
  110. dwSize = max(sizeof(cszYes), sizeof(cszNo));
  111. dwType = REG_SZ;
  112. RegSetValueEx(
  113. hKey,
  114. cszRegValNNTPEnabled,
  115. 0L,
  116. dwType,
  117. (LPBYTE)(*lpClientInfo->szNNTPServer ? cszYes : cszNo),
  118. dwSize);
  119. dwSize = max(sizeof(cszYes), sizeof(cszNo));
  120. dwType = REG_SZ;
  121. RegSetValueEx(
  122. hKey,
  123. cszRegValNNTPUseAuth,
  124. 0L,
  125. dwType,
  126. (LPBYTE)((lpClientInfo->dwFlags & INETC_LOGONNEWS) ? cszYes : cszNo),
  127. dwSize);
  128. dwSize = sizeof(lpClientInfo->szEMailName);
  129. dwType = REG_SZ;
  130. RegSetValueEx(
  131. hKey,
  132. cszRegValNNTPMailName,
  133. 0L,
  134. dwType,
  135. (LPBYTE)lpClientInfo->szEMailName,
  136. dwSize);
  137. dwSize = sizeof(lpClientInfo->szEMailAddress);
  138. dwType = REG_SZ;
  139. RegSetValueEx(
  140. hKey,
  141. cszRegValNNTPMailAddress,
  142. 0L,
  143. dwType,
  144. (LPBYTE)lpClientInfo->szEMailAddress,
  145. dwSize);
  146. dwSize = sizeof(lpClientInfo->szNNTPServer);
  147. dwType = REG_SZ;
  148. RegSetValueEx(
  149. hKey,
  150. cszRegValNNTPServer,
  151. 0L,
  152. dwType,
  153. (LPBYTE)lpClientInfo->szNNTPServer,
  154. dwSize);
  155. RegCloseKey(hKey);
  156. SetAuthInfo(lpClientInfo->szNNTPLogonName, lpClientInfo->szNNTPLogonPassword);
  157. return ERROR_SUCCESS;
  158. }