예제 #1
0
/**
 * \brief parse the options from the 'template' keyword in the rule into
 *        the Signature data structure.
 *
 * \param de_ctx pointer to the Detection Engine Context
 * \param s pointer to the Current Signature
 * \param templatestr pointer to the user provided template options
 *
 * \retval 0 on Success
 * \retval -1 on Failure
 */
static int DetectTemplateSetup (DetectEngineCtx *de_ctx, Signature *s, char *templatestr)
{
    DetectTemplateData *templated = NULL;
    SigMatch *sm = NULL;

    templated = DetectTemplateParse(templatestr);
    if (templated == NULL)
        goto error;

    sm = SigMatchAlloc();
    if (sm == NULL)
        goto error;

    sm->type = DETECT_TEMPLATE;
    sm->ctx = (void *)templated;

    SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_MATCH);
    s->flags |= SIG_FLAG_REQUIRE_PACKET;

    return 0;

error:
    if (templated != NULL)
        DetectTemplateFree(templated);
    if (sm != NULL)
        SCFree(sm);
    return -1;
}
예제 #2
0
static int DetectTemplateParseTest01 (void)
{
    DetectTemplateData *templated = DetectTemplateParse("1,10");
    FAIL_IF_NULL(templated);
    FAIL_IF(!(templated->arg1 == 1 && templated->arg2 == 10));
    DetectTemplateFree(templated);
    PASS;
}
예제 #3
0
static int DetectTemplateParseTest01 (void) {
    DetectTemplateData *templated = NULL;
    uint8_t res = 0;

    templated = DetectTemplateParse("1,10");
    if (templated != NULL) {
        if (templated->arg1 == 1 && templated->arg2 == 10)
            res = 1;

        DetectTemplateFree(templated);
    }

    return res;
}