Various code rearrangements to achieve portable password verification.
[mod_auth_kerb.cvs/.git] / src / mod_auth_kerb.c
index f4b2585..a480f47 100644 (file)
@@ -1,6 +1,8 @@
 /*************************************************************************** 
  Included Headers And Module Declaration
  ***************************************************************************/
+#ident "$Id$"
+
 #ifdef APXS1
 #include "httpd.h"
 #include "http_config.h"
@@ -28,6 +30,7 @@ module AP_MODULE_DECLARE_DATA kerb_auth_module;
 
 #ifdef KRB5
 #include <krb5.h>
+#include <gssapi.h>
 #endif /* KRB5 */
 
 #ifdef KRB4
@@ -47,7 +50,6 @@ module AP_MODULE_DECLARE_DATA kerb_auth_module;
 #define MK_TABLE_TYPE table
 #define MK_PSTRDUP ap_pstrdup
 #define MK_PROXY STD_PROXY
-#define MK_RERROR_LEVEL ""
 #define MK_USER r->connection->user
 #define MK_AUTH_TYPE r->connection->ap_auth_type
 #define MK_ARRAY_HEADER array_header
@@ -59,7 +61,6 @@ module AP_MODULE_DECLARE_DATA kerb_auth_module;
 #define MK_TABLE_TYPE apr_table_t
 #define MK_PSTRDUP apr_pstrdup
 #define MK_PROXY PROXYREQ_PROXY
-#define MK_RERROR_LEVEL "0, "
 #define MK_USER r->user
 #define MK_AUTH_TYPE r->ap_auth_type
 #define MK_ARRAY_HEADER apr_array_header_t
@@ -93,8 +94,30 @@ typedef struct {
 #endif /* KRB5 */
        int krb_save_credentials;
        char *krb_tmp_dir;
+       char *service_name;
 } kerb_auth_config;
 
+typedef struct {
+   gss_ctx_id_t context;
+   gss_cred_id_t server_creds;
+} gss_connection_t;
+
+static gss_connection_t *gss_connection = NULL;
+
+static void
+cleanup_gss_connection(void *data)
+{
+   OM_uint32 minor_status;
+   gss_connection_t *gss_conn = (gss_connection_t *)data;
+
+   if (data == NULL)
+      return;
+   if (gss_conn->context != GSS_C_NO_CONTEXT)
+      gss_delete_sec_context(&minor_status, &gss_conn->context,
+                            GSS_C_NO_BUFFER);
+   if (gss_conn->server_creds != GSS_C_NO_CREDENTIAL)
+      gss_release_cred(&minor_status, &gss_conn->server_creds);
+}
 
 
 
