[SAMSRV]
[reactos.git] / reactos / dll / win32 / samsrv / database.c
index 421ef74..95811fb 100644 (file)
@@ -484,10 +484,10 @@ SampCloseDbObject(PSAM_DB_OBJECT DbObject)
 
 
 NTSTATUS
-SampSetDbObjectNameAlias(IN PSAM_DB_OBJECT DomainObject,
-                         IN LPCWSTR lpContainerName,
-                         IN LPCWSTR lpAliasName,
-                         IN ULONG ulAliasValue)
+SampSetAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
+                           IN LPCWSTR lpContainerName,
+                           IN LPCWSTR lpAccountName,
+                           IN ULONG ulRelativeId)
 {
     OBJECT_ATTRIBUTES ObjectAttributes;
     UNICODE_STRING KeyName;
@@ -496,6 +496,8 @@ SampSetDbObjectNameAlias(IN PSAM_DB_OBJECT DomainObject,
     HANDLE NamesKeyHandle = NULL;
     NTSTATUS Status;
 
+    TRACE("SampSetAccountNameInDomain()\n");
+
     /* Open the container key */
     RtlInitUnicodeString(&KeyName, lpContainerName);
 
@@ -527,13 +529,13 @@ SampSetDbObjectNameAlias(IN PSAM_DB_OBJECT DomainObject,
         goto done;
 
     /* Set the alias value */
-    RtlInitUnicodeString(&ValueName, lpAliasName);
+    RtlInitUnicodeString(&ValueName, lpAccountName);
 
     Status = NtSetValueKey(NamesKeyHandle,
                            &ValueName,
                            0,
                            REG_DWORD,
-                           (LPVOID)&ulAliasValue,
+                           (LPVOID)&ulRelativeId,
                            sizeof(ULONG));
 
 done:
@@ -547,87 +549,6 @@ done:
 }
 
 
-NTSTATUS
-SampCheckDbObjectNameAlias(IN PSAM_DB_OBJECT DomainObject,
-                           IN LPCWSTR lpContainerName,
-                           IN LPCWSTR lpAliasName,
-                           OUT PBOOL bAliasExists)
-{
-    PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    UNICODE_STRING KeyName;
-    UNICODE_STRING ValueName;
-    HANDLE ContainerKeyHandle = NULL;
-    HANDLE NamesKeyHandle = NULL;
-    ULONG BufferLength = sizeof(ULONG);
-    NTSTATUS Status;
-
-    /* Open the container key */
-    RtlInitUnicodeString(&KeyName, lpContainerName);
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &KeyName,
-                               OBJ_CASE_INSENSITIVE,
-                               DomainObject->KeyHandle,
-                               NULL);
-
-    Status = NtOpenKey(&ContainerKeyHandle,
-                       KEY_ALL_ACCESS,
-                       &ObjectAttributes);
-    if (!NT_SUCCESS(Status))
-        return Status;
-
-    /* Open the 'Names' key */
-    RtlInitUnicodeString(&KeyName, L"Names");
-
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &KeyName,
-                               OBJ_CASE_INSENSITIVE,
-                               ContainerKeyHandle,
-                               NULL);
-
-    Status = NtOpenKey(&NamesKeyHandle,
-                       KEY_ALL_ACCESS,
-                       &ObjectAttributes);
-    if (!NT_SUCCESS(Status))
-        goto done;
-
-    /* Get the alias value */
-    RtlInitUnicodeString(&ValueName, lpAliasName);
-
-    BufferLength += FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
-
-    /* Allocate memory for the value */
-    ValueInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferLength);
-    if (ValueInfo == NULL)
-        return STATUS_NO_MEMORY;
-
-    /* Query the value */
-    Status = ZwQueryValueKey(NamesKeyHandle,
-                             &ValueName,
-                             KeyValuePartialInformation,
-                             ValueInfo,
-                             BufferLength,
-                             &BufferLength);
-
-    *bAliasExists = (Status != STATUS_OBJECT_NAME_NOT_FOUND);
-
-    Status = STATUS_SUCCESS;
-
-    /* Free the memory and return status */
-    RtlFreeHeap(RtlGetProcessHeap(), 0, ValueInfo);
-
-done:
-    if (NamesKeyHandle)
-        NtClose(NamesKeyHandle);
-
-    if (ContainerKeyHandle)
-        NtClose(ContainerKeyHandle);
-
-    return Status;
-}
-
-
 NTSTATUS
 SampCheckAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
                              IN LPWSTR lpAccountName)
@@ -636,7 +557,7 @@ SampCheckAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
     HANDLE NamesKey;
     NTSTATUS Status;
 
-    TRACE("SampCheckNameInDomain()\n");
+    TRACE("SampCheckAccountNameInDomain()\n");
 
     Status = SampRegOpenKey(DomainObject->KeyHandle,
                             L"Aliases",
@@ -656,11 +577,12 @@ SampCheckAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
                                        NULL,
                                        NULL);
             if (Status == STATUS_SUCCESS)
+            {
+                SampRegCloseKey(NamesKey);
                 Status = STATUS_ALIAS_EXISTS;
+            }
             else if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
                 Status = STATUS_SUCCESS;
-
-            SampRegCloseKey(NamesKey);
         }
 
         SampRegCloseKey(AccountKey);
@@ -690,11 +612,12 @@ SampCheckAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
                                        NULL,
                                        NULL);
             if (Status == STATUS_SUCCESS)
+            {
+                SampRegCloseKey(NamesKey);
                 Status = STATUS_ALIAS_EXISTS;
+            }
             else if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
                 Status = STATUS_SUCCESS;
-
-            SampRegCloseKey(NamesKey);
         }
 
         SampRegCloseKey(AccountKey);
@@ -724,11 +647,12 @@ SampCheckAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
                                        NULL,
                                        NULL);
             if (Status == STATUS_SUCCESS)
+            {
+                SampRegCloseKey(NamesKey);
                 Status = STATUS_ALIAS_EXISTS;
+            }
             else if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
                 Status = STATUS_SUCCESS;
-
-            SampRegCloseKey(NamesKey);
         }
 
         SampRegCloseKey(AccountKey);
@@ -840,8 +764,8 @@ SampGetObjectAttributeString(PSAM_DB_OBJECT DbObject,
         goto done;
     }
 
-    String->Length = Length - sizeof(WCHAR);
-    String->MaximumLength = Length;
+    String->Length = (USHORT)(Length - sizeof(WCHAR));
+    String->MaximumLength = (USHORT)Length;
     String->Buffer = midl_user_allocate(Length);
     if (String->Buffer == NULL)
     {