]>
Commit | Line | Data |
---|---|---|
7e1b7485 | 1 | /* |
846e33c7 | 2 | * Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved. |
7e1b7485 | 3 | * |
846e33c7 RS |
4 | * Licensed under the OpenSSL license (the "License"). You may not use |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
7e1b7485 RS |
8 | */ |
9 | ||
537c9823 RL |
10 | #if defined( __VMS) && !defined( OPENSSL_NO_DECC_INIT) && \ |
11 | defined( __DECC) && !defined( __VAX) && (__CRTL_VER >= 70301000) | |
12 | # define USE_DECC_INIT 1 | |
13 | #endif | |
14 | ||
15 | #ifdef USE_DECC_INIT | |
16 | ||
7e1b7485 RS |
17 | /* |
18 | * ---------------------------------------------------------------------- | |
19 | * decc_init() On non-VAX systems, uses LIB$INITIALIZE to set a collection | |
20 | * of C RTL features without using the DECC$* logical name method. | |
21 | * ---------------------------------------------------------------------- | |
537c9823 RL |
22 | */ |
23 | ||
0f113f3e MC |
24 | # include <stdio.h> |
25 | # include <stdlib.h> | |
26 | # include <unixlib.h> | |
537c9823 | 27 | |
3dc9589c RL |
28 | # include "apps.h" |
29 | ||
537c9823 RL |
30 | /* Global storage. */ |
31 | ||
32 | /* Flag to sense if decc_init() was called. */ | |
33 | ||
34 | int decc_init_done = -1; | |
35 | ||
537c9823 RL |
36 | /* Structure to hold a DECC$* feature name and its desired value. */ |
37 | ||
0f113f3e | 38 | typedef struct { |
537c9823 RL |
39 | char *name; |
40 | int value; | |
41 | } decc_feat_t; | |
42 | ||
0f113f3e MC |
43 | /* |
44 | * Array of DECC$* feature names and their desired values. Note: | |
45 | * DECC$ARGV_PARSE_STYLE is the urgent one. | |
537c9823 RL |
46 | */ |
47 | ||
0f113f3e MC |
48 | decc_feat_t decc_feat_array[] = { |
49 | /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */ | |
50 | {"DECC$ARGV_PARSE_STYLE", 1}, | |
537c9823 | 51 | |
0f113f3e MC |
52 | /* Preserve case for file names on ODS5 disks. */ |
53 | {"DECC$EFS_CASE_PRESERVE", 1}, | |
537c9823 | 54 | |
0f113f3e MC |
55 | /* |
56 | * Enable multiple dots (and most characters) in ODS5 file names, while | |
57 | * preserving VMS-ness of ";version". | |
58 | */ | |
59 | {"DECC$EFS_CHARSET", 1}, | |
537c9823 | 60 | |
0f113f3e MC |
61 | /* List terminator. */ |
62 | {(char *)NULL, 0} | |
537c9823 RL |
63 | }; |
64 | ||
087ca80a | 65 | |
368058d0 | 66 | char **copy_argv(int *argc, char *argv[]) |
7e1b7485 RS |
67 | { |
68 | /*- | |
69 | * The note below is for historical purpose. On VMS now we always | |
70 | * copy argv "safely." | |
71 | * | |
72 | * 2011-03-22 SMS. | |
73 | * If we have 32-bit pointers everywhere, then we're safe, and | |
74 | * we bypass this mess, as on non-VMS systems. | |
75 | * Problem 1: Compaq/HP C before V7.3 always used 32-bit | |
76 | * pointers for argv[]. | |
77 | * Fix 1: For a 32-bit argv[], when we're using 64-bit pointers | |
78 | * everywhere else, we always allocate and use a 64-bit | |
79 | * duplicate of argv[]. | |
80 | * Problem 2: Compaq/HP C V7.3 (Alpha, IA64) before ECO1 failed | |
81 | * to NULL-terminate a 64-bit argv[]. (As this was written, the | |
82 | * compiler ECO was available only on IA64.) | |
83 | * Fix 2: Unless advised not to (VMS_TRUST_ARGV), we test a | |
84 | * 64-bit argv[argc] for NULL, and, if necessary, use a | |
85 | * (properly) NULL-terminated (64-bit) duplicate of argv[]. | |
86 | * The same code is used in either case to duplicate argv[]. | |
87 | * Some of these decisions could be handled in preprocessing, | |
88 | * but the code tends to get even uglier, and the penalty for | |
89 | * deciding at compile- or run-time is tiny. | |
90 | */ | |
91 | ||
92 | int i, count = *argc; | |
b4faea50 | 93 | char **newargv = app_malloc(sizeof(*newargv) * (count + 1), "argv copy"); |
7e1b7485 RS |
94 | |
95 | for (i = 0; i < count; i++) | |
96 | newargv[i] = argv[i]; | |
97 | newargv[i] = NULL; | |
98 | *argc = i; | |
99 | return newargv; | |
100 | } | |
101 | ||
537c9823 RL |
102 | /* LIB$INITIALIZE initialization function. */ |
103 | ||
0f113f3e | 104 | static void decc_init(void) |
537c9823 RL |
105 | { |
106 | char *openssl_debug_decc_init; | |
107 | int verbose = 0; | |
108 | int feat_index; | |
109 | int feat_value; | |
110 | int feat_value_max; | |
111 | int feat_value_min; | |
112 | int i; | |
113 | int sts; | |
114 | ||
115 | /* Get debug option. */ | |
0f113f3e MC |
116 | openssl_debug_decc_init = getenv("OPENSSL_DEBUG_DECC_INIT"); |
117 | if (openssl_debug_decc_init != NULL) { | |
118 | verbose = strtol(openssl_debug_decc_init, NULL, 10); | |
119 | if (verbose <= 0) { | |
537c9823 RL |
120 | verbose = 1; |
121 | } | |
122 | } | |
123 | ||
124 | /* Set the global flag to indicate that LIB$INITIALIZE worked. */ | |
125 | decc_init_done = 1; | |
126 | ||
127 | /* Loop through all items in the decc_feat_array[]. */ | |
128 | ||
0f113f3e | 129 | for (i = 0; decc_feat_array[i].name != NULL; i++) { |
537c9823 | 130 | /* Get the feature index. */ |
0f113f3e MC |
131 | feat_index = decc$feature_get_index(decc_feat_array[i].name); |
132 | if (feat_index >= 0) { | |
537c9823 | 133 | /* Valid item. Collect its properties. */ |
0f113f3e MC |
134 | feat_value = decc$feature_get_value(feat_index, 1); |
135 | feat_value_min = decc$feature_get_value(feat_index, 2); | |
136 | feat_value_max = decc$feature_get_value(feat_index, 3); | |
537c9823 RL |
137 | |
138 | /* Check the validity of our desired value. */ | |
0f113f3e MC |
139 | if ((decc_feat_array[i].value >= feat_value_min) && |
140 | (decc_feat_array[i].value <= feat_value_max)) { | |
537c9823 | 141 | /* Valid value. Set it if necessary. */ |
0f113f3e MC |
142 | if (feat_value != decc_feat_array[i].value) { |
143 | sts = decc$feature_set_value(feat_index, | |
144 | 1, decc_feat_array[i].value); | |
145 | ||
146 | if (verbose > 1) { | |
147 | fprintf(stderr, " %s = %d, sts = %d.\n", | |
148 | decc_feat_array[i].name, | |
149 | decc_feat_array[i].value, sts); | |
150 | } | |
537c9823 | 151 | } |
0f113f3e | 152 | } else { |
537c9823 | 153 | /* Invalid DECC feature value. */ |
0f113f3e MC |
154 | fprintf(stderr, |
155 | " INVALID DECC$FEATURE VALUE, %d: %d <= %s <= %d.\n", | |
156 | feat_value, | |
157 | feat_value_min, decc_feat_array[i].name, | |
158 | feat_value_max); | |
537c9823 | 159 | } |
0f113f3e | 160 | } else { |
537c9823 | 161 | /* Invalid DECC feature name. */ |
0f113f3e MC |
162 | fprintf(stderr, |
163 | " UNKNOWN DECC$FEATURE: %s.\n", decc_feat_array[i].name); | |
537c9823 RL |
164 | } |
165 | } | |
166 | ||
0f113f3e MC |
167 | if (verbose > 0) { |
168 | fprintf(stderr, " DECC_INIT complete.\n"); | |
537c9823 RL |
169 | } |
170 | } | |
171 | ||
172 | /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */ | |
173 | ||
0f113f3e | 174 | # pragma nostandard |
537c9823 | 175 | |
0f113f3e MC |
176 | /* |
177 | * Establish the LIB$INITIALIZE PSECTs, with proper alignment and other | |
178 | * attributes. Note that "nopic" is significant only on VAX. | |
537c9823 | 179 | */ |
0f113f3e | 180 | # pragma extern_model save |
537c9823 | 181 | |
0f113f3e MC |
182 | # if __INITIAL_POINTER_SIZE == 64 |
183 | # define PSECT_ALIGN 3 | |
184 | # else | |
185 | # define PSECT_ALIGN 2 | |
186 | # endif | |
537c9823 | 187 | |
0f113f3e MC |
188 | # pragma extern_model strict_refdef "LIB$INITIALIZ" PSECT_ALIGN, nopic, nowrt |
189 | const int spare[8] = { 0 }; | |
537c9823 | 190 | |
0f113f3e MC |
191 | # pragma extern_model strict_refdef "LIB$INITIALIZE" PSECT_ALIGN, nopic, nowrt |
192 | void (*const x_decc_init) () = decc_init; | |
537c9823 | 193 | |
0f113f3e | 194 | # pragma extern_model restore |
537c9823 RL |
195 | |
196 | /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */ | |
197 | ||
0f113f3e | 198 | # pragma extern_model save |
537c9823 | 199 | |
0f113f3e | 200 | int LIB$INITIALIZE(void); |
537c9823 | 201 | |
0f113f3e MC |
202 | # pragma extern_model strict_refdef |
203 | int dmy_lib$initialize = (int)LIB$INITIALIZE; | |
537c9823 | 204 | |
0f113f3e | 205 | # pragma extern_model restore |
537c9823 | 206 | |
0f113f3e | 207 | # pragma standard |
537c9823 | 208 | |
0f113f3e | 209 | #else /* def USE_DECC_INIT */ |
537c9823 RL |
210 | |
211 | /* Dummy code to avoid a %CC-W-EMPTYFILE complaint. */ | |
0f113f3e | 212 | int decc_init_dummy(void); |
537c9823 | 213 | |
0f113f3e | 214 | #endif /* def USE_DECC_INIT */ |