44 OPT_ACCOUNT = (1 << 0),
45 OPT_DATABASE = (1 << 1),
46 OPT_MULTIPLE = (1 << 3),
47 OPT_REMOVE = (1 << 4),
58 static const char app[] =
"Authenticate";
127 int res = 0, retries, maxdigits;
128 char passwd[256], *prompt =
"agent-pass", *argcopy = NULL;
138 if (ast_strlen_zero(data)) {
139 ast_log(LOG_WARNING,
"Authenticate requires an argument(password)\n");
152 if (!ast_strlen_zero(arglist.options))
155 if (!ast_strlen_zero(arglist.maxdigits)) {
156 maxdigits = atoi(arglist.maxdigits);
157 if ((maxdigits<1) || (maxdigits>
sizeof(passwd)-2))
158 maxdigits =
sizeof(passwd) - 2;
160 maxdigits =
sizeof(passwd) - 2;
163 if (!ast_strlen_zero(arglist.prompt)) {
164 prompt = arglist.prompt;
166 prompt =
"agent-pass";
170 for (retries = 0; retries < 3; retries++) {
176 if (arglist.password[0] !=
'/') {
178 if (!strcmp(passwd, arglist.password))
180 }
else if (ast_test_flag(&flags,OPT_DATABASE)) {
183 if (!
ast_db_get(arglist.password + 1, passwd, tmp,
sizeof(tmp))) {
185 if (ast_test_flag(&flags,OPT_REMOVE))
192 char buf[256] =
"", md5passwd[33] =
"", *md5secret = NULL;
194 if (!(f = fopen(arglist.password,
"r"))) {
195 ast_log(LOG_WARNING,
"Unable to open file '%s' for authentication: %s\n", arglist.password, strerror(errno));
205 if (!fgets(buf,
sizeof(buf), f)) {
209 if (ast_strlen_zero(buf))
212 len = strlen(buf) - 1;
213 if (buf[len] ==
'\n')
216 if (ast_test_flag(&flags, OPT_MULTIPLE)) {
218 strsep(&md5secret,
":");
222 if (!strcmp(md5passwd, md5secret)) {
223 if (ast_test_flag(&flags, OPT_ACCOUNT)) {
224 ast_channel_lock(chan);
225 ast_channel_accountcode_set(chan, buf);
226 ast_channel_unlock(chan);
231 if (!strcmp(passwd, buf)) {
232 if (ast_test_flag(&flags, OPT_ACCOUNT)) {
233 ast_channel_lock(chan);
234 ast_channel_accountcode_set(chan, buf);
235 ast_channel_unlock(chan);
244 if (!ast_strlen_zero(buf)) {
245 if (ast_test_flag(&flags, OPT_MULTIPLE)) {
246 if (md5secret && !strcmp(md5passwd, md5secret))
249 if (!strcmp(passwd, buf))
254 prompt =
"auth-incorrect";
257 if ((retries < 3) && !res) {
258 if (ast_test_flag(&flags,OPT_ACCOUNT) && !ast_test_flag(&flags,OPT_MULTIPLE)) {
259 ast_channel_lock(chan);
260 ast_channel_accountcode_set(chan, passwd);
261 ast_channel_unlock(chan);
263 if (!(res =
ast_streamfile(chan,
"auth-thankyou", ast_channel_language(chan))))
266 if (!
ast_streamfile(chan,
"vm-goodbye", ast_channel_language(chan)))
274 static int unload_module(
void)
279 static int load_module(
void)
Main Channel structure associated with a channel.
enum ast_getdata_result ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout)
Plays a stream and gets DTMF data from a channel.
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
ast_channel_state
ast_channel states
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_unregister_application(const char *app)
Unregister an application.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Core PBX routines and definitions.
union ast_frame::@224 data
Module has failed to load, may be in an inconsistent state.
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
Structure used to handle boolean flags.
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
int ast_answer(struct ast_channel *chan)
Answer a channel.
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
void ast_md5_hash(char *output, const char *input)
Produces MD5 hash based on input string.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
Persistent data storage (akin to *doze registry)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define AST_APP_ARG(name)
Define an application argument.