mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-18 15:49:56 +00:00
properly handle password changes when mailbox is last line of config file and not followed by a newline (issue #5870)
reformat password changing code to conform to coding guidelines (issue #5870) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@7272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -660,91 +660,89 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (!feof(configin)) {
|
while (!feof(configin)) {
|
||||||
|
char *user = NULL, *pass = NULL, *rest = NULL, *comment = NULL, *tmpctx = NULL, *tmpctxend = NULL;
|
||||||
|
|
||||||
/* Read in the line */
|
/* Read in the line */
|
||||||
fgets(inbuf, sizeof(inbuf), configin);
|
fgets(inbuf, sizeof(inbuf), configin);
|
||||||
linenum++;
|
linenum++;
|
||||||
if (!feof(configin)) {
|
|
||||||
char *user = NULL, *pass = NULL, *rest = NULL,
|
|
||||||
*comment = NULL, *tmpctx = NULL, *tmpctxend = NULL;
|
|
||||||
|
|
||||||
if (ast_strlen_zero(inbuf)) {
|
|
||||||
fprintf(configout, "\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make a backup of it */
|
if (ast_strlen_zero(inbuf)) {
|
||||||
ast_copy_string(orig, inbuf, sizeof(orig));
|
fprintf(configout, "\n");
|
||||||
|
continue;
|
||||||
/*
|
}
|
||||||
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';
|
|
||||||
|
|
||||||
if ((comment = strchr(inbuf, ';')))
|
/* Make a backup of it */
|
||||||
*comment++ = '\0'; /* Now inbuf is terminated just before the comment */
|
ast_copy_string(orig, inbuf, sizeof(orig));
|
||||||
|
|
||||||
if (ast_strlen_zero(inbuf)) {
|
/*
|
||||||
|
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';
|
||||||
|
|
||||||
|
if ((comment = strchr(inbuf, ';')))
|
||||||
|
*comment++ = '\0'; /* Now inbuf is terminated just before the comment */
|
||||||
|
|
||||||
|
if (ast_strlen_zero(inbuf)) {
|
||||||
|
fprintf(configout, "%s", orig);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for a context, first '[' to first ']' */
|
||||||
|
if ((tmpctx = strchr(inbuf, '['))) {
|
||||||
|
tmpctxend = strchr(tmpctx, ']');
|
||||||
|
if (tmpctxend) {
|
||||||
|
/* Valid context */
|
||||||
|
ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx);
|
||||||
fprintf(configout, "%s", orig);
|
fprintf(configout, "%s", orig);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Check for a context, first '[' to first ']' */
|
|
||||||
if ((tmpctx = strchr(inbuf, '['))) {
|
/* This isn't a context line, check for MBX => PSWD... */
|
||||||
tmpctxend = strchr(tmpctx, ']');
|
user = inbuf;
|
||||||
if (tmpctxend) {
|
if ((pass = strchr(user, '='))) {
|
||||||
/* Valid context */
|
/* We have a line in the form of aaaaa=aaaaaa */
|
||||||
ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx);
|
*pass++ = '\0';
|
||||||
fprintf(configout, "%s", orig);
|
|
||||||
continue;
|
user = ast_strip(user);
|
||||||
}
|
|
||||||
}
|
if (*pass == '>')
|
||||||
|
|
||||||
/* This isn't a context line, check for MBX => PSWD... */
|
|
||||||
user = inbuf;
|
|
||||||
if ((pass = strchr(user, '='))) {
|
|
||||||
/* We have a line in the form of aaaaa=aaaaaa */
|
|
||||||
*pass++ = '\0';
|
*pass++ = '\0';
|
||||||
|
|
||||||
user = ast_strip(user);
|
|
||||||
|
|
||||||
if (*pass == '>')
|
pass = ast_skip_blanks(pass);
|
||||||
*pass++ = '\0';
|
|
||||||
|
|
||||||
pass = ast_skip_blanks(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
|
||||||
Since no whitespace allowed in fields, or more correctly white space
|
at the comma or EOL whichever comes first.
|
||||||
inside the fields is there for a purpose, we can just terminate pass
|
*/
|
||||||
at the comma or EOL whichever comes first.
|
if ((rest = strchr(pass, ',')))
|
||||||
*/
|
*rest++ = '\0';
|
||||||
if ((rest = strchr(pass, ',')))
|
} else {
|
||||||
*rest++ = '\0';
|
user = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compare user, pass AND context */
|
||||||
|
if (!ast_strlen_zero(user) && !strcmp(user, vmu->mailbox) &&
|
||||||
|
!ast_strlen_zero(pass) && !strcmp(pass, vmu->password) &&
|
||||||
|
!strcasecmp(currcontext, vmu->context)) {
|
||||||
|
/* This is the line */
|
||||||
|
if (rest) {
|
||||||
|
fprintf(configout, "%s => %s,%s", user, newpassword, rest);
|
||||||
} else {
|
} else {
|
||||||
user = NULL;
|
fprintf(configout, "%s => %s", user, newpassword);
|
||||||
}
|
|
||||||
|
|
||||||
/* Compare user, pass AND context */
|
|
||||||
if (!ast_strlen_zero(user) && !strcmp(user, vmu->mailbox) &&
|
|
||||||
!ast_strlen_zero(pass) && !strcmp(pass, vmu->password) &&
|
|
||||||
!strcasecmp(currcontext, vmu->context)) {
|
|
||||||
/* This is the line */
|
|
||||||
if (rest) {
|
|
||||||
fprintf(configout, "%s => %s,%s", user, newpassword, rest);
|
|
||||||
} else {
|
|
||||||
fprintf(configout, "%s => %s", user, newpassword);
|
|
||||||
}
|
|
||||||
/* If there was a comment on the line print it out */
|
|
||||||
if (comment) {
|
|
||||||
fprintf(configout, ";%s\n", comment);
|
|
||||||
} else {
|
|
||||||
fprintf(configout, "\n");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Put it back like it was */
|
|
||||||
fprintf(configout, "%s", orig);
|
|
||||||
}
|
}
|
||||||
|
/* If there was a comment on the line print it out */
|
||||||
|
if (comment) {
|
||||||
|
fprintf(configout, ";%s\n", comment);
|
||||||
|
} else {
|
||||||
|
fprintf(configout, "\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Put it back like it was */
|
||||||
|
fprintf(configout, "%s", orig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(configin);
|
fclose(configin);
|
||||||
|
|||||||
Reference in New Issue
Block a user