curl_crtl_init.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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
  99. (const char * logname,
  100. char * value,
  101. int value_len)
  102. {
  103. const $DESCRIPTOR(table_dsc, "LNM$FILE_DEV");
  104. const unsigned long attr = LNM$M_CASE_BLIND;
  105. struct dsc$descriptor_s name_dsc;
  106. int status;
  107. unsigned short result;
  108. struct itmlst_3 itlst[2];
  109. itlst[0].buflen = value_len;
  110. itlst[0].itmcode = LNM$_STRING;
  111. itlst[0].bufadr = value;
  112. itlst[0].retlen = &result;
  113. itlst[1].buflen = 0;
  114. itlst[1].itmcode = 0;
  115. name_dsc.dsc$w_length = strlen(logname);
  116. name_dsc.dsc$a_pointer = (char *)logname;
  117. name_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
  118. name_dsc.dsc$b_class = DSC$K_CLASS_S;
  119. status = SYS$TRNLNM(&attr, &table_dsc, &name_dsc, 0, itlst);
  120. if($VMS_STATUS_SUCCESS(status)) {
  121. /* Null terminate and return the string */
  122. /*--------------------------------------*/
  123. value[result] = '\0';
  124. }
  125. return status;
  126. }
  127. /* How to simply create a logical name */
  128. static int sys_crelnm
  129. (const char * logname,
  130. const char * value)
  131. {
  132. int ret_val;
  133. const char * proc_table = "LNM$PROCESS_TABLE";
  134. struct dsc$descriptor_s proc_table_dsc;
  135. struct dsc$descriptor_s logname_dsc;
  136. struct itmlst_3 item_list[2];
  137. proc_table_dsc.dsc$a_pointer = (char *) proc_table;
  138. proc_table_dsc.dsc$w_length = strlen(proc_table);
  139. proc_table_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
  140. proc_table_dsc.dsc$b_class = DSC$K_CLASS_S;
  141. logname_dsc.dsc$a_pointer = (char *) logname;
  142. logname_dsc.dsc$w_length = strlen(logname);
  143. logname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
  144. logname_dsc.dsc$b_class = DSC$K_CLASS_S;
  145. item_list[0].buflen = strlen(value);
  146. item_list[0].itmcode = LNM$_STRING;
  147. item_list[0].bufadr = (char *)value;
  148. item_list[0].retlen = NULL;
  149. item_list[1].buflen = 0;
  150. item_list[1].itmcode = 0;
  151. ret_val = SYS$CRELNM(NULL, &proc_table_dsc, &logname_dsc, NULL, item_list);
  152. return ret_val;
  153. }
  154. /* Start of DECC RTL Feature handling */
  155. /*
  156. ** Sets default value for a feature
  157. */
  158. #ifdef __VAX
  159. static void set_feature_default(const char *name, const char *value)
  160. {
  161. sys_crelnm(name, value);
  162. }
  163. #else
  164. static void set_feature_default(const char *name, int value)
  165. {
  166. int index;
  167. index = decc$feature_get_index(name);
  168. if(index > 0)
  169. decc$feature_set_value (index, 0, value);
  170. }
  171. #endif
  172. static void set_features(void)
  173. {
  174. int status;
  175. char unix_shell_name[255];
  176. int use_unix_settings = 1;
  177. status = sys_trnlnm("GNV$UNIX_SHELL",
  178. unix_shell_name, sizeof unix_shell_name -1);
  179. if(!$VMS_STATUS_SUCCESS(status)) {
  180. use_unix_settings = 0;
  181. }
  182. /* ACCESS should check ACLs or it is lying. */
  183. set_feature_default("DECC$ACL_ACCESS_CHECK", ENABLE);
  184. /* We always want the new parse style */
  185. set_feature_default ("DECC$ARGV_PARSE_STYLE" , ENABLE);
  186. /* Unless we are in POSIX compliant mode, we want the old POSIX root
  187. * enabled.
  188. */
  189. set_feature_default("DECC$DISABLE_POSIX_ROOT", DISABLE);
  190. /* EFS charset, means UTF-8 support */
  191. /* VTF-7 support is controlled by a feature setting called UTF8 */
  192. set_feature_default ("DECC$EFS_CHARSET", ENABLE);
  193. set_feature_default ("DECC$EFS_CASE_PRESERVE", ENABLE);
  194. /* Support timestamps when available */
  195. set_feature_default ("DECC$EFS_FILE_TIMESTAMPS", ENABLE);
  196. /* Cache environment variables - performance improvements */
  197. set_feature_default ("DECC$ENABLE_GETENV_CACHE", ENABLE);
  198. /* Start out with new file attribute inheritance */
  199. #ifdef __VAX
  200. set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", "2");
  201. #else
  202. set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", 2);
  203. #endif
  204. /* Don't display trailing dot after files without type */
  205. set_feature_default ("DECC$READDIR_DROPDOTNOTYPE", ENABLE);
  206. /* For standard output channels buffer output until terminator */
  207. /* Gets rid of output logs with single character lines in them. */
  208. set_feature_default ("DECC$STDIO_CTX_EOL", ENABLE);
  209. /* Fix mv aa.bb aa */
  210. set_feature_default ("DECC$RENAME_NO_INHERIT", ENABLE);
  211. if(use_unix_settings) {
  212. /* POSIX requires that open files be able to be removed */
  213. set_feature_default ("DECC$ALLOW_REMOVE_OPEN_FILES", ENABLE);
  214. /* Default to outputting Unix filenames in VMS routines */
  215. set_feature_default ("DECC$FILENAME_UNIX_ONLY", ENABLE);
  216. /* FILENAME_UNIX_ONLY Implicitly sets */
  217. /* decc$disable_to_vms_logname_translation */
  218. set_feature_default ("DECC$FILE_PERMISSION_UNIX", ENABLE);
  219. set_feature_default ("DECC$FILE_SHARING", ENABLE);
  220. set_feature_default ("DECC$FILE_OWNER_UNIX", ENABLE);
  221. set_feature_default ("DECC$POSIX_SEEK_STREAM_FILE", ENABLE);
  222. } else {
  223. set_feature_default("DECC$FILENAME_UNIX_REPORT", ENABLE);
  224. }
  225. /* When reporting Unix filenames, glob the same way */
  226. set_feature_default ("DECC$GLOB_UNIX_STYLE", ENABLE);
  227. /* The VMS version numbers on Unix filenames is incompatible with most */
  228. /* ported packages. */
  229. set_feature_default("DECC$FILENAME_UNIX_NO_VERSION", ENABLE);
  230. /* The VMS version numbers on Unix filenames is incompatible with most */
  231. /* ported packages. */
  232. set_feature_default("DECC$UNIX_PATH_BEFORE_LOGNAME", ENABLE);
  233. /* Set strtol to proper behavior */
  234. set_feature_default("DECC$STRTOL_ERANGE", ENABLE);
  235. /* Commented here to prevent future bugs: A program or user should */
  236. /* never ever enable DECC$POSIX_STYLE_UID. */
  237. /* It will probably break all code that accesses UIDs */
  238. /* do_not_set_default ("DECC$POSIX_STYLE_UID", TRUE); */
  239. }
  240. /* Some boilerplate to force this to be a proper LIB$INITIALIZE section */
  241. #pragma nostandard
  242. #pragma extern_model save
  243. #ifdef __VAX
  244. #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long, nopic
  245. #else
  246. #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long
  247. # if __INITIAL_POINTER_SIZE
  248. # pragma __pointer_size __save
  249. # pragma __pointer_size 32
  250. # else
  251. # pragma __required_pointer_size __save
  252. # pragma __required_pointer_size 32
  253. # endif
  254. #endif
  255. /* Set our contribution to the LIB$INITIALIZE array */
  256. void (* const iniarray[])(void) = {set_features, } ;
  257. #ifndef __VAX
  258. # if __INITIAL_POINTER_SIZE
  259. # pragma __pointer_size __restore
  260. # else
  261. # pragma __required_pointer_size __restore
  262. # endif
  263. #endif
  264. /*
  265. ** Force a reference to LIB$INITIALIZE to ensure it
  266. ** exists in the image.
  267. */
  268. int LIB$INITIALIZE(void);
  269. #ifdef __DECC
  270. #pragma extern_model strict_refdef
  271. #endif
  272. int lib_init_ref = (int) LIB$INITIALIZE;
  273. #ifdef __DECC
  274. #pragma extern_model restore
  275. #pragma standard
  276. #endif