Ejemplo n.º 1
0
DWORD
DJCopyLine(
        PHOSTSFILELINE pSrc, 
        PHOSTSFILELINE *ppDest)
{
    PHOSTSFILELINE ret = NULL;
    PHOSTFILEALIAS srcAlias = NULL, *destAlias = NULL;
    DWORD ceError = ERROR_SUCCESS;

    ceError = CTAllocateMemory(sizeof(HOSTSFILELINE),
                               (PVOID*)(PVOID)&ret);
    BAIL_ON_CENTERIS_ERROR(ceError);

    ret->bModified = pSrc->bModified;
    ceError = CTDupOrNullStr(pSrc->pszComment, &ret->pszComment);
    BAIL_ON_CENTERIS_ERROR(ceError);

    if(pSrc->pEntry != NULL)
    {
        ceError = CTAllocateMemory(sizeof(HOSTSFILEENTRY),
                                   (PVOID*)(PVOID)&ret->pEntry);
        BAIL_ON_CENTERIS_ERROR(ceError);
        ceError = CTDupOrNullStr(pSrc->pEntry->pszIpAddress, &ret->pEntry->pszIpAddress);
        BAIL_ON_CENTERIS_ERROR(ceError);
        ceError = CTDupOrNullStr(pSrc->pEntry->pszCanonicalName, &ret->pEntry->pszCanonicalName);
        BAIL_ON_CENTERIS_ERROR(ceError);

        srcAlias = pSrc->pEntry->pAliasList;
        destAlias = &ret->pEntry->pAliasList;
    }

    while(srcAlias != NULL)
    {
        ceError = CTAllocateMemory(sizeof(HOSTFILEALIAS),
                                   (PVOID*)(PVOID)destAlias);
        BAIL_ON_CENTERIS_ERROR(ceError);
        ceError = CTDupOrNullStr(srcAlias->pszAlias, &(*destAlias)->pszAlias);
        BAIL_ON_CENTERIS_ERROR(ceError);

        srcAlias = srcAlias->pNext;
        destAlias = &(*destAlias)->pNext;
    }

    *ppDest = ret;
    ret = NULL;

error:
    if(ret != NULL)
        DJFreeHostsFileLineList(ret);
    return ceError;
}
Ejemplo n.º 2
0
DWORD CTCopyTokenContents(CTParseToken *dest, const CTParseToken *source)
{
    DWORD ceError = ERROR_SUCCESS;
    memset(dest, 0, sizeof(*dest));
    if(source->value != NULL)
    {
        ceError = CTDupOrNullStr(source->value, &dest->value);
        BAIL_ON_CENTERIS_ERROR(ceError);
    }
    if(source->trailingSeparator != NULL)
    {
        ceError = CTDupOrNullStr(source->trailingSeparator, &dest->trailingSeparator);
        BAIL_ON_CENTERIS_ERROR(ceError);
    }

error:
    if(ceError)
        CTFreeParseTokenContents(dest);
    return ceError;
}
Ejemplo n.º 3
0
static DWORD InsertModule(NsswitchConf *conf, const DistroInfo *distro,
        int line, int insertIndex, const char *name)
{
    DWORD ceError = ERROR_SUCCESS;
    NsswitchEntry *lineObj = (NsswitchEntry *)GetEntry(conf, line);
    CTParseToken *beforeModule = NULL, *afterModule = NULL;
    CTParseToken addModule;

    memset(&addModule, 0, sizeof(addModule));
    if(insertIndex == -1)
        insertIndex = lineObj->modules.size;

    GCE(ceError = CTStrdup(name, &addModule.value));

    if(insertIndex - 1 >= 0)
        beforeModule = (CTParseToken *)lineObj->modules.data + insertIndex - 1;
    if(insertIndex < lineObj->modules.size)
        afterModule = (CTParseToken *)lineObj->modules.data + insertIndex;

    if(beforeModule != NULL)
    {
        /* Copy the separator from the previous module */
        GCE(ceError = CTDupOrNullStr(beforeModule->trailingSeparator,
                &addModule.trailingSeparator));
        if(afterModule == NULL)
        {
            /*This is the last module.  Put in the correct separator after the
             * previous module */
            CT_SAFE_FREE_STRING(beforeModule->trailingSeparator);
            GCE(ceError = CTStrdup(GetModuleSeparator(conf, distro),
                    &beforeModule->trailingSeparator));
        }
    }
    else
    {
        if(afterModule == NULL)
        {
            //This is the last module
            if(lineObj->comment == NULL)
            {
                //Leave the trailingSeparator as NULL
            }
            else
            {
                GCE(ceError = CTStrdup(" ", &addModule.trailingSeparator));
            }
        }
        else
        {
            //This is the first module. Add the appropriate separator to
            //distinguish it from the next module.
            GCE(ceError = CTStrdup(GetModuleSeparator(conf, distro),
                    &addModule.trailingSeparator));
        }
    }

    GCE(ceError = CTArrayInsert(&lineObj->modules, insertIndex,
                sizeof(addModule), &addModule, 1));
    memset(&addModule, 0, sizeof(addModule));
    conf->modified = 1;

cleanup:
    CTFreeParseTokenContents(&addModule);
    return ceError;
}