Add gssweb sources
[mod_auth_kerb.cvs/.git] / gss.c
diff --git a/gss.c b/gss.c
index 6b04e53..bc84033 100644 (file)
--- a/gss.c
+++ b/gss.c
@@ -1,5 +1,93 @@
+/*
+ * Copyright (c) 2010 CESNET
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of CESNET nor the names of its contributors may
+ *    be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
 #include "mod_auth_gssapi.h"
 
+void
+gss_log(const char *file, int line, int level, int status,
+        const request_rec *r, const char *fmt, ...)
+{
+    char errstr[1024];
+    va_list ap;
+
+    va_start(ap, fmt);
+    vsnprintf(errstr, sizeof(errstr), fmt, ap);
+    va_end(ap);
+   
+    ap_log_rerror(file, line, level | APLOG_NOERRNO, status, r, "%s", errstr);
+}
+
+apr_status_t
+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);
+
+    return APR_SUCCESS;
+}
+
+gss_conn_ctx
+gss_get_conn_ctx(request_rec *r)
+{
+    char key[1024];
+    gss_conn_ctx ctx = NULL;
+
+    snprintf(key, sizeof(key), "mod_auth_gssapi: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->user = NULL;
+       apr_pool_userdata_set(ctx, key, cleanup_conn_ctx, r->connection->pool);
+    }
+    return ctx;
+}
+
+void *
+gss_config_dir_create(apr_pool_t *p, char *d)
+{
+    gss_auth_config *conf;
+
+    conf = (gss_auth_config *) apr_pcalloc(p, sizeof(*conf));
+    return conf;
+}
+
+
 static const char *
 get_gss_error(request_rec *r, OM_uint32 err_maj, OM_uint32 err_min, char *prefix)
 {
@@ -267,9 +355,14 @@ gss_authenticate(request_rec *r, gss_auth_config *conf, gss_conn_ctx ctx,
      gss_log(APLOG_MARK, APLOG_ERR, 0, r,
             "%s", get_gss_error(r, major_status, minor_status,
                                 "Failed to establish authentication"));
+#if 0
      /* Don't offer the Negotiate method again if call to GSS layer failed */
      /* XXX ... which means we don't return the "error" output */
      *negotiate_ret_value = NULL;
+#endif
+     gss_delete_sec_context(&minor_status, &ctx->context, GSS_C_NO_BUFFER);
+     ctx->context = GSS_C_NO_CONTEXT;
+     ctx->state = GSS_CTX_EMPTY;
      ret = HTTP_UNAUTHORIZED;
      goto end;
   }