+/* $Id: dllmain.c,v 1.2 2000/09/05 22:59:58 ekohl Exp $
+ *
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS system libraries
+ * FILE: lib/advapi32/misc/dllmain.c
+ * PURPOSE: Library main function
+ * PROGRAMMER: ???
+ * UPDATE HISTORY:
+ * Created ???
+ */
+
+#include <ddk/ntddk.h>
#include <windows.h>
+
+//#define NDEBUG
+#include <debug.h>
+
+
INT
STDCALL
DllMain(
PVOID reserved
)
{
+DPRINT1("ADVAPI32: DllMain() called\n");
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
+ DisableThreadLibraryCalls (hinstDll);
+ RegInitialize ();
break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- break;
+
case DLL_PROCESS_DETACH:
+ RegCleanup ();
break;
}
- return(1);
+
+DPRINT1("ADVAPI32: DllMain() done\n");
+
+ return TRUE;
}
+/* EOF */
-/*
+/* $Id: reg.c,v 1.8 2000/09/05 23:00:27 ekohl Exp $
+ *
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/advapi32/reg/reg.c
* Created 01/11/98
* 19990309 EA Stubs
*/
-#include <windows.h>
#include <ddk/ntddk.h>
+#include <ntdll/rtl.h>
+#include <windows.h>
#include <wchar.h>
+#define NDEBUG
+#include <debug.h>
+
+/* GLOBALS *******************************************************************/
+
+#define MAX_DEFAULT_HANDLES 7
+
+static CRITICAL_SECTION HandleTableCS;
+static HANDLE DefaultHandleTable[MAX_DEFAULT_HANDLES];
+
+
+/* PROTOTYPES ****************************************************************/
+
+static NTSTATUS MapDefaultKey (PHKEY ParentKey, HKEY Key);
+static VOID CloseDefaultHandles(VOID);
+
+static NTSTATUS OpenLocalMachineKey (PHANDLE KeyHandle);
+
+
+/* FUNCTIONS *****************************************************************/
+
+/************************************************************************
+ * RegInitDefaultHandles
+ */
+
+BOOL
+RegInitialize (VOID)
+{
+ DPRINT1("RegInitialize()\n");
+
+ RtlZeroMemory (DefaultHandleTable,
+ MAX_DEFAULT_HANDLES * sizeof(HANDLE));
+
+ RtlInitializeCriticalSection(&HandleTableCS);
+ return TRUE;
+}
+
+
+/************************************************************************
+ * RegInit
+ */
+BOOL
+RegCleanup(VOID)
+{
+ DPRINT1("RegCleanup()\n");
+
+ CloseDefaultHandles();
+ RtlDeleteCriticalSection(&HandleTableCS);
+ return TRUE;
+}
+
+
+static NTSTATUS
+MapDefaultKey (PHKEY ParentKey,
+ HKEY Key)
+{
+ PHANDLE Handle;
+ ULONG Index;
+ NTSTATUS Status = STATUS_SUCCESS;
+
+ DPRINT1("MapDefaultKey (Key %x)\n", Key);
+
+ if (((ULONG)Key & 0xF0000000) != 0x80000000)
+ {
+ *ParentKey = Key;
+ return STATUS_SUCCESS;
+ }
+
+ /* Handle special cases here */
+ Index = (ULONG)Key & 0x0FFFFFFF;
+DPRINT1("Index %x\n", Index);
+
+ if (Index >= MAX_DEFAULT_HANDLES)
+ return STATUS_INVALID_PARAMETER;
+
+ RtlEnterCriticalSection(&HandleTableCS);
+
+ Handle = &DefaultHandleTable[Index];
+ if (*Handle == NULL)
+ {
+ /* create/open the default handle */
+ switch (Index)
+ {
+ case 2: /*HKEY_LOCAL_MACHINE */
+ Status = OpenLocalMachineKey(Handle);
+ break;
+
+ default:
+ DPRINT1("MapDefaultHandle() no handle creator\n");
+ Status = STATUS_INVALID_PARAMETER;
+ }
+ }
+
+ RtlLeaveCriticalSection(&HandleTableCS);
+
+DPRINT1("Status %x\n", Status);
+
+ if (NT_SUCCESS(Status))
+ {
+ *ParentKey = (HKEY)*Handle;
+ }
+
+ return Status;
+}
+
+
+static VOID CloseDefaultHandles(VOID)
+{
+ ULONG i;
+
+ RtlEnterCriticalSection(&HandleTableCS);
+
+ for (i = 0; i < MAX_DEFAULT_HANDLES; i++)
+ {
+ if (DefaultHandleTable[i] != NULL)
+ {
+// NtClose (DefaultHandleTable[i]);
+ DefaultHandleTable[i] = NULL;
+ }
+ }
+
+ RtlLeaveCriticalSection(&HandleTableCS);
+}
+
+
+static NTSTATUS
+OpenLocalMachineKey (PHANDLE KeyHandle)
+{
+ OBJECT_ATTRIBUTES Attributes;
+ UNICODE_STRING KeyName;
+
+ DPRINT1("OpenLocalMachineKey()\n");
+
+ RtlInitUnicodeString(&KeyName,
+ L"\\Registry\\Machine");
+
+ InitializeObjectAttributes(&Attributes,
+ &KeyName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ return (NtOpenKey (KeyHandle, 0x200000, &Attributes));
+}
+
+
/************************************************************************
* RegCloseKey
*/
0,
NULL,
0,
- MAXIMUM_ALLOWED,
+ KEY_ALL_ACCESS,
NULL,
phkResult,
NULL);
0,
NULL,
0,
- MAXIMUM_ALLOWED,
+ KEY_ALL_ACCESS,
NULL,
phkResult,
NULL);
LPDWORD lpdwDisposition
)
{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return ERROR_CALL_NOT_IMPLEMENTED;
+ UNICODE_STRING SubKeyString;
+ UNICODE_STRING ClassString;
+ OBJECT_ATTRIBUTES Attributes;
+ NTSTATUS Status;
+ HKEY ParentKey;
+
+ DPRINT1("RegCreateKeyExW() called\n");
+
+ /* get the real parent key */
+ Status = MapDefaultKey (&ParentKey, hKey);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError (RtlNtStatusToDosError(Status));
+ return (RtlNtStatusToDosError(Status));
+ }
+
+ DPRINT1("ParentKey %x\n", (ULONG)ParentKey);
+
+ RtlInitUnicodeString (&ClassString, lpClass);
+ RtlInitUnicodeString (&SubKeyString, lpSubKey);
+
+ InitializeObjectAttributes (&Attributes,
+ &SubKeyString,
+ OBJ_CASE_INSENSITIVE,
+ (HANDLE)ParentKey,
+ (PSECURITY_DESCRIPTOR)lpSecurityAttributes);
+
+ Status = NtCreateKey (phkResult,
+ samDesired,
+ &Attributes,
+ 0,
+ (lpClass == NULL)? NULL : &ClassString,
+ dwOptions,
+ (PULONG)lpdwDisposition);
+ DPRINT1("Status %x\n", Status);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError (RtlNtStatusToDosError(Status));
+ return (RtlNtStatusToDosError(Status));
+ }
+ DPRINT1("Returned handle %x\n", (ULONG)*phkResult);
+
+ return ERROR_SUCCESS;
}
return ERROR_CALL_NOT_IMPLEMENTED;
}
-
/* EOF */
-/* $Id: thread.c,v 1.19 2000/09/05 13:52:44 ekohl Exp $
+/* $Id: thread.c,v 1.20 2000/09/05 23:01:07 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
#include <kernel32/error.h>
+static VOID ThreadAttachDlls (VOID);
+
+/* Type for a DLL's entry point */
+typedef
+WINBOOL
+STDCALL
+(* PDLLMAIN_FUNC) (
+ HANDLE hInst,
+ ULONG ul_reason_for_call,
+ LPVOID lpReserved
+ );
+
/* FUNCTIONS *****************************************************************/
static VOID STDCALL
{
UINT uExitCode;
+ ThreadAttachDlls ();
+
+ /* FIXME: notify csrss of thread creation ?? */
+
uExitCode = (lpStartAddress)(lpParameter);
- NtTerminateThread(NtCurrentThread(),
- uExitCode);
+ ExitThread(uExitCode);
}
+static VOID
+ThreadAttachDlls (VOID)
+{
+ PLIST_ENTRY ModuleListHead;
+ PLIST_ENTRY Entry;
+ PLDR_MODULE Module;
+
+ DPRINT("ThreadAttachDlls() called\n");
+
+ RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
+
+ ModuleListHead = &NtCurrentPeb()->Ldr->InInitializationOrderModuleList;
+ Entry = ModuleListHead->Blink;
+
+ while (Entry != ModuleListHead)
+ {
+ Module = CONTAINING_RECORD(Entry, LDR_MODULE, InInitializationOrderModuleList);
+
+ if (Module->EntryPoint != 0)
+ {
+ PDLLMAIN_FUNC Entrypoint = (PDLLMAIN_FUNC)Module->EntryPoint;
+
+ DPRINT("Calling entry point at 0x%08x\n", Entrypoint);
+ Entrypoint (Module->BaseAddress,
+ DLL_THREAD_ATTACH,
+ NULL);
+ }
+
+ Entry = Entry->Blink;
+ }
+
+ RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
+
+ DPRINT("ThreadAttachDlls() done\n");
+}
HANDLE STDCALL CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize,
-/* $Id: registry.c,v 1.26 2000/09/03 14:46:49 ekohl Exp $
+/* $Id: registry.c,v 1.27 2000/09/05 23:03:09 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
Status = CmiBuildKeyPath(&KeyNameBuf, ObjectAttributes);
if (!NT_SUCCESS(Status))
{
+CHECKPOINT1;
return Status;
}
KeyHandle);
ExFreePool(KeyNameBuf);
+CHECKPOINT1;
return Status;
}
{
ExFreePool(KeyNameBuf);
+CHECKPOINT1;
return Status;
}
CmiKeyType);
if (NewKey == NULL)
{
+CHECKPOINT1;
return STATUS_UNSUCCESSFUL;
}
NewKey->Flags = 0;
FALSE,
KeyHandle);
+CHECKPOINT1;
return Status;
#else
UNIMPLEMENTED;
}
-NTSTATUS
+NTSTATUS
STDCALL
NtOpenKey (
- OUT PHANDLE KeyHandle,
+ OUT PHANDLE KeyHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes
)
}
/* Open the key in the registry file */
+CHECKPOINT1;
FileToUse = CmiSystemFile;
Status = CmiFindKey(FileToUse,
KeyNameBuf,
DesiredAccess,
0,
NULL);
+CHECKPOINT1;
if (!NT_SUCCESS(Status))
{
+CHECKPOINT1;
FileToUse = CmiVolatileFile;
Status = CmiFindKey(FileToUse,
KeyNameBuf,
DesiredAccess,
0,
NULL);
+CHECKPOINT1;
if (!NT_SUCCESS(Status))
{
+CHECKPOINT1;
ExFreePool(KeyNameBuf);
return Status;
}
}
+CHECKPOINT1;
/* Create new key object and put into linked list */
NewKey = ObCreateObject(KeyHandle,
ObjectHeader = 0;
if (ObjectAttributes->RootDirectory != NULL)
{
+DbgPrint ("RootDirectory %x\n", ObjectAttributes->RootDirectory);
+DbgPrint ("KeyName %wZ\n", ObjectAttributes->ObjectName);
/* FIXME: determine type of object for RootDirectory */
Status = ObReferenceObjectByHandle(ObjectAttributes->RootDirectory,
KEY_READ,
NULL);
if (!NT_SUCCESS(Status))
{
+CHECKPOINT1;
return Status;
}
ObjectHeader = BODY_TO_HEADER(ObjectBody);
PWSTR Remainder, NextSlash;
PKEY_BLOCK CurKeyBlock, SubKeyBlock;
+DbgPrint("KeyNameBuf %S\n", KeyNameBuf);
+
+CHECKPOINT1;
+ if (RegistryFile == NULL)
+ return STATUS_UNSUCCESSFUL;
+CHECKPOINT1;
+
/* FIXME: Should handle search by Class/TitleIndex */
/* Loop through each key level and find the needed subkey */
/* FIXME: this access of RootKeyBlock should be guarded by spinlock */
CurKeyBlock = CmiGetKeyBlock(RegistryFile, RegistryFile->HeaderBlock->RootKeyBlock);
Remainder = KeyNameBuf;
+ wcscpy(CurKeyName, Remainder);
while (NT_SUCCESS(Status) &&
(NextSlash = wcschr(Remainder, L'\\')) != NULL)
{
/* Copy just the current subkey name to a buffer */
wcsncpy(CurKeyName, Remainder, NextSlash - Remainder);
CurKeyName[NextSlash - Remainder] = 0;
+DbgPrint("CurKeyName %S\n", CurKeyName);
/* Verify existance of CurKeyName */
Status = CmiScanForSubKey(RegistryFile,
}
if (SubKeyBlock == NULL)
{
+CHECKPOINT1;
Status = STATUS_UNSUCCESSFUL;
continue;
}
}
if (NT_SUCCESS(Status))
{
+DbgPrint("CurKeyName %S\n", CurKeyName);
Status = CmiScanForSubKey(RegistryFile,
CurKeyBlock,
&SubKeyBlock,
{
if (SubKeyBlock == NULL)
{
+CHECKPOINT1;
Status = STATUS_UNSUCCESSFUL;
}
else
}
}
CmiReleaseBlock(RegistryFile, CurKeyBlock);
+CHECKPOINT1;
return Status;
}
PHASH_TABLE_BLOCK HashBlock;
PKEY_BLOCK CurSubKeyBlock;
+CHECKPOINT1;
HashBlock = CmiGetHashTableBlock(RegistryFile, KeyBlock->HashTableOffset);
*SubKeyBlock = NULL;
if (HashBlock == 0)
{
+CHECKPOINT1;
return STATUS_SUCCESS;
}
+CHECKPOINT1;
for (Idx = 0; Idx < HashBlock->HashTableSize; Idx++)
{
+DbgPrint ("KeyName %S HashValue %x\n", KeyName, HashBlock->Table[Idx].HashValue);
if (HashBlock->Table[Idx].KeyOffset != 0 &&
- !wcsncmp(KeyName, (PWSTR) &HashBlock->Table[Idx].HashValue, 4))
+ !wcsncmp(KeyName, (PWSTR) &HashBlock->Table[Idx].HashValue, 2))
+// !wcsncmp(KeyName, (PWSTR) &HashBlock->Table[Idx].HashValue, 4))
{
CurSubKeyBlock = CmiGetKeyBlock(RegistryFile,
HashBlock->Table[Idx].KeyOffset);
if (!wcscmp(KeyName, CurSubKeyBlock->Name))
{
+CHECKPOINT1;
*SubKeyBlock = CurSubKeyBlock;
break;
}