Changeset 33826c5 in mod_gnutls for src/gnutls_hooks.c


Ignore:
Timestamp:
Oct 4, 2011, 7:01:32 AM (8 years ago)
Author:
Dash Shendy <neuromancer@…>
Branches:
debian/master, debian/stretch-backports, jessie-backports, master, msva, upstream
Children:
37f8282
Parents:
a4feefc
Message:

mod_proxy support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gnutls_hooks.c

    ra4feefc r33826c5  
    5252
    5353#if MOD_GNUTLS_DEBUG
    54 
    5554static void gnutls_debug_log_all(int level, const char *str) {
    5655    apr_file_printf(debug_log_fp, "<%d> %s\n", level, str);
    5756}
    58 
    5957#define _gnutls_log apr_file_printf
    6058#else
     
    6260#endif
    6361
    64 int
    65 mgs_hook_pre_config(apr_pool_t * pconf,
    66         apr_pool_t * plog, apr_pool_t * ptemp) {
    67     int ret;
    68 
     62int mgs_hook_open_logs(apr_pool_t * pconf,apr_pool_t * plog,
     63        apr_pool_t * ptemp) {
    6964#if MOD_GNUTLS_DEBUG
    7065    apr_file_open(&debug_log_fp, "/tmp/gnutls_debug",
     
    7368
    7469    _gnutls_log(debug_log_fp, "%s: %d\n", __func__, __LINE__);
    75 
    7670    gnutls_global_set_log_level(9);
    7771    gnutls_global_set_log_function(gnutls_debug_log_all);
    7872    _gnutls_log(debug_log_fp, "gnutls: %s\n",
    7973            gnutls_check_version(NULL));
    80 #endif
     74#endif   
     75}
     76
     77int mgs_hook_pre_config(apr_pool_t * pconf, apr_pool_t * plog,
     78         apr_pool_t * ptemp) {
     79    int ret;
    8180
    8281    if (gnutls_check_version(LIBGNUTLS_VERSION) == NULL) {
     
    8483                "gnutls_check_version() failed. Required: gnutls-%s Found: gnutls-%s\n",
    8584                LIBGNUTLS_VERSION, gnutls_check_version(NULL));
    86         return -3;
     85        return DECLINED;
    8786    }
    8887
     
    9190        _gnutls_log(debug_log_fp, "gnutls_global_init: %s\n",
    9291                gnutls_strerror(ret));
    93         return -3;
     92        return DECLINED;
    9493    }
    9594
     
    353352
    354353        /* Check if the priorities have been set */
    355         if (sc->priorities == NULL
    356                 && sc->enabled == GNUTLS_ENABLED_TRUE) {
     354        if (sc->priorities == NULL && sc->enabled == GNUTLS_ENABLED_TRUE) {
    357355            ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s,
    358356                    "GnuTLS: Host '%s:%d' is missing the GnuTLSPriorities directive!",
     
    454452        }
    455453    }
     454    /* Block SIGPIPE Signals */
     455    status = apr_signal_block(SIGPIPE);
     456    if(status != APR_SUCCESS) {
     457        /* error sending output */
     458        ap_log_error(APLOG_MARK,APLOG_INFO,ctxt->output_rc,ctxt->c->base_server,
     459                "GnuTLS: Error Blocking SIGPIPE Signal!");       
     460        return status;
     461    }   
    456462}
    457463
     
    625631}
    626632
    627 static mgs_handle_t *create_gnutls_handle(apr_pool_t * pool, conn_rec * c) {
     633static void create_gnutls_handle(conn_rec * c) {
    628634    mgs_handle_t *ctxt;
    629635    /* Get mod_gnutls Configuration Record */
     
    632638
    633639    _gnutls_log(debug_log_fp, "%s: %d\n", __func__, __LINE__);
    634     ctxt = apr_pcalloc(pool, sizeof (*ctxt));
     640    ctxt = apr_pcalloc(c->pool, sizeof (*ctxt));
    635641    ctxt->c = c;
    636642    ctxt->sc = sc;
     
    657663    /* Initialize Session Cache */
    658664    mgs_cache_session_init(ctxt);
    659     /* Return GnuTLS Handle */
    660     return ctxt;
    661 }
    662 
    663 int mgs_hook_pre_connection(conn_rec * c, void *csd) {
    664     mgs_handle_t *ctxt;
    665     mgs_srvconf_rec *sc;
    666 
    667     _gnutls_log(debug_log_fp, "%s: %d\n", __func__, __LINE__);
    668 
    669     if (c == NULL) {
    670         return DECLINED;
    671     }
    672 
    673     sc = (mgs_srvconf_rec *) ap_get_module_config(c->base_server->
    674             module_config,
    675             &gnutls_module);
    676 
    677     if (!(sc && (sc->enabled == GNUTLS_ENABLED_TRUE))) {
    678         return DECLINED;
    679     }
    680 
    681     if (c->remote_addr->hostname || apr_strnatcmp(c->remote_ip, c->local_ip) == 0) {
    682         /* Connection initiated by Apache (mod_proxy) => ignore */
    683         return OK;
    684     }
    685 
    686     ctxt = create_gnutls_handle(c->pool, c);
    687 
     665   
     666    /* Set this config for this connection */
    688667    ap_set_module_config(c->conn_config, &gnutls_module, ctxt);
    689 
     668    /* Set pull, push & ptr functions */
    690669    gnutls_transport_set_pull_function(ctxt->session,
    691670            mgs_transport_read);
    692671    gnutls_transport_set_push_function(ctxt->session,
    693672            mgs_transport_write);
    694     gnutls_transport_set_ptr(ctxt->session, ctxt);
    695 
    696     ctxt->input_filter =
    697             ap_add_input_filter(GNUTLS_INPUT_FILTER_NAME, ctxt, NULL, c);
    698     ctxt->output_filter =
    699             ap_add_output_filter(GNUTLS_OUTPUT_FILTER_NAME, ctxt, NULL, c);
     673    gnutls_transport_set_ptr2(ctxt->session, ctxt);
     674    /* Add IO filters */
     675    ctxt->input_filter = ap_add_input_filter(GNUTLS_INPUT_FILTER_NAME,
     676            ctxt, NULL, c);
     677    ctxt->output_filter = ap_add_output_filter(GNUTLS_OUTPUT_FILTER_NAME,
     678            ctxt, NULL, c);   
     679}
     680
     681int mgs_hook_pre_connection(conn_rec * c, void *csd) {
     682    mgs_handle_t *ctxt;
     683    mgs_srvconf_rec *sc;
     684
     685    _gnutls_log(debug_log_fp, "%s: %d\n", __func__, __LINE__);
     686
     687    sc = (mgs_srvconf_rec *) ap_get_module_config(c->base_server->module_config,
     688            &gnutls_module);
     689
     690    if (sc && !sc->enabled) {
     691        return DECLINED;
     692    }
     693
     694    if (c->remote_addr->hostname) {
     695        /* Connection initiated by Apache (mod_proxy) => ignore */
     696        return OK;
     697    }
     698
     699    create_gnutls_handle(c);
    700700
    701701    return OK;
     
    780780            GNUTLS_CRT_OPENPGP)
    781781        mgs_add_common_pgpcert_vars(r, ctxt->sc->cert_pgp, 0,
    782             ctxt->
    783             sc->export_certificates_enabled);
     782            ctxt->sc->export_certificates_enabled);
    784783
    785784    return rv;
Note: See TracChangeset for help on using the changeset viewer.