Ejemplo n.º 1
0
        public static void Create(UrlReservation urlReservation)
        {
            if (urlReservation.securityIdentifiers.Count == 0)
            {
                throw new Exception("No SecurityIdentifiers have been assigned to the URLACL");
            }

            var sddl = GenerateSecurityDescriptor(urlReservation.securityIdentifiers);

            reserveURL(urlReservation.Url, sddl);
        }
Ejemplo n.º 2
0
        public static void Delete(UrlReservation urlReservation)
        {
            var securityDescriptor = GenerateSecurityDescriptor(urlReservation.securityIdentifiers);

            FreeURL(urlReservation.Url, securityDescriptor);
        }
Ejemplo n.º 3
0
        public static ReadOnlyCollection <UrlReservation> GetAll()
        {
            var reservations = new List <UrlReservation>();

            var retVal = HttpApi.HttpInitialize(HttpApiConstants.Version1, HttpApiConstants.InitializeConfig, IntPtr.Zero);

            if (retVal == ErrorCode.Success)
            {
                var inputConfigInfoSet = new  HttpServiceConfigUrlAclQuery
                {
                    QueryDesc = HttpServiceConfigQueryType.HttpServiceConfigQueryNext
                };

                var i = 0;
                while (retVal == 0)
                {
                    inputConfigInfoSet.Token = (uint)i;
                    var pInputConfigInfo = Marshal.AllocHGlobal((Marshal.SizeOf(typeof(HttpServiceConfigUrlAclQuery))));
                    Marshal.StructureToPtr(inputConfigInfoSet, pInputConfigInfo, false);

                    var pOutputConfigInfo = Marshal.AllocHGlobal(0);
                    var returnLength      = 0;
                    retVal = HttpApi.HttpQueryServiceConfiguration(IntPtr.Zero,
                                                                   HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                   pInputConfigInfo,
                                                                   Marshal.SizeOf(inputConfigInfoSet),
                                                                   pOutputConfigInfo,
                                                                   returnLength,
                                                                   out returnLength,
                                                                   IntPtr.Zero);

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

                        retVal = HttpApi.HttpQueryServiceConfiguration(IntPtr.Zero,
                                                                       HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                       pInputConfigInfo,
                                                                       Marshal.SizeOf(inputConfigInfoSet),
                                                                       pOutputConfigInfo,
                                                                       returnLength,
                                                                       out returnLength,
                                                                       IntPtr.Zero);
                    }

                    if (retVal == ErrorCode.Success)
                    {
                        var outputConfigInfo = (HttpServiceConfigUrlAclSet)Marshal.PtrToStructure(pOutputConfigInfo, typeof(HttpServiceConfigUrlAclSet));
                        var rev = new UrlReservation(outputConfigInfo.KeyDesc.UrlPrefix, SecurityIdentifiersFromSecurityDescriptor(outputConfigInfo.ParamDesc.StringSecurityDescriptor).ToArray());
                        reservations.Add(rev);
                    }
                    Marshal.FreeHGlobal(pOutputConfigInfo);
                    Marshal.FreeHGlobal(pInputConfigInfo);
                    i++;
                }

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

            if (retVal != ErrorCode.Success)
            {
                throw new Win32Exception(Convert.ToInt32(retVal));
            }
            return(new ReadOnlyCollection <UrlReservation>(reservations));
        }