diff -Nuar asterisk.org/apps/app_authenticate.c asterisk/apps/app_authenticate.c --- asterisk.org/apps/app_authenticate.c 2005-07-26 13:33:11.000000000 -0400 +++ asterisk/apps/app_authenticate.c 2005-07-26 16:14:47.000000000 -0400 @@ -30,6 +30,7 @@ #include "asterisk/app.h" #include "asterisk/astdb.h" #include "asterisk/utils.h" +#include "asterisk/options.h" static char *tdesc = "Authentication Application"; @@ -50,13 +51,17 @@ " 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" "When using a database key, the value associated with the key can be\n" "anything.\n" +"\nThe result of the application will be reported in the AUTHENTICATESTATUS\n" +"channel variable:\n" +" SUCCESS Authentication succeeded\n" +" FAILURE Authentication failed\n" "Returns 0 if the user enters a valid password within three\n" -"tries, or -1 on hangup. If the priority n+101 exists and invalid\n" +"tries, or -1 on hangup.\n\n" +"Old depraciated behaviour: If the priority n+101 exists and invalid\n" "authentication was entered, and the 'j' flag was specified, processing\n" "will jump to n+101 and 0 will be returned.\n"; @@ -66,16 +71,18 @@ static int auth_exec(struct ast_channel *chan, void *data) { - int res=0; - int jump = 0; + int res = 0; int retries; struct localuser *u; - char password[256]=""; + char password[256] = ""; char passwd[256]; - char *opts; - char *prompt; + char *opts = ""; + char *prompt = ""; + char *status = "FAILURE"; + if (!data || ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Authenticate requires an argument(password)\n"); + pbx_builtin_setvar_helper(chan, "AUTHENICATESTATUS", status); return -1; } LOCAL_USER_ADD(u); @@ -83,18 +90,16 @@ res = ast_answer(chan); if (res) { LOCAL_USER_REMOVE(u); + pbx_builtin_setvar_helper(chan, "AUTHENICATESTATUS", status); return -1; } } strncpy(password, data, sizeof(password) - 1); - opts=strchr(password, '|'); + opts = strchr(password, '|'); if (opts) { *opts = 0; opts++; - } else - opts = ""; - if (strchr(opts, 'j')) - jump = 1; + } /* Start asking for password */ prompt = "agent-pass"; for (retries = 0; retries < 3; retries++) { @@ -120,7 +125,7 @@ if (f) { char buf[256] = ""; char md5passwd[33] = ""; - char *md5secret; + char *md5secret = ""; while (!feof(f)) { fgets(buf, sizeof(buf), f); @@ -152,25 +157,27 @@ break; } } - } else - ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", password, strerror(errno)); + } else { + ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", password, strerror(errno)); } } } else { /* Compare against a fixed password */ if (!strcmp(passwd, password)) break; } - prompt="auth-incorrect"; + prompt = "auth-incorrect"; } if ((retries < 3) && !res) { + status = "SUCCESS"; if (strchr(opts, 'a')) ast_cdr_setaccount(chan, passwd); res = ast_streamfile(chan, "auth-thankyou", chan->language); if (!res) res = ast_waitstream(chan, ""); } else { - if (jump && ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num)) { - chan->priority+=100; + if (option_priority_jumping && ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num)) { + chan->priority += 100; + status = "SUCCESS"; res = 0; } else { if (!ast_streamfile(chan, "vm-goodbye", chan->language)) @@ -179,6 +186,7 @@ } } LOCAL_USER_REMOVE(u); + pbx_builtin_setvar_helper(chan, "AUTHENICATESTATUS", status); return res; }