basically fix indentation of a large function after previous

simplifications. On passing, use a single exit point.

(once done with the cleanup i will merge the changes into 1.4,
if applicable)



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@44626 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Luigi Rizzo 2006-10-06 21:04:43 +00:00
parent 35cada23f0
commit 684d1f1698
1 changed files with 66 additions and 71 deletions

View File

@ -851,28 +851,26 @@ static int set_eventmask(struct mansession *s, char *eventmask)
static int authenticate(struct mansession *s, struct message *m)
{
struct ast_config *cfg;
char *cat;
char *user = astman_get_header(m, "Username");
char *pass = astman_get_header(m, "Secret");
char *authtype = astman_get_header(m, "AuthType");
char *key = astman_get_header(m, "Key");
char *events = astman_get_header(m, "Events");
char *cat = NULL;
struct ast_config *cfg = ast_config_load("manager.conf");
int ret = -1; /* default: error return */
cfg = ast_config_load("manager.conf");
if (!cfg)
return -1;
cat = NULL;
while ( (cat = ast_category_browse(cfg, cat)) ) {
if (!strcasecmp(cat, "general") || strcasecmp(cat, user))
continue; /* skip 'general' and non-matching sections */
/* XXX fix indentation */
{
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 */
/* collect parameters for the user's entry */
for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
if (!strcasecmp(v->name, "secret")) {
password = v->value;
@ -897,13 +895,14 @@ static int authenticate(struct mansession *s, struct message *m)
}
}
if (ha && !ast_apply_ha(ha, &(s->sin))) {
if (ha) {
if (!ast_apply_ha(ha, &(s->sin))) {
ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
ast_free_ha(ha);
ast_config_destroy(cfg);
return -1;
} else if (ha)
goto error;
}
ast_free_ha(ha);
}
if (!strcasecmp(authtype, "MD5")) {
if (!ast_strlen_zero(key) && s->challenge) {
int x;
@ -919,32 +918,28 @@ static int authenticate(struct mansession *s, struct message *m)
len += sprintf(md5key + len, "%2.2x", digest[x]);
if (!strcmp(md5key, key))
break;
else {
ast_config_destroy(cfg);
return -1;
}
}
} else if (password && !strcmp(password, pass)) {
} else if (password) {
if (!strcmp(password, pass))
break;
} else {
}
ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
ast_config_destroy(cfg);
return -1;
}
}
goto error;
}
/* we get here with user not found (cat = NULL) or successful authentication */
if (cat) {
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"));
ast_config_destroy(cfg);
if (events)
set_eventmask(s, events);
return 0;
}
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 -1;
return ret;
}
/*! \brief Manager PING */