diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-07-25 18:59:11 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-07-25 18:59:11 +0000 |
commit | 8e93280ca4b31322e740afdbcbb3837872e7413c (patch) | |
tree | 1951f9520a26be07935bc3713b7a0f6eafc13ed1 /apps/app_authenticate.c | |
parent | 04d94dcf1e73438203deddc04c8238350e5b04d0 (diff) |
add MD5-hash matching (bug #4764, with mods)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6198 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_authenticate.c')
-rwxr-xr-x | apps/app_authenticate.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/apps/app_authenticate.c b/apps/app_authenticate.c index d1383eb85..d50b5b2f2 100755 --- a/apps/app_authenticate.c +++ b/apps/app_authenticate.c @@ -46,6 +46,10 @@ static char *descrip = "of the following letters:\n" " a - Set account code to the password that is entered\n" " d - Interpret path as database key, not literal file\n" +" m - Interpret path as a file which contains a list of\n" +" account codes and password hashes delimited with ':'\n" +" one per line. When password matched, corresponding\n" +" account code will be set\n" " j - Support jumping to n+101\n" " r - Remove database key upon successful entry (valid with 'd' only)\n" "\n" @@ -115,17 +119,39 @@ static int auth_exec(struct ast_channel *chan, void *data) f = fopen(password, "r"); if (f) { char buf[256] = ""; - while(!feof(f)) { + char md5passwd[33] = ""; + char *md5secret; + + while (!feof(f)) { fgets(buf, sizeof(buf), f); if (!feof(f) && !ast_strlen_zero(buf)) { - buf[strlen(buf) - 1] = '\0'; - if (!ast_strlen_zero(buf) && !strcmp(passwd, buf)) - break; + if (strchr(opts, 'm')) { + md5secret = strchr(buf, ':'); + if (md5secret == NULL) + continue; + *md5secret = '\0'; + md5secret++; + ast_md5_hash(md5passwd, passwd); + if (!strcmp(md5passwd, md5secret)) { + ast_cdr_setaccount(chan, buf); + break; + } + } else { + if(!strcmp(passwd, buf)) + break; + } } } fclose(f); - if (!ast_strlen_zero(buf) && !strcmp(passwd, buf)) - break; + if (!ast_strlen_zero(buf)) { + if (strchr(opts, 'm')) { + if (!strcmp(md5passwd, md5secret)) + break; + } else { + if (!strcmp(passwd, buf)) + break; + } + } } else ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", password, strerror(errno)); } |