Fix path to DLL.
[shibboleth/sp.git] / msi / scripts / shib_uninstall_isapi_filter.vbs
1 Sub DeleteISAPIFilters(IISPath,dllPath)
2
3   Dim filter, FiltersObj, LoadOrder, FilterArray, FilterItem
4
5   Set FiltersObj = GetObject(IISPath & "/Filters")
6   LoadOrder = FiltersObj.FilterLoadOrder
7
8   for each filter in FiltersObj
9     if (filter.Class = "IIsFilter") then
10       if (filter.FilterPath = dllPath) then
11
12         'Delete the found filter here
13         'If there's anything to potentially delete...
14         if (LoadOrder <> "") then
15           FilterArray = split(LoadOrder,",")
16           LoadOrder = ""
17           for each FilterItem in FilterArray
18             if (FilterItem <> filter.Name) then
19               LoadOrder = LoadOrder & FilterItem & ","
20             end if
21           next
22           'Remove trailing comma if any filters were kept
23           if (LoadOrder <> "") then
24             LoadOrder = mid(LoadOrder,1,len(LoadOrder)-1)
25           end if
26
27           'Set the Load Order to the new shibboleth-less order
28           if (FiltersObj.FilterLoadOrder <> LoadOrder) then
29             FiltersObj.FilterLoadOrder = LoadOrder
30             FiltersObj.SetInfo
31           end if
32         end if
33
34         'Delete the actual IISFilter object
35         FiltersObj.Delete "IIsFilter",filter.Name
36
37       end if
38     end if
39   next
40
41 End Sub
42
43
44 Sub DeleteFileExtensions(siteObj, dllPath)
45
46 Dim ScriptMaps, newScriptMaps
47 Dim line, lineArray, lineIndex
48 Dim fileExtension
49 Dim existsFlag
50
51   ScriptMaps = siteObj.ScriptMaps
52   redim newScriptMaps(0)
53   lineIndex = 0
54   'copy each entry from the old ScriptMaps to newScriptMaps
55   'unless it is for dllPath
56   for each line in ScriptMaps
57     lineArray = split(line,",")
58     if (lineArray(1) <> dllPath) then
59       redim preserve newScriptMaps(lineIndex)
60       newScriptMaps(lineIndex) = line
61       lineIndex = lineIndex + 1
62     else
63       existsFlag = "exists"
64     end if
65   next
66   'If we found dllPath, then use the newScriptMaps instead
67   if (existsFlag = "exists") then
68     siteObj.ScriptMaps = newScriptMaps
69     siteObj.SetInfo
70   end if
71
72 End Sub
73
74
75 '*** Begin Main Code ***
76 Dim WebObj
77 Dim InstallDir
78 Dim ShibISAPIPath
79 Dim site, siteObj, sitePath
80
81
82 'Don't show errors, we'll handle anything important
83 On Error Resume Next
84
85 'Attempt to get W3SVC.  If failure, end script (e.g. IIS isn't available)
86 Set WebObj = GetObject("IIS://LocalHost/W3SVC")
87 if (Err = 0) then
88
89   'Get the INSTALLDIR value via CustomActionData
90   InstallDir = Session.Property("CustomActionData")
91
92   'Remove all trailing backslashes to normalize
93   do while (mid(InstallDir,Len(InstallDir),1) = "\")
94     InstallDir = mid(InstallDir,1,Len(InstallDir)-1)
95   loop
96   ShibISAPIPath = InstallDir & "\lib\shibboleth\isapi_shib.dll"
97
98   'Delete ISAPI Filter
99   'First do the master service
100   DeleteISAPIFilters "IIS://LocalHost/W3SVC",ShibISAPIPath
101   'Now do the websites
102   for each site in WebObj
103     if (site.Class = "IIsWebServer") then
104       sitePath = "IIS://LocalHost/W3SVC/" & site.Name
105       DeleteISAPIFilters sitePath,ShibISAPIPath
106     end if
107   next
108
109   'Delete File Extensions
110   'First do the master service
111   DeleteFileExtensions WebObj,ShibISAPIPath
112   'Now do the websites
113   for each site in WebObj
114     if (site.Class = "IIsWebServer") then
115       set siteObj = GetObject("IIS://LocalHost/W3SVC/" & site.Name & "/ROOT")
116       DeleteFileExtensions siteObj,ShibISAPIPath
117     end if
118   next
119
120
121   'Delete Web Services Extension (universal, no need to do for each site)
122   WebObj.DeleteExtensionFileRecord ShibISAPIPath
123
124 'Last end if
125 end if