Check-in [e14e862239]
Overview
Comment:Started work on runtime loading of dependencies
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | runtime-loading-of-deps
Files: files | file ages | folders
SHA1:e14e862239766461a52f4523c2ac998b8d8e1403
User & Date: rkeene on 2017-12-27 17:52:34
Other Links: manifest | tags
Context
2017-12-27
17:52
Started work on runtime loading of dependencies Leaf check-in: e14e862239 user: rkeene tags: runtime-loading-of-deps
2017-07-17
13:56
Updated to treat returning a zero-length signed message as an error check-in: 0c7c510048 user: rkeene tags: trunk
Changes

Modified aclocal/Makefile from [2810947b90] to [7b6874b298].

1
2
../aclocal.m4: acx_pthread.m4 dc_shobjs.m4 dc_pcsc.m4 dc_versionscript.m4
	cat $^ > "$@"
|

1
2
../aclocal.m4: acx_pthread.m4 dc_shobjs.m4 dc_pcsc.m4 dc_versionscript.m4 dc_dlfuncs.m4
	cat $^ > "$@"

Added aclocal/dc_dlfuncs.m4 version [d34cc673cd].











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
AC_DEFUN([DC_DLFUNCS], [
	dnl Check for dl headers and functions
	AC_CHECK_HEADERS(dlfcn.h)
	if test -n "${ac_cv_func_dlsym}"; then
		AC_CHECK_FUNC(dlsym, [
			AC_DEFINE([HAVE_DLSYM], [1], [Have dlsym()])
		])
	else
		SAVE_LIBS="${LIBS}"
		for addlibs in '' '-ldl'; do
			LIBS="${SAVE_LIBS} ${addlibs}"
			unset ac_cv_func_dlsym
			AC_CHECK_FUNC(dlsym, [
				AC_DEFINE([HAVE_DLSYM], [1], [Have dlsym()])
				SAVE_LIBS="${LIBS}"
				break
			])
		done
		LIBS="${SAVE_LIBS}"
	fi
])

Modified cackey.c from [de5cf6edd0] to [47e7747ccc].

43
44
45
46
47
48
49








50
51
52
53
54
55
56
....
3734
3735
3736
3737
3738
3739
3740


































3741
3742
3743
3744
3745
3746
3747
....
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
....
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
....
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
....
4614
4615
4616
4617
4618
4619
4620








4621
4622
4623
4624
4625
4626
4627
#  ifdef HAVE_LIBZ
#    include <zlib.h>
#  endif
#else
#  ifdef HAVE_LIBZ
#    undef HAVE_LIBZ
#  endif








#endif
#ifdef CACKEY_DEBUG_SEARCH_SPEEDTEST
#  include <sys/time.h>
#endif

#define CK_PTR *
#define CK_DEFINE_FUNCTION(returnType, name) returnType name
................................................................................
		return(-1);
	}
#  endif
#endif

	return(x509_read_ret);
}



































/* Returns 0 on success */
static int cackey_mutex_create(void **mutex) {
	pthread_mutex_t *pthread_mutex;
	int pthread_retval;
	CK_RV custom_retval;

................................................................................
		pthread_mutex = malloc(sizeof(*pthread_mutex));
		if (!pthread_mutex) {
			CACKEY_DEBUG_PRINTF("Failed to allocate memory.");

			return(-1);
		}

		pthread_retval = pthread_mutex_init(pthread_mutex, NULL);
		if (pthread_retval != 0) {
			CACKEY_DEBUG_PRINTF("pthread_mutex_init() returned error (%i).", pthread_retval);

			return(-1);
		}

		*mutex = pthread_mutex;
................................................................................
	CK_RV custom_retval;

	CACKEY_DEBUG_PRINTF("Called.");

	if ((cackey_args.flags & CKF_OS_LOCKING_OK) == CKF_OS_LOCKING_OK) {
		pthread_mutex = mutex;

		pthread_retval = pthread_mutex_lock(pthread_mutex);
		if (pthread_retval != 0) {
			CACKEY_DEBUG_PRINTF("pthread_mutex_lock() returned error (%i).", pthread_retval);

			return(-1);
		}
	} else {
		if (cackey_args.LockMutex) {
................................................................................
	CK_RV custom_retval;

	CACKEY_DEBUG_PRINTF("Called.");

	if ((cackey_args.flags & CKF_OS_LOCKING_OK) == CKF_OS_LOCKING_OK) {
		pthread_mutex = mutex;

		pthread_retval = pthread_mutex_unlock(pthread_mutex);
		if (pthread_retval != 0) {
			CACKEY_DEBUG_PRINTF("pthread_mutex_unlock() returned error (%i).", pthread_retval);

			return(-1);
		}
	} else {
		if (cackey_args.UnlockMutex) {
................................................................................

		if (args->CreateMutex == NULL || args->DestroyMutex == NULL || args->LockMutex == NULL || args->UnlockMutex == NULL) {
			if (args->CreateMutex != NULL || args->DestroyMutex != NULL || args->LockMutex != NULL || args->UnlockMutex != NULL) {
				CACKEY_DEBUG_PRINTF("Error. Some, but not All threading primitives provided.");

				return(CKR_ARGUMENTS_BAD);
			}








		}
	} else {
		cackey_args.CreateMutex = NULL;
		cackey_args.DestroyMutex = NULL;
		cackey_args.LockMutex = NULL;
		cackey_args.UnlockMutex = NULL;
		cackey_args.flags = 0;







>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|







 







|







 







>
>
>
>
>
>
>
>







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
....
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
....
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
....
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
....
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
....
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
#  ifdef HAVE_LIBZ
#    include <zlib.h>
#  endif
#else
#  ifdef HAVE_LIBZ
#    undef HAVE_LIBZ
#  endif
#endif
#ifndef _THREAD_EMULATION
#  ifdef HAVE_DLFCN_H
#    ifdef HAVE_DLSYM
#      include <dlfcn.h>
#      define HAVE_CACKEY_MUTEX_PTHREAD_FUNCS 1
#    endif
#  endif
#endif
#ifdef CACKEY_DEBUG_SEARCH_SPEEDTEST
#  include <sys/time.h>
#endif

#define CK_PTR *
#define CK_DEFINE_FUNCTION(returnType, name) returnType name
................................................................................
		return(-1);
	}
#  endif
#endif

	return(x509_read_ret);
}

/* Dynamically load pthreads from the running application */
#ifdef HAVE_CACKEY_MUTEX_PTHREAD_FUNCS
#warning building with pthreads opened via dlsym
struct cackey_mutex_pthread_funcs_st {
	int (*pthread_mutex_init)(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);
	int (*pthread_mutex_lock)(pthread_mutex_t *mutex);
	int (*pthread_mutex_unlock)(pthread_mutex_t *mutex);
};

static struct cackey_mutex_pthread_funcs_st *cackey_mutex_pthread_funcs(void) {
	static struct cackey_mutex_pthread_funcs_st funcs = {0};
	static int init = 0;

	if (init != 0) {
		return(&funcs);
	}

	funcs.pthread_mutex_init = dlsym(RTLD_DEFAULT, "pthread_mutex_init");
	funcs.pthread_mutex_lock = dlsym(RTLD_DEFAULT, "pthread_mutex_lock");
	funcs.pthread_mutex_unlock = dlsym(RTLD_DEFAULT, "pthread_mutex_unlock");

	init = 1;

	return(&funcs);
}
#define cackey_pthread_mutex_init cackey_mutex_pthread_funcs()->pthread_mutex_init
#define cackey_pthread_mutex_lock cackey_mutex_pthread_funcs()->pthread_mutex_lock
#define cackey_pthread_mutex_unlock cackey_mutex_pthread_funcs()->pthread_mutex_unlock
#else
#define cackey_pthread_mutex_init pthread_mutex_init
#define cackey_pthread_mutex_lock pthread_mutex_lock
#define cackey_pthread_mutex_unlock pthread_mutex_unlock
#endif

/* Returns 0 on success */
static int cackey_mutex_create(void **mutex) {
	pthread_mutex_t *pthread_mutex;
	int pthread_retval;
	CK_RV custom_retval;

................................................................................
		pthread_mutex = malloc(sizeof(*pthread_mutex));
		if (!pthread_mutex) {
			CACKEY_DEBUG_PRINTF("Failed to allocate memory.");

			return(-1);
		}

		pthread_retval = cackey_pthread_mutex_init(pthread_mutex, NULL);
		if (pthread_retval != 0) {
			CACKEY_DEBUG_PRINTF("pthread_mutex_init() returned error (%i).", pthread_retval);

			return(-1);
		}

		*mutex = pthread_mutex;
................................................................................
	CK_RV custom_retval;

	CACKEY_DEBUG_PRINTF("Called.");

	if ((cackey_args.flags & CKF_OS_LOCKING_OK) == CKF_OS_LOCKING_OK) {
		pthread_mutex = mutex;

		pthread_retval = cackey_pthread_mutex_lock(pthread_mutex);
		if (pthread_retval != 0) {
			CACKEY_DEBUG_PRINTF("pthread_mutex_lock() returned error (%i).", pthread_retval);

			return(-1);
		}
	} else {
		if (cackey_args.LockMutex) {
................................................................................
	CK_RV custom_retval;

	CACKEY_DEBUG_PRINTF("Called.");

	if ((cackey_args.flags & CKF_OS_LOCKING_OK) == CKF_OS_LOCKING_OK) {
		pthread_mutex = mutex;

		pthread_retval = cackey_pthread_mutex_unlock(pthread_mutex);
		if (pthread_retval != 0) {
			CACKEY_DEBUG_PRINTF("pthread_mutex_unlock() returned error (%i).", pthread_retval);

			return(-1);
		}
	} else {
		if (cackey_args.UnlockMutex) {
................................................................................

		if (args->CreateMutex == NULL || args->DestroyMutex == NULL || args->LockMutex == NULL || args->UnlockMutex == NULL) {
			if (args->CreateMutex != NULL || args->DestroyMutex != NULL || args->LockMutex != NULL || args->UnlockMutex != NULL) {
				CACKEY_DEBUG_PRINTF("Error. Some, but not All threading primitives provided.");

				return(CKR_ARGUMENTS_BAD);
			}
		} else {
#ifdef HAVE_CACKEY_MUTEX_PTHREAD_FUNCS
			if (cackey_mutex_pthread_funcs()->pthread_mutex_init == NULL || cackey_mutex_pthread_funcs()->pthread_mutex_lock == NULL || cackey_mutex_pthread_funcs()->pthread_mutex_unlock == NULL) {
				CACKEY_DEBUG_PRINTF("Error. Library is not linked to pthreads and we are unable to find them at runtime.");

				return(CKR_GENERAL_ERROR);
			}
#endif
		}
	} else {
		cackey_args.CreateMutex = NULL;
		cackey_args.DestroyMutex = NULL;
		cackey_args.LockMutex = NULL;
		cackey_args.UnlockMutex = NULL;
		cackey_args.flags = 0;

Modified configure.ac from [a419c60439] to [383d36814d].

77
78
79
80
81
82
83



84
85
86
87
88
89
90
])

dnl Check for PC/SC headers and libraries
DC_PCSC

dnl Check for ZLIB libraries
AC_CHECK_LIB(z, uncompress)




dnl Verify that a basic program will compile
AC_CACHE_CHECK([if basic PC/SC program works], cackey_cv_pcsc_works, [
	AC_LINK_IFELSE(
		AC_LANG_PROGRAM([[
#ifdef HAVE_WINTYPES_H
#  include <wintypes.h>







>
>
>







77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
])

dnl Check for PC/SC headers and libraries
DC_PCSC

dnl Check for ZLIB libraries
AC_CHECK_LIB(z, uncompress)

dnl Check for dl headers and functions
DC_DLFUNCS

dnl Verify that a basic program will compile
AC_CACHE_CHECK([if basic PC/SC program works], cackey_cv_pcsc_works, [
	AC_LINK_IFELSE(
		AC_LANG_PROGRAM([[
#ifdef HAVE_WINTYPES_H
#  include <wintypes.h>