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     
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                 
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     
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 }