Leaked source code of windows server 2003
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.

154 lines
3.5 KiB

  1. #include <windows.h>
  2. #include <atlbase.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <strsafe.h>
  6. #include <iads.h>
  7. #include <adshlp.h>
  8. #include "iiisext.h"
  9. #include <iiscnfg.h>
  10. #include <iadmw.h>
  11. #include <adsiid.h>
  12. #include "iiisext.h"
  13. #include "iisext_i.c"
  14. #define INITGUID
  15. #include <guiddef.h>
  16. DEFINE_GUID(CLSID_MSAdminBase_W, 0xa9e69610, 0xb80d, 0x11d0, 0xb9, 0xb9, 0x0, 0xa0, 0xc9, 0x22, 0xe7, 0x50);
  17. DEFINE_GUID(IID_IMSAdminBase_W, 0x70b51430, 0xb6ca, 0x11d0, 0xb9, 0xb9, 0x0, 0xa0, 0xc9, 0x22, 0xe7, 0x50);
  18. #undef INITGUID
  19. #define GROUP_ID L"PBS"
  20. #define APP_ID GROUP_ID
  21. #define DESCRIPTION L"Phone Book Service"
  22. IISWebService * g_pWeb = NULL;
  23. HRESULT AddWebSvcExtension(WCHAR *Path, WCHAR *GroupID, WCHAR *Description)
  24. {
  25. HRESULT hr;
  26. VARIANT var1,var2;
  27. VariantInit(&var1);
  28. VariantInit(&var2);
  29. var1.vt = VT_BOOL;
  30. var1.boolVal = VARIANT_TRUE;
  31. var2.vt = VT_BOOL;
  32. var2.boolVal = VARIANT_TRUE;
  33. hr = g_pWeb->AddExtensionFile(Path,var1,GroupID,var2,Description);
  34. if (FAILED(hr)) {
  35. wprintf(L"g_pWeb->AddExtensionFile failed(0x%08x)\n", hr);
  36. return hr;
  37. }
  38. VariantClear(&var1);
  39. VariantClear(&var2);
  40. wprintf(L"Finish AddWebSvcExtention.\n");
  41. return S_OK;
  42. }
  43. HRESULT RemoveExtension(WCHAR *path) {
  44. HRESULT hr;
  45. hr = g_pWeb->DeleteExtensionFileRecord(path);
  46. if (FAILED(hr)) {
  47. wprintf(L"g_pWeb->DeleteExtensionFileRecord failed(0x%08x)\n", hr);
  48. return hr;
  49. }
  50. wprintf(L"Finish RemoveExtension.\n");
  51. return S_OK;
  52. }
  53. HRESULT RemoveApp(WCHAR *appId) {
  54. HRESULT hr;
  55. hr = g_pWeb->RemoveApplication (appId);
  56. if (FAILED(hr)) {
  57. wprintf(L"g_pWeb->RemoveApplication failed(0x%08x)\n", hr);
  58. return hr;
  59. }
  60. wprintf(L"Finish RemoveApp.\n");
  61. return S_OK;
  62. }
  63. int __cdecl wmain( int argc, WCHAR* argv[])
  64. {
  65. WCHAR* wszRootWeb6 = L"IIS://LOCALHOST/W3SVC";
  66. WCHAR* wszPBSLocation = L"%ProgramFiles%\\Phone Book Service\\Bin\\pbserver.dll";
  67. WCHAR DllPath[MAX_PATH+1];
  68. HRESULT hr = S_OK;
  69. bool install;
  70. hr = CoInitialize(NULL);
  71. if (hr) {
  72. return hr;
  73. }
  74. if (argc == 1) {
  75. wprintf(L"Wrong parameters. Usage: pbsnetoc /i | /u\n");
  76. return E_INVALIDARG;
  77. }
  78. if (wcscmp(argv[1], L"/i") == 0) {
  79. install = true;
  80. }
  81. else if (wcscmp(argv[1], L"/u") == 0) {
  82. install = false;
  83. }
  84. else {
  85. wprintf(L"Wrong parameters. Usage: pbsnetoc /i | /u\n");
  86. return E_INVALIDARG;
  87. }
  88. hr = ADsGetObject(wszRootWeb6, IID_IISWebService, (void**)&g_pWeb);
  89. if (FAILED(hr) || NULL == g_pWeb) {
  90. wprintf(L"FAIL:no object (0x%08x)\n", hr);
  91. return hr;
  92. }
  93. if (!ExpandEnvironmentStrings(wszPBSLocation, DllPath, MAX_PATH + 1))
  94. {
  95. hr = HRESULT_FROM_WIN32(GetLastError());
  96. wprintf(L"FAIL:could not get PBS path (0x%08x)\n", hr);
  97. return hr;
  98. }
  99. wprintf(L"Path: %s\n", DllPath);
  100. if (install)
  101. {
  102. hr = AddWebSvcExtension(DllPath, GROUP_ID, DESCRIPTION);
  103. if (FAILED(hr)) {
  104. return hr;
  105. }
  106. }
  107. else
  108. {
  109. hr = RemoveExtension(DllPath);
  110. if (FAILED(hr)) {
  111. return hr;
  112. }
  113. }
  114. g_pWeb->Release();
  115. CoUninitialize();
  116. if (S_OK != hr)
  117. {
  118. wprintf(L"returning with failure code (0x%08x)\n", hr);
  119. }
  120. return hr;
  121. }