--- mysql-vm-routines.h 2004-07-13 13:27:22.000000000 -0700 +++ asterisk-addons/mysql-vm-routines.h 2004-07-13 13:28:23.000000000 -0700 @@ -36,7 +36,7 @@ MYSQL_ROW rowval; MYSQL_FIELD *fields; int numFields, i; - char query[1024]; + char query[240]; char options[160] = ""; struct ast_vm_user *retval; @@ -59,14 +59,11 @@ /* We should at this point have the context and retval->context else we free retval and return NULL */ if (*retval->context) { - sprintf(query,db_getvmuser_query,mailbox,context ? context : "default" ); + sprintf(query, "SELECT password,fullname,email,pager,options FROM users WHERE context='%s' AND mailbox='%s'", context, mailbox); } else { free(retval); return(NULL); } -#if EXTRA_LOG - fprintf(stderr,"vm_find_user: query = %s\n",query); -#endif ast_mutex_lock(&mysqllock); mysql_query(dbhandler, query); if ((result=mysql_store_result(dbhandler))!=NULL) { @@ -106,11 +103,15 @@ } static void vm_change_password(struct ast_vm_user *vmu, char *password) { - char query[1024]; - sprintf(query,db_changepassword_query,password,vmu->password,vmu->mailbox,vmu->context ? vmu->context : "default" ); -#if EXTRA_LOG - fprintf(stderr,"vm_change_password: query = %s\n",query); -#endif + char query[400]; + + if (*vmu->context) { + sprintf(query, "UPDATE users SET password='%s' WHERE context='%s' AND mailbox='%s' AND password='%s'", password, vmu->context, vmu->mailbox, vmu->password); + } else { + /* Lets be specific here since we can have for example exten 123 in diffrent contexts. + This has the ability to update/change passwords for all users with mailbox 123. */ + sprintf(query, "UPDATE users SET password='%s' WHERE mailbox='%s' AND password='%s' AND context='default'", password, vmu->mailbox, vmu->password); + } ast_mutex_lock(&mysqllock); mysql_query(dbhandler, query); strcpy(vmu->password, password); @@ -119,11 +120,15 @@ static void reset_user_pw(char *context, char *mailbox, char *password) { - char query[1024]; - sprintf(query,db_setpassword_query,password,mailbox, context ? context : "default" ); -#if EXTRA_LOG - fprintf(stderr,"reset_user_pw: query = %s\n",query); -#endif + char query[320]; + + if (context) { + sprintf(query, "UPDATE users SET password='%s' WHERE context='%s' AND mailbox='%s'", password, context, mailbox); + } else { + /* Lets be specific here since we can have for example exten 123 in diffrent contexts. + This has the ability to reset passwords for all users with mailbox 123. */ + sprintf(query, "UPDATE users SET password='%s' WHERE mailbox='%s' AND context='default'", password, mailbox); + } ast_mutex_lock(&mysqllock); mysql_query(dbhandler, query); ast_mutex_unlock(&mysqllock);