1
0

dsalib_location.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 install location of the server under the admserv
  125. * directory.
  126. */
  127. DS_EXPORT_SYMBOL char *
  128. ds_get_admserv_based_root()
  129. {
  130. char *root;
  131. char *ds_name;
  132. static char install_root[PATH_MAX];
  133. if ( (root = getenv("ADMSERV_ROOT")) == NULL )
  134. return(NULL);
  135. if ( (ds_name = ds_get_server_name()) == NULL )
  136. return(NULL);
  137. PR_snprintf(install_root, sizeof(install_root), "%s/%s", root, ds_name);
  138. return(install_root);
  139. }
  140. DS_EXPORT_SYMBOL char *
  141. ds_get_server_name()
  142. {
  143. if( getenv("SERVER_NAMES") )
  144. return( getenv("SERVER_NAMES") );
  145. else {
  146. static char logfile[PATH_MAX];
  147. char *buf;
  148. char *out = logfile;
  149. buf = getenv("SCRIPT_NAME");
  150. if ( buf && (*buf == '/') )
  151. buf++;
  152. while ( *buf && (*buf != '/') ) {
  153. *out++ = *buf++;
  154. }
  155. *out = 0;
  156. return logfile;
  157. }
  158. }
  159. DS_EXPORT_SYMBOL char *
  160. ds_get_logfile_name(int config_type)
  161. {
  162. char *filename;
  163. char **ds_config = NULL;
  164. static char logfile[PATH_MAX+1];
  165. if ( (ds_config = ds_get_config(DS_REAL_CONFIG)) == NULL ) {
  166. /* For DS 4.0, no error output if file doesn't exist - that's
  167. a normal situation */
  168. /* ds_send_error("ds_get_config(DS_REAL_CONFIG) == NULL", 0); */
  169. return(NULL);
  170. }
  171. filename = ds_get_value(ds_config, ds_get_var_name(config_type), 0, 1);
  172. if ( filename == NULL ) {
  173. /* For DS 4.0, no error output if file doesn't exist - that's
  174. a normal situation */
  175. /* ds_send_error("ds_get_logfile_name: filename == NULL", 0); */
  176. return(NULL);
  177. }
  178. if ( ((int) strlen(filename)) >= PATH_MAX ) {
  179. ds_send_error("ds_get_logfile_name: filename too long", 0);
  180. free(filename);
  181. return(NULL);
  182. }
  183. PL_strncpyz(logfile, filename, sizeof(logfile));
  184. free(filename);
  185. return(logfile);
  186. }
  187. DS_EXPORT_SYMBOL char *
  188. ds_get_errors_name()
  189. {
  190. return( ds_get_logfile_name(DS_ERRORLOG) );
  191. }
  192. DS_EXPORT_SYMBOL char *
  193. ds_get_access_name()
  194. {
  195. return( ds_get_logfile_name(DS_ACCESSLOG) );
  196. }
  197. DS_EXPORT_SYMBOL char *
  198. ds_get_audit_name()
  199. {
  200. return( ds_get_logfile_name(DS_AUDITFILE) );
  201. }