- Move some helper functions to a separate file.
- Implement SamrRemoveMemberFromForeignDomain.

svn path=/trunk/; revision=59066
This commit is contained in:
Eric Kohl 2013-05-22 13:56:49 +00:00
parent d05faf138b
commit 8a56b68510
6 changed files with 320 additions and 127 deletions

View File

@ -17,6 +17,7 @@ list(APPEND SOURCE
samsrv.c
setup.c
user.c
utils.c
samsrv.rc
${CMAKE_CURRENT_BINARY_DIR}/samsrv_stubs.c
${CMAKE_CURRENT_BINARY_DIR}/samsrv.def

View File

@ -256,4 +256,93 @@ SampCheckAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
return Status;
}
NTSTATUS
SampRemoveMemberFromAllAliases(IN PSAM_DB_OBJECT DomainObject,
IN PRPC_SID MemberSid)
{
WCHAR AliasKeyName[64];
LPWSTR MemberSidString = NULL;
HANDLE AliasesKey;
HANDLE MembersKey;
HANDLE AliasKey;
ULONG Index;
NTSTATUS Status;
TRACE("(%p %p)\n", DomainObject, MemberSid);
ConvertSidToStringSidW(MemberSid, &MemberSidString);
TRACE("Member SID: %S\n", MemberSidString);
Status = SampRegOpenKey(DomainObject->KeyHandle,
L"Aliases",
KEY_READ,
&AliasesKey);
if (NT_SUCCESS(Status))
{
Index = 0;
while (TRUE)
{
Status = SampRegEnumerateSubKey(AliasesKey,
Index,
64,
AliasKeyName);
if (!NT_SUCCESS(Status))
{
if (Status == STATUS_NO_MORE_ENTRIES)
Status = STATUS_SUCCESS;
break;
}
TRACE("Alias key name: %S\n", AliasKeyName);
Status = SampRegOpenKey(AliasesKey,
AliasKeyName,
KEY_READ,
&AliasKey);
if (NT_SUCCESS(Status))
{
Status = SampRegOpenKey(AliasKey,
L"Members",
KEY_WRITE,
&MembersKey);
if (NT_SUCCESS(Status))
{
Status = SampRegDeleteValue(AliasKey,
MemberSidString);
SampRegCloseKey(MembersKey);
}
else if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
Status = STATUS_SUCCESS;
SampRegCloseKey(AliasKey);
}
Index++;
}
Status = SampRegOpenKey(AliasesKey,
L"Members",
KEY_WRITE,
&MembersKey);
if (NT_SUCCESS(Status))
{
Status = SampRegDeleteKey(MembersKey,
MemberSidString);
if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
Status = STATUS_SUCCESS;
SampRegCloseKey(MembersKey);
}
SampRegCloseKey(AliasesKey);
}
if (MemberSidString != NULL)
LocalFree(MemberSidString);
return Status;
}
/* EOF */

View File

@ -7648,8 +7648,49 @@ NTAPI
SamrRemoveMemberFromForeignDomain(IN SAMPR_HANDLE DomainHandle,
IN PRPC_SID MemberSid)
{
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
PSAM_DB_OBJECT DomainObject;
ULONG Rid = 0;
NTSTATUS Status;
TRACE("(%p %p)\n",
DomainHandle, MemberSid);
/* Validate the domain object */
Status = SampValidateDbObject(DomainHandle,
SamDbDomainObject,
DOMAIN_LOOKUP,
&DomainObject);
if (!NT_SUCCESS(Status))
{
TRACE("SampValidateDbObject failed with status 0x%08lx\n", Status);
return Status;
}
/* Retrieve the RID from the MemberSID */
Status = SampGetRidFromSid((PSID)MemberSid,
&Rid);
if (!NT_SUCCESS(Status))
{
TRACE("SampGetRidFromSid failed with status 0x%08lx\n", Status);
return Status;
}
/* Fail, if the RID represents a special account */
if (Rid < 1000)
{
TRACE("Cannot remove a special account (RID: %lu)\n", Rid);
return STATUS_SPECIAL_ACCOUNT;
}
/* Remove the member from all aliases in the domain */
Status = SampRemoveMemberFromAllAliases(DomainObject,
MemberSid);
if (!NT_SUCCESS(Status))
{
TRACE("SampRemoveMemberFromAllAliases failed with status 0x%08lx\n", Status);
}
return Status;
}

