/// <summary>
        /// Removes access rules that contain the same security identifier and access mask
        /// as the specified access rule from the Discretionary Access Control List (DACL)
        /// associated with this <see cref="HttpUrlReservation"/> object.
        /// </summary>
        /// <param name="rule">The access rule to remove.</param>
        /// <returns>true if the access rule was successfully removed; otherwise, false.</returns>
        /// <exception cref="HttpUrlReservationNotFoundException">If the current <see cref="HttpUrlReservation"/> does not still exist.</exception>
        /// <exception cref="HttpServerException">If an internal error has been occured (use the <see cref="Win32Exception.NativeErrorCode"/> for more information).</exception>
        public bool RemoveAccessRule(HttpUrlReservationAccessRule rule)
        {
            var result = base.RemoveAccessRule(rule);

            this.Update();

            return(result);
        }
示例#2
0
        /// <summary>
        /// Register an URL reservation in the Windows HTTP Server.
        /// </summary>
        /// <param name="url">URL to register.</param>
        /// <param name="rule">Rule to apply to the URL to register.</param>
        /// <returns>An instance of <see cref="HttpUrlReservation"/> which allows to manage the URL reservation.</returns>
        public static HttpUrlReservation RegisterUrlReservation(string url, HttpUrlReservationAccessRule rule)
        {
            Contracts.IsNotNull(url, nameof(url));
            Contracts.IsNotNull(rule, nameof(rule));

            Initialize();

            try
            {
                // Create the ACL access
                var acl = new DiscretionaryAcl(false, false, 1);
                acl.AddAccess(rule.AccessControlType, (SecurityIdentifier)rule.IdentityReference, (int)rule.HttpUrlReservationAccessRights, rule.InheritanceFlags, rule.PropagationFlags);

                // Create the security descriptor and convert it to SDDL.
                var securityDescriptor = new CommonSecurityDescriptor(false, false, ControlFlags.DiscretionaryAclPresent, (SecurityIdentifier)rule.IdentityReference, null, null, acl);
                var ssdl = securityDescriptor.GetSddlForm(AccessControlSections.Access);

                var configInformation = new HttpServerApi.HTTP_SERVICE_CONFIG_URLACL_SET(url, ssdl);

                var result = HttpServerApi.HttpSetServiceConfiguration(IntPtr.Zero, HttpServerApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, configInformation, Marshal.SizeOf(configInformation), IntPtr.Zero);

                if (result == Win32Error.ERROR_ALREADY_EXISTS)
                {
                    throw new HttpUrlReservationAlreadyExistsException(result, string.Format(CultureInfo.CurrentUICulture, HttpServerResources.UrlReservationAlreadyExists, url));
                }

                if (result != Win32Error.NO_ERROR)
                {
                    throw new HttpServerException(result);
                }

                return(new HttpUrlReservation(url, new[] { rule }));
            }
            finally
            {
                Terminate();
            }
        }
 /// <summary>
 /// Adds the specified access rule to the Discretionary Access Control List(DACL) associated with this <see cref="HttpUrlReservation"/> object.
 /// </summary>
 /// <param name="rule">The access rule to add.</param>
 /// <exception cref="HttpUrlReservationNotFoundException">If the current <see cref="HttpUrlReservation"/> does not still exist.</exception>
 /// <exception cref="HttpServerException">If an internal error has been occured (use the <see cref="Win32Exception.NativeErrorCode"/> for more information).</exception>
 public void AddAccessRule(HttpUrlReservationAccessRule rule)
 {
     base.AddAccessRule(rule);
     this.Update();
 }