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.

118 lines
4.1 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. #define LEN_Service 200
  11. //#import "\bin\DBManager.tlb" no_namespace, named_guids
  12. #import "DBMgr.tlb" no_namespace, named_guids
  13. #include "CommaLog.hpp"
  14. class TEntryNode : public TNode
  15. {
  16. WCHAR computer[LEN_Computer];
  17. WCHAR service[LEN_Service];
  18. WCHAR account[LEN_Account];
  19. WCHAR password[LEN_Password];
  20. public:
  21. TEntryNode(WCHAR const * c,WCHAR const * s,WCHAR const * a,WCHAR const* p)
  22. {
  23. safecopy(computer,c);
  24. safecopy(service,s);
  25. safecopy(account,a);
  26. safecopy(password,p ? p: L"");
  27. }
  28. WCHAR const * GetComputer() { return computer; }
  29. WCHAR const * GetService() { return service; }
  30. WCHAR const * GetAccount() { return account; }
  31. WCHAR const * GetPassword() { return password; }
  32. void SetPassword(WCHAR const* p) { safecopy(password,p ? p: L""); }
  33. };
  34. class TEntryList : public TNodeList
  35. {
  36. WCHAR file[LEN_Path];
  37. public:
  38. TEntryList(WCHAR const * filename) { safecopy(file,filename); LoadFromFile(file); }
  39. DWORD LoadFromFile(WCHAR const * filename);
  40. DWORD SaveToFile(WCHAR const * filename);
  41. ~TEntryList() { SaveToFile(file); DeleteAllListItems(TEntryNode); }
  42. private:
  43. HCRYPTPROV AcquireContext(bool bContainerMustExist);
  44. };
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CServMigr
  47. class ATL_NO_VTABLE CServMigr :
  48. public CComObjectRootEx<CComSingleThreadModel>,
  49. public CComCoClass<CServMigr, &CLSID_ServMigr>,
  50. public IDispatchImpl<IExtendAccountMigration, &IID_IExtendAccountMigration, &LIBID_SCMMIGRLib>,
  51. public ISvcMgr
  52. {
  53. TEntryList m_List;
  54. IIManageDBPtr m_pDB;
  55. BOOL m_bFatal;
  56. CommaDelimitedLog m_passwordLog; //Password file
  57. bool m_bTriedToOpenFile;
  58. long m_Sequence;
  59. public:
  60. CServMigr() : m_List(L"SCMData.txt")
  61. {
  62. HRESULT hr = m_pDB.CreateInstance(CLSID_IManageDB);
  63. if ( FAILED(hr) )
  64. {
  65. m_bFatal = TRUE;
  66. }
  67. else
  68. {
  69. m_bFatal = FALSE;
  70. }
  71. m_bTriedToOpenFile = FALSE;
  72. m_Sequence = AREXT_DEFAULT_SEQUENCE_NUMBER;
  73. }
  74. DECLARE_REGISTRY_RESOURCEID(IDR_SvcMgr)
  75. DECLARE_PROTECT_FINAL_CONSTRUCT()
  76. BEGIN_COM_MAP(CServMigr)
  77. COM_INTERFACE_ENTRY(IExtendAccountMigration)
  78. COM_INTERFACE_ENTRY(ISvcMgr)
  79. COM_INTERFACE_ENTRY(IDispatch)
  80. END_COM_MAP()
  81. // IExtendAccountMigration
  82. public:
  83. STDMETHOD(ProcessUndo)(/*[in]*/ IUnknown * pSource, /*[in]*/ IUnknown * pTarget, /*[in]*/ IUnknown * pMainSettings, /*[in, out]*/ IUnknown ** pPropToSet);
  84. STDMETHOD(PreProcessObject)(/*[in]*/ IUnknown * pSource, /*[in]*/ IUnknown * pTarget, /*[in]*/ IUnknown * pMainSettings, /*[in,out]*/ IUnknown ** ppPropsToSet);
  85. STDMETHOD(ProcessObject)(/*[in]*/ IUnknown * pSource, /*[in]*/ IUnknown * pTarget, /*[in]*/ IUnknown * pMainSettings, /*[in,out]*/ IUnknown ** ppPropsToSet);
  86. STDMETHOD(get_sDesc)(/*[out, retval]*/ BSTR *pVal);
  87. STDMETHOD(put_sDesc)(/*[in]*/ BSTR newVal);
  88. STDMETHOD(get_sName)(/*[out, retval]*/ BSTR *pVal);
  89. STDMETHOD(put_sName)(/*[in]*/ BSTR newVal);
  90. STDMETHOD(get_SequenceNumber)(/*[out, retval]*/ LONG * value) { (*value) = m_Sequence; return S_OK; }
  91. protected:
  92. // Helper functions
  93. BOOL UpdateSCMs(IUnknown * pVarSet,WCHAR const * account, WCHAR const * password,WCHAR const * strSid,IIManageDB * pDB);
  94. HRESULT SaveEncryptedPassword(WCHAR const * server,WCHAR const * service,WCHAR const * account,WCHAR const * password);
  95. DWORD DoUpdate(WCHAR const * acount,WCHAR const * password,WCHAR const * strSid,WCHAR const * computer,WCHAR const * service,BOOL bNeedToGrantLOS);
  96. BOOL GetDirectory(WCHAR* filename);
  97. // ISvcMgr
  98. public:
  99. STDMETHOD(TryUpdateSam)(BSTR computer,BSTR service,BSTR account);
  100. STDMETHOD(TryUpdateSamWithPassword)(BSTR computer,BSTR service,BSTR account,BSTR password);
  101. };
  102. #endif //__SERVMIGR_H_