/**********************************************/
/*                                            */    
/* iPerms.cpp                                 */
/*                                            */
/* permissions management                     */
/*                                            */
/* scol v 4                                   */
/*                                            */
/**********************************************/



#include <windows.h>


#define CRYONETWORKS_KEYPATH "Software\\Cryo-Networks\\"







/**********************************************/
/*                                            */    
/* BOOL iperms_IsUserAuthorized()             */
/*                                            */
/* return 0 if the user is authorized to      */
/* write in registry, HKEY_LOCAL_MACHINE.     */
/* returns non zero if he's authorized        */
/*                                            */
/**********************************************/

BOOL iperms_IsUserAuthorized()
{
HKEY tmpKey;
byte data = 0;

	//open or create the Cryo-Networks software local key
	if ((RegCreateKeyEx (HKEY_LOCAL_MACHINE, CRYONETWORKS_KEYPATH, 0,
			NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &tmpKey, NULL)) != ERROR_SUCCESS)
		return 0;


	//write value 
	if ((RegSetValueEx (tmpKey, "tmp", 0, (DWORD)REG_BINARY, &data, sizeof(byte))) != ERROR_SUCCESS)
	{
		RegCloseKey (tmpKey);
		return 0;
	}

	//remove value 
	if ((RegDeleteValue (tmpKey, "tmp")) != ERROR_SUCCESS)
	{
		RegCloseKey (tmpKey);
		return 0;
	}


	RegCloseKey (tmpKey);
	return 1;
}