Exemple #1
0
NTSTATUS
LsaAllocateSecurityDescriptor(
    OUT PSECURITY_DESCRIPTOR_RELATIVE   *ppOut,
    IN  PLSA_SECURITY_DESCRIPTOR_BUFFER  pIn
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    PSECURITY_DESCRIPTOR_RELATIVE pSecDesc = NULL;

    BAIL_ON_INVALID_PTR(ppOut, ntStatus);
    BAIL_ON_INVALID_PTR(pIn, ntStatus);

    ntStatus = LsaRpcAllocateMemory(OUT_PPVOID(&pSecDesc),
                                    pIn->BufferLen);
    BAIL_ON_NT_STATUS(ntStatus);

    memcpy(pSecDesc, pIn->pBuffer, pIn->BufferLen);

    *ppOut = pSecDesc;

cleanup:
    return ntStatus;

error:
    if (pSecDesc)
    {
        LsaRpcFreeMemory(pSecDesc);
    }

    *ppOut = NULL;

    goto cleanup;
}
Exemple #2
0
DWORD
LsaMarshalGroupInfo0ToGroupAddInfo(
    HANDLE hLsa,
    PLSA_GROUP_INFO_0 pGroupInfo,
    PLSA_GROUP_ADD_INFO* ppAddInfo
    )
{
    DWORD dwError = 0;
    PLSA_GROUP_ADD_INFO pAddInfo = NULL;

    dwError = LwAllocateMemory(sizeof(*pAddInfo), OUT_PPVOID(&pAddInfo));
    BAIL_ON_LSA_ERROR(dwError);

    pAddInfo->gid = pGroupInfo->gid;
    
    dwError = LwStrDupOrNull(pGroupInfo->pszName, &pAddInfo->pszName);
    BAIL_ON_LSA_ERROR(dwError);

    *ppAddInfo = pAddInfo;

cleanup:

    return dwError;
    
error:

    *ppAddInfo = NULL;

    if (pAddInfo)
    {
        LsaFreeGroupAddInfo(pAddInfo);
    }

    goto cleanup;
}
DWORD
LsaImplConvertMachinePasswordInfoWideToMultiByte(
    IN PLSA_MACHINE_PASSWORD_INFO_W pPasswordInfo,
    OUT PLSA_MACHINE_PASSWORD_INFO_A* ppNewPasswordInfo
    )
{
    DWORD dwError = 0;
    PLSA_MACHINE_PASSWORD_INFO_A pNewPasswordInfo = NULL;

    dwError = LwAllocateMemory(sizeof(*pNewPasswordInfo), OUT_PPVOID(&pNewPasswordInfo));
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaImplFillMachinePasswordInfoWideToMultiByte(pPasswordInfo, pNewPasswordInfo);
    BAIL_ON_LSA_ERROR(dwError);

error:
    if (dwError)
    {
        if (pNewPasswordInfo)
        {
            LsaImplFreeMachinePasswordInfoA(pNewPasswordInfo);
            pNewPasswordInfo = NULL;
        }
    }

    *ppNewPasswordInfo = pNewPasswordInfo;

    return dwError;
}
Exemple #4
0
static
DWORD
LwSmDriverConstruct(
    PLW_SERVICE_OBJECT pObject,
    PCLW_SERVICE_INFO pInfo,
    PVOID* ppData
    )
{
    DWORD dwError = 0;
    PDRIVER_STATE pState = NULL;

    dwError = LwAllocateMemory(sizeof(*pState), OUT_PPVOID(&pState));
    BAIL_ON_ERROR(dwError);

    dwError = LwSmCopyString(pInfo->pwszName, &pState->pName);
    BAIL_ON_ERROR(dwError);

    pState->State = LW_SERVICE_STATE_STOPPED;

    *ppData = pState;

error:

    return dwError;
}
Exemple #5
0
static
NTSTATUS
PvfsNotifyAllocateFilter(
    PPVFS_NOTIFY_FILTER_RECORD *ppNotifyRecord,
    PPVFS_IRP_CONTEXT pIrpContext,
    PPVFS_CCB pCcb,
    FILE_NOTIFY_CHANGE NotifyFilter,
    BOOLEAN bWatchTree
    )
{
    NTSTATUS ntError = STATUS_UNSUCCESSFUL;
    PPVFS_NOTIFY_FILTER_RECORD pFilter = NULL;

    ntError = PvfsAllocateMemory(
                  OUT_PPVOID(&pFilter),
                  sizeof(PVFS_NOTIFY_FILTER_RECORD),
                  TRUE);
    BAIL_ON_NT_STATUS(ntError);

    pFilter->pIrpContext = PvfsReferenceIrpContext(pIrpContext);
    pFilter->pCcb = PvfsReferenceCCB(pCcb);
    pFilter->NotifyFilter = NotifyFilter;
    pFilter->bWatchTree = bWatchTree;

    *ppNotifyRecord = pFilter;
    pFilter  = NULL;

cleanup:
    return ntError;

error:
    goto cleanup;
}
Exemple #6
0
/**
 * Get Net BIOS domain name from a fully qualified name.
 *
 * @param str Name to parse.
 * @param out Domain component.
 * @return 0 on success; error code on failure.
 */
