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.

177 lines
5.8 KiB

  1. #include <stdio.h>
  2. #include <tchar.h>
  3. #define INITGUID // must be before iadmw.h
  4. #include <iadmw.h> // Interface header
  5. // for adsi objects
  6. #include <Iads.h>
  7. #include <Adshlp.h>
  8. // for the IID_IISWebService object
  9. #include "iiisext.h"
  10. #include "iisext_i.c"
  11. #define WEBSVCEXT_RESTRICTION_LIST_ADSI_LOCATION L"IIS://LOCALHOST/W3SVC"
  12. HRESULT AddWebSvcExtention(LPWSTR lpwszFileName,VARIANT_BOOL bEnabled,LPWSTR lpwszGroupID,VARIANT_BOOL bDeletableThruUI,LPWSTR lpwszGroupDescription);
  13. HRESULT RemoveWebSvcExtention(LPWSTR lpwszFileName);
  14. HRESULT AddApplicationDependencyUponGroup(LPWSTR lpwszAppName,LPWSTR lpwszGroupID);
  15. HRESULT RemoveApplicationDependencyUponGroup(LPWSTR lpwszAppName,LPWSTR lpwszGroupID);
  16. int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
  17. {
  18. BOOL bComInitialized = SUCCEEDED( ::CoInitialize( NULL ) );
  19. // Add MyFile.dll to the restrictionlist, make sure it's enabled,
  20. // and that the user is able to remove the entry thru the UI if they wanted to
  21. AddWebSvcExtention(L"c:\\windows\\system32\\inetsrv\\MyFile.dll",VARIANT_TRUE,L"MyGroup",VARIANT_TRUE,L"My Description");
  22. // The Commerce Server group would make this entry, to say that
  23. // They're app is dependent upon MyGroup (like dependent upon ASP or soemthing)
  24. //
  25. // This way, if the user installed disabled all of the extensions
  26. // and then discovered "Commerce Server" wasn't working right, they could
  27. // just go to the iis ui and enable all extensions that are used by "Commerce Server" --
  28. // so that "Commerce Server" would work.
  29. AddApplicationDependencyUponGroup(L"Commerce Server",L"MyGroup");
  30. AddApplicationDependencyUponGroup(L"Commerce Server",L"ASP60");
  31. AddApplicationDependencyUponGroup(L"Commerce Server",L"INDEX2002");
  32. //RemoveWebSvcExtention(L"c:\\windows\\system32\\inetsrv\\MyFile.dll");
  33. //RemoveApplicationDependencyUponGroup(L"Commerce Server",L"MyGroup");
  34. //RemoveApplicationDependencyUponGroup(L"Commerce Server",L"ASP60");
  35. //RemoveApplicationDependencyUponGroup(L"Commerce Server",L"INDEX2002");
  36. if ( bComInitialized )
  37. {
  38. ::CoUninitialize();
  39. }
  40. return 0;
  41. }
  42. /*
  43. IID_IISWebService has:
  44. o.EnableApplication(myapp);
  45. o.RemoveApplication(myapp);
  46. o.ListApplications(foo); // must declare foo first � returned as a VB array
  47. o.AddDependency(myapp, mygroup);
  48. o.RemoveDependency(myapp, mygroup);
  49. o.EnableWebServiceExtension(mygroup);
  50. o.DisableWebServiceExtension(mygroup);
  51. o.ListWebServiceExtensions(foo); // see foo note above
  52. o.EnableExtensionFile(myfile);
  53. o.DisableExtensionFile(myfile);
  54. o.AddExtensionFile(myfile, boolEnabled, mygroup, boolCanDelete, my description sucks); // boolEnabled = t/f, boolCanDelete = t/f
  55. o.DeleteExtensionFileRecord(myfile);
  56. o.ListExtensionFiles(foo); // see foo note above
  57. */
  58. HRESULT AddWebSvcExtention(LPWSTR lpwszFileName,VARIANT_BOOL bEnabled,LPWSTR lpwszGroupID,VARIANT_BOOL bDeletableThruUI,LPWSTR lpwszGroupDescription)
  59. {
  60. HRESULT hrRet = S_FALSE;
  61. WCHAR* wszRootWeb6 = WEBSVCEXT_RESTRICTION_LIST_ADSI_LOCATION;
  62. IISWebService * pWeb = NULL;
  63. HRESULT hr = ADsGetObject(wszRootWeb6, IID_IISWebService, (void**)&pWeb);
  64. if (SUCCEEDED(hr) && NULL != pWeb)
  65. {
  66. VARIANT var1,var2;
  67. VariantInit(&var1);
  68. VariantInit(&var2);
  69. var1.vt = VT_BOOL;
  70. var1.boolVal = bEnabled;
  71. var2.vt = VT_BOOL;
  72. var2.boolVal = bDeletableThruUI;
  73. hr = pWeb->AddExtensionFile(lpwszFileName,var1,lpwszGroupID,var2,lpwszGroupDescription);
  74. if (SUCCEEDED(hr))
  75. {
  76. hrRet = S_OK;
  77. }
  78. else
  79. {
  80. OutputDebugString(_T("failed,probably already exists\r\n"));
  81. }
  82. VariantClear(&var1);
  83. VariantClear(&var2);
  84. pWeb->Release();
  85. }
  86. return hrRet;
  87. }
  88. HRESULT RemoveWebSvcExtention(LPWSTR lpwszFileName)
  89. {
  90. HRESULT hrRet = S_FALSE;
  91. WCHAR* wszRootWeb6 = WEBSVCEXT_RESTRICTION_LIST_ADSI_LOCATION;
  92. IISWebService * pWeb = NULL;
  93. HRESULT hr = ADsGetObject(wszRootWeb6, IID_IISWebService, (void**)&pWeb);
  94. if (SUCCEEDED(hr) && NULL != pWeb)
  95. {
  96. hr = pWeb->DeleteExtensionFileRecord(lpwszFileName);
  97. if (SUCCEEDED(hr))
  98. {
  99. hrRet = S_OK;
  100. }
  101. else
  102. {
  103. OutputDebugString(_T("failed,probably already gone\r\n"));
  104. }
  105. pWeb->Release();
  106. }
  107. return hrRet;
  108. }
  109. HRESULT AddApplicationDependencyUponGroup(LPWSTR lpwszAppName,LPWSTR lpwszGroupID)
  110. {
  111. HRESULT hrRet = S_FALSE;
  112. WCHAR* wszRootWeb6 = WEBSVCEXT_RESTRICTION_LIST_ADSI_LOCATION;
  113. IISWebService * pWeb = NULL;
  114. HRESULT hr = ADsGetObject(wszRootWeb6, IID_IISWebService, (void**)&pWeb);
  115. if (SUCCEEDED(hr) && NULL != pWeb)
  116. {
  117. hr = pWeb->AddDependency(lpwszAppName,lpwszGroupID);
  118. if (SUCCEEDED(hr))
  119. {
  120. hrRet = S_OK;
  121. }
  122. else
  123. {
  124. OutputDebugString(_T("failed,probably already exists\r\n"));
  125. }
  126. pWeb->Release();
  127. }
  128. return hrRet;
  129. }
  130. HRESULT RemoveApplicationDependencyUponGroup(LPWSTR lpwszAppName,LPWSTR lpwszGroupID)
  131. {
  132. HRESULT hrRet = S_FALSE;
  133. WCHAR* wszRootWeb6 = WEBSVCEXT_RESTRICTION_LIST_ADSI_LOCATION;
  134. IISWebService * pWeb = NULL;
  135. HRESULT hr = ADsGetObject(wszRootWeb6, IID_IISWebService, (void**)&pWeb);
  136. if (SUCCEEDED(hr) && NULL != pWeb)
  137. {
  138. hr = pWeb->RemoveDependency(lpwszAppName,lpwszGroupID);
  139. if (SUCCEEDED(hr))
  140. {
  141. hrRet = S_OK;
  142. }
  143. else
  144. {
  145. OutputDebugString(_T("failed,probably already gone\r\n"));
  146. }
  147. pWeb->Release();
  148. }
  149. return hrRet;
  150. }