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.

328 lines
9.0 KiB

  1. //****************************************************************************
  2. //
  3. // Module: INETCFG.DLL
  4. // File: iclient.c
  5. // Content: This file contains all the functions that handle importing
  6. // client information.
  7. // History:
  8. // Sat 10-Mar-1996 23:50:40 -by- Mark MacLin [mmaclin]
  9. // 96/03/13 markdu Assimilated with inetcfg.dll.
  10. // 96/03/20 markdu Combined export.h and iclient.h into inetcfg.h
  11. // 96/04/18 markdu NASH BUG 18443
  12. //
  13. // Copyright (c) Microsoft Corporation 1991-1996
  14. //
  15. //****************************************************************************
  16. #include "wizard.h"
  17. #include "inetcfg.h"
  18. #define REGSTR_PATH_INTERNET_CLIENT TEXT("Software\\Microsoft\\Internet ClientX")
  19. #pragma data_seg(".rdata")
  20. // registry constants
  21. static const TCHAR cszRegPathInternetClient[] = REGSTR_PATH_INTERNET_CLIENT;
  22. static const TCHAR cszRegValEMailName[] = TEXT("EMail_Name");
  23. static const TCHAR cszRegValEMailAddress[] = TEXT("EMail_Address");
  24. static const TCHAR cszRegValPOPLogonRequired[] = TEXT("POP_Logon_Required");
  25. static const TCHAR cszRegValPOPLogonName[] = TEXT("POP_Logon_Name");
  26. static const TCHAR cszRegValPOPLogonPassword[] = TEXT("POP_Logon_Password");
  27. static const TCHAR cszRegValPOPServer[] = TEXT("POP_Server");
  28. static const TCHAR cszRegValSMTPServer[] = TEXT("SMTP_Server");
  29. static const TCHAR cszRegValNNTPLogonRequired[] = TEXT("NNTP_Logon_Required");
  30. static const TCHAR cszRegValNNTPLogonName[] = TEXT("NNTP_Logon_Name");
  31. static const TCHAR cszRegValNNTPLogonPassword[] = TEXT("NNTP_Logon_Password");
  32. static const TCHAR cszRegValNNTPServer[] = TEXT("NNTP_Server");
  33. static const TCHAR cszNull[] = TEXT("");
  34. static const TCHAR cszYes[] = TEXT("yes");
  35. static const TCHAR cszNo[] = TEXT("no");
  36. #pragma data_seg()
  37. #ifdef UNICODE
  38. PWCHAR ToUnicodeWithAlloc(LPCSTR);
  39. VOID ToAnsiClientInfo(LPINETCLIENTINFOA, LPINETCLIENTINFOW);
  40. VOID ToUnicodeClientInfo(LPINETCLIENTINFOW, LPINETCLIENTINFOA);
  41. #endif
  42. //*******************************************************************
  43. //
  44. // FUNCTION: InetGetClientInfo
  45. //
  46. // PURPOSE: This function will get the internet client params
  47. // from the registry
  48. //
  49. // PARAMETERS: lpClientInfo - on return, this structure will contain
  50. // the internet client params as set in the registry.
  51. // lpszProfileName - Name of client info profile to
  52. // retrieve. If this is NULL, the default profile is used.
  53. //
  54. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  55. //
  56. //*******************************************************************
  57. #ifdef UNICODE
  58. extern "C" HRESULT WINAPI InetGetClientInfoA
  59. (
  60. LPCSTR lpszProfileName,
  61. LPINETCLIENTINFOA lpClientInfo
  62. )
  63. {
  64. HRESULT hr;
  65. TCHAR lpszProfileNameW[MAX_PATH+1];
  66. INETCLIENTINFOW ClientInfoW;
  67. mbstowcs(lpszProfileNameW, lpszProfileName, lstrlenA(lpszProfileName)+1);
  68. hr = InetGetClientInfoW(lpszProfileNameW, &ClientInfoW);
  69. ToAnsiClientInfo(lpClientInfo, &ClientInfoW);
  70. return hr;
  71. }
  72. extern "C" HRESULT WINAPI InetGetClientInfoW
  73. #else
  74. extern "C" HRESULT WINAPI InetGetClientInfoA
  75. #endif
  76. (
  77. LPCTSTR lpszProfileName,
  78. LPINETCLIENTINFO lpClientInfo
  79. )
  80. {
  81. HKEY hKey;
  82. DWORD dwRet;
  83. DWORD dwSize;
  84. DWORD dwType;
  85. DWORD dwVal;
  86. if (sizeof(INETCLIENTINFO) > lpClientInfo->dwSize)
  87. {
  88. return ERROR_INSUFFICIENT_BUFFER;
  89. }
  90. dwRet = RegOpenKey(HKEY_CURRENT_USER, cszRegPathInternetClient, &hKey);
  91. if (ERROR_SUCCESS != dwRet)
  92. {
  93. return dwRet;
  94. }
  95. lpClientInfo->dwFlags = 0;
  96. dwSize = sizeof(dwVal);
  97. dwType = REG_DWORD;
  98. RegQueryValueEx(
  99. hKey,
  100. cszRegValPOPLogonRequired,
  101. 0L,
  102. &dwType,
  103. (LPBYTE)&dwVal,
  104. &dwSize);
  105. if (dwVal)
  106. {
  107. lpClientInfo->dwFlags |= INETC_LOGONMAIL;
  108. }
  109. dwSize = sizeof(dwVal);
  110. dwType = REG_DWORD;
  111. RegQueryValueEx(
  112. hKey,
  113. cszRegValNNTPLogonRequired,
  114. 0L,
  115. &dwType,
  116. (LPBYTE)&dwVal,
  117. &dwSize);
  118. if (dwVal)
  119. {
  120. lpClientInfo->dwFlags |= INETC_LOGONNEWS;
  121. }
  122. dwSize = sizeof(lpClientInfo->szEMailName);
  123. dwType = REG_SZ;
  124. RegQueryValueEx(
  125. hKey,
  126. cszRegValEMailName,
  127. 0L,
  128. &dwType,
  129. (LPBYTE)lpClientInfo->szEMailName,
  130. &dwSize);
  131. dwSize = sizeof(lpClientInfo->szEMailAddress);
  132. dwType = REG_SZ;
  133. RegQueryValueEx(
  134. hKey,
  135. cszRegValEMailAddress,
  136. 0L,
  137. &dwType,
  138. (LPBYTE)lpClientInfo->szEMailAddress,
  139. &dwSize);
  140. dwSize = sizeof(lpClientInfo->szPOPServer);
  141. dwType = REG_SZ;
  142. RegQueryValueEx(
  143. hKey,
  144. cszRegValPOPServer,
  145. 0L,
  146. &dwType,
  147. (LPBYTE)lpClientInfo->szPOPServer,
  148. &dwSize);
  149. dwSize = sizeof(lpClientInfo->szSMTPServer);
  150. dwType = REG_SZ;
  151. RegQueryValueEx(
  152. hKey,
  153. cszRegValSMTPServer,
  154. 0L,
  155. &dwType,
  156. (LPBYTE)lpClientInfo->szSMTPServer,
  157. &dwSize);
  158. dwSize = sizeof(lpClientInfo->szNNTPServer);
  159. dwType = REG_SZ;
  160. RegQueryValueEx(
  161. hKey,
  162. cszRegValNNTPServer,
  163. 0L,
  164. &dwType,
  165. (LPBYTE)lpClientInfo->szNNTPServer,
  166. &dwSize);
  167. RegCloseKey(hKey);
  168. return ERROR_SUCCESS;
  169. }
  170. //*******************************************************************
  171. //
  172. // FUNCTION: InetSetClientInfo
  173. //
  174. // PURPOSE: This function will set the internet client params
  175. //
  176. // PARAMETERS: lpClientInfo - pointer to struct with info to set
  177. // in the registry.
  178. // lpszProfileName - Name of client info profile to
  179. // modify. If this is NULL, the default profile is used.
  180. //
  181. // RETURNS: HRESULT code, ERROR_SUCCESS if no errors occurred
  182. //
  183. //*******************************************************************
  184. #ifdef UNICODE
  185. extern "C" HRESULT WINAPI InetSetClientInfoA
  186. (
  187. LPCSTR lpszProfileName,
  188. LPINETCLIENTINFOA lpClientInfo
  189. )
  190. {
  191. TCHAR szProfileNameW[MAX_PATH+1];
  192. INETCLIENTINFOW ClientInfoW;
  193. mbstowcs(szProfileNameW, lpszProfileName, lstrlenA(lpszProfileName)+1);
  194. ToUnicodeClientInfo(&ClientInfoW, lpClientInfo);
  195. return InetSetClientInfoW(szProfileNameW, &ClientInfoW);
  196. }
  197. extern "C" HRESULT WINAPI InetSetClientInfoW
  198. #else
  199. extern "C" HRESULT WINAPI InetSetClientInfoA
  200. #endif
  201. (
  202. LPCTSTR lpszProfileName,
  203. LPINETCLIENTINFO lpClientInfo
  204. )
  205. {
  206. HKEY hKey;
  207. DWORD dwRet;
  208. DWORD dwSize;
  209. DWORD dwType;
  210. DWORD dwVal;
  211. if (sizeof(INETCLIENTINFO) > lpClientInfo->dwSize)
  212. {
  213. return ERROR_INSUFFICIENT_BUFFER;
  214. }
  215. dwRet = RegCreateKey(HKEY_CURRENT_USER, cszRegPathInternetClient, &hKey);
  216. if (ERROR_SUCCESS != dwRet)
  217. {
  218. return dwRet;
  219. }
  220. dwVal = lpClientInfo->dwFlags & INETC_LOGONMAIL ? 1 : 0;
  221. dwSize = sizeof(dwVal);
  222. dwType = REG_DWORD;
  223. RegSetValueEx(
  224. hKey,
  225. cszRegValPOPLogonRequired,
  226. 0L,
  227. dwType,
  228. (LPBYTE)&dwVal,
  229. dwSize);
  230. dwVal = lpClientInfo->dwFlags & INETC_LOGONNEWS ? 1 : 0;
  231. dwSize = sizeof(dwVal);
  232. dwType = REG_DWORD;
  233. RegSetValueEx(
  234. hKey,
  235. cszRegValNNTPLogonRequired,
  236. 0L,
  237. dwType,
  238. (LPBYTE)&dwVal,
  239. dwSize);
  240. dwSize = sizeof(lpClientInfo->szEMailName);
  241. dwType = REG_SZ;
  242. RegSetValueEx(
  243. hKey,
  244. cszRegValEMailName,
  245. 0L,
  246. dwType,
  247. (LPBYTE)lpClientInfo->szEMailName,
  248. dwSize);
  249. dwSize = sizeof(lpClientInfo->szEMailAddress);
  250. dwType = REG_SZ;
  251. RegSetValueEx(
  252. hKey,
  253. cszRegValEMailAddress,
  254. 0L,
  255. dwType,
  256. (LPBYTE)lpClientInfo->szEMailAddress,
  257. dwSize);
  258. dwSize = sizeof(lpClientInfo->szPOPServer);
  259. dwType = REG_SZ;
  260. RegSetValueEx(
  261. hKey,
  262. cszRegValPOPServer,
  263. 0L,
  264. dwType,
  265. (LPBYTE)lpClientInfo->szPOPServer,
  266. dwSize);
  267. dwSize = sizeof(lpClientInfo->szSMTPServer);
  268. dwType = REG_SZ;
  269. RegSetValueEx(
  270. hKey,
  271. cszRegValSMTPServer,
  272. 0L,
  273. dwType,
  274. (LPBYTE)lpClientInfo->szSMTPServer,
  275. dwSize);
  276. dwSize = sizeof(lpClientInfo->szNNTPServer);
  277. dwType = REG_SZ;
  278. RegSetValueEx(
  279. hKey,
  280. cszRegValNNTPServer,
  281. 0L,
  282. dwType,
  283. (LPBYTE)lpClientInfo->szNNTPServer,
  284. dwSize);
  285. RegCloseKey(hKey);
  286. return dwRet;
  287. }