Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 48388) +++ apps/app_voicemail.c (working copy) @@ -84,6 +84,7 @@ #include "asterisk/utils.h" #include "asterisk/stringfields.h" #include "asterisk/smdi.h" +#include "asterisk/astdb.h" #ifdef ODBC_STORAGE #include "asterisk/res_odbc.h" #endif @@ -151,6 +152,9 @@ mailcmd= command in voicemail.conf */ #define SENDMAIL "/usr/sbin/sendmail -t" +/* Default realtime password configuration */ +#define REALTIME_PWD "none" + #define INTRO "vm-intro" #define MAXMSG 100 @@ -507,6 +511,7 @@ static int silencethreshold = 128; static char serveremail[80]; static char mailcmd[160]; /* Configurable mail cmd */ +static char realtimepwd[80]; /* Configurable realtime database for password */ static char externnotify[160]; static struct ast_smdi_interface *smdi_iface = NULL; static char vmfmts[80]; @@ -649,6 +654,40 @@ return -1; } + +static int change_password_astdb(struct ast_vm_user *vmu, const char *password) +{ + char astdbres[256]; + char searchstr[256]; + char *astdbpass, *temp; + /* Password to database if using Astdb Realtime */ + /* [context_section] + extension_number => voicemail_password,user_name,user_email_address,user_pager_email_address,user_option(s) */ + strcpy(searchstr, vmu->context); + strcat(searchstr, "."); + strcat(searchstr, vmu->mailbox); + int res = 0; + + /* If the database already contain the entry, store to the database */ + if(!ast_db_get("voicemail.conf", searchstr, astdbres, sizeof(astdbres))) { + if(!ast_strlen_zero(astdbres)) { + astdbpass = strtok(astdbres, ","); + temp = strtok(NULL, "\n"); + if(strcmp(astdbpass, password)) { + /* write the new password into the Asterisk Database */ + snprintf(astdbres, sizeof(astdbres), "%s,%s", password, temp); + res = ast_db_put("voicemail.conf", searchstr, astdbres); + if(res) { + ast_log(LOG_WARNING, "app_voicemail: astdb error, password not changed for Mailbox: %s or asterisk database realtime.\n", vmu->mailbox); + } else { + ast_log(LOG_WARNING, "app_voicemail: password changed for Mailbox: %s for asterisk database realtime.\n", vmu->mailbox); + } + } + } + } + return res; +} + static void apply_options(struct ast_vm_user *vmu, const char *options) { /* Destructively Parse options and apply */ char *stringp; @@ -777,10 +816,25 @@ char tmpin[PATH_MAX]; char tmpout[PATH_MAX]; struct stat statbuf; + char *realtimedb, *realtimetb; if (!change_password_realtime(vmu, newpassword)) return; + + /* Different database configurations for realtime password goes here */ + if(!ast_strlen_zero(realtimepwd) && strcmp(realtimepwd, "none")) { + realtimedb = strtok(realtimepwd, ","); + realtimetb = strtok(NULL, ","); + + if(realtimedb != NULL && realtimetb != NULL) { + if(!strcmp(realtimedb, "astdb") && !change_password_astdb(vmu, newpassword) ) { + return; + } + /* add more for different databases */ + } + } + /* Password to voicemail.conf */ 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"); @@ -7087,6 +7177,7 @@ const char *astemail; const char *ucontext; const char *astmailcmd = SENDMAIL; + const char *astrealtimepwd = REALTIME_PWD; const char *astforcename; const char *astforcegreet; const char *s; @@ -7102,6 +7193,7 @@ const char *vm_passchange; const char *vm_reenterpass; const char *vm_mism; + int x; int tmpadsi[4]; @@ -7153,7 +7245,12 @@ strcpy(mailcmd, SENDMAIL); if ((astmailcmd = ast_variable_retrieve(cfg, "general", "mailcmd"))) ast_copy_string(mailcmd, astmailcmd, sizeof(mailcmd)); /* User setting */ - + + /* User password from realtime engine? */ + strcpy(mailcmd, REALTIME_PWD); + if ((astrealtimepwd = ast_variable_retrieve(cfg, "general", "realtimepwd"))) + ast_copy_string(realtimepwd, astrealtimepwd, sizeof(realtimepwd)); + maxsilence = 0; if ((silencestr = ast_variable_retrieve(cfg, "general", "maxsilence"))) { maxsilence = atoi(silencestr);