krb5_error_code ret;
krb5_verify_init_creds_opt opt;
+ /* XXX error messages shouldn't be logged here (and in the while() loop in
+ * authenticate_user_krb5pwd() as weell), in order to avoid confusing log
+ * entries when using multiple realms */
+
memset(&creds, 0, sizeof(creds));
ret = krb5_get_init_creds_password(context, &creds, principal,
(char *)password, krb5_prompter_posix,
NULL, 0, NULL, NULL);
- if (ret)
+ if (ret) {
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+ "krb5_get_init_creds_password() failed: %s",
+ krb5_get_err_text(context, ret));
return ret;
+ }
ret = krb5_sname_to_principal(context, ap_get_server_name(r), service,
KRB5_NT_SRV_HST, &server);
- if (ret)
+ if (ret) {
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+ "krb5_sname_to_principal() failed: %s",
+ krb5_get_err_text(context, ret));
goto end;
+ }
krb5_verify_init_creds_opt_init(&opt);
krb5_verify_init_creds_opt_set_ap_req_nofail(&opt, krb_verify_kdc);
ret = krb5_verify_init_creds(context, &creds, server, keytab, NULL, &opt);
- if (ret)
+ if (ret) {
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+ "krb5_verify_init_creds() failed: %s",
+ krb5_get_err_text(context, ret));
goto end;
-
+ }
+
if (ccache) {
ret = krb5_cc_initialize(context, ccache, principal);
- if (ret == 0)
- ret = krb5_cc_store_cred(context, ccache, &creds);
+ if (ret) {
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+ "krb5_cc_initialize() failed: %s",
+ krb5_get_err_text(context, ret));
+ goto end;
+ }
+
+ ret = krb5_cc_store_cred(context, ccache, &creds);
+ if (ret) {
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+ "krb5_cc_store_cred() failed: %s",
+ krb5_get_err_text(context, ret));
+ goto end;
+ }
}
end:
}
sent_pw = ap_pbase64decode(r->pool, auth_line);
- if (sent_pw == NULL || *sent_pw == '\0') {
- log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "empty passwords are not accepted");
- ret = HTTP_UNAUTHORIZED;
- goto end;
- }
-
sent_name = ap_getword (r->pool, &sent_pw, ':');
/* do not allow user to override realm setting of server */
if (strchr(sent_name, '@')) {
goto end;
}
- /* XXX Heimdal allows to use the MEMORY: type with empty argument ? */
- ccname = ap_psprintf(r->pool, "MEMORY:%s/krb5cc_apache_XXXXXX", P_tmpdir);
- fd = mkstemp(ccname + strlen("MEMORY:"));
- if (fd < 0) {
+ if (sent_pw == NULL || *sent_pw == '\0') {
log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "mkstemp() failed: %s", strerror(errno));
- ret = HTTP_INTERNAL_SERVER_ERROR;
+ "empty passwords are not accepted");
+ ret = HTTP_UNAUTHORIZED;
goto end;
}
- close(fd);
- code = krb5_cc_resolve(kcontext, ccname, &ccache);
+#ifdef HEIMDAL
+ code = krb5_cc_gen_new(kcontext, &krb5_mcc_ops, &ccache);
+#else
+ code = krb5_cc_resolve(kcontext, "MEMORY:", &ccache);
+#endif
if (code) {
log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "krb5_cc_resolve() failed: %s",
+ "generating new memory ccache failed: %s",
krb5_get_err_text(kcontext, code));
ret = HTTP_INTERNAL_SERVER_ERROR;
unlink(ccname);
realms = conf->krb_auth_realms;
do {
if (realms && (code = krb5_set_default_realm(kcontext,
- ap_getword_white(r->pool, &realms))))
+ ap_getword_white(r->pool, &realms)))){
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+ "krb5_set_default_realm() failed: %s",
+ krb5_get_err_text(kcontext, code));
continue;
+ }
if (client) {
krb5_free_principal(kcontext, client);
client = NULL;
}
code = krb5_parse_name(kcontext, sent_name, &client);
- if (code)
+ if (code) {
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+ "krb5_parse_name() failed: %s",
+ krb5_get_err_text(kcontext, code));
continue;
+ }
code = verify_krb5_user(r, kcontext, client, ccache, sent_pw,
conf->krb_service_name,
memset((char *)sent_pw, 0, strlen(sent_pw));
if (code) {
- /* XXX log only in the verify_krb5_user() call */
- log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "Verifying krb5 password failed: %s",
- krb5_get_err_text(kcontext, code));
if (!conf->krb_authoritative && all_principals_unkown == 1 && code == KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN)
ret = DECLINED;
else
gss_name_t server_name = GSS_C_NO_NAME;
char buf[1024];
- snprintf(buf, sizeof(buf), "%s/%s", conf->krb_service_name, ap_get_server_name(r));
+#if 0
+ /* Don't specify service name. This makes MIT 1.3 not to use replay caches,
+ * which causes large problems with the Microsoft krb5 implementation. MS
+ * obviously uses a format of the krb5 authenticator that is considered by
+ * the MIT as replay (Two valid MS authenticators may contain the same time
+ * and utime fields and only differ in the sequential numbers).
+ */
+ snprintf(buf, sizeof(buf), "%s/%s", conf->krb_service_name,
+ ap_get_server_name(r));
input_token.value = buf;
input_token.length = strlen(buf) + 1;
"gss_import_name() failed"));
return HTTP_INTERNAL_SERVER_ERROR;
}
+#endif
major_status = gss_acquire_cred(&minor_status, server_name, GSS_C_INDEFINITE,
GSS_C_NO_OID_SET, GSS_C_ACCEPT,