diff --git a/reactos/include/ntdll/rtl.h b/reactos/include/ntdll/rtl.h index 7d41be0a5bd..e66f2d9e24e 100644 --- a/reactos/include/ntdll/rtl.h +++ b/reactos/include/ntdll/rtl.h @@ -1,4 +1,4 @@ -/* $Id: rtl.h,v 1.31 2001/06/24 17:58:13 phreak Exp $ +/* $Id: rtl.h,v 1.32 2001/11/21 22:27:26 ekohl Exp $ * */ @@ -465,6 +465,12 @@ RtlIsValidIndexHandle ( IN ULONG Index ); +NTSTATUS +STDCALL +RtlImpersonateSelf ( + IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel + ); + NTSTATUS STDCALL RtlpNtCreateKey ( diff --git a/reactos/lib/ntdll/def/ntdll.def b/reactos/lib/ntdll/def/ntdll.def index 71bdba050b6..6660aabdeed 100644 --- a/reactos/lib/ntdll/def/ntdll.def +++ b/reactos/lib/ntdll/def/ntdll.def @@ -1,4 +1,4 @@ -; $Id: ntdll.def,v 1.80 2001/11/03 16:48:06 chorns Exp $ +; $Id: ntdll.def,v 1.81 2001/11/21 22:31:18 ekohl Exp $ ; ; ReactOS Operating System ; @@ -434,7 +434,7 @@ RtlImageDirectoryEntryToData@16 RtlImageNtHeader@4 RtlImageRvaToSection@12 RtlImageRvaToVa@16 -;RtlImpersonateSelf +RtlImpersonateSelf@4 RtlInitAnsiString@8 ;RtlInitCodePageTable ;RtlInitNlsTables diff --git a/reactos/lib/ntdll/def/ntdll.edf b/reactos/lib/ntdll/def/ntdll.edf index 7fc9125b7ec..9e7cc479c6e 100644 --- a/reactos/lib/ntdll/def/ntdll.edf +++ b/reactos/lib/ntdll/def/ntdll.edf @@ -1,4 +1,4 @@ -; $Id: ntdll.edf,v 1.69 2001/11/03 16:48:06 chorns Exp $ +; $Id: ntdll.edf,v 1.70 2001/11/21 22:31:18 ekohl Exp $ ; ; ReactOS Operating System ; @@ -433,7 +433,7 @@ RtlImageDirectoryEntryToData=RtlImageDirectoryEntryToData@16 RtlImageNtHeader=RtlImageNtHeader@4 RtlImageRvaToSection=RtlImageRvaToSection@12 RtlImageRvaToVa=RtlImageRvaToVa@16 -;RtlImpersonateSelf +RtlImpersonateSelf=RtlImpersonateSelf@4 RtlInitAnsiString=RtlInitAnsiString@8 ;RtlInitCodePageTable ;RtlInitNlsTables diff --git a/reactos/lib/ntdll/makefile b/reactos/lib/ntdll/makefile index 48f93880732..fcc5af0aa94 100644 --- a/reactos/lib/ntdll/makefile +++ b/reactos/lib/ntdll/makefile @@ -1,4 +1,4 @@ -# $Id: makefile,v 1.67 2001/11/03 16:48:05 chorns Exp $ +# $Id: makefile,v 1.68 2001/11/21 22:30:57 ekohl Exp $ PATH_TO_TOP = ../.. @@ -31,7 +31,7 @@ RTL_OBJECTS = rtl/critical.o rtl/error.o rtl/heap.o rtl/largeint.o \ rtl/access.o rtl/apc.o rtl/callback.o rtl/luid.o rtl/misc.o \ rtl/registry.o rtl/exception.o rtl/intrlck.o rtl/resource.o \ rtl/handle.o rtl/atom.o rtl/message.o rtl/timezone.o \ - rtl/propvar.o + rtl/propvar.o rtl/security.o STDIO_OBJECTS = stdio/sprintf.o stdio/swprintf.o diff --git a/reactos/lib/ntdll/rtl/security.c b/reactos/lib/ntdll/rtl/security.c new file mode 100644 index 00000000000..f770a5947af --- /dev/null +++ b/reactos/lib/ntdll/rtl/security.c @@ -0,0 +1,65 @@ +/* $Id: security.c,v 1.4 2001/11/21 22:30:45 ekohl Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: lib/ntdll/rtl/security.c + * PURPOSE: Miscellaneous securitiy related functions + * PROGRAMMER: Eric Kohl + * UPDATE HISTORY: + * 21/11/2001 Created + */ + +#include +#include + + +NTSTATUS STDCALL +RtlImpersonateSelf(IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + SECURITY_QUALITY_OF_SERVICE SecQos; + HANDLE ProcessToken; + HANDLE ImpersonationToken; + NTSTATUS Status; + + Status = NtOpenProcessToken(NtCurrentProcess(), + TOKEN_DUPLICATE, + &ProcessToken); + if (!NT_SUCCESS(Status)) + return(Status); + + SecQos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE); + SecQos.ImpersonationLevel = ImpersonationLevel; + SecQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING; + SecQos.EffectiveOnly = FALSE; + + ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = 0; + ObjectAttributes.ObjectName = NULL; + ObjectAttributes.Attributes = 0; + ObjectAttributes.SecurityDescriptor = NULL; + ObjectAttributes.SecurityQualityOfService = &SecQos; + + Status = NtDuplicateToken(ProcessToken, + TOKEN_IMPERSONATE, + &ObjectAttributes, + NULL, + TokenImpersonation, + &ImpersonationToken); + if (!NT_SUCCESS(Status)) + { + NtClose(ProcessToken); + return(Status); + } + + Status = NtSetInformationThread(NtCurrentThread(), + ThreadImpersonationToken, + &ImpersonationToken, + sizeof(HANDLE)); + NtClose(ImpersonationToken); + NtClose(ProcessToken); + + return(Status); +} + +/* EOF */