]>
Commit | Line | Data |
---|---|---|
7e1b7485 RS |
1 | /* |
2 | * Written by sms and contributed to the OpenSSL project. | |
3 | */ | |
4 | /* ==================================================================== | |
5 | * Copyright (c) 2010 The OpenSSL Project. All rights reserved. | |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | |
10 | * | |
11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | |
15 | * notice, this list of conditions and the following disclaimer in | |
16 | * the documentation and/or other materials provided with the | |
17 | * distribution. | |
18 | * | |
19 | * 3. All advertising materials mentioning features or use of this | |
20 | * software must display the following acknowledgment: | |
21 | * "This product includes software developed by the OpenSSL Project | |
22 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | |
23 | * | |
24 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | |
25 | * endorse or promote products derived from this software without | |
26 | * prior written permission. For written permission, please contact | |
27 | * licensing@OpenSSL.org. | |
28 | * | |
29 | * 5. Products derived from this software may not be called "OpenSSL" | |
30 | * nor may "OpenSSL" appear in their names without prior written | |
31 | * permission of the OpenSSL Project. | |
32 | * | |
33 | * 6. Redistributions of any form whatsoever must retain the following | |
34 | * acknowledgment: | |
35 | * "This product includes software developed by the OpenSSL Project | |
36 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | |
37 | * | |
38 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | |
39 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
40 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
41 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | |
42 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
44 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
45 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
46 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
47 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
48 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
49 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
50 | * ==================================================================== | |
51 | */ | |
52 | ||
537c9823 RL |
53 | #if defined( __VMS) && !defined( OPENSSL_NO_DECC_INIT) && \ |
54 | defined( __DECC) && !defined( __VAX) && (__CRTL_VER >= 70301000) | |
55 | # define USE_DECC_INIT 1 | |
56 | #endif | |
57 | ||
58 | #ifdef USE_DECC_INIT | |
59 | ||
7e1b7485 RS |
60 | /* |
61 | * ---------------------------------------------------------------------- | |
62 | * decc_init() On non-VAX systems, uses LIB$INITIALIZE to set a collection | |
63 | * of C RTL features without using the DECC$* logical name method. | |
64 | * ---------------------------------------------------------------------- | |
537c9823 RL |
65 | */ |
66 | ||
0f113f3e MC |
67 | # include <stdio.h> |
68 | # include <stdlib.h> | |
69 | # include <unixlib.h> | |
537c9823 RL |
70 | |
71 | /* Global storage. */ | |
72 | ||
73 | /* Flag to sense if decc_init() was called. */ | |
74 | ||
75 | int decc_init_done = -1; | |
76 | ||
537c9823 RL |
77 | /* Structure to hold a DECC$* feature name and its desired value. */ |
78 | ||
0f113f3e | 79 | typedef struct { |
537c9823 RL |
80 | char *name; |
81 | int value; | |
82 | } decc_feat_t; | |
83 | ||
0f113f3e MC |
84 | /* |
85 | * Array of DECC$* feature names and their desired values. Note: | |
86 | * DECC$ARGV_PARSE_STYLE is the urgent one. | |
537c9823 RL |
87 | */ |
88 | ||
0f113f3e MC |
89 | decc_feat_t decc_feat_array[] = { |
90 | /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */ | |
91 | {"DECC$ARGV_PARSE_STYLE", 1}, | |
537c9823 | 92 | |
0f113f3e MC |
93 | /* Preserve case for file names on ODS5 disks. */ |
94 | {"DECC$EFS_CASE_PRESERVE", 1}, | |
537c9823 | 95 | |
0f113f3e MC |
96 | /* |
97 | * Enable multiple dots (and most characters) in ODS5 file names, while | |
98 | * preserving VMS-ness of ";version". | |
99 | */ | |
100 | {"DECC$EFS_CHARSET", 1}, | |
537c9823 | 101 | |
0f113f3e MC |
102 | /* List terminator. */ |
103 | {(char *)NULL, 0} | |
537c9823 RL |
104 | }; |
105 | ||
7e1b7485 RS |
106 | char **copy_argv(int *argc, char *argv[]) |
107 | { | |
108 | /*- | |
109 | * The note below is for historical purpose. On VMS now we always | |
110 | * copy argv "safely." | |
111 | * | |
112 | * 2011-03-22 SMS. | |
113 | * If we have 32-bit pointers everywhere, then we're safe, and | |
114 | * we bypass this mess, as on non-VMS systems. | |
115 | * Problem 1: Compaq/HP C before V7.3 always used 32-bit | |
116 | * pointers for argv[]. | |
117 | * Fix 1: For a 32-bit argv[], when we're using 64-bit pointers | |
118 | * everywhere else, we always allocate and use a 64-bit | |
119 | * duplicate of argv[]. | |
120 | * Problem 2: Compaq/HP C V7.3 (Alpha, IA64) before ECO1 failed | |
121 | * to NULL-terminate a 64-bit argv[]. (As this was written, the | |
122 | * compiler ECO was available only on IA64.) | |
123 | * Fix 2: Unless advised not to (VMS_TRUST_ARGV), we test a | |
124 | * 64-bit argv[argc] for NULL, and, if necessary, use a | |
125 | * (properly) NULL-terminated (64-bit) duplicate of argv[]. | |
126 | * The same code is used in either case to duplicate argv[]. | |
127 | * Some of these decisions could be handled in preprocessing, | |
128 | * but the code tends to get even uglier, and the penalty for | |
129 | * deciding at compile- or run-time is tiny. | |
130 | */ | |
131 | ||
132 | int i, count = *argc; | |
b196e7d9 | 133 | char **newargv = OPENSSL_malloc((count + 1) * sizeof *newargv); |
7e1b7485 RS |
134 | |
135 | for (i = 0; i < count; i++) | |
136 | newargv[i] = argv[i]; | |
137 | newargv[i] = NULL; | |
138 | *argc = i; | |
139 | return newargv; | |
140 | } | |
141 | ||
537c9823 RL |
142 | /* LIB$INITIALIZE initialization function. */ |
143 | ||
0f113f3e | 144 | static void decc_init(void) |
537c9823 RL |
145 | { |
146 | char *openssl_debug_decc_init; | |
147 | int verbose = 0; | |
148 | int feat_index; | |
149 | int feat_value; | |
150 | int feat_value_max; | |
151 | int feat_value_min; | |
152 | int i; | |
153 | int sts; | |
154 | ||
155 | /* Get debug option. */ | |
0f113f3e MC |
156 | openssl_debug_decc_init = getenv("OPENSSL_DEBUG_DECC_INIT"); |
157 | if (openssl_debug_decc_init != NULL) { | |
158 | verbose = strtol(openssl_debug_decc_init, NULL, 10); | |
159 | if (verbose <= 0) { | |
537c9823 RL |
160 | verbose = 1; |
161 | } | |
162 | } | |
163 | ||
164 | /* Set the global flag to indicate that LIB$INITIALIZE worked. */ | |
165 | decc_init_done = 1; | |
166 | ||
167 | /* Loop through all items in the decc_feat_array[]. */ | |
168 | ||
0f113f3e | 169 | for (i = 0; decc_feat_array[i].name != NULL; i++) { |
537c9823 | 170 | /* Get the feature index. */ |
0f113f3e MC |
171 | feat_index = decc$feature_get_index(decc_feat_array[i].name); |
172 | if (feat_index >= 0) { | |
537c9823 | 173 | /* Valid item. Collect its properties. */ |
0f113f3e MC |
174 | feat_value = decc$feature_get_value(feat_index, 1); |
175 | feat_value_min = decc$feature_get_value(feat_index, 2); | |
176 | feat_value_max = decc$feature_get_value(feat_index, 3); | |
537c9823 RL |
177 | |
178 | /* Check the validity of our desired value. */ | |
0f113f3e MC |
179 | if ((decc_feat_array[i].value >= feat_value_min) && |
180 | (decc_feat_array[i].value <= feat_value_max)) { | |
537c9823 | 181 | /* Valid value. Set it if necessary. */ |
0f113f3e MC |
182 | if (feat_value != decc_feat_array[i].value) { |
183 | sts = decc$feature_set_value(feat_index, | |
184 | 1, decc_feat_array[i].value); | |
185 | ||
186 | if (verbose > 1) { | |
187 | fprintf(stderr, " %s = %d, sts = %d.\n", | |
188 | decc_feat_array[i].name, | |
189 | decc_feat_array[i].value, sts); | |
190 | } | |
537c9823 | 191 | } |
0f113f3e | 192 | } else { |
537c9823 | 193 | /* Invalid DECC feature value. */ |
0f113f3e MC |
194 | fprintf(stderr, |
195 | " INVALID DECC$FEATURE VALUE, %d: %d <= %s <= %d.\n", | |
196 | feat_value, | |
197 | feat_value_min, decc_feat_array[i].name, | |
198 | feat_value_max); | |
537c9823 | 199 | } |
0f113f3e | 200 | } else { |
537c9823 | 201 | /* Invalid DECC feature name. */ |
0f113f3e MC |
202 | fprintf(stderr, |
203 | " UNKNOWN DECC$FEATURE: %s.\n", decc_feat_array[i].name); | |
537c9823 RL |
204 | } |
205 | } | |
206 | ||
0f113f3e MC |
207 | if (verbose > 0) { |
208 | fprintf(stderr, " DECC_INIT complete.\n"); | |
537c9823 RL |
209 | } |
210 | } | |
211 | ||
212 | /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */ | |
213 | ||
0f113f3e | 214 | # pragma nostandard |
537c9823 | 215 | |
0f113f3e MC |
216 | /* |
217 | * Establish the LIB$INITIALIZE PSECTs, with proper alignment and other | |
218 | * attributes. Note that "nopic" is significant only on VAX. | |
537c9823 | 219 | */ |
0f113f3e | 220 | # pragma extern_model save |
537c9823 | 221 | |
0f113f3e MC |
222 | # if __INITIAL_POINTER_SIZE == 64 |
223 | # define PSECT_ALIGN 3 | |
224 | # else | |
225 | # define PSECT_ALIGN 2 | |
226 | # endif | |
537c9823 | 227 | |
0f113f3e MC |
228 | # pragma extern_model strict_refdef "LIB$INITIALIZ" PSECT_ALIGN, nopic, nowrt |
229 | const int spare[8] = { 0 }; | |
537c9823 | 230 | |
0f113f3e MC |
231 | # pragma extern_model strict_refdef "LIB$INITIALIZE" PSECT_ALIGN, nopic, nowrt |
232 | void (*const x_decc_init) () = decc_init; | |
537c9823 | 233 | |
0f113f3e | 234 | # pragma extern_model restore |
537c9823 RL |
235 | |
236 | /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */ | |
237 | ||
0f113f3e | 238 | # pragma extern_model save |
537c9823 | 239 | |
0f113f3e | 240 | int LIB$INITIALIZE(void); |
537c9823 | 241 | |
0f113f3e MC |
242 | # pragma extern_model strict_refdef |
243 | int dmy_lib$initialize = (int)LIB$INITIALIZE; | |
537c9823 | 244 | |
0f113f3e | 245 | # pragma extern_model restore |
537c9823 | 246 | |
0f113f3e | 247 | # pragma standard |
537c9823 | 248 | |
0f113f3e | 249 | #else /* def USE_DECC_INIT */ |
537c9823 RL |
250 | |
251 | /* Dummy code to avoid a %CC-W-EMPTYFILE complaint. */ | |
0f113f3e | 252 | int decc_init_dummy(void); |
537c9823 | 253 | |
0f113f3e | 254 | #endif /* def USE_DECC_INIT */ |