/*++ Copyright (c) 1996 Microsoft Corporation Module Name: rollback.c Abstract: Main module for program that rolls back the system to the state it was in at the end of text mode setup. Author: Ted Miller (tedm) 13-Mar-1996 Revision History: --*/ #include "rollback.h" #pragma hdrstop // // Program exit codes. // #define RC_SUCCESS 0 #define RC_FAILURE 1 // // Handle to this module, filled in at init time. // HMODULE ThisModule; // // Table telling us which files we care about for rollback. // struct { // // Key and subkey that is at the root of the hive. // HKEY RootKey; PCWSTR Subkey; // // Name active hive has in the config directory. // PCWSTR Hive; // // Name of backup hive made at the end of text mode setup // (ie, *.sav) // PCWSTR BackupHive; // // Name to use for new hive file, that will be the hive // at next boot. // PCWSTR NewHive; // // Name to use for current hive file, that will be deleted // on next boot. // PCWSTR DeleteHive; } HiveTable[3] = { // // System hive. This MUST be entry 0 -- other code depends on it! // { HKEY_LOCAL_MACHINE, L"SYSTEM" , L"SYSTEM" , L"SYSTEM.SAV" , L"SYS$$$$$.$$$", L"SYS$$$$$.DEL" }, // // Software hive // { HKEY_LOCAL_MACHINE, L"SOFTWARE", L"SOFTWARE", L"SOFTWARE.SAV", L"SOF$$$$$.$$$", L"SOF$$$$$.DEL" }, // // Default user hive // { HKEY_USERS , L".DEFAULT", L"DEFAULT" , L"DEFAULT.SAV" , L"DEF$$$$$.$$$", L"DEF$$$$$.DEL " } }; // // Define name of key used for loading temporary system hive. // #define TEMP_SYSHIVE_KEY L"$$$TEMPSYS" // // Name of delete list value in session manager, used by MoveFileEx(). // PCWSTR szDeleteListValue = L"PendingFileRenameOperations"; BOOL MakeNewHives( VOID ); BOOL BuildDeleteList( VOID ); BOOL ProcessNewSystemHive( VOID ); BOOL ShuffleHives( VOID ); int _CRTAPI1 main( IN int argc, IN char *argv[] ) { ThisModule = GetModuleHandle(NULL); Message(FALSE,MSG_BANNER); // // Make sure we are administrator and enable restore privilege. // if(!IsUserAdmin()) { Message(FALSE,MSG_NOT_ADMIN); return(RC_FAILURE); } if(!EnablePrivilege(SE_RESTORE_NAME,TRUE) || !EnablePrivilege(SE_SHUTDOWN_NAME,TRUE)) { Message(FALSE,MSG_NO_PRIVILEGE); return(RC_FAILURE); } // // Make copies of the backup (.sav) hives. These will be used with // RegReplaceKey, later. // if(!MakeNewHives()) { return(RC_FAILURE); } // // Build the list of files that will have to get deleted from // the system directory. // if(!BuildDeleteList()) { return(RC_FAILURE); } // // Special processing for the system hive. We have to set the RestartSetup // value to 0, and transfer the delete list into it. // if(!ProcessNewSystemHive()) { return(RC_FAILURE); } // // Replace hives in use by newly made copies on next boot. // if(!ShuffleHives()) { return(RC_FAILURE); } // // Done. // Message(FALSE,MSG_SUCCESS); return(RC_SUCCESS); } BOOL MakeNewHives( VOID ) /*++ Routine Description: Verify that all required files are present by looking through HiveTable and checking for the presence of the file named by BackupHive, in the system32\config directory. Make copies of each such file, using the name specified for NewHive. If a file is not present or a copy operation fails a message will be printed out. Arguments: None. Return Value: Boolean value indicating outcome. --*/ { int i; WCHAR Name1[MAX_PATH],Name2[MAX_PATH]; for(i=0; i