Browse code

- Convert all relative pathnames of files to absolute with respect to the main SER configuration file (the external TLS config file and modparams) or the TLS config file (file included from there). - Use get_abs_pathname from sip_router/ut.c instead of the local function get_pathname

Jan Janak authored on 08/02/2008 05:38:39
Showing 4 changed files
... ...
@@ -41,6 +41,7 @@
41 41
 #include "tls_config.h"
42 42
 #include "tls_util.h"
43 43
 #include "tls_domain.h"
44
+#include "tls_mod.h"
44 45
 
45 46
 #define MAX_TOKEN_LEN 256
46 47
 
... ...
@@ -681,7 +682,7 @@ static char* parse_file_val(token_t* token)
681 682
 	char* file, *res;
682 683
 	str val;
683 684
 	if (parse_string_val(&val, token) < 0) return 0;
684
-	file = get_pathname(&val);
685
+	file = get_abs_pathname(&tls_cfg_file, &val);
685 686
 	if (!file) return 0;
686 687
 	if (shm_asciiz_dup(&res, file) < 0) {
687 688
 		free(file);
... ...
@@ -995,7 +996,7 @@ tls_cfg_t* tls_load_config(str* filename)
995 996
 {
996 997
 	char* file;
997 998
 
998
-	file = get_pathname(filename);
999
+	file = get_abs_pathname(NULL, filename);
999 1000
 	if (!file) return 0;
1000 1001
 
1001 1002
 	pstate.f = fopen(file, "r");
... ...
@@ -51,12 +51,14 @@
51 51
 #include "../../timer_ticks.h"
52 52
 #include "../../timer.h" /* ticks_t */
53 53
 #include "../../tls_hooks.h"
54
+#include "../../ut.h"
54 55
 #include "tls_init.h"
55 56
 #include "tls_server.h"
56 57
 #include "tls_domain.h"
57 58
 #include "tls_select.h"
58 59
 #include "tls_config.h"
59 60
 #include "tls_rpc.h"
61
+#include "tls_util.h"
60 62
 #include "tls_mod.h"
61 63
 
62 64
 #ifndef TLS_HOOKS
... ...
@@ -168,7 +170,7 @@ int tls_send_timeout = 120;
168 170
 int tls_con_lifetime = 600; /* this value will be adjusted to ticks later */
169 171
 int tls_log = 3;
170 172
 int tls_session_cache = 0;
171
-str tls_session_id = STR_STATIC_INIT("ser-tls-0.9.0");
173
+str tls_session_id = STR_STATIC_INIT("ser-tls-2.1.0");
172 174
 str tls_cfg_file = STR_NULL;
173 175
 
174 176
 
... ...
@@ -261,6 +263,40 @@ static tls_cfg_t* tls_use_modparams(void)
261 263
 #endif
262 264
 
263 265
 
266
+static int fix_rel_pathnames(void)
267
+{
268
+	str tmp;
269
+  	
270
+	if (tls_cfg_file.s) {
271
+		tls_cfg_file.s = get_abs_pathname(NULL, &tls_cfg_file);
272
+		if (tls_cfg_file.s == NULL) return -1;
273
+		tls_cfg_file.len = strlen(tls_cfg_file.s);
274
+	}
275
+	
276
+	if (mod_params.pkey_file) {
277
+		tmp.s = mod_params.pkey_file;
278
+		tmp.len = strlen(tmp.s);
279
+		mod_params.pkey_file = get_abs_pathname(NULL, &tmp);
280
+		if (mod_params.pkey_file == NULL) return -1;
281
+	}
282
+	
283
+	if (mod_params.ca_file) {
284
+		tmp.s = mod_params.ca_file;
285
+		tmp.len = strlen(tmp.s);
286
+		mod_params.ca_file = get_abs_pathname(NULL, &tmp);
287
+		if (mod_params.ca_file == NULL) return -1;
288
+	}
289
+	
290
+	if (mod_params.cert_file) {
291
+		tmp.s = mod_params.cert_file;
292
+		tmp.len = strlen(tmp.s);
293
+		mod_params.cert_file = get_abs_pathname(NULL, &tmp);
294
+		if (mod_params.cert_file == NULL) return -1;
295
+	}
296
+	
297
+	return 0;
298
+}
299
+
264 300
 static int mod_init(void)
265 301
 {
266 302
 	int method;
... ...
@@ -278,6 +314,12 @@ static int mod_init(void)
278 314
 	}
279 315
 	mod_params.method = method;
280 316
 
317
+	/* Update relative paths of files configured through modparams, relative
318
+	 * pathnames will be converted to absolute and the directory of the main
319
+	 * SER configuration file will be used as reference.
320
+	 */
321
+	if (fix_rel_pathnames() < 0) return -1;
322
+
281 323
 	tls_cfg = (tls_cfg_t**)shm_malloc(sizeof(tls_cfg_t*));
282 324
 	if (!tls_cfg) {
283 325
 		ERR("Not enough shared memory left\n");
... ...
@@ -5,7 +5,7 @@
5 5
  *
6 6
  * Copyright (C) 2001-2003 FhG FOKUS
7 7
  * Copyright (C) 2004,2005 Free Software Foundation, Inc.
8
- * COpyright (C) 2005 iptelorg GmbH
8
+ * Copyright (C) 2005 iptelorg GmbH
9 9
  *
10 10
  * This file is part of ser, a free SIP server.
11 11
  *
... ...
@@ -119,52 +119,3 @@ void collect_garbage(void)
119 119
 	lock_release(tls_cfg_lock);
120 120
 }
121 121
 
122
-/** Get full pathname of file. This function returns the full pathname of a
123
- * file in parameter. If the parameter does not start with / then the pathname
124
- * of the file will be relative to the pathname of the main SER configuration
125
- * file.
126
- * @param filename A pathname to be converted to absolute.
127
- * @return A string containing absolute pathname, the string
128
- *         must be freed with free.
129
- */
130
-char* get_pathname(str* file)
131
-{
132
-	char* buf, *dir, *res;
133
-	int len;
134
-
135
-	if (!file || !file->s || file->len <= 0 || !cfg_file) {
136
-		BUG("tls: Cannot get full pathname of file\n");
137
-		return NULL;
138
-	}
139
-
140
-	if (file->s[0] == '/') {
141
-		/* This is an absolute pathname, make a zero terminated
142
-		 * copy and use it as it is */
143
-		if ((res = strndup(file->s, file->len)) == NULL) {
144
-			ERR("tls: No memory left (strndup failed)\n");
145
-		}
146
-	} else {
147
-		/* This is not an absolute pathname, make it relative
148
-		 * to the location of the main SER configuration file
149
-		 */
150
-		/* Make a copy, function dirname may modify the string */
151
-		if ((buf = strdup(cfg_file)) == NULL) {
152
-			ERR("tls: No memory left (strdup failed)\n");
153
-			return NULL;
154
-		}
155
-		dir = dirname(buf);
156
-
157
-		len = strlen(dir);
158
-		if ((res = malloc(len + 1 + file->len + 1)) == NULL) {
159
-			ERR("tls: No memory left (malloc failed)\n");
160
-			free(buf);
161
-			return NULL;
162
-		}
163
-		memcpy(res, dir, len);
164
-		res[len] = '/';
165
-		memcpy(res + len + 1, file->s, file->len);
166
-		res[len + 1 + file->len] = '\0';
167
-		free(buf);
168
-	}
169
-	return res;
170
-}
... ...
@@ -81,16 +81,4 @@ int shm_asciiz_dup(char** dest, char* val);
81 81
  */
82 82
 void collect_garbage(void);
83 83
 
84
-
85
-/** Get full pathname of file. This function returns the full pathname of a
86
- * file in parameter. If the parameter does not start with / then the pathname
87
- * of the file will be relative to the pathname of the main SER configuration
88
- * file.
89
- * @param filename A pathname to be converted to absolute.
90
- * @return A string containing absolute pathname, the string
91
- *         must be freed with free.
92
- */
93
-char* get_pathname(str* filename);
94
-
95
-
96 84
 #endif /* _TLS_UTIL_H */