@@ -137,18 +160,17 @@ static const char *kerb_set_type_slot(cmd_parms *cmd, void *struct_ptr,
                                        const char *arg)
 {
        int offset = (int) (long) cmd->info;
-       if
 #ifdef KRB5
-          (!strncasecmp(arg, "v5", 2))
+       if (!strncasecmp(arg, "v5", 2))
                *(char **) ((char *)struct_ptr + offset) = MK_PSTRDUP(cmd->pool, "KerberosV5");
-       else if
+       else
 #endif /* KRB5 */
 #ifdef KRB4
-          (!strncasecmp(arg, "v4", 2))
+       if (!strncasecmp(arg, "v4", 2))
                *(char **) ((char *)struct_ptr + offset) = MK_PSTRDUP(cmd->pool, "KerberosV4");
+       else
 #endif /* KRB4 */
-       else if
-          (!strncasecmp(arg, "dualv5v4", 8))
+       if (!strncasecmp(arg, "dualv5v4", 8))
                *(char **) ((char *)struct_ptr + offset) = MK_PSTRDUP(cmd->pool, "KerberosDualV5V4");
        else if
           (!strncasecmp(arg, "dualv4v5", 8))
@@ -288,7 +310,7 @@ command_rec kerb_auth_cmds[] = {
                "KrbTmpdir",
                ap_set_string_slot,
                (void*)XtOffsetOf(kerb_auth_config, krb_tmp_dir),
-               OR_AUTHCFG,
+               RSRC_CONF & ACCESS_CONF,
                TAKE1,
                "Path to store ticket files and such in."
        },
@@ -406,7 +428,7 @@ static const command_rec kerb_auth_cmds[] = {
                "KrbTmpdir",
                ap_set_string_slot,
                (void*)APR_XtOffsetOf(kerb_auth_config, krb_tmp_dir),
-               OR_AUTHCFG,
+               RSRC_CONF & ACCESS_CONF,
                "Path to store ticket files and such in."
        ),
 
@@ -416,72 +438,251 @@ static const command_rec kerb_auth_cmds[] = {
 #endif /* APXS1 */
 
 
+#ifndef HEIMDAL
+krb5_error_code
+krb5_verify_user(krb5_context context, krb5_principal principal,
+                krb5_ccache ccache, const char *password, krb5_boolean secure,
+                const char *service)
+{
+   int problem;
+   krb5_creds my_creds;
+   krb5_data tgtname = {
+      0,
+      KRB5_TGS_NAME_SIZE,
+      KRB5_TGS_NAME
+   }
+
+   memset((char *)&my_creds, 0, sizeof(my_creds));
+   my_creds.client = principal;
+
+   if (krb5_build_principal_ext(kcontext, &server,
+                               krb5_princ_realm(kcontext, me)->length,
+                               krb5_princ_realm(kcontext, me)->data,
+                               tgtname.length, tgtname.data,
+                               krb5_princ_realm(kcontext, me)->length,
+                               krb5_princ_realm(kcontext, me)->data,
+                               0)) {
+       return ret;
+   }
+
+   my_creds.server = server;
+   if (krb5_timeofday(kcontext, &now))
+       return -1;
+
+   my_creds.times.starttime = 0;
+   /* XXX
+   my_creds.times.endtime = now + lifetime;
+   my_creds.times.renew_till = now + renewal;
+   */
+
+   ret = krb5_get_in_tkt_with_password(kcontext, options, 0, NULL, 0,
+                                      pass, ccache, &my_creds, 0);
+   if (ret) {
+       return ret;
+   }
+
+   return 0;
+}
+#endif
 
 
 /*************************************************************************** 
  Username/Password Validation
  ***************************************************************************/
 #ifdef KRB5
-int kerb5_password_validate(const char *user, const char *pass) {
+int kerb5_password_validate(request_rec *r, const char *user, const char *pass)
+{
+       kerb_auth_config *conf =
+               (kerb_auth_config *)ap_get_module_config(r->per_dir_config,
+                                       &kerb_auth_module);
        int ret;
        krb5_context kcontext;
        krb5_principal server, me;
        krb5_creds my_creds;
        krb5_timestamp now;
-       krb5_deltat lifetime = 0;
+       krb5_ccache ccache = NULL;
+       krb5_deltat lifetime = 300;     /* 5 minutes */
+       krb5_deltat renewal = 0;
+       krb5_flags options = 0;
        krb5_data tgtname = {
+#ifndef HEIMDAL
                0,
+#endif
                KRB5_TGS_NAME_SIZE,
                KRB5_TGS_NAME
        };
+       char *c, ccname[MAX_STRING_LEN];
 
        if (krb5_init_context(&kcontext))
                return 0;
 
-       memset((char *)&my_creds, 0, sizeof(my_creds));
-       if(krb5_parse_name(kcontext, user, &me))
-               return 0;
-       my_creds.client = me;
+       if (conf->krb_forwardable) {
+          options |= KDC_OPT_FORWARDABLE;
+       }
 
-       if (krb5_build_principal_ext(kcontext, &server,
-                               krb5_princ_realm(kcontext, me)->length,
-                               krb5_princ_realm(kcontext, me)->data,
-                               tgtname.length, tgtname.data,
-                               krb5_princ_realm(kcontext, me)->length,
-                               krb5_princ_realm(kcontext, me)->data,
-                               0)) {
-               return 0;
+       if (conf->krb_renewable) {
+          options |= KDC_OPT_RENEWABLE;
+          renewal = 86400;        /* 24 hours */
        }
-       my_creds.server = server;
-       if (krb5_timeofday(kcontext, &now))
-               return 0;
-       my_creds.times.starttime = 0;
-       my_creds.times.endtime = now + lifetime;
-       my_creds.times.renew_till = 0;
 
-       ret = krb5_get_in_tkt_with_password(kcontext, 0, 0, NULL, 0,
-                               pass, NULL, &my_creds, 0);
-       if (ret) {
-               return 0;
+       if (conf->krb_lifetime) {
+          lifetime = atoi(conf->krb_lifetime);
        }
 
-       krb5_free_cred_contents(kcontext, &my_creds);
+       code = krb5_cc_gen_new(kcontext, &krb5_mcc_ops, &ccache);
+       if (code) {
+          snprintf(errstr, sizeof(errstr), "krb5_cc_gen_new(): %.100s",
+                   krb5_get_err_text(kcontext, code));
+          ap_log_reason (errstr, r->uri, r);
+          ret = SERVER_ERROR;
+          goto end;
+       }
+
+       realms = conf->krb5_auth_realm;
+       do {
+          code = 0;
+          if (realms) {
+             code = krb5_set_default_realm(kcontext, 
+                                           ap_getword_white(r->pool, &realms));
+             if (code)
+                continue;
+          }
+
+          code = krb5_parse_name(kcontext, r->connection->user, &princ);
+          if (code)
+             continue;
+
+          code = krb5_verify_user(kcontext, princ, ccache, sent_pw,
+                                  1, "khttp");
+          if (code == 0)
+             break;
+
+          /* ap_getword_white() used above shifts the parameter, so it's not
+             needed to touch the realms variable */
+       } while (realms && *realms);
+
+       memset((char *)pass, 0, strlen(pass));
+
+       if (code) {
+          snprintf(errstr, sizeof(errstr), "Verifying krb5 password failed: %s",
+                   krb5_get_err_text(kcontext, code));
+          ap_log_reason (errstr, r->uri, r);
+          ret = HTTP_UNAUTHORIZED;
+          return 0;
+       }
+
+       if (conf->krb_save_credentials) {
+               sprintf(ccname, "FILE:%s/k5cc_ap_%s",
+                       conf->krb_tmp_dir ? conf->krb_tmp_dir : "/tmp",
+                       MK_USER);
+
+               for (c = ccname + strlen(conf->krb_tmp_dir ? conf->krb_tmp_dir :                                "/tmp") + 1; *c; c++) {
+                       if (*c == '/')
+                               *c = '.';
+               }
+
+               ap_table_setn(r->subprocess_env, "KRB5CCNAME", ccname);
+               if (krb5_cc_set_default_name(kcontext, ccname)) {
+                       return 0;
+               }
+               unlink(ccname+strlen("FILE:"));
+
+               if (krb5_cc_resolve(kcontext, ccname, &ccache))
+                       return 0;
+
+               problem = krb5_cc_get_principal(krb_ctx, mem_ccache, &me);
+
+               if (krb5_cc_initialize(kcontext, ccache, me))
+                       return 0;
+
+               problem = krb5_cc_copy_cache(krb_ctx, delegated_cred, ccache);
+               if (problem) {
+                  return 0;
+               }
+
+               krb5_cc_close(krb_ctx, ccache);
+       }
 
        return 1;
 }
 #endif /* KRB5 */
 
 #ifdef KRB4
-int kerb4_password_validate(const char *user, const char *pass) {
+int kerb4_password_validate(request_rec *r, const char *user, const char *pass)
+{
+       kerb_auth_config *conf =
+               (kerb_auth_config *)ap_get_module_config(r->per_dir_config,
+                                       &kerb_auth_module);
        int ret;
-       char realm[REALM_SZ];
-
-       ret = krb_get_lrealm(realm, 1);
-       if (ret != KSUCCESS)
+       int lifetime = DEFAULT_TKT_LIFE;
+       char *c, *tfname;
+       char *username = NULL;
+       char *instance = NULL;
+       char *realm = NULL;
+
+       username = (char *)ap_pstrdup(r->pool, user);
+       if (!username) {
                return 0;
+       }
+
+       instance = strchr(username, '.');
+       if (instance) {
+               *instance++ = '\0';
+       }
+       else {
+               instance = "";
+       }
+
+       realm = strchr(username, '@');
+       if (realm) {
+               *realm++ = '\0';
+       }
+       else {
+               realm = "";
+       }
 
-       ret = krb_get_pw_in_tkt((char *)user, "", realm, "krbtgt", realm,
-                                       DEFAULT_TKT_LIFE, (char *)pass);
+       if (conf->krb_lifetime) {
+               lifetime = atoi(conf->krb_lifetime);
+       }
+
+       if (conf->krb_force_instance) {
+               instance = conf->krb_force_instance;
+       }
+
+       if (conf->krb_save_credentials) {
+               tfname = (char *)malloc(sizeof(char) * MAX_STRING_LEN);
+               sprintf(tfname, "%s/k5cc_ap_%s",
+                       conf->krb_tmp_dir ? conf->krb_tmp_dir : "/tmp",
+                       MK_USER);
+
+               if (!strcmp(instance, "")) {
+                       tfname = strcat(tfname, ".");
+                       tfname = strcat(tfname, instance);
+               }
+
+               if (!strcmp(realm, "")) {
+                       tfname = strcat(tfname, ".");
+                       tfname = strcat(tfname, realm);
+               }
+
+               for (c = tfname + strlen(conf->krb_tmp_dir ? conf->krb_tmp_dir :
+                               "/tmp") + 1; *c; c++) {
+                       if (*c == '/')
+                               *c = '.';
+               }
+
+               krb_set_tkt_string(tfname);
+       }
+
+       if (!strcmp(realm, "")) {
+               realm = (char *)malloc(sizeof(char) * (REALM_SZ + 1));
+               ret = krb_get_lrealm(realm, 1);
+               if (ret != KSUCCESS)
+                       return 0;
+       }
+
+       ret = krb_get_pw_in_tkt((char *)user, instance, realm, "krbtgt", realm,
+                                       lifetime, (char *)pass);
        switch (ret) {
                case INTK_OK:
                case INTK_W_NOTALL:
@@ -495,13 +696,235 @@ int kerb4_password_validate(const char *user, const char *pass) {
 }
 #endif /* KRB4 */
 
+static int
+get_gss_creds(request_rec *r,
+              kerb_auth_config *conf,
+             gss_cred_id_t *server_creds)
+{
+   int ret = 0;
+   gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER;
+   OM_uint32 major_status, minor_status;
+   gss_name_t server_name = GSS_C_NO_NAME;
+
+   if (conf->service_name) {
+      input_token.value = conf->service_name;
+      input_token.length = strlen(conf->service_name) + 1;
+   }
+   else {
+      input_token.value = "khttp";
+      input_token.length = 6;
+   }
+   major_status = gss_import_name(&minor_status, &input_token,
+                                 (conf->service_name) ? 
+                                      GSS_C_NT_USER_NAME : GSS_C_NT_HOSTBASED_SERVICE,
+                                 &server_name);
+   if (GSS_ERROR(major_status)) {
+      ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, r,
+                   "%s", get_gss_error(r->pool, minor_status,
+                   "gss_import_name() failed"));
+      ret = SERVER_ERROR;
+      goto fail;
+   }
+   
+#ifdef KRB5
+   if (conf->krb_5_keytab)
+      setenv("KRB5_KTNAME", conf->krb_5_keytab, 1);
+#endif
 
+   major_status = gss_acquire_cred(&minor_status, server_name, GSS_C_INDEFINITE,
+                                  GSS_C_NO_OID_SET, GSS_C_ACCEPT,
+                                  server_creds, NULL, NULL);
+#ifdef KRB5
+   if (conf->krb_5_keytab)
+      unsetenv("KRB5_KTNAME");
+#endif
+   if (GSS_ERROR(major_status)) {
+      ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, r,
+                  "%s", get_gss_error(r->pool, minor_status,
+                                      "gss_acquire_cred() failed"));
+      ret = SERVER_ERROR;
+      goto fail;
+   }
+   
+   return 0;
+
+fail:
+   /* XXX cleanup */
+
+   return ret;
+}
+
+static int
+negotiate_authenticate_user(request_rec *r,
+                           kerb_auth_config *conf,
+                           const char *auth_line)
+{
+  OM_uint32 major_status, minor_status, minor_status2;
+  gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER;
+  gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER;
+  const char *auth_param = NULL;
+  krb5_context krb_ctx = NULL;
+  int ret;
+  gss_name_t client_name = GSS_C_NO_NAME;
+  gss_cred_id_t delegated_cred = GSS_C_NO_CREDENTIAL;
+  char *p;
+
+  if (gss_connection == NULL) {
+     gss_connection = ap_pcalloc(r->connection->pool, sizeof(*gss_connection));
+     if (gss_connection == NULL) {
+       ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, r,
+                     "ap_pcalloc() failed");
+       ret = SERVER_ERROR;
+       goto end;
+     }
+     memset(gss_connection, 0, sizeof(*gss_connection));
+     ap_register_cleanup(r->connection->pool, gss_connection, cleanup_gss_connection, ap_null_cleanup);
+  }
+
+  if (gss_connection->server_creds == GSS_C_NO_CREDENTIAL) {
+     ret = get_gss_creds(r, conf, &gss_connection->server_creds);
+     if (ret)
+       goto end;
+  }
+
+  /* ap_getword() shifts parameter */
+  auth_param = ap_getword_white(r->pool, &auth_line);
+  if (auth_param == NULL) {
+     ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, r,
+                  "No Authorization parameter from client");
+     ret = HTTP_UNAUTHORIZED;
+     goto end;
+  }
+
+  input_token.length = ap_base64decode_len(auth_param);
+  input_token.value = ap_pcalloc(r->connection->pool, input_token.length);
+  if (input_token.value == NULL) {
+     ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, r,
+                  "Not enough memory");
+     ret = SERVER_ERROR;
+     goto end;
+  }
+  input_token.length = ap_base64decode(input_token.value, auth_param);
+
+  major_status = gss_accept_sec_context(&minor_status,
+                                       &gss_connection->context,
+                                       gss_connection->server_creds,
+                                       &input_token,
+                                       GSS_C_NO_CHANNEL_BINDINGS,
+                                       &client_name,
+                                       NULL,
+                                       &output_token,
+                                       NULL,
+                                       NULL,
+                                       &delegated_cred);
+  if (output_token.length) {
+     char *token = NULL;
+     size_t len;
+     
+     len = ap_base64encode_len(output_token.length);
+     token = ap_pcalloc(r->connection->pool, len + 1);
+     if (token == NULL) {
+       ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, r,
+                    "Not enough memory");
+        ret = SERVER_ERROR;
+       gss_release_buffer(&minor_status2, &output_token);
+       goto end;
+     }
+     ap_base64encode(token, output_token.value, output_token.length);
+     token[len] = '\0';
+     ap_table_set(r->err_headers_out, "WWW-Authenticate",
+                 ap_pstrcat(r->pool, "GSS-Negotiate ", token, NULL));
+     free(token);
+     gss_release_buffer(&minor_status2, &output_token);
+  }
+
+  if (GSS_ERROR(major_status)) {
+     ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, r,
+                  "%s", get_gss_error(r->pool, minor_status,
+                                      "gss_accept_sec_context() failed"));
+     ret = HTTP_UNAUTHORIZED;
+     goto end;
+  }
+
+  if (major_status & GSS_S_CONTINUE_NEEDED) {
+#if 0
+     ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, r,
+                  "only one authentication iteration allowed"); 
+#endif
+     ret = HTTP_UNAUTHORIZED;
+     goto end;
+  }
+
+  major_status = gss_export_name(&minor_status, client_name, &output_token);
+  gss_release_name(&minor_status, &client_name); 
+  if (GSS_ERROR(major_status)) {
+    ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, r,
+                 "%s", get_gss_error(r->pool, minor_status, 
+                                     "gss_export_name() failed"));
+    ret = SERVER_ERROR;
+    goto end;
+  }
+
+  r->connection->ap_auth_type = "Negotiate";
+  r->connection->user = ap_pstrdup(r->pool, output_token.value);
+#if 0
+  /* If the user comes from a realm specified by configuration don't include
+      its realm name in the username so that the authorization routine could
+      work for both Password-based and Ticket-based authentication. It's
+      administrators responsibility to include only such realm that have
+      unified principal instances, i.e. if the same principal name occures in
+      multiple realms, it must be always assigned to a single user.
+  */    
+  p = strchr(r->connection->user, '@');
+  if (p != NULL) {
+     const char *realms = conf->gss_krb5_realms;
+
+     while (realms && *realms) {
+       if (strcmp(p+1, ap_getword_white(r->pool, &realms)) == 0) {
+          *p = '\0';
+          break;
+       }
+     }
+  }
+#endif
+
+  gss_release_buffer(&minor_status, &output_token);
+
+#if 0
+  /* This should be only done if afs token are requested or gss_save creds is 
+   * specified */
+  /* gss_export_cred() from the GGF GSS Extensions could be used */
+  if (delegated_cred != GSS_C_NO_CREDENTIAL &&
+      (conf->gss_save_creds || (conf->gss_krb5_cells && k_hasafs()))) {        
+     krb5_init_context(&krb_ctx);
+     do_afs_log(krb_ctx, r, delegated_cred->ccache, conf->gss_krb5_cells);
+     ret = store_krb5_creds(krb_ctx, r, conf, delegated_cred->ccache);
+     krb5_free_context(krb_ctx);
+     if (ret)
+       goto end;
+  }
+#endif
+  ret = OK;
+
+end:
+  if (delegated_cred)
+     gss_release_cred(&minor_status, &delegated_cred);
+
+  if (output_token.length) 
+     gss_release_buffer(&minor_status, &output_token);
+
+  if (client_name != GSS_C_NO_NAME)
+     gss_release_name(&minor_status, &client_name);
+
+  return ret;
+}
 
 
 /*************************************************************************** 
  User Authentication
  ***************************************************************************/
