Lines Matching defs:ctx

120 int get_password(struct passwd_ctx *ctx)
123 if (ctx->passwd_src == PW_STDIN) {
126 if (apr_file_open_stdin(&file_stdin, ctx->pool) != APR_SUCCESS) {
127 ctx->errstr = "Unable to read from stdin.";
142 ctx->passwd = apr_pstrdup(ctx->pool, buf);
144 else if (ctx->passwd_src == PW_PROMPT_VERIFY) {
148 ctx->passwd = apr_pstrdup(ctx->pool, buf);
154 ctx->passwd = apr_pstrdup(ctx->pool, buf);
158 if (strcmp(ctx->passwd, buf) != 0) {
159 ctx->errstr = "password verification error";
160 memset(ctx->passwd, '\0', strlen(ctx->passwd));
169 ctx->errstr = apr_psprintf(ctx->pool,
171 ctx->out_len - 1);
177 * indicates success; on failure, ctx->errstr points to the error message.
179 int mkhash(struct passwd_ctx *ctx)
189 if (ctx->cost != 0 && ctx->alg != ALG_BCRYPT) {
194 if (ctx->passwd == NULL) {
195 if ((ret = get_password(ctx)) != 0)
198 pw = ctx->passwd;
200 switch (ctx->alg) {
203 apr_sha1_base64(pw, strlen(pw), ctx->out);
207 ret = generate_salt(salt, 8, &ctx->errstr, ctx->pool);
210 rv = apr_md5_encode(pw, salt, ctx->out, ctx->out_len);
212 ctx->errstr = apr_psprintf(ctx->pool,
220 apr_cpystrn(ctx->out, pw, ctx->out_len);
225 ret = generate_salt(salt, 8, &ctx->errstr, ctx->pool);
231 ctx->errstr = apr_psprintf(ctx->pool, "crypt() failed: %pm", &rv);
236 apr_cpystrn(ctx->out, cbuf, ctx->out_len - 1);
238 char *truncpw = apr_pstrdup(ctx->pool, pw);
240 if (!strcmp(ctx->out, crypt(truncpw, salt))) {
253 ctx->errstr = apr_psprintf(ctx->pool, "Unable to generate random "
259 if (ctx->cost == 0)
260 ctx->cost = BCRYPT_DEFAULT_COST;
261 rv = apr_bcrypt_encode(pw, ctx->cost, (unsigned char*)salt, 16,
262 ctx->out, ctx->out_len);
264 ctx->errstr = apr_psprintf(ctx->pool, "Unable to encode with "
274 ctx->alg);
281 int parse_common_options(struct passwd_ctx *ctx, char opt,
286 ctx->passwd_src = PW_ARG;
289 ctx->passwd_src = PW_STDIN;
292 ctx->alg = ALG_APMD5;
295 ctx->alg = ALG_APSHA;
298 ctx->alg = ALG_PLAIN;
308 ctx->alg = ALG_CRYPT;
315 ctx->alg = ALG_APMD5;
320 ctx->alg = ALG_BCRYPT;
323 ctx->errstr = "BCRYPT algorithm not supported on this platform";
331 ctx->errstr = "argument to -C must be a positive integer";
334 ctx->cost = num;