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.

138 lines
5.0 KiB

  1. // ServMigr.h : Declaration of the CServMigr
  2. #ifndef __SERVMIGR_H_
  3. #define __SERVMIGR_H_
  4. #include "resource.h" // main symbols
  5. #include "TNode.hpp"
  6. #include "EaLen.hpp"
  7. #include "UString.hpp"
  8. #include "ExtSeq.h"
  9. #include <wincrypt.h>
  10. #include "crypt.hxx"
  11. #define LEN_Service 200
  12. //#import "\bin\DBManager.tlb" no_namespace, named_guids
  13. #import "DBMgr.tlb" no_namespace, named_guids
  14. #include "CommaLog.hpp"
  15. class TEntryNode : public TNode
  16. {
  17. WCHAR computer[LEN_Computer];
  18. WCHAR service[LEN_Service];
  19. WCHAR account[LEN_Account];
  20. CSecureString cryptpassword;
  21. public:
  22. TEntryNode(WCHAR const * c,WCHAR const * s,WCHAR const * a,WCHAR const* p)
  23. {
  24. safecopy(computer,c);
  25. safecopy(service,s);
  26. safecopy(account,a);
  27. cryptpassword = (p ? p: L""); // can throw exception
  28. }
  29. WCHAR const * GetComputer() { return computer; }
  30. WCHAR const * GetService() { return service; }
  31. WCHAR const * GetAccount() { return account; }
  32. WCHAR const * GetPassword() // can throw exception
  33. {
  34. WCHAR* p;
  35. if (!cryptpassword.GetString(&p))
  36. {
  37. _com_issue_error(SEC_E_DECRYPT_FAILURE);
  38. }
  39. return p;
  40. }
  41. void const ReleasePassword() { cryptpassword.ReleaseString(); }
  42. void SetPassword(WCHAR const* p) { cryptpassword = (p ? p: L""); } // can throw exception
  43. };
  44. class TEntryList : public TNodeList
  45. {
  46. WCHAR file[LEN_Path];
  47. public:
  48. TEntryList(WCHAR const * filename) { safecopy(file,filename); LoadFromFile(file); }
  49. DWORD LoadFromFile(WCHAR const * filename);
  50. DWORD SaveToFile(WCHAR const * filename);
  51. ~TEntryList() { SaveToFile(file); DeleteAllListItems(TEntryNode); }
  52. private:
  53. HCRYPTPROV AcquireContext(bool bContainerMustExist);
  54. };
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CServMigr
  57. class ATL_NO_VTABLE CServMigr :
  58. public CComObjectRootEx<CComSingleThreadModel>,
  59. public CComCoClass<CServMigr, &CLSID_ServMigr>,
  60. public IDispatchImpl<IExtendAccountMigration, &IID_IExtendAccountMigration, &LIBID_SCMMIGRLib>,
  61. public ISvcMgr
  62. {
  63. TEntryList m_List;
  64. IIManageDBPtr m_pDB;
  65. BOOL m_bFatal;
  66. CPasswordLog m_passwordLog; //Password file
  67. bool m_bTriedToOpenFile;
  68. long m_Sequence;
  69. _bstr_t m_strSourceDomain;
  70. _bstr_t m_strSourceDomainFlat;
  71. _bstr_t m_strTargetDomain;
  72. _bstr_t m_strTargetDomainFlat;
  73. _bstr_t m_strSourceSam;
  74. _bstr_t m_strTargetSam;
  75. public:
  76. CServMigr() : m_List(L"SCMData.txt")
  77. {
  78. HRESULT hr = m_pDB.CreateInstance(CLSID_IManageDB);
  79. if ( FAILED(hr) )
  80. {
  81. m_bFatal = TRUE;
  82. }
  83. else
  84. {
  85. m_bFatal = FALSE;
  86. }
  87. m_bTriedToOpenFile = FALSE;
  88. m_Sequence = AREXT_DEFAULT_SEQUENCE_NUMBER;
  89. }
  90. DECLARE_REGISTRY_RESOURCEID(IDR_SvcMgr)
  91. DECLARE_PROTECT_FINAL_CONSTRUCT()
  92. BEGIN_COM_MAP(CServMigr)
  93. COM_INTERFACE_ENTRY(IExtendAccountMigration)
  94. COM_INTERFACE_ENTRY(ISvcMgr)
  95. COM_INTERFACE_ENTRY(IDispatch)
  96. END_COM_MAP()
  97. // IExtendAccountMigration
  98. public:
  99. STDMETHOD(ProcessUndo)(/*[in]*/ IUnknown * pSource, /*[in]*/ IUnknown * pTarget, /*[in]*/ IUnknown * pMainSettings, /*[in, out]*/ IUnknown ** pPropToSet, /*[in,out]*/ EAMAccountStats* pStats);
  100. STDMETHOD(PreProcessObject)(/*[in]*/ IUnknown * pSource, /*[in]*/ IUnknown * pTarget, /*[in]*/ IUnknown * pMainSettings, /*[in,out]*/ IUnknown ** ppPropsToSet, /*[in,out]*/ EAMAccountStats* pStats);
  101. STDMETHOD(ProcessObject)(/*[in]*/ IUnknown * pSource, /*[in]*/ IUnknown * pTarget, /*[in]*/ IUnknown * pMainSettings, /*[in,out]*/ IUnknown ** ppPropsToSet, /*[in,out]*/ EAMAccountStats* pStats);
  102. STDMETHOD(get_sDesc)(/*[out, retval]*/ BSTR *pVal);
  103. STDMETHOD(put_sDesc)(/*[in]*/ BSTR newVal);
  104. STDMETHOD(get_sName)(/*[out, retval]*/ BSTR *pVal);
  105. STDMETHOD(put_sName)(/*[in]*/ BSTR newVal);
  106. STDMETHOD(get_SequenceNumber)(/*[out, retval]*/ LONG * value) { (*value) = m_Sequence; return S_OK; }
  107. protected:
  108. // Helper functions
  109. BOOL UpdateSCMs(IUnknown * pVarSet,WCHAR const * account, WCHAR const * password,WCHAR const * strSid,IIManageDB * pDB, EAMAccountStats* pStats);
  110. HRESULT SaveEncryptedPassword(WCHAR const * server,WCHAR const * service,WCHAR const * account,WCHAR const * password);
  111. DWORD DoUpdate(WCHAR const * acount,WCHAR const * password,WCHAR const * strSid,WCHAR const * computer,WCHAR const * service,BOOL bNeedToGrantLOS, EAMAccountStats* pStats);
  112. BOOL GetDirectory(WCHAR* filename);
  113. BOOL RetrieveOriginalAccount(_bstr_t &sSrcDom, _bstr_t &sSrcSAM);
  114. _bstr_t GetUPNName(_bstr_t sSrcSAM);
  115. // ISvcMgr
  116. public:
  117. STDMETHOD(TryUpdateSam)(BSTR computer,BSTR service,BSTR account);
  118. STDMETHOD(TryUpdateSamWithPassword)(BSTR computer,BSTR service,BSTR account,BSTR password);
  119. };
  120. #endif //__SERVMIGR_H_