[asterisk-commits] russell: trunk r101745 - /trunk/apps/app_authenticate.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Feb 1 00:20:25 CST 2008


Author: russell
Date: Fri Feb  1 00:20:24 2008
New Revision: 101745

URL: http://svn.digium.com/view/asterisk?view=rev&rev=101745
Log:
reduce a level of indentation

Modified:
    trunk/apps/app_authenticate.c

Modified: trunk/apps/app_authenticate.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_authenticate.c?view=diff&rev=101745&r1=101744&r2=101745
==============================================================================
--- trunk/apps/app_authenticate.c (original)
+++ trunk/apps/app_authenticate.c Fri Feb  1 00:20:24 2008
@@ -119,70 +119,74 @@
 	for (retries = 0; retries < 3; retries++) {
 		if ((res = ast_app_getdata(chan, prompt, passwd, maxdigits, 0)) < 0)
 			break;
+
 		res = 0;
-		if (arglist.password[0] == '/') {
-			if (ast_test_flag(&flags,OPT_DATABASE)) {
-				char tmp[256];
-				/* Compare against a database key */
-				if (!ast_db_get(arglist.password + 1, passwd, tmp, sizeof(tmp))) {
-					/* It's a good password */
-					if (ast_test_flag(&flags,OPT_REMOVE))
-						ast_db_del(arglist.password + 1, passwd);
-					break;
-				}
-			} else {
-				/* Compare against a file */
-				FILE *f;
-				char buf[256] = "", md5passwd[33] = "", *md5secret = NULL;
-				
-				if (!(f = fopen(arglist.password, "r"))) {
-					ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", arglist.password, strerror(errno));
-					continue;
-				}
-
-				while (!feof(f)) {
-					fgets(buf, sizeof(buf), f);
-					if (!feof(f) && !ast_strlen_zero(buf)) {
-						buf[strlen(buf) - 1] = '\0';
-						if (ast_test_flag(&flags,OPT_MULTIPLE)) {
-							md5secret = strchr(buf, ':');
-							if (md5secret == NULL)
-								continue;
-							*md5secret = '\0';
-							md5secret++;
-							ast_md5_hash(md5passwd, passwd);
-							if (!strcmp(md5passwd, md5secret)) {
-								if (ast_test_flag(&flags,OPT_ACCOUNT))
-									ast_cdr_setaccount(chan, buf);
-								break;
-							}
-						} else {
-							if (!strcmp(passwd, buf)) {
-								if (ast_test_flag(&flags,OPT_ACCOUNT))
-									ast_cdr_setaccount(chan, buf);
-								break;
-							}
-						}
-					}
-				}
-				fclose(f);
-				if (!ast_strlen_zero(buf)) {
-					if (ast_test_flag(&flags,OPT_MULTIPLE)) {
-						if (md5secret && !strcmp(md5passwd, md5secret))
-							break;
-					} else {
-						if (!strcmp(passwd, buf))
-							break;
-					}
-				}
-			}
-		} else {
+
+		if (arglist.password[0] != '/') {
 			/* Compare against a fixed password */
 			if (!strcmp(passwd, arglist.password)) 
 				break;
 		}
+
+		if (ast_test_flag(&flags,OPT_DATABASE)) {
+			char tmp[256];
+			/* Compare against a database key */
+			if (!ast_db_get(arglist.password + 1, passwd, tmp, sizeof(tmp))) {
+				/* It's a good password */
+				if (ast_test_flag(&flags,OPT_REMOVE))
+					ast_db_del(arglist.password + 1, passwd);
+				break;
+			}
+		} else {
+			/* Compare against a file */
+			FILE *f;
+			char buf[256] = "", md5passwd[33] = "", *md5secret = NULL;
+				
+			if (!(f = fopen(arglist.password, "r"))) {
+				ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", arglist.password, strerror(errno));
+				continue;
+			}
+
+			while (!feof(f)) {
+				fgets(buf, sizeof(buf), f);
+				if (!feof(f) && !ast_strlen_zero(buf)) {
+					buf[strlen(buf) - 1] = '\0';
+					if (ast_test_flag(&flags,OPT_MULTIPLE)) {
+						md5secret = strchr(buf, ':');
+						if (!md5secret)
+							continue;
+						*md5secret++ = '\0';
+						ast_md5_hash(md5passwd, passwd);
+						if (!strcmp(md5passwd, md5secret)) {
+							if (ast_test_flag(&flags,OPT_ACCOUNT))
+								ast_cdr_setaccount(chan, buf);
+							break;
+						}
+					} else {
+						if (!strcmp(passwd, buf)) {
+							if (ast_test_flag(&flags,OPT_ACCOUNT))
+								ast_cdr_setaccount(chan, buf);
+							break;
+						}
+					}
+				}
+			}
+
+			fclose(f);
+
+			if (!ast_strlen_zero(buf)) {
+				if (ast_test_flag(&flags,OPT_MULTIPLE)) {
+					if (md5secret && !strcmp(md5passwd, md5secret))
+						break;
+				} else {
+					if (!strcmp(passwd, buf))
+						break;
+				}
+			}
+		}
 		prompt = "auth-incorrect";
 	}
+
 	if ((retries < 3) && !res) {
 		if (ast_test_flag(&flags,OPT_ACCOUNT) && !ast_test_flag(&flags,OPT_MULTIPLE)) 
 			ast_cdr_setaccount(chan, passwd);




More information about the asterisk-commits mailing list