mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 16:21:01 +00:00
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:
@@ -851,28 +851,26 @@ static int set_eventmask(struct mansession *s, char *eventmask)
|
|||||||
|
|
||||||
static int authenticate(struct mansession *s, struct message *m)
|
static int authenticate(struct mansession *s, struct message *m)
|
||||||
{
|
{
|
||||||
struct ast_config *cfg;
|
|
||||||
char *cat;
|
|
||||||
char *user = astman_get_header(m, "Username");
|
char *user = astman_get_header(m, "Username");
|
||||||
char *pass = astman_get_header(m, "Secret");
|
char *pass = astman_get_header(m, "Secret");
|
||||||
char *authtype = astman_get_header(m, "AuthType");
|
char *authtype = astman_get_header(m, "AuthType");
|
||||||
char *key = astman_get_header(m, "Key");
|
char *key = astman_get_header(m, "Key");
|
||||||
char *events = astman_get_header(m, "Events");
|
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)
|
if (!cfg)
|
||||||
return -1;
|
return -1;
|
||||||
cat = NULL;
|
|
||||||
while ( (cat = ast_category_browse(cfg, cat)) ) {
|
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_variable *v;
|
||||||
struct ast_ha *ha = NULL;
|
struct ast_ha *ha = NULL;
|
||||||
char *password = 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) {
|
for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
|
||||||
if (!strcasecmp(v->name, "secret")) {
|
if (!strcasecmp(v->name, "secret")) {
|
||||||
password = v->value;
|
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_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_free_ha(ha);
|
||||||
ast_config_destroy(cfg);
|
goto error;
|
||||||
return -1;
|
}
|
||||||
} else if (ha)
|
|
||||||
ast_free_ha(ha);
|
ast_free_ha(ha);
|
||||||
|
}
|
||||||
if (!strcasecmp(authtype, "MD5")) {
|
if (!strcasecmp(authtype, "MD5")) {
|
||||||
if (!ast_strlen_zero(key) && s->challenge) {
|
if (!ast_strlen_zero(key) && s->challenge) {
|
||||||
int x;
|
int x;
|
||||||
@@ -919,32 +918,28 @@ static int authenticate(struct mansession *s, struct message *m)
|
|||||||
len += sprintf(md5key + len, "%2.2x", digest[x]);
|
len += sprintf(md5key + len, "%2.2x", digest[x]);
|
||||||
if (!strcmp(md5key, key))
|
if (!strcmp(md5key, key))
|
||||||
break;
|
break;
|
||||||
else {
|
|
||||||
ast_config_destroy(cfg);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
} else if (password) {
|
||||||
} else if (password && !strcmp(password, pass)) {
|
if (!strcmp(password, pass))
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
|
ast_log(LOG_NOTICE, "%s failed to authenticate as '%s'\n", ast_inet_ntoa(s->sin.sin_addr), user);
|
||||||
ast_config_destroy(cfg);
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
/* we get here with user not found (cat = NULL) or successful authentication */
|
||||||
if (cat) {
|
if (cat) {
|
||||||
ast_copy_string(s->username, cat, sizeof(s->username));
|
ast_copy_string(s->username, cat, sizeof(s->username));
|
||||||
s->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read"));
|
s->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read"));
|
||||||
s->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write"));
|
s->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write"));
|
||||||
ast_config_destroy(cfg);
|
|
||||||
if (events)
|
if (events)
|
||||||
set_eventmask(s, 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);
|
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);
|
ast_config_destroy(cfg);
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Manager PING */
|
/*! \brief Manager PING */
|
||||||
|
Reference in New Issue
Block a user