[asterisk-commits] rizzo: trunk r45516 - /trunk/main/manager.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Oct 18 04:54:06 MST 2006


Author: rizzo
Date: Wed Oct 18 06:54:06 2006
New Revision: 45516

URL: http://svn.digium.com/view/asterisk?rev=45516&view=rev
Log:
first pass as simplifying authenticate(), avoiding whitespace changes


Modified:
    trunk/main/manager.c

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?rev=45516&r1=45515&r2=45516&view=diff
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Wed Oct 18 06:54:06 2006
@@ -862,6 +862,9 @@
 	char *cat = NULL;
 	struct ast_config *cfg = ast_config_load("manager.conf");
 	int ret = -1;	/* default: error return */
+	struct ast_variable *v;
+	struct ast_ha *ha = NULL;
+	char *password = NULL;
 
 	/*
 	 * XXX there is no need to scan the config file again here,
@@ -872,12 +875,15 @@
 	if (!cfg)
 		return -1;
 	while ( (cat = ast_category_browse(cfg, cat)) ) {
-		struct ast_variable *v;
-		struct ast_ha *ha = NULL;
-		char *password = NULL;
-
-		if (!strcasecmp(cat, "general") || strcasecmp(cat, user))
-			continue;	/* skip 'general' and non-matching sections */
+		/* "general" is not a valid user */
+		if (!strcasecmp(cat, user) && strcasecmp(cat, "general"))
+			break;
+	}
+	if (!cat) {
+		ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
+		ast_config_destroy(cfg);
+		return ret;
+	}
 
 		/* collect parameters for the user's entry */
 		for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
@@ -926,26 +932,23 @@
 				for (x=0; x<16; x++)
 					len += sprintf(md5key + len, "%2.2x", digest[x]);
 				if (!strcmp(md5key, key))
-					break;
+					goto ok;
 			}
 		} else if (password) {
 			if (!strcmp(password, pass))
-				break;
+				goto ok;
 		}
 		ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
 		goto error;
-	}
-	/* we get here with user not found (cat = NULL) or successful authentication */
-	if (cat) {
+
+ok:
 		ast_copy_string(s->username, cat, sizeof(s->username));
 		s->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read"));
 		s->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write"));
 		if (events)
 			set_eventmask(s, events);
 		ret = 0;
-	} else {
-		ast_log(LOG_NOTICE, "%s tried to authenticate with nonexistent user '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
-	}
+
 error:
 	ast_config_destroy(cfg);
 	return ret;



More information about the asterisk-commits mailing list