Click here to Skip to main content
15,867,985 members
Articles / Programming Languages / Visual Basic

The Windows Access Control Model Part 3

Rate me:
Please Sign up or sign in to vote.
4.80/5 (28 votes)
1 Jul 200525 min read 232K   5.2K   126  
In the third part of this series, we will take a tour of the new access control classes coming in .NET v2.0.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Security.AccessControl;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace NetAccessControl
{
	public partial class Inheritance<DatType> : Form where DatType : AuthorizationRule
	{
		internal PropagationFlags Entryprops;
		internal InheritanceFlags Entryinhers;
		internal bool isInherited;

		public Inheritance(DatType EntryIn)
		{
			/* Fill up our class member variables. */
			InitializeComponent();
			this.Entryprops = (EntryIn != null) ? EntryIn.PropagationFlags : PropagationFlags.None;
			this.Entryinhers = (EntryIn != null) ? EntryIn.InheritanceFlags : InheritanceFlags.None;
			this.isInherited = (EntryIn != null) ? EntryIn.IsInherited : false;
		}

		private void Inheritance_Load(object sender, EventArgs e)
		{
			/* Start ticking the entries according to Entry */
			try
			{
				if ((this.Entryprops & PropagationFlags.InheritOnly) != 0)
				{
					this.ioCheck.CheckState = CheckState.Checked;
				}
				if ((this.Entryprops & PropagationFlags.NoPropagateInherit) != 0)
				{
					this.npCheck.CheckState = CheckState.Checked;
				}
				if ((this.Entryinhers & InheritanceFlags.ContainerInherit) != 0)
				{
					this.ciCheck.CheckState = CheckState.Checked;
				}
				if ((this.Entryinhers & InheritanceFlags.ObjectInherit) != 0)
				{
					this.oiCheck.CheckState = CheckState.Checked;
				}
				if (this.isInherited)
				{
					this.idCheck.CheckState = CheckState.Checked;
				}
			}
			catch (System.NullReferenceException)
			{
				/* ignore this error */
			}
			catch (System.Exception)
			{
				this.Close();
			}
		}

		private void OKButton_Click(object sender, EventArgs e)
		{
			/* build up a new accessrule based on the current data and the new check boxes */
			if (this.ioCheck.Checked) this.Entryprops |= PropagationFlags.InheritOnly;
			else this.Entryprops &= ~PropagationFlags.InheritOnly;

			if (this.npCheck.Checked) this.Entryprops |= PropagationFlags.NoPropagateInherit;
			else this.Entryprops &= ~PropagationFlags.NoPropagateInherit;

			if (this.ciCheck.Checked) this.Entryinhers |= InheritanceFlags.ContainerInherit;
			else this.Entryinhers &= ~InheritanceFlags.ContainerInherit;

			if (this.oiCheck.Checked) this.Entryinhers |= InheritanceFlags.ObjectInherit;
			else this.Entryinhers &= ~InheritanceFlags.ObjectInherit;
			/* ignore any change of the id flag. This is not the place to remove inherited ACEs. */

			this.Close();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Mr. Shah is a reclusive C++/C# developer lurking somewhere in the depths of the city of London. He learnt physics at Kings' College London and obtained a Master in Science there. Having earned an MCAD, he teeters on the brink of transitioning from C++ to C#, unsure of which language to jump to. Fortunately, he also knows how to use .NET interop to merge code between the two languages (which means he won't have to make the choice anytime soon).

His interests (apart from programming) are walking, football (the real one!), philosophy, history, retro-gaming, strategy gaming, and any good game in general.

He maintains a website / blog / FAQ / junk at shexec32.serveftp.net, where he places the best answers he's written to the questions you've asked. If you can find him, maybe you can hire Mr. Shah to help you with anything C++[/CLI]/C#/.NET related Smile | :) .

Comments and Discussions