openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsyslog/8.1903.0-r0/rsyslog-8.1903.0/runtime/net.c
static rsRetVal AddPermittedPeerWildcard(permittedPeers_t* pPeer, uchar* pszStr,
                                         size_t lenStr)
{
    permittedPeerWildcard_t* pNew = NULL;
    size_t iSrc;
    size_t iDst;
    DEFiRet;

    assert(pPeer != NULL);
    assert(pszStr != NULL);

    CHKmalloc(pNew = calloc(1, sizeof(*pNew)));

    if (lenStr == 0)
    { /* empty domain components are permitted */
        pNew->wildcardType = PEER_WILDCARD_EMPTY_COMPONENT;
        FINALIZE;
    }
    else
    {
        /* alloc memory for the domain component. We may waste a byte or
         * two, but that's ok.
         */
        CHKmalloc(pNew->pszDomainPart = malloc(lenStr + 1));
    }

    if (pszStr[0] == '*')
    {
        pNew->wildcardType = PEER_WILDCARD_AT_START;
        iSrc = 1; /* skip '*' */
    }
    else
    {
        iSrc = 0;
    }

    for (iDst = 0; iSrc < lenStr && pszStr[iSrc] != '*'; ++iSrc, ++iDst)
    {
        pNew->pszDomainPart[iDst] = pszStr[iSrc];
    }

    if (iSrc < lenStr)
    {
        if (iSrc + 1 == lenStr && pszStr[iSrc] == '*')
        {
            if (pNew->wildcardType == PEER_WILDCARD_AT_START)
            {
                ABORT_FINALIZE(RS_RET_INVALID_WILDCARD);
            }
            else
            {
                pNew->wildcardType = PEER_WILDCARD_AT_END;
            }
        }
        else
        {
            /* we have an invalid wildcard, something follows the asterisk! */
            ABORT_FINALIZE(RS_RET_INVALID_WILDCARD);
        }
    }

    if (lenStr == 1 && pNew->wildcardType == PEER_WILDCARD_AT_START)
    {
        pNew->wildcardType = PEER_WILDCARD_MATCH_ALL;
    }

    /* if we reach this point, we had a valid wildcard. We now need to
     * properly terminate the domain component string.
     */
    pNew->pszDomainPart[iDst] = '\0';
    pNew->lenDomainPart = strlen((char*)pNew->pszDomainPart);

finalize_it:
    if (iRet != RS_RET_OK)
    {
        if (pNew != NULL)
        {
            if (pNew->pszDomainPart != NULL)
                free(pNew->pszDomainPart);
            free(pNew);
        }
    }
    else
    {
        /* enqueue the element */
        if (pPeer->pWildcardRoot == NULL)
        {
            pPeer->pWildcardRoot = pNew;
            pPeer->pWildcardLast = pNew;
        }
        else
        {
            pPeer->pWildcardLast->pNext = pNew;
        }
        pPeer->pWildcardLast = pNew;
    }

    RETiRet;
}
/* add a wildcard entry to this permitted peer. Entries are always
 * added at the tail of the list. pszStr and lenStr identify the wildcard
 * entry to be added. Note that the string is NOT \0 terminated, so
 * we must rely on lenStr for when it is finished.
 * rgerhards, 2008-05-27
 */
