Example #1
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;
}
Example #2
0
DWORD
ADCacheDuplicateMembership(
    PLSA_GROUP_MEMBERSHIP* ppDest,
    PLSA_GROUP_MEMBERSHIP pSrc
    )
{
    DWORD dwError = 0;
    PLSA_GROUP_MEMBERSHIP pDest = NULL;

    dwError = LwAllocateMemory(
                    sizeof(*pDest),
                    (PVOID*)&pDest);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = ADCacheDuplicateMembershipContents(
                    pDest,
                    pSrc);
    BAIL_ON_LSA_ERROR(dwError);

    *ppDest = pDest;

cleanup:
    return dwError;

error:
    ADCacheSafeFreeGroupMembership(&pDest);
    *ppDest = NULL;
    goto cleanup;
}
Example #3
0
static
DWORD
CreateQueryListEntry(
    OUT PLSA_AD_QUERY_LISTS_ENTRY* ppEntry,
    IN DWORD dwQueryCount,
    IN PSTR* ppszQueryValues
    )
{
    DWORD dwError = 0;
    PLSA_AD_QUERY_LISTS_ENTRY pEntry = NULL;

    dwError = LwAllocateMemory(sizeof(*pEntry), (PVOID*)&pEntry);
    BAIL_ON_LSA_ERROR(dwError);

    pEntry->dwQueryCount = dwQueryCount;
    pEntry->ppszQueryValues = ppszQueryValues;

    *ppEntry = pEntry;

cleanup:
    return dwError;

error:
    *ppEntry = NULL;
    DestroyQueryListEntry(&pEntry);
    goto cleanup;
}
Example #4
0
DWORD
LsaBuildGroupModInfo(
    gid_t gid,
    PLSA_GROUP_MOD_INFO* ppGroupModInfo
    )
{
    DWORD dwError = 0;
    PLSA_GROUP_MOD_INFO pGroupModInfo = NULL;

    dwError = LwAllocateMemory(
                    sizeof(LSA_GROUP_MOD_INFO),
                    (PVOID*)&pGroupModInfo);
    BAIL_ON_LSA_ERROR(dwError);

    pGroupModInfo->gid = gid;

    *ppGroupModInfo = pGroupModInfo;

cleanup:
    return dwError;

error:
    if (pGroupModInfo) {
        LsaFreeGroupModInfo(pGroupModInfo);
    }

    *ppGroupModInfo = NULL;
    goto cleanup;
}
Example #5
0
DWORD
LWSaveConfigSectionList(
    PCSTR pszConfigFilePath,
    PCFGSECTION pSectionList
    )
{
    DWORD dwError = 0;
    /*PNVPAIR pNVPair = NULL;*/
    FILE* fp = NULL;
    PSTR pszTmpPath = NULL;
    BOOLEAN bRemoveFile = FALSE;

    dwError = LwAllocateMemory(strlen(pszConfigFilePath)+strlen(".macadutil")+1,
                               (PVOID*)&pszTmpPath);
    BAIL_ON_MAC_ERROR(dwError);

    sprintf(pszTmpPath, "%s.macadutil", pszConfigFilePath);

    if ((fp = fopen(pszTmpPath, "w")) == NULL) {
        dwError = errno;
        BAIL_ON_MAC_ERROR(dwError);
    }

    if (fcntl(fileno(fp), F_SETFD, FD_CLOEXEC) < 0) {
        dwError = errno;
        BAIL_ON_MAC_ERROR(dwError);
    }

    bRemoveFile = TRUE;

    dwError = LWSaveConfigSectionListToFile(fp, pSectionList);
    BAIL_ON_MAC_ERROR(dwError);

    fclose(fp); fp = NULL;

    dwError = LwMoveFile(pszTmpPath, pszConfigFilePath);
    BAIL_ON_MAC_ERROR(dwError);

    bRemoveFile = FALSE;

cleanup:

    if (bRemoveFile)
    {
        LwRemoveFile(pszTmpPath);
    }

    if (fp)
    {
        fclose(fp);
    }

    LW_SAFE_FREE_STRING(pszTmpPath);

    return dwError;

error:

    goto cleanup;
}
Example #6
0
static
NSS_STATUS
LsaNssPushNetgroup(
    PLSA_NSS_NETGROUP_LIST* ppList,
    PCSTR pszGroup
    )
{
    int ret = NSS_STATUS_SUCCESS;
    PLSA_NSS_NETGROUP_LIST pLink = NULL;

    ret = MAP_LSA_ERROR(NULL,
                        LwAllocateMemory(
                            sizeof(*pLink),
                            (void**) &pLink));
    BAIL_ON_NSS_ERROR(ret);

    ret = MAP_LSA_ERROR(NULL,
                        LwAllocateString(
                            pszGroup,
                            &pLink->pszGroup));
    BAIL_ON_NSS_ERROR(ret);

    pLink->pNext = *ppList;
    *ppList = pLink;

error:

    return ret;
}
Example #7
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;
}
Example #8
0
static
DWORD
LwmEvtSrvCreateError(
    DWORD ErrorCode,
    PCWSTR pErrorMessage,
    PEVT_IPC_GENERIC_ERROR* ppError
)
{
    DWORD dwError = 0;
    PEVT_IPC_GENERIC_ERROR pError = NULL;

    dwError = LwAllocateMemory(sizeof(*pError), (PVOID*) &pError);
    BAIL_ON_EVT_ERROR(dwError);

    if (pErrorMessage)
    {
        dwError = LwAllocateWc16String(
                      (PWSTR*)&pError->pErrorMessage,
                      pErrorMessage);
        BAIL_ON_EVT_ERROR(dwError);
    }

    pError->Error = ErrorCode;

    *ppError = pError;

error:
    return dwError;
}
Example #9
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
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;
}
Example #11
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;
}
Example #12
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;
}
Example #13
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;
}
Example #14
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;
}
Example #15
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;
}
Example #16
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;
}
Example #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;
}
Example #18
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;
}
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;    
}
Example #20
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;
}
Example #21
0
static
DWORD
ADUGetGPTINIFile(
    PSTR  pszgPCFileSysPath,
    PSTR* ppszGPTINIFilePath
    )
{
    DWORD dwError = MAC_AD_ERROR_SUCCESS;
    char szSourceFilePath[PATH_MAX + 1];
    PSTR pszDestFilePath = NULL;
    PSTR pszSourcePath = NULL;
    PSTR pszDomainName = NULL;
    PSTR pszPolicyIdentifier = NULL;

    dwError = LwAllocateMemory( PATH_MAX + 1,
                                (PVOID*)&pszDestFilePath);
    BAIL_ON_MAC_ERROR(dwError);

    dwError =  ADUCrackFileSysPath(pszgPCFileSysPath,
                                    &pszDomainName,
                                    &pszSourcePath,
                                    &pszPolicyIdentifier);
    BAIL_ON_MAC_ERROR(dwError);

    sprintf( szSourceFilePath,
             "%s\\%s",
             pszSourcePath,
             "GPT.INI");

    sprintf(pszDestFilePath,
            "%s/%s_GPT.INI",
            LWDS_ADMIN_CACHE_DIR,
            pszPolicyIdentifier);

    dwError = ADUSMBGetFile(pszDomainName,
                             szSourceFilePath,
                             pszDestFilePath);
    BAIL_ON_MAC_ERROR(dwError);

    *ppszGPTINIFilePath = pszDestFilePath;
    pszDestFilePath = NULL;

cleanup:

    LW_SAFE_FREE_STRING(pszDomainName);
    LW_SAFE_FREE_STRING(pszSourcePath);
    LW_SAFE_FREE_STRING(pszPolicyIdentifier);
    LW_SAFE_FREE_STRING(pszDestFilePath);

    return dwError;

error:

    if (ppszGPTINIFilePath)
        *ppszGPTINIFilePath = NULL;

    goto cleanup;
}
Example #22
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;
}
Example #23
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;
}
Example #24
0
DWORD
SedEscapeLiteral(
    PCSTR pInput,
    PSTR* ppOutput
    )
{
    PSTR pOutput = NULL;
    DWORD outputIndex = 0;
    DWORD index = 0;
    DWORD dwError = 0;

    // Calculate the length first
    for (index = 0; pInput[index]; index++)
    {
        switch (pInput[index])
        {
            // See the \char section of gnu sed manual
            case '$':
            case '*':
            case '.':
            case '[':
            case '\\':
            case '^':
                outputIndex += 2;
                break;
            default:
                outputIndex += 1;
        }
    }

    dwError = LwAllocateMemory(
                    outputIndex + 1,
                    PPCAST(&pOutput));
    BAIL_ON_CENTERIS_ERROR(dwError);

    outputIndex = 0;
    for (index = 0; pInput[index]; index++)
    {
        switch (pInput[index])
        {
            // See the \char section of gnu sed manual
            case '$':
            case '*':
            case '.':
            case '[':
            case '\\':
            case '^':
                pOutput[outputIndex++] = '\\';
                break;
        }
        pOutput[outputIndex++] = pInput[index];
    }
    pOutput[outputIndex++] = 0;

error:
    *ppOutput = pOutput;
    return dwError;
}
Example #25
0
DWORD
LsaNssAllocateGroupFromInfo0(
        PLSA_GROUP_INFO_0 pInfo,
        struct group** ppResult
        )
{
    DWORD dwError = LW_ERROR_SUCCESS;
    // Do not free directly. Free pStartMem instead on error
    struct group* pResult = NULL;
    void *pStartMem = NULL;
    // Do not free
    PBYTE pMem = NULL;
    size_t sRequiredSize = 0;
    size_t sLen = 0;

    sRequiredSize += sizeof(struct group);
    sRequiredSize += strlen(pInfo->pszName) + 1;
    sRequiredSize += 2;

    dwError = LwAllocateMemory(
            sRequiredSize,
            &pStartMem);
    BAIL_ON_LSA_ERROR(dwError);

    pMem = pStartMem;
    pResult = (struct group *)pMem;
    pMem += sizeof(struct group);

    pResult->gr_mem = NULL;

    sLen = strlen(pInfo->pszName);
    pResult->gr_name = (char *)pMem;
    memcpy(pResult->gr_name, pInfo->pszName, sLen + 1);
    pMem += sLen + 1;

    sLen = 1;
    pResult->gr_passwd = (char *)pMem;
    memcpy(pResult->gr_passwd, "*", sLen + 1);
    pMem += sLen + 1;

    pResult->gr_gid = pInfo->gid;

    assert(pMem == pStartMem + sRequiredSize);

    *ppResult = pResult;

cleanup:

    return dwError;

error:

    *ppResult = NULL;
    LW_SAFE_FREE_MEMORY(pStartMem);

    goto cleanup;
}
Example #26
0
static
DWORD
LsaAllocateGroupInfo_1(
    PLSA_GROUP_INFO_1 *ppDstGroupInfo,
    DWORD dwLevel,
    PLSA_GROUP_INFO_1 pSrcGroupInfo
    )
{
    DWORD dwError = 0;
    PLSA_GROUP_INFO_1 pGroupInfo = NULL;

    dwError = LwAllocateMemory(sizeof(*pGroupInfo),
                                (PVOID*)&pGroupInfo);
    BAIL_ON_LSA_ERROR(dwError);

    if (pSrcGroupInfo) {
        pGroupInfo->gid = pSrcGroupInfo->gid;

        if (pSrcGroupInfo->pszName) {
            dwError = LwAllocateString(pSrcGroupInfo->pszName,
                                        &pGroupInfo->pszName);
            BAIL_ON_LSA_ERROR(dwError);
        }

        if (pSrcGroupInfo->pszSid) {
            dwError = LwAllocateString(pSrcGroupInfo->pszSid,
                                        &pGroupInfo->pszSid);
            BAIL_ON_LSA_ERROR(dwError);
        }

        if (pSrcGroupInfo->pszDN) {
            dwError = LwAllocateString(pSrcGroupInfo->pszDN,
                                        &pGroupInfo->pszDN);
            BAIL_ON_LSA_ERROR(dwError);
        }

        if (pSrcGroupInfo->pszPasswd) {
            dwError = LwAllocateString(pSrcGroupInfo->pszPasswd,
                                        &pGroupInfo->pszPasswd);
            BAIL_ON_LSA_ERROR(dwError);
        }
    }

    *ppDstGroupInfo = pGroupInfo;

cleanup:
    return dwError;

error:
    if (pGroupInfo) {
        LsaFreeGroupInfo(dwLevel, pGroupInfo);
    }

    *ppDstGroupInfo = NULL;
    goto cleanup;
}
Example #27
0
DWORD
NtlmGetWorkstationFromResponse(
    IN PNTLM_RESPONSE_MESSAGE_V1 pRespMsg,
    IN DWORD dwRespMsgSize,
    IN BOOLEAN bUnicode,
    OUT PSTR* ppWorkstation
    )
{
    DWORD dwError = LW_ERROR_SUCCESS;
    PCHAR pName = NULL;
    DWORD dwNameLength = 0;
    PBYTE pBuffer = NULL;
    PNTLM_SEC_BUFFER pSecBuffer = &pRespMsg->Workstation;

    *ppWorkstation = NULL;

    if (dwRespMsgSize < sizeof(*pRespMsg))
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_LSA_ERROR(dwError);
    }

    if (LW_LTOH32(pSecBuffer->dwOffset) + LW_LTOH16(pSecBuffer->usLength) > dwRespMsgSize)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_LSA_ERROR(dwError);
    }

    dwNameLength = LW_LTOH16(pSecBuffer->usLength);
    pBuffer = LW_LTOH32(pSecBuffer->dwOffset) + (PBYTE)pRespMsg;

    if (!bUnicode)
    {
        dwError = LwAllocateMemory(dwNameLength + 1, OUT_PPVOID(&pName));
        BAIL_ON_LSA_ERROR(dwError);

        memcpy(pName, pBuffer, dwNameLength);
    }
    else
    {
        dwError = NtlmGetCStringFromUnicodeBuffer(
                      pBuffer,
                      dwNameLength,
                      &pName);
        BAIL_ON_LSA_ERROR(dwError);

    }

