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 
28 #include <dlfcn.h>
29 #include <openssl/opensslv.h>
30 #include <openssl/crypto.h>
31 
32 #include <string.h>
33 #include <descrip.h>
34 #include <libclidef.h>
35 #include <stsdef.h>
36 #include <errno.h>
37 
38 unsigned long LIB$SET_SYMBOL(
39   const struct dsc$descriptor_s * symbol,
40   const struct dsc$descriptor_s * value,
41   const unsigned long *table_type);
42 
main(int argc,char ** argv)43 int main(int argc, char **argv)
44 {
45   void *libptr;
46   const char * (*ssl_version)(int t);
47   const char *version;
48 
49   if(argc < 1) {
50     puts("report_openssl_version filename");
51     exit(1);
52   }
53 
54   libptr = dlopen(argv[1], 0);
55 
56   ssl_version = (const char * (*)(int))dlsym(libptr, "SSLeay_version");
57   if(!ssl_version) {
58     ssl_version = (const char * (*)(int))dlsym(libptr, "ssleay_version");
59     if(!ssl_version) {
60       ssl_version = (const char * (*)(int))dlsym(libptr, "SSLEAY_VERSION");
61     }
62   }
63 
64   dlclose(libptr);
65 
66   if(!ssl_version) {
67     puts("Unable to lookup version of OpenSSL");
68     exit(1);
69   }
70 
71   version = ssl_version(SSLEAY_VERSION);
72 
73   puts(version);
74 
75   /* Was a symbol argument given? */
76   if(argc > 1) {
77     int status;
78     struct dsc$descriptor_s symbol_dsc;
79     struct dsc$descriptor_s value_dsc;
80     const unsigned long table_type = LIB$K_CLI_LOCAL_SYM;
81 
82     symbol_dsc.dsc$a_pointer = argv[2];
83     symbol_dsc.dsc$w_length = strlen(argv[2]);
84     symbol_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
85     symbol_dsc.dsc$b_class = DSC$K_CLASS_S;
86 
87     value_dsc.dsc$a_pointer = (char *)version; /* Cast ok */
88     value_dsc.dsc$w_length = strlen(version);
89     value_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
90     value_dsc.dsc$b_class = DSC$K_CLASS_S;
91 
92     status = LIB$SET_SYMBOL(&symbol_dsc, &value_dsc, &table_type);
93     if(!$VMS_STATUS_SUCCESS(status)) {
94       exit(status);
95     }
96   }
97 
98   exit(0);
99 }
100