Пример #1
0
/// @test Test util logformat library - ib_logformat_create() and *_set()
TEST_F(TestIBUtilLogformat, test_create)
{
    ib_status_t rc;

    ib_logformat_t *lf = NULL;

    rc = ib_logformat_create(MM(), &lf);
    ASSERT_EQ(IB_OK, rc);
    ASSERT_TRUE(lf->items);
}
Пример #2
0
TEST_F(TestIBUtilLogformat, test_parse_custom3)
{
    ib_status_t rc;
    ib_logformat_t *lf = NULL;
    size_t len;
    static char linebuf[buflen + 1];
    static const char *formatted = \
                                   "Start" SITE_ID " \\ " SENSOR_ID " " HOST_NAME "  \t" LOG_FILE " %End";

    rc = ib_logformat_create(MM(), &lf);
    ASSERT_EQ(IB_OK, rc);

    rc = ib_logformat_parse(lf, "Start%s \\\\ %S %h\\n\\r\\t%f %%End");
    ASSERT_EQ(IB_OK, rc);
    ASSERT_EQ(9U, ib_list_elements(lf->items));

    rc = ib_logformat_format(lf, linebuf, buflen, &len, format_field, NULL);
    ASSERT_EQ(IB_OK, rc);
    ASSERT_STREQ(formatted, linebuf);
}
Пример #3
0
/// @test Test util logformat library - ib_logformat_parse()
TEST_F(TestIBUtilLogformat, test_parse_custom1)
{
    ib_status_t rc;
    ib_logformat_t *lf = NULL;
    size_t len;
    static char linebuf[buflen + 1];
    static const char *formatted = \
                                   "MyFormat " SITE_ID " " SENSOR_ID " " HOST_NAME " " LOG_FILE " END";

    rc = ib_logformat_create(MM(), &lf);
    ASSERT_EQ(IB_OK, rc);

    rc = ib_logformat_parse(lf, "MyFormat %s %S %h %f END");
    ASSERT_EQ(IB_OK, rc);
    ASSERT_EQ(9U, ib_list_elements(lf->items));

    rc = ib_logformat_format(lf, linebuf, buflen, &len, format_field, NULL);
    ASSERT_EQ(IB_OK, rc);
    ASSERT_STREQ(formatted, linebuf);
}
Пример #4
0
ib_status_t core_audit_open(ib_engine_t *ib,
                            ib_auditlog_t *log)
{
    ib_core_audit_cfg_t *cfg = (ib_core_audit_cfg_t *)log->cfg_data;
    ib_core_cfg_t *corecfg;
    ib_status_t rc;

    /* Non const struct we will build and then assign to
     * corecfg->auditlog_index_hp. */
    ib_logformat_t *auditlog_index_hp;

    assert(NULL != log);
    assert(NULL != log->ctx);
    assert(NULL != log->ctx->auditlog);

    rc = ib_core_context_config(log->ctx, &corecfg);
    if (rc != IB_OK) {
        ib_log_error(log->ib, "Error fetching core configuration: %s",
                     ib_status_to_string(rc) );
        return rc;
    }

    assert(NULL != corecfg);

    /* Copy the FILE* into the ib_core_audit_cfg_t. */
    if (log->ctx->auditlog->index_fp != NULL) {
        cfg->index_fp = log->ctx->auditlog->index_fp;
    }

    /* If we have a file name but no file pointer, assign cfg->index_fp. */
    else if ((log->ctx->auditlog->index != NULL) && (cfg->index_fp == NULL)) {

        /**
         * Open the audit log index file. If the file name starts with
         * a | a pipe is opened to a subprocess, etc...
         */
        rc = core_audit_open_auditindexfile(ib, log, cfg, corecfg);

        if (rc != IB_OK) {
            ib_log_error(log->ib,  "Failed to open auditlog index.");
            return rc;
        }
    }

    /* Open audit file that contains the record identified by the line
     * written in index_fp. */
    if (cfg->fp == NULL) {
        rc = core_audit_open_auditfile(ib, log, cfg, corecfg);

        if (rc!=IB_OK) {
            ib_log_error(log->ib,  "Failed to open audit log file.");
            return rc;
        }
    }

    /* Set the Audit Log index format */
    if (corecfg->auditlog_index_hp == NULL) {
        rc = ib_logformat_create(
            ib_engine_mm_main_get(log->ib),
            &auditlog_index_hp
        );
        if (rc != IB_OK) {
            return rc;
        }
        if (corecfg->auditlog_index_fmt != NULL) {
            rc = ib_logformat_parse(auditlog_index_hp,
                                    corecfg->auditlog_index_fmt);
        }
        else {
            rc = ib_logformat_parse(auditlog_index_hp, IB_LOGFORMAT_DEFAULT);
        }
        if (rc != IB_OK) {
            return rc;
        }

        /* Commit built struct. */
        corecfg->auditlog_index_hp = auditlog_index_hp;
    }

    /* Notify all handlers that the given audit log has been opened. */
    rc = ib_core_dispatch_auditlog(
        log->tx,
        IB_CORE_AUDITLOG_OPENED,
        log);
    if (rc != IB_OK) {
        ib_log_error(log->ib, "Failed to dispatch auditlog to handlers.");
        return rc;
    }

    return IB_OK;
}
Пример #5
0
TEST_F(TestIBUtilLogformat, test_parse_default)
{
    ib_status_t rc;
    ib_logformat_t *lf = NULL;
    const ib_list_node_t *node;
    const ib_logformat_item_t *item;
    static char linebuf[buflen + 1];
    static const char *formatted = \
                                   TIME_STAMP " " HOST_NAME " " REMOTE_IP " " SENSOR_ID " " SITE_ID " " \
                                   TX_ID " " LOG_FILE;
    size_t len;

    rc = ib_logformat_create(MM(), &lf);
    ASSERT_EQ(IB_OK, rc);

    rc = ib_logformat_parse(lf, IB_LOGFORMAT_DEFAULT);
    ASSERT_EQ(IB_OK, rc);

    ASSERT_STREQ(IB_LOGFORMAT_DEFAULT, lf->format);

    ASSERT_EQ(13U, ib_list_elements(lf->items));

    node = ib_list_first_const(lf->items);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_format, item->itype);
    ASSERT_EQ('T', item->item.field.fchar);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_literal, item->itype);
    ASSERT_STREQ(" ", item->item.literal.buf.short_str);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_format, item->itype);
    ASSERT_EQ('h', item->item.field.fchar);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_literal, item->itype);
    ASSERT_STREQ(" ", item->item.literal.buf.short_str);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_format, item->itype);
    ASSERT_EQ('a', item->item.field.fchar);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_literal, item->itype);
    ASSERT_STREQ(" ", item->item.literal.buf.short_str);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_format, item->itype);
    ASSERT_EQ('S', item->item.field.fchar);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_literal, item->itype);
    ASSERT_STREQ(" ", item->item.literal.buf.short_str);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_format, item->itype);
    ASSERT_EQ('s', item->item.field.fchar);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_literal, item->itype);
    ASSERT_STREQ(" ", item->item.literal.buf.short_str);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_format, item->itype);
    ASSERT_EQ('t', item->item.field.fchar);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_literal, item->itype);
    ASSERT_STREQ(" ", item->item.literal.buf.short_str);

    node = ib_list_node_next_const(node);
    ASSERT_TRUE(node);
    item = (const ib_logformat_item_t *)node->data;
    ASSERT_EQ(item_type_format, item->itype);
    ASSERT_EQ('f', item->item.field.fchar);

    rc = ib_logformat_format(lf, linebuf, buflen, &len, format_field, NULL);
    ASSERT_EQ(IB_OK, rc);
    ASSERT_STREQ(formatted, linebuf);

    /* Verify that truncation is handled correctly */
    rc = ib_logformat_format(lf, linebuf, trunclen, &len, format_field, NULL);
    ASSERT_EQ(IB_ETRUNC, rc);
    ASSERT_EQ(len, trunclen-1);
    char trunc_buf[trunclen];
    strncpy(trunc_buf, formatted, trunclen-1);
    trunc_buf[trunclen-1] = '\0';
    ASSERT_STREQ(trunc_buf, linebuf);
}
Пример #6
0
ib_status_t core_audit_open(ib_provider_inst_t *lpi,
                            ib_auditlog_t *log)
{
    IB_FTRACE_INIT();
    core_audit_cfg_t *cfg = (core_audit_cfg_t *)log->cfg_data;
    ib_core_cfg_t *corecfg;
    ib_status_t rc;

    /* Non const struct we will build and then assign to
     * corecfg->auditlog_index_hp. */
    ib_logformat_t *auditlog_index_hp;

    assert(NULL != lpi);
    assert(NULL != log);
    assert(NULL != log->ctx);
    assert(NULL != log->ctx->auditlog);

    rc = ib_context_module_config(log->ctx, ib_core_module(),
                                  (void *)&corecfg);
    if (rc != IB_OK) {
        ib_log_error(log->ib,  "Could not fetch core configuration: %s", ib_status_to_string(rc) );
        IB_FTRACE_RET_STATUS(rc);
    }

    assert(NULL != corecfg);

    /* Copy the FILE* into the core_audit_cfg_t. */
    if (log->ctx->auditlog->index_fp != NULL) {
        cfg->index_fp = log->ctx->auditlog->index_fp;
    }

    /* If we have a file name but no file pointer, assign cfg->index_fp. */
    else if ((log->ctx->auditlog->index != NULL) && (cfg->index_fp == NULL)) {

        /**
         * Open the audit log index file. If the file name starts with
         * a | a pipe is opened to a subprocess, etc...
         */
        rc = core_audit_open_auditindexfile(lpi, log, cfg, corecfg);

        if (rc != IB_OK) {
            ib_log_error(log->ib,  "Could not open auditlog index.");
            IB_FTRACE_RET_STATUS(rc);
        }
    }

    /* Open audit file that contains the record identified by the line
     * written in index_fp. */
    if (cfg->fp == NULL) {
        rc = core_audit_open_auditfile(lpi, log, cfg, corecfg);

        if (rc!=IB_OK) {
            ib_log_error(log->ib,  "Failed to open audit log file.");
            IB_FTRACE_RET_STATUS(rc);
        }
    }

    /* Set the Audit Log index format */
    if (corecfg->auditlog_index_hp == NULL) {
        rc = ib_logformat_create(log->ib->mp, &auditlog_index_hp);
        if (rc != IB_OK) {
            IB_FTRACE_RET_STATUS(rc);
        }
        if (corecfg->auditlog_index_fmt != NULL) {
            rc = ib_logformat_set(auditlog_index_hp,
                                  corecfg->auditlog_index_fmt);
        }
        else {
            rc = ib_logformat_set(auditlog_index_hp, IB_LOGFORMAT_DEFAULT);
        }
        if (rc != IB_OK) {
            IB_FTRACE_RET_STATUS(rc);
        }

        /* Commit built struct. */
        corecfg->auditlog_index_hp = auditlog_index_hp;
    }

    IB_FTRACE_RET_STATUS(IB_OK);
}