Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

rtrestor.c File Reference

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include "cmp.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Defines

#define WORK_SIZE   1024

Functions

void __cdecl main (int, char *)
void processargs ()
void __cdecl main (int argc, char *argv[])
void processargs (int argc, char *argv[])

Variables

UNICODE_STRING KeyPath
WCHAR KeyPathBuffer [WORK_SIZE]
UNICODE_STRING FileName
WCHAR FileNameBuffer [WORK_SIZE]
BOOLEAN HiveVolatile


Define Documentation

#define WORK_SIZE   1024
 

Definition at line 37 of file rtrestor.c.


Function Documentation

void __cdecl main int  argc,
char *  argv[]
 

Definition at line 51 of file rtrestor.c.

References exit, FALSE, FileName, FileNameBuffer, HiveVolatile, KeyPath, KeyPathBuffer, L, NT_SUCCESS, NtCreateFile(), NtOpenKey(), NtRestoreKey(), NTSTATUS(), NULL, ObjectAttributes, processargs(), RtlAdjustPrivilege(), TRUE, and WORK_SIZE.

00055 { 00056 NTSTATUS status; 00057 OBJECT_ATTRIBUTES ObjectAttributes; 00058 IO_STATUS_BLOCK IoStatus; 00059 HANDLE FileHandle; 00060 HANDLE KeyHandle; 00061 BOOLEAN WasEnabled; 00062 00063 // 00064 // Process args 00065 // 00066 00067 KeyPath.MaximumLength = WORK_SIZE; 00068 KeyPath.Length = 0L; 00069 KeyPath.Buffer = &(KeyPathBuffer[0]); 00070 00071 FileName.MaximumLength = WORK_SIZE; 00072 FileName.Length = 0L; 00073 FileName.Buffer = &(FileNameBuffer[0]); 00074 00075 processargs(argc, argv); 00076 00077 00078 // 00079 // Set up and open FileName 00080 // 00081 00082 printf("rtrestor: starting\n"); 00083 00084 InitializeObjectAttributes( 00085 &ObjectAttributes, 00086 &FileName, 00087 0, 00088 (HANDLE)NULL, 00089 NULL 00090 ); 00091 ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; 00092 00093 status = NtCreateFile( 00094 &FileHandle, 00095 GENERIC_READ | SYNCHRONIZE, 00096 &ObjectAttributes, 00097 &IoStatus, 00098 0, // AllocationSize 00099 FILE_ATTRIBUTE_NORMAL, 00100 0, // ShareAccess 00101 FILE_OPEN_IF, 00102 FILE_SYNCHRONOUS_IO_NONALERT, 00103 NULL, // EaBuffer 00104 0 // EaLength 00105 ); 00106 00107 if (!NT_SUCCESS(status)) { 00108 printf("rtsave: file open failed status = %08lx\n", status); 00109 exit(1); 00110 } 00111 00112 InitializeObjectAttributes( 00113 &ObjectAttributes, 00114 &KeyPath, 00115 0, 00116 (HANDLE)NULL, 00117 NULL 00118 ); 00119 ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; 00120 00121 status = NtOpenKey( 00122 &KeyHandle, 00123 KEY_READ, 00124 &ObjectAttributes 00125 ); 00126 if (!NT_SUCCESS(status)) { 00127 printf("rtsave: key open failed status = %08lx\n", status); 00128 exit(1); 00129 } 00130 00131 RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, TRUE, FALSE, &WasEnabled); 00132 00133 if (HiveVolatile) { 00134 status = NtRestoreKey(KeyHandle, FileHandle, REG_WHOLE_HIVE_VOLATILE); 00135 } else { 00136 status = NtRestoreKey(KeyHandle, FileHandle, 0); 00137 } 00138 00139 RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, WasEnabled, FALSE, &WasEnabled); 00140 00141 if (!NT_SUCCESS(status)) { 00142 printf("rtrestor: NtRestorKey failed status = %08lx\n", status); 00143 exit(1); 00144 } 00145 00146 printf("rtsave: success\n"); 00147 exit(0); 00148 }

void __cdecl main int  ,
char * 
 

void processargs int  argc,
char *  argv[]
 

Definition at line 151 of file rtrestor.c.

References exit, FALSE, FileName, HiveVolatile, KeyPath, NULL, RtlAnsiStringToUnicodeString(), RtlDosPathNameToNtPathName_U(), RtlInitAnsiString(), and TRUE.

00155 { 00156 ANSI_STRING temp; 00157 UNICODE_STRING DosFileName; 00158 00159 if ( (argc < 3) || (argc > 4) ) 00160 { 00161 printf("Usage: %s <KeyName> <FileName> [VOLATILE]\n", 00162 argv[0]); 00163 exit(1); 00164 } 00165 00166 RtlInitAnsiString( 00167 &temp, 00168 argv[1] 00169 ); 00170 00171 RtlAnsiStringToUnicodeString( 00172 &KeyPath, 00173 &temp, 00174 TRUE 00175 ); 00176 00177 RtlInitAnsiString( 00178 &temp, 00179 argv[2] 00180 ); 00181 00182 RtlAnsiStringToUnicodeString( 00183 &DosFileName, 00184 &temp, 00185 TRUE 00186 ); 00187 00188 RtlDosPathNameToNtPathName_U( DosFileName.Buffer, 00189 &FileName, 00190 NULL, 00191 NULL); 00192 00193 if ((argc==4) && (_stricmp(argv[3],"volatile")==0)) { 00194 HiveVolatile = TRUE; 00195 } else { 00196 HiveVolatile = FALSE; 00197 } 00198 00199 return; 00200 }

void processargs  ) 
 


Variable Documentation

UNICODE_STRING FileName
 

Definition at line 45 of file rtrestor.c.

WCHAR FileNameBuffer[WORK_SIZE]
 

Definition at line 46 of file rtrestor.c.

BOOLEAN HiveVolatile
 

Definition at line 48 of file rtrestor.c.

Referenced by main(), and processargs().

UNICODE_STRING KeyPath
 

Definition at line 42 of file rtrestor.c.

WCHAR KeyPathBuffer[WORK_SIZE]
 

Definition at line 43 of file rtrestor.c.


Generated on Sat May 15 19:45:30 2004 for test by doxygen 1.3.7