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

rttrecpy.c File Reference

#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 argc, char *)
void processargs ()
void Copy (HANDLE Source, HANDLE Dest)
void __cdecl main (int argc, char *argv[])
void processargs (int argc, char *argv[])

Variables

UNICODE_STRING SourceName
UNICODE_STRING DestName
BOOLEAN CopySecurity


Define Documentation

#define WORK_SIZE   1024
 

Definition at line 36 of file rttrecpy.c.


Function Documentation

void Copy HANDLE  Source,
HANDLE  Dest
 

Definition at line 114 of file rttrecpy.c.

References CopySecurity, exit, KeyName, NT_SUCCESS, NtClose(), NtCreateKey(), NtEnumerateKey(), NtEnumerateValueKey(), NtOpenKey(), NtQuerySecurityObject(), NtSetValueKey(), NTSTATUS(), NULL, ObjectAttributes, Status, TRUE, ValueName, and WORK_SIZE.

Referenced by main().

00118 { 00119 NTSTATUS Status; 00120 PKEY_BASIC_INFORMATION KeyInformation; 00121 PKEY_VALUE_FULL_INFORMATION KeyValue; 00122 OBJECT_ATTRIBUTES ObjectAttributes; 00123 ULONG NamePos; 00124 ULONG index; 00125 STRING enumname; 00126 HANDLE SourceChild; 00127 HANDLE DestChild; 00128 ULONG ResultLength; 00129 static char buffer[WORK_SIZE]; 00130 static char SecurityBuffer[WORK_SIZE]; 00131 PSECURITY_DESCRIPTOR SecurityDescriptor; 00132 UNICODE_STRING ValueName; 00133 UNICODE_STRING KeyName; 00134 00135 00136 // 00137 // Enumerate source node's values and copy them to target node. 00138 // 00139 KeyValue = (PKEY_VALUE_FULL_INFORMATION)buffer; 00140 for (index = 0; TRUE; index++) { 00141 Status = NtEnumerateValueKey(Source, 00142 index, 00143 KeyValueFullInformation, 00144 buffer, 00145 WORK_SIZE, 00146 &ResultLength); 00147 00148 if (!NT_SUCCESS(Status)) { 00149 if (Status == STATUS_NO_MORE_ENTRIES) { 00150 00151 // 00152 // done with the values 00153 // 00154 break; 00155 } else { 00156 printf("rttrecpy: NtEnumerateValueKey failed %08lx\n",Status); 00157 break; 00158 } 00159 } 00160 00161 ValueName.Buffer = KeyValue->Name; 00162 ValueName.Length = KeyValue->NameLength; 00163 00164 Status = NtSetValueKey(Dest, 00165 &ValueName, 00166 KeyValue->TitleIndex, 00167 KeyValue->Type, 00168 buffer+KeyValue->DataOffset, 00169 KeyValue->DataLength); 00170 if (!NT_SUCCESS(Status)) { 00171 printf("rttrecpy: NtSetValueKey failed to set value %wS\n",&ValueName); 00172 } 00173 00174 } 00175 00176 // 00177 // Enumerate node's children and apply ourselves to each one 00178 // 00179 00180 KeyInformation = (PKEY_BASIC_INFORMATION)buffer; 00181 if (CopySecurity) { 00182 SecurityDescriptor = SecurityBuffer; 00183 } else { 00184 SecurityDescriptor = NULL; 00185 } 00186 for (index = 0; TRUE; index++) { 00187 00188 Status = NtEnumerateKey(Source, 00189 index, 00190 KeyBasicInformation, 00191 KeyInformation, 00192 WORK_SIZE, 00193 &ResultLength); 00194 00195 if (Status == STATUS_NO_MORE_ENTRIES) { 00196 00197 break; 00198 00199 } else if (!NT_SUCCESS(Status)) { 00200 printf("rttrecpy: NtEnumerateKey failed Status = %08lx\n", Status); 00201 exit(1); 00202 } 00203 00204 KeyName.Buffer = KeyInformation->Name; 00205 KeyName.Length = KeyInformation->NameLength; 00206 00207 InitializeObjectAttributes( 00208 &ObjectAttributes, 00209 &KeyName, 00210 OBJ_CASE_INSENSITIVE, 00211 Source, 00212 NULL 00213 ); 00214 00215 Status = NtOpenKey( 00216 &SourceChild, 00217 KEY_READ, 00218 &ObjectAttributes 00219 ); 00220 if (!NT_SUCCESS(Status)) { 00221 printf("rttrecpy: NtOpenKey %wS failed: %08lx\n", Status); 00222 exit(1); 00223 } 00224 00225 if (CopySecurity) { 00226 Status = NtQuerySecurityObject(SourceChild, 00227 DACL_SECURITY_INFORMATION, 00228 SecurityDescriptor, 00229 WORK_SIZE, 00230 &ResultLength); 00231 if (!NT_SUCCESS(Status)) { 00232 printf("rttrecpy: NtQuerySecurityObject failed %08lx\n",Status); 00233 } 00234 } 00235 00236 InitializeObjectAttributes(&ObjectAttributes, 00237 &KeyName, 00238 OBJ_CASE_INSENSITIVE, 00239 Dest, 00240 SecurityDescriptor); 00241 Status = NtCreateKey(&DestChild, 00242 KEY_READ | KEY_WRITE, 00243 &ObjectAttributes, 00244 0, 00245 NULL, 00246 0, 00247 NULL); 00248 if (!NT_SUCCESS(Status)) { 00249 printf("rttrecpy: NtCreateKey %wS failed %08lx\n",Status); 00250 exit(1); 00251 } 00252 00253 Copy(SourceChild, DestChild); 00254 NtClose(SourceChild); 00255 NtClose(DestChild); 00256 00257 } 00258 00259 return; 00260 }

void __cdecl main int  argc,
char *  argv[]
 

Definition at line 52 of file rttrecpy.c.

References Copy(), DestName, exit, NT_SUCCESS, NtCreateKey(), NtOpenKey(), NTSTATUS(), NULL, ObjectAttributes, processargs(), SourceName, and Status.

00056 { 00057 NTSTATUS Status; 00058 OBJECT_ATTRIBUTES ObjectAttributes; 00059 HANDLE SourceHandle; 00060 HANDLE DestHandle; 00061 00062 // 00063 // Process args 00064 // 00065 processargs(argc, argv); 00066 00067 00068 // 00069 // Set up and open KeyPath 00070 // 00071 00072 printf("rttrecpy: starting\n"); 00073 00074 InitializeObjectAttributes( 00075 &ObjectAttributes, 00076 &SourceName, 00077 OBJ_CASE_INSENSITIVE, 00078 (HANDLE)NULL, 00079 NULL 00080 ); 00081 00082 Status = NtOpenKey( 00083 &SourceHandle, 00084 KEY_READ, 00085 &ObjectAttributes 00086 ); 00087 if (!NT_SUCCESS(Status)) { 00088 printf("rttrecpy: NtOpenKey %wS failed %08lx\n", &SourceName, Status); 00089 exit(1); 00090 } 00091 00092 InitializeObjectAttributes(&ObjectAttributes, 00093 &DestName, 00094 OBJ_CASE_INSENSITIVE, 00095 NULL, 00096 NULL); 00097 Status = NtCreateKey(&DestHandle, 00098 KEY_WRITE, 00099 &ObjectAttributes, 00100 0, 00101 NULL, 00102 0, 00103 NULL); 00104 if (!NT_SUCCESS(Status)) { 00105 printf("rttrecpy: NtCreateKey %wS failed %08lx\n",DestName,Status); 00106 exit(1); 00107 } 00108 00109 Copy(SourceHandle, DestHandle); 00110 }

void __cdecl main int  argc,
char * 
 

void processargs int  argc,
char *  argv[]
 

Definition at line 264 of file rttrecpy.c.

References CopySecurity, DestName, exit, FALSE, RtlAnsiStringToUnicodeString(), RtlInitAnsiString(), SourceName, and TRUE.

00268 { 00269 ANSI_STRING temp; 00270 char **p; 00271 00272 if ( (argc > 4) || (argc < 3) ) 00273 { 00274 printf("Usage: %s [-s] <SourceKey> <DestKey>\n", 00275 argv[0]); 00276 exit(1); 00277 } 00278 00279 p=argv+1; 00280 if (_stricmp(*p,"-s")==0) { 00281 CopySecurity = TRUE; 00282 ++p; 00283 } else { 00284 CopySecurity = FALSE; 00285 } 00286 00287 RtlInitAnsiString( 00288 &temp, 00289 *p 00290 ); 00291 00292 ++p; 00293 00294 RtlAnsiStringToUnicodeString( 00295 &SourceName, 00296 &temp, 00297 TRUE 00298 ); 00299 00300 RtlInitAnsiString(&temp, 00301 *p); 00302 00303 RtlAnsiStringToUnicodeString(&DestName, 00304 &temp, 00305 TRUE); 00306 00307 return; 00308 }

void processargs  ) 
 


Variable Documentation

BOOLEAN CopySecurity
 

Definition at line 49 of file rttrecpy.c.

Referenced by Copy(), and processargs().

UNICODE_STRING DestName
 

Definition at line 48 of file rttrecpy.c.

Referenced by main(), and processargs().

UNICODE_STRING SourceName
 

Definition at line 47 of file rttrecpy.c.

Referenced by main(), and processargs().


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