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/tcpsrv.c
static rsRetVal SessAccept(tcpsrv_t* pThis, tcpLstnPortList_t* pLstnInfo,
                           tcps_sess_t** ppSess, netstrm_t* pStrm)
{
    DEFiRet;
    tcps_sess_t* pSess = NULL;
    netstrm_t* pNewStrm = NULL;
    int iSess = -1;
    struct sockaddr_storage* addr;
    uchar* fromHostFQDN = NULL;
    prop_t* fromHostIP;

    ISOBJ_TYPE_assert(pThis, tcpsrv);
    assert(pLstnInfo != NULL);

    CHKiRet(netstrm.AcceptConnReq(pStrm, &pNewStrm));

    /* Add to session list */
    iSess = TCPSessTblFindFreeSpot(pThis);
    if (iSess == -1)
    {
        errno = 0;
        LogError(0, RS_RET_MAX_SESS_REACHED,
                 "too many tcp sessions - dropping incoming request");
        ABORT_FINALIZE(RS_RET_MAX_SESS_REACHED);
    }

    if (pThis->bUseKeepAlive)
    {
        CHKiRet(netstrm.SetKeepAliveProbes(pNewStrm, pThis->iKeepAliveProbes));
        CHKiRet(netstrm.SetKeepAliveTime(pNewStrm, pThis->iKeepAliveTime));
        CHKiRet(netstrm.SetKeepAliveIntvl(pNewStrm, pThis->iKeepAliveIntvl));
        CHKiRet(netstrm.EnableKeepAlive(pNewStrm));
    }

    /* we found a free spot and can construct our session object */
    if (pThis->gnutlsPriorityString != NULL)
    {
        CHKiRet(netstrm.SetGnutlsPriorityString(pNewStrm,
                                                pThis->gnutlsPriorityString));
    }
    CHKiRet(tcps_sess.Construct(&pSess));
    CHKiRet(tcps_sess.SetTcpsrv(pSess, pThis));
    CHKiRet(tcps_sess.SetLstnInfo(pSess, pLstnInfo));
    if (pThis->OnMsgReceive != NULL)
        CHKiRet(tcps_sess.SetOnMsgReceive(pSess, pThis->OnMsgReceive));

    /* get the host name */
    CHKiRet(netstrm.GetRemoteHName(pNewStrm, &fromHostFQDN));
    if (!pThis->bPreserveCase)
    {
        /* preserve_case = off */
        uchar* p;
        for (p = fromHostFQDN; *p; p++)
        {
            if (isupper((int)*p))
            {
                *p = tolower((int)*p);
            }
        }
    }
    CHKiRet(netstrm.GetRemoteIP(pNewStrm, &fromHostIP));
    CHKiRet(netstrm.GetRemAddr(pNewStrm, &addr));
    /* TODO: check if we need to strip the domain name here -- rgerhards,
     * 2008-04-24 */

    /* Here we check if a host is permitted to send us messages. If it isn't, we
     * do not further process the message but log a warning (if we are
     * configured to do this). rgerhards, 2005-09-26
     */
    if (!pThis->pIsPermittedHost((struct sockaddr*)addr, (char*)fromHostFQDN,
                                 pThis->pUsr, pSess->pUsr))
    {
        DBGPRINTF("%s is not an allowed sender\n", fromHostFQDN);
        if (glbl.GetOption_DisallowWarning())
        {
            errno = 0;
            LogError(0, RS_RET_HOST_NOT_PERMITTED,
                     "TCP message from disallowed "
                     "sender %s discarded",
                     fromHostFQDN);
        }
        ABORT_FINALIZE(RS_RET_HOST_NOT_PERMITTED);
    }

    /* OK, we have an allowed sender, so let's continue, what
     * means we can finally fill in the session object.
     */
    CHKiRet(tcps_sess.SetHost(pSess, fromHostFQDN));
    fromHostFQDN = NULL; /* we handed this string over */
    CHKiRet(tcps_sess.SetHostIP(pSess, fromHostIP));
    CHKiRet(tcps_sess.SetStrm(pSess, pNewStrm));
    pNewStrm = NULL; /* prevent it from being freed in error handler, now done
                        in tcps_sess! */
    CHKiRet(tcps_sess.SetMsgIdx(pSess, 0));
    CHKiRet(tcps_sess.ConstructFinalize(pSess));

    /* check if we need to call our callback */
    if (pThis->pOnSessAccept != NULL)
    {
        CHKiRet(pThis->pOnSessAccept(pThis, pSess));
    }

    *ppSess = pSess;
    if (!pThis->bUsingEPoll)
        pThis->pSessions[iSess] = pSess;
    pSess = NULL; /* this is now also handed over */

finalize_it:
    if (iRet != RS_RET_OK)
    {
        if (pSess != NULL)
            tcps_sess.Destruct(&pSess);
        if (pNewStrm != NULL)
            netstrm.Destruct(&pNewStrm);
        free(fromHostFQDN);
    }

    RETiRet;
}
/* Accept new TCP connection; make entry in session table. If there
 * is no more space left in the connection table, the new TCP
 * connection is immediately dropped.
 * ppSess has a pointer to the newly created session, if it succeeds.
 * If it does not succeed, no session is created and ppSess is
 * undefined. If the user has provided an OnSessAccept Callback,
 * this one is executed immediately after creation of the
 * session object, so that it can do its own initialization.
 * rgerhards, 2008-03-02
 */
