2
0
Эх сурвалжийг харах

- 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 17 жил өмнө
parent
commit
d128c59d5f

+ 3 - 2
modules/tls/tls_config.c

@@ -41,6 +41,7 @@
 #include "tls_config.h"
 #include "tls_util.h"
 #include "tls_domain.h"
+#include "tls_mod.h"
 
 #define MAX_TOKEN_LEN 256
 
@@ -681,7 +682,7 @@ static char* parse_file_val(token_t* token)
 	char* file, *res;
 	str val;
 	if (parse_string_val(&val, token) < 0) return 0;
-	file = get_pathname(&val);
+	file = get_abs_pathname(&tls_cfg_file, &val);
 	if (!file) return 0;
 	if (shm_asciiz_dup(&res, file) < 0) {
 		free(file);
@@ -995,7 +996,7 @@ tls_cfg_t* tls_load_config(str* filename)
 {
 	char* file;
 
-	file = get_pathname(filename);
+	file = get_abs_pathname(NULL, filename);
 	if (!file) return 0;
 
 	pstate.f = fopen(file, "r");

+ 43 - 1
modules/tls/tls_mod.c

@@ -51,12 +51,14 @@
 #include "../../timer_ticks.h"
 #include "../../timer.h" /* ticks_t */
 #include "../../tls_hooks.h"
+#include "../../ut.h"
 #include "tls_init.h"
 #include "tls_server.h"
 #include "tls_domain.h"
 #include "tls_select.h"
 #include "tls_config.h"
 #include "tls_rpc.h"
+#include "tls_util.h"
 #include "tls_mod.h"
 
 #ifndef TLS_HOOKS
@@ -168,7 +170,7 @@ int tls_send_timeout = 120;
 int tls_con_lifetime = 600; /* this value will be adjusted to ticks later */
 int tls_log = 3;
 int tls_session_cache = 0;
-str tls_session_id = STR_STATIC_INIT("ser-tls-0.9.0");
+str tls_session_id = STR_STATIC_INIT("ser-tls-2.1.0");
 str tls_cfg_file = STR_NULL;
 
 
@@ -261,6 +263,40 @@ static tls_cfg_t* tls_use_modparams(void)
 #endif
 
 
+static int fix_rel_pathnames(void)
+{
+	str tmp;
+  	
+	if (tls_cfg_file.s) {
+		tls_cfg_file.s = get_abs_pathname(NULL, &tls_cfg_file);
+		if (tls_cfg_file.s == NULL) return -1;
+		tls_cfg_file.len = strlen(tls_cfg_file.s);
+	}
+	
+	if (mod_params.pkey_file) {
+		tmp.s = mod_params.pkey_file;
+		tmp.len = strlen(tmp.s);
+		mod_params.pkey_file = get_abs_pathname(NULL, &tmp);
+		if (mod_params.pkey_file == NULL) return -1;
+	}
+	
+	if (mod_params.ca_file) {
+		tmp.s = mod_params.ca_file;
+		tmp.len = strlen(tmp.s);
+		mod_params.ca_file = get_abs_pathname(NULL, &tmp);
+		if (mod_params.ca_file == NULL) return -1;
+	}
+	
+	if (mod_params.cert_file) {
+		tmp.s = mod_params.cert_file;
+		tmp.len = strlen(tmp.s);
+		mod_params.cert_file = get_abs_pathname(NULL, &tmp);
+		if (mod_params.cert_file == NULL) return -1;
+	}
+	
+	return 0;
+}
+
 static int mod_init(void)
 {
 	int method;
@@ -278,6 +314,12 @@ static int mod_init(void)
 	}
 	mod_params.method = method;
 
+	/* Update relative paths of files configured through modparams, relative
+	 * pathnames will be converted to absolute and the directory of the main
+	 * SER configuration file will be used as reference.
+	 */
+	if (fix_rel_pathnames() < 0) return -1;
+
 	tls_cfg = (tls_cfg_t**)shm_malloc(sizeof(tls_cfg_t*));
 	if (!tls_cfg) {
 		ERR("Not enough shared memory left\n");

+ 1 - 50
modules/tls/tls_util.c

@@ -5,7 +5,7 @@
  *
  * Copyright (C) 2001-2003 FhG FOKUS
  * Copyright (C) 2004,2005 Free Software Foundation, Inc.
- * COpyright (C) 2005 iptelorg GmbH
+ * Copyright (C) 2005 iptelorg GmbH
  *
  * This file is part of ser, a free SIP server.
  *
@@ -119,52 +119,3 @@ void collect_garbage(void)
 	lock_release(tls_cfg_lock);
 }
 
-/** Get full pathname of file. This function returns the full pathname of a
- * file in parameter. If the parameter does not start with / then the pathname
- * of the file will be relative to the pathname of the main SER configuration
- * file.
- * @param filename A pathname to be converted to absolute.
- * @return A string containing absolute pathname, the string
- *         must be freed with free.
- */
-char* get_pathname(str* file)
-{
-	char* buf, *dir, *res;
-	int len;
-
-	if (!file || !file->s || file->len <= 0 || !cfg_file) {
-		BUG("tls: Cannot get full pathname of file\n");
-		return NULL;
-	}
-
-	if (file->s[0] == '/') {
-		/* This is an absolute pathname, make a zero terminated
-		 * copy and use it as it is */
-		if ((res = strndup(file->s, file->len)) == NULL) {
-			ERR("tls: No memory left (strndup failed)\n");
-		}
-	} else {
-		/* This is not an absolute pathname, make it relative
-		 * to the location of the main SER configuration file
-		 */
-		/* Make a copy, function dirname may modify the string */
-		if ((buf = strdup(cfg_file)) == NULL) {
-			ERR("tls: No memory left (strdup failed)\n");
-			return NULL;
-		}
-		dir = dirname(buf);
-
-		len = strlen(dir);
-		if ((res = malloc(len + 1 + file->len + 1)) == NULL) {
-			ERR("tls: No memory left (malloc failed)\n");
-			free(buf);
-			return NULL;
-		}
-		memcpy(res, dir, len);
-		res[len] = '/';
-		memcpy(res + len + 1, file->s, file->len);
-		res[len + 1 + file->len] = '\0';
-		free(buf);
-	}
-	return res;
-}

+ 0 - 12
modules/tls/tls_util.h

@@ -81,16 +81,4 @@ int shm_asciiz_dup(char** dest, char* val);
  */
 void collect_garbage(void);
 
-
-/** Get full pathname of file. This function returns the full pathname of a
- * file in parameter. If the parameter does not start with / then the pathname
- * of the file will be relative to the pathname of the main SER configuration
- * file.
- * @param filename A pathname to be converted to absolute.
- * @return A string containing absolute pathname, the string
- *         must be freed with free.
- */
-char* get_pathname(str* filename);
-
-
 #endif /* _TLS_UTIL_H */