mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-18 15:49:56 +00:00
handle comments containing what appear to be context names during voicemail.conf updates better (issue #5385)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6917 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -607,13 +607,11 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
|
|||||||
char currcontext[256] ="";
|
char currcontext[256] ="";
|
||||||
char tmpin[AST_CONFIG_MAX_PATH];
|
char tmpin[AST_CONFIG_MAX_PATH];
|
||||||
char tmpout[AST_CONFIG_MAX_PATH];
|
char tmpout[AST_CONFIG_MAX_PATH];
|
||||||
char *user, *pass, *rest, *trim, *tempcontext;
|
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
if (!change_password_realtime(vmu, newpassword))
|
if (!change_password_realtime(vmu, newpassword))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tempcontext = NULL;
|
|
||||||
snprintf(tmpin, sizeof(tmpin), "%s/voicemail.conf", ast_config_AST_CONFIG_DIR);
|
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);
|
snprintf(tmpout, sizeof(tmpout), "%s/voicemail.conf.new", ast_config_AST_CONFIG_DIR);
|
||||||
configin = fopen(tmpin,"r");
|
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);
|
fgets(inbuf, sizeof(inbuf), configin);
|
||||||
linenum++;
|
linenum++;
|
||||||
if (!feof(configin)) {
|
if (!feof(configin)) {
|
||||||
|
char *user = NULL, *pass = NULL, *rest = NULL, *trim = NULL,
|
||||||
|
*comment = NULL, *tmpctx = NULL, *tmpctxend = NULL;
|
||||||
|
|
||||||
/* Make a backup of it */
|
/* Make a backup of it */
|
||||||
memcpy(orig, inbuf, sizeof(orig));
|
ast_copy_string(orig, inbuf, sizeof(orig));
|
||||||
/* Strip trailing \n and comment */
|
|
||||||
inbuf[strlen(inbuf) - 1] = '\0';
|
/*
|
||||||
user = strchr(inbuf, ';');
|
Read the file line by line, split each line into a comment and command section
|
||||||
if (user)
|
only parse the command portion of the line
|
||||||
*user = '\0';
|
*/
|
||||||
user=inbuf;
|
if (inbuf[strlen(inbuf) - 1] == '\n')
|
||||||
while (*user < 33)
|
inbuf[strlen(inbuf) - 1] = '\0';
|
||||||
user++;
|
comment = strchr(inbuf, ';');
|
||||||
/* check for '[' (opening of context name ) */
|
if (comment) {
|
||||||
tempcontext = strchr(user, '[');
|
*comment = '\0'; /* Now inbuf is terminated just before the comment */
|
||||||
if (tempcontext) {
|
comment++;
|
||||||
ast_copy_string(currcontext, tempcontext +1, sizeof(currcontext));
|
|
||||||
/* now check for ']' */
|
|
||||||
tempcontext = strchr(currcontext, ']');
|
|
||||||
if (tempcontext)
|
|
||||||
*tempcontext = '\0';
|
|
||||||
else
|
|
||||||
currcontext[0] = '\0';
|
|
||||||
}
|
}
|
||||||
pass = strchr(user, '=');
|
|
||||||
if (pass > user) {
|
if (inbuf[0] != '\0') { /* skip over parsing for lines starting with a comment character and empty lines */
|
||||||
trim = pass - 1;
|
/* Check for a context, first '[' to first ']' */
|
||||||
while (*trim && *trim < 33) {
|
tmpctx = strchr(inbuf, '[');
|
||||||
*trim = '\0';
|
if (tmpctx) {
|
||||||
trim--;
|
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) {
|
if (!tmpctx) {
|
||||||
*pass = '\0';
|
/* This isn't a context line, check for MBX => PSWD... */
|
||||||
pass++;
|
user = inbuf;
|
||||||
if (*pass == '>')
|
pass = strchr(user, '=');
|
||||||
pass++;
|
if(pass > user) {
|
||||||
while (*pass && *pass < 33)
|
/* We have a line in the form of aaaaa=aaaaaa */
|
||||||
pass++;
|
*pass = '\0';
|
||||||
}
|
pass++;
|
||||||
if (pass) {
|
|
||||||
rest = strchr(pass,',');
|
/* Trim whitespace from user */
|
||||||
if (rest) {
|
trim = pass - 2;
|
||||||
*rest = '\0';
|
while (*trim && *trim < 33) {
|
||||||
rest++;
|
*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 */
|
/* Compare user, pass AND context */
|
||||||
if (user && *user && !strcmp(user, vmu->mailbox) &&
|
if (user && *user && !strcmp(user, vmu->mailbox) &&
|
||||||
pass && !strcmp(pass, vmu->password) &&
|
pass && !strcmp(pass, vmu->password) &&
|
||||||
currcontext && *currcontext && !strcmp(currcontext, vmu->context)) {
|
currcontext && *currcontext && !strcmp(currcontext, vmu->context)) {
|
||||||
|
|
||||||
|
/* Write */
|
||||||
/* This is the line */
|
/* This is the line */
|
||||||
if (rest) {
|
if (rest) {
|
||||||
fprintf(configout, "%s => %s,%s\n", vmu->mailbox,newpassword,rest);
|
fprintf(configout, "%s => %s,%s", vmu->mailbox,newpassword,rest);
|
||||||
} else {
|
} else {
|
||||||
fprintf(configout, "%s => %s\n", vmu->mailbox,newpassword);
|
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, "\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Put it back like it was */
|
/* Put it back like it was */
|
||||||
|
|||||||
Reference in New Issue
Block a user