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.

180 lines
3.1 KiB

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