DWORD GetDomainComp(IN PSTR str, OUT PSTR *out)
{
    DWORD dwError = 0;
    INT len = 0;

    if(!str || !str[0]) {
        *out = NULL;
        goto cleanup;
    }

    if(!IsDotPresent(str)) {
        dwError = LwStrDupOrNull(str, out);
        ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);
        goto cleanup;
    }

    len = GetFirstIndexOfChar(str, '.', 1);

    dwError = LwAllocateMemory(sizeof(CHAR) * (len + 1), OUT_PPVOID(out));
    ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

    strncpy(*out, str, len);

    cleanup:
        return dwError;

    error:
        goto cleanup;
}
Exemple #7
0
DWORD
LwSmSrvAcquireServiceHandle(
    PCWSTR pwszName,
    PLW_SERVICE_HANDLE phHandle
    )
{
    DWORD dwError = 0;
    PSM_TABLE_ENTRY pEntry = NULL;
    LW_SERVICE_HANDLE hHandle = NULL;

    dwError = LwSmTableGetEntry(pwszName, &pEntry);
    BAIL_ON_ERROR(dwError);

    dwError = LwAllocateMemory(sizeof(*hHandle), OUT_PPVOID(&hHandle));
    BAIL_ON_ERROR(dwError);

    hHandle->pEntry = pEntry;
    *phHandle = hHandle;
    
cleanup:
    
    return dwError;
    
error:
    
    *phHandle = NULL;
    
    if (pEntry)
    {
        LwSmTableReleaseEntry(pEntry);
    }
    
    goto cleanup;
}
Exemple #8
0
NTSTATUS
LwIoGetThreadState(
    OUT PIO_THREAD_STATE* ppState
    )
{
    NTSTATUS Status = STATUS_SUCCESS;
    PIO_THREAD_STATE pState = NULL;

    Status = LwIoThreadInit();
    BAIL_ON_NT_STATUS(Status);

    pState = pthread_getspecific(gStateKey);

    if (!pState)
    {
        Status = LwIoAllocateMemory(sizeof(*pState), OUT_PPVOID(&pState));
        BAIL_ON_NT_STATUS(Status);
        
        if (pthread_setspecific(gStateKey, pState))
        {
            Status = STATUS_INSUFFICIENT_RESOURCES;
            BAIL_ON_NT_STATUS(Status);
        }
    }

    *ppState = pState;

error:

    return Status;
}
Exemple #9
0
DWORD
LwSmQueryServiceDependencyClosure(
    LW_SERVICE_HANDLE hHandle,
    PWSTR** pppwszServiceList
    )
{
    DWORD dwError = 0;
    PWSTR* ppwszServiceList = NULL;

    dwError = LwAllocateMemory(sizeof(*ppwszServiceList) * 1, OUT_PPVOID(&ppwszServiceList));
    BAIL_ON_ERROR(dwError);

    dwError = LwSmQueryServiceDependencyClosureHelper(hHandle, &ppwszServiceList);
    BAIL_ON_ERROR(dwError);

    *pppwszServiceList = ppwszServiceList;

cleanup:

    return dwError;

error:

    *pppwszServiceList = NULL;

    if (ppwszServiceList)
    {
        LwSmFreeStringList(ppwszServiceList);
    }

    goto cleanup;
}
Exemple #10
0
DWORD
LwLdapEnablePageControlOption(
    HANDLE hDirectory
    )
{
    DWORD dwError = LW_ERROR_SUCCESS;
    PLW_LDAP_DIRECTORY_CONTEXT pDirectory = NULL;
    LDAPControl serverControl = {0};
    LDAPControl *ppServerPageCtrls[2] = {NULL, NULL};

    serverControl.ldctl_value.bv_val = NULL;
    serverControl.ldctl_value.bv_len = 0;
    serverControl.ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
    serverControl.ldctl_iscritical = 'T';

    ppServerPageCtrls[0] = &serverControl;

    pDirectory = (PLW_LDAP_DIRECTORY_CONTEXT)hDirectory;

    dwError = ldap_set_option(pDirectory->ld,
                              LDAP_OPT_SERVER_CONTROLS,
                              OUT_PPVOID(&ppServerPageCtrls));
    BAIL_ON_LDAP_ERROR(dwError);

cleanup:

    return dwError;

error:

    goto cleanup;
}
Exemple #11
0
/**
 * Get realm component from UPN..
 *
 * @param logonName Name to parse.
 * @return Realm component (Dynamically allocated.)
 */
