Click here to Skip to main content
15,896,269 members
Articles / Programming Languages / C++

The Windows Access Control Model Part 4

Rate me:
Please Sign up or sign in to vote.
4.86/5 (29 votes)
7 Sep 200543 min read 229.2K   6.8K   100  
The final article in the access control series presents a guide to the access control editor and its associated ISecurityInformation interface.
/**
*	This code is by OShah. all code will have the following licence.
*	Copyright Shexec32. All code bears the following licence:
**/

/**
*	Copyright Shexec32 2004-2005. All rights reserved.
*
*	THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
*	ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
*	TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
*	PARTICULAR PURPOSE.
**/
#ifndef RAII_H
#define RAII_H
#pragma once


template<class DatType>
class sized_array
{/**	A simplified scoped_array class from Boost. This has copy semantics. For Anti-hacking technologies, we're
*	going to Zero all memory allocated. For STL compatibility, we are going to add a copy consructor and equality
*	operator. This makes it act more like a C99 VLA rather than an auto_ptr.
*	Due to the lack of export keyword support in many C++ compilers, I'll need to define the shared class here.
**/
protected:
	size_t Size;
	DatType * OurPtr;	/* The scope of this variable is determined by the object. */

	void CopyHelper(const std::basic_string<TCHAR> &OldClass)
	{
		/* always resize. */
		if(this->get_Size() < OldClass.size() + 1)
		{
			this->reset(OldClass.size() + 1);
		}
#ifndef _SCL_INSECURE_DEPRECATE
		OldClass.copy(this->get(), OldClass.size(), 0);
#else
		OldClass._Copy_s(this->get(), this->get_Size(), OldClass.size(), 0);
#endif /* _SCL_INSECURE_DEPRECATE */
	};

	void DoCopy(DatType *TheirPtr, size_t TheirSize)
	{
		std::copy<const DatType *, DatType *>(TheirPtr, TheirPtr + TheirSize, this->OurPtr);
	};

public:
	explicit sized_array (size_t len = 1) : OurPtr(NULL), Size(len)
	{
		if(len != 0)
		{
			this->OurPtr = new DatType[len];
			SecureZeroMemory(OurPtr, len * sizeof(DatType));
		}
	};

	sized_array(const sized_array &OldClass) : Size(OldClass.Size), OurPtr(new DatType[OldClass.Size])
	{
		DoCopy(OldClass.OurPtr, OldClass.Size);
		//std::copy<const DatType *, DatType *>(OldClass.OurPtr, OldClass.OurPtr + Size, OurPtr);
	};

	void reset(size_t len = 1)
	{/* Also called release and reallocate. */
		delete [] OurPtr;
		OurPtr = new DatType[len];
		SecureZeroMemory(OurPtr, len * sizeof(DatType));

		Size = len;
	};


	DatType *get(void) const
	{/* Accessor. Only get is currently implemented. */
		return OurPtr;
	};

	size_t get_Size(void) const
	{/* For Convenience */
		return Size;
	};


	sized_array &operator=(const sized_array &OldClass)
	{/* This equality may be required by CObjSecurity. */
		if(this==&OldClass) return *this;

		Size = OldClass.Size;
		this->reset(Size);
		DoCopy(OldClass.OurPtr, Size);
		return *this;
	};

	sized_array(const std::basic_string<DatType> &OldClass) : Size(0), OurPtr(NULL)
	{/* Copy contructor for strings */
		this->CopyHelper(OldClass);
	};

	sized_array &operator=(const std::basic_string<DatType> &OldClass)
	{
		this->CopyHelper(OldClass);
		return *this;
	};

	virtual ~sized_array()
	{
		delete [] OurPtr;
		OurPtr = NULL;
	};
};

#endif /* RAII_H */

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