[svn-commits] file: trunk r83156 - /trunk/apps/app_authenticate.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Sep 19 12:20:43 CDT 2007


Author: file
Date: Wed Sep 19 12:20:43 2007
New Revision: 83156

URL: http://svn.digium.com/view/asterisk?view=rev&rev=83156
Log:
Clean up code in app_authenticate.

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=83156&r1=83155&r2=83156
==============================================================================
--- trunk/apps/app_authenticate.c (original)
+++ trunk/apps/app_authenticate.c Wed Sep 19 12:20:43 2007
@@ -88,12 +88,8 @@
 
 static int auth_exec(struct ast_channel *chan, void *data)
 {
-	int res=0;
-	int retries;
-	char passwd[256];
-	char *prompt;
-	int maxdigits;
-	char *argcopy =NULL;
+	int res = 0, retries, maxdigits;
+	char passwd[256], *prompt = "agent-pass", *argcopy = NULL;
 	struct ast_flags flags = {0};
 
 	AST_DECLARE_APP_ARGS(arglist,
@@ -114,11 +110,10 @@
 	
 	argcopy = ast_strdupa(data);
 
-	AST_STANDARD_APP_ARGS(arglist,argcopy);
+	AST_STANDARD_APP_ARGS(arglist, argcopy);
 	
-	if (!ast_strlen_zero(arglist.options)) {
+	if (!ast_strlen_zero(arglist.options))
 		ast_app_parse_options(auth_app_options, &flags, NULL, arglist.options);
-	}
 
 	if (!ast_strlen_zero(arglist.maxdigits)) {
 		maxdigits = atoi(arglist.maxdigits);
@@ -129,10 +124,8 @@
 	}
 
 	/* Start asking for password */
-	prompt = "agent-pass";
 	for (retries = 0; retries < 3; retries++) {
-		res = ast_app_getdata(chan, prompt, passwd, maxdigits, 0);
-		if (res < 0)
+		if ((res = ast_app_getdata(chan, prompt, passwd, maxdigits, 0)) < 0)
 			break;
 		res = 0;
 		if (arglist.password[0] == '/') {
@@ -141,70 +134,67 @@
 				/* 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)) {
+					if (ast_test_flag(&flags,OPT_REMOVE))
 						ast_db_del(arglist.password + 1, passwd);
-					}
 					break;
 				}
 			} else {
 				/* Compare against a file */
 				FILE *f;
-				f = fopen(arglist.password, "r");
-				if (f) {
-					char buf[256] = "";
-					char md5passwd[33] = "";
-					char *md5secret = NULL;
-
-					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;
-								}
+				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;
-						}
+				}
+				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 
-					ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", arglist.password, strerror(errno));
+				}
 			}
 		} else {
 			/* Compare against a fixed password */
 			if (!strcmp(passwd, arglist.password)) 
 				break;
 		}
-		prompt="auth-incorrect";
+		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);
-		res = ast_streamfile(chan, "auth-thankyou", chan->language);
-		if (!res)
+		if (!(res = ast_streamfile(chan, "auth-thankyou", chan->language)))
 			res = ast_waitstream(chan, "");
 	} else {
 		if (!ast_streamfile(chan, "vm-goodbye", chan->language))




More information about the svn-commits mailing list