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.

321 lines
6.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: copyobj.h
  8. //
  9. //--------------------------------------------------------------------------
  10. /////////////////////////////////////////////////////////////////////
  11. // copyobj.h
  12. #ifndef __COPYOBJ_H_INCLUDED__
  13. #define __COPYOBJ_H_INCLUDED__
  14. /////////////////////////////////////////////////////////////////////
  15. // CCopyableAttributesHolder
  16. class CCopyableAttributesHolder
  17. {
  18. public:
  19. CCopyableAttributesHolder()
  20. {
  21. }
  22. ~CCopyableAttributesHolder()
  23. {
  24. }
  25. HRESULT LoadFromSchema(MyBasePathsInfo* pBasePathsInfo);
  26. BOOL CanCopy(LPCWSTR lpszAttributeName);
  27. private:
  28. BOOL _FindInNotCopyableHardwiredList(LPCWSTR lpszAttributeName);
  29. CStringList m_attributeNameList;
  30. };
  31. /////////////////////////////////////////////////////////////////////
  32. // CCopyObjectHandlerBase
  33. class CCopyObjectHandlerBase
  34. {
  35. public:
  36. CCopyObjectHandlerBase()
  37. {
  38. }
  39. virtual ~CCopyObjectHandlerBase()
  40. {
  41. }
  42. IADs* GetCopyFrom()
  43. {
  44. ASSERT(m_spIADsCopyFrom != NULL);
  45. return m_spIADsCopyFrom;
  46. }
  47. virtual HRESULT Init(MyBasePathsInfo*, IADs* pIADsCopyFrom)
  48. {
  49. m_spIADsCopyFrom = pIADsCopyFrom;
  50. return S_OK;
  51. }
  52. virtual HRESULT CopyAtCreation(IADs*)
  53. {
  54. return S_OK;
  55. }
  56. virtual HRESULT Copy(IADs*, BOOL, HWND, LPCWSTR)
  57. {
  58. return S_OK;
  59. }
  60. protected:
  61. CComPtr<IADs> m_spIADsCopyFrom;
  62. };
  63. /////////////////////////////////////////////////////////////////////
  64. // CGroupMembershipEntry
  65. class CGroupMembershipEntry
  66. {
  67. public:
  68. enum actionType { none, add, remove};
  69. CGroupMembershipEntry(DWORD dwObjectRID, LPCWSTR lpszDistinguishedName)
  70. {
  71. m_dwObjectRID = dwObjectRID;
  72. m_szDistinguishedName = lpszDistinguishedName;
  73. m_action = none;
  74. m_hr = S_OK;
  75. }
  76. ~CGroupMembershipEntry()
  77. {
  78. }
  79. LPCWSTR GetDN() { return m_szDistinguishedName; }
  80. DWORD GetRID() { return m_dwObjectRID; }
  81. BOOL IsPrimaryGroup() { return m_dwObjectRID != 0x0; }
  82. actionType GetActionType() { return m_action; }
  83. void MarkAdd() { m_action = add; }
  84. void MarkRemove() { m_action = remove; }
  85. #ifdef DBG
  86. LPCWSTR GetActionString()
  87. {
  88. if (m_action == none)
  89. return L"none";
  90. else if (m_action == add)
  91. return L"add";
  92. return L"remove";
  93. }
  94. #endif // DBG
  95. public:
  96. HRESULT m_hr;
  97. private:
  98. CString m_szDistinguishedName; // DN of the group
  99. DWORD m_dwObjectRID; // RID (valid only if it is the primary group)
  100. actionType m_action;
  101. };
  102. /////////////////////////////////////////////////////////////////////
  103. // CGroupMembershipEntryList
  104. class CGroupMembershipEntryList :
  105. public CList<CGroupMembershipEntry*, CGroupMembershipEntry*>
  106. {
  107. public:
  108. ~CGroupMembershipEntryList()
  109. {
  110. _RemoveAll();
  111. }
  112. CGroupMembershipEntry* FindByDN(LPCWSTR lpszDN)
  113. {
  114. for (POSITION pos = GetHeadPosition(); pos != NULL; )
  115. {
  116. CGroupMembershipEntry* pEntry = GetNext(pos);
  117. if (wcscmp(lpszDN, pEntry->GetDN()) == 0)
  118. {
  119. return pEntry;
  120. }
  121. }
  122. return NULL;
  123. }
  124. void Merge(CGroupMembershipEntryList* pList)
  125. {
  126. while(!pList->IsEmpty())
  127. AddTail(pList->RemoveHead());
  128. }
  129. #ifdef DBG
  130. void Trace(LPCWSTR lpszTitle)
  131. {
  132. TRACE(L"\n%s\n\n", lpszTitle);
  133. for (POSITION pos = GetHeadPosition(); pos != NULL; )
  134. {
  135. CGroupMembershipEntry* pEntry = GetNext(pos);
  136. TRACE(L"action = %s RID %d, DN = <%s> \n", pEntry->GetActionString(), pEntry->GetRID(), pEntry->GetDN());
  137. }
  138. TRACE(L"\n");
  139. }
  140. #endif // DBG
  141. private:
  142. void _RemoveAll()
  143. {
  144. while(!IsEmpty())
  145. delete RemoveHead();
  146. }
  147. };
  148. /////////////////////////////////////////////////////////////////////
  149. // CSid
  150. class CSid
  151. {
  152. public:
  153. CSid()
  154. {
  155. m_pSID = NULL;
  156. }
  157. ~CSid()
  158. {
  159. if (m_pSID != NULL)
  160. free(m_pSID);
  161. }
  162. HRESULT Init(IADs* pIADs);
  163. BOOL Init(size_t nByteLen, PSID pSID)
  164. {
  165. if ((nByteLen == 0) || (pSID == NULL))
  166. return FALSE;
  167. m_pSID = malloc(nByteLen);
  168. if (m_pSID == NULL)
  169. return FALSE;
  170. memcpy(m_pSID, pSID, nByteLen);
  171. return TRUE;
  172. }
  173. PSID GetSid() { return m_pSID;}
  174. private:
  175. PSID m_pSID;
  176. };
  177. /////////////////////////////////////////////////////////////////////
  178. // CGroupMembershipHolder
  179. class CGroupMembershipHolder
  180. {
  181. public:
  182. CGroupMembershipHolder()
  183. {
  184. m_bPrimaryGroupFound = FALSE;
  185. }
  186. ~CGroupMembershipHolder()
  187. {
  188. }
  189. HRESULT Read(IADs* pIADs);
  190. HRESULT CopyFrom(CGroupMembershipHolder* pSource);
  191. HRESULT Write();
  192. void ProcessFailures(HRESULT& hr, CString& szFailureString, BOOL* pPrimaryGroupFound);
  193. private:
  194. HRESULT _ReadPrimaryGroupInfo();
  195. HRESULT _ReadNonPrimaryGroupInfo();
  196. CComPtr<IADs> m_spIADs; // object ADSI pointer
  197. CSid m_objectSid; // object SID
  198. CString m_szDomainLDAPPath; // LDAP path of the domain the object is in
  199. CGroupMembershipEntryList m_entryList;
  200. BOOL m_bPrimaryGroupFound;
  201. };
  202. /////////////////////////////////////////////////////////////////////
  203. // CCopyUserHandler
  204. class CCopyUserHandler : public CCopyObjectHandlerBase
  205. {
  206. public:
  207. CCopyUserHandler()
  208. {
  209. m_bPasswordCannotChange = FALSE;
  210. m_bPasswordMustChange = FALSE;
  211. m_hrFailure = S_OK;
  212. m_bPrimaryGroupFound = FALSE;
  213. m_bNeedToCreateHomeDir = FALSE;
  214. }
  215. virtual HRESULT Init(MyBasePathsInfo* pBasePathsInfo, IADs* pIADsCopyFrom);
  216. virtual HRESULT CopyAtCreation(IADs* pIADsCopyTo)
  217. {
  218. return _CopyAttributes(pIADsCopyTo);
  219. }
  220. virtual HRESULT Copy(IADs* pIADsCopyTo, BOOL bPostCommit,
  221. HWND hWnd, LPCWSTR lpszObjectName);
  222. BOOL PasswordCannotChange()
  223. {
  224. return m_bPasswordCannotChange;
  225. }
  226. BOOL PasswordMustChange()
  227. {
  228. return m_bPasswordMustChange;
  229. }
  230. void _ShowGroupMembershipWarnings(HWND hWnd, LPCWSTR lpszObjectName);
  231. private:
  232. HRESULT _ReadPasswordCannotChange();
  233. HRESULT _ReadPasswordMustChange();
  234. HRESULT _CopyAttributes(IADs* pIADsCopyTo);
  235. HRESULT _CopyGroupMembership(IADs* pIADsCopyTo);
  236. HRESULT _UpdatePaths(IADs* pIADsCopyTo);
  237. HRESULT _CreateHomeDirectory(IADs* pIADsCopyTo, LPCWSTR lpszObjectName, HWND hWnd);
  238. CCopyableAttributesHolder m_copyableAttributesHolder;
  239. CGroupMembershipHolder m_sourceMembershipHolder;
  240. BOOL m_bPasswordCannotChange;
  241. BOOL m_bPasswordMustChange;
  242. HRESULT m_hrFailure;
  243. CString m_szFailureString;
  244. BOOL m_bPrimaryGroupFound;
  245. BOOL m_bNeedToCreateHomeDir;
  246. };
  247. #endif // __COPYOBJ_H_INCLUDED__