Exemplo n.º 1
0
        public override void ApplyConfig()
        {
            IntPtr pStruct = IntPtr.Zero;

            HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET setStruct = new HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET();

            setStruct.KeyDesc.pUrlPrefix = _url;

            setStruct.ParamDesc.pStringSecurityDescriptor = _acl.ToSddl();

            try
            {
                pStruct = Marshal.AllocHGlobal(Marshal.SizeOf(setStruct));

                Marshal.StructureToPtr(setStruct, pStruct, false);

                if ((Status == ModifiedStatus.Modified) || (Status == ModifiedStatus.Removed))
                {
                    HttpApi.Error error = HttpApi.HttpDeleteServiceConfiguration(
                        IntPtr.Zero,
                        HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
                        pStruct,
                        Marshal.SizeOf(setStruct),
                        IntPtr.Zero);

                    if (error != HttpApi.Error.NO_ERROR)
                    {
                        throw new HttpApiException(error, "HttpDeleteServiceConfiguration (URLACL) failed.  Error = " + error);
                    }
                }

                if ((Status == ModifiedStatus.Modified) || (Status == ModifiedStatus.Added))
                {
                    HttpApi.Error error = HttpApi.HttpSetServiceConfiguration(
                        IntPtr.Zero,
                        HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
                        pStruct,
                        Marshal.SizeOf(setStruct),
                        IntPtr.Zero);

                    if (error != HttpApi.Error.NO_ERROR)
                    {
                        throw new HttpApiException(error, "HttpSetServiceConfiguration (URLACL) failed.  Error = " + error);
                    }
                }
            }
            finally
            {
                if (pStruct != IntPtr.Zero)
                {
                    Marshal.DestroyStructure(pStruct, typeof(HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET));
                    Marshal.FreeHGlobal(pStruct);
                }
            }
        }
Exemplo n.º 2
0
        private static UrlAclConfigItem Deserialize(IntPtr pUrlAclConfigSetStruct)
        {
            UrlAclConfigItem item = new UrlAclConfigItem();

            HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET aclStruct =
                (HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET)Marshal.PtrToStructure(pUrlAclConfigSetStruct, typeof(HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET));

            item.Url = aclStruct.KeyDesc.pUrlPrefix;

            item.Dacl = Acl.FromSddl(aclStruct.ParamDesc.pStringSecurityDescriptor);

            item.Status = ModifiedStatus.Unmodified;

            return(item);
        }
        private void ApplyConfig(ConfigItemAction action)
        {
            IntPtr pStruct = IntPtr.Zero;

            HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET setStruct = new HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET();

            setStruct.KeyDesc.pUrlPrefix = this.Url;

            setStruct.ParamDesc.pStringSecurityDescriptor = this.Dacl.ToSddl();

            try
            {
                pStruct = Marshal.AllocHGlobal(Marshal.SizeOf(setStruct));

                Marshal.StructureToPtr(setStruct, pStruct, false);

                //if(this.presentInHttpCfg && 
                //    (action == ConfigItemAction.Delete || action == ConfigItemAction.Update))
                if (this.presentInHttpCfg)
                {
                    HttpApi.Error error = HttpApi.HttpDeleteServiceConfiguration(
                        IntPtr.Zero,
                        HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
                        pStruct,
                        Marshal.SizeOf(setStruct),
                        IntPtr.Zero);
                        
                    ErrorCheck.VerifySuccess(error, "HttpDeleteServiceConfiguration (URLACL) failed.");
                }

                if (action == ConfigItemAction.Create|| action == ConfigItemAction.Update)
                {
                    HttpApi.Error error = HttpApi.HttpSetServiceConfiguration(
                        IntPtr.Zero,
                        HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
                        pStruct,
                        Marshal.SizeOf(setStruct),
                        IntPtr.Zero);

                    if (error != HttpApi.Error.ERROR_ALREADY_EXISTS)
                        ErrorCheck.VerifySuccess(error, "HttpSetServiceConfiguration (URLACL) failed.");
                }
            }
            finally
            {
                if(pStruct != IntPtr.Zero)
                {
                    Marshal.DestroyStructure(pStruct, typeof(HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET));
                    Marshal.FreeHGlobal(pStruct);
                }
            }
        }