[asterisk-commits] anthonyl: branch anthonyl/usersconf-vmpassword
r50216 - /team/anthonyl/usersc...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Jan 9 14:52:35 MST 2007
Author: anthonyl
Date: Tue Jan 9 15:52:35 2007
New Revision: 50216
URL: http://svn.digium.com/view/asterisk?view=rev&rev=50216
Log:
backing up some work, so far i just replaced change_vm_password to be a tad more sane
Modified:
team/anthonyl/usersconf-vmpassword/apps/app_voicemail.c
Modified: team/anthonyl/usersconf-vmpassword/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/usersconf-vmpassword/apps/app_voicemail.c?view=diff&rev=50216&r1=50215&r2=50216
==============================================================================
--- team/anthonyl/usersconf-vmpassword/apps/app_voicemail.c (original)
+++ team/anthonyl/usersconf-vmpassword/apps/app_voicemail.c Tue Jan 9 15:52:35 2007
@@ -773,136 +773,68 @@
return res;
}
+/* nice-er implimentation of vm_change_password */
+/* this one also supports users.conf with the vmpassword param */
+/* the current method i am trying to impliment just tries to change both */
static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
{
- /* There's probably a better way of doing this. */
- /* That's why I've put the password change in a separate function. */
- /* This could also be done with a database function */
+
+ struct ast_config *cfg;
+ struct ast_variable *var;
+ struct ast_category *cat;
+ char *category=NULL, *tmp=NULL, *value=NULL, *new=NULL;
+ int len;
- FILE *configin;
- FILE *configout;
- int linenum=0;
- char inbuf[256];
- char orig[256];
- char currcontext[256] ="";
- char tmpin[PATH_MAX];
- char tmpout[PATH_MAX];
- struct stat statbuf;
-
- if (!change_password_realtime(vmu, newpassword))
- return;
-
- 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");
- if (configin)
- configout = fopen(tmpout,"w+");
- else
- configout = NULL;
- if (!configin || !configout) {
- if (configin)
- fclose(configin);
- else
- ast_log(LOG_WARNING, "Warning: Unable to open '%s' for reading: %s\n", tmpin, strerror(errno));
- if (configout)
- fclose(configout);
- else
- ast_log(LOG_WARNING, "Warning: Unable to open '%s' for writing: %s\n", tmpout, strerror(errno));
- return;
- }
-
- while (!feof(configin)) {
- char *user = NULL, *pass = NULL, *rest = NULL, *comment = NULL, *tmpctx = NULL, *tmpctxend = NULL;
-
- /* Read in the line */
- if (fgets(inbuf, sizeof(inbuf), configin) == NULL)
- continue;
- linenum++;
-
- /* Make a backup of it */
- 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';
-
- 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);
- continue;
- }
- }
-
- /* 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';
-
- user = ast_strip(user);
-
- if (*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
- at the comma or EOL whichever comes first.
- */
- if ((rest = strchr(pass, ',')))
- *rest++ = '\0';
- } else {
- 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 {
- 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);
- }
- }
- fclose(configin);
- fclose(configout);
-
- stat(tmpin, &statbuf);
- chmod(tmpout, statbuf.st_mode);
- chown(tmpout, statbuf.st_uid, statbuf.st_gid);
- unlink(tmpin);
- rename(tmpout, tmpin);
- reset_user_pw(vmu->context, vmu->mailbox, newpassword);
- ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
+ /* check voicemail.conf */
+ if ((cfg = ast_config_load("voicemail.conf"))) {
+ while ((category = ast_category_browse(cfg, category))) {
+ if (!strcasecmp(category, vmu->context)) {
+ tmp = ast_variable_retrieve(cfg, category, vmu->mailbox);
+ if (!tmp) {
+ ast_log(LOG_WARNING, "We could not find the mailbox.\n");
+ break;
+ }
+ value = strstr(tmp,",");
+ if (!value) {
+ ast_log(LOG_WARNING, "variable has bad format.\n");
+ break;
+ }
+ len = (strlen(value) + strlen(newpassword));
+
+ if (!(new = ast_calloc(1,len))) {
+ ast_log(LOG_WARNING, "Memory Allocation Failed.\n");
+ break;
+ }
+ sprintf(new,"%s%s", newpassword, value);
+
+ if (!(cat = ast_category_get(cfg, category))) {
+ ast_log(LOG_WARNING, "Failed to get category structure.\n");
+ break;
+ }
+ ast_variable_update(cat, vmu->mailbox, new, NULL);
+ }
+ }
+ /* save the results */
+ reset_user_pw(vmu->context, vmu->mailbox, newpassword);
+ ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
+ config_text_file_save("voicemail.conf", cfg, "AppVoicemail");
+ }
+
+ /* check users.conf and update the password stored for the mailbox*/
+ /* if no vmpassword entry exists create one. */
+ if ((cfg = ast_config_load("users.conf"))) {
+ while ((category = ast_category_browse(cfg, category))) {
+ for (var = ast_variable_browse(cfg, category); var; var = var->next) {
+ /* check the context */
+ /* write the password to memory */
+ /* reset_user_pw(vmu->context, vmu->mailbox, newpassword); */
+ }
+ }
+ /* save the results */
+ config_text_file_save("users.conf", cfg, "AppVoicemail");
+ }
+
+ return;
}
static void vm_change_password_shell(struct ast_vm_user *vmu, char *newpassword)
More information about the asterisk-commits
mailing list