void RegSafeFreeValueAttributes( PLWREG_VALUE_ATTRIBUTES* ppValueAttrs ) { PLWREG_VALUE_ATTRIBUTES pValueAttrs = NULL; if ((ppValueAttrs == NULL) || (*ppValueAttrs == NULL)) { return; } pValueAttrs = *ppValueAttrs; RTL_FREE(&pValueAttrs->pDefaultValue); RTL_FREE(&pValueAttrs->pwszDocString); if (LWREG_VALUE_RANGE_TYPE_ENUM == pValueAttrs->RangeType) { if (pValueAttrs->Range.ppwszRangeEnumStrings) { RegFreeWC16StringArrayWithNullTerminator(pValueAttrs->Range.ppwszRangeEnumStrings); } pValueAttrs->Range.ppwszRangeEnumStrings = NULL; } RTL_FREE(&pValueAttrs); *ppValueAttrs = NULL; return; }
static BOOLEAN RdrQueryDfsReferral2Complete( PRDR_OP_CONTEXT pContext, NTSTATUS status, PVOID pParam ) { PSMB_PACKET pPacket = pParam; PBYTE pOutput = NULL; ULONG ulOutputSize = 0; BAIL_ON_NT_STATUS(status); status = pPacket->pSMB2Header->error; switch (status) { case STATUS_NO_SUCH_FILE: case STATUS_NO_SUCH_DEVICE: case STATUS_NOT_FOUND: /* Referral failed -- insert negative cache entry */ pOutput = NULL; ulOutputSize = 0; status = STATUS_SUCCESS; break; default: BAIL_ON_NT_STATUS(status); status = RdrSmb2DecodeIoctlResponse(pPacket, &pOutput, &ulOutputSize); BAIL_ON_NT_STATUS(status); } status = RdrDfsRegisterNamespace( pContext->State.DfsConnect.pwszNamespace, (PDFS_RESPONSE_HEADER) pOutput, (USHORT) ulOutputSize); BAIL_ON_NT_STATUS(status); status = RdrDfsConnectAttempt(pContext); BAIL_ON_NT_STATUS(status); cleanup: RdrFreePacket(pPacket); if (status != STATUS_PENDING) { RdrContinueContext(pContext->State.DfsConnect.pContinue, status, NULL); RTL_FREE(&pContext->State.DfsConnect.pwszNamespace); RTL_FREE(pContext->State.DfsConnect.ppwszCanonicalPath); RTL_FREE(pContext->State.DfsConnect.ppwszFilePath); RdrFreeContext(pContext); } return FALSE; error: goto cleanup; }
VOID RdrFreePacket( PSMB_PACKET pPacket ) { if (pPacket) { RTL_FREE(&pPacket->pRawBuffer); RTL_FREE(&pPacket); } }
VOID RdrFreeContext( PRDR_OP_CONTEXT pContext ) { if (pContext) { LWIO_LOG_DEBUG("Freed op context %p", pContext); RTL_FREE(&pContext->Packet.pRawBuffer); RTL_FREE(&pContext); } }
static NTSTATUS RdrIsInPlaceRename( PRDR_CCB pFile, PFILE_RENAME_INFORMATION pRenameInfo, PBOOLEAN pbIsInPlace ) { NTSTATUS status = STATUS_SUCCESS; PWSTR pwszShare = NULL; PWSTR pwszFile = NULL; PWSTR pwszExisting = NULL; PWSTR pwszNew = NULL; status = RdrConvertPath( pRenameInfo->FileName, NULL, &pwszShare, &pwszFile ); BAIL_ON_NT_STATUS(status); status = LwRtlWC16StringAllocatePrintfW( &pwszNew, L"%ws%ws", pwszShare, pwszFile); BAIL_ON_NT_STATUS(status); status = LwRtlWC16StringDuplicate(&pwszExisting, pFile->pwszCanonicalPath); BAIL_ON_NT_STATUS(status); RdrTrimLastPathElement(pwszNew); RdrTrimLastPathElement(pwszExisting); *pbIsInPlace = LwRtlWC16StringIsEqual(pwszNew, pwszExisting, FALSE); cleanup: RTL_FREE(&pwszShare); RTL_FREE(&pwszFile); RTL_FREE(&pwszExisting); RTL_FREE(&pwszNew); return status; error: *pbIsInPlace = FALSE; goto cleanup; }
VOID NtRegCloseConfig( PLWREG_CONFIG_REG pReg ) { if (pReg) { LwRtlCStringFree(&pReg->pszConfigKey); LwRtlCStringFree(&pReg->pszPolicyKey); if (pReg->hConnection) { if ( pReg->hKey ) { NtRegCloseKey(pReg->hConnection, pReg->hKey); pReg->hKey = NULL; } NtRegCloseServer(pReg->hConnection); pReg->hConnection = NULL; } RTL_FREE(&pReg); } }
VOID LwRtlThreadpoolDestructor( VOID ) { RTL_FREE(&gSignal.pSubscribers); }
LW_NTSTATUS LwRtlQueueWorkItem( LW_IN PLW_THREAD_POOL pPool, LW_IN LW_WORK_ITEM_FUNCTION_COMPAT pfnFunc, LW_IN LW_PVOID pContext, LW_IN LW_WORK_ITEM_FLAGS Flags ) { NTSTATUS status = STATUS_SUCCESS; PCOMPAT_WORK_ITEM pCompat = NULL; PLW_WORK_ITEM pItem = NULL; status = LW_RTL_ALLOCATE_AUTO(&pCompat); GOTO_ERROR_ON_STATUS(status); pCompat->pfnFunc = pfnFunc; pCompat->pContext = pContext; status = LwRtlCreateWorkItem(pPool, &pItem, CompatWorkItem, pCompat); GOTO_ERROR_ON_STATUS(status); pCompat = NULL; LwRtlScheduleWorkItem(pItem, Flags); pItem = NULL; error: RTL_FREE(&pCompat); LwRtlFreeWorkItem(&pItem); return status; }
LW_NTSTATUS LwRtlAnsiStringAllocatePrintfV( LW_OUT LW_PANSI_STRING pNewString, LW_IN LW_PCSTR Format, LW_IN va_list Args ) { NTSTATUS status = 0; PSTR pOutputString = NULL; ANSI_STRING newString = { 0 }; status = LwRtlCStringAllocatePrintfV( &pOutputString, Format, Args); GOTO_CLEANUP_ON_STATUS(status); status = LwRtlAnsiStringInitEx(&newString, pOutputString); GOTO_CLEANUP_ON_STATUS(status); pOutputString = NULL; cleanup: if (status) { RTL_ANSI_STRING_FREE(&newString); } RTL_FREE(&pOutputString); *pNewString = newString; return status; }
VOID LwIoRdrFreePhysicalPath( LW_PWSTR pResolved ) { RTL_FREE(&pResolved); }
NTSTATUS PvfsListInit( PPVFS_LIST *ppNewList, DWORD dwMaxSize, PPVFS_LIST_FREE_DATA_FN pfnFreeData ) { NTSTATUS ntError = STATUS_UNSUCCESSFUL; PPVFS_LIST pList = NULL; BAIL_ON_INVALID_PTR(ppNewList, ntError); ntError = RTL_ALLOCATE(&pList, PVFS_LIST, sizeof(PVFS_LIST)); BAIL_ON_NT_STATUS(ntError); pList->MaxSize = dwMaxSize; pList->CurrentSize = 0; pList->pfnFreeData = pfnFreeData; LwListInit(&pList->DataList); *ppNewList = pList; pList = NULL; ntError = STATUS_SUCCESS; cleanup: RTL_FREE(&pList); return ntError; error: goto cleanup; }
static VOID DestroyEventThread( PKQUEUE_THREAD pThread ) { pthread_mutex_destroy(&pThread->Lock); pthread_cond_destroy(&pThread->Event); if (pThread->KqueueFd >= 0) { close(pThread->KqueueFd); } if (pThread->SignalFds[0] >= 0) { close(pThread->SignalFds[0]); } if (pThread->SignalFds[1] >= 0) { close(pThread->SignalFds[1]); } RTL_FREE(&pThread->Commands.pCommands); }
VOID LwRtlFreeThreadPoolAttributes( LW_IN LW_OUT PLW_THREAD_POOL_ATTRIBUTES* ppAttrs ) { RTL_FREE(ppAttrs); }
static VOID StartWorkItem( PLW_WORK_ITEM pItem, PVOID pContext ) { NTSTATUS status = STATUS_SUCCESS; PSVCM_START_STATE pState = pContext; status = pState->pInstance->pTable->Start( pState->pInstance, pState->ArgCount, pState->ppArgs, pState->FdCount, pState->pFds); if (pState->Notify) { pState->Notify(pState->pInstance, status, pState->pNotifyContext); } RTL_FREE(&pState); LwRtlFreeWorkItem(&pItem); }
LW_NTSTATUS LwRtlWC16StringAllocateFromUnicodeString( LW_OUT LW_PWSTR* ppszNewString, LW_IN LW_PUNICODE_STRING pOriginalString ) { NTSTATUS status = 0; UNICODE_STRING terminatedOriginalString = { 0 }; PWSTR pszNewString = NULL; // Since duplicate always does NULL-termination, we can // safely use the Buffer field as a WC16String. status = LwRtlUnicodeStringDuplicate(&terminatedOriginalString, pOriginalString); GOTO_CLEANUP_ON_STATUS(status); pszNewString = terminatedOriginalString.Buffer; terminatedOriginalString.Buffer = NULL; terminatedOriginalString.Length = 0; terminatedOriginalString.MaximumLength = 0; cleanup: if (!NT_SUCCESS(status)) { RTL_FREE(&pszNewString); } LwRtlUnicodeStringFree(&terminatedOriginalString); *ppszNewString = pszNewString; return status; }
/* * Converts array of sid strings to array of sids */ static PSID* create_sid_list(char **strlist) { int list_len = 0; PSID* sid_list = NULL; int i = 0; if (strlist == NULL) return NULL; /* count the elements (including terminating zero) */ while (strlist[list_len++]); /* allocate the wchar16_t strings array */ sid_list = (PSID*) malloc(sizeof(PSID) * list_len); if (sid_list == NULL) return NULL; memset((void*)sid_list, 0, sizeof(PSID) * list_len); /* copy mbs strings to wchar16_t strings */ for (i = 0; strlist[i] && i < list_len; i++) { RtlAllocateSidFromCString(&sid_list[i], strlist[i]); if (sid_list[i] == NULL) { i--; while (i >= 0) { RTL_FREE(&sid_list[i--]); } free(sid_list); return NULL; } } return sid_list; }
NTSTATUS LwRtlWC16StringDuplicate( OUT PWSTR* ppszNewString, IN PCWSTR pszOriginalString ) { NTSTATUS status = 0; int EE ATTRIBUTE_UNUSED = 0; size_t size = 0; PWSTR pszNewString = NULL; if (!pszOriginalString) { status = STATUS_INVALID_PARAMETER; GOTO_CLEANUP_ON_STATUS_EE(status, EE); } size = (LwRtlWC16StringNumChars(pszOriginalString) + 1) * sizeof(pszOriginalString[0]); status = RTL_ALLOCATE(&pszNewString, wchar16_t, size); GOTO_CLEANUP_ON_STATUS_EE(status, EE); memcpy(pszNewString, pszOriginalString, size); cleanup: if (status) { RTL_FREE(&pszNewString); } *ppszNewString = pszNewString; return status; }
VOID LwRtlWC16StringFree( OUT PWSTR* ppszString ) { RTL_FREE(ppszString); }
NTSTATUS RtlDuplicateSid( OUT PSID* NewSid, IN PSID OriginalSid ) { NTSTATUS status = STATUS_SUCCESS; ULONG length = RtlLengthSid(OriginalSid); PSID resultSid = NULL; status = RTL_ALLOCATE(&resultSid, SID, length); GOTO_CLEANUP_ON_STATUS(status); RtlCopyMemory(resultSid, OriginalSid, length); cleanup: if (!NT_SUCCESS(status)) { RTL_FREE(&resultSid); } *NewSid = resultSid; return status; }
static VOID LwNtCreateFileComplete( PIO_CLIENT_ASYNC_CONTEXT pBase, NTSTATUS status ) { PCREATEFILE_CONTEXT pContext = (PCREATEFILE_CONTEXT) pBase; PNT_IPC_MESSAGE_CREATE_FILE_RESULT pResponse = pBase->out.data; if (status == STATUS_SUCCESS) { *pContext->FileHandle = pResponse->FileHandle; pResponse->FileHandle = NULL; pContext->IoStatusBlock->Status = pResponse->Status; pContext->IoStatusBlock->CreateResult = pResponse->CreateResult; status = pContext->IoStatusBlock->Status; } else { pContext->IoStatusBlock->Status = status; } if (pContext->Request.pSecurityToken) { LwIoDeleteCreds(pContext->Request.pSecurityToken); } if (pContext->Request.EcpList) { RTL_FREE(&pContext->Request.EcpList); } }
VOID PvfsFreeMemory( IN OUT PVOID *ppBuffer ) { RTL_FREE(ppBuffer); }
VOID LwRtlAnsiStringFree( IN OUT PANSI_STRING pString ) { RTL_FREE(&pString->Buffer); pString->Length = pString->MaximumLength = 0; }
VOID RdrFreeContextArray( PRDR_OP_CONTEXT pContexts, ULONG ulCount ) { ULONG ulIndex = 0; if (pContexts) { for (ulIndex = 0; ulIndex < ulCount; ulIndex++) { RTL_FREE(&pContexts[ulIndex].Packet.pRawBuffer); } RTL_FREE(&pContexts); } }
static VOID TaskDelete( PEPOLL_TASK pTask ) { RTL_FREE(&pTask->pUnixSignal); RtlMemoryFree(pTask); }
NTSTATUS RdrAllocateContextPacket( PRDR_OP_CONTEXT pContext, ULONG ulSize ) { RTL_FREE(&pContext->Packet.pRawBuffer); return RdrAllocatePacketBuffer(&pContext->Packet, ulSize); }
void RegSafeFreeCurrentValueInfo( PLWREG_CURRENT_VALUEINFO* ppValueInfo ) { PLWREG_CURRENT_VALUEINFO pValueInfo = NULL; if ((ppValueInfo == NULL) || (*ppValueInfo == NULL)) { return; } pValueInfo = *ppValueInfo; RTL_FREE(&pValueInfo->pvData); RTL_FREE(&pValueInfo); *ppValueInfo = NULL; return; }
void RdrReleaseFile2( PRDR_CCB2 pFile ) { if (pFile->pTree) { RdrTree2Release(pFile->pTree); } if (pFile->bMutexInitialized) { pthread_mutex_destroy(&pFile->mutex); } RTL_FREE(&pFile->pwszPath); RTL_FREE(&pFile->pwszCanonicalPath); LwIoFreeMemory(pFile); }
VOID RdrFreeTreeConnectContext( PRDR_OP_CONTEXT pContext ) { if (pContext) { RTL_FREE(&pContext->State.TreeConnect.pwszSharename); RdrFreePacket(pContext->State.TreeConnect.pPacket); if (pContext->State.TreeConnect.pszCachePath) { SMBKrb5DestroyCache(pContext->State.TreeConnect.pszCachePath); RTL_FREE(&pContext->State.TreeConnect.pszCachePath); } RdrFreeContext(pContext); } }
static VOID SrvShareFreeAbsoluteSecurityDescriptor( IN OUT PSECURITY_DESCRIPTOR_ABSOLUTE *ppSecDesc ) { NTSTATUS ntStatus = STATUS_SUCCESS; PSID pOwner = NULL; PSID pGroup = NULL; PACL pDacl = NULL; PACL pSacl = NULL; BOOLEAN bDefaulted = FALSE; BOOLEAN bPresent = FALSE; PSECURITY_DESCRIPTOR_ABSOLUTE pSecDesc = NULL; if ((ppSecDesc == NULL) || (*ppSecDesc == NULL)) { return; } pSecDesc = *ppSecDesc; ntStatus = RtlGetOwnerSecurityDescriptor(pSecDesc, &pOwner, &bDefaulted); ntStatus = RtlGetGroupSecurityDescriptor(pSecDesc, &pGroup, &bDefaulted); ntStatus = RtlGetDaclSecurityDescriptor(pSecDesc, &bPresent, &pDacl, &bDefaulted); ntStatus = RtlGetSaclSecurityDescriptor(pSecDesc, &bPresent, &pSacl, &bDefaulted); ntStatus = ntStatus; RTL_FREE(&pSecDesc); RTL_FREE(&pOwner); RTL_FREE(&pGroup); RTL_FREE(&pDacl); RTL_FREE(&pSacl); *ppSecDesc = NULL; return; }
static VOID LwNtCreateNamedPipeComplete( PVOID pParam ) { PCREATEPIPE_CONTEXT pContext = (PCREATEPIPE_CONTEXT) pParam; pContext->pChain->Callback(pContext->pChain->CallbackContext); IoRtlEcpListFree(&pContext->pEcpList); RTL_FREE(&pContext); }