PSTR GetRealmComp(IN PSTR logonName) {
    DWORD dwError = 0;
    PSTR name = NULL;
    int i;

    if(!logonName) {
        goto cleanup;
    }

    for(i = 0; i < strlen(logonName); ++i) {
        if(logonName[i] == '@') {
            dwError = LwStrDupOrNull(logonName + i + 1, &name);
            ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

            goto cleanup;
        }
    }

    for(i = 0; i < strlen(logonName); ++i) {
        if(logonName[i] == '/') {
            dwError = LwAllocateMemory(sizeof(CHAR) * (i + 1), OUT_PPVOID(&name));
            ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

            strncpy(name, (PCSTR) logonName, i);
            goto cleanup;
        }
    }

    cleanup:
        return name;

    error:
        goto cleanup;
}
DWORD
LsaImplDuplicateMachineAccountInfoW(
    IN PLSA_MACHINE_ACCOUNT_INFO_W pAccountInfo,
    OUT PLSA_MACHINE_ACCOUNT_INFO_W* ppNewAccountInfo
    )
{
    DWORD dwError = 0;
    PLSA_MACHINE_ACCOUNT_INFO_W pNewAccountInfo = NULL;

    dwError = LwAllocateMemory(sizeof(*pNewAccountInfo), OUT_PPVOID(&pNewAccountInfo));
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaImplFillMachineAccountInfoW(pAccountInfo, pNewAccountInfo);
    BAIL_ON_LSA_ERROR(dwError);

error:
    if (dwError)
    {
        if (pNewAccountInfo)
        {
            LsaImplFreeMachineAccountInfoW(pNewAccountInfo);
            pNewAccountInfo = NULL;
        }
    }

    *ppNewAccountInfo = pNewAccountInfo;

    return dwError;    
}
Exemple #13
0
NTSTATUS
RdrResolveToDomain(
    PCWSTR pwszHostname,
    PWSTR* ppwszDomain
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    BOOLEAN bLocked = FALSE;
    PWSTR pwszDomain = NULL;

    LWIO_LOCK_MUTEX(bLocked, &gRdrRuntime.Lock);

    if (!gRdrRuntime.pDomainHints)
    {
        status = STATUS_NOT_FOUND;
    }
    else
    {
        status = LwRtlHashMapFindKey(
            gRdrRuntime.pDomainHints,
            OUT_PPVOID(&pwszDomain),
            pwszHostname);
    }
    BAIL_ON_NT_STATUS(status);

    status = LwRtlWC16StringDuplicate(ppwszDomain, pwszDomain);
    BAIL_ON_NT_STATUS(status);

error:

    LWIO_UNLOCK_MUTEX(bLocked, &gRdrRuntime.Lock);

    return status;
}
Exemple #14
0
/**
 * Process option with a "-" value.
 *
 * @param str Password option address.
 * @return 0 on success; error code on failure.
 */
