2
0

report_openssl_version.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* File: report_openssl_version.c
  2. *
  3. * This file dynamically loads the OpenSSL shared image to report the
  4. * version string.
  5. *
  6. * It will optionally place that version string in a DCL symbol.
  7. *
  8. * Usage: report_openssl_version <shared_image> [<dcl_symbol>]
  9. *
  10. * Copyright (C) John Malmberg
  11. *
  12. * Permission to use, copy, modify, and/or distribute this software for any
  13. * purpose with or without fee is hereby granted, provided that the above
  14. * copyright notice and this permission notice appear in all copies.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  17. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  19. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  20. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  21. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  22. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  23. *
  24. * SPDX-License-Identifier: ISC
  25. *
  26. */
  27. #include <dlfcn.h>
  28. #include <openssl/opensslv.h>
  29. #include <openssl/crypto.h>
  30. #include <string.h>
  31. #include <descrip.h>
  32. #include <libclidef.h>
  33. #include <stsdef.h>
  34. #include <errno.h>
  35. unsigned long LIB$SET_SYMBOL(
  36. const struct dsc$descriptor_s * symbol,
  37. const struct dsc$descriptor_s * value,
  38. const unsigned long * table_type);
  39. int main(int argc, char ** argv) {
  40. void * libptr;
  41. const char * (*ssl_version)(int t);
  42. const char * version;
  43. if(argc < 1) {
  44. puts("report_openssl_version filename");
  45. exit(1);
  46. }
  47. libptr = dlopen(argv[1], 0);
  48. ssl_version = (const char * (*)(int))dlsym(libptr, "SSLeay_version");
  49. if(ssl_version == NULL) {
  50. ssl_version = (const char * (*)(int))dlsym(libptr, "ssleay_version");
  51. if(ssl_version == NULL) {
  52. ssl_version = (const char * (*)(int))dlsym(libptr, "SSLEAY_VERSION");
  53. }
  54. }
  55. dlclose(libptr);
  56. if(ssl_version == NULL) {
  57. puts("Unable to lookup version of OpenSSL");
  58. exit(1);
  59. }
  60. version = ssl_version(SSLEAY_VERSION);
  61. puts(version);
  62. /* Was a symbol argument given? */
  63. if(argc > 1) {
  64. int status;
  65. struct dsc$descriptor_s symbol_dsc;
  66. struct dsc$descriptor_s value_dsc;
  67. const unsigned long table_type = LIB$K_CLI_LOCAL_SYM;
  68. symbol_dsc.dsc$a_pointer = argv[2];
  69. symbol_dsc.dsc$w_length = strlen(argv[2]);
  70. symbol_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
  71. symbol_dsc.dsc$b_class = DSC$K_CLASS_S;
  72. value_dsc.dsc$a_pointer = (char *)version; /* Cast ok */
  73. value_dsc.dsc$w_length = strlen(version);
  74. value_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
  75. value_dsc.dsc$b_class = DSC$K_CLASS_S;
  76. status = LIB$SET_SYMBOL(&symbol_dsc, &value_dsc, &table_type);
  77. if(!$VMS_STATUS_SUCCESS(status)) {
  78. exit(status);
  79. }
  80. }
  81. exit(0);
  82. }