|
|
0e5650 |
|
|
|
0e5650 |
Add S4U2Proxy feature:
|
|
|
0e5650 |
|
|
|
0e5650 |
http://sourceforge.net/mailarchive/forum.php?thread_name=4EE665D1.3000308%40redhat.com&forum_name=modauthkerb-help
|
|
|
0e5650 |
|
|
|
0e5650 |
The attached patches add support for using s4u2proxy
|
|
|
0e5650 |
(http://k5wiki.kerberos.org/wiki/Projects/Services4User) to allow the
|
|
|
0e5650 |
web service to obtain credentials on behalf of the authenticated user.
|
|
|
0e5650 |
|
|
|
0e5650 |
The first patch adds basic support for s4u2proxy. This requires the web
|
|
|
0e5650 |
administrator to manually create and manage the credentails cache for
|
|
|
0e5650 |
the apache user (via a cron job, for example).
|
|
|
0e5650 |
|
|
|
0e5650 |
The second patch builds on this and makes mod_auth_kerb manage the
|
|
|
0e5650 |
ccache instead.
|
|
|
0e5650 |
|
|
|
0e5650 |
These are patches against the current CVS HEAD (mod_auth_krb 5.4).
|
|
|
0e5650 |
|
|
|
0e5650 |
I've added a new module option to enable this support,
|
|
|
0e5650 |
KrbConstrainedDelegation. The default is off.
|
|
|
0e5650 |
|
|
|
0e5650 |
--- mod_auth_kerb-5.4.orig/README 2008-11-26 11:51:05.000000000 -0500
|
|
|
0e5650 |
+++ mod_auth_kerb-5.4/README 2012-01-04 11:17:22.000000000 -0500
|
|
|
0e5650 |
@@ -122,4 +122,16 @@ KrbSaveCredentials, the tickets will be
|
|
|
0e5650 |
credential cache that will be available for the request handler. The ticket
|
|
|
0e5650 |
file will be removed after request is handled.
|
|
|
0e5650 |
|
|
|
0e5650 |
+Constrained Delegation
|
|
|
0e5650 |
+----------------------
|
|
|
0e5650 |
+S4U2Proxy, or constrained delegation, enables a service to use a client's
|
|
|
0e5650 |
+ticket to itself to request another ticket for delegation. The KDC
|
|
|
0e5650 |
+checks krbAllowedToDelegateTo to decide if it will issue a new ticket.
|
|
|
0e5650 |
+If KrbConstrainedDelegation is enabled the server will use its own credentials
|
|
|
0e5650 |
+to retrieve a delegated ticket for the user. For this to work the user must
|
|
|
0e5650 |
+have a forwardable ticket (though the delegation flag need not be set).
|
|
|
0e5650 |
+The server needs a valid credentials cache for this to work.
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+The module itself will obtain and manage the necessary credentials.
|
|
|
0e5650 |
+
|
|
|
0e5650 |
$Id: README,v 1.12 2008/09/17 14:01:55 baalberith Exp $
|
|
|
0e5650 |
diff -up --recursive mod_auth_kerb-5.4.orig/src/mod_auth_kerb.c mod_auth_kerb-5.4/src/mod_auth_kerb.c
|
|
|
0e5650 |
--- mod_auth_kerb-5.4.orig/src/mod_auth_kerb.c 2011-12-09 17:55:05.000000000 -0500
|
|
|
0e5650 |
+++ mod_auth_kerb-5.4/src/mod_auth_kerb.c 2012-03-01 14:19:40.000000000 -0500
|
|
|
0e5650 |
@@ -42,6 +42,31 @@
|
|
|
0e5650 |
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
0e5650 |
*/
|
|
|
0e5650 |
|
|
|
0e5650 |
+/*
|
|
|
0e5650 |
+ * Locking mechanism inspired by mod_rewrite.
|
|
|
0e5650 |
+ *
|
|
|
0e5650 |
+ * Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
0e5650 |
+ * contributor license agreements. See the NOTICE file distributed with
|
|
|
0e5650 |
+ * this work for additional information regarding copyright ownership.
|
|
|
0e5650 |
+ * The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
0e5650 |
+ * (the "License"); you may not use this file except in compliance with
|
|
|
0e5650 |
+ * the License. You may obtain a copy of the License at
|
|
|
0e5650 |
+ *
|
|
|
0e5650 |
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
0e5650 |
+ *
|
|
|
0e5650 |
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
0e5650 |
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
0e5650 |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
0e5650 |
+ * See the License for the specific language governing permissions and
|
|
|
0e5650 |
+ * limitations under the License.
|
|
|
0e5650 |
+ */
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+/*
|
|
|
0e5650 |
+ * S4U2Proxy code
|
|
|
0e5650 |
+ *
|
|
|
0e5650 |
+ * Copyright (C) 2012 Red Hat
|
|
|
0e5650 |
+ */
|
|
|
0e5650 |
+
|
|
|
0e5650 |
#ident "$Id: mod_auth_kerb.c,v 1.150 2008/12/04 10:14:03 baalberith Exp $"
|
|
|
0e5650 |
|
|
|
0e5650 |
#include "config.h"
|
|
|
0e5650 |
@@ -49,6 +74,7 @@
|
|
|
0e5650 |
#include <stdlib.h>
|
|
|
0e5650 |
#include <stdio.h>
|
|
|
0e5650 |
#include <stdarg.h>
|
|
|
0e5650 |
+#include <unixd.h>
|
|
|
0e5650 |
|
|
|
0e5650 |
#define MODAUTHKERB_VERSION "5.4"
|
|
|
0e5650 |
|
|
|
0e5650 |
@@ -131,6 +157,12 @@ module AP_MODULE_DECLARE_DATA auth_kerb_
|
|
|
0e5650 |
module auth_kerb_module;
|
|
|
0e5650 |
#endif
|
|
|
0e5650 |
|
|
|
0e5650 |
+#ifdef STANDARD20_MODULE_STUFF
|
|
|
0e5650 |
+/* s4u2proxy only supported in 2.0+ */
|
|
|
0e5650 |
+static const char *lockname;
|
|
|
0e5650 |
+static apr_global_mutex_t *s4u2proxy_lock = NULL;
|
|
|
0e5650 |
+#endif
|
|
|
0e5650 |
+
|
|
|
0e5650 |
/***************************************************************************
|
|
|
0e5650 |
Macros To Ease Compatibility
|
|
|
0e5650 |
***************************************************************************/
|
|
|
0e5650 |
@@ -165,6 +197,7 @@ typedef struct {
|
|
|
0e5650 |
int krb_method_gssapi;
|
|
|
0e5650 |
int krb_method_k5pass;
|
|
|
0e5650 |
int krb5_do_auth_to_local;
|
|
|
0e5650 |
+ int krb5_s4u2proxy;
|
|
|
0e5650 |
#endif
|
|
|
0e5650 |
#ifdef KRB4
|
|
|
0e5650 |
char *krb_4_srvtab;
|
|
|
0e5650 |
@@ -185,6 +218,11 @@ set_kerb_auth_headers(request_rec *r, co
|
|
|
0e5650 |
|
|
|
0e5650 |
static const char*
|
|
|
0e5650 |
krb5_save_realms(cmd_parms *cmd, void *sec, const char *arg);
|
|
|
0e5650 |
+static const char *
|
|
|
0e5650 |
+cmd_delegationlock(cmd_parms *cmd, void *dconf, const char *a1);
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+static int
|
|
|
0e5650 |
+obtain_server_credentials(request_rec *r, const char *service_name);
|
|
|
0e5650 |
|
|
|
0e5650 |
#ifdef STANDARD20_MODULE_STUFF
|
|
|
0e5650 |
#define command(name, func, var, type, usage) \
|
|
|
0e5650 |
@@ -237,6 +275,12 @@ static const command_rec kerb_auth_cmds[
|
|
|
0e5650 |
|
|
|
0e5650 |
command("KrbLocalUserMapping", ap_set_flag_slot, krb5_do_auth_to_local,
|
|
|
0e5650 |
FLAG, "Set to 'on' to have Kerberos do auth_to_local mapping of principal names to system user names."),
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ command("KrbConstrainedDelegation", ap_set_flag_slot, krb5_s4u2proxy,
|
|
|
0e5650 |
+ FLAG, "Set to 'on' to have Kerberos use S4U2Proxy delegation."),
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ AP_INIT_TAKE1("KrbConstrainedDelegationLock", cmd_delegationlock, NULL,
|
|
|
0e5650 |
+ RSRC_CONF, "the filename of a lockfile used for inter-process synchronization"),
|
|
|
0e5650 |
#endif
|
|
|
0e5650 |
|
|
|
0e5650 |
#ifdef KRB4
|
|
|
0e5650 |
@@ -302,6 +346,7 @@ static void *kerb_dir_create_config(MK_P
|
|
|
0e5650 |
#endif
|
|
|
0e5650 |
#ifdef KRB5
|
|
|
0e5650 |
((kerb_auth_config *)rec)->krb5_do_auth_to_local = 0;
|
|
|
0e5650 |
+ ((kerb_auth_config *)rec)->krb5_s4u2proxy = 0;
|
|
|
0e5650 |
((kerb_auth_config *)rec)->krb_method_k5pass = 1;
|
|
|
0e5650 |
((kerb_auth_config *)rec)->krb_method_gssapi = 1;
|
|
|
0e5650 |
#endif
|
|
|
0e5650 |
@@ -319,6 +364,24 @@ krb5_save_realms(cmd_parms *cmd, void *v
|
|
|
0e5650 |
return NULL;
|
|
|
0e5650 |
}
|
|
|
0e5650 |
|
|
|
0e5650 |
+static const char *
|
|
|
0e5650 |
+cmd_delegationlock(cmd_parms *cmd, void *dconf, const char *a1)
|
|
|
0e5650 |
+{
|
|
|
0e5650 |
+ const char *error;
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((error = ap_check_cmd_context(cmd, GLOBAL_ONLY)) != NULL)
|
|
|
0e5650 |
+ return error;
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ /* fixup the path, especially for s4u2proxylock_remove() */
|
|
|
0e5650 |
+ lockname = ap_server_root_relative(cmd->pool, a1);
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if (!lockname) {
|
|
|
0e5650 |
+ return apr_pstrcat(cmd->pool, "Invalid KrbConstrainedDelegationLock path ", a1, NULL);
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ return NULL;
|
|
|
0e5650 |
+}
|
|
|
0e5650 |
+
|
|
|
0e5650 |
static void
|
|
|
0e5650 |
log_rerror(const char *file, int line, int level, int status,
|
|
|
0e5650 |
const request_rec *r, const char *fmt, ...)
|
|
|
0e5650 |
@@ -1170,6 +1233,7 @@ get_gss_creds(request_rec *r,
|
|
|
0e5650 |
gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
|
|
|
0e5650 |
OM_uint32 major_status, minor_status, minor_status2;
|
|
|
0e5650 |
gss_name_t server_name = GSS_C_NO_NAME;
|
|
|
0e5650 |
+ gss_cred_usage_t usage = GSS_C_ACCEPT;
|
|
|
0e5650 |
char buf[1024];
|
|
|
0e5650 |
int have_server_princ;
|
|
|
0e5650 |
|
|
|
0e5650 |
@@ -1212,10 +1276,14 @@ get_gss_creds(request_rec *r,
|
|
|
0e5650 |
|
|
|
0e5650 |
log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Acquiring creds for %s",
|
|
|
0e5650 |
token.value);
|
|
|
0e5650 |
+ if (conf->krb5_s4u2proxy) {
|
|
|
0e5650 |
+ usage = GSS_C_BOTH;
|
|
|
0e5650 |
+ obtain_server_credentials(r, conf->krb_service_name);
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
gss_release_buffer(&minor_status, &token);
|
|
|
0e5650 |
|
|
|
0e5650 |
major_status = gss_acquire_cred(&minor_status, server_name, GSS_C_INDEFINITE,
|
|
|
0e5650 |
- GSS_C_NO_OID_SET, GSS_C_ACCEPT,
|
|
|
0e5650 |
+ GSS_C_NO_OID_SET, usage,
|
|
|
0e5650 |
server_creds, NULL, NULL);
|
|
|
0e5650 |
gss_release_name(&minor_status2, &server_name);
|
|
|
0e5650 |
if (GSS_ERROR(major_status)) {
|
|
|
0e5650 |
@@ -1257,6 +1325,293 @@ cmp_gss_type(gss_buffer_t token, gss_OID
|
|
|
0e5650 |
}
|
|
|
0e5650 |
#endif
|
|
|
0e5650 |
|
|
|
0e5650 |
+/* Renew the ticket if it will expire in under a minute */
|
|
|
0e5650 |
+#define RENEWAL_TIME 60
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+/*
|
|
|
0e5650 |
+ * Services4U2Proxy lets a server prinicipal request another service
|
|
|
0e5650 |
+ * principal on behalf of a user. To do this the Apache service needs
|
|
|
0e5650 |
+ * to have its own ccache. This will ensure that the ccache has a valid
|
|
|
0e5650 |
+ * principal and will initialize or renew new credentials when needed.
|
|
|
0e5650 |
+ */
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+static int
|
|
|
0e5650 |
+verify_server_credentials(request_rec *r,
|
|
|
0e5650 |
+ krb5_context kcontext,
|
|
|
0e5650 |
+ krb5_ccache ccache,
|
|
|
0e5650 |
+ krb5_principal princ,
|
|
|
0e5650 |
+ int *renew
|
|
|
0e5650 |
+)
|
|
|
0e5650 |
+{
|
|
|
0e5650 |
+ krb5_creds match_cred;
|
|
|
0e5650 |
+ krb5_creds creds;
|
|
|
0e5650 |
+ char * princ_name = NULL;
|
|
|
0e5650 |
+ char *tgs_princ_name = NULL;
|
|
|
0e5650 |
+ krb5_timestamp now;
|
|
|
0e5650 |
+ krb5_error_code kerr = 0;
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ *renew = 0;
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ memset (&match_cred, 0, sizeof(match_cred));
|
|
|
0e5650 |
+ memset (&creds, 0, sizeof(creds));
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if (NULL == ccache || NULL == princ) {
|
|
|
0e5650 |
+ /* Nothing to verify */
|
|
|
0e5650 |
+ *renew = 1;
|
|
|
0e5650 |
+ goto cleanup;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_unparse_name(kcontext, princ, &princ_name))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Could not unparse principal %s (%d)",
|
|
|
0e5650 |
+ error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto cleanup;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
|
|
|
0e5650 |
+ "Using principal %s for s4u2proxy", princ_name);
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ tgs_princ_name = apr_psprintf(r->pool, "%s/%.*s@%.*s", KRB5_TGS_NAME,
|
|
|
0e5650 |
+ krb5_princ_realm(kcontext, princ)->length,
|
|
|
0e5650 |
+ krb5_princ_realm(kcontext, princ)->data,
|
|
|
0e5650 |
+ krb5_princ_realm(kcontext, princ)->length,
|
|
|
0e5650 |
+ krb5_princ_realm(kcontext, princ)->data);
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_parse_name(kcontext, tgs_princ_name, &match_cred.server)))
|
|
|
0e5650 |
+ {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Could not parse principal %s: %s (%d)",
|
|
|
0e5650 |
+ tgs_princ_name, error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto cleanup;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ match_cred.client = princ;
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_cc_retrieve_cred(kcontext, ccache, 0, &match_cred, &creds)))
|
|
|
0e5650 |
+ {
|
|
|
0e5650 |
+ krb5_unparse_name(kcontext, princ, &princ_name);
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
|
|
|
0e5650 |
+ "Could not unparse principal %s: %s (%d)",
|
|
|
0e5650 |
+ princ_name, error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto cleanup;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_timeofday(kcontext, &now))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Could not get current time: %d (%s)",
|
|
|
0e5650 |
+ kerr, error_message(kerr));
|
|
|
0e5650 |
+ goto cleanup;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if (now > (creds.times.endtime + RENEWAL_TIME)) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Credentials for %s have expired or will soon "
|
|
|
0e5650 |
+ "expire - now %d endtime %d",
|
|
|
0e5650 |
+ princ_name, now, creds.times.endtime);
|
|
|
0e5650 |
+ *renew = 1;
|
|
|
0e5650 |
+ } else {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
|
|
|
0e5650 |
+ "Credentials for %s will expire at "
|
|
|
0e5650 |
+ "%d, it is now %d", princ_name, creds.times.endtime, now);
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+cleanup:
|
|
|
0e5650 |
+ /* Closing context, ccache, etc happens elsewhere */
|
|
|
0e5650 |
+ if (match_cred.server) {
|
|
|
0e5650 |
+ krb5_free_principal(kcontext, match_cred.server);
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+ if (creds.client) {
|
|
|
0e5650 |
+ krb5_free_cred_contents(kcontext, &creds);
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ return kerr;
|
|
|
0e5650 |
+}
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+static int
|
|
|
0e5650 |
+obtain_server_credentials(request_rec *r,
|
|
|
0e5650 |
+ const char *service_name)
|
|
|
0e5650 |
+{
|
|
|
0e5650 |
+ krb5_context kcontext = NULL;
|
|
|
0e5650 |
+ krb5_keytab keytab = NULL;
|
|
|
0e5650 |
+ krb5_ccache ccache = NULL;
|
|
|
0e5650 |
+ char * princ_name = NULL;
|
|
|
0e5650 |
+ char *tgs_princ_name = NULL;
|
|
|
0e5650 |
+ krb5_error_code kerr = 0;
|
|
|
0e5650 |
+ krb5_principal princ = NULL;
|
|
|
0e5650 |
+ krb5_creds creds;
|
|
|
0e5650 |
+ krb5_get_init_creds_opt gicopts;
|
|
|
0e5650 |
+ int renew = 0;
|
|
|
0e5650 |
+ apr_status_t rv = 0;
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ memset(&creds, 0, sizeof(creds));
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_init_context(&kcontext))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Kerberos context initialization failed: %s (%d)", error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto done;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_cc_default(kcontext, &ccache))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Could not get default Kerberos ccache: %s (%d)",
|
|
|
0e5650 |
+ error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto done;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_cc_get_principal(kcontext, ccache, &princ))) {
|
|
|
0e5650 |
+ char * name = NULL;
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((asprintf(&name, "%s:%s", krb5_cc_get_type(kcontext, ccache),
|
|
|
0e5650 |
+ krb5_cc_get_name(kcontext, ccache))) == -1) {
|
|
|
0e5650 |
+ kerr = KRB5_CC_NOMEM;
|
|
|
0e5650 |
+ goto done;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if (KRB5_FCC_NOFILE == kerr) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
|
|
|
0e5650 |
+ "Credentials cache %s not found, create one", name);
|
|
|
0e5650 |
+ krb5_cc_close(kcontext, ccache);
|
|
|
0e5650 |
+ ccache = NULL;
|
|
|
0e5650 |
+ free(name);
|
|
|
0e5650 |
+ } else {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Failure to open credentials cache %s: %s (%d)",
|
|
|
0e5650 |
+ name, error_message(kerr), kerr);
|
|
|
0e5650 |
+ free(name);
|
|
|
0e5650 |
+ goto done;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ kerr = verify_server_credentials(r, kcontext, ccache, princ, &renew);
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if (kerr || !renew) {
|
|
|
0e5650 |
+ goto done;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+#ifdef STANDARD20_MODULE_STUFF
|
|
|
0e5650 |
+ if (s4u2proxy_lock) {
|
|
|
0e5650 |
+ rv = apr_global_mutex_lock(s4u2proxy_lock);
|
|
|
0e5650 |
+ if (rv != APR_SUCCESS) {
|
|
|
0e5650 |
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
|
|
|
0e5650 |
+ "apr_global_mutex_lock(s4u2proxy_lock) "
|
|
|
0e5650 |
+ "failed");
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+#endif
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ /* We have the lock, check again to be sure another process hasn't already
|
|
|
0e5650 |
+ * renewed the ticket.
|
|
|
0e5650 |
+ */
|
|
|
0e5650 |
+ kerr = verify_server_credentials(r, kcontext, ccache, princ, &renew);
|
|
|
0e5650 |
+ if (kerr || !renew) {
|
|
|
0e5650 |
+ goto unlock;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if (NULL == princ) {
|
|
|
0e5650 |
+ princ_name = apr_psprintf(r->pool, "%s/%s",
|
|
|
0e5650 |
+ (service_name) ? service_name : SERVICE_NAME,
|
|
|
0e5650 |
+ ap_get_server_name(r));
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_parse_name(kcontext, princ_name, &princ))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Could not parse principal %s: %s (%d) ",
|
|
|
0e5650 |
+ princ_name, error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto unlock;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+ } else if (NULL == princ_name) {
|
|
|
0e5650 |
+ if ((kerr = krb5_unparse_name(kcontext, princ, &princ_name))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
|
|
|
0e5650 |
+ "Could not unparse principal %s: %s (%d)",
|
|
|
0e5650 |
+ princ_name, error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto unlock;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_kt_default(kcontext, &keytab))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Unable to get default keytab: %s (%d)",
|
|
|
0e5650 |
+ error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto unlock;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
|
|
|
0e5650 |
+ "Obtaining new credentials for %s", princ_name);
|
|
|
0e5650 |
+ krb5_get_init_creds_opt_init(&gicopts);
|
|
|
0e5650 |
+ krb5_get_init_creds_opt_set_forwardable(&gicopts, 1);
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ tgs_princ_name = apr_psprintf(r->pool, "%s/%.*s@%.*s", KRB5_TGS_NAME,
|
|
|
0e5650 |
+ krb5_princ_realm(kcontext, princ)->length,
|
|
|
0e5650 |
+ krb5_princ_realm(kcontext, princ)->data,
|
|
|
0e5650 |
+ krb5_princ_realm(kcontext, princ)->length,
|
|
|
0e5650 |
+ krb5_princ_realm(kcontext, princ)->data);
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_get_init_creds_keytab(kcontext, &creds, princ, keytab,
|
|
|
0e5650 |
+ 0, tgs_princ_name, &gicopts))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Failed to obtain credentials for principal %s: "
|
|
|
0e5650 |
+ "%s (%d)", princ_name, error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto unlock;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ krb5_kt_close(kcontext, keytab);
|
|
|
0e5650 |
+ keytab = NULL;
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if (NULL == ccache) {
|
|
|
0e5650 |
+ if ((kerr = krb5_cc_default(kcontext, &ccache))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Failed to open default ccache: %s (%d)",
|
|
|
0e5650 |
+ error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto unlock;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_cc_initialize(kcontext, ccache, princ))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Failed to initialize ccache for %s: %s (%d)",
|
|
|
0e5650 |
+ princ_name, error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto unlock;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if ((kerr = krb5_cc_store_cred(kcontext, ccache, &creds))) {
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
|
|
0e5650 |
+ "Failed to store %s in ccache: %s (%d)",
|
|
|
0e5650 |
+ princ_name, error_message(kerr), kerr);
|
|
|
0e5650 |
+ goto unlock;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+unlock:
|
|
|
0e5650 |
+#ifdef STANDARD20_MODULE_STUFF
|
|
|
0e5650 |
+ if (s4u2proxy_lock) {
|
|
|
0e5650 |
+ apr_global_mutex_unlock(s4u2proxy_lock);
|
|
|
0e5650 |
+ if (rv != APR_SUCCESS) {
|
|
|
0e5650 |
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
|
|
|
0e5650 |
+ "apr_global_mutex_unlock(s4u2proxy_lock) "
|
|
|
0e5650 |
+ "failed");
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+#endif
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+done:
|
|
|
0e5650 |
+ if (0 == kerr)
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
|
|
|
0e5650 |
+ "Done obtaining credentials for s4u2proxy");
|
|
|
0e5650 |
+ else
|
|
|
0e5650 |
+ log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
|
|
|
0e5650 |
+ "Failed to obtain credentials for s4u2proxy");
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ if (creds.client) {
|
|
|
0e5650 |
+ krb5_free_cred_contents(kcontext, &creds);
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+ if (ccache) {
|
|
|
0e5650 |
+ krb5_cc_close(kcontext, ccache);
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+ if (kcontext) {
|
|
|
0e5650 |
+ krb5_free_context(kcontext);
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ return kerr;
|
|
|
0e5650 |
+}
|
|
|
0e5650 |
+
|
|
|
0e5650 |
static int
|
|
|
0e5650 |
authenticate_user_gss(request_rec *r, kerb_auth_config *conf,
|
|
|
0e5650 |
const char *auth_line, char **negotiate_ret_value)
|
|
|
0e5650 |
@@ -1697,10 +2052,60 @@ have_rcache_type(const char *type)
|
|
|
0e5650 |
/***************************************************************************
|
|
|
0e5650 |
Module Setup/Configuration
|
|
|
0e5650 |
***************************************************************************/
|
|
|
0e5650 |
+#ifdef STANDARD20_MODULE_STUFF
|
|
|
0e5650 |
+static apr_status_t
|
|
|
0e5650 |
+s4u2proxylock_create(server_rec *s, apr_pool_t *p)
|
|
|
0e5650 |
+{
|
|
|
0e5650 |
+ apr_status_t rc;
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ /* only operate if a lockfile is used */
|
|
|
0e5650 |
+ if (lockname == NULL || *(lockname) == '\0') {
|
|
|
0e5650 |
+ return APR_SUCCESS;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ /* create the lockfile */
|
|
|
0e5650 |
+ rc = apr_global_mutex_create(&s4u2proxy_lock, lockname,
|
|
|
0e5650 |
+ APR_LOCK_DEFAULT, p);
|
|
|
0e5650 |
+ if (rc != APR_SUCCESS) {
|
|
|
0e5650 |
+ ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s,
|
|
|
0e5650 |
+ "Parent could not create lock file %s", lockname);
|
|
|
0e5650 |
+ return rc;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+#ifdef AP_NEED_SET_MUTEX_PERMS
|
|
|
0e5650 |
+ rc = unixd_set_global_mutex_perms(s4u2proxy_lock);
|
|
|
0e5650 |
+ if (rc != APR_SUCCESS) {
|
|
|
0e5650 |
+ ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s,
|
|
|
0e5650 |
+ "mod_auth_kerb: Parent could not set permissions "
|
|
|
0e5650 |
+ "on lock; check User and Group directives");
|
|
|
0e5650 |
+ return rc;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+#endif
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ return APR_SUCCESS;
|
|
|
0e5650 |
+}
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+static apr_status_t
|
|
|
0e5650 |
+s4u2proxylock_remove(void *unused)
|
|
|
0e5650 |
+{
|
|
|
0e5650 |
+ /* only operate if a lockfile is used */
|
|
|
0e5650 |
+ if (lockname == NULL || *(lockname) == '\0') {
|
|
|
0e5650 |
+ return APR_SUCCESS;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ /* destroy the rewritelock */
|
|
|
0e5650 |
+ apr_global_mutex_destroy(s4u2proxy_lock);
|
|
|
0e5650 |
+ s4u2proxy_lock = NULL;
|
|
|
0e5650 |
+ lockname = NULL;
|
|
|
0e5650 |
+ return APR_SUCCESS;
|
|
|
0e5650 |
+}
|
|
|
0e5650 |
+#endif
|
|
|
0e5650 |
+
|
|
|
0e5650 |
#ifndef STANDARD20_MODULE_STUFF
|
|
|
0e5650 |
static void
|
|
|
0e5650 |
kerb_module_init(server_rec *dummy, pool *p)
|
|
|
0e5650 |
{
|
|
|
0e5650 |
+ apr_status_t status;
|
|
|
0e5650 |
#ifndef HEIMDAL
|
|
|
0e5650 |
/* Suppress the MIT replay cache. Requires MIT Kerberos 1.4.0 or later.
|
|
|
0e5650 |
1.3.x are covered by the hack overiding the replay calls */
|
|
|
0e5650 |
@@ -1741,6 +2146,7 @@ static int
|
|
|
0e5650 |
kerb_init_handler(apr_pool_t *p, apr_pool_t *plog,
|
|
|
0e5650 |
apr_pool_t *ptemp, server_rec *s)
|
|
|
0e5650 |
{
|
|
|
0e5650 |
+ apr_status_t rv;
|
|
|
0e5650 |
ap_add_version_component(p, "mod_auth_kerb/" MODAUTHKERB_VERSION);
|
|
|
0e5650 |
#ifndef HEIMDAL
|
|
|
0e5650 |
/* Suppress the MIT replay cache. Requires MIT Kerberos 1.4.0 or later.
|
|
|
0e5650 |
@@ -1748,14 +2154,41 @@ kerb_init_handler(apr_pool_t *p, apr_poo
|
|
|
0e5650 |
if (getenv("KRB5RCACHETYPE") == NULL && have_rcache_type("none"))
|
|
|
0e5650 |
putenv(strdup("KRB5RCACHETYPE=none"));
|
|
|
0e5650 |
#endif
|
|
|
0e5650 |
+#ifdef STANDARD20_MODULE_STUFF
|
|
|
0e5650 |
+ rv = s4u2proxylock_create(s, p);
|
|
|
0e5650 |
+ if (rv != APR_SUCCESS) {
|
|
|
0e5650 |
+ return HTTP_INTERNAL_SERVER_ERROR;
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+ apr_pool_cleanup_register(p, (void *)s, s4u2proxylock_remove,
|
|
|
0e5650 |
+ apr_pool_cleanup_null);
|
|
|
0e5650 |
+#endif
|
|
|
0e5650 |
|
|
|
0e5650 |
return OK;
|
|
|
0e5650 |
}
|
|
|
0e5650 |
|
|
|
0e5650 |
static void
|
|
|
0e5650 |
+initialize_child(apr_pool_t *p, server_rec *s)
|
|
|
0e5650 |
+{
|
|
|
0e5650 |
+ apr_status_t rv = 0;
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+#ifdef STANDARD20_MODULE_STUFF
|
|
|
0e5650 |
+ if (lockname != NULL && *(lockname) != '\0') {
|
|
|
0e5650 |
+ rv = apr_global_mutex_child_init(&s4u2proxy_lock, lockname, p);
|
|
|
0e5650 |
+ if (rv != APR_SUCCESS) {
|
|
|
0e5650 |
+ ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
|
|
|
0e5650 |
+ "mod_auth_kerb: could not init s4u2proxy_lock"
|
|
|
0e5650 |
+ " in child");
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+ }
|
|
|
0e5650 |
+#endif
|
|
|
0e5650 |
+}
|
|
|
0e5650 |
+
|
|
|
0e5650 |
+static void
|
|
|
0e5650 |
kerb_register_hooks(apr_pool_t *p)
|
|
|
0e5650 |
{
|
|
|
0e5650 |
ap_hook_post_config(kerb_init_handler, NULL, NULL, APR_HOOK_MIDDLE);
|
|
|
0e5650 |
+ ap_hook_child_init(initialize_child, NULL, NULL, APR_HOOK_MIDDLE);
|
|
|
0e5650 |
ap_hook_check_user_id(kerb_authenticate_user, NULL, NULL, APR_HOOK_MIDDLE);
|
|
|
0e5650 |
}
|
|
|
0e5650 |
|