add a wildcard entry to this permitted peer. Entries are always
added at the tail of the list. pszStr and lenStr identify the wildcard
entry to be added. Note that the string is NOT \0 terminated, so
we must rely on lenStr for when it is finished.
add a wildcard entry to this permitted peer . Entries are always added at the tail of the list . pszStr and lenStr identify the wildcard entry to be added . Note that the string is NOT \ 0 terminated so we must rely on lenStr for when it is finished .
static rsRetVal AddPermittedPeerWildcard(permittedPeers_t* pPeer, uchar* pszStr,
                                         size_t lenStr)
{
    permittedPeerWildcard_t* pNew = NULL;
    size_t iSrc;
    size_t iDst;
    DEFiRet;
    assert(pPeer != NULL);
    assert(pszStr != NULL);
    CHKmalloc(pNew = calloc(1, sizeof(*pNew)));
    if (lenStr == 0)
    { 
        pNew->wildcardType = PEER_WILDCARD_EMPTY_COMPONENT;
        FINALIZE;
    }
    else
    {
        CHKmalloc(pNew->pszDomainPart = malloc(lenStr + 1));
    }
    if (pszStr[0] == '*')
    {
        pNew->wildcardType = PEER_WILDCARD_AT_START;
        iSrc = 1; 
    }
    else
    {
        iSrc = 0;
    }
    for (iDst = 0; iSrc < lenStr && pszStr[iSrc] != '*'; ++iSrc, ++iDst)
    {
        pNew->pszDomainPart[iDst] = pszStr[iSrc];
    }
    if (iSrc < lenStr)
    {
        if (iSrc + 1 == lenStr && pszStr[iSrc] == '*')
        {
            if (pNew->wildcardType == PEER_WILDCARD_AT_START)
            {
                ABORT_FINALIZE(RS_RET_INVALID_WILDCARD);
            }
            else
            {
                pNew->wildcardType = PEER_WILDCARD_AT_END;
            }
        }
        else
        {
            ABORT_FINALIZE(RS_RET_INVALID_WILDCARD);
        }
    }
    if (lenStr == 1 && pNew->wildcardType == PEER_WILDCARD_AT_START)
    {
        pNew->wildcardType = PEER_WILDCARD_MATCH_ALL;
    }
    pNew->pszDomainPart[iDst] = '\0';
    pNew->lenDomainPart = strlen((char*)pNew->pszDomainPart);
finalize_it:
    if (iRet != RS_RET_OK)
    {
        if (pNew != NULL)
        {
            if (pNew->pszDomainPart != NULL)
                free(pNew->pszDomainPart);
            free(pNew);
        }
    }
    else
    {
        if (pPeer->pWildcardRoot == NULL)
        {
            pPeer->pWildcardRoot = pNew;
            pPeer->pWildcardLast = pNew;
        }
        else
        {
            pPeer->pWildcardLast->pNext = pNew;
        }
        pPeer->pWildcardLast = pNew;
    }
    RETiRet;
}
static rsRetVal AddPermittedPeerWildcard ( permittedPeers_t * pPeer , uchar * pszStr , size_t lenStr ) { permittedPeerWildcard_t * pNew = NULL ; size_t iSrc ; size_t iDst ; DEFiRet ; assert ( pPeer != NULL ) ; assert ( pszStr != NULL ) ; CHKmalloc ( pNew = calloc ( 1 , sizeof ( * pNew ) ) ) ; if ( lenStr == 0 ) { pNew -> wildcardType = PEER_WILDCARD_EMPTY_COMPONENT ; FINALIZE ; } else { CHKmalloc ( pNew -> pszDomainPart = malloc ( lenStr + 1 ) ) ; } if ( pszStr [ 0 ] == ' ' ) { pNew -> wildcardType = PEER_WILDCARD_AT_START ; iSrc = 1 ; } else { iSrc = 0 ; } for ( iDst = 0 ; iSrc < lenStr && pszStr [ iSrc ] != ' ' ; ++ iSrc , ++ iDst ) { pNew -> pszDomainPart [ iDst ] = pszStr [ iSrc ] ; } if ( iSrc < lenStr ) { if ( iSrc + 1 == lenStr && pszStr [ iSrc ] == ' ' ) { if ( pNew -> wildcardType == PEER_WILDCARD_AT_START ) { ABORT_FINALIZE ( RS_RET_INVALID_WILDCARD ) ; } else { pNew -> wildcardType = PEER_WILDCARD_AT_END ; } } else { ABORT_FINALIZE ( RS_RET_INVALID_WILDCARD ) ; } } if ( lenStr == 1 && pNew -> wildcardType == PEER_WILDCARD_AT_START ) { pNew -> wildcardType = PEER_WILDCARD_MATCH_ALL ; } pNew -> pszDomainPart [ iDst ] = ' \0 ' ; pNew -> lenDomainPart = strlen ( ( char * ) pNew -> pszDomainPart ) ; finalize_it : if ( iRet != RS_RET_OK ) { if ( pNew != NULL ) { if ( pNew -> pszDomainPart != NULL ) free ( pNew -> pszDomainPart ) ; free ( pNew ) ; } } else { if ( pPeer -> pWildcardRoot == NULL ) { pPeer -> pWildcardRoot = pNew ; pPeer -> pWildcardLast = pNew ; } else { pPeer -> pWildcardLast -> pNext = pNew ; } pPeer -> pWildcardLast = pNew ; } RETiRet ; }
add a wildcard entry to this permitted peer.
add a wildcard entry to this permitted peer .
/* empty domain components are permitted */ /* alloc memory for the domain component. We may waste a byte or
         * two, but that's ok.
         */ /* skip '*' */ /* we have an invalid wildcard, something follows the asterisk! */ /* if we reach this point, we had a valid wildcard. We now need to
     * properly terminate the domain component string.
     */ /* enqueue the element */