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,9 +660,14 @@ 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));
@ -672,83 +677,59 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
*/ */
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 ']' */
tmpctx = strchr(inbuf, '['); if ((tmpctx = strchr(inbuf, '['))) {
if (tmpctx) { tmpctxend = strchr(tmpctx, ']');
tmpctxend = strchr(inbuf, ']'); if (tmpctxend) {
if (tmpctxend && (tmpctxend > tmpctx)) {
/* Valid context */ /* Valid context */
ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx - 1); ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx);
currcontext[tmpctxend - tmpctx - 1] = '\0'; fprintf(configout, "%s", orig);
} else { continue;
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;
pass = strchr(user, '='); if ((pass = strchr(user, '='))) {
if(pass > user) {
/* We have a line in the form of aaaaa=aaaaaa */ /* We have a line in the form of aaaaa=aaaaaa */
*pass = '\0'; *pass++ = '\0';
pass++;
/* Trim whitespace from user */ user = ast_strip(user);
trim = pass - 2;
while (*trim && *trim < 33) {
*trim = '\0';
trim--;
}
/* Trim whitespace and '>' from pass */ if (*pass == '>')
if (*pass == '>') { *pass++ = '\0';
*pass = '\0';
pass++; pass = ast_skip_blanks(pass);
}
while (*pass && *pass < 33) {
*pass = '\0';
pass++;
}
/* /*
Since no whitespace allowed in fields, or more correctly white space Since no whitespace allowed in fields, or more correctly white space
inside the fields is there for a purpose, we can just terminate pass inside the fields is there for a purpose, we can just terminate pass
at the comma or EOL whichever comes first. at the comma or EOL whichever comes first.
*/ */
trim = strchr(pass, ','); if ((rest = strchr(pass, ',')))
if (trim) { *rest++ = '\0';
*trim = '\0';
rest = trim + 1;
} else {
rest = NULL;
}
} 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