Use only NtCreateKey and better suited access rights.
[reactos.git] / reactos / lib / kernel32 / file / move.c
index 23c1cba..2b93dc1 100644 (file)
@@ -72,14 +72,12 @@ static BOOL add_boot_rename_entry( LPCWSTR source, LPCWSTR dest, DWORD flags )
     static const WCHAR ValueName[] = {'P','e','n','d','i','n','g',
                                       'F','i','l','e','R','e','n','a','m','e',
                                       'O','p','e','r','a','t','i','o','n','s',0};
-    static const WCHAR SessionW[] = {'M','a','c','h','i','n','e','\\',
-                                     'S','y','s','t','e','m','\\',
-                                     'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
-                                     'C','o','n','t','r','o','l','\\',
-                                     'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
+
+    UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Session Manager");
+
     static const int info_size = FIELD_OFFSET( KEY_VALUE_PARTIAL_INFORMATION, Data );
 
-    OBJECT_ATTRIBUTES attr;
+    OBJECT_ATTRIBUTES ObjectAttributes;
     UNICODE_STRING nameW, source_name, dest_name;
     KEY_VALUE_PARTIAL_INFORMATION *info;
     BOOL rc = FALSE;
@@ -88,34 +86,40 @@ static BOOL add_boot_rename_entry( LPCWSTR source, LPCWSTR dest, DWORD flags )
     DWORD DataSize = 0;
     BYTE *Buffer = NULL;
     WCHAR *p;
+    NTSTATUS Status;
 
     DPRINT("Add support to smss for keys created by MOVEFILE_DELAY_UNTIL_REBOOT\n");
 
-    if (!RtlDosPathNameToNtPathName_U( (LPWSTR)source, &source_name, NULL, NULL ))
+    if (!RtlDosPathNameToNtPathName_U( source, &source_name, NULL, NULL ))
     {
         SetLastError( ERROR_PATH_NOT_FOUND );
         return FALSE;
     }
     dest_name.Buffer = NULL;
-    if (dest && !RtlDosPathNameToNtPathName_U( (LPWSTR)dest, &dest_name, NULL, NULL ))
+    if (dest && !RtlDosPathNameToNtPathName_U( dest, &dest_name, NULL, NULL ))
     {
         RtlFreeUnicodeString( &source_name );
         SetLastError( ERROR_PATH_NOT_FOUND );
         return FALSE;
     }
 
-    attr.Length = sizeof(attr);
-    attr.RootDirectory = 0;
-    attr.ObjectName = &nameW;
-    attr.Attributes = 0;
-    attr.SecurityDescriptor = NULL;
-    attr.SecurityQualityOfService = NULL;
-    RtlInitUnicodeString( &nameW, SessionW );
-
-    if (NtCreateKey( &Reboot, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) != STATUS_SUCCESS)
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &KeyName,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+
+     Status = NtCreateKey(&Reboot, 
+                          KEY_QUERY_VALUE | KEY_SET_VALUE,
+                          &ObjectAttributes,
+                          0,
+                          NULL,
+                          REG_OPTION_NON_VOLATILE,
+                          NULL);
+
+    if (!NT_SUCCESS(Status))
     {
-        DPRINT1("Error creating key for reboot managment [%s]\n",
-             "SYSTEM\\CurrentControlSet\\Control\\Session Manager");
+        DPRINT1("NtCreateKey() failed (Status 0x%lx)\n", Status);
         RtlFreeUnicodeString( &source_name );
         RtlFreeUnicodeString( &dest_name );
         return FALSE;
@@ -224,7 +228,7 @@ MoveFileWithProgressW (
 
        
         /* validate & translate the filename */
-        if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpNewFileName,
+        if (!RtlDosPathNameToNtPathName_U (lpNewFileName,
                                           &DstPathU,
                                           NULL,
                                           NULL))
@@ -346,7 +350,8 @@ MoveFileWithProgressW (
                         */
                   RemoveReadOnlyAttributeW(lpExistingFileName);
            RemoveReadOnlyAttributeW(lpNewFileName);
-                  CreateDirectoryExW(lpExistingFileName,lpNewFileName,NULL);
+                  //CreateDirectoryExW(lpExistingFileName,lpNewFileName,NULL);
+                  CreateDirectoryW(lpNewFileName, NULL);
                                   
                   /* search the files/folders and move them */
                   while (loop==TRUE)
@@ -479,7 +484,8 @@ MoveFileWithProgressW (
                           RemoveReadOnlyAttributeW(lpDeleteFile);
                           RemoveReadOnlyAttributeW(lpNewFileName2);
 
-                  CreateDirectoryExW(lpDeleteFile, lpNewFileName2,NULL);
+                          CreateDirectoryW(lpNewFileName2,NULL);
+                  //CreateDirectoryExW(lpDeleteFile, lpNewFileName2,NULL);
                           
 
                           /* set new search path  from src string */