Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

Go to top

Low-level Security Classes

, 1 Mar 2000
A set of classes to encapsulate the Win32 Security APIs
secdesc_demo.zip
secdesc.dsw
testSD.dsp
testSD.exe
secdesc_src.zip
#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

Share

About the Author

Peter Kenyon
Web Developer
New Zealand New Zealand
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 2 Mar 2000
Article Copyright 2000 by Peter Kenyon
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid