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.

200 lines
4.0 KiB

  1. #include "mslocusr.h"
  2. #include "msluglob.h"
  3. STDMETHODIMP CLUClassFactory::QueryInterface(
  4. /* [in] */ REFIID riid,
  5. /* [out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
  6. {
  7. *ppvObject = NULL;
  8. if (IsEqualIID(riid, IID_IUnknown) ||
  9. IsEqualIID(riid, IID_IClassFactory)) {
  10. *ppvObject = (LPVOID)this;
  11. AddRef();
  12. return NOERROR;
  13. }
  14. return ResultFromScode(E_NOINTERFACE);
  15. }
  16. STDMETHODIMP_(ULONG) CLUClassFactory::AddRef(void)
  17. {
  18. RefThisDLL(TRUE);
  19. return 1;
  20. }
  21. STDMETHODIMP_(ULONG) CLUClassFactory::Release(void)
  22. {
  23. RefThisDLL(FALSE);
  24. return 1;
  25. }
  26. HRESULT CreateUserDatabase(REFIID riid, void **ppOut)
  27. {
  28. CLUDatabase *pObj = new CLUDatabase;
  29. if (NULL == pObj)
  30. return ResultFromScode(E_OUTOFMEMORY);
  31. HRESULT hr = pObj->QueryInterface(riid, ppOut);
  32. if (FAILED(hr)) {
  33. delete pObj;
  34. }
  35. else {
  36. pObj->AddRef();
  37. }
  38. return NOERROR;
  39. }
  40. STDMETHODIMP CLUClassFactory::CreateInstance(
  41. /* [unique][in] */ IUnknown __RPC_FAR *pUnkOuter,
  42. /* [in] */ REFIID riid,
  43. /* [out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
  44. {
  45. if (NULL != pUnkOuter)
  46. return ResultFromScode(CLASS_E_NOAGGREGATION);
  47. return CreateUserDatabase(riid, ppvObject);
  48. }
  49. STDMETHODIMP CLUClassFactory::LockServer(
  50. /* [in] */ BOOL fLock)
  51. {
  52. LockThisDLL(fLock);
  53. return NOERROR;
  54. }
  55. /* This function signals our stub NP DLL in MPREXE's context to load or
  56. * unload MSLOCUSR as a net provider DLL. This way, when we uninstall,
  57. * DllUnregisterServer can get MSLOCUSR unloaded from MPREXE's process
  58. * space, so it can be deleted and upgraded. Then, DllRegisterServer
  59. * will tell the stub NP to reload MSLOCUSR again.
  60. */
  61. void SignalStubNP(BOOL fLoad)
  62. {
  63. HWND hwnd = FindWindow("WndClass_NPSTUBMonitor", NULL);
  64. if (hwnd != NULL) {
  65. SendMessage(hwnd, fLoad ? WM_USER : (WM_USER+1), 0, 0);
  66. }
  67. }
  68. extern "C" {
  69. STDAPI DllRegisterServer(void)
  70. {
  71. HKEY hkeyCLSID;
  72. HKEY hkeyOurs;
  73. HKEY hkeyInproc;
  74. LONG err;
  75. err = ::RegOpenKey(HKEY_CLASSES_ROOT, ::szCLSID, &hkeyCLSID);
  76. if (err == ERROR_SUCCESS) {
  77. err = ::RegCreateKey(hkeyCLSID, ::szOurCLSID, &hkeyOurs);
  78. if (err == ERROR_SUCCESS) {
  79. err = ::RegCreateKey(hkeyOurs, ::szINPROCSERVER32, &hkeyInproc);
  80. if (err == ERROR_SUCCESS) {
  81. err = ::RegSetValueEx(hkeyInproc, NULL, 0, REG_EXPAND_SZ,
  82. (LPBYTE)::szDLLNAME, ::strlenf(::szDLLNAME));
  83. if (err == ERROR_SUCCESS) {
  84. err = ::RegSetValueEx(hkeyInproc, ::szTHREADINGMODEL, 0,
  85. REG_SZ, (LPBYTE)::szAPARTMENT,
  86. ::strlenf(::szAPARTMENT));
  87. }
  88. ::RegCloseKey(hkeyInproc);
  89. }
  90. ::RegCloseKey(hkeyOurs);
  91. }
  92. ::RegCloseKey(hkeyCLSID);
  93. }
  94. if (err == ERROR_SUCCESS)
  95. return S_OK;
  96. else
  97. return HRESULT_FROM_WIN32(err);
  98. }
  99. STDAPI DllUnregisterServer(void)
  100. {
  101. HKEY hkeyCLSID;
  102. HKEY hkeyOurs;
  103. LONG err;
  104. err = ::RegOpenKey(HKEY_CLASSES_ROOT, ::szCLSID, &hkeyCLSID);
  105. if (err == ERROR_SUCCESS) {
  106. err = ::RegOpenKey(hkeyCLSID, ::szOurCLSID, &hkeyOurs);
  107. if (err == ERROR_SUCCESS) {
  108. err = ::RegDeleteKey(hkeyOurs, ::szINPROCSERVER32);
  109. ::RegCloseKey(hkeyOurs);
  110. if (err == ERROR_SUCCESS)
  111. err = ::RegDeleteKey(hkeyCLSID, ::szOurCLSID);
  112. }
  113. ::RegCloseKey(hkeyCLSID);
  114. }
  115. DeinstallLogonDialog();
  116. if (err == ERROR_SUCCESS)
  117. return S_OK;
  118. else
  119. return HRESULT_FROM_WIN32(err);
  120. }
  121. STDAPI DllInstall(BOOL fInstall, LPCSTR psz)
  122. {
  123. SignalStubNP(fInstall);
  124. return S_OK;
  125. }
  126. STDAPI DllCanUnloadNow(void)
  127. {
  128. SCODE sc;
  129. sc = (0 == g_cRefThisDll && 0 == g_cLocks) ? S_OK : S_FALSE;
  130. return ResultFromScode(sc);
  131. }
  132. STDAPI DllGetClassObject(
  133. REFCLSID rclsid,
  134. REFIID riid,
  135. LPVOID FAR *ppv)
  136. {
  137. if (!IsEqualCLSID(rclsid, CLSID_LocalUsers)) {
  138. return ResultFromScode(E_FAIL);
  139. }
  140. if (!IsEqualIID(riid, IID_IUnknown) &&
  141. !IsEqualIID(riid, IID_IClassFactory)) {
  142. return ResultFromScode(E_NOINTERFACE);
  143. }
  144. static CLUClassFactory cf;
  145. *ppv = (LPVOID)&cf;
  146. cf.AddRef();
  147. return NOERROR;
  148. }
  149. }; /* extern "C" */