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.

626 lines
14 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cgroup.cxx
  7. //
  8. // Contents: Group object
  9. //
  10. // History: Jan-29-1996 t-ptam(PatrickT) Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "NWCOMPAT.hxx"
  14. #pragma hdrstop
  15. //
  16. // Class CNWCOMPATGroup
  17. //
  18. DEFINE_IDispatch_ExtMgr_Implementation(CNWCOMPATGroup)
  19. DEFINE_IADs_TempImplementation(CNWCOMPATGroup)
  20. DEFINE_IADs_PutGetImplementation(CNWCOMPATGroup, GroupClass, gdwGroupTableSize)
  21. DEFINE_IADsPropertyList_Implementation(CNWCOMPATGroup, GroupClass, gdwGroupTableSize)
  22. //----------------------------------------------------------------------------
  23. //
  24. // Function: CNWCOMPATGroup::CNWCOMPATGroup
  25. //
  26. // Synopsis:
  27. //
  28. //----------------------------------------------------------------------------
  29. CNWCOMPATGroup::CNWCOMPATGroup():
  30. _pDispMgr(NULL),
  31. _pExtMgr(NULL),
  32. _pPropertyCache(NULL),
  33. _ParentType(0),
  34. _ServerName(NULL)
  35. {
  36. ENLIST_TRACKING(CNWCOMPATGroup);
  37. }
  38. //----------------------------------------------------------------------------
  39. //
  40. // Function: CNWCOMPATGroup::CreateGroup
  41. //
  42. // Synopsis:
  43. //
  44. //----------------------------------------------------------------------------
  45. HRESULT
  46. CNWCOMPATGroup::CreateGroup(
  47. BSTR Parent,
  48. ULONG ParentType,
  49. BSTR ServerName,
  50. BSTR GroupName,
  51. DWORD dwObjectState,
  52. REFIID riid,
  53. void **ppvObj
  54. )
  55. {
  56. CNWCOMPATGroup FAR * pGroup = NULL;
  57. HRESULT hr = S_OK;
  58. //
  59. // Allocate memory for a Group object.
  60. //
  61. hr = AllocateGroupObject(&pGroup);
  62. BAIL_ON_FAILURE(hr);
  63. //
  64. // Initialize group's core object.
  65. //
  66. hr = pGroup->InitializeCoreObject(
  67. Parent,
  68. GroupName,
  69. GROUP_CLASS_NAME,
  70. GROUP_SCHEMA_NAME,
  71. CLSID_NWCOMPATGroup,
  72. dwObjectState
  73. );
  74. BAIL_ON_FAILURE(hr);
  75. //
  76. // Save protected values.
  77. //
  78. hr = ADsAllocString( ServerName , &pGroup->_ServerName);
  79. BAIL_ON_FAILURE(hr);
  80. //
  81. // QueryInterface.
  82. //
  83. hr = pGroup->QueryInterface(riid, ppvObj);
  84. BAIL_ON_FAILURE(hr);
  85. pGroup->Release();
  86. hr = pGroup->_pExtMgr->FinalInitializeExtensions();
  87. BAIL_ON_FAILURE(hr);
  88. //
  89. // Return.
  90. //
  91. RRETURN(hr);
  92. error:
  93. delete pGroup;
  94. RRETURN_EXP_IF_ERR(hr);
  95. }
  96. //----------------------------------------------------------------------------
  97. //
  98. // Function: CNWCOMPATGroup::~CNWCOMPATGroup
  99. //
  100. // Synopsis:
  101. //
  102. //----------------------------------------------------------------------------
  103. CNWCOMPATGroup::~CNWCOMPATGroup( )
  104. {
  105. ADsFreeString(_ServerName);
  106. delete _pExtMgr; // created last, destroyed first
  107. delete _pDispMgr;
  108. delete _pPropertyCache;
  109. }
  110. //----------------------------------------------------------------------------
  111. //
  112. // Function: CNWCOMPATGroup::QueryInterface
  113. //
  114. // Synopsis:
  115. //
  116. //----------------------------------------------------------------------------
  117. STDMETHODIMP
  118. CNWCOMPATGroup::QueryInterface(
  119. REFIID iid,
  120. LPVOID FAR* ppv
  121. )
  122. {
  123. if (ppv == NULL) {
  124. RRETURN(E_POINTER);
  125. }
  126. if (IsEqualIID(iid, IID_IUnknown))
  127. {
  128. *ppv = (IADsGroup FAR *) this;
  129. }
  130. else if (IsEqualIID(iid, IID_IADsGroup))
  131. {
  132. *ppv = (IADsGroup FAR *) this;
  133. }
  134. else if (IsEqualIID(iid, IID_IADs))
  135. {
  136. *ppv = (IADsGroup FAR *) this;
  137. }
  138. else if (IsEqualIID(iid, IID_IDispatch))
  139. {
  140. *ppv = (IADsGroup FAR *) this;
  141. }
  142. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  143. {
  144. *ppv = (ISupportErrorInfo FAR *) this;
  145. }
  146. else if (IsEqualIID(iid, IID_IADsPropertyList))
  147. {
  148. *ppv = (IADsPropertyList FAR *) this;
  149. }
  150. else if (_pExtMgr)
  151. {
  152. RRETURN( _pExtMgr->QueryInterface(iid, ppv));
  153. }
  154. else
  155. {
  156. *ppv = NULL;
  157. return E_NOINTERFACE;
  158. }
  159. AddRef();
  160. return NOERROR;
  161. }
  162. /* ISupportErrorInfo method */
  163. STDMETHODIMP
  164. CNWCOMPATGroup::InterfaceSupportsErrorInfo(
  165. THIS_ REFIID riid
  166. )
  167. {
  168. if (IsEqualIID(riid, IID_IADs) ||
  169. IsEqualIID(riid, IID_IADsGroup) ||
  170. IsEqualIID(riid, IID_IADsPropertyList)) {
  171. RRETURN(S_OK);
  172. } else {
  173. RRETURN(S_FALSE);
  174. }
  175. }
  176. /* IADs methods */
  177. //----------------------------------------------------------------------------
  178. //
  179. // Function: CNWCOMPATGroup::SetInfo
  180. //
  181. // Synopsis:
  182. //
  183. //----------------------------------------------------------------------------
  184. STDMETHODIMP
  185. CNWCOMPATGroup::SetInfo(THIS)
  186. {
  187. HRESULT hr = S_OK;
  188. POBJECTINFO pObjectInfo = NULL;
  189. //
  190. // Bind an object to a real life resource if it is not bounded already.
  191. //
  192. if (GetObjectState() == ADS_OBJECT_UNBOUND) {
  193. hr = BuildObjectInfo(
  194. _Parent,
  195. _Name,
  196. &pObjectInfo
  197. );
  198. BAIL_ON_FAILURE(hr);
  199. hr = NWApiCreateGroup(
  200. pObjectInfo
  201. );
  202. BAIL_ON_FAILURE(hr);
  203. SetObjectState(ADS_OBJECT_BOUND);
  204. }
  205. //
  206. // Persist changes.
  207. //
  208. hr = SetInfo(GROUP_WILD_CARD_ID);
  209. BAIL_ON_FAILURE(hr);
  210. error:
  211. if (pObjectInfo) {
  212. FreeObjectInfo(pObjectInfo);
  213. }
  214. RRETURN_EXP_IF_ERR(hr);
  215. }
  216. //----------------------------------------------------------------------------
  217. //
  218. // Function: CNWCOMPATGroup::GetInfo
  219. //
  220. // Synopsis:
  221. //
  222. //----------------------------------------------------------------------------
  223. STDMETHODIMP
  224. CNWCOMPATGroup::GetInfo(THIS)
  225. {
  226. HRESULT hr = S_OK;
  227. _pPropertyCache->flushpropcache();
  228. hr = GetInfo(
  229. TRUE,
  230. GROUP_WILD_CARD_ID
  231. );
  232. RRETURN_EXP_IF_ERR(hr);
  233. }
  234. /* IADsGroup methods */
  235. //----------------------------------------------------------------------------
  236. //
  237. // Function: CNWCOMPATGroup::AllocateGroupObject
  238. //
  239. // Synopsis:
  240. //
  241. //----------------------------------------------------------------------------
  242. HRESULT
  243. CNWCOMPATGroup::AllocateGroupObject(
  244. CNWCOMPATGroup ** ppGroup
  245. )
  246. {
  247. CNWCOMPATGroup FAR * pGroup = NULL;
  248. CNWCOMPATGroupGenInfo FAR * pGenInfo = NULL;
  249. CAggregatorDispMgr FAR * pDispMgr = NULL;
  250. CADsExtMgr FAR * pExtensionMgr = NULL;
  251. CPropertyCache FAR * pPropertyCache = NULL;
  252. HRESULT hr = S_OK;
  253. pGroup = new CNWCOMPATGroup();
  254. if (pGroup == NULL) {
  255. hr = E_OUTOFMEMORY;
  256. }
  257. BAIL_ON_FAILURE(hr);
  258. //
  259. // Create dispatch manager.
  260. //
  261. pDispMgr = new CAggregatorDispMgr;
  262. if (pDispMgr == NULL) {
  263. hr = E_OUTOFMEMORY;
  264. }
  265. BAIL_ON_FAILURE(hr);
  266. //
  267. // Load type info.
  268. //
  269. hr = LoadTypeInfoEntry(
  270. pDispMgr,
  271. LIBID_ADs,
  272. IID_IADsGroup,
  273. (IADsGroup *)pGroup,
  274. DISPID_REGULAR
  275. );
  276. BAIL_ON_FAILURE(hr);
  277. hr = LoadTypeInfoEntry(
  278. pDispMgr,
  279. LIBID_ADs,
  280. IID_IADsPropertyList,
  281. (IADsPropertyList *)pGroup,
  282. DISPID_VALUE
  283. );
  284. BAIL_ON_FAILURE(hr);
  285. hr = CPropertyCache::createpropertycache(
  286. GroupClass,
  287. gdwGroupTableSize,
  288. (CCoreADsObject *)pGroup,
  289. &pPropertyCache
  290. );
  291. BAIL_ON_FAILURE(hr);
  292. pDispMgr->RegisterPropertyCache(
  293. pPropertyCache
  294. );
  295. hr = ADSILoadExtensionManager(
  296. GROUP_CLASS_NAME,
  297. (IADs *)pGroup,
  298. pDispMgr,
  299. &pExtensionMgr
  300. );
  301. BAIL_ON_FAILURE(hr);
  302. pGroup->_pPropertyCache = pPropertyCache;
  303. pGroup->_pExtMgr = pExtensionMgr;
  304. pGroup->_pDispMgr = pDispMgr;
  305. pGroup->_pGenInfo = pGenInfo;
  306. *ppGroup = pGroup;
  307. RRETURN(hr);
  308. error:
  309. delete pDispMgr;
  310. delete pExtensionMgr;
  311. delete pPropertyCache;
  312. delete pGroup;
  313. RRETURN(hr);
  314. }
  315. //----------------------------------------------------------------------------
  316. //
  317. // Function: CNWCOMPATGroup::SetInfo
  318. //
  319. // Synopsis:
  320. //
  321. //----------------------------------------------------------------------------
  322. STDMETHODIMP
  323. CNWCOMPATGroup::SetInfo(THIS_ DWORD dwPropertyID)
  324. {
  325. HRESULT hr = S_OK;
  326. HRESULT hrTemp = S_OK;
  327. NWCONN_HANDLE hConn = NULL;
  328. //
  329. // Get a handle to the bindery this object resides on.
  330. //
  331. hr = NWApiGetBinderyHandle(
  332. &hConn,
  333. _ServerName
  334. );
  335. BAIL_ON_FAILURE(hr);
  336. //
  337. // Persist changes in cache.
  338. //
  339. hr = SetDescription(hConn);
  340. BAIL_ON_FAILURE(hr);
  341. error:
  342. //
  343. // Release handle.
  344. //
  345. if (hConn) {
  346. hrTemp = NWApiReleaseBinderyHandle(hConn);
  347. }
  348. RRETURN_EXP_IF_ERR(hr);
  349. }
  350. //----------------------------------------------------------------------------
  351. //
  352. // Function: CNWCOMPATGroup::SetDescription
  353. //
  354. // Synopsis:
  355. //
  356. //----------------------------------------------------------------------------
  357. HRESULT
  358. CNWCOMPATGroup::SetDescription(
  359. NWCONN_HANDLE hConn
  360. )
  361. {
  362. LPWSTR pszDescription = NULL;
  363. WCHAR szwData[MAX_FULLNAME_LEN +1];
  364. CHAR szData[(MAX_FULLNAME_LEN + 1)*2];
  365. HRESULT hr = S_OK;
  366. memset(szwData, 0, sizeof(WCHAR)*(MAX_FULLNAME_LEN +1));
  367. hr = GetLPTSTRPropertyFromCache(
  368. _pPropertyCache,
  369. TEXT("Description"),
  370. &pszDescription
  371. );
  372. if (SUCCEEDED(hr)) {
  373. //
  374. // Convert bstr in ANSI string.
  375. //
  376. wcsncpy(szwData, pszDescription, MAX_FULLNAME_LEN);
  377. UnicodeToAnsiString(
  378. szwData,
  379. szData,
  380. 0
  381. );
  382. //
  383. // Commit change.
  384. //
  385. hr = NWApiWriteProperty(
  386. hConn,
  387. _Name,
  388. OT_USER_GROUP,
  389. NW_PROP_IDENTIFICATION,
  390. (LPBYTE) szData
  391. );
  392. BAIL_ON_FAILURE(hr);
  393. }
  394. //
  395. // Not is modified, that's ok.
  396. // reset hr to S_OK
  397. hr = S_OK;
  398. error:
  399. if (pszDescription ) {
  400. FreeADsStr(pszDescription);
  401. }
  402. RRETURN_EXP_IF_ERR(hr);
  403. }
  404. //----------------------------------------------------------------------------
  405. //
  406. // Function: CNWCOMPATGroup::GetInfo
  407. //
  408. // Synopsis:
  409. //
  410. //----------------------------------------------------------------------------
  411. STDMETHODIMP
  412. CNWCOMPATGroup::GetInfo(
  413. BOOL fExplicit,
  414. DWORD dwPropertyID
  415. )
  416. {
  417. HRESULT hr = S_OK;
  418. HRESULT hrTemp = S_OK;
  419. NWCONN_HANDLE hConn = NULL;
  420. if (GetObjectState() == ADS_OBJECT_UNBOUND) {
  421. RRETURN_EXP_IF_ERR(E_ADS_OBJECT_UNBOUND);
  422. }
  423. //
  424. // Get a handle to the bindery this computer object represents.
  425. //
  426. hr = NWApiGetBinderyHandle(
  427. &hConn,
  428. _ServerName
  429. );
  430. BAIL_ON_FAILURE(hr);
  431. //
  432. // Get property.
  433. //
  434. hr = GetProperty_Description(hConn, fExplicit);
  435. BAIL_ON_FAILURE(hr);
  436. error:
  437. if (hConn) {
  438. hrTemp = NWApiReleaseBinderyHandle(hConn);
  439. }
  440. RRETURN_EXP_IF_ERR(hr);
  441. }
  442. //----------------------------------------------------------------------------
  443. //
  444. // Function: CNWCOMPATGroup::GetProperty_Description
  445. //
  446. // Synopsis:
  447. //
  448. //----------------------------------------------------------------------------
  449. HRESULT
  450. CNWCOMPATGroup::GetProperty_Description(
  451. NWCONN_HANDLE hConn,
  452. BOOL fExplicit
  453. )
  454. {
  455. LPWSTR lpszFullName = NULL;
  456. CHAR szFullName[MAX_FULLNAME_LEN + 1];
  457. DWORD dwNumSegment = 0;
  458. HRESULT hr = S_OK;
  459. LP_RPLY_SGMT_LST lpReplySegment = NULL;
  460. LP_RPLY_SGMT_LST lpTemp = NULL; // Used by DELETE_LIST macro below
  461. //
  462. // Get IDENTIFICATIOIN. This property contains the full name of an object.
  463. // It is often used in place of "Description".
  464. //
  465. hr = NWApiGetProperty(
  466. _Name,
  467. NW_PROP_IDENTIFICATION,
  468. OT_USER_GROUP,
  469. hConn,
  470. &lpReplySegment,
  471. &dwNumSegment
  472. );
  473. if (SUCCEEDED(hr)) {
  474. //
  475. // Convert result into a UNICODE string.
  476. //
  477. strcpy(szFullName, lpReplySegment->Segment);
  478. lpszFullName = (LPWSTR) AllocADsMem(
  479. (strlen(szFullName) + 1) * sizeof(WCHAR)
  480. );
  481. if (!lpszFullName)
  482. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  483. AnsiToUnicodeString(
  484. szFullName,
  485. lpszFullName,
  486. 0
  487. );
  488. //
  489. // Unmarshall.
  490. //
  491. hr = SetLPTSTRPropertyInCache(
  492. _pPropertyCache,
  493. TEXT("Description"),
  494. lpszFullName,
  495. fExplicit
  496. );
  497. BAIL_ON_FAILURE(hr);
  498. }
  499. //
  500. // Couldn't retrieve the property from the server. Not
  501. // a problem, we just ignore it.
  502. //
  503. hr = S_OK;
  504. error:
  505. if (lpszFullName) {
  506. FreeADsMem(lpszFullName);
  507. }
  508. if (lpReplySegment) {
  509. DELETE_LIST(lpReplySegment);
  510. }
  511. RRETURN(hr);
  512. }