Пример #1
0
        private void EditUrlAcl()
        {
            try
            {
                UrlAclConfigItem selectedItem = (UrlAclConfigItem)urlAclListView.SelectedItems[0];

                string originalSddl = selectedItem.Dacl.ToSddl();

                string editedSddl = SecurityEditor.EditSecurity(Handle, selectedItem.Url, originalSddl);

                if (editedSddl != originalSddl)
                {
                    selectedItem.Dacl = Acl.FromSddl(editedSddl);

                    if (selectedItem.Status == ModifiedStatus.Unmodified)
                    {
                        selectedItem.Status = ModifiedStatus.Modified;
                    }

                    applyButton.Enabled = true;

                    PopulateConfigListView(_urlAclItems, urlAclListView);
                }
            }
            finally
            {
                EnableUrlAclButtons();
            }
        }
        internal static UrlAclConfigItem LoadOrCreateConfigItem(string url, string user, ref object allUrlsRaw)
        {
            string loweredUrl = url.ToLowerInvariant();

            UrlAclConfigItem urlItem;

            Dictionary<string, UrlAclConfigItem> allUrls = null;

            if (allUrlsRaw != null)
                allUrls = (Dictionary<string, UrlAclConfigItem>)allUrlsRaw;
            else
            {
                allUrls = QueryConfig();
                allUrlsRaw = allUrls;
            }

            if (!allUrls.TryGetValue(loweredUrl, out urlItem))
            {
                urlItem = new UrlAclConfigItem(url, user);
                allUrls[loweredUrl] = urlItem;
            }else
            {
                if (!urlItem.Dacl.MatchesUser(loweredUrl))
                    urlItem.Dacl.SetUser(user);
                else
                    urlItem.needUpdate = false;
            }

            return urlItem;
        }
Пример #3
0
        private void addUrlAclButton_Click(object sender, System.EventArgs e)
        {
            try
            {
                using (InputBox input = new InputBox("New URL", "Please enter the URL:"))
                {
                    if (input.ShowDialog(this) == DialogResult.OK)
                    {
                        UrlAclConfigItem newItem = new UrlAclConfigItem();

                        newItem.Url = input.UserInput;

                        bool exists = false;
                        if (_urlAclItems.Contains(newItem.Key))
                        {
                            exists = true;

                            if (((ConfigItem)_urlAclItems[newItem.Key]).Status != ModifiedStatus.Removed)
                            {
                                MessageBox.Show(this, "Security is already configured for the Url you entered.", "Invalid Input");
                                return;
                            }
                        }

                        string originalSddl = newItem.Dacl != null?newItem.Dacl.ToSddl() : "D:";

                        string editedSddl = SecurityEditor.EditSecurity(Handle, newItem.Url, originalSddl);

                        if (editedSddl != originalSddl)
                        {
                            if (exists)
                            {
                                newItem.Status            = ModifiedStatus.Modified;
                                _urlAclItems[newItem.Key] = newItem;
                            }
                            else
                            {
                                newItem.Dacl   = Acl.FromSddl(editedSddl);
                                newItem.Status = ModifiedStatus.Added;
                                _urlAclItems.Add(newItem.Key, newItem);
                            }

                            applyButton.Enabled = true;

                            PopulateConfigListView(_urlAclItems, urlAclListView);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }
            finally
            {
                EnableUrlAclButtons();
            }
        }
Пример #4
0
        private static UrlAclConfigItem Deserialize(IntPtr pUrlAclConfigSetStruct)
        {
            UrlAclConfigItem item = new UrlAclConfigItem();

            HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET aclStruct =
                (HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET)Marshal.PtrToStructure(pUrlAclConfigSetStruct, typeof(HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET));

            item.Url = aclStruct.KeyDesc.pUrlPrefix;

            item.Dacl = Acl.FromSddl(aclStruct.ParamDesc.pStringSecurityDescriptor);

            item.Status = ModifiedStatus.Unmodified;

            return(item);
        }
Пример #5
0
        private void removeUrlAclButton_Click(object sender, System.EventArgs e)
        {
            try
            {
                ArrayList removedItems = new ArrayList();

                foreach (int i in urlAclListView.SelectedIndices)
                {
                    applyButton.Enabled = true;
                    removedItems.Add(((UrlAclConfigItem)urlAclListView.Items[i]).Key);
                }

                foreach (object key in removedItems)
                {
                    UrlAclConfigItem item = (UrlAclConfigItem)_urlAclItems[key];

                    switch (item.Status)
                    {
                    case ModifiedStatus.Added:
                        _urlAclItems.Remove(item.Key);
                        break;

                    case ModifiedStatus.Unmodified:
                        item.Status = ModifiedStatus.Removed;
                        break;

                    case ModifiedStatus.Modified:
                        item.Status = ModifiedStatus.Removed;
                        break;

                    default:
                        break;
                    }
                }

                PopulateConfigListView(_urlAclItems, urlAclListView);
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }
            finally
            {
                EnableUrlAclButtons();
            }
        }
Пример #6
0
        public static Hashtable QueryConfig()
        {
            Hashtable items = new Hashtable();

            HttpApi.HTTP_SERVICE_CONFIG_URLACL_QUERY query = new HttpApi.HTTP_SERVICE_CONFIG_URLACL_QUERY();

            query.QueryDesc = HttpApi.HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext;

            HttpApi.Error error = HttpApi.Error.NO_ERROR;

            IntPtr pInput = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HttpApi.HTTP_SERVICE_CONFIG_URLACL_QUERY)));

            try
            {
                for (query.dwToken = 0; ; query.dwToken++)
                {
                    Marshal.StructureToPtr(query, pInput, false);

                    int requiredBufferLength = 0;

                    error = QueryServiceConfig(pInput, IntPtr.Zero, 0, out requiredBufferLength);

                    if (error == HttpApi.Error.ERROR_NO_MORE_ITEMS)
                    {
                        break;
                    }
                    else if (error != HttpApi.Error.ERROR_INSUFFICIENT_BUFFER)
                    {
                        throw new HttpApiException(error, "HttpQueryServiceConfiguration (URLACL) failed.  Error = " + error);
                    }

                    IntPtr pOutput = Marshal.AllocHGlobal(requiredBufferLength);

                    try
                    {
                        HttpApi.ZeroMemory(pOutput, requiredBufferLength);

                        error = QueryServiceConfig(pInput, pOutput, requiredBufferLength, out requiredBufferLength);

                        if (error != HttpApi.Error.NO_ERROR)
                        {
                            throw new HttpApiException(error, "HttpQueryServiceConfiguration (URLACL) failed.  Error = " + error);
                        }

                        UrlAclConfigItem item = Deserialize(pOutput);

                        items.Add(item.Key, item);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(pOutput);
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(pInput);
            }

            return(items);
        }
Пример #7
0
        private void Load_UrlAclItems()
        {
            _urlAclItems = UrlAclConfigItem.QueryConfig();

            PopulateConfigListView(_urlAclItems, urlAclListView);
        }
        private static UrlAclConfigItem Deserialize(IntPtr pUrlAclConfigSetStruct)
        {
            UrlAclConfigItem item = new UrlAclConfigItem();

            HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET aclStruct =
                (HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET)Marshal.PtrToStructure(pUrlAclConfigSetStruct, typeof(HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET));

            item.Url = aclStruct.KeyDesc.pUrlPrefix;

            item.Dacl = Acl.FromSddl(aclStruct.ParamDesc.pStringSecurityDescriptor);

            item.presentInHttpCfg = true;

            return item;
        }