curl_crtl_init.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2020, 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. ***************************************************************************/
  22. /* File: curl_crtl_init.c
  23. *
  24. * This file makes sure that the DECC Unix settings are correct for
  25. * the mode the program is run in.
  26. *
  27. * The CRTL has not been initialized at the time that these routines
  28. * are called, so many routines can not be called.
  29. *
  30. * This is a module that provides a LIB$INITIALIZE routine that
  31. * will turn on some CRTL features that are not enabled by default.
  32. *
  33. * The CRTL features can also be turned on via logical names, but that
  34. * impacts all programs and some aren't ready, willing, or able to handle
  35. * those settings.
  36. *
  37. * On VMS versions that are too old to use the feature setting API, this
  38. * module falls back to using logical names.
  39. *
  40. * Copyright 2013, John Malmberg
  41. *
  42. * Permission to use, copy, modify, and/or distribute this software for any
  43. * purpose with or without fee is hereby granted, provided that the above
  44. * copyright notice and this permission notice appear in all copies.
  45. *
  46. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  47. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  48. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  49. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  50. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  51. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  52. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  53. *
  54. */
  55. /* Unix headers */
  56. #include <stdio.h>
  57. #include <string.h>
  58. /* VMS specific headers */
  59. #include <descrip.h>
  60. #include <lnmdef.h>
  61. #include <stsdef.h>
  62. #pragma member_alignment save
  63. #pragma nomember_alignment longword
  64. #pragma message save
  65. #pragma message disable misalgndmem
  66. struct itmlst_3 {
  67. unsigned short int buflen;
  68. unsigned short int itmcode;
  69. void *bufadr;
  70. unsigned short int *retlen;
  71. };
  72. #pragma message restore
  73. #pragma member_alignment restore
  74. #ifdef __VAX
  75. #define ENABLE "ENABLE"
  76. #define DISABLE "DISABLE"
  77. #else
  78. #define ENABLE TRUE
  79. #define DISABLE 0
  80. int decc$feature_get_index (const char *name);
  81. int decc$feature_set_value (int index, int mode, int value);
  82. #endif
  83. int SYS$TRNLNM(
  84. const unsigned long * attr,
  85. const struct dsc$descriptor_s * table_dsc,
  86. struct dsc$descriptor_s * name_dsc,
  87. const unsigned char * acmode,
  88. const struct itmlst_3 * item_list);
  89. int SYS$CRELNM(
  90. const unsigned long * attr,
  91. const struct dsc$descriptor_s * table_dsc,
  92. const struct dsc$descriptor_s * name_dsc,
  93. const unsigned char * acmode,
  94. const struct itmlst_3 * item_list);
  95. /* Take all the fun out of simply looking up a logical name */
  96. static int sys_trnlnm
  97. (const char * logname,
  98. char * value,
  99. int value_len)
  100. {
  101. const $DESCRIPTOR(table_dsc, "LNM$FILE_DEV");
  102. const unsigned long attr = LNM$M_CASE_BLIND;
  103. struct dsc$descriptor_s name_dsc;
  104. int status;
  105. unsigned short result;
  106. struct itmlst_3 itlst[2];
  107. itlst[0].buflen = value_len;
  108. itlst[0].itmcode = LNM$_STRING;
  109. itlst[0].bufadr = value;
  110. itlst[0].retlen = &result;
  111. itlst[1].buflen = 0;
  112. itlst[1].itmcode = 0;
  113. name_dsc.dsc$w_length = strlen(logname);
  114. name_dsc.dsc$a_pointer = (char *)logname;
  115. name_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
  116. name_dsc.dsc$b_class = DSC$K_CLASS_S;
  117. status = SYS$TRNLNM(&attr, &table_dsc, &name_dsc, 0, itlst);
  118. if ($VMS_STATUS_SUCCESS(status)) {
  119. /* Null terminate and return the string */
  120. /*--------------------------------------*/
  121. value[result] = '\0';
  122. }
  123. return status;
  124. }
  125. /* How to simply create a logical name */
  126. static int sys_crelnm
  127. (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. } else {
  221. set_feature_default("DECC$FILENAME_UNIX_REPORT", ENABLE);
  222. }
  223. /* When reporting Unix filenames, glob the same way */
  224. set_feature_default ("DECC$GLOB_UNIX_STYLE", ENABLE);
  225. /* The VMS version numbers on Unix filenames is incompatible with most */
  226. /* ported packages. */
  227. set_feature_default("DECC$FILENAME_UNIX_NO_VERSION", ENABLE);
  228. /* The VMS version numbers on Unix filenames is incompatible with most */
  229. /* ported packages. */
  230. set_feature_default("DECC$UNIX_PATH_BEFORE_LOGNAME", ENABLE);
  231. /* Set strtol to proper behavior */
  232. set_feature_default("DECC$STRTOL_ERANGE", ENABLE);
  233. /* Commented here to prevent future bugs: A program or user should */
  234. /* never ever enable DECC$POSIX_STYLE_UID. */
  235. /* It will probably break all code that accesses UIDs */
  236. /* do_not_set_default ("DECC$POSIX_STYLE_UID", TRUE); */
  237. }
  238. /* Some boilerplate to force this to be a proper LIB$INITIALIZE section */
  239. #pragma nostandard
  240. #pragma extern_model save
  241. #ifdef __VAX
  242. #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long, nopic
  243. #else
  244. #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long
  245. # if __INITIAL_POINTER_SIZE
  246. # pragma __pointer_size __save
  247. # pragma __pointer_size 32
  248. # else
  249. # pragma __required_pointer_size __save
  250. # pragma __required_pointer_size 32
  251. # endif
  252. #endif
  253. /* Set our contribution to the LIB$INITIALIZE array */
  254. void (* const iniarray[])(void) = {set_features, } ;
  255. #ifndef __VAX
  256. # if __INITIAL_POINTER_SIZE
  257. # pragma __pointer_size __restore
  258. # else
  259. # pragma __required_pointer_size __restore
  260. # endif
  261. #endif
  262. /*
  263. ** Force a reference to LIB$INITIALIZE to ensure it
  264. ** exists in the image.
  265. */
  266. int LIB$INITIALIZE(void);
  267. #ifdef __DECC
  268. #pragma extern_model strict_refdef
  269. #endif
  270. int lib_init_ref = (int) LIB$INITIALIZE;
  271. #ifdef __DECC
  272. #pragma extern_model restore
  273. #pragma standard
  274. #endif