[Asterisk-cvs] asterisk-addons mysql-vm-routines.h,1.5,1.6

markster at lists.digium.com markster at lists.digium.com
Tue Jun 1 17:40:37 CDT 2004


Update of /usr/cvsroot/asterisk-addons
In directory mongoose.digium.com:/tmp/cvs-serv17041

Modified Files:
	mysql-vm-routines.h 
Log Message:
Context handling fix (Bug #1759)


Index: mysql-vm-routines.h
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/mysql-vm-routines.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mysql-vm-routines.h	15 May 2004 23:18:11 -0000	1.5
+++ mysql-vm-routines.h	1 Jun 2004 21:56:48 -0000	1.6
@@ -43,13 +43,7 @@
 	retval=malloc(sizeof(struct ast_vm_user));
 
 	if (retval) {
-		*retval->mailbox='\0';
-		*retval->context='\0';
-		*retval->password='\0';
-		*retval->fullname='\0';
-		*retval->email='\0';
-		*retval->pager='\0';
-		*retval->serveremail='\0';
+		memset(retval, 0, sizeof(struct ast_vm_user));
 		retval->attach=-1;
 		retval->alloced=1;
 		retval->next=NULL;
@@ -58,12 +52,17 @@
 		}
 		if (context) {
 			strcpy(retval->context, context);
-		} 
+		} else {
+			strcpy(retval->context, "default");
+			strcpy(context, "default");
+		}
 
+		/* We should at this point have the context and retval->context else we free retval and return NULL */
 		if (*retval->context) {
 			sprintf(query, "SELECT password,fullname,email,pager,options FROM users WHERE context='%s' AND mailbox='%s'", context, mailbox);
 		} else {
-			sprintf(query, "SELECT password,fullname,email,pager,options FROM users WHERE context='default' AND mailbox='%s'", mailbox);
+			free(retval);
+			return(NULL);
 		}
 		ast_mutex_lock(&mysqllock);
 		mysql_query(dbhandler, query);
@@ -109,7 +108,9 @@
 	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 {
-		sprintf(query, "UPDATE users SET password='%s' WHERE mailbox='%s' AND password='%s'", password, vmu->mailbox, vmu->password);
+		/* 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);
@@ -124,7 +125,9 @@
 	if (context) {
 		sprintf(query, "UPDATE users SET password='%s' WHERE context='%s' AND mailbox='%s'", password, context, mailbox);
 	} else {
-		sprintf(query, "UPDATE users SET password='%s' WHERE mailbox='%s'", password, mailbox);
+		/* 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);




More information about the svn-commits mailing list