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.

182 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. bitssrvcfgimp.h
  5. Abstract:
  6. Implementation header to define server configuration information.
  7. --*/
  8. HRESULT PropertyIDManager::LoadPropertyInfo( const WCHAR * MachineName )
  9. {
  10. bool ComLoaded;
  11. HRESULT Hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
  12. if ( RPC_E_CHANGED_MODE == Hr )
  13. ComLoaded = false;
  14. else if ( FAILED(Hr) )
  15. return Hr;
  16. else
  17. ComLoaded = true;
  18. BSTR MetaIDBSTR = NULL;
  19. BSTR UserTypeBSTR = NULL;
  20. WCHAR *PathBuffer = NULL;
  21. SIZE_T PathBufferSize = 0;
  22. MetaIDBSTR = SysAllocString( L"MetaId" );
  23. UserTypeBSTR = SysAllocString( L"UserType" );
  24. if ( !MetaIDBSTR || !UserTypeBSTR)
  25. {
  26. Hr = E_OUTOFMEMORY;
  27. goto exit;
  28. }
  29. PathBuffer = (WCHAR*)HeapAlloc( GetProcessHeap(), 0, 1024 );
  30. if ( !PathBuffer )
  31. {
  32. Hr = E_OUTOFMEMORY;
  33. goto exit;
  34. }
  35. PathBufferSize = 1024;
  36. for ( SIZE_T i = 0; i < g_NumberOfProperties; i++ )
  37. {
  38. WCHAR SchemaPrefix[] = L"IIS://";
  39. WCHAR SchemaPath[] = L"/Schema/";
  40. SIZE_T SchemaPrefixSize = ( sizeof( SchemaPrefix ) / sizeof( WCHAR ) ) - 1;
  41. SIZE_T SchemaPathSize = ( sizeof( SchemaPath ) / sizeof( WCHAR ) ) - 1;
  42. SIZE_T MachineNameSize = wcslen( MachineName );
  43. SIZE_T PropertyNameSize = wcslen( g_Properties[i].PropertyName );
  44. SIZE_T PathSize = SchemaPrefixSize + SchemaPathSize +
  45. MachineNameSize + PropertyNameSize + 1;
  46. if ( PathBufferSize < ( PathSize * sizeof( WCHAR ) ) )
  47. {
  48. WCHAR *NewBuffer =
  49. (WCHAR*)HeapReAlloc(
  50. GetProcessHeap(),
  51. 0,
  52. PathBuffer,
  53. PathSize * sizeof( WCHAR ) );
  54. if ( !NewBuffer )
  55. {
  56. Hr = E_OUTOFMEMORY;
  57. goto exit;
  58. }
  59. PathBuffer = NewBuffer;
  60. PathBufferSize = PathSize * sizeof( WCHAR );
  61. }
  62. // build schema path
  63. WCHAR *ObjectPath = PathBuffer;
  64. {
  65. WCHAR *TempPointer = ObjectPath;
  66. memcpy( TempPointer, SchemaPrefix, SchemaPrefixSize * sizeof( WCHAR ) );
  67. TempPointer += SchemaPrefixSize;
  68. memcpy( TempPointer, MachineName, MachineNameSize * sizeof( WCHAR ) );
  69. TempPointer += MachineNameSize;
  70. memcpy( TempPointer, SchemaPath, SchemaPathSize * sizeof( WCHAR ) );
  71. TempPointer += SchemaPathSize;
  72. memcpy( TempPointer, g_Properties[i].PropertyName, ( PropertyNameSize + 1 ) * sizeof( WCHAR ) );
  73. }
  74. // Open the object
  75. IADs *MbObject = NULL;
  76. Hr = ADsGetObject(
  77. ObjectPath,
  78. __uuidof( *MbObject ),
  79. reinterpret_cast<void**>( &MbObject ) );
  80. if ( FAILED( Hr ) )
  81. goto exit;
  82. VARIANT var;
  83. VariantInit( &var );
  84. Hr = MbObject->Get( MetaIDBSTR, &var );
  85. if ( FAILED(Hr ) )
  86. {
  87. MbObject->Release();
  88. goto exit;
  89. }
  90. Hr = VariantChangeType( &var, &var, 0, VT_UI4 );
  91. if ( FAILED(Hr ) )
  92. {
  93. MbObject->Release();
  94. VariantClear( &var );
  95. goto exit;
  96. }
  97. m_PropertyIDs[i] = var.ulVal;
  98. VariantClear( &var );
  99. Hr = MbObject->Get( UserTypeBSTR, &var );
  100. if ( FAILED( Hr ) )
  101. {
  102. MbObject->Release();
  103. goto exit;
  104. }
  105. Hr = VariantChangeType( &var, &var, 0, VT_UI4 );
  106. if ( FAILED( Hr ) )
  107. {
  108. MbObject->Release();
  109. VariantClear( &var );
  110. goto exit;
  111. }
  112. m_PropertyUserTypes[i] = var.ulVal;
  113. VariantClear( &var );
  114. MbObject->Release();
  115. }
  116. Hr = S_OK;
  117. exit:
  118. SysFreeString( MetaIDBSTR );
  119. SysFreeString( UserTypeBSTR );
  120. if ( ComLoaded )
  121. CoUninitialize();
  122. if ( PathBuffer )
  123. {
  124. HeapFree( GetProcessHeap(), 0, PathBuffer );
  125. PathBuffer = 0;
  126. PathBufferSize = 0;
  127. }
  128. return Hr;
  129. }