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

rtrestor.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1991 Microsoft Corporation 00004 00005 Module Name: 00006 00007 rtrestor.c 00008 00009 Abstract: 00010 00011 NT level registry api test program, basic non-error paths. 00012 00013 Perform an NtRestoreKey call to load part of the registry from a file. 00014 00015 rtrestor <KeyPath> <FileName> 00016 00017 Example: 00018 00019 rtrestor \registry\machine\user userfile.rd 00020 00021 Author: 00022 00023 Bryan Willman (bryanwi) 24-Jan-92 00024 00025 Revision History: 00026 00027 --*/ 00028 #include <nt.h> 00029 #include <ntrtl.h> 00030 #include <nturtl.h> 00031 00032 #include "cmp.h" 00033 #include <stdio.h> 00034 #include <stdlib.h> 00035 #include <string.h> 00036 00037 #define WORK_SIZE 1024 00038 00039 void __cdecl main(int, char *); 00040 void processargs(); 00041 00042 UNICODE_STRING KeyPath; 00043 WCHAR KeyPathBuffer[WORK_SIZE]; 00044 00045 UNICODE_STRING FileName; 00046 WCHAR FileNameBuffer[WORK_SIZE]; 00047 00048 BOOLEAN HiveVolatile; 00049 00050 void 00051 __cdecl main( 00052 int argc, 00053 char *argv[] 00054 ) 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 } 00149 00150 void 00151 processargs( 00152 int argc, 00153 char *argv[] 00154 ) 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 }

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