/*++ Copyright (c) 1996 Microsoft Corporation Module Name: registry.c Abstract: This file provides access to the registry. Environment: WIN32 User Mode Author: Wesley Witt (wesw) 17-Feb-1996 --*/ #include "faxocm.h" #pragma hdrstop BOOL CreateDeviceProvider( HKEY hKey, LPWSTR ProviderKey, LPWSTR FriendlyName, LPWSTR ImageName, LPWSTR ProviderName ) { hKey = OpenRegistryKey( hKey, ProviderKey, TRUE, KEY_ALL_ACCESS ); if (!hKey) { DebugPrint(( L"could not create/open registry key (test)" )); return FALSE; } if (!SetRegistryString( hKey, REGVAL_FRIENDLY_NAME, FriendlyName )) { DebugPrint(( L"could not add friendly name value" )); return FALSE; } if (!SetRegistryStringExpand( hKey, REGVAL_IMAGE_NAME, ImageName )) { DebugPrint(( L"could not add image name value" )); return FALSE; } if (!SetRegistryString( hKey, REGVAL_PROVIDER_NAME, ProviderName )) { DebugPrint(( L"could not add provider name value" )); return FALSE; } RegCloseKey( hKey ); return TRUE; } BOOL CreateRoutingMethod( HKEY hKey, LPWSTR MethodName, LPWSTR FunctionName, LPWSTR FriendlyName, LPWSTR Guid, DWORD Priority ) { hKey = OpenRegistryKey( hKey, MethodName, TRUE, KEY_ALL_ACCESS ); if (!hKey) { DebugPrint(( L"could not create/open registry key for routing method" )); return FALSE; } if (!SetRegistryString( hKey, REGVAL_FUNCTION_NAME, FunctionName )) { DebugPrint(( L"could not add function name value" )); return FALSE; } if (!SetRegistryString( hKey, REGVAL_FRIENDLY_NAME, FriendlyName )) { DebugPrint(( L"could not add friendly name value" )); return FALSE; } if (!SetRegistryString( hKey, REGVAL_GUID, Guid )) { DebugPrint(( L"could not add function name value" )); return FALSE; } if (!SetRegistryDword( hKey, REGVAL_ROUTING_PRIORITY, Priority )) { DebugPrint(( L"Could not set priority registry value" )); } RegCloseKey( hKey ); return TRUE; } BOOL CreateMicrosoftRoutingExtension( HKEY hKey, LPWSTR RoutingKey, LPWSTR FriendlyName, LPWSTR ImageName ) { HKEY hKeyMethods; hKey = OpenRegistryKey( hKey, RoutingKey, TRUE, KEY_ALL_ACCESS ); if (!hKey) { DebugPrint(( L"could not create/open registry key for routing extension" )); return FALSE; } if (!SetRegistryString( hKey, REGVAL_FRIENDLY_NAME, FriendlyName )) { DebugPrint(( L"could not add friendly name value" )); return FALSE; } if (!SetRegistryStringExpand( hKey, REGVAL_IMAGE_NAME, ImageName )) { DebugPrint(( L"could not add image name value" )); return FALSE; } hKeyMethods = OpenRegistryKey( hKey, REGKEY_ROUTING_METHODS, TRUE, KEY_ALL_ACCESS ); if (!hKeyMethods) { DebugPrint(( L"could not create/open registry key for routing methods" )); return FALSE; } CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_EMAIL, REGVAL_RM_EMAIL_FUNCTION, GetString(IDS_RT_EMAIL_FRIENDLY), REGVAL_RM_EMAIL_GUID, 4 ); CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_FOLDER, REGVAL_RM_FOLDER_FUNCTION, GetString(IDS_RT_FOLDER_FRIENDLY), REGVAL_RM_FOLDER_GUID, 1 ); CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_INBOX, REGVAL_RM_INBOX_FUNCTION, GetString(IDS_RT_INBOX_FRIENDLY), REGVAL_RM_INBOX_GUID, 3 ); CreateRoutingMethod( hKeyMethods, REGKEY_ROUTING_METHOD_PRINTING, REGVAL_RM_PRINTING_FUNCTION, GetString(IDS_RT_PRINT_FRIENDLY), REGVAL_RM_PRINTING_GUID, 2 ); RegCloseKey( hKeyMethods ); RegCloseKey( hKey ); return TRUE; } VOID RegCreateFaxDevice( HKEY hKeyDev, DWORD PermanentLineID, DWORD Rings, DWORD Priority, DWORD Flags, LPWSTR DeviceName, LPWSTR ProviderName, LPWSTR Csid, LPWSTR Tsid, DWORD RoutingMask, LPWSTR RoutePrinterName, LPWSTR RouteDir, LPWSTR RouteProfile ) { HKEY hKey; HKEY hKeyRouting; WCHAR PortName[32]; swprintf( PortName, L"%08d", PermanentLineID ); hKey = OpenRegistryKey( hKeyDev, PortName, TRUE, KEY_ALL_ACCESS ); if (!hKey) { DebugPrint(( L"Could not open device registry key" )); return; } if (!SetRegistryDword( hKey, REGVAL_PERMANENT_LINEID, PermanentLineID )) { DebugPrint(( L"Could not set device id registry value" )); } if (!SetRegistryDword( hKey, REGVAL_FLAGS, Flags )) { DebugPrint(( L"Could not set device flags registry value" )); } if (!SetRegistryDword( hKey, REGVAL_RINGS, Rings )) { DebugPrint(( L"Could not set device rings registry value" )); } if (!SetRegistryDword( hKey, REGVAL_PRIORITY, Priority )) { DebugPrint(( L"Could not set device rings registry value" )); } if (!SetRegistryString( hKey, REGVAL_DEVICE_NAME, DeviceName )) { DebugPrint(( L"Could not set device name registry value" )); } if (!SetRegistryString( hKey, REGVAL_PROVIDER, ProviderName )) { DebugPrint(( L"Could not set provider name registry value" )); } if (!SetRegistryString( hKey, REGVAL_ROUTING_CSID, Csid )) { DebugPrint(( L"Could not set csid registry value" )); } if (!SetRegistryString( hKey, REGVAL_ROUTING_TSID, Tsid )) { DebugPrint(( L"Could not set csid registry value" )); } hKeyRouting = OpenRegistryKey( hKey, REGKEY_ROUTING, TRUE, KEY_ALL_ACCESS ); if (!hKeyRouting) { DebugPrint(( L"Could not open routing registry key" )); return; } if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_PRINTER, RoutePrinterName )) { DebugPrint(( L"Could not set printer name registry value" )); } if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_DIR, RouteDir )) { DebugPrint(( L"Could not set routing dir registry value" )); } if (!SetRegistryString( hKeyRouting, REGVAL_ROUTING_PROFILE, RouteProfile )) { DebugPrint(( L"Could not set routing profile name registry value" )); } if (!SetRegistryDword( hKeyRouting, REGVAL_ROUTING_MASK, RoutingMask )) { DebugPrint(( L"Could not set routing mask registry value" )); } RegCloseKey( hKeyRouting ); RegCloseKey( hKey ); } BOOL CreateFileAssociation( LPWSTR FileExtension, LPWSTR FileAssociationName, LPWSTR FileAssociationDescription, LPWSTR OpenCommand, LPWSTR PrintCommand, LPWSTR PrintToCommand, LPWSTR FileName, DWORD IconIndex ) { LONG rVal = 0; HKEY hKey = NULL; HKEY hKeyOpen = NULL; HKEY hKeyPrint = NULL; HKEY hKeyPrintTo = NULL; HKEY hKeyIcon = NULL; DWORD Disposition = 0; WCHAR Buffer[MAX_PATH*2]; rVal = RegCreateKeyEx( HKEY_CLASSES_ROOT, FileExtension, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &Disposition ); if (rVal != ERROR_SUCCESS) { goto exit; } rVal = RegSetValueEx( hKey, NULL, 0, REG_SZ, (LPBYTE) FileAssociationName, StringSize( FileAssociationName ) ); if (rVal != ERROR_SUCCESS) { goto exit; } RegCloseKey( hKey ); rVal = RegCreateKeyEx( HKEY_CLASSES_ROOT, FileAssociationName, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &Disposition ); if (rVal != ERROR_SUCCESS) { goto exit; } rVal = RegSetValueEx( hKey, NULL, 0, REG_SZ, (LPBYTE) FileAssociationDescription, StringSize( FileAssociationDescription ) ); if (rVal != ERROR_SUCCESS) { goto exit; } rVal = RegCreateKeyEx( hKey, L"Shell\\Open\\Command", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKeyOpen, &Disposition ); if (rVal != ERROR_SUCCESS) { goto exit; } rVal = RegSetValueEx( hKeyOpen, NULL, 0, REG_EXPAND_SZ, (LPBYTE) OpenCommand, StringSize( OpenCommand ) ); if (rVal != ERROR_SUCCESS) { goto exit; } if (PrintCommand) { rVal = RegCreateKeyEx( hKey, L"Shell\\Print\\Command", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKeyPrint, &Disposition ); if (rVal != ERROR_SUCCESS) { goto exit; } rVal = RegSetValueEx( hKeyPrint, NULL, 0, REG_EXPAND_SZ, (LPBYTE) PrintCommand, StringSize( PrintCommand ) ); if (rVal != ERROR_SUCCESS) { goto exit; } } if (PrintToCommand) { rVal = RegCreateKeyEx( hKey, L"Shell\\Printto\\Command", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKeyPrintTo, &Disposition ); if (rVal != ERROR_SUCCESS) { goto exit; } rVal = RegSetValueEx( hKeyPrintTo, NULL, 0, REG_EXPAND_SZ, (LPBYTE) PrintToCommand, StringSize( PrintToCommand ) ); if (rVal != ERROR_SUCCESS) { goto exit; } } if (FileName) { rVal = RegCreateKeyEx( hKey, L"DefaultIcon", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKeyIcon, &Disposition ); if (rVal != ERROR_SUCCESS) { goto exit; } wsprintf( Buffer, L"%s,%d", FileName, IconIndex ); rVal = RegSetValueEx( hKeyIcon, NULL, 0, REG_EXPAND_SZ, (LPBYTE) Buffer, StringSize( Buffer ) ); if (rVal != ERROR_SUCCESS) { goto exit; } } exit: RegCloseKey( hKey ); RegCloseKey( hKeyOpen ); RegCloseKey( hKeyPrint ); RegCloseKey( hKeyPrintTo ); RegCloseKey( hKeyIcon ); return rVal == ERROR_SUCCESS; } BOOL SetServerRegistryData( LPWSTR SourceRoot ) { HKEY hKey; LONG rVal; DWORD i; HKEY hKeyDev; HANDLE hNull; STARTUPINFO si; PROCESS_INFORMATION pi; WCHAR CmdLine[128]; LPWSTR LodCmdLine; LPWSTR LodSrcPath; // // set top level defaults // hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_SOFTWARE, TRUE, KEY_ALL_ACCESS ); if (!hKey) { DebugPrint(( L"Could not open software registry key" )); return FALSE; } if (!Upgrade) { if (!SetKeySecurity(hKey) ) { DebugPrint(( L"Couldn't set key security" )); return FALSE; } } if (!Upgrade) { if (!SetRegistryDword( hKey, REGVAL_RETRIES, DEFAULT_REGVAL_RETRIES )) { DebugPrint(( L"Could not set retries registry value" )); } if (!SetRegistryDword( hKey, REGVAL_RETRYDELAY, DEFAULT_REGVAL_RETRYDELAY )) { DebugPrint(( L"Could not set retry delay registry value" )); } if (!SetRegistryDword( hKey, REGVAL_DIRTYDAYS, DEFAULT_REGVAL_DIRTYDAYS )) { DebugPrint(( L"Could not set dirty days registry value" )); } if (!SetRegistryDword( hKey, REGVAL_QUEUE_PAUSED, DEFAULT_REGVAL_QUEUE_PAUSED )) { DebugPrint(( L"Could not set queue paused registry value" )); } if (!SetRegistryDword( hKey, REGVAL_JOB_NUMBER, DEFAULT_REGVAL_JOB_NUMBER )) { DebugPrint(( L"Could not net job number registry value" )); } if (!SetRegistryDword( hKey, REGVAL_BRANDING, DEFAULT_REGVAL_BRANDING )) { DebugPrint(( L"Could not set branding registry value" )); } if (!SetRegistryDword( hKey, REGVAL_USE_DEVICE_TSID, DEFAULT_REGVAL_USEDEVICETSID )) { DebugPrint(( L"Could not set usedevicetsid registry value" )); } if (!SetRegistryString( hKey, REGVAL_INBOUND_PROFILE, EMPTY_STRING )) { DebugPrint(( L"Could not set inbound profile registry value" )); } if (!SetRegistryDword( hKey, REGVAL_SERVERCP, DEFAULT_REGVAL_SERVERCP )) { DebugPrint(( L"Could not set servercp registry value" )); } if (!SetRegistryDword( hKey, REGVAL_STARTCHEAP, DEFAULT_REGVAL_STARTCHEAP )) { DebugPrint(( L"Could not set startcheap registry value" )); } if (!SetRegistryDword( hKey, REGVAL_STOPCHEAP, DEFAULT_REGVAL_STOPCHEAP )) { DebugPrint(( L"Could not set stopcheap registry value" )); } if (WizData.ArchiveOutgoing) { if (!SetRegistryDword( hKey, REGVAL_ARCHIVEFLAG, 1 )) { DebugPrint(( L"Could not set archiveflag registry value" )); } if (!SetRegistryString( hKey, REGVAL_ARCHIVEDIR, WizData.ArchiveDir )) { DebugPrint(( L"Could not set archive dir registry value" )); } } RegCloseKey( hKey ); } if (!Upgrade) { hKeyDev = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_FAX_DEVICES, TRUE, KEY_ALL_ACCESS ); if (!hKey) { DebugPrint(( L"Could not open devices registry key" )); return FALSE; } // // enumerate the devices and create the registry data // for (i=0; iAceCount;i++) { if (!GetAce(Dacl,i,(LPVOID *) &CurrentAce) ) { DebugPrint(( TEXT("Couldn't GetAce, ec = %d\n"), GetLastError() )); break; } CurrentSid = (PSID) &CurrentAce->SidStart; if (EqualSid(EveryoneSid,CurrentSid)) { CurrentAce->Mask &= ~(KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK | DELETE); } } rslt = SetSecurityInfo( hKey, // handle to the object SE_REGISTRY_KEY, // type of object DACL_SECURITY_INFORMATION,// type of security information to set NULL,// pointer to the new owner SID NULL,// pointer to the new primary group SID Dacl,//NewDAcl // pointer to the new DACL NULL // pointer to the new SACL ); if (rslt != ERROR_SUCCESS) { DebugPrint(( TEXT("Couldn't SetSecurityInfo, ec = %d\n"), rslt )); } else { DebugPrint(( TEXT("SetSecurityInfo succeeded, ec = %d\n"), rslt )); } // // cleanup // FreeSid(EveryoneSid); LocalFree(pSecurityDescriptor); return rslt==ERROR_SUCCESS ? TRUE : FALSE; }