Example #1
0
        private static void FreeURL(string networkURL, string securityDescriptor)
        {
            var retVal = HttpApi.HttpInitialize(HttpApiConstants.Version1, HttpApiConstants.InitializeConfig, IntPtr.Zero);

            if (ErrorCode.Success == retVal)
            {
                var urlAclKey   = new HttpServiceConfigUrlAclKey(networkURL);
                var urlAclParam = new HttpServiceConfigUrlAclParam(securityDescriptor);

                var urlAclSet = new HttpServiceConfigUrlAclSet
                {
                    KeyDesc   = urlAclKey,
                    ParamDesc = urlAclParam
                };

                var configInformation = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HttpServiceConfigUrlAclSet)));
                Marshal.StructureToPtr(urlAclSet, configInformation, false);
                var configInformationSize = Marshal.SizeOf(urlAclSet);
                retVal = HttpApi.HttpDeleteServiceConfiguration(IntPtr.Zero,
                                                                HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                configInformation,
                                                                configInformationSize,
                                                                IntPtr.Zero);

                Marshal.FreeHGlobal(configInformation);
                HttpApi.HttpTerminate(HttpApiConstants.InitializeConfig, IntPtr.Zero);
            }

            if (ErrorCode.Success != retVal)
            {
                throw new Win32Exception(Convert.ToInt32(retVal));
            }
        }
Example #2
0
        /// <summary>
        /// Adds a reservation to the list of reserved URLs
        /// </summary>
        /// <param name="urlPrefix">The prefix of the URL to reserve.</param>
        /// <param name="user">The user with which to reserve the URL.</param>
        internal static void AddReservation(string urlPrefix, string user)
        {
            NTAccount          account = new NTAccount(user);
            SecurityIdentifier sid     = (SecurityIdentifier)account.Translate(typeof(SecurityIdentifier));
            string             sddl    = GenerateSddl(sid);
            ErrorCode          retVal  = ErrorCode.Success; // NOERROR = 0

            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 = paramDesc;

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

                retVal = NativeMethods.HttpSetServiceConfiguration(
                    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.HttpSetServiceConfiguration(
                            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));
            }
        }
Example #3
0
        private static void reserveURL(string networkURL, string securityDescriptor)
        {
            var retVal = HttpApi.HttpInitialize(HttpApiConstants.Version1, HttpApiConstants.InitializeConfig, IntPtr.Zero);

            if (retVal == ErrorCode.Success)
            {
                var keyDesc   = new HttpServiceConfigUrlAclKey(networkURL);
                var paramDesc = new HttpServiceConfigUrlAclParam(securityDescriptor);

                var inputConfigInfoSet = new HttpServiceConfigUrlAclSet
                {
                    KeyDesc   = keyDesc,
                    ParamDesc = paramDesc
                };

                var pInputConfigInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HttpServiceConfigUrlAclSet)));
                Marshal.StructureToPtr(inputConfigInfoSet, pInputConfigInfo, false);

                retVal = HttpApi.HttpSetServiceConfiguration(IntPtr.Zero,
                                                             HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                             pInputConfigInfo,
                                                             Marshal.SizeOf(inputConfigInfoSet),
                                                             IntPtr.Zero);

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

                    if (ErrorCode.Success == retVal)
                    {
                        retVal = HttpApi.HttpSetServiceConfiguration(IntPtr.Zero,
                                                                     HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                     pInputConfigInfo,
                                                                     Marshal.SizeOf(inputConfigInfoSet),
                                                                     IntPtr.Zero);
                    }
                }

                Marshal.FreeHGlobal(pInputConfigInfo);
                HttpApi.HttpTerminate(HttpApiConstants.InitializeConfig, IntPtr.Zero);
            }

            if (retVal != ErrorCode.Success)
            {
                throw new Win32Exception(Convert.ToInt32(retVal));
            }
        }
Example #4
0
        /// <summary>
        /// Gets the list of reserved URLs
        /// </summary>
        /// <returns>The list of reserved URLs.</returns>
        internal 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));
        }
 private static extern int HttpDeleteServiceConfigurationAcl(IntPtr mustBeZero, int configID, [In] ref HttpServiceConfigUrlAclSet configInfo, int configInfoLength, IntPtr mustBeZero2);