DWORD ProcessDash(IN PSTR * str) {
    DWORD dwError = 0;
    PSTR buf = NULL;
    INT len = 129;
    INT nLen = 0;

    if(str && *str && !strncmp((PCSTR) *str, "-", 1024)) {
        LW_SAFE_FREE_MEMORY(*str);

        dwError = LwAllocateMemory(len, OUT_PPVOID(&buf));
        ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

        *str = fgets(buf, len - 1, stdin);

        if(*str == NULL) {
            dwError = ADT_ERR_FAILED_STDIN;
            goto error;
        }
        
        nLen = strlen(*str);

        if((nLen > 1) && ((*str)[nLen - 1] == '\n')) {
            (*str)[nLen - 1] = (char) 0;
        }
    }

    cleanup:
        return dwError;

    error:
        goto cleanup;
}
Exemple #15
0
static
NTSTATUS
PvfsWildcardStackPush(
    IN OUT PLW_LIST_LINKS pStack,
    IN PSTR pszInputString,
    IN PSTR pszPattern
    )
{
    NTSTATUS ntError = STATUS_SUCCESS;
    PPVFS_WILDCARD_STATE_ENTRY pState = NULL;

    ntError = PvfsAllocateMemory(OUT_PPVOID(&pState), sizeof(*pState), TRUE);
    BAIL_ON_NT_STATUS(ntError);

    pState->pszInputString = pszInputString;
    pState->pszPattern = pszPattern;

    LwListInsertAfter(pStack, &pState->StackLinks);

cleanup:
    return ntError;

error:
    goto cleanup;
}
Exemple #16
0
static
NTSTATUS
PvfsWildcardStackPop(
    IN OUT PLW_LIST_LINKS pStack,
    OUT PSTR *ppszInputString,
    OUT PSTR *ppszPattern
    )
{
    NTSTATUS ntError = STATUS_SUCCESS;
    PLW_LIST_LINKS pStateLink = NULL;
    PPVFS_WILDCARD_STATE_ENTRY pState = NULL;

    pStateLink = LwListRemoveAfter(pStack);

    pState = LW_STRUCT_FROM_FIELD(
                 pStateLink,
                 PVFS_WILDCARD_STATE_ENTRY,
                 StackLinks);

    *ppszInputString = pState->pszInputString;
    *ppszPattern     = pState->pszPattern;

    PvfsFreeMemory(OUT_PPVOID(&pState));

    return ntError;
}
Exemple #17
0
DWORD
LwSmTableGetEntryDependencyClosure(
    PSM_TABLE_ENTRY pEntry,
    PWSTR** pppwszServiceList
    )
{
    DWORD dwError = 0;
    PWSTR* ppwszServiceList = NULL;

    dwError = LwAllocateMemory(sizeof(*ppwszServiceList) * 1, OUT_PPVOID(&ppwszServiceList));
    BAIL_ON_ERROR(dwError);

    dwError = LwSmTableGetEntryDependencyClosureHelper(pEntry, &ppwszServiceList);
    BAIL_ON_ERROR(dwError);

    *pppwszServiceList = ppwszServiceList;

cleanup:

    return dwError;

error:

    *pppwszServiceList = NULL;

    if (ppwszServiceList)
    {
        LwSmFreeStringList(ppwszServiceList);
    }

    goto cleanup;
}
Exemple #18
0
DWORD
LwByteArrayToHexStr(
    IN UCHAR* pucByteArray,
    IN DWORD dwByteArrayLength,
    OUT PSTR* ppszHexString
    )
{
    DWORD dwError = 0;
    DWORD i = 0;
    PSTR pszHexString = NULL;

    dwError = LwAllocateMemory(
                (dwByteArrayLength*2 + 1) * sizeof(CHAR),
                OUT_PPVOID(&pszHexString));
    BAIL_ON_LW_ERROR(dwError);

    for (i = 0; i < dwByteArrayLength; i++)
    {
        sprintf(pszHexString+(2*i), "%.2X", pucByteArray[i]);
    }

    *ppszHexString = pszHexString;

cleanup:

    return dwError;

error:
    LW_SAFE_FREE_STRING(pszHexString);

    *ppszHexString = NULL;
    goto cleanup;
}
Exemple #19
0
DWORD
LwStrndup(
    PCSTR pszInputString,
    size_t size,
    PSTR * ppszOutputString
)
{
    DWORD dwError = 0;
    size_t copylen = 0;
    PSTR pszOutputString = NULL;

    if (!pszInputString || !ppszOutputString){
        dwError = EINVAL;
        BAIL_ON_LW_ERROR(dwError);
    }

    for (copylen = 0; copylen < size && pszInputString[copylen]; copylen++);

    dwError = LwAllocateMemory(copylen+1, OUT_PPVOID(&pszOutputString));
    BAIL_ON_LW_ERROR(dwError);

    memcpy(pszOutputString, pszInputString, copylen);
    pszOutputString[copylen] = 0;

    *ppszOutputString = pszOutputString;

cleanup:
    return dwError;

error:
    LW_SAFE_FREE_STRING(pszOutputString);
    goto cleanup;
}
Exemple #20
0
static
NTSTATUS
InitPool(
    VOID
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    PLW_THREAD_POOL pNewPool = NULL;

    if (!gSvcmState.pPool)
    {
        status = LwRtlCreateThreadPool(&pNewPool, NULL);
        GCOS(status);

        if (InterlockedCompareExchangePointer(
            OUT_PPVOID(&gSvcmState.pPool),
            pNewPool,
            NULL) != NULL)
        {
            LwRtlFreeThreadPool(&pNewPool);
        }
    }

cleanup:

    return status;
}
static
NTSTATUS
PvfsCreateSetEndOfFileContext(
    OUT PPVFS_PENDING_SET_END_OF_FILE *ppSetEndOfFileContext,
    IN  PPVFS_IRP_CONTEXT pIrpContext,
    IN  PPVFS_CCB pCcb
    )
{
    NTSTATUS ntError = STATUS_UNSUCCESSFUL;
    PPVFS_PENDING_SET_END_OF_FILE pSetEndOfFileCtx = NULL;

    ntError = PvfsAllocateMemory(
                  OUT_PPVOID(&pSetEndOfFileCtx),
                  sizeof(PVFS_PENDING_SET_END_OF_FILE),
                  TRUE);
    BAIL_ON_NT_STATUS(ntError);

    pSetEndOfFileCtx->pIrpContext = PvfsReferenceIrpContext(pIrpContext);
    pSetEndOfFileCtx->pCcb = PvfsReferenceCCB(pCcb);

    *ppSetEndOfFileContext = pSetEndOfFileCtx;

    ntError = STATUS_SUCCESS;

cleanup:
    return ntError;

error:
    goto cleanup;
}
Exemple #22
0
/**
 * Get parent DN. This method dynamically allocates memory, which must be freed.
 *
 * @param str DN to parse.
 * @param out parent DN.
 * @return 0 on success; error code on failure.
 */
