#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/astdb.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Enumerations | |
enum | { OPT_ACCOUNT = (1 << 0), OPT_DATABASE = (1 << 1), OPT_MULTIPLE = (1 << 3), OPT_REMOVE = (1 << 4) } |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | auth_exec (struct ast_channel *chan, const char *data) |
static int | load_module (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Authentication Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static const char | app [] = "Authenticate" |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_app_option | auth_app_options [128] = { [ 'a' ] = { .flag = OPT_ACCOUNT }, [ 'd' ] = { .flag = OPT_DATABASE }, [ 'm' ] = { .flag = OPT_MULTIPLE }, [ 'r' ] = { .flag = OPT_REMOVE },} |
Definition in file app_authenticate.c.
anonymous enum |
Definition at line 45 of file app_authenticate.c.
00045 { 00046 OPT_ACCOUNT = (1 << 0), 00047 OPT_DATABASE = (1 << 1), 00048 OPT_MULTIPLE = (1 << 3), 00049 OPT_REMOVE = (1 << 4), 00050 };
static void __reg_module | ( | void | ) | [static] |
Definition at line 279 of file app_authenticate.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 279 of file app_authenticate.c.
static int auth_exec | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
Definition at line 118 of file app_authenticate.c.
References ast_channel::_state, ast_answer(), AST_APP_ARG, ast_app_getdata(), ast_app_parse_options(), ast_db_del(), ast_db_get(), AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_strlen_zero(), ast_test_flag, auth_app_options, ast_flags::flags, LOG_WARNING, OPT_DATABASE, OPT_REMOVE, and prompt.
Referenced by load_module().
00119 { 00120 int res = 0, retries, maxdigits; 00121 char passwd[256], *prompt = "agent-pass", *argcopy = NULL; 00122 struct ast_flags flags = {0}; 00123 00124 AST_DECLARE_APP_ARGS(arglist, 00125 AST_APP_ARG(password); 00126 AST_APP_ARG(options); 00127 AST_APP_ARG(maxdigits); 00128 AST_APP_ARG(prompt); 00129 ); 00130 00131 if (ast_strlen_zero(data)) { 00132 ast_log(LOG_WARNING, "Authenticate requires an argument(password)\n"); 00133 return -1; 00134 } 00135 00136 if (chan->_state != AST_STATE_UP) { 00137 if ((res = ast_answer(chan))) 00138 return -1; 00139 } 00140 00141 argcopy = ast_strdupa(data); 00142 00143 AST_STANDARD_APP_ARGS(arglist, argcopy); 00144 00145 if (!ast_strlen_zero(arglist.options)) 00146 ast_app_parse_options(auth_app_options, &flags, NULL, arglist.options); 00147 00148 if (!ast_strlen_zero(arglist.maxdigits)) { 00149 maxdigits = atoi(arglist.maxdigits); 00150 if ((maxdigits<1) || (maxdigits>sizeof(passwd)-2)) 00151 maxdigits = sizeof(passwd) - 2; 00152 } else { 00153 maxdigits = sizeof(passwd) - 2; 00154 } 00155 00156 if (!ast_strlen_zero(arglist.prompt)) { 00157 prompt = arglist.prompt; 00158 } else { 00159 prompt = "agent-pass"; 00160 } 00161 00162 /* Start asking for password */ 00163 for (retries = 0; retries < 3; retries++) { 00164 if ((res = ast_app_getdata(chan, prompt, passwd, maxdigits, 0)) < 0) 00165 break; 00166 00167 res = 0; 00168 00169 if (arglist.password[0] != '/') { 00170 /* Compare against a fixed password */ 00171 if (!strcmp(passwd, arglist.password)) 00172 break; 00173 } else if (ast_test_flag(&flags,OPT_DATABASE)) { 00174 char tmp[256]; 00175 /* Compare against a database key */ 00176 if (!ast_db_get(arglist.password + 1, passwd, tmp, sizeof(tmp))) { 00177 /* It's a good password */ 00178 if (ast_test_flag(&flags,OPT_REMOVE)) 00179 ast_db_del(arglist.password + 1, passwd); 00180 break; 00181 } 00182 } else { 00183 /* Compare against a file */ 00184 FILE *f; 00185 char buf[256] = "", md5passwd[33] = "", *md5secret = NULL; 00186 00187 if (!(f = fopen(arglist.password, "r"))) { 00188 ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", arglist.password, strerror(errno)); 00189 continue; 00190 } 00191 00192 for (;;) { 00193 size_t len; 00194 00195 if (feof(f)) 00196 break; 00197 00198 if (!fgets(buf, sizeof(buf), f)) { 00199 continue; 00200 } 00201 00202 if (ast_strlen_zero(buf)) 00203 continue; 00204 00205 len = strlen(buf) - 1; 00206 if (buf[len] == '\n') 00207 buf[len] = '\0'; 00208 00209 if (ast_test_flag(&flags, OPT_MULTIPLE)) { 00210 md5secret = buf; 00211 strsep(&md5secret, ":"); 00212 if (!md5secret) 00213 continue; 00214 ast_md5_hash(md5passwd, passwd); 00215 if (!strcmp(md5passwd, md5secret)) { 00216 if (ast_test_flag(&flags,OPT_ACCOUNT)) { 00217 ast_channel_lock(chan); 00218 ast_cdr_setaccount(chan, buf); 00219 ast_channel_unlock(chan); 00220 } 00221 break; 00222 } 00223 } else { 00224 if (!strcmp(passwd, buf)) { 00225 if (ast_test_flag(&flags, OPT_ACCOUNT)) { 00226 ast_channel_lock(chan); 00227 ast_cdr_setaccount(chan, buf); 00228 ast_channel_unlock(chan); 00229 } 00230 break; 00231 } 00232 } 00233 } 00234 00235 fclose(f); 00236 00237 if (!ast_strlen_zero(buf)) { 00238 if (ast_test_flag(&flags, OPT_MULTIPLE)) { 00239 if (md5secret && !strcmp(md5passwd, md5secret)) 00240 break; 00241 } else { 00242 if (!strcmp(passwd, buf)) 00243 break; 00244 } 00245 } 00246 } 00247 prompt = "auth-incorrect"; 00248 } 00249 00250 if ((retries < 3) && !res) { 00251 if (ast_test_flag(&flags,OPT_ACCOUNT) && !ast_test_flag(&flags,OPT_MULTIPLE)) { 00252 ast_channel_lock(chan); 00253 ast_cdr_setaccount(chan, passwd); 00254 ast_channel_unlock(chan); 00255 } 00256 if (!(res = ast_streamfile(chan, "auth-thankyou", chan->language))) 00257 res = ast_waitstream(chan, ""); 00258 } else { 00259 if (!ast_streamfile(chan, "vm-goodbye", chan->language)) 00260 res = ast_waitstream(chan, ""); 00261 res = -1; 00262 } 00263 00264 return res; 00265 }
static int load_module | ( | void | ) | [static] |
Definition at line 272 of file app_authenticate.c.
References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, and auth_exec().
00273 { 00274 if (ast_register_application_xml(app, auth_exec)) 00275 return AST_MODULE_LOAD_FAILURE; 00276 return AST_MODULE_LOAD_SUCCESS; 00277 }
static int unload_module | ( | void | ) | [static] |
Definition at line 267 of file app_authenticate.c.
References ast_unregister_application().
00268 { 00269 return ast_unregister_application(app); 00270 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Authentication Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 279 of file app_authenticate.c.
const char app[] = "Authenticate" [static] |
Definition at line 60 of file app_authenticate.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 279 of file app_authenticate.c.
struct ast_app_option auth_app_options[128] = { [ 'a' ] = { .flag = OPT_ACCOUNT }, [ 'd' ] = { .flag = OPT_DATABASE }, [ 'm' ] = { .flag = OPT_MULTIPLE }, [ 'r' ] = { .flag = OPT_REMOVE },} [static] |