#include "mod_auth_gssapi.h"
void
-gss_log(const char *file, int line, int level, int status,
- const request_rec *r, const char *fmt, ...)
+gss_log(const char *file,
+ int line,
+#if AP_SERVER_MAJORVERSION_NUMBER == 2 && AP_SERVER_MINORVERSION_NUMBER == 4
+ int module_index,
+#endif
+ int level,
+ int status,
+ const request_rec *r,
+ const char *fmt, ...)
{
char errstr[1024];
va_list ap;
vsnprintf(errstr, sizeof(errstr), fmt, ap);
va_end(ap);
- ap_log_rerror(file, line, level | APLOG_NOERRNO, status, r, "%s", errstr);
+ ap_log_rerror(file,
+ line,
+#if AP_SERVER_MAJORVERSION_NUMBER == 2 && AP_SERVER_MINORVERSION_NUMBER == 4
+ module_index,
+#endif
+ level | APLOG_NOERRNO,
+ status,
+ r,
+ "%s",
+ errstr);
}
apr_status_t
-cleanup_conn_ctx(void *data)
+gss_cleanup_conn_ctx(void *data)
{
gss_conn_ctx ctx = (gss_conn_ctx) data;
OM_uint32 minor_status;
if (ctx && ctx->context != GSS_C_NO_CONTEXT)
gss_delete_sec_context(&minor_status, &ctx->context, GSS_C_NO_BUFFER);
+
+ if (ctx && ctx->server_creds != GSS_C_NO_CREDENTIAL)
+ gss_release_cred(&minor_status, &ctx->server_creds);
return APR_SUCCESS;
}
gss_conn_ctx
-gss_get_conn_ctx(request_rec *r)
+gss_create_conn_ctx(request_rec *r, gss_auth_config *conf)
{
- char key[1024];
- gss_conn_ctx ctx = NULL;
-
- snprintf(key, sizeof(key), "mod_auth_gssweb:conn_ctx");
- apr_pool_userdata_get((void **)&ctx, key, r->connection->pool);
- /* XXX LOG */
- if (ctx == NULL) {
- ctx = (gss_conn_ctx) apr_palloc(r->connection->pool, sizeof(*ctx));
- if (ctx == NULL)
- return NULL;
- ctx->context = GSS_C_NO_CONTEXT;
- ctx->state = GSS_CTX_EMPTY;
- ctx->filter_stat = GSS_FILT_NEW;
- ctx->user = NULL;
- apr_pool_userdata_set(ctx, key, cleanup_conn_ctx, r->connection->pool);
- }
- return ctx;
+ char key[1024];
+ gss_conn_ctx ctx = NULL;
+
+ snprintf(key, sizeof(key), "mod_auth_gssweb:conn_ctx");
+
+ if (NULL == (ctx = (gss_conn_ctx) apr_palloc(r->connection->pool, sizeof(*ctx)))) {
+ gss_log(APLOG_MARK, APLOG_ERR, 0, r, "gss_create_conn_ctx: Can't allocate GSS context");
+ return NULL;
+ }
+ ctx->context = GSS_C_NO_CONTEXT;
+ ctx->state = GSS_CTX_EMPTY;
+ ctx->filter_stat = GSS_FILT_NEW;
+ ctx->user = NULL;
+
+ /* Acquire and store server credentials */
+ if (0 == get_gss_creds(r, conf, &(ctx->server_creds))) {
+ gss_log(APLOG_MARK, APLOG_DEBUG, 0, r, "gss_create_conn_ctx: Server credentials acquired");
+ } else {
+ gss_log(APLOG_MARK, APLOG_ERR, 0, r, "gss_create_conn_ctx: Error: Server credentials NOT acquired");
+ return NULL;
+ }
+
+ apr_pool_userdata_set(ctx, key, gss_cleanup_conn_ctx, r->connection->pool);
+
+ return ctx;
+}
+
+gss_conn_ctx
+gss_retrieve_conn_ctx(request_rec *r)
+{
+ char key[1024];
+ gss_conn_ctx ctx = NULL;
+
+ snprintf(key, sizeof(key), "mod_auth_gssweb:conn_ctx");
+ apr_pool_userdata_get((void **)&ctx, key, r->connection->pool);
+
+ if (NULL == ctx)
+ gss_log(APLOG_MARK, APLOG_DEBUG, 0, r, "gss_retrieve_conn_ctx: No GSS context found");
+
+ return ctx;
}
void *