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 PermittedPeerWildcardMatch(permittedPeers_t* const pPeer,
                                           const uchar* pszNameToMatch,
                                           int* const pbIsMatching)
{
    const permittedPeerWildcard_t* pWildcard;
    const uchar* pC;
    size_t iWildcard, iName; /* work indexes for backward comparisons */
    DEFiRet;

    assert(pPeer != NULL);
    assert(pszNameToMatch != NULL);
    assert(pbIsMatching != NULL);

    if (pPeer->etryType == PERM_PEER_TYPE_UNDECIDED)
    {
        PermittedPeerWildcardCompile(pPeer);
    }

    if (pPeer->etryType == PERM_PEER_TYPE_PLAIN)
    {
        *pbIsMatching = !strcmp((char*)pPeer->pszID, (char*)pszNameToMatch);
        FINALIZE;
    }

    /* we have a wildcard, so we need to extract the domain components and
     * check then against the provided wildcards.
     */
    pWildcard = pPeer->pWildcardRoot;
    pC = pszNameToMatch;
    while (*pC != '\0')
    {
        if (pWildcard == NULL)
        {
            /* we have more domain components than we have wildcards --> no
             * match */
            *pbIsMatching = 0;
            FINALIZE;
        }
        const uchar* const pStart = pC; /* start of current domain component */
        while (*pC != '\0' && *pC != '.')
        {
            ++pC;
        }

        /* got the component, now do the match */
        switch (pWildcard->wildcardType)
        {
            case PEER_WILDCARD_NONE:
                if (pWildcard->lenDomainPart != (size_t)(pC - pStart) ||
                    strncmp((char*)pStart, (char*)pWildcard->pszDomainPart,
                            pC - pStart))
                {
                    *pbIsMatching = 0;
                    FINALIZE;
                }
                break;
            case PEER_WILDCARD_AT_START:
                /* we need to do the backwards-matching manually */
                if (pWildcard->lenDomainPart > (size_t)(pC - pStart))
                {
                    *pbIsMatching = 0;
                    FINALIZE;
                }
                iName = (size_t)(pC - pStart) - pWildcard->lenDomainPart;
                iWildcard = 0;
                while (iWildcard < pWildcard->lenDomainPart)
                {
// I give up, I see now way to remove false positive -- rgerhards, 2017-10-23
#ifndef __clang_analyzer__
                    if (pWildcard->pszDomainPart[iWildcard] != pStart[iName])
                    {
                        *pbIsMatching = 0;
                        FINALIZE;
                    }
#endif
                    ++iName;
                    ++iWildcard;
                }
                break;
            case PEER_WILDCARD_AT_END:
                if (pWildcard->lenDomainPart > (size_t)(pC - pStart) ||
                    strncmp((char*)pStart, (char*)pWildcard->pszDomainPart,
                            pWildcard->lenDomainPart))
                {
                    *pbIsMatching = 0;
                    FINALIZE;
                }
                break;
            case PEER_WILDCARD_MATCH_ALL:
                /* everything is OK, just continue */
                break;
            case PEER_WILDCARD_EMPTY_COMPONENT:
                if (pC - pStart > 0)
                {
                    /* if it is not empty, it is no match... */
                    *pbIsMatching = 0;
                    FINALIZE;
                }
                break;
        }
        pWildcard = pWildcard->pNext; /* we processed this entry */

        /* skip '.' if we had it and so prepare for next iteration */
        if (*pC == '.')
            ++pC;
    }

    if (pWildcard != NULL)
    {
        /* we have more domain components than in the name to be
         * checked. So this is no match.
         */
        *pbIsMatching = 0;
        FINALIZE;
    }

    *pbIsMatching = 1; /* finally... it matches ;) */

finalize_it:
    RETiRet;
}
/* Do a (potential) wildcard match. The function first checks if the wildcard
 * has already been compiled and, if not, compiles it. If the peer entry in
 * question does NOT contain a wildcard, a simple strcmp() is done.
 * *pbIsMatching is set to 0 if there is no match and something else otherwise.
 * rgerhards, 2008-05-27 */
