View | Details | Raw Unified | Return to bug 48253
Collapse All | Expand All

(-)tomcat-native-1.1.20-src/jni/native/src/ssl.c (-2 / +133 lines)
Lines 215-220 Link Here
215
    UNREFERENCED(data);
215
    UNREFERENCED(data);
216
    CRYPTO_set_locking_callback(NULL);
216
    CRYPTO_set_locking_callback(NULL);
217
    CRYPTO_set_id_callback(NULL);
217
    CRYPTO_set_id_callback(NULL);
218
    CRYPTO_set_dynlock_create_callback(NULL);
219
    CRYPTO_set_dynlock_lock_callback(NULL);
220
    CRYPTO_set_dynlock_destroy_callback(NULL);
221
222
    dynlockpool = NULL;
223
218
    /* Let the registered mutex cleanups do their own thing
224
    /* Let the registered mutex cleanups do their own thing
219
     */
225
     */
220
    return APR_SUCCESS;
226
    return APR_SUCCESS;
Lines 235-240 Link Here
235
    CRYPTO_set_id_callback(ssl_thread_id);
241
    CRYPTO_set_id_callback(ssl_thread_id);
236
    CRYPTO_set_locking_callback(ssl_thread_lock);
242
    CRYPTO_set_locking_callback(ssl_thread_lock);
237
243
244
    /* Set up dynamic locking scaffolding for OpenSSL to use at its
245
     * convenience.
246
     */
247
    dynlockpool = p;
248
    CRYPTO_set_dynlock_create_callback(ssl_dyn_create_function);
249
    CRYPTO_set_dynlock_lock_callback(ssl_dyn_lock_function);
250
    CRYPTO_set_dynlock_destroy_callback(ssl_dyn_destroy_function);
251
238
    apr_pool_cleanup_register(p, NULL, ssl_thread_cleanup,
252
    apr_pool_cleanup_register(p, NULL, ssl_thread_cleanup,
239
                              apr_pool_cleanup_null);
253
                              apr_pool_cleanup_null);
240
}
254
}
Lines 404-409 Link Here
404
    OPENSSL_load_builtin_modules();
418
    OPENSSL_load_builtin_modules();
405
#endif
419
#endif
406
420
421
    /* Initialize thread support */
422
    ssl_thread_setup(tcn_global_pool);
423
407
#ifndef OPENSSL_NO_ENGINE
424
#ifndef OPENSSL_NO_ENGINE
408
    if (J2S(engine)) {
425
    if (J2S(engine)) {
409
        ENGINE *ee = NULL;
426
        ENGINE *ee = NULL;
Lines 457-464 Link Here
457
    apr_pool_cleanup_register(tcn_global_pool, NULL,
474
    apr_pool_cleanup_register(tcn_global_pool, NULL,
458
                              ssl_init_cleanup,
475
                              ssl_init_cleanup,
459
                              apr_pool_cleanup_null);
476
                              apr_pool_cleanup_null);
460
    /* Initialize thread support */
461
    ssl_thread_setup(tcn_global_pool);
462
    TCN_FREE_CSTRING(engine);
477
    TCN_FREE_CSTRING(engine);
463
    return (jint)APR_SUCCESS;
478
    return (jint)APR_SUCCESS;
464
}
479
}
Lines 919-921 Link Here
919
}
934
}
920
935
921
#endif
936
#endif
937
938
/* Global reference to the pool used by the dynamic mutexes */
939
apr_pool_t *dynlockpool;
940
941
/* Dynamic lock structure */
942
struct CRYPTO_dynlock_value {
943
    apr_pool_t *pool;
944
    const char* file;
945
    int line;
946
    apr_thread_mutex_t *mutex;
947
};
948
949
/**
950
 * Dynamic lock callback functions
951
 */
952
static struct CRYPTO_dynlock_value *ssl_dyn_create_function(const char *file, int line);
953
static void ssl_dyn_lock_function(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line);
954
static void ssl_dyn_destroy_function(struct CRYPTO_dynlock_value *l, const char *file, int line);
955
956
/*
957
 * Dynamic lock creation callback
958
 */
959
static struct CRYPTO_dynlock_value *ssl_dyn_create_function(const char *file,
960
                                                     int line)
961
{
962
    struct CRYPTO_dynlock_value *value;
963
    apr_pool_t *p;
964
    apr_status_t rv;
965
966
    /* 
967
     * We need a pool to allocate our mutex.  Since we can't clear
968
     * allocated memory from a pool, create a subpool that we can blow
969
     * away in the destruction callback. 
970
     */
971
    rv = apr_pool_create(&p, dynlockpool);
972
    if (rv != APR_SUCCESS) {
973
        fprintf(stderr, "Failed to create subpool for dynamic lock");
974
        return NULL;
975
    }
976
977
    /*
978
    fprintf(stderr, "Creating dynamic lock");
979
    */
980
981
    value = (struct CRYPTO_dynlock_value *)apr_palloc(p,
982
                                                      sizeof(struct CRYPTO_dynlock_value));
983
    if (!value) {
984
        fprintf(stderr, "Failed to allocate dynamic lock structure");
985
        return NULL;
986
    }
987
988
    value->pool = p;
989
    /* Keep our own copy of the place from which we were created,
990
       using our own pool. */
991
    value->file = apr_pstrdup(p, file);
992
    value->line = line;
993
    rv = apr_thread_mutex_create(&(value->mutex), APR_THREAD_MUTEX_DEFAULT,
994
                                p);
995
    if (rv != APR_SUCCESS) {
996
        fprintf(stderr, "Failed to create thread mutex for dynamic lock");
997
        apr_pool_destroy(p);
998
        return NULL;
999
    }
1000
    return value;
1001
}
1002
1003
/*
1004
 * Dynamic locking and unlocking function
1005
 */
1006
1007
static void ssl_dyn_lock_function(int mode, struct CRYPTO_dynlock_value *l,
1008
                           const char *file, int line)
1009
{
1010
    apr_status_t rv;
1011
1012
    if (mode & CRYPTO_LOCK) {
1013
        /*
1014
        fprintf(stderr, "Acquiring mutex %s:%d", l->file, l->line);
1015
        */
1016
        rv = apr_thread_mutex_lock(l->mutex);
1017
        /*
1018
        fprintf(stderr, "Mutex %s:%d acquired!", l->file, l->line);
1019
        */
1020
    }
1021
    else {
1022
        /*
1023
        fprintf(stderr, "Releasing mutex %s:%d", l->file, l->line);
1024
        */
1025
        rv = apr_thread_mutex_unlock(l->mutex);
1026
        /*
1027
        fprintf(stderr, "Mutex %s:%d released!", l->file, l->line);
1028
        */
1029
    }
1030
}
1031
1032
/*
1033
 * Dynamic lock destruction callback
1034
 */
1035
static void ssl_dyn_destroy_function(struct CRYPTO_dynlock_value *l,
1036
                          const char *file, int line)
1037
{
1038
    apr_status_t rv;
1039
1040
    /*
1041
    fprintf(stderr, "Destroying dynamic lock %s:%d", l->file, l->line);
1042
    */
1043
    rv = apr_thread_mutex_destroy(l->mutex);
1044
    if (rv != APR_SUCCESS) {
1045
        fprintf(stderr, "Failed to destroy mutex for dynamic lock %s:%d", l->file, l->line);
1046
    }
1047
1048
    /* Trust that whomever owned the CRYPTO_dynlock_value we were
1049
     * passed has no future use for it...
1050
     */
1051
    apr_pool_destroy(l->pool);
1052
}

Return to bug 48253