示例#1
0
 public static void Create(UrlReservation urlReservation)
 {
     string sddl = generateSddl(urlReservation._securityIdentifiers);
     reserveURL(urlReservation.Url, sddl);
 }
示例#2
0
        public static ReadOnlyCollection<UrlReservation> GetAll()
        {
            List<UrlReservation> revs = new List<UrlReservation>();

            uint retVal = (uint)ErrorCodes.NOERROR; // NOERROR = 0

            retVal = HttpApi.HttpInitialize(HttpApiConstants.HTTPAPI_VERSION_1, HttpApiConstants.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
            if ((uint)ErrorCodes.NOERROR == retVal)
            {
                HTTP_SERVICE_CONFIG_URLACL_QUERY inputConfigInfoSet = new HTTP_SERVICE_CONFIG_URLACL_QUERY();
                inputConfigInfoSet.QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext;

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

                    IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_QUERY)));
                    Marshal.StructureToPtr(inputConfigInfoSet, pInputConfigInfo, false);

                    HTTP_SERVICE_CONFIG_URLACL_SET outputConfigInfo = new HTTP_SERVICE_CONFIG_URLACL_SET();
                    IntPtr pOutputConfigInfo = Marshal.AllocCoTaskMem(0);

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

                    if (retVal == ErrorCodes.ERROR_INSUFFICIENT_BUFFER)
                    {
                        Marshal.ZeroFreeCoTaskMemUnicode(pOutputConfigInfo);
                        pOutputConfigInfo = Marshal.AllocCoTaskMem(Convert.ToInt32(returnLength));

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

                    if (ErrorCodes.NOERROR == retVal)
                    {
                        outputConfigInfo = (HTTP_SERVICE_CONFIG_URLACL_SET)Marshal.PtrToStructure(pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_URLACL_SET));
                        UrlReservation rev = new UrlReservation(outputConfigInfo.KeyDesc.pUrlPrefix, securityIdentifiersFromSDDL(outputConfigInfo.ParamDesc.pStringSecurityDescriptor));
                        revs.Add(rev);
                    }

                    Marshal.FreeCoTaskMem(pOutputConfigInfo);
                    Marshal.FreeCoTaskMem(pInputConfigInfo);

                    i++;
                }

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

            if ((uint)ErrorCodes.NOERROR != retVal)
            {
                throw new Win32Exception(Convert.ToInt32(retVal));
            }

            return new ReadOnlyCollection<UrlReservation>(revs);
        }
 public void Delete()
 {
     UrlReservation.Delete(this);
 }
 public void Create()
 {
     UrlReservation.Create(this);
 }
        public static void Delete(UrlReservation urlReservation)
        {
            string sddl = generateSddl(urlReservation._securityIdentifiers);

            freeURL(urlReservation.Url, sddl);
        }
        public static ReadOnlyCollection <UrlReservation> GetAll()
        {
            List <UrlReservation> revs = new List <UrlReservation>();

            uint retVal = (uint)ErrorCodes.NOERROR; // NOERROR = 0

            retVal = HttpApi.HttpInitialize(HttpApiConstants.HTTPAPI_VERSION_1, HttpApiConstants.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
            if ((uint)ErrorCodes.NOERROR == retVal)
            {
                HTTP_SERVICE_CONFIG_URLACL_QUERY inputConfigInfoSet = new HTTP_SERVICE_CONFIG_URLACL_QUERY();
                inputConfigInfoSet.QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext;

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


                    IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_QUERY)));
                    Marshal.StructureToPtr(inputConfigInfoSet, pInputConfigInfo, false);

                    HTTP_SERVICE_CONFIG_URLACL_SET outputConfigInfo = new HTTP_SERVICE_CONFIG_URLACL_SET();
                    IntPtr pOutputConfigInfo = Marshal.AllocCoTaskMem(0);

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

                    if (retVal == ErrorCodes.ERROR_INSUFFICIENT_BUFFER)
                    {
                        Marshal.ZeroFreeCoTaskMemUnicode(pOutputConfigInfo);
                        pOutputConfigInfo = Marshal.AllocCoTaskMem(Convert.ToInt32(returnLength));

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

                    if (ErrorCodes.NOERROR == retVal)
                    {
                        outputConfigInfo = (HTTP_SERVICE_CONFIG_URLACL_SET)Marshal.PtrToStructure(pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_URLACL_SET));
                        UrlReservation rev = new UrlReservation(outputConfigInfo.KeyDesc.pUrlPrefix, securityIdentifiersFromSDDL(outputConfigInfo.ParamDesc.pStringSecurityDescriptor));
                        revs.Add(rev);
                    }

                    Marshal.FreeCoTaskMem(pOutputConfigInfo);
                    Marshal.FreeCoTaskMem(pInputConfigInfo);

                    i++;
                }

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

            if ((uint)ErrorCodes.NOERROR != retVal)
            {
                throw new Win32Exception(Convert.ToInt32(retVal));
            }

            return(new ReadOnlyCollection <UrlReservation>(revs));
        }