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.

215 lines
5.3 KiB

  1. #include <windows.h>
  2. #include <wininet.h>
  3. #include <shlwapi.h>
  4. #include <icwacct.h>
  5. #include "dllmain.h"
  6. #include "acctreg.h"
  7. #define ARRAYSIZE(_exp_) (sizeof(_exp_) / sizeof(_exp_[0]))
  8. CAcctReg::CAcctReg()
  9. {
  10. m_cRef = 1;
  11. DllAddRef();
  12. }
  13. CAcctReg::~CAcctReg()
  14. {
  15. DllRelease();
  16. }
  17. ULONG CAcctReg::AddRef(void)
  18. {
  19. return ++m_cRef;
  20. }
  21. ULONG CAcctReg::Release(void)
  22. {
  23. if (--m_cRef==0)
  24. {
  25. delete this;
  26. return 0;
  27. }
  28. return m_cRef;
  29. }
  30. HRESULT CAcctReg::QueryInterface(REFIID riid, void **ppvObject)
  31. {
  32. if(!ppvObject)
  33. return E_INVALIDARG;
  34. *ppvObject = NULL;
  35. if (IsEqualIID(riid, IID_IDispatch))
  36. *ppvObject = (IDispatch *)this;
  37. else if (IsEqualIID(riid, IID_IUnknown))
  38. *ppvObject = this;
  39. else
  40. return E_NOINTERFACE;
  41. AddRef();
  42. return NOERROR;
  43. }
  44. HRESULT CAcctReg::GetTypeInfoCount(UINT *pctinfo)
  45. {
  46. return E_NOTIMPL;
  47. }
  48. HRESULT CAcctReg::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  49. {
  50. return E_NOTIMPL;
  51. }
  52. HRESULT CAcctReg::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgdispid)
  53. {
  54. if (cNames == 1 && lstrcmpW(rgszNames[0], L"register") == 0)
  55. {
  56. rgdispid[0] = 666;
  57. return S_OK;
  58. }
  59. return E_NOTIMPL;
  60. }
  61. HRESULT RegisterAccounts(LPSTR pszFile)
  62. {
  63. HRESULT hr;
  64. HINSTANCE hinst;
  65. HKEY hkey;
  66. char szDll[MAX_PATH], szExpand[MAX_PATH];
  67. LPSTR psz;
  68. DWORD cb, type;
  69. PFNCREATEACCOUNTSFROMFILE pfn;
  70. hr = E_FAIL;
  71. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Internet Account Manager", 0, KEY_QUERY_VALUE, &hkey))
  72. {
  73. cb = sizeof(szDll);
  74. if (ERROR_SUCCESS == RegQueryValueEx(hkey, "DllPath", NULL, &type, (LPBYTE)szDll, &cb))
  75. {
  76. if (type == REG_EXPAND_SZ)
  77. {
  78. ExpandEnvironmentStrings(szDll, szExpand, ARRAYSIZE(szExpand));
  79. psz = szExpand;
  80. }
  81. else
  82. {
  83. psz = szDll;
  84. }
  85. hinst = LoadLibrary(psz);
  86. if (hinst != NULL)
  87. {
  88. pfn = (PFNCREATEACCOUNTSFROMFILE)GetProcAddress(hinst, "CreateAccountsFromFile");
  89. if (pfn != NULL)
  90. {
  91. hr = pfn(pszFile, 0);
  92. }
  93. FreeLibrary(hinst);
  94. }
  95. }
  96. RegCloseKey(hkey);
  97. }
  98. return(hr);
  99. }
  100. #define CBBUFFER 1024
  101. BOOL CreateLocalFile(HINTERNET hfile, LPCSTR pszFile)
  102. {
  103. BOOL fRet;
  104. HANDLE hfileLocal;
  105. LPBYTE pb;
  106. DWORD dw, dwT;
  107. fRet = FALSE;
  108. pb = (LPBYTE)malloc(CBBUFFER);
  109. if (pb != NULL)
  110. {
  111. hfileLocal = CreateFile(pszFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
  112. if (hfileLocal != INVALID_HANDLE_VALUE)
  113. {
  114. while (InternetReadFile(hfile, pb, CBBUFFER, &dw))
  115. {
  116. if (dw == 0)
  117. {
  118. fRet = TRUE;
  119. break;
  120. }
  121. if (!WriteFile(hfileLocal, pb, dw, &dwT, NULL))
  122. break;
  123. }
  124. CloseHandle(hfileLocal);
  125. if (!fRet)
  126. DeleteFile(pszFile);
  127. }
  128. free(pb);
  129. }
  130. return(fRet);
  131. }
  132. HRESULT CAcctReg::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr)
  133. {
  134. HRESULT hr;
  135. HINTERNET hnet, hfile;
  136. LPSTR pszSrc, pszFile;
  137. char szPath[MAX_PATH], szDest[MAX_PATH];
  138. int cch;
  139. DWORD dw;
  140. if (dispidMember == 666 &&
  141. pdispparams->cArgs == 1 &&
  142. pdispparams->rgvarg[0].vt == VT_BSTR &&
  143. pdispparams->rgvarg[0].bstrVal)
  144. {
  145. hr = E_FAIL;
  146. cch = WideCharToMultiByte(CP_ACP, 0, pdispparams->rgvarg[0].bstrVal, -1, NULL, 0, NULL, NULL);
  147. cch++;
  148. pszSrc = (LPSTR)malloc(cch);
  149. if (pszSrc != NULL)
  150. {
  151. WideCharToMultiByte(CP_ACP, 0, pdispparams->rgvarg[0].bstrVal, -1, pszSrc, cch, NULL, NULL);
  152. if (GetTempPath(sizeof(szPath), szPath) &&
  153. GetTempFileName(szPath, "ins", 0, szDest) != 0)
  154. {
  155. hnet = InternetOpen("Outlook Express", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  156. if (hnet != NULL)
  157. {
  158. hfile = InternetOpenUrl(hnet, pszSrc, NULL, 0, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, 0);
  159. if (hfile != NULL)
  160. {
  161. if (CreateLocalFile(hfile, szDest))
  162. {
  163. hr = RegisterAccounts(szDest);
  164. DeleteFile(szDest);
  165. }
  166. InternetCloseHandle(hfile);
  167. }
  168. InternetCloseHandle(hnet);
  169. }
  170. }
  171. free(pszSrc);
  172. }
  173. return(S_OK);
  174. }
  175. return E_NOTIMPL;
  176. }