1 1.1 christos /* 2 1.1 christos * Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * 4 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos * this file except in compliance with the License. You can obtain a copy 6 1.1 christos * in the file LICENSE in the source distribution or at 7 1.1 christos * https://www.openssl.org/source/license.html 8 1.1 christos */ 9 1.1 christos 10 1.1.1.2 christos #if defined(__VMS) && !defined(OPENSSL_NO_DECC_INIT) && defined(__DECC) && !defined(__VAX) && (__CRTL_VER >= 70301000) 11 1.1.1.2 christos #define USE_DECC_INIT 1 12 1.1 christos #endif 13 1.1 christos 14 1.1 christos #ifdef USE_DECC_INIT 15 1.1 christos 16 1.1 christos /* 17 1.1 christos * ---------------------------------------------------------------------- 18 1.1 christos * decc_init() On non-VAX systems, uses LIB$INITIALIZE to set a collection 19 1.1 christos * of C RTL features without using the DECC$* logical name method. 20 1.1 christos * ---------------------------------------------------------------------- 21 1.1 christos */ 22 1.1 christos 23 1.1.1.2 christos #include <stdio.h> 24 1.1.1.2 christos #include <stdlib.h> 25 1.1.1.2 christos #include <unixlib.h> 26 1.1 christos 27 1.1 christos /* Global storage. */ 28 1.1 christos 29 1.1 christos /* Flag to sense if decc_init() was called. */ 30 1.1 christos 31 1.1 christos int decc_init_done = -1; 32 1.1 christos 33 1.1 christos /* Structure to hold a DECC$* feature name and its desired value. */ 34 1.1 christos 35 1.1 christos typedef struct { 36 1.1 christos char *name; 37 1.1 christos int value; 38 1.1 christos } decc_feat_t; 39 1.1 christos 40 1.1 christos /* 41 1.1 christos * Array of DECC$* feature names and their desired values. Note: 42 1.1 christos * DECC$ARGV_PARSE_STYLE is the urgent one. 43 1.1 christos */ 44 1.1 christos 45 1.1 christos decc_feat_t decc_feat_array[] = { 46 1.1 christos /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */ 47 1.1.1.2 christos { "DECC$ARGV_PARSE_STYLE", 1 }, 48 1.1 christos 49 1.1 christos /* Preserve case for file names on ODS5 disks. */ 50 1.1.1.2 christos { "DECC$EFS_CASE_PRESERVE", 1 }, 51 1.1 christos 52 1.1 christos /* 53 1.1 christos * Enable multiple dots (and most characters) in ODS5 file names, while 54 1.1 christos * preserving VMS-ness of ";version". 55 1.1 christos */ 56 1.1.1.2 christos { "DECC$EFS_CHARSET", 1 }, 57 1.1 christos 58 1.1 christos /* List terminator. */ 59 1.1.1.2 christos { (char *)NULL, 0 } 60 1.1 christos }; 61 1.1 christos 62 1.1 christos /* LIB$INITIALIZE initialization function. */ 63 1.1 christos 64 1.1 christos static void decc_init(void) 65 1.1 christos { 66 1.1 christos char *openssl_debug_decc_init; 67 1.1 christos int verbose = 0; 68 1.1 christos int feat_index; 69 1.1 christos int feat_value; 70 1.1 christos int feat_value_max; 71 1.1 christos int feat_value_min; 72 1.1 christos int i; 73 1.1 christos int sts; 74 1.1 christos 75 1.1 christos /* Get debug option. */ 76 1.1 christos openssl_debug_decc_init = getenv("OPENSSL_DEBUG_DECC_INIT"); 77 1.1 christos if (openssl_debug_decc_init != NULL) { 78 1.1 christos verbose = strtol(openssl_debug_decc_init, NULL, 10); 79 1.1 christos if (verbose <= 0) { 80 1.1 christos verbose = 1; 81 1.1 christos } 82 1.1 christos } 83 1.1 christos 84 1.1 christos /* Set the global flag to indicate that LIB$INITIALIZE worked. */ 85 1.1 christos decc_init_done = 1; 86 1.1 christos 87 1.1 christos /* Loop through all items in the decc_feat_array[]. */ 88 1.1 christos 89 1.1 christos for (i = 0; decc_feat_array[i].name != NULL; i++) { 90 1.1 christos /* Get the feature index. */ 91 1.1 christos feat_index = decc$feature_get_index(decc_feat_array[i].name); 92 1.1 christos if (feat_index >= 0) { 93 1.1 christos /* Valid item. Collect its properties. */ 94 1.1 christos feat_value = decc$feature_get_value(feat_index, 1); 95 1.1 christos feat_value_min = decc$feature_get_value(feat_index, 2); 96 1.1 christos feat_value_max = decc$feature_get_value(feat_index, 3); 97 1.1 christos 98 1.1 christos /* Check the validity of our desired value. */ 99 1.1.1.2 christos if ((decc_feat_array[i].value >= feat_value_min) && (decc_feat_array[i].value <= feat_value_max)) { 100 1.1 christos /* Valid value. Set it if necessary. */ 101 1.1 christos if (feat_value != decc_feat_array[i].value) { 102 1.1 christos sts = decc$feature_set_value(feat_index, 103 1.1.1.2 christos 1, decc_feat_array[i].value); 104 1.1 christos 105 1.1 christos if (verbose > 1) { 106 1.1 christos fprintf(stderr, " %s = %d, sts = %d.\n", 107 1.1.1.2 christos decc_feat_array[i].name, 108 1.1.1.2 christos decc_feat_array[i].value, sts); 109 1.1 christos } 110 1.1 christos } 111 1.1 christos } else { 112 1.1 christos /* Invalid DECC feature value. */ 113 1.1 christos fprintf(stderr, 114 1.1.1.2 christos " INVALID DECC$FEATURE VALUE, %d: %d <= %s <= %d.\n", 115 1.1.1.2 christos feat_value, 116 1.1.1.2 christos feat_value_min, decc_feat_array[i].name, 117 1.1.1.2 christos feat_value_max); 118 1.1 christos } 119 1.1 christos } else { 120 1.1 christos /* Invalid DECC feature name. */ 121 1.1 christos fprintf(stderr, 122 1.1.1.2 christos " UNKNOWN DECC$FEATURE: %s.\n", decc_feat_array[i].name); 123 1.1 christos } 124 1.1 christos } 125 1.1 christos 126 1.1 christos if (verbose > 0) { 127 1.1 christos fprintf(stderr, " DECC_INIT complete.\n"); 128 1.1 christos } 129 1.1 christos } 130 1.1 christos 131 1.1 christos /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */ 132 1.1 christos 133 1.1.1.2 christos #pragma nostandard 134 1.1 christos 135 1.1 christos /* 136 1.1 christos * Establish the LIB$INITIALIZE PSECTs, with proper alignment and other 137 1.1 christos * attributes. Note that "nopic" is significant only on VAX. 138 1.1 christos */ 139 1.1.1.2 christos #pragma extern_model save 140 1.1 christos 141 1.1.1.2 christos #if __INITIAL_POINTER_SIZE == 64 142 1.1.1.2 christos #define PSECT_ALIGN 3 143 1.1.1.2 christos #else 144 1.1.1.2 christos #define PSECT_ALIGN 2 145 1.1.1.2 christos #endif 146 1.1 christos 147 1.1.1.2 christos #pragma extern_model strict_refdef "LIB$INITIALIZ" PSECT_ALIGN, nopic, nowrt 148 1.1 christos const int spare[8] = { 0 }; 149 1.1 christos 150 1.1.1.2 christos #pragma extern_model strict_refdef "LIB$INITIALIZE" PSECT_ALIGN, nopic, nowrt 151 1.1.1.2 christos void (*const x_decc_init)() = decc_init; 152 1.1 christos 153 1.1.1.2 christos #pragma extern_model restore 154 1.1 christos 155 1.1 christos /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */ 156 1.1 christos 157 1.1.1.2 christos #pragma extern_model save 158 1.1 christos 159 1.1 christos int LIB$INITIALIZE(void); 160 1.1 christos 161 1.1.1.2 christos #pragma extern_model strict_refdef 162 1.1 christos int dmy_lib$initialize = (int)LIB$INITIALIZE; 163 1.1 christos 164 1.1.1.2 christos #pragma extern_model restore 165 1.1 christos 166 1.1.1.2 christos #pragma standard 167 1.1 christos 168 1.1.1.2 christos #else /* def USE_DECC_INIT */ 169 1.1 christos 170 1.1 christos /* Dummy code to avoid a %CC-W-EMPTYFILE complaint. */ 171 1.1 christos int decc_init_dummy(void); 172 1.1 christos 173 1.1.1.2 christos #endif /* def USE_DECC_INIT */ 174