View File

@ -201,6 +201,10 @@ NTSTATUS
SampCheckAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
IN LPCWSTR lpAccountName);
NTSTATUS
SampRemoveMemberFromAllAliases(IN PSAM_DB_OBJECT DomainObject,
IN PRPC_SID MemberSid);
/* group.h */
@ -281,13 +285,14 @@ SampRegSetValue(IN HANDLE KeyHandle,
/* samspc.c */
VOID SampStartRpcServer(VOID);
VOID
SampStartRpcServer(VOID);
/* setup.c */
BOOL SampIsSetupRunning(VOID);
BOOL SampInitializeSAM(VOID);
BOOL
SampInitializeSAM(VOID);
/* user.c */
@ -337,4 +342,24 @@ NTSTATUS
SampSetLogonHoursAttrbute(IN PSAM_DB_OBJECT UserObject,
IN PSAMPR_LOGON_HOURS LogonHours);
/* utils.c */
INT
SampLoadString(HINSTANCE hInstance,
UINT uId,
LPWSTR lpBuffer,
INT nBufferMax);
BOOL
SampIsSetupRunning(VOID);
PSID
AppendRidToSid(PSID SrcSid,
ULONG Rid);
NTSTATUS
SampGetRidFromSid(IN PSID Sid,
OUT PULONG Rid);
/* EOF */

View File

@ -23,127 +23,6 @@ SID_IDENTIFIER_AUTHORITY SecurityNtAuthority = {SECURITY_NT_AUTHORITY};
/* FUNCTIONS ***************************************************************/
static INT
SampLoadString(HINSTANCE hInstance,
UINT uId,
LPWSTR lpBuffer,
INT nBufferMax)
{
HGLOBAL hmem;
HRSRC hrsrc;
WCHAR *p;
int string_num;
int i;
/* Use loword (incremented by 1) as resourceid */
hrsrc = FindResourceW(hInstance,
MAKEINTRESOURCEW((LOWORD(uId) >> 4) + 1),
(LPWSTR)RT_STRING);
if (!hrsrc)
return 0;
hmem = LoadResource(hInstance, hrsrc);
if (!hmem)
return 0;
p = LockResource(hmem);
string_num = uId & 0x000f;
for (i = 0; i < string_num; i++)
p += *p + 1;
i = min(nBufferMax - 1, *p);
if (i > 0)
{
memcpy(lpBuffer, p + 1, i * sizeof(WCHAR));
lpBuffer[i] = 0;
}
else
{
if (nBufferMax > 1)
{
lpBuffer[0] = 0;
return 0;
}
}
return i;
}
BOOL
SampIsSetupRunning(VOID)
{
DWORD dwError;
HKEY hKey;
DWORD dwType;
DWORD dwSize;
DWORD dwSetupType;
TRACE("SampIsSetupRunning()\n");
/* Open key */
dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SYSTEM\\Setup",
0,
KEY_QUERY_VALUE,
&hKey);
if (dwError != ERROR_SUCCESS)
return FALSE;
/* Read key */
dwSize = sizeof(DWORD);
dwError = RegQueryValueExW(hKey,
L"SetupType",
NULL,
&dwType,
(LPBYTE)&dwSetupType,
&dwSize);
/* Close key, and check if returned values are correct */
RegCloseKey(hKey);
if (dwError != ERROR_SUCCESS || dwType != REG_DWORD || dwSize != sizeof(DWORD))
return FALSE;
TRACE("SampIsSetupRunning() returns %s\n", (dwSetupType != 0) ? "TRUE" : "FALSE");
return (dwSetupType != 0);
}
static PSID
AppendRidToSid(PSID SrcSid,
ULONG Rid)
{
ULONG Rids[8] = {0, 0, 0, 0, 0, 0, 0, 0};
UCHAR RidCount;
PSID DstSid;
ULONG i;
RidCount = *RtlSubAuthorityCountSid(SrcSid);
if (RidCount >= 8)
return NULL;
for (i = 0; i < RidCount; i++)
Rids[i] = *RtlSubAuthoritySid(SrcSid, i);
Rids[RidCount] = Rid;
RidCount++;
RtlAllocateAndInitializeSid(RtlIdentifierAuthoritySid(SrcSid),
RidCount,
Rids[0],
Rids[1],
Rids[2],
Rids[3],
Rids[4],
Rids[5],
Rids[6],
Rids[7],
&DstSid);
return DstSid;
}
static BOOL
SampAddMemberToAlias(HKEY hDomainKey,
ULONG AliasId,
@ -757,7 +636,7 @@ SampInitializeSAM(VOID)
/* Create the Builtin domain */
if (SampCreateDomain(hDomainsKey,
L"Builtin",
szName, //L"Builtin", // SampGetResourceString(hInstance, IDS_DOMAIN_BUILTIN_NAME),
szName,
pBuiltinSid,
&hDomainKey))
{

View File

@ -0,0 +1,158 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: Security Account Manager (SAM) Server
* FILE: reactos/dll/win32/samsrv/utils.c
* PURPOSE: Utility functions
*
* PROGRAMMERS: Eric Kohl
*/
/* INCLUDES ****************************************************************/
#include "samsrv.h"
WINE_DEFAULT_DEBUG_CHANNEL(samsrv);
/* GLOBALS *****************************************************************/
/* FUNCTIONS ***************************************************************/
INT
SampLoadString(HINSTANCE hInstance,
UINT uId,
LPWSTR lpBuffer,
INT nBufferMax)
{
HGLOBAL hmem;
HRSRC hrsrc;
WCHAR *p;
int string_num;
int i;
/* Use loword (incremented by 1) as resourceid */
hrsrc = FindResourceW(hInstance,
MAKEINTRESOURCEW((LOWORD(uId) >> 4) + 1),
(LPWSTR)RT_STRING);
if (!hrsrc)
return 0;
hmem = LoadResource(hInstance, hrsrc);
if (!hmem)
return 0;
p = LockResource(hmem);
string_num = uId & 0x000f;
for (i = 0; i < string_num; i++)
p += *p + 1;
i = min(nBufferMax - 1, *p);
if (i > 0)
{
memcpy(lpBuffer, p + 1, i * sizeof(WCHAR));
lpBuffer[i] = 0;
}
else
{
if (nBufferMax > 1)
{
lpBuffer[0] = 0;
return 0;
}
}
return i;
}
BOOL
SampIsSetupRunning(VOID)
{
DWORD dwError;
HKEY hKey;
DWORD dwType;
DWORD dwSize;
DWORD dwSetupType;
TRACE("SampIsSetupRunning()\n");
/* Open key */
dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SYSTEM\\Setup",
0,
KEY_QUERY_VALUE,
&hKey);
if (dwError != ERROR_SUCCESS)
return FALSE;
/* Read key */
dwSize = sizeof(DWORD);
dwError = RegQueryValueExW(hKey,
L"SetupType",
NULL,
&dwType,
(LPBYTE)&dwSetupType,
&dwSize);
/* Close key, and check if returned values are correct */
RegCloseKey(hKey);
if (dwError != ERROR_SUCCESS || dwType != REG_DWORD || dwSize != sizeof(DWORD))
return FALSE;
TRACE("SampIsSetupRunning() returns %s\n", (dwSetupType != 0) ? "TRUE" : "FALSE");
return (dwSetupType != 0);
}
PSID
AppendRidToSid(PSID SrcSid,
ULONG Rid)
{
ULONG Rids[8] = {0, 0, 0, 0, 0, 0, 0, 0};
UCHAR RidCount;
PSID DstSid;
ULONG i;
RidCount = *RtlSubAuthorityCountSid(SrcSid);
if (RidCount >= 8)
return NULL;
for (i = 0; i < RidCount; i++)
Rids[i] = *RtlSubAuthoritySid(SrcSid, i);
Rids[RidCount] = Rid;
RidCount++;
RtlAllocateAndInitializeSid(RtlIdentifierAuthoritySid(SrcSid),
RidCount,
Rids[0],
Rids[1],
Rids[2],
Rids[3],
Rids[4],
Rids[5],
Rids[6],
Rids[7],
&DstSid);
return DstSid;
}
NTSTATUS
SampGetRidFromSid(IN PSID Sid,
OUT PULONG Rid)
{
UCHAR RidCount;
RidCount = *RtlSubAuthorityCountSid(Sid);
if (RidCount < 1)
return STATUS_INVALID_SID;
*Rid = *RtlSubAuthoritySid(Sid, RidCount - 1);
return STATUS_SUCCESS;
}
/* EOF */