/** * Set up everything (shared memory, etc.) so we can log, just as we would if we were * really running (as opposed to running in test harness mode). */ void logging_setup(int logging_level) { // destroy the cache, if it exists am_cache_destroy(); assert_int_equal(am_init(AM_DEFAULT_AGENT_ID, NULL), AM_SUCCESS); am_init_worker(AM_DEFAULT_AGENT_ID); sprintf(log_file_name, "log%d", rand() % 1000000); // Note that we need a valid audit file name, even though we never audit sprintf(audit_file_name, "aud%d", rand() % 1000000); am_log_register_instance(getpid(), log_file_name, logging_level, TEN_MB, audit_file_name, AM_LOG_LEVEL_AUDIT, ONE_MB, NULL); am_init_worker(AM_DEFAULT_AGENT_ID); }
static int amagent_auth_handler(request_rec *r) { const char *thisfunc = "amagent_auth_handler():"; int rv; am_request_t d; am_config_t *boot = NULL; amagent_config_t *c = ap_get_module_config(r->server->module_config, &amagent_module); if (c == NULL || !c->enabled || c->error != AM_SUCCESS) { /* amagent module is not enabled for this * server/virtualhost - we are not handling this request **/ return DECLINED; } if (c->error != AM_SUCCESS) { LOG_R(APLOG_ERR, r, "%s is not configured to handle the request " "to %s (unable to load bootstrap configuration from %s, error: %s)", DESCRIPTION, r->uri, c->config, am_strerror(c->error)); return HTTP_FORBIDDEN; } LOG_R(APLOG_DEBUG, r, "amagent_auth_handler(): [%s] [%ld]", c->config, c->config_id); /* register and update instance logger configuration (for already registered * instances - update logging level only */ am_log_register_instance(c->config_id, c->debug_file, c->debug_level, c->audit_file, c->audit_level); am_log_debug(c->config_id, "%s begin", thisfunc); /* fetch agent configuration instance (from cache if available) */ rv = am_get_agent_config(c->config_id, c->config, &boot); if (boot == NULL || rv != AM_SUCCESS) { LOG_R(APLOG_ERR, r, "%s is not configured to handle the request " "to %s (unable to get agent configuration instance, configuration: %s, error: %s)", DESCRIPTION, r->uri, c->config, am_strerror(rv)); am_log_error(c->config_id, "amagent_auth_handler(): failed to get agent configuration instance, error: %s", am_strerror(rv)); return HTTP_FORBIDDEN; } /* set up request processor data structure */ memset(&d, 0, sizeof (am_request_t)); d.conf = boot; d.status = AM_ERROR; d.instance_id = c->config_id; d.ctx = r; d.method = get_method_num(r, c->config_id); d.content_type = apr_table_get(r->headers_in, "Content-Type"); d.cookies = apr_table_get(r->headers_in, "Cookie"); if (ISVALID(d.conf->client_ip_header)) { d.client_ip = (char *) apr_table_get(r->headers_in, d.conf->client_ip_header); } if (!ISVALID(d.client_ip)) { #ifdef APACHE24 d.client_ip = (char *) r->connection->client_ip; #else d.client_ip = (char *) r->connection->remote_ip; #endif } if (ISVALID(d.conf->client_hostname_header)) { d.client_host = (char *) apr_table_get(r->headers_in, d.conf->client_hostname_header); } d.am_get_request_url_f = get_request_url; d.am_get_post_data_f = get_request_body; d.am_set_post_data_f = set_request_body; d.am_set_user_f = set_user; d.am_set_header_in_request_f = set_header_in_request; d.am_add_header_in_response_f = add_header_in_response; d.am_set_cookie_f = set_cookie; d.am_set_custom_response_f = set_custom_response; d.am_set_method_f = set_method; am_process_request(&d); rv = am_status_value(d.status); am_log_debug(c->config_id, "amagent_auth_handler(): exit status: %s (%d)", am_strerror(d.status), d.status); am_config_free(&d.conf); am_request_free(&d); LOG_R(APLOG_DEBUG, r, "amagent_auth_handler(): return status: %d", rv); return rv; }