Do a (potential) wildcard match. The function first checks if the wildcard
has already been compiled and, if not, compiles it. If the peer entry in
question does NOT contain a wildcard, a simple strcmp() is done.
*pbIsMatching is set to 0 if there is no match and something else otherwise.
Do a ( potential ) wildcard match . The function first checks if the wildcard has already been compiled and if not compiles it . If the peer entry in question does NOT contain a wildcard a simple strcmp () is done . * pbIsMatching is set to 0 if there is no match and something else otherwise .
static rsRetVal PermittedPeerWildcardMatch(permittedPeers_t* const pPeer,
                                           const uchar* pszNameToMatch,
                                           int* const pbIsMatching)
{
    const permittedPeerWildcard_t* pWildcard;
    const uchar* pC;
    size_t iWildcard, iName; 
    DEFiRet;
    assert(pPeer != NULL);
    assert(pszNameToMatch != NULL);
    assert(pbIsMatching != NULL);
    if (pPeer->etryType == PERM_PEER_TYPE_UNDECIDED)
    {
        PermittedPeerWildcardCompile(pPeer);
    }
    if (pPeer->etryType == PERM_PEER_TYPE_PLAIN)
    {
        *pbIsMatching = !strcmp((char*)pPeer->pszID, (char*)pszNameToMatch);
        FINALIZE;
    }
    pWildcard = pPeer->pWildcardRoot;
    pC = pszNameToMatch;
    while (*pC != '\0')
    {
        if (pWildcard == NULL)
        {
            *pbIsMatching = 0;
            FINALIZE;
        }
        const uchar* const pStart = pC; 
        while (*pC != '\0' && *pC != '.')
        {
            ++pC;
        }
        switch (pWildcard->wildcardType)
        {
            case PEER_WILDCARD_NONE:
                if (pWildcard->lenDomainPart != (size_t)(pC - pStart) ||
                    strncmp((char*)pStart, (char*)pWildcard->pszDomainPart,
                            pC - pStart))
                {
                    *pbIsMatching = 0;
                    FINALIZE;
                }
                break;
            case PEER_WILDCARD_AT_START:
                if (pWildcard->lenDomainPart > (size_t)(pC - pStart))
                {
                    *pbIsMatching = 0;
                    FINALIZE;
                }
                iName = (size_t)(pC - pStart) - pWildcard->lenDomainPart;
                iWildcard = 0;
                while (iWildcard < pWildcard->lenDomainPart)
                {
#ifndef __clang_analyzer__
                    if (pWildcard->pszDomainPart[iWildcard] != pStart[iName])
                    {
                        *pbIsMatching = 0;
                        FINALIZE;
                    }
#endif
                    ++iName;
                    ++iWildcard;
                }
                break;
            case PEER_WILDCARD_AT_END:
                if (pWildcard->lenDomainPart > (size_t)(pC - pStart) ||
                    strncmp((char*)pStart, (char*)pWildcard->pszDomainPart,
                            pWildcard->lenDomainPart))
                {
                    *pbIsMatching = 0;
                    FINALIZE;
                }
                break;
            case PEER_WILDCARD_MATCH_ALL:
                break;
            case PEER_WILDCARD_EMPTY_COMPONENT:
                if (pC - pStart > 0)
                {
                    *pbIsMatching = 0;
                    FINALIZE;
                }
                break;
        }
        pWildcard = pWildcard->pNext; 
        if (*pC == '.')
            ++pC;
    }
    if (pWildcard != NULL)
    {
        *pbIsMatching = 0;
        FINALIZE;
    }
    *pbIsMatching = 1; 
finalize_it:
    RETiRet;
}
static rsRetVal PermittedPeerWildcardMatch ( permittedPeers_t * const pPeer , const uchar * pszNameToMatch , int * const pbIsMatching ) { const permittedPeerWildcard_t * pWildcard ; const uchar * pC ; size_t iWildcard , iName ; DEFiRet ; assert ( pPeer != NULL ) ; assert ( pszNameToMatch != NULL ) ; assert ( pbIsMatching != NULL ) ; if ( pPeer -> etryType == PERM_PEER_TYPE_UNDECIDED ) { PermittedPeerWildcardCompile ( pPeer ) ; } if ( pPeer -> etryType == PERM_PEER_TYPE_PLAIN ) { * pbIsMatching = ! strcmp ( ( char * ) pPeer -> pszID , ( char * ) pszNameToMatch ) ; FINALIZE ; } pWildcard = pPeer -> pWildcardRoot ; pC = pszNameToMatch ; while ( * pC != ' \0 ' ) { if ( pWildcard == NULL ) { * pbIsMatching = 0 ; FINALIZE ; } const uchar * const pStart = pC ; while ( * pC != ' \0 ' && * pC != ' ' ) { ++ pC ; } switch ( pWildcard -> wildcardType ) { case PEER_WILDCARD_NONE : if ( pWildcard -> lenDomainPart != ( size_t ) ( pC - pStart ) || strncmp ( ( char * ) pStart , ( char * ) pWildcard -> pszDomainPart , pC - pStart ) ) { * pbIsMatching = 0 ; FINALIZE ; } break ; case PEER_WILDCARD_AT_START : if ( pWildcard -> lenDomainPart > ( size_t ) ( pC - pStart ) ) { * pbIsMatching = 0 ; FINALIZE ; } iName = ( size_t ) ( pC - pStart ) - pWildcard -> lenDomainPart ; iWildcard = 0 ; while ( iWildcard < pWildcard -> lenDomainPart ) { #ifndef __clang_analyzer__ if ( pWildcard -> pszDomainPart [ iWildcard ] != pStart [ iName ] ) { * pbIsMatching = 0 ; FINALIZE ; } #endif ++ iName ; ++ iWildcard ; } break ; case PEER_WILDCARD_AT_END : if ( pWildcard -> lenDomainPart > ( size_t ) ( pC - pStart ) || strncmp ( ( char * ) pStart , ( char * ) pWildcard -> pszDomainPart , pWildcard -> lenDomainPart ) ) { * pbIsMatching = 0 ; FINALIZE ; } break ; case PEER_WILDCARD_MATCH_ALL : break ; case PEER_WILDCARD_EMPTY_COMPONENT : if ( pC - pStart > 0 ) { * pbIsMatching = 0 ; FINALIZE ; } break ; } pWildcard = pWildcard -> pNext ; if ( * pC == ' ' ) ++ pC ; } if ( pWildcard != NULL ) { * pbIsMatching = 0 ; FINALIZE ; } * pbIsMatching = 1 ; finalize_it : RETiRet ; }
Do a (potential) wildcard match.
Do a ( potential ) wildcard match .
/* work indexes for backward comparisons */ /* we have a wildcard, so we need to extract the domain components and
     * check then against the provided wildcards.
     */ /* we have more domain components than we have wildcards --> no
             * match */ /* start of current domain component */ /* got the component, now do the match */ /* we need to do the backwards-matching manually */ // I give up, I see now way to remove false positive -- rgerhards, 2017-10-23 /* everything is OK, just continue */ /* if it is not empty, it is no match... */ /* we processed this entry */ /* skip '.' if we had it and so prepare for next iteration */ /* we have more domain components than in the name to be
         * checked. So this is no match.
         */ /* finally... it matches ;) */