Example #1
0
static void FreeModbusData(void *data)
{
    modbus_session_data_t *session = (modbus_session_data_t *)data;
    modbus_config_t *config = NULL;

    if (session == NULL)
        return;

    if (session->context_id != NULL)
    {
        config = (modbus_config_t *)sfPolicyUserDataGet(session->context_id, session->policy_id);
    }

    if (config != NULL)
    {
        config->ref_count--;
        if ((config->ref_count == 0) &&
            (session->context_id != modbus_context_id))
        {
            sfPolicyUserDataClear(session->context_id, session->policy_id);
            free(config);

            if (sfPolicyUserPolicyGetActive(session->context_id) == 0)
            {
                /* No more outstanding configs - free the config array */
                ModbusFreeConfig(session->context_id);
            }
        }
    }
    free(session);
}
Example #2
0
/*
 * Function: FTPFreeSession(void *preproc_session)
 *
 * Purpose: This function frees the data that is associated with a session.
 *
 * Arguments: preproc_session   => pointer to the session to free
 *
 * Returns: None
 */
static void FTPFreeSession(void *preproc_session)
{
    FTP_SESSION *ssn = (FTP_SESSION *)preproc_session;
    FTPTELNET_GLOBAL_CONF *pPolicyConfig = NULL;

    if (ssn == NULL)
        return;

    pPolicyConfig = (FTPTELNET_GLOBAL_CONF *)sfPolicyUserDataGet(ssn->global_conf, ssn->policy_id);

    if (pPolicyConfig != NULL)
    {
        pPolicyConfig->ref_count--;
        if ((pPolicyConfig->ref_count == 0) &&
            (ssn->global_conf != ftp_telnet_config))
        {

            sfPolicyUserDataClear (ssn->global_conf, ssn->policy_id);
            FTPTelnetFreeConfig(pPolicyConfig);

            if (sfPolicyUserPolicyGetActive(ssn->global_conf) == 0)
                FTPTelnetFreeConfigs(ssn->global_conf);
        }
    }

    if (ssn->filename)
    {
        free(ssn->filename);
    }

    free(ssn);
}
Example #3
0
/* Registered as a callback with our SSH data blocks when
 * they are added to the underlying stream session. Called
 * by the stream preprocessor when a session is about to be
 * destroyed.
 *
 * PARAMETERS:
 *
 * idatap:	Pointer to the moribund data.
 *
 * RETURNS:	Nothing.
 */
static void
FreeSSHData( void* idatap )
{
    SSHData *ssn = (SSHData *)idatap;
    SSHConfig *config = NULL;

    if (ssn == NULL)
        return;

    if (ssn->config != NULL)
    {
        config = (SSHConfig *)sfPolicyUserDataGet(ssn->config, ssn->policy_id);
    }

    if (config != NULL)
    {
        config->ref_count--;
        if ((config->ref_count == 0) &&
            (ssn->config != ssh_config))
        {
            sfPolicyUserDataClear (ssn->config, ssn->policy_id);
            free(config);

            if (sfPolicyUserPolicyGetActive(ssn->config) == 0)
            {
                /* No more outstanding configs - free the config array */
                SSHFreeConfig(ssn->config);
            }

        }
    }

    free(ssn);
}
Example #4
0
static void FreeDNP3Data(void *bucket)
{
    MemBucket *tmp_bucket = (MemBucket *)bucket;
    dnp3_session_data_t *session;
    dnp3_config_t *config = NULL;

    if ((tmp_bucket == NULL) || (tmp_bucket->data == NULL))
        return;

    session = tmp_bucket->data;

    if (session->context_id != NULL)
    {
        config = (dnp3_config_t *)sfPolicyUserDataGet(session->context_id, session->policy_id);
    }

    if (config != NULL)
    {
        config->ref_count--;
        if ((config->ref_count == 0) &&
            (session->context_id != dnp3_context_id))
        {
            sfPolicyUserDataClear(session->context_id, session->policy_id);
            free(config);

            if (sfPolicyUserPolicyGetActive(session->context_id) == 0)
            {
                /* No more outstanding configs - free the config array */
                DNP3FreeConfig(session->context_id);
            }
        }
    }

    mempool_free(dnp3_mempool, tmp_bucket);
}
Example #5
0
/*
 * Function: FTPFreeSession(void *preproc_session)
 *
 * Purpose: This function frees the data that is associated with a session.
 *
 * Arguments: preproc_session   => pointer to the session to free
 *
 * Returns: None
 */
static void FTPFreeSession(void *preproc_session)
{
    FTP_SESSION *ssn = (FTP_SESSION *)preproc_session;
    FTPTELNET_GLOBAL_CONF *pPolicyConfig = NULL;
    ssl_callback_interface_t *ssl_cb = (ssl_callback_interface_t *)_dpd.getSSLCallback();

    if (ssn == NULL)
        return;

    pPolicyConfig = (FTPTELNET_GLOBAL_CONF *)sfPolicyUserDataGet(ssn->global_conf, ssn->policy_id);

    if (pPolicyConfig != NULL)
    {
        pPolicyConfig->ref_count--;
        if ((pPolicyConfig->ref_count == 0) &&
            (ssn->global_conf != ftp_telnet_config))
        {

            sfPolicyUserDataClear (ssn->global_conf, ssn->policy_id);
            FTPTelnetFreeConfig(pPolicyConfig);

            if (sfPolicyUserPolicyGetActive(ssn->global_conf) == 0)
                FTPTelnetFreeConfigs(ssn->global_conf);
        }
    }

    if (ssn->filename)
    {
        free(ssn->filename);
    }

    if ( ssl_cb )
        ssl_cb->session_free(ssn->flow_id);
    free(ssn);
}
Example #6
0
/*********************************************************************
 * Function: DCE2_ReloadSwap()
 *
 * Purpose: Swaps a new config for the old one.
 *
 * Arguments: None
 *
 * Returns: None
 *
 *********************************************************************/
static void * DCE2_ReloadSwap(void)
{
    tSfPolicyUserContextId old_config = dce2_config;

    if (dce2_swap_config == NULL)
        return NULL;

    dce2_config = dce2_swap_config;
    dce2_swap_config = NULL;

    sfPolicyUserDataIterate (old_config, DCE2_ReloadSwapPolicy);

    if (sfPolicyUserPolicyGetActive(old_config) == 0)
        return (void *)old_config;

    return NULL;
}
Example #7
0
static void * SIPReloadSwap(struct _SnortConfig *sc, void *swap_config)
{
    tSfPolicyUserContextId sip_swap_config = (tSfPolicyUserContextId)swap_config;
    tSfPolicyUserContextId old_config = sip_config;

    if (sip_swap_config == NULL)
        return NULL;
        
    sip_config = sip_swap_config;

    sfPolicyUserDataFreeIterate (old_config, SIPFreeUnusedConfigPolicy);
    if (sfPolicyUserPolicyGetActive(old_config) == 0)
    {
        /* No more outstanding configs - free the config array */
        return (void *)old_config;
    }

    return NULL;
}
Example #8
0
static void * SSHReloadSwap(void)
{
    tSfPolicyUserContextId old_config = ssh_config;

    if (ssh_swap_config == NULL)
        return NULL;

    ssh_config = ssh_swap_config;
    ssh_swap_config = NULL;

    sfPolicyUserDataIterate (old_config, SshFreeUnusedConfigPolicy);

    if (sfPolicyUserPolicyGetActive(old_config) == 0)
    {
        /* No more outstanding configs - free the config array */
        return (void *)old_config;
    }

    return NULL;
}
Example #9
0
static void * ModbusReloadSwap(void)
{
    tSfPolicyUserContextId old_context_id = modbus_context_id;

    if (modbus_swap_context_id == NULL)
        return NULL;

    modbus_context_id = modbus_swap_context_id;
    modbus_swap_context_id = NULL;

    sfPolicyUserDataIterate(old_context_id, ModbusFreeUnusedConfigPolicy);

    if (sfPolicyUserPolicyGetActive(old_context_id) == 0)
    {
        /* No more outstanding configs - free the config array */
        return (void *)old_context_id;
    }

    return NULL;
}
Example #10
0
static void * DNP3ReloadSwap(struct _SnortConfig *sc, void *swap_config)
{
    tSfPolicyUserContextId dnp3_swap_context_id = (tSfPolicyUserContextId)swap_config;
    tSfPolicyUserContextId old_context_id = dnp3_context_id;

    if (dnp3_swap_context_id == NULL)
        return NULL;

    dnp3_context_id = dnp3_swap_context_id;

    sfPolicyUserDataFreeIterate(old_context_id, DNP3FreeUnusedConfigPolicy);

    if (sfPolicyUserPolicyGetActive(old_context_id) == 0)
    {
        /* No more outstanding configs - free the config array */
        return (void *)old_context_id;
    }

    return NULL;
}
Example #11
0
/***********************************************************************
 * Registered as a callback with our SIP data blocks when
 * they are added to the underlying stream session. Called
 * by the stream preprocessor when a session is about to be
 * destroyed.
 *
 * PARAMETERS:
 *
 * idatap:	Pointer to the moribund data.
 *
 * RETURNS:	Nothing.
 ***********************************************************************/
static void FreeSIPData( void* idatap )
{
    SIPData *ssn = (SIPData *)idatap;
    SIPConfig *config = NULL;

    if (ssn == NULL)
        return;
    if (numSessions > 0)
        numSessions--;

    /*Free all the dialog data*/
    sip_freeDialogs(&ssn->dialogs);

    /*Clean the configuration data*/
    if (ssn->config != NULL)
    {
        config = (SIPConfig *)sfPolicyUserDataGet(ssn->config, ssn->policy_id);
    }

    if (config == NULL)
    {
        free(ssn);
        return;
    }

    config->ref_count--;
    if ((config->ref_count == 0) &&	(ssn->config != sip_config))
    {
        sfPolicyUserDataClear (ssn->config, ssn->policy_id);
        free(config);

        if (sfPolicyUserPolicyGetActive(ssn->config) == 0)
        {
            /* No more outstanding configs - free the config array */
            SIPFreeConfig(ssn->config);
        }

    }

    free(ssn);
}
Example #12
0
/***********************************************************************
 * Registered as a callback with our GTP data blocks when
 * they are added to the underlying stream session. Called
 * by the stream preprocessor when a session is about to be
 * destroyed.
 *
 * PARAMETERS:
 *
 * idatap:	Pointer to the moribund data.
 *
 * RETURNS:	Nothing.
 ***********************************************************************/
static void FreeGTPData( void* idatap )
{
    GTPData *ssn = (GTPData *)idatap;
    GTPConfig *config = NULL;

    if (ssn == NULL)
        return;
    if (numSessions > 0)
        numSessions--;

    /*Clean the configuration data*/
    if (ssn->config != NULL)
    {
        config = (GTPConfig *)sfPolicyUserDataGet(ssn->config, ssn->policy_id);
    }

    if (config == NULL)
    {
        free(ssn);
        return;
    }

    config->ref_count--;
    if ((config->ref_count == 0) &&	(ssn->config != gtp_config))
    {
        sfPolicyUserDataClear (ssn->config, ssn->policy_id);
        free(config);

        if (sfPolicyUserPolicyGetActive(ssn->config) == 0)
        {
            /* No more outstanding configs - free the config array */
            GTPFreeConfig(ssn->config);
        }

    }

    free(ssn);
}
Example #13
0
int RemoveLWSession(Stream5SessionCache *sessionCache, Stream5LWSession *ssn)
{
    Stream5Config *pPolicyConfig = NULL;
    tSfPolicyId policy_id = ssn->policy_id;
    mempool_free(&s5FlowMempool, ssn->flowdata);
    ssn->flowdata = NULL;

    pPolicyConfig = (Stream5Config *)sfPolicyUserDataGet(ssn->config, policy_id);

    if (pPolicyConfig != NULL)
    {
        pPolicyConfig->ref_count--;
        if ((pPolicyConfig->ref_count == 0) && (ssn->config != s5_config))
        {
            sfPolicyUserDataClear (ssn->config, policy_id);
            Stream5FreeConfig(pPolicyConfig);

            if (sfPolicyUserPolicyGetActive(ssn->config) == 0)
                Stream5FreeConfigs(ssn->config);
        }
    }

    return sfxhash_remove(sessionCache->hashTable, &(ssn->key));
}