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.

116 lines
2.3 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996
  5. //
  6. // File: defcont.cxx
  7. //
  8. // Contents: Active Directory Default Container
  9. //
  10. // History: 05-21-96 RamV created
  11. // 08-02-96 t-danal add to oledscmd
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "main.hxx"
  15. #include "macro.hxx"
  16. #include "sconv.hxx"
  17. //
  18. // Local functions
  19. //
  20. HRESULT
  21. SetDefaultContainer(LPWSTR pszValue);
  22. HRESULT
  23. PrintDefaultContainer(VOID);
  24. //
  25. // Misc worker functions
  26. //
  27. HRESULT
  28. SetDefaultContainer(
  29. LPWSTR pszValue
  30. )
  31. {
  32. HRESULT hr = E_FAIL;
  33. IADsNamespaces *pNamespaces = NULL;
  34. BSTR bstrValue = NULL;
  35. if (pszValue) {
  36. BAIL_ON_NULL(bstrValue = SysAllocString(pszValue));
  37. }
  38. else {
  39. bstrValue = NULL;
  40. }
  41. hr = ADsGetObject(L"@ADS!",
  42. IID_IADsNamespaces,
  43. (void **)&pNamespaces);
  44. BAIL_ON_FAILURE(hr);
  45. hr = pNamespaces->put_DefaultContainer(bstrValue);
  46. BAIL_ON_FAILURE(hr);
  47. hr = pNamespaces->SetInfo();
  48. error:
  49. FREE_INTERFACE(pNamespaces);
  50. FREE_BSTR(bstrValue);
  51. return hr;
  52. }
  53. HRESULT
  54. PrintDefaultContainer(
  55. )
  56. {
  57. HRESULT hr;
  58. IADsNamespaces *pNamespaces = NULL;
  59. BSTR bstrValue = NULL;
  60. hr = ADsGetObject(L"@ADS!",
  61. IID_IADsNamespaces,
  62. (void **)&pNamespaces);
  63. BAIL_ON_FAILURE(hr);
  64. hr = pNamespaces->get_DefaultContainer(&bstrValue);
  65. BAIL_ON_FAILURE(hr);
  66. printf("Default Container = %ws\n", bstrValue);
  67. error:
  68. FREE_INTERFACE(pNamespaces);
  69. FREE_BSTR(bstrValue);
  70. return hr;
  71. }
  72. //
  73. // Exec function
  74. //
  75. int
  76. ExecDefaultContainer(char *szProgName, char *szAction, int argc, char * argv[])
  77. {
  78. HRESULT hr;
  79. LPWSTR pszValue = NULL ;
  80. if (argc < 0 || argc > 1) {
  81. PrintUsage(szProgName, szAction, "[default container]");
  82. return(1);
  83. }
  84. if (argc == 1) {
  85. ALLOC_UNICODE_WITH_BAIL_ON_NULL(pszValue, argv[0]);
  86. hr = SetDefaultContainer(pszValue);
  87. } else {
  88. hr = PrintDefaultContainer();
  89. }
  90. error:
  91. FreeUnicodeString(pszValue);
  92. if (FAILED(hr))
  93. return(1);
  94. return(0);
  95. }