DWORD GetParentDN(IN PSTR str, OUT PSTR *out)
{
    DWORD dwError = 0;
    INT len = 0;
    INT ind = 0;

    if(!str || !str[0]) {
        *out = NULL;
        goto cleanup;
    }

    if(!IsCommaPresent(str)) {
        dwError = LwStrDupOrNull("", out);
        ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);
        goto cleanup;
    }

    ind = GetFirstIndexOfChar(str, ',', 1);
    len = strlen(str) - ind;

    dwError = LwAllocateMemory(sizeof(CHAR) * (len + 1), OUT_PPVOID(out));
    ADT_BAIL_ON_ALLOC_FAILURE_NP(!dwError);

    strncpy(*out, str + ind + 1, len - 1);

    cleanup:
        return dwError;

    error:
        goto cleanup;
}
Exemple #23
0
static
DWORD
AppendStringArray(
    PDWORD pdwCount,
    PWSTR** pppwszArray,
    PWSTR pwszString
    )
{
    DWORD dwError = 0;
    PWSTR* ppwszNewArray = NULL;

    dwError = LwReallocMemory(
        *pppwszArray,
        OUT_PPVOID(&ppwszNewArray),
        sizeof(*ppwszNewArray) * (*pdwCount + 1));
    BAIL_ON_SRVSVC_ERROR(dwError);

    ppwszNewArray[(*pdwCount)++] = pwszString;

    *pppwszArray = ppwszNewArray;

error:

    return dwError;
}
Exemple #24
0
static
BOOLEAN
CallNetrSamLogonInteractiveEx(
    NETR_BINDING           hSchannel,
    NetrCredentials      *pNetlogonCreds,
    PWSTR                  pwszServer,
    PWSTR                  pwszDomain,
    PWSTR                  pwszComputer,
    PWSTR                  pwszUsername,
    PWSTR                  pwszPassword,
    DWORD                  logonLevel,
    PDWORD                 pValidationLevels,
    DWORD                  numValidationLevels,
    NetrValidationInfo  ***pppSamLogonInfo
)
{
    BOOLEAN bRet = TRUE;
    DWORD dwError = ERROR_SUCCESS;
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD validationLevel = 0;
    DWORD i = 0;
    NetrValidationInfo *pValidationInfo = NULL;
    NetrValidationInfo **ppSamLogonInfo = NULL;
    BYTE Authoritative = 0;
    DWORD totalNumLevels = 7;

    dwError = LwAllocateMemory(sizeof(ppSamLogonInfo[0]) * totalNumLevels,
                               OUT_PPVOID(&ppSamLogonInfo));
    BAIL_ON_WIN_ERROR(dwError);

    for (i = 0; i < numValidationLevels; i++)
    {
        validationLevel = pValidationLevels[i];

        CALL_MSRPC(ntStatus, NetrSamLogonEx(
                       hSchannel,
                       pNetlogonCreds,
                       pwszServer,
                       pwszDomain,
                       pwszComputer,
                       pwszUsername,
                       pwszPassword,
                       logonLevel,
                       validationLevel,
                       &pValidationInfo,
                       &Authoritative));
        if (ntStatus)
        {
            bRet = FALSE;
        }

        ppSamLogonInfo[validationLevel] = pValidationInfo;
    }

    *pppSamLogonInfo = ppSamLogonInfo;

error:
    return bRet;
}
static
NTSTATUS
LsaSrvQueryAccountSecurity(
    PLSAR_ACCOUNT_CONTEXT pAccountContext,
    SECURITY_INFORMATION SecurityInformation,
    PSECURITY_DESCRIPTOR_RELATIVE *ppSecurityDescRelative,
    PDWORD pSecurityDescRelativeSize
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD err = ERROR_SUCCESS;
    PSECURITY_DESCRIPTOR_RELATIVE pSecDescRelative = NULL;
    DWORD secDescRelativeSize = 0;
    PSECURITY_DESCRIPTOR_RELATIVE pSecurityDescRelative = NULL;

    err = LsaSrvPrivsGetAccountSecurity(
                        NULL,
                        pAccountContext->pPolicyCtx->pUserToken,
                        pAccountContext->pAccountContext,
                        SecurityInformation,
                        &pSecDescRelative,
                        &secDescRelativeSize);
    BAIL_ON_LSA_ERROR(err);

    ntStatus = LsaSrvAllocateMemory(
                        OUT_PPVOID(&pSecurityDescRelative),
                        secDescRelativeSize);
    BAIL_ON_NT_STATUS(ntStatus);

    memcpy(pSecurityDescRelative,
           pSecDescRelative,
           secDescRelativeSize);

    *ppSecurityDescRelative    = pSecurityDescRelative;
    *pSecurityDescRelativeSize = secDescRelativeSize;

error:
    if (err || ntStatus)
    {
        if (pSecurityDescRelative)
        {
            LsaSrvFreeMemory(pSecurityDescRelative);
        }

        *ppSecurityDescRelative    = NULL;
        *pSecurityDescRelativeSize = 0;
    }

    LW_SAFE_FREE_MEMORY(pSecDescRelative);

    if (ntStatus == STATUS_SUCCESS &&
        err != ERROR_SUCCESS)
    {
        ntStatus = LwWin32ErrorToNtStatus(err);
    }

    return ntStatus;
}
Exemple #26
0
DWORD
LwURLEncodeString(
    PCSTR pIn,
    PSTR *ppOut
    )
{
    DWORD dwError = 0;
    const char *pRequireEscape = "$&+,/:;=?@ \"'<>#%{}|\\^~[]`";
    size_t outputPos = 0;
    size_t i = 0;
    PSTR pOut = NULL;

    for (i = 0; pIn[i]; i++)
    {
        if (pIn[i] < 0x20 || pIn[i] >= 0x7F ||
                strchr(pRequireEscape, pIn[i]) != NULL)
        {
            outputPos+=3;
        }
        else
        {
            outputPos++;
        }
    }

    // Space for the NULL
    outputPos++;

    dwError = LwAllocateMemory(
                    outputPos,
                    OUT_PPVOID(&pOut));
    BAIL_ON_LW_ERROR(dwError);

    for (outputPos = 0, i = 0; pIn[i]; i++)
    {
        if (pIn[i] < 0x20 || pIn[i] >= 0x7F ||
                strchr(pRequireEscape, pIn[i]) != NULL)
        {
            sprintf(pOut + outputPos, "%%%.2X", (BYTE)pIn[i]);
            outputPos+=3;
        }
        else
        {
            pOut[outputPos] = pIn[i];
            outputPos++;
        }
    }

    *ppOut = pOut;

cleanup:
    return dwError;

error:
    *ppOut = NULL;
    LW_SAFE_FREE_STRING(pOut);
    goto cleanup;
}
Exemple #27
0
static
DWORD
AD_ConvertMultiStringToStringArray(
    IN PCSTR pszMultiString,
    OUT PSTR** pppszStringArray,
    OUT PDWORD pdwCount
)
{
    DWORD dwError = 0;
    PSTR* ppszStringArray = NULL;
    DWORD dwCount = 0;
    PCSTR pszIter = NULL;
    DWORD dwIndex = 0;

    dwCount = 0;
    for (pszIter = pszMultiString;
            pszIter && *pszIter;
            pszIter += strlen(pszIter) + 1)
    {
        dwCount++;
    }

    if (dwCount)
    {
        dwError = LwAllocateMemory(
                      dwCount * sizeof(*ppszStringArray),
                      OUT_PPVOID(&ppszStringArray));
        BAIL_ON_LSA_ERROR(dwError);
    }

    dwIndex = 0;
    for (pszIter = pszMultiString;
            pszIter && *pszIter;
            pszIter += strlen(pszIter) + 1)
    {
        dwError = LwAllocateString(pszIter, &ppszStringArray[dwIndex]);
        BAIL_ON_LSA_ERROR(dwError);

        dwIndex++;
    }

    LSA_ASSERT(dwIndex == dwCount);

cleanup:

    *pppszStringArray = ppszStringArray;
    *pdwCount = dwCount;

    return dwError;

error:

    LwFreeStringArray(ppszStringArray, dwCount);
    ppszStringArray = NULL;
    dwCount = 0;

    goto cleanup;
}
static
DWORD
LsaPstorepInitializePlugin(
    OUT PLSA_PSTORE_PLUGIN_INFO PluginInfo,
    IN PCSTR PluginName
    )
{
    DWORD dwError = 0;
    int EE = 0;
    LSA_PSTORE_PLUGIN_INITIALIZE_FUNCTION initFunction = NULL;

    dwError = LwNtStatusToWin32Error(LwRtlCStringDuplicate(&PluginInfo->Name, PluginName));
    GOTO_CLEANUP_ON_WINERROR_EE(dwError, EE);

    dwError = LsaPstorepGetPluginPath(PluginInfo->Name, &PluginInfo->Path);
    GOTO_CLEANUP_ON_WINERROR_EE(dwError, EE);
    
    dwError = LsaPstorepOpenPlugin(
                    PluginInfo->Path,
                    LSA_PSTORE_PLUGIN_INITIALIZE_FUNCTION_NAME,
                    &PluginInfo->LibraryHandle,
                    OUT_PPVOID(&initFunction));
    GOTO_CLEANUP_ON_WINERROR_EE(dwError, EE);

    dwError = initFunction(LSA_PSTORE_PLUGIN_VERSION,
                           PluginInfo->Name,
                           &PluginInfo->Dispatch,
                           &PluginInfo->Context);
    GOTO_CLEANUP_ON_WINERROR_EE(dwError, EE);

    if (!PluginInfo->Dispatch)
    {
        LW_RTL_LOG_ERROR("LSA pstore plugin %s is missing a dispatch table",
                         PluginInfo->Name);
        dwError = ERROR_DLL_INIT_FAILED;
        GOTO_CLEANUP_EE(EE);
    }

    if (!PluginInfo->Dispatch->Cleanup)
    {
        LW_RTL_LOG_ERROR("LSA pstore plugin %s is missing the Cleanup function",
                         PluginInfo->Name);
        dwError = ERROR_DLL_INIT_FAILED;
        GOTO_CLEANUP_EE(EE);
    }

    LW_RTL_LOG_VERBOSE("Loaded LSA pstore plugin %s from %s",
                       PluginInfo->Name, PluginInfo->Path);

cleanup:
    if (dwError)
    {
        LsaPstorepCleanupPlugin(PluginInfo);
    }

    LSA_PSTORE_LOG_LEAVE_ERROR_EE(dwError, EE);
    return dwError;
}
Exemple #29
0
static
NTSTATUS
PvfsFindParentFCB(
    PPVFS_FCB *ppParentFcb,
    PCSTR pszFilename
    )
{
    NTSTATUS ntError = STATUS_UNSUCCESSFUL;
    PPVFS_FCB pFcb = NULL;
    PSTR pszDirname = NULL;
    PPVFS_CB_TABLE_ENTRY pBucket = NULL;

    if (LwRtlCStringIsEqual(pszFilename, "/", TRUE))
    {
        ntError = STATUS_SUCCESS;
        *ppParentFcb = NULL;

        goto cleanup;
    }

    ntError = PvfsFileDirname(&pszDirname, pszFilename);
    BAIL_ON_NT_STATUS(ntError);

    ntError = PvfsCbTableGetBucket(&pBucket, &gPvfsDriverState.FcbTable, pszDirname);
    BAIL_ON_NT_STATUS(ntError);

    ntError = PvfsCbTableLookup((PPVFS_CONTROL_BLOCK*)OUT_PPVOID(&pFcb), pBucket, pszDirname);
    if (ntError == STATUS_OBJECT_NAME_NOT_FOUND)
    {
        ntError = PvfsCreateFCB(
                      &pFcb,
                      pszDirname,
                      FALSE,
                      0,
                      0);
    }
    BAIL_ON_NT_STATUS(ntError);

    *ppParentFcb = PvfsReferenceFCB(pFcb);

cleanup:
    if (pFcb)
    {
        PvfsReleaseFCB(&pFcb);
    }

    if (pszDirname)
    {
        LwRtlCStringFree(&pszDirname);
    }

    return ntError;

error:

    goto cleanup;
}
NTSTATUS
LwNtFsControlFile(
    IN IO_FILE_HANDLE FileHandle,
    IN OUT OPTIONAL PIO_ASYNC_CONTROL_BLOCK AsyncControlBlock,
    OUT PIO_STATUS_BLOCK IoStatusBlock,
    IN ULONG FsControlCode,
    IN PVOID InputBuffer,
    IN ULONG InputBufferLength,
    OUT PVOID OutputBuffer,
    IN ULONG OutputBufferLength
    )
{
    NTSTATUS status = 0;
    int EE = 0;
    PFSCONTROL_CONTEXT pControlContext = NULL;

    status = NtpAllocAsyncContext(OUT_PPVOID(&pControlContext), sizeof(*pControlContext));
    GOTO_CLEANUP_ON_STATUS_EE(status, EE);

    pControlContext->Request.FileHandle = FileHandle;
    pControlContext->Request.ControlCode = FsControlCode;
    pControlContext->Request.InputBuffer = InputBuffer;
    pControlContext->Request.InputBufferLength = InputBufferLength;
    pControlContext->Request.OutputBufferLength = OutputBufferLength;
    pControlContext->IoStatusBlock = IoStatusBlock;
    pControlContext->OutputBuffer = OutputBuffer;
    pControlContext->OutputBufferLength = OutputBufferLength;

    status = NtpCtxCallAsync(
        &pControlContext->Base,
        NT_IPC_MESSAGE_TYPE_FS_CONTROL_FILE,
        &pControlContext->Request,
        NT_IPC_MESSAGE_TYPE_FS_CONTROL_FILE_RESULT,
        AsyncControlBlock,
        LwNtFsControlFileComplete);
    GOTO_CLEANUP_ON_STATUS_EE(status, EE);

cleanup:

    if (status != STATUS_PENDING)
    {
        if (pControlContext)
        {
            LwNtFsControlFileComplete(&pControlContext->Base, status);
            status = IoStatusBlock->Status;
            NtpFreeClientAsyncContext(&pControlContext->Base);
        }
        else
        {
            IoStatusBlock->Status = status;
        }
    }

    LOG_LEAVE_IF_STATUS_EE(status, EE);

    return status;
}