1
0

dsalib_location.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #if defined( XP_WIN32 )
  39. #include <windows.h>
  40. #endif
  41. #include "dsalib.h"
  42. #include <stdio.h>
  43. #include <string.h>
  44. #include <stdlib.h>
  45. #include "nspr.h"
  46. #include "plstr.h"
  47. /*
  48. * Returns the server root. Info is
  49. * returned in a static area. The caller must copy it
  50. * for reuse if needed.
  51. */
  52. DS_EXPORT_SYMBOL char *
  53. ds_get_server_root()
  54. {
  55. char *root;
  56. if ( (root = getenv("NETSITE_ROOT")) == NULL )
  57. return(NULL);
  58. /* WIN32: Needed to take care of embedded space, */
  59. /* otherwise system() call fails */
  60. root = ds_makeshort( root );
  61. return root;
  62. }
  63. /*
  64. * Returns the install location of the server. Info is
  65. * returned in a static area. The caller must copy it
  66. * for reuse if needed.
  67. */
  68. DS_EXPORT_SYMBOL char *
  69. ds_get_install_root()
  70. {
  71. char *root;
  72. char *ds_name;
  73. static char install_root[PATH_MAX];
  74. if ( (root = ds_get_server_root()) == NULL )
  75. return(NULL);
  76. if ( (ds_name = ds_get_server_name()) == NULL )
  77. return(NULL);
  78. PR_snprintf(install_root, sizeof(install_root), "%s/%s", root, ds_name);
  79. return(install_root);
  80. }
  81. /*
  82. * Returns the config file location of the server. Info is
  83. * returned in a static area. The caller must copy it
  84. * for reuse if needed.
  85. */
  86. DS_EXPORT_SYMBOL char *
  87. ds_get_config_dir()
  88. {
  89. return getenv("DS_CONFIG_DIR");
  90. }
  91. /*
  92. * set config_dir to environment variable DS_CONFIG_DIR
  93. * to retrieve the value using ds_get_config_dir later.
  94. */
  95. DS_EXPORT_SYMBOL void
  96. ds_set_config_dir(char *config_dir)
  97. {
  98. static char env[PATH_MAX];
  99. PR_snprintf(env, sizeof(env), "DS_CONFIG_DIR=%s", config_dir);
  100. putenv(env);
  101. }
  102. /*
  103. * Returns the run dir of the server, where pid files are put.
  104. * Info is returned in a static area. The caller must copy it
  105. * for reuse if needed.
  106. */
  107. DS_EXPORT_SYMBOL char *
  108. ds_get_run_dir()
  109. {
  110. return getenv("DS_RUN_DIR");
  111. }
  112. /*
  113. * set run_dir to environment variable DS_RUN_DIR
  114. * to retrieve the value using ds_get_run_dir later.
  115. */
  116. DS_EXPORT_SYMBOL void
  117. ds_set_run_dir(char *run_dir)
  118. {
  119. static char env[PATH_MAX];
  120. PR_snprintf(env, sizeof(env), "DS_RUN_DIR=%s", run_dir);
  121. putenv(env);
  122. }
  123. /*
  124. * Returns the bakup dir of the server, where db backup files are put.
  125. * Info is returned in a static area. The caller must copy it
  126. * for reuse if needed.
  127. */
  128. DS_EXPORT_SYMBOL char *
  129. ds_get_bak_dir()
  130. {
  131. return getenv("DS_BAK_DIR");
  132. }
  133. /*
  134. * set bak_dir to environment variable DS_BAK_DIR
  135. * to retrieve the value using ds_get_bak_dir later.
  136. */
  137. DS_EXPORT_SYMBOL void
  138. ds_set_bak_dir(char *bak_dir)
  139. {
  140. static char env[PATH_MAX];
  141. PR_snprintf(env, sizeof(env), "DS_BAK_DIR=%s", bak_dir);
  142. putenv(env);
  143. }
  144. /*
  145. * Returns the tmp dir of the server, where tmp files are put.
  146. * Info is returned in a static area. The caller must copy it
  147. * for reuse if needed.
  148. */
  149. DS_EXPORT_SYMBOL char *
  150. ds_get_tmp_dir()
  151. {
  152. return getenv("DS_TMP_DIR");
  153. }
  154. /*
  155. * set bak_dir to environment variable DS_TMP_DIR
  156. * to retrieve the value using ds_get_tmp_dir later.
  157. */
  158. DS_EXPORT_SYMBOL void
  159. ds_set_tmp_dir(char *tmp_dir)
  160. {
  161. static char env[PATH_MAX];
  162. PR_snprintf(env, sizeof(env), "DS_TMP_DIR=%s", tmp_dir);
  163. putenv(env);
  164. }
  165. /*
  166. * Returns the install location of the server under the admserv
  167. * directory.
  168. */
  169. DS_EXPORT_SYMBOL char *
  170. ds_get_admserv_based_root()
  171. {
  172. char *root;
  173. char *ds_name;
  174. static char install_root[PATH_MAX];
  175. if ( (root = getenv("ADMSERV_ROOT")) == NULL )
  176. return(NULL);
  177. if ( (ds_name = ds_get_server_name()) == NULL )
  178. return(NULL);
  179. PR_snprintf(install_root, sizeof(install_root), "%s/%s", root, ds_name);
  180. return(install_root);
  181. }
  182. DS_EXPORT_SYMBOL char *
  183. ds_get_server_name()
  184. {
  185. if( getenv("SERVER_NAMES") )
  186. return( getenv("SERVER_NAMES") );
  187. else {
  188. static char logfile[PATH_MAX];
  189. char *buf;
  190. char *out = logfile;
  191. buf = getenv("SCRIPT_NAME");
  192. if ( buf && (*buf == '/') )
  193. buf++;
  194. while ( *buf && (*buf != '/') ) {
  195. *out++ = *buf++;
  196. }
  197. *out = 0;
  198. return logfile;
  199. }
  200. }
  201. DS_EXPORT_SYMBOL char *
  202. ds_get_logfile_name(int config_type)
  203. {
  204. char *filename;
  205. char **ds_config = NULL;
  206. static char logfile[PATH_MAX+1];
  207. if ( (ds_config = ds_get_config(DS_REAL_CONFIG)) == NULL ) {
  208. /* For DS 4.0, no error output if file doesn't exist - that's
  209. a normal situation */
  210. /* ds_send_error("ds_get_config(DS_REAL_CONFIG) == NULL", 0); */
  211. return(NULL);
  212. }
  213. filename = ds_get_value(ds_config, ds_get_var_name(config_type), 0, 1);
  214. if ( filename == NULL ) {
  215. /* For DS 4.0, no error output if file doesn't exist - that's
  216. a normal situation */
  217. /* ds_send_error("ds_get_logfile_name: filename == NULL", 0); */
  218. return(NULL);
  219. }
  220. if ( ((int) strlen(filename)) >= PATH_MAX ) {
  221. ds_send_error("ds_get_logfile_name: filename too long", 0);
  222. free(filename);
  223. return(NULL);
  224. }
  225. PL_strncpyz(logfile, filename, sizeof(logfile));
  226. free(filename);
  227. return(logfile);
  228. }
  229. DS_EXPORT_SYMBOL char *
  230. ds_get_errors_name()
  231. {
  232. return( ds_get_logfile_name(DS_ERRORLOG) );
  233. }
  234. DS_EXPORT_SYMBOL char *
  235. ds_get_access_name()
  236. {
  237. return( ds_get_logfile_name(DS_ACCESSLOG) );
  238. }
  239. DS_EXPORT_SYMBOL char *
  240. ds_get_audit_name()
  241. {
  242. return( ds_get_logfile_name(DS_AUDITFILE) );
  243. }