1 /* File: curl_crtl_init.c
2 *
3 * This file makes sure that the DECC Unix settings are correct for
4 * the mode the the program is run in.
5 *
6 * The CRTL has not been initialized at the time that these routines
7 * are called, so many routines can not be called.
8 *
9 * This is a module that provides a LIB$INITIALIZE routine that
10 * will turn on some CRTL features that are not enabled by default.
11 *
12 * The CRTL features can also be turned on via logical names, but that
13 * impacts all programs and some aren't ready, willing, or able to handle
14 * those settings.
15 *
16 * On VMS versions that are too old to use the feature setting API, this
17 * module falls back to using logical names.
18 *
19 * Copyright 2013, John Malmberg
20 *
21 * Permission to use, copy, modify, and/or distribute this software for any
22 * purpose with or without fee is hereby granted, provided that the above
23 * copyright notice and this permission notice appear in all copies.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
26 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
28 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
30 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
31 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 *
33 */
34
35 /* Unix headers */
36 #include <stdio.h>
37 #include <string.h>
38
39 /* VMS specific headers */
40 #include <descrip.h>
41 #include <lnmdef.h>
42 #include <stsdef.h>
43
44 #pragma member_alignment save
45 #pragma nomember_alignment longword
46 #pragma message save
47 #pragma message disable misalgndmem
48 struct itmlst_3 {
49 unsigned short int buflen;
50 unsigned short int itmcode;
51 void *bufadr;
52 unsigned short int *retlen;
53 };
54 #pragma message restore
55 #pragma member_alignment restore
56
57 #ifdef __VAX
58 #define ENABLE "ENABLE"
59 #define DISABLE "DISABLE"
60 #else
61
62 #define ENABLE TRUE
63 #define DISABLE 0
64 int decc$feature_get_index (const char *name);
65 int decc$feature_set_value (int index, int mode, int value);
66 #endif
67
68 int SYS$TRNLNM(
69 const unsigned long * attr,
70 const struct dsc$descriptor_s * table_dsc,
71 struct dsc$descriptor_s * name_dsc,
72 const unsigned char * acmode,
73 const struct itmlst_3 * item_list);
74 int SYS$CRELNM(
75 const unsigned long * attr,
76 const struct dsc$descriptor_s * table_dsc,
77 const struct dsc$descriptor_s * name_dsc,
78 const unsigned char * acmode,
79 const struct itmlst_3 * item_list);
80
81
82 /* Take all the fun out of simply looking up a logical name */
sys_trnlnm(const char * logname,char * value,int value_len)83 static int sys_trnlnm
84 (const char * logname,
85 char * value,
86 int value_len)
87 {
88 const $DESCRIPTOR(table_dsc, "LNM$FILE_DEV");
89 const unsigned long attr = LNM$M_CASE_BLIND;
90 struct dsc$descriptor_s name_dsc;
91 int status;
92 unsigned short result;
93 struct itmlst_3 itlst[2];
94
95 itlst[0].buflen = value_len;
96 itlst[0].itmcode = LNM$_STRING;
97 itlst[0].bufadr = value;
98 itlst[0].retlen = &result;
99
100 itlst[1].buflen = 0;
101 itlst[1].itmcode = 0;
102
103 name_dsc.dsc$w_length = strlen(logname);
104 name_dsc.dsc$a_pointer = (char *)logname;
105 name_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
106 name_dsc.dsc$b_class = DSC$K_CLASS_S;
107
108 status = SYS$TRNLNM(&attr, &table_dsc, &name_dsc, 0, itlst);
109
110 if ($VMS_STATUS_SUCCESS(status)) {
111
112 /* Null terminate and return the string */
113 /*--------------------------------------*/
114 value[result] = '\0';
115 }
116
117 return status;
118 }
119
120 /* How to simply create a logical name */
sys_crelnm(const char * logname,const char * value)121 static int sys_crelnm
122 (const char * logname,
123 const char * value)
124 {
125 int ret_val;
126 const char * proc_table = "LNM$PROCESS_TABLE";
127 struct dsc$descriptor_s proc_table_dsc;
128 struct dsc$descriptor_s logname_dsc;
129 struct itmlst_3 item_list[2];
130
131 proc_table_dsc.dsc$a_pointer = (char *) proc_table;
132 proc_table_dsc.dsc$w_length = strlen(proc_table);
133 proc_table_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
134 proc_table_dsc.dsc$b_class = DSC$K_CLASS_S;
135
136 logname_dsc.dsc$a_pointer = (char *) logname;
137 logname_dsc.dsc$w_length = strlen(logname);
138 logname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
139 logname_dsc.dsc$b_class = DSC$K_CLASS_S;
140
141 item_list[0].buflen = strlen(value);
142 item_list[0].itmcode = LNM$_STRING;
143 item_list[0].bufadr = (char *)value;
144 item_list[0].retlen = NULL;
145
146 item_list[1].buflen = 0;
147 item_list[1].itmcode = 0;
148
149 ret_val = SYS$CRELNM(NULL, &proc_table_dsc, &logname_dsc, NULL, item_list);
150
151 return ret_val;
152 }
153
154
155 /* Start of DECC RTL Feature handling */
156
157 /*
158 ** Sets default value for a feature
159 */
160 #ifdef __VAX
set_feature_default(const char * name,const char * value)161 static void set_feature_default(const char *name, const char *value)
162 {
163 sys_crelnm(name, value);
164 }
165 #else
set_feature_default(const char * name,int value)166 static void set_feature_default(const char *name, int value)
167 {
168 int index;
169
170 index = decc$feature_get_index(name);
171
172 if (index > 0)
173 decc$feature_set_value (index, 0, value);
174 }
175 #endif
176
set_features(void)177 static void set_features(void)
178 {
179 int status;
180 char unix_shell_name[255];
181 int use_unix_settings = 1;
182
183 status = sys_trnlnm("GNV$UNIX_SHELL",
184 unix_shell_name, sizeof unix_shell_name -1);
185 if (!$VMS_STATUS_SUCCESS(status)) {
186 use_unix_settings = 0;
187 }
188
189 /* ACCESS should check ACLs or it is lying. */
190 set_feature_default("DECC$ACL_ACCESS_CHECK", ENABLE);
191
192 /* We always want the new parse style */
193 set_feature_default ("DECC$ARGV_PARSE_STYLE" , ENABLE);
194
195
196 /* Unless we are in POSIX compliant mode, we want the old POSIX root
197 * enabled.
198 */
199 set_feature_default("DECC$DISABLE_POSIX_ROOT", DISABLE);
200
201 /* EFS charset, means UTF-8 support */
202 /* VTF-7 support is controlled by a feature setting called UTF8 */
203 set_feature_default ("DECC$EFS_CHARSET", ENABLE);
204 set_feature_default ("DECC$EFS_CASE_PRESERVE", ENABLE);
205
206 /* Support timestamps when available */
207 set_feature_default ("DECC$EFS_FILE_TIMESTAMPS", ENABLE);
208
209 /* Cache environment variables - performance improvements */
210 set_feature_default ("DECC$ENABLE_GETENV_CACHE", ENABLE);
211
212 /* Start out with new file attribute inheritance */
213 #ifdef __VAX
214 set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", "2");
215 #else
216 set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", 2);
217 #endif
218
219 /* Don't display trailing dot after files without type */
220 set_feature_default ("DECC$READDIR_DROPDOTNOTYPE", ENABLE);
221
222 /* For standard output channels buffer output until terminator */
223 /* Gets rid of output logs with single character lines in them. */
224 set_feature_default ("DECC$STDIO_CTX_EOL", ENABLE);
225
226 /* Fix mv aa.bb aa */
227 set_feature_default ("DECC$RENAME_NO_INHERIT", ENABLE);
228
229 if (use_unix_settings) {
230
231 /* POSIX requires that open files be able to be removed */
232 set_feature_default ("DECC$ALLOW_REMOVE_OPEN_FILES", ENABLE);
233
234 /* Default to outputting Unix filenames in VMS routines */
235 set_feature_default ("DECC$FILENAME_UNIX_ONLY", ENABLE);
236 /* FILENAME_UNIX_ONLY Implicitly sets */
237 /* decc$disable_to_vms_logname_translation */
238
239 set_feature_default ("DECC$FILE_PERMISSION_UNIX", ENABLE);
240
241 set_feature_default ("DECC$FILE_SHARING", ENABLE);
242
243 set_feature_default ("DECC$FILE_OWNER_UNIX", ENABLE);
244 set_feature_default ("DECC$POSIX_SEEK_STREAM_FILE", ENABLE);
245
246 } else {
247 set_feature_default("DECC$FILENAME_UNIX_REPORT", ENABLE);
248 }
249
250 /* When reporting Unix filenames, glob the same way */
251 set_feature_default ("DECC$GLOB_UNIX_STYLE", ENABLE);
252
253 /* The VMS version numbers on Unix filenames is incompatible with most */
254 /* ported packages. */
255 set_feature_default("DECC$FILENAME_UNIX_NO_VERSION", ENABLE);
256
257 /* The VMS version numbers on Unix filenames is incompatible with most */
258 /* ported packages. */
259 set_feature_default("DECC$UNIX_PATH_BEFORE_LOGNAME", ENABLE);
260
261 /* Set strtol to proper behavior */
262 set_feature_default("DECC$STRTOL_ERANGE", ENABLE);
263
264 /* Commented here to prevent future bugs: A program or user should */
265 /* never ever enable DECC$POSIX_STYLE_UID. */
266 /* It will probably break all code that accesses UIDs */
267 /* do_not_set_default ("DECC$POSIX_STYLE_UID", TRUE); */
268 }
269
270
271 /* Some boilerplate to force this to be a proper LIB$INITIALIZE section */
272
273 #pragma nostandard
274 #pragma extern_model save
275 #ifdef __VAX
276 #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long, nopic
277 #else
278 #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long
279 # if __INITIAL_POINTER_SIZE
280 # pragma __pointer_size __save
281 # pragma __pointer_size 32
282 # else
283 # pragma __required_pointer_size __save
284 # pragma __required_pointer_size 32
285 # endif
286 #endif
287 /* Set our contribution to the LIB$INITIALIZE array */
288 void (* const iniarray[])(void) = {set_features, } ;
289 #ifndef __VAX
290 # if __INITIAL_POINTER_SIZE
291 # pragma __pointer_size __restore
292 # else
293 # pragma __required_pointer_size __restore
294 # endif
295 #endif
296
297
298 /*
299 ** Force a reference to LIB$INITIALIZE to ensure it
300 ** exists in the image.
301 */
302 int LIB$INITIALIZE(void);
303 #ifdef __DECC
304 #pragma extern_model strict_refdef
305 #endif
306 int lib_init_ref = (int) LIB$INITIALIZE;
307 #ifdef __DECC
308 #pragma extern_model restore
309 #pragma standard
310 #endif
311