Skip to content
Snippets Groups Projects
Commit 917f50e7 authored by Mark Spencer's avatar Mark Spencer
Browse files

Add support for authenticating against astdb and one time authentication

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2092 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 15ba1fe5
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <asterisk/pbx.h> #include <asterisk/pbx.h>
#include <asterisk/module.h> #include <asterisk/module.h>
#include <asterisk/app.h> #include <asterisk/app.h>
#include <asterisk/astdb.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
...@@ -41,7 +42,11 @@ static char *descrip = ...@@ -41,7 +42,11 @@ static char *descrip =
"an optional set of opions may be provided by concatenating any\n" "an optional set of opions may be provided by concatenating any\n"
"of the following letters:\n" "of the following letters:\n"
" a - Set account code to the password that is entered\n" " a - Set account code to the password that is entered\n"
" d - Interpret path as database key, not literal file\n"
" r - Remove database key upon successful entry (valid with 'd' only)\n"
"\n" "\n"
"When using a database key, the value associated with the key can be\n"
"anything.\n"
"Returns 0 if the user enters a valid password within three\n" "Returns 0 if the user enters a valid password within three\n"
"tries, or -1 otherwise (or on hangup).\n"; "tries, or -1 otherwise (or on hangup).\n";
...@@ -85,24 +90,36 @@ static int auth_exec(struct ast_channel *chan, void *data) ...@@ -85,24 +90,36 @@ static int auth_exec(struct ast_channel *chan, void *data)
break; break;
res = 0; res = 0;
if (password[0] == '/') { if (password[0] == '/') {
/* Compare against a file */ if (strchr(opts, 'd')) {
FILE *f; char tmp[256];
f = fopen(password, "r"); /* Compare against a database key */
if (f) { if (!ast_db_get(password + 1, passwd, tmp, sizeof(tmp))) {
char buf[256] = ""; /* It's a good password */
while(!feof(f)) { if (strchr(opts, 'r')) {
fgets(buf, sizeof(buf), f); ast_db_del(password + 1, passwd);
if (!feof(f) && strlen(buf)) {
buf[strlen(buf) - 1] = '\0';
if (strlen(buf) && !strcmp(passwd, buf))
break;
} }
}
fclose(f);
if (strlen(buf) && !strcmp(passwd, buf))
break; break;
} else }
ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", password, strerror(errno)); } else {
/* Compare against a file */
FILE *f;
f = fopen(password, "r");
if (f) {
char buf[256] = "";
while(!feof(f)) {
fgets(buf, sizeof(buf), f);
if (!feof(f) && strlen(buf)) {
buf[strlen(buf) - 1] = '\0';
if (strlen(buf) && !strcmp(passwd, buf))
break;
}
}
fclose(f);
if (strlen(buf) && !strcmp(passwd, buf))
break;
} else
ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", password, strerror(errno));
}
} else { } else {
/* Compare against a fixed password */ /* Compare against a fixed password */
if (!strcmp(passwd, password)) if (!strcmp(passwd, password))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment