/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/
err_too_long:
ctx->errstr = apr_psprintf(ctx->pool, "password too long (>%" APR_SIZE_T_FMT ")", sizeof(buf) - 1); return ERR_OVERFLOW;
}
/* * Make a password record from the given information. A zero return * indicates success; on failure, ctx->errstr points to the error message.
*/ int mkhash(struct passwd_ctx *ctx)
{ char *pw; char salt[17];
apr_status_t rv; int ret = 0; #if CRYPT_ALGO_SUPPORTED char *cbuf; #endif #ifdef HAVE_CRYPT_SHA2 constchar *setting; char method; #endif
if (ctx->cost != 0 && ctx->alg != ALG_BCRYPT
&& ctx->alg != ALG_CRYPT_SHA256 && ctx->alg != ALG_CRYPT_SHA512 ) {
apr_file_printf(errfile, "Warning: Ignoring -C/-r argument for this algorithm." NL);
}
if (ctx->passwd == NULL) { if ((ret = get_password(ctx)) != 0) return ret;
}
pw = ctx->passwd;
switch (ctx->alg) { case ALG_APSHA: /* XXX out >= 28 + strlen(sha1) chars - fixed len SHA */
apr_sha1_base64(pw, strlen(pw), ctx->out); break;
case ALG_APMD5:
ret = generate_salt(salt, 8, &ctx->errstr, ctx->pool); if (ret != 0) break;
rv = apr_md5_encode(pw, salt, ctx->out, ctx->out_len); if (rv != APR_SUCCESS) {
ctx->errstr = apr_psprintf(ctx->pool, "could not encode password: %pm", &rv);
ret = ERR_GENERAL;
} break;
case ALG_PLAIN: /* XXX this len limitation is not in sync with any HTTPd len. */
apr_cpystrn(ctx->out, pw, ctx->out_len); break;
#if CRYPT_ALGO_SUPPORTED case ALG_CRYPT:
ret = generate_salt(salt, 8, &ctx->errstr, ctx->pool); if (ret != 0) break;
cbuf = crypt(pw, salt); if (cbuf == NULL) {
rv = APR_FROM_OS_ERROR(errno);
ctx->errstr = apr_psprintf(ctx->pool, "crypt() failed: %pm", &rv);
ret = ERR_PWMISMATCH; break;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.