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.

162 lines
2.8 KiB

  1. //----------------------------------------------------------------------
  2. //
  3. // Microsoft Active Directory 1.0 Sample Code
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996
  6. //
  7. // File: dump.cxx
  8. //
  9. // Contents: Functions for dumping the properties for an object.
  10. //
  11. //
  12. //----------------------------------------------------------------------
  13. #include "main.hxx"
  14. //
  15. // Given an ADsPath, bind to the object and call the DumpObject routine.
  16. //
  17. int
  18. DoDump(char *AnsiADsPath)
  19. {
  20. HRESULT hr = E_OUTOFMEMORY ;
  21. LPWSTR pszADsPath = NULL;
  22. IADs * pADs = NULL;
  23. //
  24. // Convert path to unicode and then bind to the object.
  25. //
  26. BAIL_ON_NULL(pszADsPath = AllocateUnicodeString(AnsiADsPath));
  27. hr = ADsGetObject(
  28. pszADsPath,
  29. IID_IADs,
  30. (void **)&pADs
  31. );
  32. if (FAILED(hr)) {
  33. printf("Failed to bind to object: %S\n", pszADsPath) ;
  34. }
  35. else {
  36. //
  37. // Dump the object
  38. //
  39. hr = DumpObject(pADs);
  40. if (FAILED(hr)) {
  41. printf("Unable to read properties of: %S\n", pszADsPath) ;
  42. }
  43. pADs->Release();
  44. }
  45. error:
  46. FreeUnicodeString(pszADsPath);
  47. return (FAILED(hr) ? 1 : 0) ;
  48. }
  49. //
  50. // Given an ADs pointer, dump the contents of the object
  51. //
  52. HRESULT
  53. DumpObject(
  54. IADs * pADs
  55. )
  56. {
  57. HRESULT hr;
  58. HRESULT hrSA;
  59. IADs * pADsProp = NULL;
  60. VARIANT var;
  61. ZeroMemory(&var,sizeof(var));
  62. VARIANT * pvarPropName = NULL;
  63. DWORD i = 0;
  64. VARIANT varProperty;
  65. IDispatch * pDispatch = NULL;
  66. //
  67. // Access the schema for the object
  68. //
  69. hr = GetPropertyList(
  70. pADs,
  71. &var);
  72. BAIL_ON_FAILURE(hr);
  73. //
  74. // List the Properties
  75. //
  76. hr = SafeArrayAccessData(var.parray, (void **) &pvarPropName);
  77. BAIL_ON_FAILURE(hr);
  78. for (i = 0; i < var.parray->rgsabound[0].cElements; i++){
  79. //
  80. // Get a property and print it out. The HRESULT is passed to
  81. // PrintProperty.
  82. //
  83. hr = pADs->Get(
  84. pvarPropName[i].bstrVal,
  85. &varProperty
  86. );
  87. PrintProperty(
  88. pvarPropName[i].bstrVal,
  89. hr,
  90. varProperty
  91. );
  92. }
  93. hr = SafeArrayUnaccessData(var.parray);
  94. error:
  95. // Don't destroy hr in case we're here from BAIL_ON_FAILURE
  96. if(var.parray) hrSA = SafeArrayDestroy(var.parray);
  97. return(hr);
  98. }
  99. HRESULT
  100. GetPropertyList(
  101. IADs * pADs,
  102. VARIANT * pvar )
  103. {
  104. HRESULT hr= S_OK;
  105. BSTR bstrSchemaPath = NULL;
  106. IADsClass * pADsClass = NULL;
  107. hr = pADs->get_Schema(&bstrSchemaPath);
  108. BAIL_ON_FAILURE(hr);
  109. hr = ADsGetObject(
  110. bstrSchemaPath,
  111. IID_IADsClass,
  112. (void **)&pADsClass);
  113. BAIL_ON_FAILURE(hr);
  114. //Put SafeArray of bstr's into input variant struct
  115. hr = pADsClass->get_MandatoryProperties(pvar);
  116. BAIL_ON_FAILURE(hr);
  117. error:
  118. if (bstrSchemaPath) {
  119. SysFreeString(bstrSchemaPath);
  120. }
  121. if (pADsClass) {
  122. pADsClass->Release();
  123. }
  124. return(hr);
  125. }