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

rtsave.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1991 Microsoft Corporation 00004 00005 Module Name: 00006 00007 rtsave.c 00008 00009 Abstract: 00010 00011 NT level registry api test program, basic non-error paths. 00012 00013 Perform an NtSaveKey call to dump part of the registry to a file. 00014 00015 rtsave <KeyPath> <FileName> 00016 00017 Example: 00018 00019 rtsave \registry\machine\user userfile.rd 00020 00021 Author: 00022 00023 Bryan Willman (bryanwi) 22-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 void 00049 __cdecl main( 00050 int argc, 00051 char *argv[] 00052 ) 00053 { 00054 NTSTATUS status; 00055 OBJECT_ATTRIBUTES ObjectAttributes; 00056 IO_STATUS_BLOCK IoStatus; 00057 HANDLE FileHandle; 00058 HANDLE KeyHandle; 00059 BOOLEAN WasEnabled; 00060 00061 // 00062 // Process args 00063 // 00064 00065 KeyPath.MaximumLength = WORK_SIZE; 00066 KeyPath.Length = 0L; 00067 KeyPath.Buffer = &(KeyPathBuffer[0]); 00068 00069 FileName.MaximumLength = WORK_SIZE; 00070 FileName.Length = 0L; 00071 FileName.Buffer = &(FileNameBuffer[0]); 00072 00073 processargs(argc, argv); 00074 00075 00076 // 00077 // Set up and open FileName 00078 // 00079 00080 printf("rtsave: starting\n"); 00081 printf("rtsave: saving hive rooted at\n\t'%ws'\nto file\n\t'%ws'\n", 00082 KeyPath.Buffer, FileName.Buffer); 00083 00084 InitializeObjectAttributes( 00085 &ObjectAttributes, 00086 &FileName, 00087 0, 00088 (HANDLE)NULL, 00089 NULL 00090 ); 00091 ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; 00092 00093 00094 status = NtCreateFile( 00095 &FileHandle, 00096 GENERIC_WRITE | SYNCHRONIZE, 00097 &ObjectAttributes, 00098 &IoStatus, 00099 NULL, // AllocationSize 00100 FILE_ATTRIBUTE_NORMAL, 00101 FILE_SHARE_READ, // ShareAccess 00102 FILE_CREATE, 00103 FILE_SYNCHRONOUS_IO_NONALERT, 00104 NULL, // EaBuffer 00105 0 // EaLength 00106 ); 00107 00108 if (!NT_SUCCESS(status)) { 00109 if (status == STATUS_OBJECT_NAME_COLLISION) { 00110 printf("rtsave: file '%ws' already exists!\n", 00111 FileName.Buffer); 00112 exit(1); 00113 } 00114 printf("rtsave: file open failed status = %08lx\n", status); 00115 exit(1); 00116 } 00117 00118 InitializeObjectAttributes( 00119 &ObjectAttributes, 00120 &KeyPath, 00121 0, 00122 (HANDLE)NULL, 00123 NULL 00124 ); 00125 ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; 00126 00127 status = NtOpenKey( 00128 &KeyHandle, 00129 MAXIMUM_ALLOWED, 00130 &ObjectAttributes 00131 ); 00132 if (!NT_SUCCESS(status)) { 00133 printf("rtsave: key open failed status = %08lx\n", status); 00134 exit(1); 00135 } 00136 00137 RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE, TRUE, FALSE, &WasEnabled); 00138 00139 status = NtSaveKey(KeyHandle, FileHandle); 00140 00141 RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE, WasEnabled, FALSE, &WasEnabled); 00142 00143 if (!NT_SUCCESS(status)) { 00144 printf("rtsave: NtSaveKey failed status = %08lx\n", status); 00145 exit(1); 00146 } 00147 00148 printf("rtsave: success\n"); 00149 exit(0); 00150 } 00151 00152 void 00153 processargs( 00154 int argc, 00155 char *argv[] 00156 ) 00157 { 00158 ANSI_STRING temp; 00159 UNICODE_STRING DosFileName; 00160 00161 if ( (argc != 3) ) 00162 { 00163 printf("Usage: %s <KeyName> <FileName>\nWhere <FileName> does NOT already exist\n", 00164 argv[0]); 00165 printf("Example: %s \\registry\\machine\\security d:\\backups\\security\n", 00166 argv[0]); 00167 exit(1); 00168 } 00169 00170 RtlInitAnsiString( 00171 &temp, 00172 argv[1] 00173 ); 00174 00175 RtlAnsiStringToUnicodeString( 00176 &KeyPath, 00177 &temp, 00178 TRUE 00179 ); 00180 00181 RtlInitAnsiString( 00182 &temp, 00183 argv[2] 00184 ); 00185 00186 RtlAnsiStringToUnicodeString( 00187 &DosFileName, 00188 &temp, 00189 TRUE 00190 ); 00191 00192 RtlDosPathNameToNtPathName_U( DosFileName.Buffer, 00193 &FileName, 00194 NULL, 00195 NULL ); 00196 00197 return; 00198 }

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