Execute arbitrary authenticate commands. More...
#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 | |
| AST_APP_OPTIONS (auth_app_options,{AST_APP_OPTION('a', OPT_ACCOUNT), AST_APP_OPTION('d', OPT_DATABASE), AST_APP_OPTION('m', OPT_MULTIPLE), AST_APP_OPTION('r', OPT_REMOVE),}) | |
| AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Authentication Application") | |
| static int | auth_exec (struct ast_channel *chan, void *data) |
| static int | load_module (void) |
| static int | unload_module (void) |
Variables | |
| static char * | app = "Authenticate" |
| enum { ... } | auth_option_flags |
Execute arbitrary authenticate commands.
Definition in file app_authenticate.c.
| anonymous enum |
Definition at line 41 of file app_authenticate.c.
00041 { 00042 OPT_ACCOUNT = (1 << 0), 00043 OPT_DATABASE = (1 << 1), 00044 OPT_MULTIPLE = (1 << 3), 00045 OPT_REMOVE = (1 << 4), 00046 } auth_option_flags;
| AST_APP_OPTIONS | ( | auth_app_options | ) |
| AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
| "Authentication Application" | ||||
| ) |
| static int auth_exec | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Definition at line 108 of file app_authenticate.c.
References ast_channel::_state, ast_answer(), AST_APP_ARG, ast_app_getdata(), ast_app_parse_options(), ast_cdr_setaccount(), ast_db_del(), ast_db_get(), AST_DECLARE_APP_ARGS, ast_log(), ast_md5_hash(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_test_flag, ast_waitstream(), buf, errno, f, len(), LOG_WARNING, OPT_ACCOUNT, OPT_DATABASE, OPT_MULTIPLE, OPT_REMOVE, prompt, and strsep().
Referenced by load_module().
00109 { 00110 int res = 0, retries, maxdigits; 00111 char passwd[256], *prompt = "agent-pass", *argcopy = NULL; 00112 struct ast_flags flags = {0}; 00113 00114 AST_DECLARE_APP_ARGS(arglist, 00115 AST_APP_ARG(password); 00116 AST_APP_ARG(options); 00117 AST_APP_ARG(maxdigits); 00118 AST_APP_ARG(prompt); 00119 ); 00120 00121 if (ast_strlen_zero(data)) { 00122 ast_log(LOG_WARNING, "Authenticate requires an argument(password)\n"); 00123 return -1; 00124 } 00125 00126 if (chan->_state != AST_STATE_UP) { 00127 if ((res = ast_answer(chan))) 00128 return -1; 00129 } 00130 00131 argcopy = ast_strdupa(data); 00132 00133 AST_STANDARD_APP_ARGS(arglist, argcopy); 00134 00135 if (!ast_strlen_zero(arglist.options)) 00136 ast_app_parse_options(auth_app_options, &flags, NULL, arglist.options); 00137 00138 if (!ast_strlen_zero(arglist.maxdigits)) { 00139 maxdigits = atoi(arglist.maxdigits); 00140 if ((maxdigits<1) || (maxdigits>sizeof(passwd)-2)) 00141 maxdigits = sizeof(passwd) - 2; 00142 } else { 00143 maxdigits = sizeof(passwd) - 2; 00144 } 00145 00146 if (!ast_strlen_zero(arglist.prompt)) { 00147 prompt = arglist.prompt; 00148 } else { 00149 prompt = "agent-pass"; 00150 } 00151 00152 /* Start asking for password */ 00153 for (retries = 0; retries < 3; retries++) { 00154 if ((res = ast_app_getdata(chan, prompt, passwd, maxdigits, 0)) < 0) 00155 break; 00156 00157 res = 0; 00158 00159 if (arglist.password[0] != '/') { 00160 /* Compare against a fixed password */ 00161 if (!strcmp(passwd, arglist.password)) 00162 break; 00163 } else if (ast_test_flag(&flags,OPT_DATABASE)) { 00164 char tmp[256]; 00165 /* Compare against a database key */ 00166 if (!ast_db_get(arglist.password + 1, passwd, tmp, sizeof(tmp))) { 00167 /* It's a good password */ 00168 if (ast_test_flag(&flags,OPT_REMOVE)) 00169 ast_db_del(arglist.password + 1, passwd); 00170 break; 00171 } 00172 } else { 00173 /* Compare against a file */ 00174 FILE *f; 00175 char buf[256] = "", md5passwd[33] = "", *md5secret = NULL; 00176 00177 if (!(f = fopen(arglist.password, "r"))) { 00178 ast_log(LOG_WARNING, "Unable to open file '%s' for authentication: %s\n", arglist.password, strerror(errno)); 00179 continue; 00180 } 00181 00182 for (;;) { 00183 size_t len; 00184 00185 if (feof(f)) 00186 break; 00187 00188 if (!fgets(buf, sizeof(buf), f)) { 00189 continue; 00190 } 00191 00192 if (ast_strlen_zero(buf)) 00193 continue; 00194 00195 len = strlen(buf) - 1; 00196 if (buf[len] == '\n') 00197 buf[len] = '\0'; 00198 00199 if (ast_test_flag(&flags, OPT_MULTIPLE)) { 00200 md5secret = buf; 00201 strsep(&md5secret, ":"); 00202 if (!md5secret) 00203 continue; 00204 ast_md5_hash(md5passwd, passwd); 00205 if (!strcmp(md5passwd, md5secret)) { 00206 if (ast_test_flag(&flags,OPT_ACCOUNT)) 00207 ast_cdr_setaccount(chan, buf); 00208 break; 00209 } 00210 } else { 00211 if (!strcmp(passwd, buf)) { 00212 if (ast_test_flag(&flags, OPT_ACCOUNT)) 00213 ast_cdr_setaccount(chan, buf); 00214 break; 00215 } 00216 } 00217 } 00218 00219 fclose(f); 00220 00221 if (!ast_strlen_zero(buf)) { 00222 if (ast_test_flag(&flags, OPT_MULTIPLE)) { 00223 if (md5secret && !strcmp(md5passwd, md5secret)) 00224 break; 00225 } else { 00226 if (!strcmp(passwd, buf)) 00227 break; 00228 } 00229 } 00230 } 00231 prompt = "auth-incorrect"; 00232 } 00233 00234 if ((retries < 3) && !res) { 00235 if (ast_test_flag(&flags,OPT_ACCOUNT) && !ast_test_flag(&flags,OPT_MULTIPLE)) 00236 ast_cdr_setaccount(chan, passwd); 00237 if (!(res = ast_streamfile(chan, "auth-thankyou", chan->language))) 00238 res = ast_waitstream(chan, ""); 00239 } else { 00240 if (!ast_streamfile(chan, "vm-goodbye", chan->language)) 00241 res = ast_waitstream(chan, ""); 00242 res = -1; 00243 } 00244 00245 return res; 00246 }
| static int load_module | ( | void | ) | [static] |
Definition at line 253 of file app_authenticate.c.
References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, and auth_exec().
00254 { 00255 if (ast_register_application_xml(app, auth_exec)) 00256 return AST_MODULE_LOAD_FAILURE; 00257 return AST_MODULE_LOAD_SUCCESS; 00258 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 248 of file app_authenticate.c.
References ast_unregister_application().
00249 { 00250 return ast_unregister_application(app); 00251 }
char* app = "Authenticate" [static] |
Definition at line 56 of file app_authenticate.c.
| enum { ... } auth_option_flags |
1.6.1