1 #ifndef HEADER_CURL_SETUP_VMS_H
2 #define HEADER_CURL_SETUP_VMS_H
3 /***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 * SPDX-License-Identifier: curl
24 *
25 ***************************************************************************/
26
27 /* */
28 /* JEM, 12/30/12, VMS now generates config.h, so only define wrappers for */
29 /* getenv(), getpwuid() and provide is_vms_shell() */
30 /* Also need upper case symbols for system services, and */
31 /* OpenSSL, and some Kerberos image */
32
33 #ifdef __DECC
34 #pragma message save
35 #pragma message disable dollarid
36 #endif
37
38 /* Hide the stuff we are overriding */
39 #define getenv decc_getenv
40 #ifdef __DECC
41 # if __INITIAL_POINTER_SIZE != 64
42 # define getpwuid decc_getpwuid
43 # endif
44 #endif
45 #include <stdlib.h>
46 char *decc$getenv(const char *__name);
47 #include <pwd.h>
48
49 #include <string.h>
50 #include <unixlib.h>
51
52 #undef getenv
53 #undef getpwuid
54 #define getenv vms_getenv
55 #define getpwuid vms_getpwuid
56
57 /* VAX needs these in upper case when compiling exact case */
58 #define sys$assign SYS$ASSIGN
59 #define sys$dassgn SYS$DASSGN
60 #define sys$qiow SYS$QIOW
61
62 #ifdef __DECC
63 # if __INITIAL_POINTER_SIZE
64 # pragma __pointer_size __save
65 # endif
66 #endif
67
68 #if __USE_LONG_GID_T
69 # define decc_getpwuid DECC$__LONG_GID_GETPWUID
70 #else
71 # if __INITIAL_POINTER_SIZE
72 # define decc_getpwuid decc$__32_getpwuid
73 # else
74 # define decc_getpwuid decc$getpwuid
75 # endif
76 #endif
77
78 struct passwd *decc_getpwuid(uid_t uid);
79
80 #ifdef __DECC
81 # if __INITIAL_POINTER_SIZE == 32
82 /* Translate the path, but only if the path is a VMS file specification */
83 /* The translation is usually only needed for older versions of VMS */
vms_translate_path(const char * path)84 static char *vms_translate_path(const char *path)
85 {
86 char *unix_path;
87 char *test_str;
88
89 /* See if the result is in VMS format, if not, we are done */
90 /* Assume that this is a PATH, not just some data */
91 test_str = strpbrk(path, ":[<^");
92 if(!test_str) {
93 return (char *)path;
94 }
95
96 unix_path = decc$translate_vms(path);
97
98 if((int)unix_path <= 0) {
99 /* We can not translate it, so return the original string */
100 return (char *)path;
101 }
102 }
103 # else
104 /* VMS translate path is actually not needed on the current 64 bit */
105 /* VMS platforms, so instead of figuring out the pointer settings */
106 /* Change it to a noop */
107 # define vms_translate_path(__path) __path
108 # endif
109 #endif
110
111 #ifdef __DECC
112 # if __INITIAL_POINTER_SIZE
113 # pragma __pointer_size __restore
114 # endif
115 #endif
116
vms_getenv(const char * envvar)117 static char *vms_getenv(const char *envvar)
118 {
119 char *result;
120 char *vms_path;
121
122 /* first use the DECC getenv() function */
123 result = decc$getenv(envvar);
124 if(!result) {
125 return result;
126 }
127
128 vms_path = result;
129 result = vms_translate_path(vms_path);
130
131 /* note that if you backport this to use VAX C RTL, that the VAX C RTL */
132 /* may do a malloc(2048) for each call to getenv(), so you will need */
133 /* to add a free(vms_path) */
134 /* Do not do a free() for DEC C RTL builds, which should be used for */
135 /* VMS 5.5-2 and later, even if using GCC */
136
137 return result;
138 }
139
140
141 static struct passwd vms_passwd_cache;
142
vms_getpwuid(uid_t uid)143 static struct passwd *vms_getpwuid(uid_t uid)
144 {
145 struct passwd *my_passwd;
146
147 /* Hack needed to support 64 bit builds, decc_getpwnam is 32 bit only */
148 #ifdef __DECC
149 # if __INITIAL_POINTER_SIZE
150 __char_ptr32 unix_path;
151 # else
152 char *unix_path;
153 # endif
154 #else
155 char *unix_path;
156 #endif
157
158 my_passwd = decc_getpwuid(uid);
159 if(!my_passwd) {
160 return my_passwd;
161 }
162
163 unix_path = vms_translate_path(my_passwd->pw_dir);
164
165 if((long)unix_path <= 0) {
166 /* We can not translate it, so return the original string */
167 return my_passwd;
168 }
169
170 /* If no changes needed just return it */
171 if(unix_path == my_passwd->pw_dir) {
172 return my_passwd;
173 }
174
175 /* Need to copy the structure returned */
176 /* Since curl is only using pw_dir, no need to fix up */
177 /* the pw_shell when running under Bash */
178 vms_passwd_cache.pw_name = my_passwd->pw_name;
179 vms_passwd_cache.pw_uid = my_passwd->pw_uid;
180 vms_passwd_cache.pw_gid = my_passwd->pw_uid;
181 vms_passwd_cache.pw_dir = unix_path;
182 vms_passwd_cache.pw_shell = my_passwd->pw_shell;
183
184 return &vms_passwd_cache;
185 }
186
187 #ifdef __DECC
188 #pragma message restore
189 #endif
190
191 /* Bug - VMS OpenSSL and Kerberos universal symbols are in uppercase only */
192 /* VMS libraries should have universal symbols in exact and uppercase */
193
194 #define ASN1_INTEGER_get ASN1_INTEGER_GET
195 #define ASN1_STRING_data ASN1_STRING_DATA
196 #define ASN1_STRING_length ASN1_STRING_LENGTH
197 #define ASN1_STRING_print ASN1_STRING_PRINT
198 #define ASN1_STRING_to_UTF8 ASN1_STRING_TO_UTF8
199 #define ASN1_STRING_type ASN1_STRING_TYPE
200 #define BIO_ctrl BIO_CTRL
201 #define BIO_free BIO_FREE
202 #define BIO_new BIO_NEW
203 #define BIO_s_mem BIO_S_MEM
204 #define BN_bn2bin BN_BN2BIN
205 #define BN_num_bits BN_NUM_BITS
206 #define CRYPTO_cleanup_all_ex_data CRYPTO_CLEANUP_ALL_EX_DATA
207 #define CRYPTO_free CRYPTO_FREE
208 #define CRYPTO_malloc CRYPTO_MALLOC
209 #define CONF_modules_load_file CONF_MODULES_LOAD_FILE
210 #ifdef __VAX
211 # ifdef VMS_OLD_SSL
212 /* Ancient OpenSSL on VAX/VMS missing this constant */
213 # define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
214 # undef CONF_modules_load_file
CONF_modules_load_file(const char * filename,const char * appname,unsigned long flags)215 static int CONF_modules_load_file(const char *filename,
216 const char *appname,
217 unsigned long flags) {
218 return 1;
219 }
220 # endif
221 #endif
222 #define DES_ecb_encrypt DES_ECB_ENCRYPT
223 #define DES_set_key DES_SET_KEY
224 #define DES_set_odd_parity DES_SET_ODD_PARITY
225 #define ENGINE_ctrl ENGINE_CTRL
226 #define ENGINE_ctrl_cmd ENGINE_CTRL_CMD
227 #define ENGINE_finish ENGINE_FINISH
228 #define ENGINE_free ENGINE_FREE
229 #define ENGINE_get_first ENGINE_GET_FIRST
230 #define ENGINE_get_id ENGINE_GET_ID
231 #define ENGINE_get_next ENGINE_GET_NEXT
232 #define ENGINE_init ENGINE_INIT
233 #define ENGINE_load_builtin_engines ENGINE_LOAD_BUILTIN_ENGINES
234 #define ENGINE_load_private_key ENGINE_LOAD_PRIVATE_KEY
235 #define ENGINE_set_default ENGINE_SET_DEFAULT
236 #define ERR_clear_error ERR_CLEAR_ERROR
237 #define ERR_error_string ERR_ERROR_STRING
238 #define ERR_error_string_n ERR_ERROR_STRING_N
239 #define ERR_free_strings ERR_FREE_STRINGS
240 #define ERR_get_error ERR_GET_ERROR
241 #define ERR_peek_error ERR_PEEK_ERROR
242 #define ERR_remove_state ERR_REMOVE_STATE
243 #define EVP_PKEY_copy_parameters EVP_PKEY_COPY_PARAMETERS
244 #define EVP_PKEY_free EVP_PKEY_FREE
245 #define EVP_cleanup EVP_CLEANUP
246 #define GENERAL_NAMES_free GENERAL_NAMES_FREE
247 #define i2d_X509_PUBKEY I2D_X509_PUBKEY
248 #define MD4_Final MD4_FINAL
249 #define MD4_Init MD4_INIT
250 #define MD4_Update MD4_UPDATE
251 #define MD5_Final MD5_FINAL
252 #define MD5_Init MD5_INIT
253 #define MD5_Update MD5_UPDATE
254 #define OPENSSL_add_all_algo_noconf OPENSSL_ADD_ALL_ALGO_NOCONF
255 #ifndef __VAX
256 #define OPENSSL_load_builtin_modules OPENSSL_LOAD_BUILTIN_MODULES
257 #endif
258 #define PEM_read_X509 PEM_READ_X509
259 #define PEM_write_bio_X509 PEM_WRITE_BIO_X509
260 #define PKCS12_PBE_add PKCS12_PBE_ADD
261 #define PKCS12_free PKCS12_FREE
262 #define PKCS12_parse PKCS12_PARSE
263 #define RAND_add RAND_ADD
264 #define RAND_bytes RAND_BYTES
265 #define RAND_egd RAND_EGD
266 #define RAND_file_name RAND_FILE_NAME
267 #define RAND_load_file RAND_LOAD_FILE
268 #define RAND_status RAND_STATUS
269 #define SSL_CIPHER_get_name SSL_CIPHER_GET_NAME
270 #define SSL_CTX_add_client_CA SSL_CTX_ADD_CLIENT_CA
271 #define SSL_CTX_callback_ctrl SSL_CTX_CALLBACK_CTRL
272 #define SSL_CTX_check_private_key SSL_CTX_CHECK_PRIVATE_KEY
273 #define SSL_CTX_ctrl SSL_CTX_CTRL
274 #define SSL_CTX_free SSL_CTX_FREE
275 #define SSL_CTX_get_cert_store SSL_CTX_GET_CERT_STORE
276 #define SSL_CTX_load_verify_locations SSL_CTX_LOAD_VERIFY_LOCATIONS
277 #define SSL_CTX_new SSL_CTX_NEW
278 #define SSL_CTX_set_cipher_list SSL_CTX_SET_CIPHER_LIST
279 #define SSL_CTX_set_def_passwd_cb_ud SSL_CTX_SET_DEF_PASSWD_CB_UD
280 #define SSL_CTX_set_default_passwd_cb SSL_CTX_SET_DEFAULT_PASSWD_CB
281 #define SSL_CTX_set_msg_callback SSL_CTX_SET_MSG_CALLBACK
282 #define SSL_CTX_set_verify SSL_CTX_SET_VERIFY
283 #define SSL_CTX_use_PrivateKey SSL_CTX_USE_PRIVATEKEY
284 #define SSL_CTX_use_PrivateKey_file SSL_CTX_USE_PRIVATEKEY_FILE
285 #define SSL_CTX_use_cert_chain_file SSL_CTX_USE_CERT_CHAIN_FILE
286 #define SSL_CTX_use_certificate SSL_CTX_USE_CERTIFICATE
287 #define SSL_CTX_use_certificate_file SSL_CTX_USE_CERTIFICATE_FILE
288 #define SSL_SESSION_free SSL_SESSION_FREE
289 #define SSL_connect SSL_CONNECT
290 #define SSL_free SSL_FREE
291 #define SSL_get1_session SSL_GET1_SESSION
292 #define SSL_get_certificate SSL_GET_CERTIFICATE
293 #define SSL_get_current_cipher SSL_GET_CURRENT_CIPHER
294 #define SSL_get_error SSL_GET_ERROR
295 #define SSL_get_peer_cert_chain SSL_GET_PEER_CERT_CHAIN
296 #define SSL_get_peer_certificate SSL_GET_PEER_CERTIFICATE
297 #define SSL_get_privatekey SSL_GET_PRIVATEKEY
298 #define SSL_get_session SSL_GET_SESSION
299 #define SSL_get_shutdown SSL_GET_SHUTDOWN
300 #define SSL_get_verify_result SSL_GET_VERIFY_RESULT
301 #define SSL_library_init SSL_LIBRARY_INIT
302 #define SSL_load_error_strings SSL_LOAD_ERROR_STRINGS
303 #define SSL_new SSL_NEW
304 #define SSL_peek SSL_PEEK
305 #define SSL_pending SSL_PENDING
306 #define SSL_read SSL_READ
307 #define SSL_set_connect_state SSL_SET_CONNECT_STATE
308 #define SSL_set_fd SSL_SET_FD
309 #define SSL_set_session SSL_SET_SESSION
310 #define SSL_shutdown SSL_SHUTDOWN
311 #define SSL_version SSL_VERSION
312 #define SSL_write SSL_WRITE
313 #define SSLeay SSLEAY
314 #define SSLv23_client_method SSLV23_CLIENT_METHOD
315 #define SSLv3_client_method SSLV3_CLIENT_METHOD
316 #define TLSv1_client_method TLSV1_CLIENT_METHOD
317 #define UI_create_method UI_CREATE_METHOD
318 #define UI_destroy_method UI_DESTROY_METHOD
319 #define UI_get0_user_data UI_GET0_USER_DATA
320 #define UI_get_input_flags UI_GET_INPUT_FLAGS
321 #define UI_get_string_type UI_GET_STRING_TYPE
322 #define UI_create_method UI_CREATE_METHOD
323 #define UI_destroy_method UI_DESTROY_METHOD
324 #define UI_method_get_closer UI_METHOD_GET_CLOSER
325 #define UI_method_get_opener UI_METHOD_GET_OPENER
326 #define UI_method_get_reader UI_METHOD_GET_READER
327 #define UI_method_get_writer UI_METHOD_GET_WRITER
328 #define UI_method_set_closer UI_METHOD_SET_CLOSER
329 #define UI_method_set_opener UI_METHOD_SET_OPENER
330 #define UI_method_set_reader UI_METHOD_SET_READER
331 #define UI_method_set_writer UI_METHOD_SET_WRITER
332 #define UI_OpenSSL UI_OPENSSL
333 #define UI_set_result UI_SET_RESULT
334 #define X509V3_EXT_print X509V3_EXT_PRINT
335 #define X509_EXTENSION_get_critical X509_EXTENSION_GET_CRITICAL
336 #define X509_EXTENSION_get_data X509_EXTENSION_GET_DATA
337 #define X509_EXTENSION_get_object X509_EXTENSION_GET_OBJECT
338 #define X509_LOOKUP_file X509_LOOKUP_FILE
339 #define X509_NAME_ENTRY_get_data X509_NAME_ENTRY_GET_DATA
340 #define X509_NAME_get_entry X509_NAME_GET_ENTRY
341 #define X509_NAME_get_index_by_NID X509_NAME_GET_INDEX_BY_NID
342 #define X509_NAME_print_ex X509_NAME_PRINT_EX
343 #define X509_STORE_CTX_get_current_cert X509_STORE_CTX_GET_CURRENT_CERT
344 #define X509_STORE_add_lookup X509_STORE_ADD_LOOKUP
345 #define X509_STORE_set_flags X509_STORE_SET_FLAGS
346 #define X509_check_issued X509_CHECK_ISSUED
347 #define X509_free X509_FREE
348 #define X509_get_ext_d2i X509_GET_EXT_D2I
349 #define X509_get_issuer_name X509_GET_ISSUER_NAME
350 #define X509_get_pubkey X509_GET_PUBKEY
351 #define X509_get_serialNumber X509_GET_SERIALNUMBER
352 #define X509_get_subject_name X509_GET_SUBJECT_NAME
353 #define X509_load_crl_file X509_LOAD_CRL_FILE
354 #define X509_verify_cert_error_string X509_VERIFY_CERT_ERROR_STRING
355 #define d2i_PKCS12_fp D2I_PKCS12_FP
356 #define i2t_ASN1_OBJECT I2T_ASN1_OBJECT
357 #define sk_num SK_NUM
358 #define sk_pop SK_POP
359 #define sk_pop_free SK_POP_FREE
360 #define sk_value SK_VALUE
361 #ifdef __VAX
362 #define OPENSSL_NO_SHA256
363 #endif
364 #define SHA256_Final SHA256_FINAL
365 #define SHA256_Init SHA256_INIT
366 #define SHA256_Update SHA256_UPDATE
367
368 #define USE_UPPERCASE_GSSAPI 1
369 #define gss_seal GSS_SEAL
370 #define gss_unseal GSS_UNSEAL
371
372 #define USE_UPPERCASE_KRBAPI 1
373
374 /* AI_NUMERICHOST needed for IP V6 support in Curl */
375 #ifdef HAVE_NETDB_H
376 #include <netdb.h>
377 #ifndef AI_NUMERICHOST
378 #ifdef ENABLE_IPV6
379 #undef ENABLE_IPV6
380 #endif
381 #endif
382 #endif
383
384 /* VAX symbols are always in uppercase */
385 #ifdef __VAX
386 #define inflate INFLATE
387 #define inflateEnd INFLATEEND
388 #define inflateInit2_ INFLATEINIT2_
389 #define inflateInit_ INFLATEINIT_
390 #define zlibVersion ZLIBVERSION
391 #endif
392
393 /* Older VAX OpenSSL port defines these as Macros */
394 /* Need to include the headers first and then redefine */
395 /* that way a newer port will also work if some one has one */
396 #ifdef __VAX
397
398 # if (OPENSSL_VERSION_NUMBER < 0x00907001L)
399 # define des_set_odd_parity DES_SET_ODD_PARITY
400 # define des_set_key DES_SET_KEY
401 # define des_ecb_encrypt DES_ECB_ENCRYPT
402
403 # endif
404 # include <openssl/evp.h>
405 # ifndef OpenSSL_add_all_algorithms
406 # define OpenSSL_add_all_algorithms OPENSSL_ADD_ALL_ALGORITHMS
407 void OPENSSL_ADD_ALL_ALGORITHMS(void);
408 # endif
409
410 /* Curl defines these to lower case and VAX needs them in upper case */
411 /* So we need static routines */
412 # if (OPENSSL_VERSION_NUMBER < 0x00907001L)
413
414 # undef des_set_odd_parity
415 # undef DES_set_odd_parity
416 # undef des_set_key
417 # undef DES_set_key
418 # undef des_ecb_encrypt
419 # undef DES_ecb_encrypt
420
des_set_odd_parity(des_cblock * key)421 static void des_set_odd_parity(des_cblock *key) {
422 DES_SET_ODD_PARITY(key);
423 }
424
des_set_key(const_des_cblock * key,des_key_schedule schedule)425 static int des_set_key(const_des_cblock *key,
426 des_key_schedule schedule) {
427 return DES_SET_KEY(key, schedule);
428 }
429
des_ecb_encrypt(const_des_cblock * input,des_cblock * output,des_key_schedule ks,int enc)430 static void des_ecb_encrypt(const_des_cblock *input,
431 des_cblock *output,
432 des_key_schedule ks, int enc) {
433 DES_ECB_ENCRYPT(input, output, ks, enc);
434 }
435 #endif
436 /* Need this to stop a macro redefinition error */
437 #if OPENSSL_VERSION_NUMBER < 0x00907000L
438 # ifdef X509_STORE_set_flags
439 # undef X509_STORE_set_flags
440 # define X509_STORE_set_flags(x,y) Curl_nop_stmt
441 # endif
442 #endif
443 #endif
444
445 #endif /* HEADER_CURL_SETUP_VMS_H */
446