$NetBSD: patch-aa,v 1.3 2025/07/02 04:01:41 markd Exp $

recent heimdal's dont implicitly include mech headers
so include explicitly.

Fixes for 2.4 API from https://github.com/pld-linux/apache-mod_auth_kerb/blob/master/mod_auth_kerb-apache24.patch

Fix build with recent mit.  Was using an internal API.
https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b4c542201cff236f67aac6eaa0ca86863d34df80

--- src/mod_auth_kerb.c.orig	2008-12-04 10:14:03.000000000 +0000
+++ src/mod_auth_kerb.c	2014-07-18 07:11:17.000000000 +0000
@@ -89,6 +89,7 @@
 #include <krb5.h>
 #ifdef HEIMDAL
 #  include <gssapi.h>
+#  include <gssapi/gssapi_krb5.h>
 #else
 #  include <gssapi/gssapi.h>
 #  include <gssapi/gssapi_generic.h>
@@ -147,6 +148,15 @@ module auth_kerb_module;
 #define PROXYREQ_PROXY STD_PROXY
 #endif
 
+#if MODULE_MAGIC_NUMBER_MAJOR >= 20100606
+/* 2.4.x or later */
+#define WITH_HTTPD24 1
+#define client_ip(r) ((r)->useragent_ip)
+APLOG_USE_MODULE(auth_kerb);
+#else
+#define client_ip(r) ((r)->connection->remote_ip)
+#endif
+
 /*************************************************************************** 
  Auth Configuration Structure
  ***************************************************************************/
@@ -348,7 +358,11 @@ krb5_save_realms(cmd_parms *cmd, void *v
 }
 
 static void
-log_rerror(const char *file, int line, int level, int status,
+log_rerror(const char *file, int line,
+#ifdef WITH_HTTPD24
+ int module_index,
+#endif
+ int level, int status,
            const request_rec *r, const char *fmt, ...)
 {
    char errstr[1024];
@@ -359,7 +373,9 @@ log_rerror(const char *file, int line, i
    va_end(ap);
 
    
-#ifdef STANDARD20_MODULE_STUFF
+#if defined(WITH_HTTPD24)
+ ap_log_rerror(file, line, module_index, level, status, r, "%s", errstr);
+#elif defined(STANDARD20_MODULE_STUFF)
    ap_log_rerror(file, line, level | APLOG_NOERRNO, status, r, "%s", errstr);
 #else
    ap_log_rerror(file, line, level | APLOG_NOERRNO, r, "%s", errstr);
@@ -1555,7 +1571,7 @@ already_succeeded(request_rec *r, char *
    char keyname[1024];
 
    snprintf(keyname, sizeof(keyname) - 1,
-	"mod_auth_kerb::connection::%s::%ld", r->connection->remote_ip, 
+	"mod_auth_kerb::connection::%s::%ld", client_ip(r), 
 	r->connection->id);
 
    if (apr_pool_userdata_get((void**)&conn_data, keyname, r->connection->pool) != 0)
@@ -1709,7 +1725,7 @@ kerb_authenticate_user(request_rec *r)
        prevauth->last_return = ret;
        snprintf(keyname, sizeof(keyname) - 1,
            "mod_auth_kerb::connection::%s::%ld", 
-	   r->connection->remote_ip, r->connection->id);
+	   client_ip(r), r->connection->id);
        apr_pool_userdata_set(prevauth, keyname, NULL, r->connection->pool);
    }
 
@@ -1722,28 +1738,6 @@ kerb_authenticate_user(request_rec *r)
    return ret;
 }
 
-int
-have_rcache_type(const char *type)
-{
-   krb5_error_code ret;
-   krb5_context context;
-   krb5_rcache id = NULL;
-   int found;
-
-   ret = krb5_init_context(&context);
-   if (ret)
-      return 0;
-
-   ret = krb5_rc_resolve_full(context, &id, "none:");
-   found = (ret == 0);
-
-   if (ret == 0)
-      krb5_rc_destroy(context, id);
-   krb5_free_context(context);
-
-   return found;
-}
-
 /*************************************************************************** 
  Module Setup/Configuration
  ***************************************************************************/
@@ -1754,7 +1748,7 @@ kerb_module_init(server_rec *dummy, pool
 #ifndef HEIMDAL
    /* Suppress the MIT replay cache.  Requires MIT Kerberos 1.4.0 or later.
       1.3.x are covered by the hack overiding the replay calls */
-   if (getenv("KRB5RCACHETYPE") == NULL && have_rcache_type("none"))
+   if (getenv("KRB5RCACHETYPE") == NULL)
       putenv(strdup("KRB5RCACHETYPE=none"));
 #endif
 }
@@ -1795,7 +1789,7 @@ kerb_init_handler(apr_pool_t *p, apr_poo
 #ifndef HEIMDAL
    /* Suppress the MIT replay cache.  Requires MIT Kerberos 1.4.0 or later.
       1.3.x are covered by the hack overiding the replay calls */
-   if (getenv("KRB5RCACHETYPE") == NULL && have_rcache_type("none"))
+   if (getenv("KRB5RCACHETYPE") == NULL)
       putenv(strdup("KRB5RCACHETYPE=none"));
 #endif
    
