report_openssl_version.c 2.9 KB

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