curl_crtl_init.c 9.9 KB

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