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.

508 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. mapobj.cpp
  5. Abstract:
  6. Mapping object implementation.
  7. Author:
  8. Don Ryan (donryan) 04-Jan-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "llsmgr.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char BASED_CODE THIS_FILE[] = __FILE__;
  18. #endif
  19. IMPLEMENT_DYNCREATE(CMapping, CCmdTarget)
  20. BEGIN_MESSAGE_MAP(CMapping, CCmdTarget)
  21. //{{AFX_MSG_MAP(CMapping)
  22. // NOTE - the ClassWizard will add and remove mapping macros here.
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. BEGIN_DISPATCH_MAP(CMapping, CCmdTarget)
  26. //{{AFX_DISPATCH_MAP(CMapping)
  27. DISP_PROPERTY_EX(CMapping, "Application", GetApplication, SetNotSupported, VT_DISPATCH)
  28. DISP_PROPERTY_EX(CMapping, "Parent", GetParent, SetNotSupported, VT_DISPATCH)
  29. DISP_PROPERTY_EX(CMapping, "Description", GetDescription, SetNotSupported, VT_BSTR)
  30. DISP_PROPERTY_EX(CMapping, "InUse", GetInUse, SetNotSupported, VT_I4)
  31. DISP_PROPERTY_EX(CMapping, "Name", GetName, SetNotSupported, VT_BSTR)
  32. DISP_PROPERTY_PARAM(CMapping, "Users", GetUsers, SetNotSupported, VT_DISPATCH, VTS_VARIANT)
  33. DISP_DEFVALUE(CMapping, "Name")
  34. //}}AFX_DISPATCH_MAP
  35. END_DISPATCH_MAP()
  36. CMapping::CMapping(
  37. CCmdTarget* pParent,
  38. LPCTSTR pName,
  39. long lInUse,
  40. LPCTSTR pDecription
  41. )
  42. /*++
  43. Routine Description:
  44. Constructor for mapping object.
  45. Arguments:
  46. pParent - creator of object.
  47. pName - name of mapping.
  48. lInUse - number of licenses consumed by mapping.
  49. pDescription - user-defined message describing mapping.
  50. Return Values:
  51. None.
  52. --*/
  53. {
  54. EnableAutomation();
  55. #ifdef ENABLE_PARENT_CHECK
  56. ASSERT(pParent && pParent->IsKindOf(RUNTIME_CLASS(CController)));
  57. #endif // ENABLE_PARENT_CHECK
  58. m_pParent = pParent;
  59. ASSERT(pName && *pName);
  60. m_strName = pName;
  61. m_lInUse = lInUse;
  62. m_strDescription = pDecription;
  63. m_pUsers = NULL;
  64. m_userArray.RemoveAll();
  65. m_bUsersRefreshed = FALSE;
  66. }
  67. CMapping::~CMapping()
  68. /*++
  69. Routine Description:
  70. Destructor for mapping object.
  71. Arguments:
  72. None.
  73. Return Values:
  74. None.
  75. --*/
  76. {
  77. if (m_pUsers)
  78. m_pUsers->InternalRelease();
  79. }
  80. void CMapping::OnFinalRelease()
  81. /*++
  82. Routine Description:
  83. When the last reference for an automation object is released
  84. OnFinalRelease is called. This implementation deletes object.
  85. Arguments:
  86. None.
  87. Return Values:
  88. None.
  89. --*/
  90. {
  91. ResetUsers();
  92. delete this;
  93. }
  94. LPDISPATCH CMapping::GetApplication()
  95. /*++
  96. Routine Description:
  97. Returns the application object.
  98. Arguments:
  99. None.
  100. Return Values:
  101. VT_DISPATCH.
  102. --*/
  103. {
  104. return theApp.GetAppIDispatch();
  105. }
  106. BSTR CMapping::GetDescription()
  107. /*++
  108. Routine Description:
  109. Returns the user-defined message describing mapping.
  110. Arguments:
  111. None.
  112. Return Values:
  113. VT_BSTR.
  114. --*/
  115. {
  116. return m_strDescription.AllocSysString();
  117. }
  118. long CMapping::GetInUse()
  119. /*++
  120. Routine Description:
  121. Returns the number of licenses the mapping is consuming.
  122. Arguments:
  123. None.
  124. Return Values:
  125. VT_I4.
  126. --*/
  127. {
  128. return m_lInUse;
  129. }
  130. BSTR CMapping::GetName()
  131. /*++
  132. Routine Description:
  133. Returns the name of the mapping.
  134. Arguments:
  135. None.
  136. Return Values:
  137. VT_BSTR.
  138. --*/
  139. {
  140. return m_strName.AllocSysString();
  141. }
  142. LPDISPATCH CMapping::GetParent()
  143. /*++
  144. Routine Description:
  145. Returns the parent of the object.
  146. Arguments:
  147. None.
  148. Return Values:
  149. VT_DISPATCH.
  150. --*/
  151. {
  152. return m_pParent ? m_pParent->GetIDispatch(TRUE) : NULL;
  153. }
  154. LPDISPATCH CMapping::GetUsers(const VARIANT FAR& index)
  155. /*++
  156. Routine Description:
  157. Returns a collection object containing all of the
  158. registered users replicated to the license controller
  159. pertaining to the mapping or returns an individual user
  160. pertaining to the mapping described by an index into
  161. the collection.
  162. Arguments:
  163. index - optional argument that may be a string (VT_BSTR)
  164. indicating a user name or a number (VT_I4) indicating the
  165. position within collection.
  166. Return Values:
  167. VT_DISPATCH or VT_EMPTY.
  168. --*/
  169. {
  170. LPDISPATCH lpdispatch = NULL;
  171. if (!m_pUsers)
  172. {
  173. m_pUsers = new CUsers(this, &m_userArray);
  174. }
  175. if (m_pUsers)
  176. {
  177. if (V_ISVOID((VARIANT FAR*)&index))
  178. {
  179. if (RefreshUsers())
  180. {
  181. lpdispatch = m_pUsers->GetIDispatch(TRUE);
  182. }
  183. }
  184. else
  185. {
  186. if (m_bUsersRefreshed)
  187. {
  188. lpdispatch = m_pUsers->GetItem(index);
  189. }
  190. else if (RefreshUsers())
  191. {
  192. lpdispatch = m_pUsers->GetItem(index);
  193. }
  194. }
  195. }
  196. else
  197. {
  198. LlsSetLastStatus(STATUS_NO_MEMORY);
  199. }
  200. return lpdispatch;
  201. }
  202. BOOL CMapping::Refresh()
  203. /*++
  204. Routine Description:
  205. Refreshs a mapping object.
  206. Arguments:
  207. None.
  208. Return Values:
  209. VT_BOOL.
  210. --*/
  211. {
  212. NTSTATUS NtStatus;
  213. PLLS_GROUP_INFO_1 pMappingInfo1 = NULL;
  214. NtStatus = ::LlsGroupInfoGet(
  215. LlsGetActiveHandle(),
  216. MKSTR(m_strName),
  217. 1,
  218. (LPBYTE*)&pMappingInfo1
  219. );
  220. if (NT_SUCCESS(NtStatus))
  221. {
  222. if (RefreshUsers())
  223. {
  224. m_lInUse = pMappingInfo1->Licenses;
  225. m_strDescription = pMappingInfo1->Comment;
  226. }
  227. else
  228. {
  229. NtStatus = LlsGetLastStatus();
  230. }
  231. #ifndef DISABLE_PER_NODE_ALLOCATION
  232. ::LlsFreeMemory(pMappingInfo1->Name);
  233. ::LlsFreeMemory(pMappingInfo1->Comment);
  234. #endif // DISABLE_PER_NODE_ALLOCATION
  235. ::LlsFreeMemory(pMappingInfo1);
  236. }
  237. LlsSetLastStatus(NtStatus); // called api
  238. return NT_SUCCESS(NtStatus);
  239. }
  240. BOOL CMapping::RefreshUsers()
  241. /*++
  242. Routine Description:
  243. Refreshs user object list.
  244. Arguments:
  245. None.
  246. Return Values:
  247. None.
  248. --*/
  249. {
  250. ResetUsers();
  251. NTSTATUS NtStatus;
  252. DWORD ResumeHandle = 0L;
  253. int iUser = 0;
  254. do
  255. {
  256. DWORD EntriesRead;
  257. DWORD TotalEntries;
  258. LPBYTE ReturnBuffer = NULL;
  259. NtStatus = ::LlsGroupUserEnum(
  260. LlsGetActiveHandle(),
  261. MKSTR(m_strName),
  262. 0,
  263. &ReturnBuffer,
  264. LLS_PREFERRED_LENGTH,
  265. &EntriesRead,
  266. &TotalEntries,
  267. &ResumeHandle
  268. );
  269. if (NtStatus == STATUS_SUCCESS ||
  270. NtStatus == STATUS_MORE_ENTRIES)
  271. {
  272. CUser* pUser;
  273. PLLS_USER_INFO_0 pUserInfo0;
  274. pUserInfo0 = (PLLS_USER_INFO_0)ReturnBuffer;
  275. ASSERT(iUser == m_userArray.GetSize());
  276. m_userArray.SetSize(m_userArray.GetSize() + EntriesRead);
  277. while (EntriesRead--)
  278. {
  279. pUser = new CUser(this, pUserInfo0->Name);
  280. m_userArray.SetAt(iUser++, pUser); // validate later...
  281. #ifndef DISABLE_PER_NODE_ALLOCATION
  282. ::LlsFreeMemory(pUserInfo0->Name);
  283. #endif // DISABLE_PER_NODE_ALLOCATION
  284. pUserInfo0++;
  285. }
  286. ::LlsFreeMemory(ReturnBuffer);
  287. }
  288. } while (NtStatus == STATUS_MORE_ENTRIES);
  289. LlsSetLastStatus(NtStatus); // called api
  290. if (NT_SUCCESS(NtStatus))
  291. {
  292. m_bUsersRefreshed = TRUE;
  293. }
  294. else
  295. {
  296. ResetUsers();
  297. }
  298. return m_bUsersRefreshed;
  299. }
  300. void CMapping::ResetUsers()
  301. /*++
  302. Routine Description:
  303. Resets user object list.
  304. Arguments:
  305. None.
  306. Return Values:
  307. None.
  308. --*/
  309. {
  310. CUser* pUser;
  311. INT_PTR iUser = m_userArray.GetSize();
  312. while (iUser--)
  313. {
  314. pUser = (CUser*)m_userArray[iUser];
  315. if (NULL != pUser)
  316. {
  317. ASSERT(pUser->IsKindOf(RUNTIME_CLASS(CUser)));
  318. pUser->InternalRelease();
  319. }
  320. }
  321. m_userArray.RemoveAll();
  322. m_bUsersRefreshed = FALSE;
  323. }