Accept new TCP connection; make entry in session table. If there
is no more space left in the connection table, the new TCP
connection is immediately dropped.
ppSess has a pointer to the newly created session, if it succeeds.
If it does not succeed, no session is created and ppSess is
undefined. If the user has provided an OnSessAccept Callback,
this one is executed immediately after creation of the
session object, so that it can do its own initialization.
Accept new TCP connection ; make entry in session table . If there is no more space left in the connection table the new TCP connection is immediately dropped . ppSess has a pointer to the newly created session if it succeeds . If it does not succeed no session is created and ppSess is undefined . If the user has provided an OnSessAccept Callback this one is executed immediately after creation of the session object so that it can do its own initialization .
static rsRetVal SessAccept(tcpsrv_t* pThis, tcpLstnPortList_t* pLstnInfo,
                           tcps_sess_t** ppSess, netstrm_t* pStrm)
{
    DEFiRet;
    tcps_sess_t* pSess = NULL;
    netstrm_t* pNewStrm = NULL;
    int iSess = -1;
    struct sockaddr_storage* addr;
    uchar* fromHostFQDN = NULL;
    prop_t* fromHostIP;
    ISOBJ_TYPE_assert(pThis, tcpsrv);
    assert(pLstnInfo != NULL);
    CHKiRet(netstrm.AcceptConnReq(pStrm, &pNewStrm));
    iSess = TCPSessTblFindFreeSpot(pThis);
    if (iSess == -1)
    {
        errno = 0;
        LogError(0, RS_RET_MAX_SESS_REACHED,
                 "too many tcp sessions - dropping incoming request");
        ABORT_FINALIZE(RS_RET_MAX_SESS_REACHED);
    }
    if (pThis->bUseKeepAlive)
    {
        CHKiRet(netstrm.SetKeepAliveProbes(pNewStrm, pThis->iKeepAliveProbes));
        CHKiRet(netstrm.SetKeepAliveTime(pNewStrm, pThis->iKeepAliveTime));
        CHKiRet(netstrm.SetKeepAliveIntvl(pNewStrm, pThis->iKeepAliveIntvl));
        CHKiRet(netstrm.EnableKeepAlive(pNewStrm));
    }
    if (pThis->gnutlsPriorityString != NULL)
    {
        CHKiRet(netstrm.SetGnutlsPriorityString(pNewStrm,
                                                pThis->gnutlsPriorityString));
    }
    CHKiRet(tcps_sess.Construct(&pSess));
    CHKiRet(tcps_sess.SetTcpsrv(pSess, pThis));
    CHKiRet(tcps_sess.SetLstnInfo(pSess, pLstnInfo));
    if (pThis->OnMsgReceive != NULL)
        CHKiRet(tcps_sess.SetOnMsgReceive(pSess, pThis->OnMsgReceive));
    CHKiRet(netstrm.GetRemoteHName(pNewStrm, &fromHostFQDN));
    if (!pThis->bPreserveCase)
    {
        uchar* p;
        for (p = fromHostFQDN; *p; p++)
        {
            if (isupper((int)*p))
            {
                *p = tolower((int)*p);
            }
        }
    }
    CHKiRet(netstrm.GetRemoteIP(pNewStrm, &fromHostIP));
    CHKiRet(netstrm.GetRemAddr(pNewStrm, &addr));
    if (!pThis->pIsPermittedHost((struct sockaddr*)addr, (char*)fromHostFQDN,
                                 pThis->pUsr, pSess->pUsr))
    {
        DBGPRINTF("%s is not an allowed sender\n", fromHostFQDN);
        if (glbl.GetOption_DisallowWarning())
        {
            errno = 0;
            LogError(0, RS_RET_HOST_NOT_PERMITTED,
                     "TCP message from disallowed "
                     "sender %s discarded",
                     fromHostFQDN);
        }
        ABORT_FINALIZE(RS_RET_HOST_NOT_PERMITTED);
    }
    CHKiRet(tcps_sess.SetHost(pSess, fromHostFQDN));
    fromHostFQDN = NULL; 
    CHKiRet(tcps_sess.SetHostIP(pSess, fromHostIP));
    CHKiRet(tcps_sess.SetStrm(pSess, pNewStrm));
    pNewStrm = NULL; 
    CHKiRet(tcps_sess.SetMsgIdx(pSess, 0));
    CHKiRet(tcps_sess.ConstructFinalize(pSess));
    if (pThis->pOnSessAccept != NULL)
    {
        CHKiRet(pThis->pOnSessAccept(pThis, pSess));
    }
    *ppSess = pSess;
    if (!pThis->bUsingEPoll)
        pThis->pSessions[iSess] = pSess;
    pSess = NULL; 
finalize_it:
    if (iRet != RS_RET_OK)
    {
        if (pSess != NULL)
            tcps_sess.Destruct(&pSess);
        if (pNewStrm != NULL)
            netstrm.Destruct(&pNewStrm);
        free(fromHostFQDN);
    }
    RETiRet;
}
static rsRetVal SessAccept ( tcpsrv_t * pThis , tcpLstnPortList_t * pLstnInfo , tcps_sess_t * * ppSess , netstrm_t * pStrm ) { DEFiRet ; tcps_sess_t * pSess = NULL ; netstrm_t * pNewStrm = NULL ; int iSess = -1 ; struct sockaddr_storage * addr ; uchar * fromHostFQDN = NULL ; prop_t * fromHostIP ; ISOBJ_TYPE_assert ( pThis , tcpsrv ) ; assert ( pLstnInfo != NULL ) ; CHKiRet ( netstrm . AcceptConnReq ( pStrm , & pNewStrm ) ) ; iSess = TCPSessTblFindFreeSpot ( pThis ) ; if ( iSess == -1 ) { errno = 0 ; LogError ( 0 , RS_RET_MAX_SESS_REACHED , " " ) ; ABORT_FINALIZE ( RS_RET_MAX_SESS_REACHED ) ; } if ( pThis -> bUseKeepAlive ) { CHKiRet ( netstrm . SetKeepAliveProbes ( pNewStrm , pThis -> iKeepAliveProbes ) ) ; CHKiRet ( netstrm . SetKeepAliveTime ( pNewStrm , pThis -> iKeepAliveTime ) ) ; CHKiRet ( netstrm . SetKeepAliveIntvl ( pNewStrm , pThis -> iKeepAliveIntvl ) ) ; CHKiRet ( netstrm . EnableKeepAlive ( pNewStrm ) ) ; } if ( pThis -> gnutlsPriorityString != NULL ) { CHKiRet ( netstrm . SetGnutlsPriorityString ( pNewStrm , pThis -> gnutlsPriorityString ) ) ; } CHKiRet ( tcps_sess . Construct ( & pSess ) ) ; CHKiRet ( tcps_sess . SetTcpsrv ( pSess , pThis ) ) ; CHKiRet ( tcps_sess . SetLstnInfo ( pSess , pLstnInfo ) ) ; if ( pThis -> OnMsgReceive != NULL ) CHKiRet ( tcps_sess . SetOnMsgReceive ( pSess , pThis -> OnMsgReceive ) ) ; CHKiRet ( netstrm . GetRemoteHName ( pNewStrm , & fromHostFQDN ) ) ; if ( ! pThis -> bPreserveCase ) { uchar * p ; for ( p = fromHostFQDN ; * p ; p ++ ) { if ( isupper ( ( int ) * p ) ) { * p = tolower ( ( int ) * p ) ; } } } CHKiRet ( netstrm . GetRemoteIP ( pNewStrm , & fromHostIP ) ) ; CHKiRet ( netstrm . GetRemAddr ( pNewStrm , & addr ) ) ; if ( ! pThis -> pIsPermittedHost ( ( struct sockaddr * ) addr , ( char * ) fromHostFQDN , pThis -> pUsr , pSess -> pUsr ) ) { DBGPRINTF ( " \n " , fromHostFQDN ) ; if ( glbl . GetOption_DisallowWarning ( ) ) { errno = 0 ; LogError ( 0 , RS_RET_HOST_NOT_PERMITTED , " " " " , fromHostFQDN ) ; } ABORT_FINALIZE ( RS_RET_HOST_NOT_PERMITTED ) ; } CHKiRet ( tcps_sess . SetHost ( pSess , fromHostFQDN ) ) ; fromHostFQDN = NULL ; CHKiRet ( tcps_sess . SetHostIP ( pSess , fromHostIP ) ) ; CHKiRet ( tcps_sess . SetStrm ( pSess , pNewStrm ) ) ; pNewStrm = NULL ; CHKiRet ( tcps_sess . SetMsgIdx ( pSess , 0 ) ) ; CHKiRet ( tcps_sess . ConstructFinalize ( pSess ) ) ; if ( pThis -> pOnSessAccept != NULL ) { CHKiRet ( pThis -> pOnSessAccept ( pThis , pSess ) ) ; } * ppSess = pSess ; if ( ! pThis -> bUsingEPoll ) pThis -> pSessions [ iSess ] = pSess ; pSess = NULL ; finalize_it : if ( iRet != RS_RET_OK ) { if ( pSess != NULL ) tcps_sess . Destruct ( & pSess ) ; if ( pNewStrm != NULL ) netstrm . Destruct ( & pNewStrm ) ; free ( fromHostFQDN ) ; } RETiRet ; }
Accept new TCP connection; make entry in session table.
Accept new TCP connection ; make entry in session table .
/* Add to session list */ /* we found a free spot and can construct our session object */ /* get the host name */ /* preserve_case = off */ /* TODO: check if we need to strip the domain name here -- rgerhards,
     * 2008-04-24 */ /* Here we check if a host is permitted to send us messages. If it isn't, we
     * do not further process the message but log a warning (if we are
     * configured to do this). rgerhards, 2005-09-26
     */ /* OK, we have an allowed sender, so let's continue, what
     * means we can finally fill in the session object.
     */ /* we handed this string over */ /* prevent it from being freed in error handler, now done
                        in tcps_sess! */ /* check if we need to call our callback */ /* this is now also handed over */