setup-vms.h 14 KB

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