aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-31 23:41:20 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-31 23:41:20 +0000
commitbd6eb0d6617c6ec9ecb534b57e72eba1c3c2d6f4 (patch)
tree984ba2475bee63216d923da9a56473e7833b3bc4
parent3867df3afcf692d2129eae9a14392fc000a06620 (diff)
handle comments containing what appear to be context names during voicemail.conf updates better (issue #5385)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6917 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xapps/app_voicemail.c130
1 files changed, 84 insertions, 46 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 7410fceb2..e31519ffa 100755
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -607,13 +607,11 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
char currcontext[256] ="";
char tmpin[AST_CONFIG_MAX_PATH];
char tmpout[AST_CONFIG_MAX_PATH];
- char *user, *pass, *rest, *trim, *tempcontext;
struct stat statbuf;
if (!change_password_realtime(vmu, newpassword))
return;
- tempcontext = NULL;
snprintf(tmpin, sizeof(tmpin), "%s/voicemail.conf", ast_config_AST_CONFIG_DIR);
snprintf(tmpout, sizeof(tmpout), "%s/voicemail.conf.new", ast_config_AST_CONFIG_DIR);
configin = fopen(tmpin,"r");
@@ -638,61 +636,101 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
fgets(inbuf, sizeof(inbuf), configin);
linenum++;
if (!feof(configin)) {
+ char *user = NULL, *pass = NULL, *rest = NULL, *trim = NULL,
+ *comment = NULL, *tmpctx = NULL, *tmpctxend = NULL;
+
/* Make a backup of it */
- memcpy(orig, inbuf, sizeof(orig));
- /* Strip trailing \n and comment */
- inbuf[strlen(inbuf) - 1] = '\0';
- user = strchr(inbuf, ';');
- if (user)
- *user = '\0';
- user=inbuf;
- while (*user < 33)
- user++;
- /* check for '[' (opening of context name ) */
- tempcontext = strchr(user, '[');
- if (tempcontext) {
- ast_copy_string(currcontext, tempcontext +1, sizeof(currcontext));
- /* now check for ']' */
- tempcontext = strchr(currcontext, ']');
- if (tempcontext)
- *tempcontext = '\0';
- else
- currcontext[0] = '\0';
+ ast_copy_string(orig, inbuf, sizeof(orig));
+
+ /*
+ Read the file line by line, split each line into a comment and command section
+ only parse the command portion of the line
+ */
+ if (inbuf[strlen(inbuf) - 1] == '\n')
+ inbuf[strlen(inbuf) - 1] = '\0';
+ comment = strchr(inbuf, ';');
+ if (comment) {
+ *comment = '\0'; /* Now inbuf is terminated just before the comment */
+ comment++;
}
- pass = strchr(user, '=');
- if (pass > user) {
- trim = pass - 1;
- while (*trim && *trim < 33) {
- *trim = '\0';
- trim--;
+
+ if (inbuf[0] != '\0') { /* skip over parsing for lines starting with a comment character and empty lines */
+ /* Check for a context, first '[' to first ']' */
+ tmpctx = strchr(inbuf, '[');
+ if (tmpctx) {
+ tmpctxend = strchr(inbuf, ']');
+ if (tmpctxend && (tmpctxend > tmpctx)) {
+ /* Valid context */
+ ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx - 1);
+ currcontext[tmpctxend - tmpctx - 1] = '\0';
+ } else {
+ tmpctx = NULL;
+ }
}
- }
- if (pass) {
- *pass = '\0';
- pass++;
- if (*pass == '>')
- pass++;
- while (*pass && *pass < 33)
- pass++;
- }
- if (pass) {
- rest = strchr(pass,',');
- if (rest) {
- *rest = '\0';
- rest++;
+
+ if (!tmpctx) {
+ /* This isn't a context line, check for MBX => PSWD... */
+ user = inbuf;
+ pass = strchr(user, '=');
+ if(pass > user) {
+ /* We have a line in the form of aaaaa=aaaaaa */
+ *pass = '\0';
+ pass++;
+
+ /* Trim whitespace from user */
+ trim = pass - 2;
+ while (*trim && *trim < 33) {
+ *trim = '\0';
+ trim--;
+ }
+
+ /* Trim whitespace and '>' from pass */
+ if (*pass == '>') {
+ *pass = '\0';
+ pass++;
+ }
+ while (*pass && *pass < 33) {
+ *pass = '\0';
+ pass++;
+ }
+
+ /*
+ Since no whitespace allowed in fields, or more correctly white space
+ inside the fields is there for a purpose, we can just terminate pass
+ at the comma or EOL whichever comes first.
+ */
+ trim = strchr(pass, ',');
+ if (trim) {
+ *trim = '\0';
+ rest = trim + 1;
+ } else {
+ rest = NULL;
+ }
+ } else {
+ user = NULL;
+ pass = NULL;
+ rest = NULL;
+ }
}
- } else
- rest = NULL;
-
+ }
+
/* Compare user, pass AND context */
if (user && *user && !strcmp(user, vmu->mailbox) &&
pass && !strcmp(pass, vmu->password) &&
currcontext && *currcontext && !strcmp(currcontext, vmu->context)) {
+
+ /* Write */
/* This is the line */
if (rest) {
- fprintf(configout, "%s => %s,%s\n", vmu->mailbox,newpassword,rest);
+ fprintf(configout, "%s => %s,%s", vmu->mailbox,newpassword,rest);
+ } else {
+ fprintf(configout, "%s => %s", vmu->mailbox,newpassword);
+ }
+ /* If there was a comment on the line print it out */
+ if (comment) {
+ fprintf(configout, ";%s\n", comment);
} else {
- fprintf(configout, "%s => %s\n", vmu->mailbox,newpassword);
+ fprintf(configout, "\n");
}
} else {
/* Put it back like it was */