-int kerb_authenticate_user(request_rec *r) {
+int kerb_authenticate_user(request_rec *r)
+{
        const char *name;               /* AuthName specified */
        const char *type;               /* AuthType specified */
        int KerberosV5 = 0;             /* Kerberos V5 check enabled */
@@ -564,14 +987,13 @@ int kerb_authenticate_user(request_rec *r) {
 
        name = ap_auth_name(r);
        if (!name) {
-               ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
-                               MK_RERROR_LEVEL "need AuthName: %s", r->uri);
                return HTTP_INTERNAL_SERVER_ERROR;
        }
 
        if (!auth_line) {
                MK_TABLE_SET(r->err_headers_out, "WWW-Authenticate",
-                       ap_pstrcat(r->pool, "Basic realm=\"", name, "\"", NULL));
+                       (char *)ap_pstrcat(r->pool,
+                       "Basic realm=\"", name, "\"", NULL));
                return HTTP_UNAUTHORIZED;
        }
 
@@ -586,7 +1008,7 @@ int kerb_authenticate_user(request_rec *r) {
 #ifdef KRB5
        if (KerberosV5 && !KerberosV4first && retcode != OK) {
                MK_AUTH_TYPE = "KerberosV5";
-               if (kerb5_password_validate(MK_USER, sent_pw)) {
+               if (kerb5_password_validate(r, MK_USER, sent_pw)) {
                        retcode = OK;
                }
                else {
@@ -598,7 +1020,7 @@ int kerb_authenticate_user(request_rec *r) {
 #ifdef KRB4
        if (KerberosV4 && retcode != OK) {
                MK_AUTH_TYPE = "KerberosV4";
-               if (kerb4_password_validate(MK_USER, sent_pw)) {
+               if (kerb4_password_validate(r, MK_USER, sent_pw)) {
                        retcode = OK;
                }
                else {
@@ -610,7 +1032,7 @@ int kerb_authenticate_user(request_rec *r) {
 #if defined(KRB5) && defined(KRB4)
        if (KerberosV5 && KerberosV4first && retcode != OK) {
                MK_AUTH_TYPE = "KerberosV5";
-               if (kerb5_password_validate(MK_USER, sent_pw)) {
+               if (kerb5_password_validate(r, MK_USER, sent_pw)) {
                        retcode = OK;
                }
                else {
@@ -633,7 +1055,8 @@ int kerb_authenticate_user(request_rec *r) {
 /*************************************************************************** 
  Access Verification
  ***************************************************************************/
-int kerb_check_user_access(request_rec *r) {
+int kerb_check_user_access(request_rec *r)
+{
        register int x;
        const char *t, *w;
        const MK_ARRAY_HEADER *reqs_arr = ap_requires(r);