Setting IPGrant on a folder from a WebMethod

From: DAve (dsalonius_at_pobox.com)
Date: 02/21/05

  • Next message: Joe Kaplan \(MVP - ADSI\): "Re: Setting IPGrant on a folder from a WebMethod"
    Date: 21 Feb 2005 08:42:43 -0800
    
    

    I want to be able to limit access to a folder in IIS by IP address. I
    am trying to add IP addresses from a WebMethod to the IPGrant property.
     Here's my code:

    DirectoryEntry defaultRoot = new
    DirectoryEntry("IIS://SERVERNAME/w3svc/1/root/examplefolder",username,password,
    AuthenticationTypes.Secure);
    defaultRoot.RefreshCache();
    object oIPSecurity = defaultRoot.Invoke("Get", new
    string[]{"IPSecurity"});
    Type t = oIPSecurity.GetType();
    //Get the list of granted IPs
    Array IPs = (Array)t.InvokeMember("IPGrant", BindingFlags.GetProperty,
    null, oIPSecurity, null);
    //create a new Array of IPs
    object[] newIPs = new object[IPs.Length+1];
    //copy the existing IPs to the new Array
    IPs.CopyTo(newIPs,0);
    //add a new value
    newIPs.SetValue("192.168.0.21",IPs.Length);
    //Set the new IPlist
    t.InvokeMember("IPGrant", BindingFlags.SetProperty, null, oIPSecurity,
    new object[]{newIPs});
    defaultRoot.Invoke("Put", new object[]{"IPSecurity", oIPSecurity});
    defaultRoot.CommitChanges();

    When executed, I get this error:

    System.UnauthorizedAccessException: Access is denied. at
    System.DirectoryServices.Interop.IAds.SetInfo() at
    System.DirectoryServices.DirectoryEntry.CommitChanges()

    >>From the research I've done, I'm concerned that the solution to this
    problem is going to be a security threat. Any thoughts or alternative
    ideas to accomplish this?

    Thanks,

    David


  • Next message: Joe Kaplan \(MVP - ADSI\): "Re: Setting IPGrant on a folder from a WebMethod"

    Relevant Pages

    • Re: SMTP IPSecurity
      ... DirectoryEntry SMTPServer = new ... //Get the list of denied IPs ... //create a new Array of IPs ... BindingFlags.SetProperty, null, oIPSecurity, new object); ...
      (microsoft.public.inetserver.iis.smtp_nntp)
    • Re: SMTP IPSecurity
      ... DirectoryEntry SMTPServer = new ... //Get the list of denied IPs ... //create a new Array of IPs ... BindingFlags.SetProperty, null, oIPSecurity, new object); ...
      (microsoft.public.exchange2000.admin)
    • Re: SMTP IPSecurity
      ... DirectoryEntry SMTPServer = new ... //Get the list of denied IPs ... //create a new Array of IPs ... BindingFlags.SetProperty, null, oIPSecurity, new object); ...
      (microsoft.public.exchange2000.development)
    • Re: SMTP IPSecurity
      ... DirectoryEntry SMTPServer = new ... //Get the list of denied IPs ... //create a new Array of IPs ... BindingFlags.SetProperty, null, oIPSecurity, new object); ...
      (microsoft.public.exchange2000.general)
    • Re: Retrieve an element from an array
      ... >> I'm writing my personal firewall from scratch using bash 2.05b and>> iptables...The script I'm attempt to write must set automatically default>> rules for ips, respective interface and network or>> set more restrictive rules for individual ips (but that later as I'll figure>> out how to solve the problem with retrieving an array called by a string ... >> #Number of interfaces to maintain by firewall ... >> # The lines below defines the interface of which the firewall will take care>> of. ... > array with that name. ...
      (comp.unix.shell)