aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2007-12-20 09:55:05 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2007-12-20 09:55:05 +0000
commit0a8518b7c882ee0c0e954fac34fb488d42a9fc00 (patch)
tree0d6c0aea4374306de8f0b0397b8c7138771c6870
parent832aa00d113c434ab218ae2321b88be1df51d074 (diff)
modify http://svn.digium.com/view/asterisk?view=rev&rev=93603
so that paths and filename are writable by asterisk.c without causing segfaults. This involves defining the variables as const char *, and having them point to as static, writable buffer defined in asterisk.c On passing, fix some errors in using these variables in some files in utils/ , and in res/snmp/agent.c which was redefining a variable without using paths.h (not applicable to 1.4) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@94168 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--include/asterisk/paths.h34
-rw-r--r--main/asterisk.c144
-rw-r--r--res/snmp/agent.c4
-rw-r--r--utils/ael_main.c13
-rw-r--r--utils/conf2ael.c11
-rw-r--r--utils/extconf.c2
6 files changed, 114 insertions, 94 deletions
diff --git a/include/asterisk/paths.h b/include/asterisk/paths.h
index f0052e72a..c161c284d 100644
--- a/include/asterisk/paths.h
+++ b/include/asterisk/paths.h
@@ -18,22 +18,22 @@
#ifndef _ASTERISK_PATHS_H
#define _ASTERISK_PATHS_H
-extern const char ast_config_AST_CONFIG_DIR[PATH_MAX];
-extern const char ast_config_AST_CONFIG_FILE[PATH_MAX];
-extern const char ast_config_AST_MODULE_DIR[PATH_MAX];
-extern const char ast_config_AST_SPOOL_DIR[PATH_MAX];
-extern const char ast_config_AST_MONITOR_DIR[PATH_MAX];
-extern const char ast_config_AST_VAR_DIR[PATH_MAX];
-extern const char ast_config_AST_DATA_DIR[PATH_MAX];
-extern const char ast_config_AST_LOG_DIR[PATH_MAX];
-extern const char ast_config_AST_AGI_DIR[PATH_MAX];
-extern const char ast_config_AST_DB[PATH_MAX];
-extern const char ast_config_AST_KEY_DIR[PATH_MAX];
-extern const char ast_config_AST_PID[PATH_MAX];
-extern const char ast_config_AST_SOCKET[PATH_MAX];
-extern const char ast_config_AST_RUN_DIR[PATH_MAX];
-extern const char ast_config_AST_RUN_GROUP[PATH_MAX];
-extern const char ast_config_AST_RUN_USER[PATH_MAX];
-extern const char ast_config_AST_SYSTEM_NAME[20];
+extern const char *ast_config_AST_CONFIG_DIR;
+extern const char *ast_config_AST_CONFIG_FILE;
+extern const char *ast_config_AST_MODULE_DIR;
+extern const char *ast_config_AST_SPOOL_DIR;
+extern const char *ast_config_AST_MONITOR_DIR;
+extern const char *ast_config_AST_VAR_DIR;
+extern const char *ast_config_AST_DATA_DIR;
+extern const char *ast_config_AST_LOG_DIR;
+extern const char *ast_config_AST_AGI_DIR;
+extern const char *ast_config_AST_DB;
+extern const char *ast_config_AST_KEY_DIR;
+extern const char *ast_config_AST_PID;
+extern const char *ast_config_AST_SOCKET;
+extern const char *ast_config_AST_RUN_DIR;
+extern const char *ast_config_AST_RUN_GROUP;
+extern const char *ast_config_AST_RUN_USER;
+extern const char *ast_config_AST_SYSTEM_NAME;
#endif /* _ASTERISK_PATHS_H */
diff --git a/main/asterisk.c b/main/asterisk.c
index 4e2966383..60b25444d 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -200,27 +200,52 @@ static int ast_el_add_history(char *);
static int ast_el_read_history(char *);
static int ast_el_write_history(char *);
-const char ast_config_AST_CONFIG_DIR[PATH_MAX];
-const char ast_config_AST_CONFIG_FILE[PATH_MAX];
-const char ast_config_AST_MODULE_DIR[PATH_MAX];
-const char ast_config_AST_SPOOL_DIR[PATH_MAX];
-const char ast_config_AST_MONITOR_DIR[PATH_MAX];
-const char ast_config_AST_VAR_DIR[PATH_MAX];
-const char ast_config_AST_DATA_DIR[PATH_MAX];
-const char ast_config_AST_LOG_DIR[PATH_MAX];
-const char ast_config_AST_AGI_DIR[PATH_MAX];
-const char ast_config_AST_DB[PATH_MAX];
-const char ast_config_AST_KEY_DIR[PATH_MAX];
-const char ast_config_AST_PID[PATH_MAX];
-const char ast_config_AST_SOCKET[PATH_MAX];
-const char ast_config_AST_RUN_DIR[PATH_MAX];
-const char ast_config_AST_RUN_USER[PATH_MAX];
-const char ast_config_AST_RUN_GROUP[PATH_MAX];
-static const char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
-static const char ast_config_AST_CTL_OWNER[PATH_MAX] = "\0";
-static const char ast_config_AST_CTL_GROUP[PATH_MAX] = "\0";
-static const char ast_config_AST_CTL[PATH_MAX] = "asterisk.ctl";
-const char ast_config_AST_SYSTEM_NAME[20] = "";
+struct _cfg_paths {
+ char config_dir[PATH_MAX];
+ char module_dir[PATH_MAX];
+ char spool_dir[PATH_MAX];
+ char monitor_dir[PATH_MAX];
+ char var_dir[PATH_MAX];
+ char data_dir[PATH_MAX];
+ char log_dir[PATH_MAX];
+ char agi_dir[PATH_MAX];
+ char run_dir[PATH_MAX];
+ char key_dir[PATH_MAX];
+
+ char config_file[PATH_MAX];
+ char db_path[PATH_MAX];
+ char pid_path[PATH_MAX];
+ char socket_path[PATH_MAX];
+ char run_user[PATH_MAX];
+ char run_group[PATH_MAX];
+ char system_name[128];
+};
+
+static struct _cfg_paths cfg_paths;
+
+const char *ast_config_AST_CONFIG_DIR = cfg_paths.config_dir;
+const char *ast_config_AST_CONFIG_FILE = cfg_paths.config_file;
+const char *ast_config_AST_MODULE_DIR = cfg_paths.module_dir;
+const char *ast_config_AST_SPOOL_DIR = cfg_paths.spool_dir;
+const char *ast_config_AST_MONITOR_DIR = cfg_paths.monitor_dir;
+const char *ast_config_AST_VAR_DIR = cfg_paths.var_dir;
+const char *ast_config_AST_DATA_DIR = cfg_paths.data_dir;
+const char *ast_config_AST_LOG_DIR = cfg_paths.log_dir;
+const char *ast_config_AST_AGI_DIR = cfg_paths.agi_dir;
+const char *ast_config_AST_KEY_DIR = cfg_paths.key_dir;
+const char *ast_config_AST_RUN_DIR = cfg_paths.run_dir;
+
+const char *ast_config_AST_DB = cfg_paths.db_path;
+const char *ast_config_AST_PID = cfg_paths.pid_path;
+const char *ast_config_AST_SOCKET = cfg_paths.socket_path;
+const char *ast_config_AST_RUN_USER = cfg_paths.run_user;
+const char *ast_config_AST_RUN_GROUP = cfg_paths.run_group;
+const char *ast_config_AST_SYSTEM_NAME = cfg_paths.system_name;
+
+static char ast_config_AST_CTL_PERMISSIONS[PATH_MAX];
+static char ast_config_AST_CTL_OWNER[PATH_MAX] = "\0";
+static char ast_config_AST_CTL_GROUP[PATH_MAX] = "\0";
+static char ast_config_AST_CTL[PATH_MAX] = "asterisk.ctl";
extern const char *ast_build_hostname;
extern const char *ast_build_kernel;
@@ -2423,20 +2448,19 @@ static void ast_readconfig(void)
cfg = ast_config_load(config, config_flags);
/* init with buildtime config */
-#define _SETVAR(dst, src) ast_copy_string((char *)dst, src, sizeof(dst))
- _SETVAR(ast_config_AST_CONFIG_DIR, DEFAULT_CONFIG_DIR);
- _SETVAR(ast_config_AST_SPOOL_DIR, DEFAULT_SPOOL_DIR);
- _SETVAR(ast_config_AST_MODULE_DIR, DEFAULT_MODULE_DIR);
- snprintf((char *)ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", ast_config_AST_SPOOL_DIR);
- _SETVAR(ast_config_AST_VAR_DIR, DEFAULT_VAR_DIR);
- _SETVAR(ast_config_AST_DATA_DIR, DEFAULT_DATA_DIR);
- _SETVAR(ast_config_AST_LOG_DIR, DEFAULT_LOG_DIR);
- _SETVAR(ast_config_AST_AGI_DIR, DEFAULT_AGI_DIR);
- _SETVAR(ast_config_AST_DB, DEFAULT_DB);
- _SETVAR(ast_config_AST_KEY_DIR, DEFAULT_KEY_DIR);
- _SETVAR(ast_config_AST_PID, DEFAULT_PID);
- _SETVAR(ast_config_AST_SOCKET, DEFAULT_SOCKET);
- _SETVAR(ast_config_AST_RUN_DIR, DEFAULT_RUN_DIR);
+ ast_copy_string(cfg_paths.config_dir, DEFAULT_CONFIG_DIR, sizeof(cfg_paths.config_dir));
+ ast_copy_string(cfg_paths.spool_dir, DEFAULT_SPOOL_DIR, sizeof(cfg_paths.spool_dir));
+ ast_copy_string(cfg_paths.module_dir, DEFAULT_MODULE_DIR, sizeof(cfg_paths.module_dir));
+ snprintf(cfg_paths.monitor_dir, sizeof(cfg_paths.monitor_dir) - 1, "%s/monitor", cfg_paths.spool_dir);
+ ast_copy_string(cfg_paths.var_dir, DEFAULT_VAR_DIR, sizeof(cfg_paths.var_dir));
+ ast_copy_string(cfg_paths.data_dir, DEFAULT_DATA_DIR, sizeof(cfg_paths.data_dir));
+ ast_copy_string(cfg_paths.log_dir, DEFAULT_LOG_DIR, sizeof(cfg_paths.log_dir));
+ ast_copy_string(cfg_paths.agi_dir, DEFAULT_AGI_DIR, sizeof(cfg_paths.agi_dir));
+ ast_copy_string(cfg_paths.db_path, DEFAULT_DB, sizeof(cfg_paths.db_path));
+ ast_copy_string(cfg_paths.key_dir, DEFAULT_KEY_DIR, sizeof(cfg_paths.key_dir));
+ ast_copy_string(cfg_paths.pid_path, DEFAULT_PID, sizeof(cfg_paths.pid_path));
+ ast_copy_string(cfg_paths.socket_path, DEFAULT_SOCKET, sizeof(cfg_paths.socket_path));
+ ast_copy_string(cfg_paths.run_dir, DEFAULT_RUN_DIR, sizeof(cfg_paths.run_dir));
/* no asterisk.conf? no problem, use buildtime config! */
if (!cfg) {
@@ -2445,45 +2469,45 @@ static void ast_readconfig(void)
for (v = ast_variable_browse(cfg, "files"); v; v = v->next) {
if (!strcasecmp(v->name, "astctlpermissions"))
- _SETVAR(ast_config_AST_CTL_PERMISSIONS, v->value);
+ ast_copy_string(ast_config_AST_CTL_PERMISSIONS, v->value, sizeof(ast_config_AST_CTL_PERMISSIONS));
else if (!strcasecmp(v->name, "astctlowner"))
- _SETVAR(ast_config_AST_CTL_OWNER, v->value);
+ ast_copy_string(ast_config_AST_CTL_OWNER, v->value, sizeof(ast_config_AST_CTL_OWNER));
else if (!strcasecmp(v->name, "astctlgroup"))
- _SETVAR(ast_config_AST_CTL_GROUP, v->value);
+ ast_copy_string(ast_config_AST_CTL_GROUP, v->value, sizeof(ast_config_AST_CTL_GROUP));
else if (!strcasecmp(v->name, "astctl"))
- _SETVAR(ast_config_AST_CTL, v->value);
+ ast_copy_string(ast_config_AST_CTL, v->value, sizeof(ast_config_AST_CTL));
}
for (v = ast_variable_browse(cfg, "directories"); v; v = v->next) {
if (!strcasecmp(v->name, "astetcdir")) {
- _SETVAR(ast_config_AST_CONFIG_DIR, v->value);
+ ast_copy_string(cfg_paths.config_dir, v->value, sizeof(cfg_paths.config_dir));
} else if (!strcasecmp(v->name, "astspooldir")) {
- _SETVAR(ast_config_AST_SPOOL_DIR, v->value);
- snprintf((char *)ast_config_AST_MONITOR_DIR, sizeof(ast_config_AST_MONITOR_DIR) - 1, "%s/monitor", v->value);
+ ast_copy_string(cfg_paths.spool_dir, v->value, sizeof(cfg_paths.spool_dir));
+ snprintf(cfg_paths.monitor_dir, sizeof(cfg_paths.monitor_dir) - 1, "%s/monitor", v->value);
} else if (!strcasecmp(v->name, "astvarlibdir")) {
- _SETVAR(ast_config_AST_VAR_DIR, v->value);
+ ast_copy_string(cfg_paths.var_dir, v->value, sizeof(cfg_paths.var_dir));
if (!found.dbdir)
- snprintf((char *)ast_config_AST_DB, sizeof(ast_config_AST_DB), "%s/astdb", v->value);
+ snprintf(cfg_paths.db_path, sizeof(cfg_paths.db_path), "%s/astdb", v->value);
} else if (!strcasecmp(v->name, "astdbdir")) {
- snprintf((char *)ast_config_AST_DB, sizeof(ast_config_AST_DB), "%s/astdb", v->value);
+ snprintf(cfg_paths.db_path, sizeof(cfg_paths.db_path), "%s/astdb", v->value);
found.dbdir = 1;
} else if (!strcasecmp(v->name, "astdatadir")) {
- _SETVAR(ast_config_AST_DATA_DIR, v->value);
+ ast_copy_string(cfg_paths.data_dir, v->value, sizeof(cfg_paths.data_dir));
if (!found.keydir)
- snprintf((char *)ast_config_AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR), "%s/keys", v->value);
+ snprintf(cfg_paths.key_dir, sizeof(cfg_paths.key_dir), "%s/keys", v->value);
} else if (!strcasecmp(v->name, "astkeydir")) {
- snprintf((char *)ast_config_AST_KEY_DIR, sizeof(ast_config_AST_KEY_DIR), "%s/keys", v->value);
+ snprintf(cfg_paths.key_dir, sizeof(cfg_paths.key_dir), "%s/keys", v->value);
found.keydir = 1;
} else if (!strcasecmp(v->name, "astlogdir")) {
- _SETVAR(ast_config_AST_LOG_DIR, v->value);
+ ast_copy_string(cfg_paths.log_dir, v->value, sizeof(cfg_paths.log_dir));
} else if (!strcasecmp(v->name, "astagidir")) {
- _SETVAR(ast_config_AST_AGI_DIR, v->value);
+ ast_copy_string(cfg_paths.agi_dir, v->value, sizeof(cfg_paths.agi_dir));
} else if (!strcasecmp(v->name, "astrundir")) {
- snprintf((char *)ast_config_AST_PID, sizeof(ast_config_AST_PID), "%s/%s", v->value, "asterisk.pid");
- snprintf((char *)ast_config_AST_SOCKET, sizeof(ast_config_AST_SOCKET), "%s/%s", v->value, ast_config_AST_CTL);
- _SETVAR(ast_config_AST_RUN_DIR, v->value);
+ snprintf(cfg_paths.pid_path, sizeof(cfg_paths.pid_path), "%s/%s", v->value, "asterisk.pid");
+ snprintf(cfg_paths.socket_path, sizeof(cfg_paths.socket_path), "%s/%s", v->value, ast_config_AST_CTL);
+ ast_copy_string(cfg_paths.run_dir, v->value, sizeof(cfg_paths.run_dir));
} else if (!strcasecmp(v->name, "astmoddir")) {
- _SETVAR(ast_config_AST_MODULE_DIR, v->value);
+ ast_copy_string(cfg_paths.module_dir, v->value, sizeof(cfg_paths.module_dir));
}
}
@@ -2566,19 +2590,19 @@ static void ast_readconfig(void)
set_ulimit(option_maxfiles);
/* What user to run as */
} else if (!strcasecmp(v->name, "runuser")) {
- _SETVAR(ast_config_AST_RUN_USER, v->value);
+ ast_copy_string(cfg_paths.run_user, v->value, sizeof(cfg_paths.run_user));
/* What group to run as */
} else if (!strcasecmp(v->name, "rungroup")) {
- _SETVAR(ast_config_AST_RUN_GROUP, v->value);
+ ast_copy_string(cfg_paths.run_group, v->value, sizeof(cfg_paths.run_group));
} else if (!strcasecmp(v->name, "systemname")) {
- _SETVAR(ast_config_AST_SYSTEM_NAME, v->value);
+ ast_copy_string(cfg_paths.system_name, v->value, sizeof(cfg_paths.system_name));
} else if (!strcasecmp(v->name, "autosystemname")) {
if (ast_true(v->value)) {
if (!gethostname(hostname, sizeof(hostname) - 1))
- _SETVAR(ast_config_AST_SYSTEM_NAME, hostname);
+ ast_copy_string(cfg_paths.system_name, hostname, sizeof(cfg_paths.system_name));
else {
if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)){
- _SETVAR(ast_config_AST_SYSTEM_NAME, "localhost");
+ ast_copy_string(cfg_paths.system_name, "localhost", sizeof(cfg_paths.system_name));
}
ast_log(LOG_ERROR, "Cannot obtain hostname for this system. Using '%s' instead.\n", ast_config_AST_SYSTEM_NAME);
}
@@ -2767,7 +2791,7 @@ int main(int argc, char *argv[])
xarg = optarg;
break;
case 'C':
- _SETVAR(ast_config_AST_CONFIG_FILE, optarg);
+ ast_copy_string(cfg_paths.config_file, optarg, sizeof(cfg_paths.config_file));
ast_set_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG);
break;
case 'I':
diff --git a/res/snmp/agent.c b/res/snmp/agent.c
index aace4623a..65f0fd434 100644
--- a/res/snmp/agent.c
+++ b/res/snmp/agent.c
@@ -51,6 +51,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include "asterisk/paths.h" /* need ast_config_AST_SOCKET */
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
@@ -71,9 +72,6 @@ int header_simple_table(struct variable *, oid *, size_t *, int, size_t *, Write
int register_sysORTable(oid *, size_t, const char *);
int unregister_sysORTable(oid *, size_t);
-/* Not defined in header files */
-extern char ast_config_AST_SOCKET[];
-
/* Forward declaration */
static void init_asterisk_mib(void);
diff --git a/utils/ael_main.c b/utils/ael_main.c
index 68b5dc479..7f20365f3 100644
--- a/utils/ael_main.c
+++ b/utils/ael_main.c
@@ -82,8 +82,11 @@ struct namelist *globalvars_last;
int conts=0, extens=0, priors=0;
char last_exten[18000];
-const char ast_config_AST_CONFIG_DIR[PATH_MAX];
-const char ast_config_AST_VAR_DIR[PATH_MAX];
+
+static char config_dir[PATH_MAX];
+static char var_dir[PATH_MAX];
+const char *ast_config_AST_CONFIG_DIR = config_dir;
+const char *ast_config_AST_VAR_DIR = var_dir;
void ast_cli_register_multiple(void);
int ast_add_extension2(struct ast_context *con,
@@ -514,14 +517,14 @@ int main(int argc, char **argv)
}
if( use_curr_dir ) {
- strcpy((char *)ast_config_AST_CONFIG_DIR, ".");
+ strcpy(config_dir, ".");
localized_use_local_dir();
}
else {
- strcpy((char *)ast_config_AST_CONFIG_DIR, "/etc/asterisk");
+ strcpy(config_dir, "/etc/asterisk");
localized_use_conf_dir();
}
- strcpy((char *)ast_config_AST_VAR_DIR, "/var/lib/asterisk");
+ strcpy(var_dir, "/var/lib/asterisk");
if( dump_extensions ) {
dumpfile = fopen("extensions.conf.aeldump","w");
diff --git a/utils/conf2ael.c b/utils/conf2ael.c
index b8cae75ec..fbb8aa3b6 100644
--- a/utils/conf2ael.c
+++ b/utils/conf2ael.c
@@ -29,19 +29,13 @@
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-#include <stdio.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
+#include "asterisk/paths.h" /* CONFIG_DIR */
#include <locale.h>
#include <ctype.h>
#if !defined(SOLARIS) && !defined(__CYGWIN__)
#include <err.h>
#endif
-#include <errno.h>
#include <regex.h>
-#include <limits.h>
#include "asterisk.h"
#include "asterisk/pbx.h"
@@ -59,11 +53,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/pval.h"
#include "asterisk/extconf.h"
+const char *ast_config_AST_CONFIG_DIR = "/etc/asterisk"; /* placeholder */
+
void get_start_stop(unsigned int *word, int bitsperword, int totalbits, int *start, int *end);
int all_bits_set(unsigned int *word, int bitsperword, int totalbits);
extern char *days[];
extern char *months[];
-const char ast_config_AST_CONFIG_DIR[PATH_MAX];
char *config = "extensions.conf";
diff --git a/utils/extconf.c b/utils/extconf.c
index 4621e345b..a64258cd9 100644
--- a/utils/extconf.c
+++ b/utils/extconf.c
@@ -25,6 +25,7 @@
*/
#include "asterisk/compat.h"
+#include "asterisk/paths.h" /* we use AST_CONFIG_DIR */
#include <errno.h>
#include <time.h>
@@ -53,7 +54,6 @@
# include <glob.h>
#endif
-static const char ast_config_AST_CONFIG_DIR[PATH_MAX] = {"/etc/asterisk"};
#define AST_API_MODULE 1 /* gimme the inline defs! */
struct ast_channel
{