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

Low-level Security Classes

Rate me:
Please Sign up or sign in to vote.
4.73/5 (13 votes)
1 Mar 2000 147.3K   2.4K   31  
A set of classes to encapsulate the Win32 Security APIs
#include "secdesc.h"



int main( int argc)
{

	// Initialize 2 EXPLICIT_ACCESS structures: 1 for Everyone,
	// 1 for Administrators. Assign KEY_READ privileges to Everyone
	// and KEY_ALL_ACCESS priviliges to Administrators.
	EXPLICIT_ACCESS ea[2];

	ea[0] = CExplicitAccess(KEY_READ, SET_ACCESS, NO_INHERITANCE, 
		CTrustee(TRUSTEE_IS_WELL_KNOWN_GROUP, 
			CSid(CSid::WST_EVERYONE)));

	ea[1] = CExplicitAccess(KEY_ALL_ACCESS, SET_ACCESS, NO_INHERITANCE,
		CTrustee(TRUSTEE_IS_GROUP, 
			CSid(CSid::WST_LOCALADMINS)));
	
	// Create a new ACL and set the EA entries in it
	CAcl acl;
	if(acl.SetEntriesInAcl(2, ea) == ERROR_SUCCESS)
	{

		// Initialize a security descriptor and add our ACL to it  
		CSecurityDescriptor sd;
		if(sd.SetSecurityDescriptorDacl(
			TRUE,     // fDaclPresent flag   
			acl, 
			FALSE))   // not a default DACL 
		{

			// Initialize a security attributes structure.
			CSecurityAttributes sa(sd, FALSE);

			// Use the security attributes to set the security descriptor 
			// when you create a key.
			DWORD	dwDisposition;
			HKEY	hKey;
 
			RegCreateKeyEx(HKEY_CURRENT_USER, "mykey1", 0, "", 0, 
				KEY_READ | KEY_WRITE, sa, &hKey, &dwDisposition); 

		}

	}


	return GetLastError();

}

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
New Zealand New Zealand
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions