示例#1
0
/*Get the current main file context*/
FileContext* get_main_file_context(void *ssnptr)
{
    FileSession *file_session = get_file_session (ssnptr);
    if (file_session)
        return file_session->main_context;
    else
        return NULL;
}
示例#2
0
static inline FileContext* find_main_file_context(void* p, FilePosition position,
        bool upload)
{
    FileContext* context = NULL;
    Packet *pkt = (Packet *)p;
    void *ssnptr = pkt->ssnptr;
    FileSession *file_session = get_file_session (ssnptr);

    /* Attempt to get a previously allocated context. */
    if (file_session)
        context  = file_session->main_context;

    if (context && ((position == SNORT_FILE_MIDDLE) ||
            (position == SNORT_FILE_END)))
        return context;
    else if (context)
    {
        /*Push file event when there is another file in the same packet*/
        if (pkt->packet_flags & PKT_FILE_EVENT_SET)
        {
            SnortEventqLog(snort_conf->event_queue, p);
            SnortEventqReset();
            pkt->packet_flags &= ~PKT_FILE_EVENT_SET;
        }

        if (context->verdict != FILE_VERDICT_PENDING)
        {
            /* Reuse the same context */
            file_context_reset(context);
            file_stats.files_total++;
            init_file_context(ssnptr, upload, context);
            context->file_id = file_session->max_file_id++;
            return context;
        }
    }

    context = create_file_context(ssnptr);
    file_session = get_file_session (ssnptr);
    file_session->main_context = context;
    init_file_context(ssnptr, upload, context);
    context->file_id = file_session->max_file_id++;
    return context;
}
示例#3
0
/*Set the current working file context*/
bool set_current_file_context(void *ssnptr, FileContext *ctx)
{
    FileSession *file_session = get_file_session (ssnptr);

    if (!file_session)
    {
        return false;
    }

    file_session->current_context = ctx;
    return true;
}
示例#4
0
/*Get the current working file context*/
static inline void save_to_pending_context(void *ssnptr)
{
    FileSession *file_session = get_file_session (ssnptr);
    /* Save to pending_context */
    if (!file_session)
        return;

    if (file_session->pending_context != file_session->main_context)
        file_context_free(file_session->pending_context);
    file_session->pending_context = file_session->main_context;

}
示例#5
0
static uint32_t get_new_file_instance(void *ssnptr)
{
    FileSession *file_session = get_file_session (ssnptr);

    if (file_session)
    {
        return file_session->max_file_id++;
    }
    else
    {
        return 0;
    }
}
示例#6
0
static void file_signature_callback(Packet* p)
{
    /* During retransmission */
    Packet *pkt = (Packet *)p;
    void *ssnptr = pkt->ssnptr;
    FileSession *file_session;

    if (!ssnptr)
        return;
    file_session = get_file_session (ssnptr);
    if (!file_session)
        return;
    file_session->current_context = file_session->pending_context;
    file_signature_lookup(p, 1);
}
示例#7
0
static inline void update_file_session(void *ssnptr, FileCache *fileCache,
    uint64_t file_id, FileContext *context)
{
    FileSession *file_session;

    if (!file_api->set_current_file_context(ssnptr, context))
        return;

    file_session = get_file_session (ssnptr);

    if (!file_session->file_cache)
        file_session->file_cache = fileCache;

    file_session->file_id = file_id;
}
示例#8
0
FileContext* create_file_context(void *ssnptr)
{
    FileSession *file_session;
    FileContext *context = file_context_create();

    /* Create file session if not yet*/
    file_session = get_file_session (ssnptr);
    if(!file_session)
    {
        file_session = (FileSession *)SnortAlloc(sizeof(*file_session));
        session_api->set_application_data(ssnptr, PP_FILE, file_session,
                file_session_free);
    }
    file_stats.files_total++;
    return context;
}