git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7081 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Kevin P. Fleming 20 years ago
parent 64aaaa1f4a
commit 51b54236de

@ -1,6 +1,7 @@
2005-11-11 Kevin P. Fleming <kpfleming@digium.com> 2005-11-11 Kevin P. Fleming <kpfleming@digium.com>
* apps/app_voicemail.c (close_mailbox): correct previous commit (issue #5663) * apps/app_voicemail.c (close_mailbox): correct previous commit (issue #5663)
(vm_change_password): fix password change writing (issue #5721)
* channels/chan_sip.c (transmit_invite): remove useless debug message; don't try to add OSP tokens to OPTIONS pings * channels/chan_sip.c (transmit_invite): remove useless debug message; don't try to add OSP tokens to OPTIONS pings

@ -660,95 +660,76 @@ 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, char *user = NULL, *pass = NULL, *rest = NULL,
*comment = NULL, *tmpctx = NULL, *tmpctxend = NULL; *comment = NULL, *tmpctx = NULL, *tmpctxend = NULL;
if (ast_strlen_zero(inbuf)) {
fprintf(configout, "\n");
continue;
}
/* Make a backup of it */ /* Make a backup of it */
ast_copy_string(orig, inbuf, sizeof(orig)); ast_copy_string(orig, inbuf, sizeof(orig));
/* /*
Read the file line by line, split each line into a comment and command section Read the file line by line, split each line into a comment and command section
only parse the command portion of the line only parse the command portion of the line
*/ */
if (inbuf[strlen(inbuf) - 1] == '\n') if (inbuf[strlen(inbuf) - 1] == '\n')
inbuf[strlen(inbuf) - 1] = '\0'; inbuf[strlen(inbuf) - 1] = '\0';
comment = strchr(inbuf, ';');
if (comment) { if ((comment = strchr(inbuf, ';')))
*comment = '\0'; /* Now inbuf is terminated just before the comment */ *comment++ = '\0'; /* Now inbuf is terminated just before the comment */
comment++;
if (ast_strlen_zero(inbuf)) {
fprintf(configout, "%s", orig);
continue;
} }
if (inbuf[0] != '\0') { /* skip over parsing for lines starting with a comment character and empty lines */ /* Check for a context, first '[' to first ']' */
/* Check for a context, first '[' to first ']' */ if ((tmpctx = strchr(inbuf, '['))) {
tmpctx = strchr(inbuf, '['); tmpctxend = strchr(tmpctx, ']');
if (tmpctx) { if (tmpctxend) {
tmpctxend = strchr(inbuf, ']'); /* Valid context */
if (tmpctxend && (tmpctxend > tmpctx)) { ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx);
/* Valid context */ fprintf(configout, "%s", orig);
ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx - 1); continue;
currcontext[tmpctxend - tmpctx - 1] = '\0';
} else {
tmpctx = NULL;
}
} }
}
if (!tmpctx) { /* This isn't a context line, check for MBX => PSWD... */
/* This isn't a context line, check for MBX => PSWD... */ user = inbuf;
user = inbuf; if ((pass = strchr(user, '='))) {
pass = strchr(user, '='); /* We have a line in the form of aaaaa=aaaaaa */
if(pass > user) { *pass++ = '\0';
/* 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 */ user = ast_strip(user);
if (*pass == '>') {
*pass = '\0';
pass++;
}
while (*pass && *pass < 33) {
*pass = '\0';
pass++;
}
/* if (*pass == '>')
Since no whitespace allowed in fields, or more correctly white space *pass++ = '\0';
inside the fields is there for a purpose, we can just terminate pass
at the comma or EOL whichever comes first. pass = ast_skip_blanks(pass);
*/
trim = strchr(pass, ','); /*
if (trim) { Since no whitespace allowed in fields, or more correctly white space
*trim = '\0'; inside the fields is there for a purpose, we can just terminate pass
rest = trim + 1; at the comma or EOL whichever comes first.
} else { */
rest = NULL; if ((rest = strchr(pass, ',')))
} *rest++ = '\0';
} else { } else {
user = NULL; user = NULL;
pass = NULL;
rest = NULL;
}
}
} }
/* Compare user, pass AND context */ /* Compare user, pass AND context */
if (user && *user && !strcmp(user, vmu->mailbox) && if (!ast_strlen_zero(user) && !strcmp(user, vmu->mailbox) &&
pass && !strcmp(pass, vmu->password) && !ast_strlen_zero(pass) && !strcmp(pass, vmu->password) &&
currcontext && *currcontext && !strcmp(currcontext, vmu->context)) { !strcasecmp(currcontext, vmu->context)) {
/* Write */
/* This is the line */ /* This is the line */
if (rest) { if (rest) {
fprintf(configout, "%s => %s,%s", vmu->mailbox,newpassword,rest); fprintf(configout, "%s => %s,%s", user, newpassword, rest);
} else { } else {
fprintf(configout, "%s => %s", vmu->mailbox,newpassword); fprintf(configout, "%s => %s", user, newpassword);
} }
/* If there was a comment on the line print it out */ /* If there was a comment on the line print it out */
if (comment) { if (comment) {
@ -765,11 +746,11 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
fclose(configin); fclose(configin);
fclose(configout); fclose(configout);
stat((char *)tmpin, &statbuf); stat(tmpin, &statbuf);
chmod((char *)tmpout, statbuf.st_mode); chmod(tmpout, statbuf.st_mode);
chown((char *)tmpout, statbuf.st_uid, statbuf.st_gid); chown(tmpout, statbuf.st_uid, statbuf.st_gid);
unlink((char *)tmpin); unlink(tmpin);
rename((char *)tmpout,(char *)tmpin); rename(tmpout, tmpin);
reset_user_pw(vmu->context, vmu->mailbox, newpassword); reset_user_pw(vmu->context, vmu->mailbox, newpassword);
ast_copy_string(vmu->password, newpassword, sizeof(vmu->password)); ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
} }

Loading…
Cancel
Save