示例#1
0
        /// <summary>
        /// Gets the list of reserved URLs
        /// </summary>
        /// <returns>The list of reserved URLs.</returns>
        public static ReadOnlyCollection<string> GetReservedUrlList()
        {
            List<string> revs = new List<string>();

            ErrorCode retVal = ErrorCode.Success; // NOERROR = 0

            retVal = NativeMethods.HttpInitialize(HttpApiConstants.Version1, HttpApiConstants.InitializeConfig, IntPtr.Zero);
            if (ErrorCode.Success == retVal)
            {
                HttpServiceConfigUrlAclQuery inputConfigInfoSet = new HttpServiceConfigUrlAclQuery();
                inputConfigInfoSet.QueryDesc = HttpServiceConfigQueryType.HttpServiceConfigQueryNext;

                int i = 0;
                while (retVal == 0)
                {
                    inputConfigInfoSet.Token = (uint)i;

                    IntPtr inputConfigInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HttpServiceConfigUrlAclQuery)));
                    Marshal.StructureToPtr(inputConfigInfoSet, inputConfigInfo, false);

                    HttpServiceConfigUrlAclSet outputConfigInfo = new HttpServiceConfigUrlAclSet();
                    IntPtr outputConfigInfoBuffer = Marshal.AllocHGlobal(0);

                    int returnLength = 0;
                    retVal = NativeMethods.HttpQueryServiceConfiguration(
                        IntPtr.Zero,
                        HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                        inputConfigInfo,
                        Marshal.SizeOf(inputConfigInfoSet),
                        outputConfigInfoBuffer,
                        returnLength,
                        out returnLength,
                        IntPtr.Zero);

                    if (retVal == ErrorCode.InsufficientBuffer)
                    {
                        Marshal.FreeHGlobal(outputConfigInfoBuffer);
                        outputConfigInfoBuffer = Marshal.AllocHGlobal(Convert.ToInt32(returnLength));

                        retVal = NativeMethods.HttpQueryServiceConfiguration(
                            IntPtr.Zero,
                            HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                            inputConfigInfo,
                            Marshal.SizeOf(inputConfigInfoSet),
                            outputConfigInfoBuffer,
                            returnLength,
                            out returnLength,
                            IntPtr.Zero);
                    }

                    if (ErrorCode.Success == retVal)
                    {
                        outputConfigInfo = (HttpServiceConfigUrlAclSet)Marshal.PtrToStructure(outputConfigInfoBuffer, typeof(HttpServiceConfigUrlAclSet));
                        string urlPrefix = outputConfigInfo.KeyDesc.UrlPrefix;
                        revs.Add(urlPrefix);
                    }

                    Marshal.FreeHGlobal(outputConfigInfoBuffer);
                    Marshal.FreeHGlobal(inputConfigInfo);

                    i++;
                }

                retVal = NativeMethods.HttpTerminate(HttpApiConstants.InitializeConfig, IntPtr.Zero);
            }

            if (ErrorCode.Success != retVal)
            {
                throw new Win32Exception(Convert.ToInt32(retVal, CultureInfo.InvariantCulture));
            }

            return new ReadOnlyCollection<string>(revs);
        }
示例#2
0
        internal static void DeleteReservation(string urlPrefix,string user)
        {
            NTAccount account = new NTAccount(user);
            SecurityIdentifier sid = (SecurityIdentifier)account.Translate(typeof(SecurityIdentifier));
            string sddl = GenerateSddl(sid);

            ErrorCode retVal = ErrorCode.Success;
            retVal = NativeMethods.HttpInitialize(HttpApiConstants.Version1, HttpApiConstants.InitializeConfig, IntPtr.Zero);
            if (ErrorCode.Success == retVal)
            {
                HttpServiceConfigUrlAclKey keyDesc = new HttpServiceConfigUrlAclKey(urlPrefix);
                HttpServiceConfigUrlAclParam paramDesc = new HttpServiceConfigUrlAclParam(sddl);

                HttpServiceConfigUrlAclSet inputConfigInfoSet = new HttpServiceConfigUrlAclSet();
                inputConfigInfoSet.KeyDesc = keyDesc;
                inputConfigInfoSet.ParamDesc = new HttpServiceConfigUrlAclParam();

                IntPtr inputConfigInfoBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HttpServiceConfigUrlAclSet)));
                Marshal.StructureToPtr(inputConfigInfoSet, inputConfigInfoBuffer, false);

                retVal = NativeMethods.HttpDeleteServiceConfiguration(
                    IntPtr.Zero,
                    HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                    inputConfigInfoBuffer,
                    Marshal.SizeOf(inputConfigInfoSet),
                    IntPtr.Zero);

                if (ErrorCode.AlreadyExists == retVal)
                {
                    retVal = NativeMethods.HttpDeleteServiceConfiguration(
                        IntPtr.Zero,
                        HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                        inputConfigInfoBuffer,
                        Marshal.SizeOf(inputConfigInfoSet),
                        IntPtr.Zero);

                    if (ErrorCode.Success == retVal)
                    {
                        retVal = NativeMethods.HttpDeleteServiceConfiguration(
                            IntPtr.Zero,
                            HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                            inputConfigInfoBuffer,
                            Marshal.SizeOf(inputConfigInfoSet),
                            IntPtr.Zero);
                    }
                }

                Marshal.FreeHGlobal(inputConfigInfoBuffer);
                NativeMethods.HttpTerminate(HttpApiConstants.InitializeConfig, IntPtr.Zero);

                if (ErrorCode.Success != retVal)
                {
                    throw new Win32Exception(Convert.ToInt32(retVal, CultureInfo.InvariantCulture));
                }
            }
        }