Esempio n. 1
0
/**
 * Initialize the IronBee ATS plugin.
 *
 * Performs initializations required by ATS.
 *
 * @param[in] argc Command-line argument count
 * @param[in] argv Command-line argument list
 */
static void *ibinit(void *x)
{
    TSCont cont = x;
    ib_status_t rc;

    rc = ironbee_init(&module_data);
    if (rc != IB_OK) {
        TSError("[ironbee] initialization failed: %s",
                ib_status_to_string(rc));
        goto Lerror;
    }

    /* connection initialization & cleanup */
    TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, cont);

    /* now all's up and running, flag it to our READ_REQUEST_HDR hook */
    TSContDataSet(cont, &module_data);

    /* Register our continuation for management update for traffic_line -x
     * Note that this requires Trafficserver 3.3.5 or later, or else
     * apply the patch from bug TS-2036
     */
    TSMgmtUpdateRegister(cont, "ironbee");

    return NULL;

Lerror:
    TSError("[ironbee] Unable to initialize plugin (disabled).");

    return NULL;
}
Esempio n. 2
0
/**
 * nginx post-config handler to insert our handlers.
 *
 * @param[in]  cf     Configuration rec
 * @return     Return value from ironbee_init, or error
 */
static ngx_int_t ngxib_post_conf(ngx_conf_t *cf)
{
    ngx_http_core_main_conf_t *main_cf;
    ngx_http_handler_pt *req_handler;
    ironbee_proc_t *ipcf;

    /* Step aside if not configured in nginx */
    ipcf = ngx_http_conf_get_module_main_conf(cf, ngx_ironbee_module);
    if (ipcf->config_file.len == 0) {
        return NGX_OK;
    }

    /* Give ourself the chance to attach gdb */
    do {
        const char *csleeptime = getenv("sleeptime");
        if (csleeptime) {
            int sleeptime = atoi(csleeptime);
            sleep(sleeptime);
        }
    } while (0);

    main_cf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
    assert (main_cf != NULL);

    /* Register a handler to deal with request line and headers */
    req_handler = ngx_array_push(&main_cf->phases[NGX_HTTP_POST_READ_PHASE].handlers);
    if (req_handler == NULL) {
        return NGX_ERROR;
    }
    *req_handler = ironbee_post_read_request;

    /* Register dummy handler to pull input */
    /* Don't use content phase.  That's "special", and often gets overridden
     * (it's always overridden when proxying).  The last phase we can insert
     * a handler into is ACCESS, but that leaves us with a return value that
     * has a special meaning, so we can't use it without side-effect.
     * Try preaccess, and if that fails try rewrite.
     * (ref: http://www.nginxguts.com/2011/01/phases/).
     */
    //req_handler = ngx_array_push(&main_cf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
    req_handler = ngx_array_push(&main_cf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);
    if (req_handler == NULL) {
        return NGX_ERROR;
    }
    *req_handler = ngxib_handler;

    /* Insert headers_out filter */
    ngx_http_next_header_filter = ngx_http_top_header_filter;
    ngx_http_top_header_filter = ironbee_headers_out;

    /* Insert body_out filter */
    ngx_http_next_body_filter = ngx_http_top_body_filter;
    ngx_http_top_body_filter = ironbee_body_out;

    return ironbee_init(cf);
}
Esempio n. 3
0
void TSPluginInit(int argc, const char *argv[])
{
  int rv;
  TSPluginRegistrationInfo info;
  TSCont cont;

  /* FIXME - check why these are char*, not const char* */
  info.plugin_name = (char *)"ironbee";
  info.vendor_name = (char *)"Qualys, Inc";
  info.support_email = (char *)"*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("[ironbee] Plugin registration failed.\n");
    goto Lerror;
  }

  if (!check_ts_version()) {
    TSError("[ironbee] Plugin requires Traffic Server 3.0 or later\n");
    goto Lerror;
  }

  cont = TSContCreate(ironbee_plugin, NULL);

  /* connection initialisation & cleanup */
  TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, cont);


  if (argc < 2) {
    TSError("[ironbee] configuration file name required\n");
    goto Lerror;
  }
  rv = ironbee_init(argv[1], argc >= 3 ? argv[2] : DEFAULT_LOG);
  if (rv != IB_OK) {
    TSError("[ironbee] initialisation failed with %d\n", rv);
  }
  return;

Lerror:
  TSError("[ironbee] Unable to initialize plugin (disabled).\n");
}