129{
  130    int res = 0, retries, maxdigits;
  131    char passwd[256], *
prompt = 
"agent-pass", *argcopy = 
NULL;
 
  133 
  139    );
  140 
  143        return -1;
  144    }
  145 
  148            return -1;
  149    }
  150 
  152 
  154 
  157 
  159        maxdigits = atoi(arglist.maxdigits);
  160        if ((maxdigits<1) || (maxdigits>sizeof(passwd)-2))
  161            maxdigits = sizeof(passwd) - 2;
  162    } else {
  163        maxdigits = sizeof(passwd) - 2;
  164    }
  165 
  168    } else {
  170    }
  171 
  172    
  173    for (retries = 0; retries < 3; retries++) {
  175            break;
  176 
  177        res = 0;
  178 
  179        if (arglist.password[0] != '/') {
  180            
  181            if (!strcmp(passwd, arglist.password))
  182                break;
  184            char tmp[256];
  185            
  186            if (!
ast_db_get(arglist.password + 1, passwd, tmp, 
sizeof(tmp))) {
 
  187                
  190                break;
  191            }
  192        } else {
  193            
  194            FILE *f;
  195            char buf[256] = 
"", md5passwd[33] = 
"", *md5secret = 
NULL;
 
  196 
  197            if (!(f = fopen(arglist.password, "r"))) {
  199                continue;
  200            }
  201 
  202            for (;;) {
  204 
  205                if (feof(f))
  206                    break;
  207 
  208                if (!fgets(
buf, 
sizeof(
buf), f)) {
 
  209                    continue;
  210                }
  211 
  213                    continue;
  214 
  218 
  222                    if (!md5secret)
  223                        continue;
  225                    if (!strcmp(md5passwd, md5secret)) {
  228                            ast_channel_accountcode_set(chan, 
buf);
 
  230                        }
  231                        break;
  232                    }
  233                } else {
  234                    if (!strcmp(passwd, 
buf)) {
 
  237                            ast_channel_accountcode_set(chan, 
buf);
 
  239                        }
  240                        break;
  241                    }
  242                }
  243            }
  244 
  245            fclose(f);
  246 
  249                    if (md5secret && !strcmp(md5passwd, md5secret))
  250                        break;
  251                } else {
  252                    if (!strcmp(passwd, 
buf))
 
  253                        break;
  254                }
  255            }
  256        }
  257        prompt = 
"auth-incorrect";
 
  258    }
  259 
  260    if ((retries < 3) && !res) {
  263            ast_channel_accountcode_set(chan, passwd);
  265        }
  268    } else {
  271        res = -1;
  272    }
  273 
  274    return res;
  275}
static const struct ast_app_option auth_app_options[128]
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
char * strsep(char **str, const char *delims)
static struct ast_str * prompt
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_channel_lock(chan)
const char * ast_channel_language(const struct ast_channel *chan)
int ast_answer(struct ast_channel *chan)
Answer a channel.
#define ast_channel_unlock(chan)
ast_channel_state
ast_channel states
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_APP_ARG(name)
Define an application argument.
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.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
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.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Structure used to handle boolean flags.
#define ast_test_flag(p, flag)
void ast_md5_hash(char *output, const char *input)
Produces MD5 hash based on input string.