static NTSTATUS ElfCreateBackupLogHandle(PLOGHANDLE* LogHandle, PUNICODE_STRING FileName) { NTSTATUS Status = STATUS_SUCCESS; PLOGHANDLE pLogHandle; DPRINT("ElfCreateBackupLogHandle(%wZ)\n", FileName); *LogHandle = NULL; pLogHandle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LOGHANDLE)); if (pLogHandle == NULL) { DPRINT1("Failed to allocate Heap!\n"); return STATUS_NO_MEMORY; } /* Create the log file */ Status = LogfCreate(&pLogHandle->LogFile, NULL, FileName, 0, 0, FALSE, TRUE); if (!NT_SUCCESS(Status)) { DPRINT1("Failed to create the log file! (Status 0x%08lx)\n", Status); goto Done; } /* Set the backup flag */ pLogHandle->Flags |= LOG_HANDLE_BACKUP_FILE; /* Reset the current record */ pLogHandle->CurrentRecord = 0; Done: if (NT_SUCCESS(Status)) { /* Append log handle */ EnterCriticalSection(&LogHandleListCs); InsertTailList(&LogHandleListHead, &pLogHandle->LogHandleListEntry); LeaveCriticalSection(&LogHandleListCs); *LogHandle = pLogHandle; } else { HeapFree(GetProcessHeap(), 0, pLogHandle); } return Status; }
PLOGFILE LoadLogFile(HKEY hKey, WCHAR * LogName) { DWORD MaxValueLen, ValueLen, Type, ExpandedLen; WCHAR *Buf = NULL, *Expanded = NULL; LONG Result; PLOGFILE pLogf; DPRINT("LoadLogFile: %S\n", LogName); RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &MaxValueLen, NULL, NULL); Buf = HeapAlloc(MyHeap, 0, MaxValueLen); if (!Buf) { DPRINT1("Can't allocate heap!\n"); return NULL; } ValueLen = MaxValueLen; Result = RegQueryValueEx(hKey, L"File", NULL, &Type, (LPBYTE) Buf, &ValueLen); if (Result != ERROR_SUCCESS) { DPRINT1("RegQueryValueEx failed: %d\n", GetLastError()); HeapFree(MyHeap, 0, Buf); return NULL; } if (Type != REG_EXPAND_SZ && Type != REG_SZ) { DPRINT1("%S\\File - value of wrong type %x.\n", LogName, Type); HeapFree(MyHeap, 0, Buf); return NULL; } ExpandedLen = ExpandEnvironmentStrings(Buf, NULL, 0); Expanded = HeapAlloc(MyHeap, 0, ExpandedLen * sizeof(WCHAR)); if (!Expanded) { DPRINT1("Can't allocate heap!\n"); HeapFree(MyHeap, 0, Buf); return NULL; } ExpandEnvironmentStrings(Buf, Expanded, ExpandedLen); DPRINT("%S -> %S\n", Buf, Expanded); pLogf = LogfCreate(LogName, Expanded); if (pLogf == NULL) { DPRINT1("Failed to create %S!\n", Expanded); } HeapFree(MyHeap, 0, Buf); HeapFree(MyHeap, 0, Expanded); return pLogf; }
PLOGFILE LoadLogFile(HKEY hKey, WCHAR * LogName) { DWORD MaxValueLen, ValueLen, Type, ExpandedLen; WCHAR *Buf = NULL, *Expanded = NULL; LONG Result; PLOGFILE pLogf = NULL; UNICODE_STRING FileName; ULONG ulMaxSize, ulRetention; NTSTATUS Status; DPRINT("LoadLogFile: %S\n", LogName); Result = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &MaxValueLen, NULL, NULL); if (Result != ERROR_SUCCESS) { DPRINT1("RegQueryInfoKey failed: %lu\n", Result); return NULL; } Buf = HeapAlloc(MyHeap, 0, MaxValueLen); if (!Buf) { DPRINT1("Can't allocate heap!\n"); return NULL; } ValueLen = MaxValueLen; Result = RegQueryValueEx(hKey, L"File", NULL, &Type, (LPBYTE) Buf, &ValueLen); if (Result != ERROR_SUCCESS) { DPRINT1("RegQueryValueEx failed: %lu\n", Result); HeapFree(MyHeap, 0, Buf); return NULL; } if (Type != REG_EXPAND_SZ && Type != REG_SZ) { DPRINT1("%S\\File - value of wrong type %x.\n", LogName, Type); HeapFree(MyHeap, 0, Buf); return NULL; } ExpandedLen = ExpandEnvironmentStrings(Buf, NULL, 0); Expanded = HeapAlloc(MyHeap, 0, ExpandedLen * sizeof(WCHAR)); if (!Expanded) { DPRINT1("Can't allocate heap!\n"); HeapFree(MyHeap, 0, Buf); return NULL; } ExpandEnvironmentStrings(Buf, Expanded, ExpandedLen); if (!RtlDosPathNameToNtPathName_U(Expanded, &FileName, NULL, NULL)) { DPRINT1("Can't convert path!\n"); HeapFree(MyHeap, 0, Expanded); HeapFree(MyHeap, 0, Buf); return NULL; } DPRINT("%S -> %S\n", Buf, Expanded); ValueLen = sizeof(ULONG); Result = RegQueryValueEx(hKey, L"MaxSize", NULL, &Type, (LPBYTE)&ulMaxSize, &ValueLen); if (Result != ERROR_SUCCESS) ulMaxSize = 512 * 1024; /* 512 kBytes */ ValueLen = sizeof(ULONG); Result = RegQueryValueEx(hKey, L"Retention", NULL, &Type, (LPBYTE)&ulRetention, &ValueLen); if (Result != ERROR_SUCCESS) ulRetention = 0; Status = LogfCreate(&pLogf, LogName, &FileName, ulMaxSize, ulRetention, TRUE, FALSE); if (!NT_SUCCESS(Status)) { DPRINT1("Failed to create %S! (Status %08lx)\n", Expanded, Status); } HeapFree(MyHeap, 0, Buf); HeapFree(MyHeap, 0, Expanded); return pLogf; }