summaryrefslogtreecommitdiffstats
path: root/ldap/admin/lib/dsalib_location.c
blob: 06cbafb5f2cc7d290566a6c5e4697b73993281f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/** BEGIN COPYRIGHT BLOCK
 * Copyright 2001 Sun Microsystems, Inc.
 * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
 * All rights reserved.
 * END COPYRIGHT BLOCK **/
#if defined( XP_WIN32 )
#include <windows.h>
#endif
#include "dsalib.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/*
 * Returns the server root. Info is 
 * returned in a static area. The caller must copy it 
 * for reuse if needed.
 */
DS_EXPORT_SYMBOL char *
ds_get_server_root()
{
    char        *root;
 
    if ( (root = getenv("NETSITE_ROOT")) == NULL )
        return(NULL);

	/* WIN32: Needed to take care of embedded space, */
	/* otherwise system() call fails */
	root = ds_makeshort( root );

	return root;
}

/*
 * Returns the install location of the server. Info is 
 * returned in a static area. The caller must copy it 
 * for reuse if needed.
 */
DS_EXPORT_SYMBOL char *
ds_get_install_root()
{
    char        *root;
    char        *ds_name;
    static char install_root[PATH_MAX];
 
    if ( (root = ds_get_server_root()) == NULL )
        return(NULL);
    if ( (ds_name = ds_get_server_name()) == NULL )
        return(NULL);

    sprintf(install_root, "%s/%s", root, ds_name);
    return(install_root);
}

/*
 * Returns the install location of the server under the admserv
 * directory.
 */
DS_EXPORT_SYMBOL char *
ds_get_admserv_based_root()
{
    char        *root;
    char        *ds_name;
    static char install_root[PATH_MAX];
 
    if ( (root = getenv("ADMSERV_ROOT")) == NULL )
        return(NULL);
    if ( (ds_name = ds_get_server_name()) == NULL )
        return(NULL);
    sprintf(install_root, "%s/%s", root, ds_name);
    return(install_root);
}

DS_EXPORT_SYMBOL char *
ds_get_server_name()
{
    if( getenv("SERVER_NAMES") )
		return( getenv("SERVER_NAMES") );
	else {
		static char logfile[PATH_MAX];
		char *buf;
		char *out = logfile;
		buf = getenv("SCRIPT_NAME");
		if ( buf && (*buf == '/') )
			buf++;
		while ( *buf && (*buf != '/') ) {
			*out++ = *buf++;
		}
		*out = 0;
		return logfile;
	}
}

DS_EXPORT_SYMBOL char *
ds_get_logfile_name(int config_type)
{
    char        *filename;
    char	**ds_config = NULL;
    static char logfile[PATH_MAX];
 
    if ( (ds_config = ds_get_config(DS_REAL_CONFIG)) == NULL ) {
		/* For DS 4.0, no error output if file doesn't exist - that's
		   a normal situation */
		/* ds_send_error("ds_get_config(DS_REAL_CONFIG) == NULL", 0); */
        return(NULL);
    }
    filename = ds_get_value(ds_config, ds_get_var_name(config_type), 0, 1);

    if ( filename == NULL ) {
		/* For DS 4.0, no error output if file doesn't exist - that's
		   a normal situation */
		/* ds_send_error("ds_get_logfile_name: filename == NULL", 0); */
        return(NULL);
    }
    if ( ((int) strlen(filename)) >= PATH_MAX ) {
		ds_send_error("ds_get_logfile_name: filename too long", 0);
		free(filename);
        return(NULL);
    }
    strcpy(logfile, filename);
	free(filename);
    return(logfile);
}

DS_EXPORT_SYMBOL char *
ds_get_errors_name()
{
    return( ds_get_logfile_name(DS_ERRORLOG) );
}

DS_EXPORT_SYMBOL char *
ds_get_access_name()
{
    return( ds_get_logfile_name(DS_ACCESSLOG) );
}

DS_EXPORT_SYMBOL char *
ds_get_audit_name()
{
    return( ds_get_logfile_name(DS_AUDITFILE) );
}