Add CGI ISAPI restriction to IIS - Advanced Installer Community
kissack
Posts: 57
Joined: Fri Feb 04, 2011 11:45 am

Add CGI ISAPI restriction to IIS

Hello,
I am trying to add (allow) a CGI/ISAPI restriction to a IIS server. I tried the following approaches:

1. Execute exe in working dir - trying to call appcmd.exe, but having trouble passing the parameters as the syntax contains the rectangular brackets
example:
appcmd.exe set config -section:system.webServer/security/isapiCgiRestriction /+"[path='C:\Inetpub\www.contoso.com\wwwroot\isapi\custom.dll',allowed='True',groupId='ContosoGroup',description='Contoso Extension']" /commit:apphost

2.executing vbs script, but it gives me error, I can execute the script without problems with cscript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set isapiCgiRestrictionSection = adminManager.GetAdminSection("system.webServer/security/isapiCgiRestriction", "MACHINE/WEBROOT/APPHOST")
Set isapiCgiRestrictionCollection = isapiCgiRestrictionSection.Collection

Set addElement = isapiCgiRestrictionCollection.CreateNewElement("add")
addElement.Properties.Item("path").Value = "C:\Inetpub\www.contoso.com\wwwroot\isapi\custom.dll"
addElement.Properties.Item("allowed").Value = True
addElement.Properties.Item("groupId").Value = "ContosoGroup"
addElement.Properties.Item("description").Value = "Contoso Extension"
isapiCgiRestrictionCollection.AddElement(addElement)

adminManager.CommitChanges()

Is there a recommended (well actually functioning) way to add this restriction ?

Thanks.
kissack
Posts: 57
Joined: Fri Feb 04, 2011 11:45 am

Re: Add CGI ISAPI restriction to IIS

Hello,
set the vbs script as deferred action without impersonation and it works.

Any other comments ?
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Add CGI ISAPI restriction to IIS

Hello,

Unfortunately, we don't have any predefined functionality to add this setting to your IIS server. However, the development team already had the feature on our TODO list so it will be available in a future version.

That custom action needed admin privileges to run properly and setting it with "Deferred with no impersonation" did the trick in your case.

Best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Add CGI ISAPI restriction to IIS

Hello,

This improvement was added in version 10.0 of Advanced Installer released on March 21, 2013.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
mgorga
Posts: 45
Joined: Fri Jun 03, 2011 1:00 pm

Re: Add CGI ISAPI restriction to IIS

Hello,
I'm trying this new feature because I need the restriction to allow the execution of an Isapi Dll. I just need to add the restriction but it seems that is necessary to associate to:
1. An Isapi filter
2. Application Mappings

Is it possible to add just the ISAPI restriction?

Best regards,
Mario
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Add CGI ISAPI restriction to IIS

Hello Mario,

Unfortunately we don't have predefined support for this. However, we have added this improvement on our TODO list and will be available in a future version of Advanced Installer. Thank you for your suggestion.

I'll let you know when this improvement will be available.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
mgorga
Posts: 45
Joined: Fri Jun 03, 2011 1:00 pm

Re: Add CGI ISAPI restriction to IIS

Hello,
based with this posts http://www.advancedinstaller.com/forums ... f=2&t=9632 I've made this approach :
1. Create a file ExecuteBat.vbs with this code:

Code: Select all

'Usage:
'- Save this script as ExecuteBat.vbs
'- from the Custom Actions page, add a new Attatched Custom Action
'- select ExecuteBat.vbs from the Browse dialog
'- make sure the Source Type is set to "Visual basic script (*.vbs)
'- set the Function Name field to ExecuteBat
'- the Action Data field will be the command line to execute

Function ExecuteBat()   
   Dim result, actData
   
   'extracting the command to execute
   actData = Session.Property("CustomActionData")
   
   'creating the shell object
   set objShell = CreateObject("WScript.Shell")   
   
   'running the bat file synchronously to avoid unexpected behavior due
   'to interference with the install process
   'this behavior can be overridden by selecting Asynchronous execution from Advanced Installer
   actData = "cmd.exe /C "&actData
   result = objShell.Run(actData, WindowStyle_Visible,1)
End Function
2. Create a Custom Action "Launch attached file" with the file ExecuteBat.vbs. This file is used to execute a command line. I didn't find a better approach.
3. Configure the action to be executed after "Add Resources" and on "Execution Stage Condition" mark only "install" option. Mark the action to be "execute with no impersonation" because it must be executed with administration privileges.
4. On property function of the Custom Action, put ExecuteBat.
5. For add the ISAPI restriction, put this line on the Action Data property, changing the file name:

Code: Select all

[WindowsFolder]system32\inetsrv\appcmd set config /section:isapiCgiRestriction /+"[\[]path='[APPDIR]MyFile.dll',description='My ISAPI description',allowed='True']"
NOTE: add another Custom Action executed on "uninstall" to remove the ISAPI restriction. You need to change the "+" for "-" and be sure that the path, description and allowed properties are exactly the same used on the installation process because IIS can't delete it if the values are not identically:

Code: Select all

[WindowsFolder]system32\inetsrv\appcmd set config /section:isapiCgiRestriction /-"[\[]path='[APPDIR]MyFile.dll',description='My ISAPI description',allowed='True']"
Best regards,
Mario
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Add CGI ISAPI restriction to IIS

Hello Mario,

Thank you for sharing this with us. Certainly this solution will help future users in the same situation.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”