cleanup:
    *ppWorkstation = pName;
    return dwError;
error:
    LW_SAFE_FREE_STRING(pName);
    goto cleanup;
}
Example #28
0
DWORD
LsaLogGetInfo(
    PLSA_LOG_INFO* ppLogInfo
    )
{
    DWORD dwError = 0;
    PLSA_LOG_INFO pLogInfo = NULL;

    switch(gLogTarget)
    {
        case LSA_LOG_TARGET_DISABLED:
        case LSA_LOG_TARGET_CONSOLE:
        case LSA_LOG_TARGET_SYSLOG:

            dwError = LwAllocateMemory(
                            sizeof(LSA_LOG_INFO),
                            (PVOID*)&pLogInfo);
            BAIL_ON_LSA_ERROR(dwError);

            pLogInfo->logTarget = gLogTarget;
            pLogInfo->maxAllowedLogLevel = gLsaMaxLogLevel;

            break;

        case LSA_LOG_TARGET_FILE:

            dwError = LsaGetFileLogInfo(
                            ghLog,
                            &pLogInfo);
            BAIL_ON_LSA_ERROR(dwError);

            break;

        default:
            dwError = LW_ERROR_INVALID_PARAMETER;
            BAIL_ON_LSA_ERROR(dwError);
    }

    *ppLogInfo = pLogInfo;

cleanup:

    return dwError;

error:

    *ppLogInfo = NULL;

    if (pLogInfo)
    {
        LsaFreeLogInfo(pLogInfo);
    }

    goto cleanup;
}
Example #29
0
DWORD
LwSmTableAddEntry(
    PLW_SERVICE_INFO pInfo,
    PSM_TABLE_ENTRY* ppEntry
    )
{
    DWORD dwError = 0;
    BOOL bLocked = TRUE;
    PSM_TABLE_ENTRY pEntry = NULL;

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

    LwSmLinkInit(&pEntry->link);
    LwSmLinkInit(&pEntry->waiters);

    pEntry->bValid = TRUE;

    dwError = LwSmCopyServiceInfo(pInfo, &pEntry->pInfo);
    
    dwError = LwMapErrnoToLwError(pthread_mutex_init(&pEntry->lock, NULL));
    BAIL_ON_ERROR(dwError);
    pEntry->pLock = &pEntry->lock;

    dwError = LwMapErrnoToLwError(pthread_cond_init(&pEntry->event, NULL));
    BAIL_ON_ERROR(dwError);
    pEntry->pEvent = &pEntry->event;

    dwError = LwSmTableReconstructEntry(pEntry);
    BAIL_ON_ERROR(dwError);

    LOCK(bLocked, gServiceTable.pLock);

    LwSmLinkInsertBefore(&gServiceTable.entries, &pEntry->link);

    pEntry->dwRefCount++;

    UNLOCK(bLocked, gServiceTable.pLock);

    *ppEntry = pEntry;

cleanup:

    return dwError;

error:

    if (pEntry)
    {
        LwSmTableFreeEntry(pEntry);
    }

    goto cleanup;
}
Example #30
0
static
NSS_STATUS
LsaNssIrsNetgroupInnetgr(
    PLSA_NSS_NETGROUP_PRIVATE pPrivate,
    PCSTR pszGroup,
    PCSTR pszMatchHost,
    PCSTR pszMatchUser,
    PCSTR pszMatchDomain
    )
{
    NSS_STATUS status = NSS_STATUS_SUCCESS;
    PLSA_NSS_NETGROUP_PRIVATE pInner = NULL;
    PSTR pszHost = NULL;
    PSTR pszUser = NULL;
    PSTR pszDomain = NULL;

    status = MAP_LSA_ERROR(NULL,
                           LwAllocateMemory(
                               sizeof(*pInner),
                               (void**) &pInner));

    status = LsaNssPushNetgroup(&pInner->pExpand, pszGroup);
    BAIL_ON_NSS_ERROR(status);

    while (1)
    {
        status = LsaNssIrsNetgroupParse(
            pInner,
            &pszHost,
            &pszUser,
            &pszDomain);
        BAIL_ON_NSS_ERROR(status);

        if ((pszMatchHost == NULL || !strcmp(pszHost, pszMatchHost)) &&
            (pszMatchUser == NULL || !strcmp(pszUser, pszMatchUser)) &&
            (pszMatchDomain == NULL || !strcmp(pszDomain, pszMatchDomain)))
        {
            goto cleanup;
        }
    }

    status = NSS_STATUS_NOTFOUND;
    BAIL_ON_NSS_ERROR(status);

cleanup:

    LsaNssIrsNetgroupDestructor(pInner);

    return status;

error:

    goto cleanup;
}