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.

230 lines
6.1 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 "wizard.h"
  16. #include "inetcfg.h"
  17. extern "C" {
  18. #include <netmpr.h>
  19. }
  20. #pragma data_seg(".rdata")
  21. #define REGSTR_PATH_IE_SERVICES REGSTR_PATH_IEXPLORER TEXT("\\Services")
  22. static const TCHAR cszRegPathIEServices[] = REGSTR_PATH_IE_SERVICES;
  23. static const TCHAR cszRegValNNTPEnabled[] = TEXT("NNTP_Enabled");
  24. static const TCHAR cszRegValNNTPUseAuth[] = TEXT("NNTP_Use_Auth");
  25. static const TCHAR cszRegValNNTPServer[] = TEXT("NNTP_Server");
  26. static const TCHAR cszRegValNNTPMailName[] = TEXT("NNTP_MailName");
  27. static const TCHAR cszRegValNNTPMailAddress[] = TEXT("NNTP_MailAddr");
  28. static const TCHAR cszYes[] = TEXT("yes");
  29. static const TCHAR cszNo[] = TEXT("no");
  30. #pragma data_seg()
  31. #define PCE_WWW_BASIC 0x13
  32. TCHAR szNNTP_Resource[] = TEXT("NNTP");
  33. typedef DWORD (APIENTRY *PFNWNETGETCACHEDPASSWORD)(LPTSTR,WORD,LPTSTR,LPWORD,BYTE);
  34. DWORD MyWNetGetCachedPassword(LPTSTR pbResource,WORD cbResource,LPTSTR pbPassword,
  35. LPWORD pcbPassword,BYTE nType)
  36. {
  37. HINSTANCE hInst = NULL;
  38. FARPROC fp = NULL;
  39. DWORD dwRet = 0;
  40. hInst = LoadLibrary(TEXT("MPR.DLL"));
  41. if (hInst)
  42. {
  43. fp = GetProcAddress(hInst,"WNetGetCachedPassword");
  44. if (fp)
  45. dwRet = ((PFNWNETGETCACHEDPASSWORD)fp) (pbResource, cbResource, pbPassword, pcbPassword, nType);
  46. else
  47. dwRet = GetLastError();
  48. FreeLibrary(hInst);
  49. hInst = NULL;
  50. } else {
  51. dwRet = GetLastError();
  52. }
  53. return dwRet;
  54. }
  55. BOOL
  56. GetAuthInfo( TCHAR *szUsername, int cbUser, TCHAR *szPassword, int cbPass )
  57. {
  58. int wnet_status;
  59. TCHAR szUserInfo[256];
  60. WORD cbUserInfo = sizeof(szUserInfo);
  61. TCHAR *p;
  62. if (cbUser && szUsername)
  63. *szUsername = '\0';
  64. if (cbPass && szPassword)
  65. *szPassword = '\0';
  66. wnet_status = MyWNetGetCachedPassword (szNNTP_Resource, sizeof(szNNTP_Resource) - 1, szUserInfo, &cbUserInfo, PCE_WWW_BASIC);
  67. switch (wnet_status) {
  68. case WN_NOT_SUPPORTED:
  69. return( FALSE ); // Cache not enabled
  70. break;
  71. case WN_CANCEL:
  72. return( TRUE ); // Cache enabled but no password set
  73. break;
  74. case WN_SUCCESS:
  75. p = _tcschr(szUserInfo,':');
  76. if (p) {
  77. *p = 0;
  78. lstrcpyn(szUsername, szUserInfo, cbUser - 1);
  79. szUserInfo[cbUser - 1] = '\0';
  80. lstrcpyn(szPassword, p+1, cbPass - 1);
  81. szPassword[cbPass - 1] = '\0';
  82. }
  83. return( TRUE );
  84. break;
  85. default:
  86. //// XX_Assert((0),("Unexpected Return from WNetGetCachedPassword: %d", wnet_status ));
  87. return( FALSE );
  88. }
  89. /*NOTREACHED*/
  90. return(FALSE);
  91. }
  92. typedef DWORD (APIENTRY *PFNWNETCACHEPASSWORD)(LPTSTR,WORD,LPTSTR,WORD,BYTE,UINT);
  93. DWORD MyWNetCachePassword(
  94. LPTSTR pbResource,
  95. WORD cbResource,
  96. LPTSTR pbPassword,
  97. WORD cbPassword,
  98. BYTE nType,
  99. UINT fnFlags
  100. )
  101. {
  102. HINSTANCE hInst = NULL;
  103. FARPROC fp = NULL;
  104. DWORD dwRet = 0;
  105. hInst = LoadLibrary(TEXT("MPR.DLL"));
  106. if (hInst)
  107. {
  108. fp = GetProcAddress(hInst,"WNetCachePassword");
  109. if (fp)
  110. dwRet = ((PFNWNETCACHEPASSWORD)fp)(pbResource,cbResource,pbPassword,cbPassword,nType,fnFlags);
  111. else
  112. dwRet = GetLastError();
  113. FreeLibrary(hInst);
  114. hInst = NULL;
  115. fp = NULL;
  116. } else {
  117. dwRet = GetLastError();
  118. }
  119. return dwRet;
  120. }
  121. BOOL
  122. SetAuthInfo( TCHAR *szUsername, TCHAR *szPassword)
  123. {
  124. int wnet_status;
  125. TCHAR szUserInfo[256];
  126. WORD cbUserInfo = sizeof(szUserInfo);
  127. if (_tcschr(szUsername, ':')) {
  128. //// XX_Assert((0),("SetAuthInfo(): Username has ':' in it!: %s", szUsername ));
  129. return(FALSE);
  130. }
  131. lstrcpy( szUserInfo, szUsername );
  132. lstrcat( szUserInfo, TEXT(":") );
  133. lstrcat( szUserInfo, szPassword );
  134. wnet_status = MyWNetCachePassword (szNNTP_Resource, sizeof(szNNTP_Resource) - 1, szUserInfo, (USHORT)lstrlen( szUserInfo ), PCE_WWW_BASIC, 0);
  135. return( wnet_status == WN_SUCCESS );
  136. }
  137. DWORD SetIEClientInfo(LPINETCLIENTINFO lpClientInfo)
  138. {
  139. HKEY hKey;
  140. DWORD dwRet;
  141. DWORD dwSize;
  142. DWORD dwType;
  143. dwRet = RegCreateKey(HKEY_CURRENT_USER, cszRegPathIEServices, &hKey);
  144. if (ERROR_SUCCESS != dwRet)
  145. {
  146. return dwRet;
  147. }
  148. dwSize = max(sizeof(cszYes), sizeof(cszNo));
  149. dwType = REG_SZ;
  150. RegSetValueEx(
  151. hKey,
  152. cszRegValNNTPEnabled,
  153. 0L,
  154. dwType,
  155. (LPBYTE)(*lpClientInfo->szNNTPServer ? cszYes : cszNo),
  156. dwSize);
  157. dwSize = max(sizeof(cszYes), sizeof(cszNo));
  158. dwType = REG_SZ;
  159. RegSetValueEx(
  160. hKey,
  161. cszRegValNNTPUseAuth,
  162. 0L,
  163. dwType,
  164. (LPBYTE)((lpClientInfo->dwFlags & INETC_LOGONNEWS) ? cszYes : cszNo),
  165. dwSize);
  166. dwSize = sizeof(lpClientInfo->szEMailName);
  167. dwType = REG_SZ;
  168. RegSetValueEx(
  169. hKey,
  170. cszRegValNNTPMailName,
  171. 0L,
  172. dwType,
  173. (LPBYTE)lpClientInfo->szEMailName,
  174. dwSize);
  175. dwSize = sizeof(lpClientInfo->szEMailAddress);
  176. dwType = REG_SZ;
  177. RegSetValueEx(
  178. hKey,
  179. cszRegValNNTPMailAddress,
  180. 0L,
  181. dwType,
  182. (LPBYTE)lpClientInfo->szEMailAddress,
  183. dwSize);
  184. dwSize = sizeof(lpClientInfo->szNNTPServer);
  185. dwType = REG_SZ;
  186. RegSetValueEx(
  187. hKey,
  188. cszRegValNNTPServer,
  189. 0L,
  190. dwType,
  191. (LPBYTE)lpClientInfo->szNNTPServer,
  192. dwSize);
  193. RegCloseKey(hKey);
  194. SetAuthInfo(lpClientInfo->szNNTPLogonName, lpClientInfo->szNNTPLogonPassword);
  195. return ERROR_SUCCESS;
  196. }