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.

126 lines
3.3 KiB

  1. // EnumTrusts.cpp
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <atlbase.h>
  5. #include <adserr.h>
  6. #import "..\McsVarSetMin.tlb"
  7. #import "..\McsEnumTrustRelations.tlb"
  8. namespace
  9. {
  10. void
  11. usage(
  12. WCHAR const * cmdName // in, what was the name of this program
  13. )
  14. {
  15. printf("Usage: %ls servername\n", cmdName);
  16. }
  17. }
  18. #define STRING_CASE(name) case name: err_name = #name; break
  19. int printNameHresult(HRESULT hr){
  20. const char* err_name = "Unknown error";
  21. switch(hr){
  22. STRING_CASE(S_OK);
  23. STRING_CASE(S_FALSE);
  24. STRING_CASE(DRAGDROP_S_CANCEL);
  25. STRING_CASE(DRAGDROP_S_DROP);
  26. STRING_CASE(DRAGDROP_S_USEDEFAULTCURSORS);
  27. STRING_CASE(E_UNEXPECTED);
  28. STRING_CASE(E_NOTIMPL);
  29. STRING_CASE(E_OUTOFMEMORY);
  30. STRING_CASE(E_INVALIDARG);
  31. STRING_CASE(E_NOINTERFACE);
  32. STRING_CASE(E_POINTER);
  33. STRING_CASE(E_HANDLE);
  34. STRING_CASE(E_ABORT);
  35. STRING_CASE(E_FAIL);
  36. STRING_CASE(E_ACCESSDENIED);
  37. STRING_CASE(CLASS_E_NOAGGREGATION);
  38. STRING_CASE(CO_E_NOTINITIALIZED);
  39. STRING_CASE(CO_E_ALREADYINITIALIZED);
  40. STRING_CASE(CO_E_INIT_ONLY_SINGLE_THREADED);
  41. STRING_CASE(REGDB_E_INVALIDVALUE);
  42. STRING_CASE(REGDB_E_CLASSNOTREG);
  43. STRING_CASE(REGDB_E_IIDNOTREG);
  44. STRING_CASE(DV_E_DVASPECT);
  45. STRING_CASE(E_ADS_BAD_PATHNAME);
  46. STRING_CASE(E_ADS_INVALID_DOMAIN_OBJECT);
  47. STRING_CASE(E_ADS_INVALID_USER_OBJECT);
  48. STRING_CASE(E_ADS_INVALID_COMPUTER_OBJECT);
  49. STRING_CASE(E_ADS_UNKNOWN_OBJECT);
  50. STRING_CASE(E_ADS_PROPERTY_NOT_SET);
  51. STRING_CASE(E_ADS_PROPERTY_NOT_SUPPORTED);
  52. STRING_CASE(E_ADS_PROPERTY_INVALID);
  53. STRING_CASE(E_ADS_BAD_PARAMETER);
  54. STRING_CASE(E_ADS_OBJECT_UNBOUND);
  55. STRING_CASE(E_ADS_PROPERTY_NOT_MODIFIED);
  56. STRING_CASE(E_ADS_PROPERTY_MODIFIED);
  57. STRING_CASE(E_ADS_CANT_CONVERT_DATATYPE);
  58. STRING_CASE(E_ADS_PROPERTY_NOT_FOUND);
  59. STRING_CASE(E_ADS_OBJECT_EXISTS);
  60. STRING_CASE(E_ADS_SCHEMA_VIOLATION);
  61. STRING_CASE(E_ADS_COLUMN_NOT_SET);
  62. STRING_CASE(S_ADS_ERRORSOCCURRED);
  63. STRING_CASE(S_ADS_NOMORE_ROWS);
  64. STRING_CASE(S_ADS_NOMORE_COLUMNS);
  65. STRING_CASE(E_ADS_INVALID_FILTER);
  66. }
  67. printf("HRESULT = 0x%x : %s\n", hr, err_name);
  68. return 3;
  69. }
  70. #undef STRING_CASE
  71. using namespace MCSENUMTRUSTRELATIONSLib;
  72. using namespace MCSVARSETMINLib;
  73. extern "C"
  74. int
  75. wmain(
  76. int argc ,
  77. WCHAR const * argv[] // The name of a server
  78. )
  79. {
  80. if( argc <= 1 || wcsncmp(argv[1], L"/?", 2) == 0 )
  81. {
  82. usage(argv[0]);
  83. return 1;
  84. }
  85. if( FAILED( CoInitialize(NULL) ) )
  86. {
  87. printf("Couldn't initialize the COM library"); return 4;
  88. }
  89. CComPtr<ITrustEnumerator> pIEnumerator = NULL;
  90. IVarSetPtr pIVarSet = NULL;
  91. HRESULT hr;
  92. hr = pIEnumerator.CoCreateInstance(__uuidof(TrustEnumerator));
  93. if( FAILED(hr) )
  94. {
  95. printNameHresult(hr);
  96. printf("Couldn't create an instance of the TrustEnumerator\n");
  97. return 2;
  98. }
  99. hr = pIEnumerator->raw_getTrustRelations( _bstr_t(argv[1]), reinterpret_cast<IUnknown **>(& pIVarSet) );
  100. if( FAILED(hr) )
  101. {
  102. printNameHresult(hr);
  103. printf("Couldn't getTrustRelations\n");
  104. return 3;
  105. }
  106. hr = pIVarSet->DumpToFile(L"dump.txt");
  107. return 0;
  108. }