Author: ekohl
Date: Fri Jun 21 23:19:37 2013
New Revision: 59278
URL:
http://svn.reactos.org/svn/reactos?rev=59278&view=rev
Log:
[SAMSRV]
Changing user account names requires more than just changing the name attribute. Do it
properly.
Modified:
trunk/reactos/dll/win32/samsrv/samrpc.c
Modified: trunk/reactos/dll/win32/samsrv/samrpc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/samrpc.c?…
==============================================================================
--- trunk/reactos/dll/win32/samsrv/samrpc.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/samsrv/samrpc.c [iso-8859-1] Fri Jun 21 23:19:37 2013
@@ -6752,6 +6752,71 @@
static NTSTATUS
+SampSetUserName(PSAM_DB_OBJECT UserObject,
+ PRPC_UNICODE_STRING NewUserName)
+{
+ UNICODE_STRING OldUserName = {0, 0, NULL};
+ NTSTATUS Status;
+
+ Status = SampGetObjectAttributeString(UserObject,
+ L"Name",
+ (PRPC_UNICODE_STRING)&OldUserName);
+ if (!NT_SUCCESS(Status))
+ {
+ TRACE("SampGetObjectAttributeString failed (Status 0x%08lx)\n",
Status);
+ goto done;
+ }
+
+ if (!RtlEqualUnicodeString(&OldUserName, (PCUNICODE_STRING)NewUserName, TRUE))
+ {
+ Status = SampCheckAccountNameInDomain(UserObject->ParentObject,
+ NewUserName->Buffer);
+ if (!NT_SUCCESS(Status))
+ {
+ TRACE("User name \'%S\' already exists in domain (Status
0x%08lx)\n",
+ NewUserName->Buffer, Status);
+ goto done;
+ }
+ }
+
+ Status = SampSetAccountNameInDomain(UserObject->ParentObject,
+ L"Users",
+ NewUserName->Buffer,
+ UserObject->RelativeId);
+ if (!NT_SUCCESS(Status))
+ {
+ TRACE("SampSetAccountNameInDomain failed (Status 0x%08lx)\n", Status);
+ goto done;
+ }
+
+ Status = SampRemoveAccountNameFromDomain(UserObject->ParentObject,
+ L"Users",
+ OldUserName.Buffer);
+ if (!NT_SUCCESS(Status))
+ {
+ TRACE("SampRemoveAccountNameFromDomain failed (Status 0x%08lx)\n",
Status);
+ goto done;
+ }
+
+ Status = SampSetObjectAttribute(UserObject,
+ L"Name",
+ REG_SZ,
+ NewUserName->Buffer,
+ NewUserName->Length + sizeof(WCHAR));
+ if (!NT_SUCCESS(Status))
+ {
+ TRACE("SampSetObjectAttribute failed (Status 0x%08lx)\n", Status);
+ }
+
+done:
+ if (OldUserName.Buffer != NULL)
+ midl_user_free(OldUserName.Buffer);
+
+ return Status;
+}
+
+
+static NTSTATUS
SampSetUserGeneral(PSAM_DB_OBJECT UserObject,
PSAMPR_USER_INFO_BUFFER Buffer)
{
@@ -6778,11 +6843,8 @@
if (!NT_SUCCESS(Status))
goto done;
- Status = SampSetObjectAttribute(UserObject,
- L"Name",
- REG_SZ,
- Buffer->General.UserName.Buffer,
- Buffer->General.UserName.MaximumLength);
+ Status = SampSetUserName(UserObject,
+ &Buffer->General.UserName);
if (!NT_SUCCESS(Status))
goto done;
@@ -7011,11 +7073,8 @@
if (WhichFields & USER_ALL_USERNAME)
{
- Status = SampSetObjectAttribute(UserObject,
- L"Name",
- REG_SZ,
- Buffer->All.UserName.Buffer,
- Buffer->All.UserName.MaximumLength);
+ Status = SampSetUserName(UserObject,
+ &Buffer->All.UserName);
if (!NT_SUCCESS(Status))
goto done;
}
@@ -7265,11 +7324,8 @@
break;
case UserNameInformation:
- Status = SampSetObjectAttribute(UserObject,
- L"Name",
- REG_SZ,
- Buffer->Name.UserName.Buffer,
- Buffer->Name.UserName.MaximumLength);
+ Status = SampSetUserName(UserObject,
+ &Buffer->Name.UserName);
if (!NT_SUCCESS(Status))
break;
@@ -7281,11 +7337,8 @@
break;
case UserAccountNameInformation:
- Status = SampSetObjectAttribute(UserObject,
- L"Name",
- REG_SZ,
- Buffer->AccountName.UserName.Buffer,
-
Buffer->AccountName.UserName.MaximumLength);
+ Status = SampSetUserName(UserObject,
+ &Buffer->AccountName.UserName);
break;
case UserFullNameInformation: