forked from caml-pkcs11/caml-crush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-win32.ac
1400 lines (1318 loc) · 51.6 KB
/
configure-win32.ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
define([PACKAGE_VERSION_MAJOR], [1])
define([PACKAGE_VERSION_MINOR], [0])
define([PACKAGE_VERSION_FIX], [4])
AC_INIT(cam-crush, [PACKAGE_VERSION_MAJOR.PACKAGE_VERSION_MINOR.PACKAGE_VERSION_FIX])
AC_CONFIG_SRCDIR([src/client-lib/modwrap.c])
bindings_dir="src/bindings-pkcs11"
rpc_dir="src/rpc-pkcs11"
server_dir="src/pkcs11proxyd"
client_dir="src/client-lib"
filter_dir="src/filter"
filter_filter_dir="src/filter/filter"
filter_backend_dir="src/filter/backend"
filter_frontend_dir="src/filter/frontend"
tests_dir="src/tests"
ocaml_tests_dir="src/tests/ocaml"
c_tests_dir="src/tests/c-based"
scripts_dir="scripts"
AC_CONFIG_FILES([$bindings_dir/Makefile $bindings_dir/Makefile.standalone $rpc_dir/Makefile $server_dir/Makefile $client_dir/Makefile $filter_filter_dir/Makefile $filter_backend_dir/Makefile $filter_frontend_dir/Makefile $filter_dir/Makefile $tests_dir/Makefile $ocaml_tests_dir/Makefile $c_tests_dir/Makefile $scripts_dir/pkcs11proxyd])
AC_ARG_WITH(caml-crush, [ --without-caml-crush compile only pkcs11 bindings, (this is NOT the default)], [], with_caml_crush=yes)
AC_ARG_WITH(client-socket, [ --with-client-socket configure client socket type and path, default is tcp with 127.0.0.1 (format is --with-client-socket="unix,path" or --with-client-socket="tcp,address:port")])
AC_ARG_WITH(libname_file, [ --with-libname-file configure library to fetch libname from a disk file (default)])
AC_ARG_WITH(libnames, [ --with-libnames configure library names to be generated, comma deparated (default is the empty string). E.g: --with-libnames=foo,bar])
AC_ARG_WITH(ocamlclient, [ --with-ocamlclient use OCaml client library and RPC instead of default native C one])
AC_ARG_WITH(cclient, [ --with-cclient use C based client library and RPC (this is the default)])
AC_ARG_WITH(debuglibs, [ --with-debuglibs activate verbose debug output for the modules of the proxy that do not support it dynamically (the bindings and the client library)])
AC_ARG_WITH(rpcgen, [ --with-rpcgen force regeneration of the rpc header and code files again (this is NOT the default)])
AC_ARG_WITH(idlgen, [ --with-idlgen force regeneration of the idl header and code files again (this is NOT the default)])
AC_ARG_WITH(ssl, [ --with-ssl use SSL authentication and encryption over the transport layer (TCP or Unix socket). Use the OpenSSL library by default if --with-gnutls is not given.])
AC_ARG_WITH(gnutls, [ --with-gnutls use the gnutls library instead of the OpenSSL library for native C client RPC over ssl.)])
AC_ARG_WITH(ssl-clientfiles, [ --with-ssl-clientfiles CA and client certificate files as well as private key (in pem format) for SSL on the target. These are paths on the client if there is a prepending path, environment variables if there is a prepending env (PKCS11PROXY_SSL_CA/PKCS11PROXY_SSL_CERT/PKCS11_SSL_PRIVKEY: this is the default), or a path of files on the host to be embedded inside the client if there is a prepending embed. E.g: --with-ssl-clientfiles='path;ca=path_to_ca,cert=path_to_cert,privkey=path_to_key')], sslfiles="$withval")
AC_ARG_WITH(ssl-servercerts, [ --with-ssl-servercerts enforce the client to strictly accept authentication with specific servers that use the certificates provided either in the folder or in a file (as a concatenation of certificates)], sslservercerts="$withval")
AC_ARG_WITH(filter, [ --without-filter compile the server without the filter: all the PKCS#11 commands are passed through to the bindings.], [], with_filter=yes)
AC_ARG_WITH(aliasing, [ --with-aliasing aliasing of the sessions and objects handles. There are two aliasing modes: incremental and random (non predictable aliases): --with-aliasing=rand or --with-aliasing=inc, default is random.], aliasing="$withval")
AC_ARG_WITH(daemonize, [ --with-daemonize compile with daemonization primitives support (User can amend C_Daemonize function to provide its own privilege reduction primitives inside the server process instead of using the sandbox launcher).])
full_libdir=`eval eval eval eval eval echo "${libdir}" | sed "s#NONE#${prefix}#" | sed "s#NONE#${ac_default_prefix}#"`
# Install the library in a sub-directory
full_libdir="$full_libdir/caml-crush"
libdir=$full_libdir
# Summary helpers
AC_DEFUN(WRITE_TO_FILE,[
printf "%-40s: %s\n" $2 $3 >> $1
])
AC_DEFUN(SHOW_SUMMARY,[
cat $1 && rm -f $1
])
#Try to detect host_type and set variable
if host_type=`${srcdir}/config.guess`; then :; else
echo "Cannot guess host type"
exit 2
fi
# Remove any existing summary file
rm -f ./summary
echo "###########################################" >> ./summary
echo "### SUMMARY ###" >> ./summary
echo "###########################################" >> ./summary
##########
# CHECK Make
case $host_type in
*freebsd*)
AC_CHECK_PROG(MAKEPROG,gmake,gmake,no)
if test "$MAKEPROG" == "no"
then
AC_MSG_ERROR(Cannot find GNU gmake.)
fi
AC_SUBST(MAKEPROG,$MAKEPROG)
;;
*)
AC_CHECK_PROG(MAKEPROG,make,make,no)
if test "$MAKEPROG" == "no"
then
AC_MSG_ERROR(Cannot find GNU make.)
fi
AC_SUBST(MAKEPROG,$MAKEPROG)
;;
esac
##########
# CHECK OCaml an needed binaries
AC_DEFUN(AC_PROG_OCAML,
[dnl
# checking for ocamlc
AC_CHECK_PROG(OCAMLC,ocamlc,yes,no)
if test "$OCAMLC" == "no"
then
AC_MSG_ERROR(Cannot find ocamlc.)
fi
OCAMLVERSION=$(ocamlc -version | tr -d '\r')
AC_MSG_RESULT(OCaml version is $OCAMLVERSION)
OCAMLLIB=$(ocamlc -where | tr -d '\r')
AC_MSG_RESULT(OCaml library path is $OCAMLLIB)
# checking for ocamlopt
AC_CHECK_PROG(OCAMLOPT,ocamlopt,ocamlopt)
OCAMLBEST=byte
if test -z "$OCAMLOPT"; then
AC_MSG_WARN(Cannot find ocamlopt; bytecode compilation only.)
else
TMPVERSION=$($OCAMLOPT -version)
if test "$TMPVERSION" != "$OCAMLVERSION" ; then
AC_MSG_RESULT(versions differs from ocamlc; ocamlopt discarded.)
unset OCAMLOPT
else
OCAMLBEST=opt
fi
fi
# checking for ocamlc.opt
AC_CHECK_PROG(OCAMLCDOTOPT,ocamlc.opt,ocamlc.opt)
if test "$OCAMLCDOTOPT"; then
TMPVERSION=$($OCAMLCDOTOPT -version)
if test "$TMPVERSION" != "$OCAMLVERSION" ; then
AC_MSG_RESULT(versions differs from ocamlc; ocamlc.opt discarded.)
else
OCAMLC=$OCAMLCDOTOPT
fi
fi
# checking for ocamlopt.opt
if test "$OCAMLOPT" ; then
AC_CHECK_PROG(OCAMLOPTDOTOPT,ocamlopt.opt,ocamlopt.opt)
if test "$OCAMLOPTDOTOPT"; then
TMPVERSION=$($OCAMLOPTDOTOPT -version)
if test "$TMPVERSION" != "$OCAMLVERSION" ; then
AC_MSG_RESULT(version differs from ocamlc; ocamlopt.opt discarded.)
else
OCAMLOPT=$OCAMLOPTDOTOPT
fi
fi
fi
# checking for ocamldep
AC_CHECK_PROG(OCAMLDEP,ocamldep,ocamldep,AC_MSG_WARN(Cannot find ocamldep.))
#checking for ocamlmklib
AC_CHECK_PROG(OCAMLMKLIB,ocamlmklib,ocamlmklib, AC_MSG_WARN(Cannot find ocamlmklib.))
AC_SUBST(OCAMLC)
AC_SUBST(OCAMLOPT)
AC_SUBST(OCAMLDEP)
AC_SUBST(OCAMLBEST)
AC_SUBST(OCAMLVERSION)
AC_SUBST(OCAMLLIB)
AC_SUBST(OCAMLMKLIB)
])
# CHECK for ocamlp4 needed for
# some conditional compilation
AC_DEFUN(AC_PROG_CAMLP4,
[dnl
AC_REQUIRE([AC_PROG_OCAML])
# checking for camlp4
AC_CHECK_PROG(CAMLP4,camlp4,yes,no)
if test "$CAMLP4" == "no"; then
TMPVERSION=$($CAMLP4 -v 2>&1| sed -n -e 's|.*version *\(.*\)$|\1|p')
if test "$TMPVERSION" != "$OCAMLVERSION" ; then
AC_MSG_ERROR(versions differs from ocamlc)
else
AC_CHECK_PROG(CAMLP4O,camlp4o,camlp4o)
fi
fi
AC_SUBST(CAMLP4)
AC_SUBST(CAMLP4O)
])
# CHECK for OCaml findlib needed
# for dependency solving
AC_DEFUN(AC_PROG_FINDLIB,
[dnl
# checking for ocamlfind
AC_CHECK_PROG(OCAMLFIND,ocamlfind,ocamlfind,
AC_MSG_ERROR(ocamlfind not found))
AC_SUBST(OCAMLFIND)
])
AC_DEFUN(AC_CHECK_OCAML_PKG,
[dnl
AC_REQUIRE([AC_PROG_FINDLIB])
AC_MSG_CHECKING(OCaml package $1)
if $OCAMLFIND query $1 >/dev/null 2>/dev/null; then
AC_MSG_RESULT(found)
pkg_$2="$1"
else
AC_MSG_ERROR(not found)
unset pkg_$2
fi
])
dnl
dnl
dnl
dnl AC_ARG_OCAML_INSTALLDIR adds a --with-installdir option
AC_DEFUN(AC_ARG_OCAML_INSTALLDIR,
[dnl
AC_ARG_WITH(installdir,[ --with-installdir=DIR specify installation directory],INSTALLDIR="$withval")
if ! test "$INSTALLDIR" -o "$use_findlib" ; then
INSTALLDIR='$(OCAMLLIB)/$(NAME)'
fi
AC_SUBST(INSTALLDIR)
])
dnl
dnl
dnl
dnl AC_CHECK_OCAML_MODULE looks for a module in a given path
dnl 1 -> name (for printing)
dnl 2 -> env var name
dnl 3 -> module to check
dnl 4 -> default dirs
AC_DEFUN(AC_CHECK_OCAML_MODULE,
[dnl
AC_MSG_CHECKING($1 directory)
cat > conftest.ml <<EOF
open $3
EOF
unset found
for $2 in $$2 $4 ; do
if $OCAMLC -c -I "$$2" conftest.ml > /dev/null 2>&1 ; then
found=yes
break
fi
done
if test "$found" ; then
AC_MSG_RESULT($$2)
else
AC_MSG_RESULT(not found)
unset $2
fi
AC_SUBST($2)])
#***********************#
AC_PROG_OCAML
##########
# CHECK PLATFORM
AC_CHECK_HEADERS([windows.h],,AC_MSG_ERROR(Could not find Windows headers.))
##########
# CHECK HEADERS
# OCAML
export CFLAGS="$CFLAGS -I$OCAMLLIB"
export CPPFLAGS="$CPPFLAGS -I$OCAMLLIB"
AC_CHECK_HEADERS([caml/mlvalues.h],,AC_MSG_ERROR(Could not find OCaml headers.))
# OCAML IDL
AC_CHECK_HEADERS([caml/camlidlruntime.h],,AC_MSG_ERROR(Could not find OCaml IDL headers.))
# Dynamic linker
case $host_type in
*cygwin*)
AC_CHECK_HEADERS([fcntl.h],,AC_MSG_ERROR(Could not find fcntl headers.))
;;
*)
AC_CHECK_HEADERS([dlfcn.h],,AC_MSG_ERROR(Could not find dlfcn headers.))
;;
esac
# pthread
AC_CHECK_HEADERS([pthread.h],,AC_MSG_ERROR(Could not find pthread headers.))
AC_PROG_CAMLP4
AC_PROG_FINDLIB
if test "$with_caml_crush" == "yes" #--without-caml-crush was not set
then
case $host_type in
*cygwin*)
;;
*)
# CHECK for ocamlnet RPC
AC_CHECK_OCAML_PKG([rpc], rpc)
# CHECK for ocaml str regexp package
AC_CHECK_OCAML_PKG([str], str)
# CHECK for the config-file package
AC_CHECK_OCAML_PKG([config-file], configfile)
;;
esac
# CHECK for the camlidl library
fi
AC_CHECK_OCAML_PKG([camlidl], camlidl)
##########
# CHECK LIBS for basic linking
# CHECK for dl
case $host_type in
*freebsd*)
AC_MSG_NOTICE(System is FreeBSD skip libdl check)
;;
*cygwin*)
AC_MSG_NOTICE(System is Cygwin skip libdl check)
;;
*)
AC_CHECK_LIB(dl, dlopen, DL_LIB="-ldl",
AC_MSG_ERROR(Cannot find dl library.))
;;
esac
# CHECK pthread
AC_CHECK_LIB(pthread, pthread_mutex_init, THREAD_LIB="-lpthread",
AC_MSG_ERROR(Cannot find pthread library.))
# IDL generation handling
####
# CHECK for the camlidl program,
# only needed if we need to generate the idl files again
if test "$with_idlgen" != ""
then
AC_CHECK_PROG(CAMLIDL,camlidl,yes,no)
if test "$CAMLIDL" == "no"
then
AC_MSG_ERROR(Cannot find camlidl: needed for PKCS11 bindings generation.)
fi
AC_SUBST(idl_gen, "idl")
WRITE_TO_FILE(summary, "IDL gen", "YES")
else
WRITE_TO_FILE(summary, "IDL gen", "NO")
fi
# DEBUG MODE HANDLING
if test "$with_debuglibs" != ""
then
AC_MSG_NOTICE([Using debug mode libs])
AC_SUBST(debug_mode, "debug")
WRITE_TO_FILE(summary, "debug libs", "YES")
else
AC_SUBST(debug_mode, "")
WRITE_TO_FILE(summary, "debug libs", "NO")
fi
if test "$with_caml_crush" == "yes" #--without-caml-crush was not set
then
############# OCAML RELATED CHECKS #########
# CHECK if OCaml runtime was build with
# -fPIC: if yes, build the ocaml client
# against the local lib. If no, fail
# and advise user to either use the C client
# or to rebuild the OCaml binaries.
if test "$with_ocamlclient" != ""
then
AC_MSG_CHECKING(OCaml support for fPIC)
# Try to compile a sample program
ML_TEST_FILE="mltest"
ML=".ml"
CMI=".cmi"
CMX=".cmx"
OBJ=".o"
cat <<EOM >$ML_TEST_FILE$ML
let _ = Printf.printf "Testing -fPIC\n"
EOM
$OCAMLOPT -output-obj -o a.so $ML_TEST_FILE$ML 2> ocamlopt.log
OCAMLOPT_ERR=`cat ocamlopt.log | grep -i error`
if test "$OCAMLOPT_ERR" != ""
then
rm -f $ML_TEST_FILE$CMI $ML_TEST_FILE$CMX $ML_TEST_FILE$OBJ $ML_TEST_FILE$ML a.so ocamlopt.log
AC_MSG_RESULT(no)
AC_MSG_WARN(OCaml is not compiled with fPIC support either use --with-cclient or recompile the OCaml suite)
AC_MSG_ERROR(OCaml client cannot be compiled. Read the documentation for more details.)
else
AC_MSG_RESULT(yes)
fi
rm -f $ML_TEST_FILE$CMI $ML_TEST_FILE$CMX $ML_TEST_FILE$OBJ $ML_TEST_FILE$ML a.so ocamlopt.log
fi
########## INTERNAL OPTIONS ###########
#########
# RPC TYPE HANDLING
summary=""
if test "$with_ocamlclient" != ""
then
if test "$with_cclient" != ""
then
AC_MSG_ERROR([--with-ocamlclient and --with-cclient are NOT compatible!])
fi
WRITE_TO_FILE(summary, "client type", "OCaml based client (OCamlnet RPC)")
AC_MSG_NOTICE([Using OCaml based client and RPC instead of native C client])
AC_SUBST(client_to_compile, "camlrpc")
AC_SUBST(client_to_compile_debug, "camlrpc_debug")
else
WRITE_TO_FILE(summary, "client type", "Native C client (RPC generated with native rpcgen)")
AC_MSG_NOTICE([Using default C based client and RPC])
AC_MSG_NOTICE([Should fix configure to look for Win32 RPC headers])
#AC_CHECK_HEADERS([rpc/rpc.h],,AC_MSG_ERROR(Could not find C RPC headers.))
#AC_CHECK_HEADERS([rpc/clnt.h],,AC_MSG_ERROR(Could not find C RPC client headers.))
AC_SUBST(client_to_compile, "crpc")
AC_SUBST(client_to_compile_debug, "crpc_debug")
fi
# LIBNAME HANDLING
if test -n "${with_libnames+x}" && test -n "${with_libname_file+x}"
then
AC_MSG_ERROR([--with-libname-file incompatible --with-libnames!, choose one])
fi
#default no choice
if test -z "${with_libnames+x}" && test -z "${with_libname_file+x}"
then
AC_MSG_NOTICE([Client library configured to read libname from a file])
AC_SUBST(lib_names, "\"\"")
AC_SUBST(libname_file, "-DLIBNAME_FILE")
WRITE_TO_FILE(summary, "client lib", "Using .camlcrushlibname file")
fi
#using builtin
if test -n "${with_libnames+x}"
then
libraries=$(echo $with_libnames | sed 's/\([[^,]]*\)/\"\1\"/g' | tr ',' ' ')
AC_MSG_NOTICE([Client libraries configured for $libraries])
AC_SUBST(lib_names, $libraries)
WRITE_TO_FILE(summary, "client libs", "$libraries")
fi
#using disk file
if test -n "${with_libname_file+x}"
then
AC_MSG_NOTICE([Client library configured to read libname from a file])
AC_SUBST(lib_names, "\"\"")
AC_SUBST(libname_file, "-DLIBNAME_FILE")
WRITE_TO_FILE(summary, "client lib", "Using .camlcrushlibname file")
fi
# SOCKET HANDLING
unix="UNIX_SOCKET"
tcp="TCP_SOCKET"
if test "$with_client_socket" != ""
then
socket_type=$(echo $with_client_socket | sed 's/\(.*\),.*/\1/g')
case $socket_type in
unix)
AC_MSG_ERROR(UNIX socket unsupported on Win32 platforms)
;;
tcp)
tcp_host=$(echo $with_client_socket | sed 's/tcp,\(.*\)/\1/g')
AC_MSG_NOTICE([Client library configured to use Tcp socket with host $tcp_path])
AC_SUBST(socket_path, $tcp_host)
AC_SUBST(socket_type, $tcp)
WRITE_TO_FILE(summary, "client socket", "tcp -> $tcp_host")
;;
*)
AC_MSG_ERROR(Unsupported socket type)
;;
esac
else
tcp_path="127.0.0.1:4444"
AC_MSG_NOTICE([Client library configured to use default: Tcp socket with host $tcp_path])
AC_SUBST(socket_path, $tcp_path)
AC_SUBST(socket_type, $tcp)
WRITE_TO_FILE(summary, "client socket", "tcp -> $tcp_path (DEFAULT)")
fi
#########
# RPC library support checks
if test "$with_ocamlclient" == ""
then
#socket_type now contains UNIX_SOCKET/TCP_SOCKET
case $socket_type in
UNIX_SOCKET)
AC_MSG_ERROR(UNIX socket unsupported on Win32 platforms)
;;
TCP_SOCKET)
AC_MSG_NOTICE([Should fix configure to look for Win32 RPC library])
# Check the library against RPC tcp client creation
#AC_CHECK_LIB(c, clnttcp_create, ,
#AC_MSG_ERROR(Cannot find RPC clnttcp_create symbol in C library.))
;;
*)
AC_MSG_ERROR(We should not end up in this test.)
;;
esac
fi
# RPC generation handling
####
# CHECK for the rpcgen programs
if test "$with_rpcgen" != ""
then
AC_MSG_NOTICE([OCaml RPC generation forced for server side ...])
AC_CHECK_PROG(OCAMLRPCGEN,ocamlrpcgen,yes,no)
if test "$OCAMLRPCGEN" == "no"
then
AC_MSG_ERROR(Cannot find ocamlrpcgen: needed for RPC server generation.)
fi
AC_SUBST(caml_rpc_gen, rpc)
# rpcgen is only needed if we generate native C client RPC
if test "$with_ocamlclient" == ""
then
AC_MSG_NOTICE([Native C RPC generation for client side ...])
AC_CHECK_PROG(RPCGEN,rpcgen,yes,no)
if test "$RPCGEN" == "no"
then
AC_MSG_ERROR(Cannot find rpcgen: needed for native C client library RPC generation.)
fi
RPCGENVERSION=$(rpcgen --version)
AC_MSG_RESULT(rpcgen found, version is $RPCGENVERSION)
AC_SUBST(c_rpc_gen, "rpc")
#Linux C_RPC can be patched to avoid unused buffer
case $host_type in
*linux*)
AC_SUBST(linux_c_rpc_patch, "linux_c_rpc_patch")
;;
*)
AC_SUBST(linux_c_rpc_patch, "")
;;
esac
else
AC_MSG_NOTICE([OCaml RPC generation forced for client side ...])
AC_SUBST(c_rpc_gen,"")
fi
WRITE_TO_FILE(summary, "RPC gen", "YES")
else
AC_SUBST(caml_rpc_gen,"")
WRITE_TO_FILE(summary, "RPC gen", "NO")
fi
# FIXME: Need to check rpcgen support for MT
AC_SUBST(rpc_mt_define, "-DRPCGEN_MT")
AC_SUBST(caml_rpc_clean, pkcs11_rpc_*)
AC_SUBST(c_rpc_clean, "pkcs11_rpc.h pkcs11_rpc_xdr.c pkcs11_rpc_svc.c pkcs11_rpc_clnt.c")
# SSL/GnuTLS handling
if test "$with_ssl" != ""
then
WRITE_TO_FILE(summary, "SSL", "YES (on the server and client side)")
if test "$with_ssl_clientfiles" == ""
then
AC_MSG_ERROR([--with-ssl needs --with-ssl-clientfiles!])
fi
AC_MSG_NOTICE([Using OCaml RPC over ssl for server side ...])
# We need the ssl and rpc-ssl package for RPC over ssl support
AC_CHECK_OCAML_PKG([ssl], ssl)
AC_CHECK_OCAML_PKG([rpc-ssl], rpcssl)
# Position the ssl define and linking for the server
AC_SUBST(caml_server_ssl_define, "-DWITH_SSL")
AC_SUBST(caml_server_ssl_package, "-package \"ssl\" -package \"rpc-ssl\"")
if test "$with_ocamlclient" == ""
then
if test "$with_gnutls" != ""
then
WRITE_TO_FILE(summary, " -SSL client lib", "GnuTLS")
AC_MSG_NOTICE([Using native C RPC over ssl (gnu-tls) for client side ...])
# If we compile the native C client, and if the gnu-tls
# library is configured, we check it
# Check the headers
AC_CHECK_HEADERS([gnutls/gnutls.h],,AC_MSG_ERROR(Could not find gnutls headers.))
# Check the library against all the symbols we use
AC_CHECK_LIB(gnutls, gnutls_record_recv, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_record_send, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_global_init, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_init, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_perror, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_priority_set_direct, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_credentials_set, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_transport_set_ptr, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_handshake, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_certificate_get_peers, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_certificate_verify_peers2, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_strerror, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_bye, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_deinit, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_certificate_free_credentials, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_global_deinit, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_certificate_set_x509_trust_mem, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_CHECK_LIB(gnutls, gnutls_certificate_set_x509_key_mem, GNUTLS_LIB="-lgnutls",
AC_MSG_ERROR(Cannot find symbol in gnutls library.))
AC_SUBST(c_ssl_package, "-lgnutls")
AC_SUBST(c_gnutls_define, "-DGNU_TLS")
else
WRITE_TO_FILE(summary, " -SSL client lib", "OpenSSL")
AC_MSG_NOTICE([Using native C RPC over ssl (OpenSSL) for client side ...])
# If we compile the native C client, we need
# the openssl library bu default
# Check the headers
AC_CHECK_HEADERS([openssl/ssl.h],,AC_MSG_ERROR(Could not find openssl headers.))
# Check the library
AC_CHECK_LIB(ssl, SSL_read, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_write, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_load_error_strings, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_library_init, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_CTX_new, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
#AC_CHECK_LIB(ssl, SSL_CTX_set_options, OPENSSL_LIB="-lssl",
# AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_CTX_load_verify_locations, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_CTX_use_certificate_file, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_CTX_use_PrivateKey_file, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_CTX_check_private_key, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_new, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_set_fd, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_connect, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_get_peer_certificate, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_get_verify_result, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_shutdown, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_free, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_CTX_free, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_CTX_get_cert_store, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_CTX_use_certificate, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, SSL_CTX_use_RSAPrivateKey, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
# Following symbols might use the libcrypto
AC_SEARCH_LIBS([BIO_new_mem_buf], [ssl crypto], [],
AC_MSG_ERROR(Cannot find SSL symbol in libraries.))
AC_CHECK_LIB(ssl, PEM_read_bio_X509, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, PEM_read_bio_RSAPrivateKey, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_CHECK_LIB(ssl, X509_STORE_add_cert, OPENSSL_LIB="-lssl",
AC_MSG_ERROR(Cannot find symbol in openssl library.))
AC_SUBST(c_ssl_package, "-lssl")
AC_SUBST(c_gnutls_define, "")
fi
AC_SUBST(c_ssl_define, "-DWITH_SSL")
AC_SUBST(caml_client_ssl_define, "")
else
if test "$with_gnutls" != ""
then
AC_MSG_ERROR([--with-ocamlclient and --with-gnutls are NOT compatible!])
fi
WRITE_TO_FILE(summary, " -SSL client lib", "OpenSSL (OCaml bindings)")
AC_MSG_NOTICE([Using OCaml RPC over ssl for client side ...])
AC_SUBST(c_ssl_package, "")
AC_SUBST(c_gnutls_define, "")
AC_SUBST(c_ssl_define, "")
AC_SUBST(caml_client_ssl_define, "-DWITH_SSL")
AC_SUBST(caml_client_ssl_package, "-package \"ssl\" -package \"rpc-ssl\"")
fi
else
if test "$with_gnutls" != ""
then
AC_MSG_ERROR([--with-gnutls needs --with-ssl!])
fi
AC_SUBST(caml_client_ssl_package, "")
AC_SUBST(c_ssl_package, "")
AC_SUBST(c_gnutls_define, "")
AC_SUBST(c_ssl_define, "")
AC_SUBST(caml_client_ssl_define, "")
AC_SUBST(caml_client_ssl_package, "")
WRITE_TO_FILE(summary, "SSL", "NO (neither on the server nor on the client side)")
fi
###################################################################
###################################################################
###################################################################
###################################################################
# HANDLE SSL files
# Macro to create the ssl headers, for C and ML clients, from the
# given files $1 is the file path, $2 is the file type ("ca", "cert",
# "priv" for private key, "server" for the allowed servers certificates)
AC_DEFUN(CREATE_SSL_HEADERS,[
C_FILE="./create_ssl_files.c"
FILE="./create_ssl_files"
rm -f $C_FILE $FILE
cat <<EOM >$C_FILE
#include <stdio.h>
#include <stdlib.h>
#define OUT_C 0
#define OUT_ML 1
#define OUT_UNK 2
unsigned char output_type = OUT_UNK;
size_t mygetline(char **lineptr, size_t *n, FILE *stream) {
char *bufptr = NULL;
char *p = bufptr;
size_t size;
int c;
if (lineptr == NULL) {
return -1;
}
if (stream == NULL) {
return -1;
}
if (n == NULL) {
return -1;
}
bufptr = *lineptr;
size = *n;
c = fgetc(stream);
if (c == EOF) {
return -1;
}
if (bufptr == NULL) {
bufptr = malloc(128);
if (bufptr == NULL) {
return -1;
}
size = 128;
}
p = bufptr;
while(c != EOF) {
if ((p - bufptr) > (size - 1)) {
size = size + 128;
bufptr = realloc(bufptr, size);
if (bufptr == NULL) {
return -1;
}
}
*p++ = c;
if (c == '\n') {
break;
}
c = fgetc(stream);
}
*p++ = '\0';
*lineptr = bufptr;
*n = size;
return p - bufptr - 1;
}
int write_line(FILE* fp, char* line, size_t lsize){
int i;
size_t end;
/* Check if we have a \n or \r\n at the end of the line */
if(lsize >= 2){
if(line[[lsize-2]] == '\r'){
end = lsize - 2;
}
else{
end = lsize-1;
}
}
else{
end = lsize-1;
}
for(i=0; i<end; i++){
if((line[[i]] < 0x20) || (line[[i]] > 0x7E)){
printf("Error: non ASCII character in PEM file!\n");
return -1;
}
else{
fprintf(fp, "%c", line[[i]]);
}
}
fprintf(fp, "\\\n");
return 1;
}
int main(int argc, char* argv[[]]){
if(argc != 4){
printf("Error: expected three arguments ...\n");
return -1;
}
if(strcmp("C", argv[[3]]) == 0){
output_type = OUT_C;
}
else if(strcmp("ML", argv[[3]]) == 0){
output_type = OUT_ML;
}
else{
printf("Error: argument %s is not known (should be \"C\" or \"ML\")\n", argv[[3]]);
return -1;
}
/* Open the input file given as arg1 */
FILE *f = fopen(argv[[1]], "r");
if(f == NULL){
printf("Error: can't open file %s for reading\n", argv[[1]]);
return -1;
}
/* Read the first line and check it depending on the type */
char *line = NULL;
size_t len = 0;
int lsize = mygetline(&line, &len, f);
/* --------------- */
/* --------------- */
if(strcmp(argv[[2]], "cert") == 0){
FILE *certf;
if(output_type == OUT_C){
certf = fopen("src/client-lib/cert_file.h", "w");
}
else{
certf = fopen("src/client-lib/cert_file.inc", "w");
}
if(certf == NULL){
printf("Error: can't open cert header for writing\n");
return -1;
}
if((strcmp(line, "-----BEGIN CERTIFICATE-----\n") != 0) && (strcmp(line, "-----BEGIN CERTIFICATE-----\r\n") != 0)){
printf("Error: file %s doesn't seem to be a PEM certificate!\n", argv[[1]]);
return -1;
}
/* OK: we have a PEM certificate, copy everything until we reach the end */
int num_lines = 0;
if(output_type == OUT_C){
fprintf(certf, "/* Override the ISO C89 max string length by locally removing warnings */\n");
fprintf(certf, "#ifdef __GNUC__\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Woverlength-strings\"\n#endif\n");
fprintf(certf, "const char cert_file_buff[[]] = \"");
}
else{
fprintf(certf, "let cert_file_buff = \"");
}
while((strcmp(line, "-----END CERTIFICATE-----\n") != 0) && (strcmp(line, "-----END CERTIFICATE-----\r\n") != 0)){
if(write_line(certf, line, lsize) != 1){
return -1;
}
lsize = mygetline(&line, &len, f);
num_lines++;
}
if(write_line(certf, line, lsize) != 1){
return -1;
}
if(output_type == OUT_C){
fprintf(certf, "\";\\n\\n");
fprintf(certf, "#ifdef __GNUC__\n#pragma GCC diagnostic pop\n#endif\n");
}
else{
fprintf(certf, "\"\\n\\n");
}
fclose(certf);
fclose(f);
}
/* --------------- */
/* --------------- */
else if(strcmp(argv[[2]], "ca") == 0){
FILE *caf;
if(output_type == OUT_C){
caf = fopen("src/client-lib/ca_file.h", "w");
}
else{
caf = fopen("src/client-lib/ca_file.inc", "w");
}
if(caf == NULL){
printf("Error: can't open ca header for writing\n");
return -1;
}
int num_certs = 0;
int num_lines = 0;
/* We might have to get more certificates*/
if((strcmp(line, "-----BEGIN CERTIFICATE-----\n") != 0) && (strcmp(line, "-----BEGIN CERTIFICATE-----\r\n") != 0)){
printf("Error: file %s doesn't seem to be a PEM certificate!\n", argv[[1]]);
return -1;
}
GET_NEW_CA_CERT:
num_certs++;
/* OK: we have a PEM certificate, copy everything until we reach the end */
if(output_type == OUT_C){
fprintf(caf, "/* Override the ISO C89 max string length by locally removing warnings */\n");
fprintf(caf, "#ifdef __GNUC__\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Woverlength-strings\"\n#endif\n");
fprintf(caf, "const char ca_file_buff%d[[]] = \"", num_certs-1);
}
else{
fprintf(caf, "let ca_file_buff%d = \"", num_certs-1);
}
while((strcmp(line, "-----END CERTIFICATE-----\n") != 0) && (strcmp(line, "-----END CERTIFICATE-----\r\n") != 0)){
if(write_line(caf, line, lsize) != 1){
return -1;
}
lsize = mygetline(&line, &len, f);
num_lines++;
}
if(write_line(caf, line, lsize) != 1){
return -1;
}
if(output_type == OUT_C){
fprintf(caf, "\";\\n\\n");
fprintf(caf, "#ifdef __GNUC__\n#pragma GCC diagnostic pop\n#endif\n");
}
else{
fprintf(caf, "\"\\n\\n");
}
lsize = mygetline(&line, &len, f);
if((strcmp(line, "-----BEGIN CERTIFICATE-----\n") == 0) || (strcmp(line, "-----BEGIN CERTIFICATE-----\r\n") == 0)){
goto GET_NEW_CA_CERT;
}
/* We ve got all the certificates */
if(output_type == OUT_C){
fprintf(caf, "const char* ca_file_buff[[]] = {");
unsigned int i;
for(i=0; i < num_certs-1; i++){
fprintf(caf, "ca_file_buff%d, ", i);
}
fprintf(caf, "ca_file_buff%d};\n\n", num_certs-1);
fprintf(caf, "#define CA_CERTS_NB %d\n", num_certs);
}
else{
fprintf(caf, "let ca_file_buff = [[");
unsigned int i;
for(i=0; i < num_certs-1; i++){
fprintf(caf, "ca_file_buff%d; ", i);
}
fprintf(caf, "ca_file_buff%d]]\n\n", num_certs-1);
}
fclose(caf);
fclose(f);
}
/* --------------- */
/* --------------- */
else if(strcmp(argv[[2]], "privkey") == 0){
FILE *privkeyf;
if(output_type == OUT_C){
privkeyf = fopen("src/client-lib/private_key_file.h", "w");
}
else{
privkeyf = fopen("src/client-lib/private_key_file.inc", "w");
}
if(privkeyf == NULL){
printf("Error: can't open private key header for writing\n");
return -1;
}
if((strcmp(line, "-----BEGIN RSA PRIVATE KEY-----\n") != 0) && (strcmp(line, "-----BEGIN RSA PRIVATE KEY-----\r\n") != 0)){
printf("Error: file %s doesn't seem to be a PEM certificate!\n", argv[[1]]);
return -1;
}
/* OK: we have a PEM certificate, copy everything until we reach the end */
int num_lines = 0;
if(output_type == OUT_C){
fprintf(privkeyf, "/* Override the ISO C89 max string length by locally removing warnings */\n");
fprintf(privkeyf, "#ifdef __GNUC__\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Woverlength-strings\"\n#endif\n");
fprintf(privkeyf, "const char private_key_file_buff[[]] = \"");
}
else{
fprintf(privkeyf, "let private_key_file_buff = \"");
}
while((strcmp(line, "-----END RSA PRIVATE KEY-----\n") != 0) && (strcmp(line, "-----END RSA PRIVATE KEY-----\r\n") != 0)){
if(write_line(privkeyf, line, lsize) != 1){
return -1;
}
lsize = mygetline(&line, &len, f);
num_lines++;
}
if(write_line(privkeyf, line, lsize) != 1){
return -1;
}
if(output_type == OUT_C){
fprintf(privkeyf, "\";\\n\\n");
fprintf(privkeyf, "#ifdef __GNUC__\n#pragma GCC diagnostic pop\n#endif\n");
}
else{
fprintf(privkeyf, "\"\\n\\n");
}
fclose(privkeyf);
fclose(f);
}
/* --------------- */
/* --------------- */
else if(strcmp(argv[[2]], "server") == 0){
FILE *serverf;
if(output_type == OUT_C){
serverf = fopen("src/client-lib/server_file.h", "w");
}
else{
serverf = fopen("src/client-lib/server_file.inc", "w");
}
if(serverf == NULL){
printf("Error: can't open server header for writing\n");
return -1;
}
int num_certs = 0;
int num_lines = 0;
/* We might have to get more certificates*/
if((strcmp(line, "-----BEGIN CERTIFICATE-----\n") != 0) && (strcmp(line, "-----BEGIN CERTIFICATE-----\r\n") != 0)){
printf("Error: file %s doesn't seem to be a PEM certificate!\n", argv[[1]]);
return -1;
}
GET_NEW_SERVER_CERT:
num_certs++;