Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C

Domain authentication based on-the-fly encryption/decryption system for USB storage devices

Rate me:
Please Sign up or sign in to vote.
4.22/5 (7 votes)
27 Feb 2008CPOL8 min read 49.3K   2.5K   50  
Encrypts/Decrypts files on a USB within a domain,on the fly.

#ifndef _USBCNTLSDMGR_H  /* not _USBCNTLSDMGR_H */
#define _USBCNTLSDMGR_H

//--------------------------------------------------------------------
// Include

#include <windows.h>
#include <tchar.h>

#include <string>
#include <winspool.h>

using namespace std;

//! System user-name
#define USBCNTL_SYSTEM_USER				L"system"
//! Everyone user-name
#define USBCNTL_EVERY_USER				L"Everyone"

//! Size of domain name buffer
#define SD_BUFSIZE_DOMAINNAME		1024

//! Succession right used when management authority of document of printer is given
#define PRINTER_INHERIT (OBJECT_INHERIT_ACE | INHERIT_ONLY_ACE)

// Kind of right of access
typedef struct {
	DWORD	All;
	DWORD	Write;
	DWORD	Read;
} USBCNTL_RSRC_ACCESSMASK;


/*@
  @class	CUSBCntlSdMgr
  @brief	Security descriptor control class
  @variable	+SECURITY_ATTRIBUTES	m_SecAttr			:SECURITY_ATTRIBUTES structure
  @variable	#PSECURITY_DESCRIPTOR	m_pSecDesc			:Pointer of security descriptor
  @variable	#PSID					m_pSid				:Pointer of SID
  @variable	#PSID					m_pSidSystemUser	:Pointer of system user SID
  @variable	#PSID					m_pSidEveryUser		:Pointer of EveryOne user SID
  @variable	#PACL					m_pAcl				:Pointer to access control list
  @*/
class CUSBCntlSdMgr
{
public:
	CUSBCntlSdMgr(void);
	~CUSBCntlSdMgr(void);

protected:
//public:
	PSECURITY_DESCRIPTOR m_pSecDesc;
	PSID m_pSid;
	PSID m_pSidSystemUser;
	PSID m_pSidEveryUser;
	PACL m_pAcl;


public:

	typedef enum tag_USBCNTL_RESOURCE_ID {
		driFile = 0,
		driEvent,
		driMutex,
		driReg,
		driShMem,
		driPrinter,
		driMax
	};

	SECURITY_ATTRIBUTES m_SecAttr;

	// Initialization
	BOOL InitSecDesc(void);
	// Close of resource
	BOOL Close(void);

	// Everyone full access
	BOOL GenerateSdOfEveryoneFullAccess(DWORD dwRsrcId);
	// Only Admin full access
	BOOL GenerateSdOfOnlyAdminAccess(DWORD dwRsrcId);

	// Only the reference Admin full accesses Everyone. 
	BOOL GenerateSdOfEveryoneReadOnly(DWORD dwRsrcId);
	// EVeryone and Admin full access
	BOOL GenerateSdOfSystemAndEveryoneFullAccess(DWORD dwRsrcId);

	// Only System full is accessed. 
	BOOL GenerateSdOfSystemFullAccess(DWORD dwRsrcId);

	// One user's SID is acquired. 
	BOOL GetSid(PWCHAR pwszUserName, PSID& pSid);

	// One user's SECURITY_DESCRIPTOR is made. 
	BOOL GetSecdesc(PWCHAR pwszUserName, DWORD dwAccessMask);
};

#endif /* end _USBCNTLSDMGR_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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) NEC HCL System Technologies Ltd, India
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions