static ib_status_t audit_add_line_item(const ib_logformat_t *lf, const ib_logformat_field_t *field, const void *cbdata, const char **str) { const auditlog_callback_data_t *logdata = (const auditlog_callback_data_t *)cbdata; switch (field->fchar) { case IB_LOG_FIELD_REMOTE_ADDR: *str = logdata->tx->remote_ipstr; break; case IB_LOG_FIELD_LOCAL_ADDR: *str = logdata->conn->local_ipstr; break; case IB_LOG_FIELD_HOSTNAME: *str = logdata->tx->hostname; break; case IB_LOG_FIELD_SITE_ID: if (logdata->site == NULL) { *str = (char *)"-"; } else { *str = logdata->site->id; } break; case IB_LOG_FIELD_SENSOR_ID: *str = logdata->log->ib->sensor_id; break; case IB_LOG_FIELD_TRANSACTION_ID: *str = logdata->tx->id; break; case IB_LOG_FIELD_TIMESTAMP: { char *tstamp = NULL; /* Prepare timestamp (only if needed) */ tstamp = (char *)ib_mm_alloc(logdata->log->mm, 30); if (tstamp == NULL) { return IB_EALLOC; } ib_clock_timestamp(tstamp, &logdata->tx->tv_created); *str = tstamp; break; } case IB_LOG_FIELD_LOG_FILE: *str = logdata->cfg->fn; break; default: *str = "\n"; /* Not understood */ return IB_EINVAL; } return IB_OK; }
void ib_clock_relative_timestamp( char *buf, const ib_timeval_t *ptv, ib_time_t offset ) { ib_timeval_t adj_tv; if (ptv != NULL) { IB_CLOCK_ASSIGN_TIMEVAL(adj_tv, *ptv); } else { ib_clock_gettimeofday(&adj_tv); } IB_CLOCK_ADJUST_TIMEVAL(adj_tv, offset); ib_clock_timestamp(buf, &adj_tv); }
ib_status_t core_audit_get_index_line(ib_provider_inst_t *lpi, ib_auditlog_t *log, char *line, int *line_size) { IB_FTRACE_INIT(); core_audit_cfg_t *cfg = (core_audit_cfg_t *)log->cfg_data; ib_core_cfg_t *corecfg; ib_tx_t *tx = log->tx; ib_conn_t *conn = tx->conn; ib_site_t *site = ib_context_site_get(log->ctx); const ib_logformat_t *lf; ib_status_t rc; char *ptr = line; char *tstamp = NULL; uint8_t which; int i = 0; int l = 0; int used = 0; const char *aux = NULL; /* Retrieve corecfg to get the AuditLogIndexFormat */ rc = ib_context_module_config(log->ctx, ib_core_module(), (void *)&corecfg); if (rc != IB_OK) { IB_FTRACE_RET_STATUS(rc); } lf = corecfg->auditlog_index_hp; which = lf->literal_starts ? 1 : 0; for (; (i < lf->field_cnt || l < lf->literal_cnt) && used < IB_LOGFORMAT_MAXLINELEN;) { if (which++ % 2 == 0) { int aux_i = 0; switch (lf->fields[i]) { case IB_LOG_FIELD_REMOTE_ADDR: aux = tx->er_ipstr; break; case IB_LOG_FIELD_LOCAL_ADDR: aux = conn->local_ipstr; break; case IB_LOG_FIELD_HOSTNAME: aux = tx->hostname; break; case IB_LOG_FIELD_SITE_ID: if (site == NULL) { aux = (char *)"-"; } else { aux = site->id_str; } break; case IB_LOG_FIELD_SENSOR_ID: aux = log->ib->sensor_id_str; break; case IB_LOG_FIELD_TRANSACTION_ID: aux = tx->id; break; case IB_LOG_FIELD_TIMESTAMP: /* Prepare timestamp (only if needed) */ tstamp = (char *)ib_mpool_alloc(log->mp, 30); if (tstamp == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } ib_clock_timestamp(tstamp, &tx->tv_created); aux = tstamp; break; case IB_LOG_FIELD_LOG_FILE: aux = cfg->fn; break; default: ptr[used++] = '\n'; /* Not understood */ IB_FTRACE_RET_STATUS(IB_EINVAL); break; } for (; aux != NULL && aux[aux_i] != '\0';) { if (used < IB_LOGFORMAT_MAXLINELEN) { ptr[used++] = aux[aux_i++]; } else { ptr[used++] = '\n'; IB_FTRACE_RET_STATUS(IB_ETRUNC); } } ++i; } else { /* Use literals */ if (used + lf->literals_len[l] < IB_LOGFORMAT_MAXLINELEN) { memcpy(&ptr[used], lf->literals[l], lf->literals_len[l]); used += lf->literals_len[l]; ++l; } else { /* Truncated.. */ ptr[used++] = '\n'; IB_FTRACE_RET_STATUS(IB_ETRUNC); } } } ptr[used++] = '\n'; *line_size = used; IB_FTRACE_RET_STATUS(IB_OK); }