Author: ekohl
Date: Wed May 22 13:56:49 2013
New Revision: 59066
URL:
http://svn.reactos.org/svn/reactos?rev=59066&view=rev
Log:
[SAMSRV]
- Move some helper functions to a separate file.
- Implement SamrRemoveMemberFromForeignDomain.
Added:
trunk/reactos/dll/win32/samsrv/utils.c (with props)
Modified:
trunk/reactos/dll/win32/samsrv/CMakeLists.txt
trunk/reactos/dll/win32/samsrv/domain.c
trunk/reactos/dll/win32/samsrv/samrpc.c
trunk/reactos/dll/win32/samsrv/samsrv.h
trunk/reactos/dll/win32/samsrv/setup.c
Modified: trunk/reactos/dll/win32/samsrv/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/CMakeList…
==============================================================================
--- trunk/reactos/dll/win32/samsrv/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/samsrv/CMakeLists.txt [iso-8859-1] Wed May 22 13:56:49 2013
@@ -17,6 +17,7 @@
samsrv.c
setup.c
user.c
+ utils.c
samsrv.rc
${CMAKE_CURRENT_BINARY_DIR}/samsrv_stubs.c
${CMAKE_CURRENT_BINARY_DIR}/samsrv.def
Modified: trunk/reactos/dll/win32/samsrv/domain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/domain.c?…
==============================================================================
--- trunk/reactos/dll/win32/samsrv/domain.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/samsrv/domain.c [iso-8859-1] Wed May 22 13:56:49 2013
@@ -256,4 +256,93 @@
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 */
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] Wed May 22 13:56:49 2013
@@ -7648,8 +7648,49 @@
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;
}
Modified: trunk/reactos/dll/win32/samsrv/samsrv.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/samsrv.h?…
==============================================================================
--- trunk/reactos/dll/win32/samsrv/samsrv.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/samsrv/samsrv.h [iso-8859-1] Wed May 22 13:56:49 2013
@@ -201,6 +201,10 @@
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 @@
/* 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 @@
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 */
Modified: trunk/reactos/dll/win32/samsrv/setup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/setup.c?r…
==============================================================================
--- trunk/reactos/dll/win32/samsrv/setup.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/samsrv/setup.c [iso-8859-1] Wed May 22 13:56:49 2013
@@ -22,127 +22,6 @@
/* 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,
@@ -757,7 +636,7 @@
/* Create the Builtin domain */
if (SampCreateDomain(hDomainsKey,
L"Builtin",
- szName, //L"Builtin", //
SampGetResourceString(hInstance, IDS_DOMAIN_BUILTIN_NAME),
+ szName,
pBuiltinSid,
&hDomainKey))
{
Added: trunk/reactos/dll/win32/samsrv/utils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/utils.c?r…
==============================================================================
--- trunk/reactos/dll/win32/samsrv/utils.c (added)
+++ trunk/reactos/dll/win32/samsrv/utils.c [iso-8859-1] Wed May 22 13:56:49 2013
@@ -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 */
Propchange: trunk/reactos/dll/win32/samsrv/utils.c
------------------------------------------------------------------------------
svn:eol-style = native