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.

200 lines
4.2 KiB

  1. #include "main.hxx"
  2. #include "main.hxx"
  3. void main()
  4. {
  5. IADsContainer *pGlobalContainer;
  6. IADsContainer *pSchemaContainer;
  7. IDispatch *pNewObject;
  8. IADsUser *pUser;
  9. IADs *pGlobal;
  10. IADs *pSchema;
  11. IDispatch *pDispatchNewClass;
  12. IADs *pNewClass;
  13. HRESULT hr;
  14. CoInitialize(NULL);
  15. //
  16. // Bind to the known container.
  17. //
  18. hr = ADsGetObject(TEXT("LDAP://RootDSE"),
  19. #ifdef USE_CONTAINER
  20. IID_IADsContainer, // <--- This is presumptious, non?
  21. (void**)&pGlobalContainer);
  22. #else
  23. IID_IADs,
  24. (void**)&pGlobal);
  25. #endif
  26. if (FAILED(hr)) {
  27. printf("GetObject failed, hr = %X\n", hr);
  28. return;
  29. } else {
  30. printf("Get Object Succeeded\n");
  31. }
  32. //
  33. // Get IADs Interface From Container
  34. //
  35. #ifdef USE_CONTAINER
  36. hr = pGlobalContainer->QueryInterface(IID_IADs, (void**)&pGlobal);
  37. if (FAILED(hr)) {
  38. printf("QI failed, hr = %X\n", hr);
  39. return;
  40. }
  41. #else
  42. // the preceding code was unnecessary since every ADs obj must
  43. // implement the IADS interface.
  44. #endif
  45. VARIANT varSchemaPath;
  46. hr = pGlobal->Get(L"schemaNamingContext", &varSchemaPath);
  47. if (FAILED(hr)) {
  48. printf("Get Schema Path failed, hr = %X\n", hr);
  49. return;
  50. }
  51. WCHAR pszSchemaPath[500];
  52. wcscpy(pszSchemaPath, L"LDAP://");
  53. wcscat(pszSchemaPath, varSchemaPath.bstrVal);
  54. hr = ADsGetObject(pszSchemaPath,
  55. IID_IADsContainer,
  56. (void**)&pSchemaContainer);
  57. if (FAILED(hr)) {
  58. printf("Get Schema Object failed, hr = %X\n", hr);
  59. return;
  60. }
  61. hr = pSchemaContainer->Create(L"classSchema", L"cn=IISServiceLocation", &pDispatchNewClass);
  62. if (FAILED(hr)) {
  63. printf("Create new class failed, hr = %X\n", hr);
  64. return;
  65. }
  66. //
  67. // Get IADs Interface From Container
  68. //
  69. hr = pDispatchNewClass->QueryInterface(IID_IADs, (void**)&pNewClass);
  70. if (FAILED(hr)) {
  71. printf("QI NewClass failed, hr = %X\n", hr);
  72. return;
  73. }
  74. VARIANT varValue;
  75. VariantInit(&varValue);
  76. varValue.vt = VT_BSTR;
  77. varValue.bstrVal = SysAllocString(L"IISServiceLocation");
  78. hr = pNewClass->Put(L"cn", varValue);
  79. if (FAILED(hr)) {
  80. printf("Put failed, hr = %X\n", hr);
  81. }
  82. VariantInit(&varValue);
  83. varValue.vt = VT_BSTR;
  84. varValue.bstrVal = SysAllocString(L"1.2.840.113556.1.5.7000.1209348");
  85. hr = pNewClass->Put(L"governsId", varValue);
  86. if (FAILED(hr)) {
  87. printf("Put failed, hr = %X\n", hr);
  88. }
  89. VariantInit(&varValue);
  90. varValue.vt = VT_I4;
  91. varValue.lVal = 1;
  92. hr = pNewClass->Put(L"objectClassCategory", varValue);
  93. if (FAILED(hr)) {
  94. printf("Put failed, hr = %X\n", hr);
  95. }
  96. VariantInit(&varValue);
  97. varValue.vt = VT_BSTR;
  98. varValue.bstrVal = SysAllocString(L"serviceAdministrationPoint");
  99. hr = pNewClass->Put(L"subClassOf", varValue);
  100. if (FAILED(hr)) {
  101. printf("Put failed, hr = %X\n", hr);
  102. }
  103. /*
  104. hr = pNewClass.Put(L"mustContain",L"networkAddress");
  105. if (FAILED(hr)) {
  106. printf("Put failed, hr = %X\n", hr);
  107. }
  108. */
  109. VariantInit(&varValue);
  110. varValue.vt = VT_BSTR;
  111. varValue.bstrVal = SysAllocString(L"container");
  112. hr = pNewClass->Put(L"possSuperiors", varValue);
  113. if (FAILED(hr)) {
  114. printf("Put failed, hr = %X\n", hr);
  115. }
  116. hr = pNewClass->SetInfo();
  117. if (FAILED(hr)) {
  118. printf("SetInfo failed, hr = %X\n", hr);
  119. }
  120. /*
  121. //
  122. // Create the new wrapper.
  123. //
  124. hr = pContainer->Create(TEXT("user"),
  125. TEXT("Jane"),
  126. &pNewObject);
  127. if (FAILED(hr)) {
  128. printf("Create failed");
  129. return;
  130. }
  131. //
  132. // Get the IADsUser interface from the wrapper.
  133. //
  134. pNewObject->QueryInterface(IID_IADsUser, (void**)&pUser);
  135. //
  136. // Write it back to the DS.
  137. //
  138. hr = pUser->SetInfo();
  139. if (FAILED(hr)) {
  140. printf("SetInfo failed");
  141. return;
  142. }
  143. //
  144. // Set Janes password.
  145. //
  146. hr = pUser ->SetPassword(TEXT("Argus"));
  147. */
  148. CoUninitialize();
  149. }