- note_kerb_auth_failure() renamed to set_kerb_auth_headers()
[mod_auth_kerb.cvs/.git] / src / mod_auth_kerb.c
1 /*
2  * Daniel Kouril <kouril@users.sourceforge.net>
3  *
4  * Source and Documentation can be found at:
5  * http://modauthkerb.sourceforge.net/
6  *
7  * Based on work by
8  *   James E. Robinson, III <james@ncstate.net>
9  *   Daniel Henninger <daniel@ncsu.edu>
10  *   Ludek Sulak <xsulak@fi.muni.cz>
11  */
12
13 /*
14  * Copyright (c) 2004 Masarykova universita
15  * (Masaryk University, Brno, Czech Republic)
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are met:
20  *
21  * 1. Redistributions of source code must retain the above copyright notice,
22  *    this list of conditions and the following disclaimer.
23  *
24  * 2. Redistributions in binary form must reproduce the above copyright
25  *    notice, this list of conditions and the following disclaimer in the
26  *    documentation and/or other materials provided with the distribution.
27  *
28  * 3. Neither the name of the University nor the names of its contributors may
29  *    be used to endorse or promote products derived from this software
30  *    without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
36  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGE.
43  */
44
45 #ident "$Id$"
46
47 #include "config.h"
48
49 #define MODAUTHKERB_VERSION "5.0-rc4"
50
51 #ifndef APXS1
52 #include "ap_compat.h"
53 #include "apr_strings.h"
54 #endif
55 #include "httpd.h"
56 #include "http_config.h"
57 #include "http_core.h"
58 #include "http_log.h"
59 #include "http_protocol.h"
60 #include "http_request.h"
61
62 #ifdef KRB5
63 #include <krb5.h>
64 #ifdef HEIMDAL
65 #  include <gssapi.h>
66 #else
67 #  include <gssapi/gssapi.h>
68 #  include <gssapi/gssapi_generic.h>
69 #  define GSS_C_NT_USER_NAME gss_nt_user_name
70 #  define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name
71 #  define krb5_get_err_text(context,code) error_message(code)
72 #endif
73 #include "spnegokrb5.h"
74 #endif /* KRB5 */
75
76 #ifdef KRB4
77 /*Prevent warning about closesocket redefinition (Apache's ap_config.h and 
78  * MIT Kerberos' port-sockets.h both define it as close) */
79 #ifdef closesocket
80 #  undef closesocket
81 #endif
82 #include <krb.h>
83 #include <netdb.h> /* gethostbyname() */
84 #endif /* KRB4 */
85
86 #ifdef APXS1
87 module auth_kerb_module;
88 #else
89 module AP_MODULE_DECLARE_DATA auth_kerb_module;
90 #endif
91
92 /*************************************************************************** 
93  Macros To Ease Compatibility
94  ***************************************************************************/
95 #ifdef APXS1
96 #define MK_POOL pool
97 #define MK_TABLE_GET ap_table_get
98 #define MK_USER r->connection->user
99 #define MK_AUTH_TYPE r->connection->ap_auth_type
100 #define PROXYREQ_PROXY STD_PROXY
101 #else
102 #define MK_POOL apr_pool_t
103 #define MK_TABLE_GET apr_table_get
104 #define MK_USER r->user
105 #define MK_AUTH_TYPE r->ap_auth_type
106 #endif /* APXS1 */
107
108
109 /*************************************************************************** 
110  Auth Configuration Structure
111  ***************************************************************************/
112 typedef struct {
113         char *krb_auth_realms;
114         int krb_save_credentials;
115         int krb_verify_kdc;
116         char *krb_service_name;
117         int krb_authoritative;
118 #ifdef KRB5
119         char *krb_5_keytab;
120         int krb_method_gssapi;
121         int krb_method_k5pass;
122 #endif
123 #ifdef KRB4
124         char *krb_4_srvtab;
125         int krb_method_k4pass;
126 #endif
127 } kerb_auth_config;
128
129 static void
130 set_kerb_auth_headers(request_rec *r, const kerb_auth_config *conf,
131                       int use_krb4, int use_krb5pwd, char *negotiate_ret_value);
132
133 static const char*
134 krb5_save_realms(cmd_parms *cmd, kerb_auth_config *sec, char *arg);
135
136 #ifdef APXS1
137 #define command(name, func, var, type, usage)           \
138   { name, func,                                         \
139     (void*)XtOffsetOf(kerb_auth_config, var),           \
140     OR_AUTHCFG, type, usage }
141 #else
142 #define command(name, func, var, type, usage)           \
143   AP_INIT_ ## type (name, func,                         \
144         (void*)APR_XtOffsetOf(kerb_auth_config, var),   \
145         OR_AUTHCFG, usage)
146 #endif
147
148 static const command_rec kerb_auth_cmds[] = {
149    command("KrbAuthRealms", krb5_save_realms, krb_auth_realms,
150      RAW_ARGS, "Realms to attempt authentication against (can be multiple)."),
151
152    command("KrbAuthRealm", krb5_save_realms, krb_auth_realms,
153      RAW_ARGS, "Alias for KrbAuthRealms."),
154
155    command("KrbSaveCredentials", ap_set_flag_slot, krb_save_credentials,
156      FLAG, "Save and store credentials/tickets retrieved during auth."),
157
158    command("KrbVerifyKDC", ap_set_flag_slot, krb_verify_kdc,
159      FLAG, "Verify tickets against keytab to prevent KDC spoofing attacks."),
160
161    command("KrbServiceName", ap_set_string_slot, krb_service_name,
162      TAKE1, "Service name to be used by Apache for authentication."),
163
164    command("KrbAuthoritative", ap_set_flag_slot, krb_authoritative,
165      FLAG, "Set to 'off' to allow access control to be passed along to lower modules if the UserID is not known to this module."),
166
167 #ifdef KRB5
168    command("Krb5Keytab", ap_set_file_slot, krb_5_keytab,
169      TAKE1, "Location of Kerberos V5 keytab file."),
170
171    command("KrbMethodNegotiate", ap_set_flag_slot, krb_method_gssapi,
172      FLAG, "Enable Negotiate authentication method."),
173
174    command("KrbMethodK5Passwd", ap_set_flag_slot, krb_method_k5pass,
175      FLAG, "Enable Kerberos V5 password authentication."),
176 #endif 
177
178 #ifdef KRB4
179    command("Krb4Srvtab", ap_set_file_slot, krb_4_srvtab,
180      TAKE1, "Location of Kerberos V4 srvtab file."),
181
182    command("KrbMethodK4Passwd", ap_set_flag_slot, krb_method_k4pass,
183      FLAG, "Enable Kerberos V4 password authentication."),
184 #endif
185
186    { NULL }
187 };
188
189 #ifdef KRB5
190 typedef struct {
191    gss_ctx_id_t context;
192    gss_cred_id_t server_creds;
193 } gss_connection_t;
194
195 static gss_connection_t *gss_connection = NULL;
196 #endif
197
198
199 /*************************************************************************** 
200  Auth Configuration Initialization
201  ***************************************************************************/
202 static void *kerb_dir_create_config(MK_POOL *p, char *d)
203 {
204         kerb_auth_config *rec;
205
206         rec = (kerb_auth_config *) ap_pcalloc(p, sizeof(kerb_auth_config));
207         ((kerb_auth_config *)rec)->krb_verify_kdc = 1;
208         ((kerb_auth_config *)rec)->krb_service_name = "HTTP";
209         ((kerb_auth_config *)rec)->krb_authoritative = 1;
210 #ifdef KRB5
211         ((kerb_auth_config *)rec)->krb_method_k5pass = 1;
212         ((kerb_auth_config *)rec)->krb_method_gssapi = 1;
213 #endif
214 #ifdef KRB4
215         ((kerb_auth_config *)rec)->krb_method_k4pass = 1;
216 #endif
217         return rec;
218 }
219
220 static const char*
221 krb5_save_realms(cmd_parms *cmd, kerb_auth_config *sec, char *arg)
222 {
223    sec->krb_auth_realms= ap_pstrdup(cmd->pool, arg);
224    return NULL;
225 }
226
227 void log_rerror(const char *file, int line, int level, int status,
228                 const request_rec *r, const char *fmt, ...)
229 {
230    char errstr[1024];
231    va_list ap;
232
233    va_start(ap, fmt);
234    vsnprintf(errstr, sizeof(errstr), fmt, ap);
235    va_end(ap);
236
237    
238 #ifdef APXS1
239    ap_log_rerror(file, line, level | APLOG_NOERRNO, r, "%s", errstr);
240 #else
241    ap_log_rerror(file, line, level | APLOG_NOERRNO, status, r, "%s", errstr);
242 #endif
243 }
244
245 #ifdef KRB4
246 /*************************************************************************** 
247  Username/Password Validation for Krb4
248  ***************************************************************************/
249 static int
250 verify_krb4_user(request_rec *r, char *name, char *instance, char *realm,
251                  char *password, char *linstance, char *srvtab, int krb_verify_kdc)
252 {
253    int ret;
254    char *phost;
255    unsigned long addr;
256    struct hostent *hp;
257    const char *hostname;
258    KTEXT_ST ticket;
259    AUTH_DAT authdata;
260    char lrealm[REALM_SZ];
261
262    ret = krb_get_pw_in_tkt(name, instance, realm, "krbtgt", realm, 
263                            DEFAULT_TKT_LIFE, password);
264    if (ret) {
265       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
266                  "Cannot get krb4 ticket: krb_get_pw_in_tkt() failed: %s",
267                  krb_get_err_text(ret));
268       return ret;
269    }
270
271    if (!krb_verify_kdc)
272       return ret;
273
274    hostname = ap_get_server_name(r);
275
276    hp = gethostbyname(hostname);
277    if (hp == NULL) {
278       dest_tkt();
279       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
280                  "Cannot verify krb4 ticket: gethostbyname() failed: %s",
281                  hstrerror(h_errno));
282       return h_errno;
283    }
284    memcpy(&addr, hp->h_addr, sizeof(addr));
285
286    phost = krb_get_phost((char *)hostname);
287
288    krb_get_lrealm(lrealm, 1);
289
290    ret = krb_mk_req(&ticket, linstance, phost, lrealm, 0);
291    if (ret) {
292       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
293                  "Cannot verify krb4 ticket: krb_mk_req() failed: %s",
294                  krb_get_err_text(ret));
295       dest_tkt();
296       return ret;
297    }
298
299    ret = krb_rd_req(&ticket, linstance, phost, addr, &authdata, srvtab);
300    if (ret) {
301       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
302                  "Cannot verify krb4 ticket: krb_rd_req() failed: %s",
303                  krb_get_err_text(ret));
304       dest_tkt();
305    }
306
307    return ret;
308 }
309
310 static int
311 krb4_cache_cleanup(void *data)
312 {
313    char *tkt_file = (char *) data;
314    
315    krb_set_tkt_string(tkt_file);
316    dest_tkt();
317    return OK;
318 }
319
320 static int 
321 authenticate_user_krb4pwd(request_rec *r,
322                           kerb_auth_config *conf,
323                           const char *auth_line)
324 {
325    int ret;
326    const char *sent_pw;
327    const char *sent_name;
328    char *sent_instance;
329    char tkt_file[32];
330    char *tkt_file_p = NULL;
331    int fd;
332    const char *realms;
333    const char *realm;
334    char *user;
335    char lrealm[REALM_SZ];
336    int all_principals_unkown;
337
338    sent_pw = ap_pbase64decode(r->pool, auth_line);
339    sent_name = ap_getword (r->pool, &sent_pw, ':');
340
341    /* do not allow user to override realm setting of server */
342    if (strchr(sent_name, '@')) {
343       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
344                  "specifying realm in user name is prohibited");
345       return HTTP_UNAUTHORIZED;
346    }
347
348    sent_instance = strchr(sent_name, '.');
349    if (sent_instance)
350       *sent_instance++ = '\0'; 
351
352    snprintf(tkt_file, sizeof(tkt_file), "/tmp/apache_tkt_XXXXXX");
353    fd = mkstemp(tkt_file);
354    if (fd < 0) {
355       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
356                  "Cannot create krb4 ccache: mkstemp() failed: %s",
357                  strerror(errno));
358       return HTTP_INTERNAL_SERVER_ERROR;
359    }
360
361    tkt_file_p = ap_pstrdup(r->pool, tkt_file);
362    ap_register_cleanup(r->pool, tkt_file_p,
363                        krb4_cache_cleanup, ap_null_cleanup);
364
365    krb_set_tkt_string(tkt_file);
366
367    all_principals_unkown = 1;
368    realms = conf->krb_auth_realms;
369    do {
370       memset(lrealm, 0, sizeof(lrealm));
371       realm = NULL;
372       if (realms)
373          realm = ap_getword_white(r->pool, &realms);
374
375       if (realm == NULL) {
376          ret = krb_get_lrealm(lrealm, 1);
377          if (ret)
378             break;
379          realm = lrealm;
380       }
381
382       ret = verify_krb4_user(r, (char *)sent_name, 
383                              (sent_instance) ? sent_instance : "",
384                              (char *)realm, (char *)sent_pw,
385                              conf->krb_service_name,
386                              conf->krb_4_srvtab, conf->krb_verify_kdc);
387       if (!conf->krb_authoritative && ret) {
388          /* if we're not authoritative, we allow authentication to pass on
389           * to another modules if (and only if) the user is not known to us */
390          if (all_principals_unkown && ret != KDC_PR_UNKNOWN)
391             all_principals_unkown = 0;
392       }
393
394       if (ret == 0)
395          break;
396    } while (realms && *realms);
397
398    if (ret) {
399       /* XXX log only in the verify_krb4_user() call */
400       log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Verifying krb4 password failed");
401       ret = (!conf->krb_authoritative && all_principals_unkown == 1 && ret == KDC_PR_UNKNOWN) ?
402                  DECLINED : HTTP_UNAUTHORIZED;
403       goto end;
404    }
405
406    user = ap_pstrdup(r->pool, sent_name);
407    if (sent_instance)
408       user = ap_pstrcat(r->pool, user, ".", sent_instance, NULL);
409    user = ap_pstrcat(r->pool, user, "@", realm, NULL);
410
411    MK_USER = user;
412    MK_AUTH_TYPE = "Basic";
413    ap_table_setn(r->subprocess_env, "KRBTKFILE", tkt_file_p);
414
415    if (!conf->krb_save_credentials)
416       krb4_cache_cleanup(tkt_file);
417
418 end:
419    if (ret)
420       krb4_cache_cleanup(tkt_file);
421    close(fd);
422    tf_close();
423
424    return ret;
425 }
426 #endif /* KRB4 */
427
428 #ifdef KRB5
429 /*************************************************************************** 
430  Username/Password Validation for Krb5
431  ***************************************************************************/
432 /* Inspired by krb5_verify_user from Heimdal */
433 static krb5_error_code
434 verify_krb5_user(request_rec *r, krb5_context context, krb5_principal principal,
435                  krb5_ccache ccache, const char *password, const char *service,
436                  krb5_keytab keytab, int krb_verify_kdc)
437 {
438    krb5_creds creds;
439    krb5_principal server = NULL;
440    krb5_error_code ret;
441    krb5_verify_init_creds_opt opt;
442
443    /* XXX error messages shouldn't be logged here (and in the while() loop in
444     * authenticate_user_krb5pwd() as weell), in order to avoid confusing log
445     * entries when using multiple realms */
446
447    memset(&creds, 0, sizeof(creds));
448
449    ret = krb5_get_init_creds_password(context, &creds, principal, 
450                                       (char *)password, NULL,
451                                       NULL, 0, NULL, NULL);
452    if (ret) {
453       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
454                  "krb5_get_init_creds_password() failed: %s",
455                  krb5_get_err_text(context, ret));
456       return ret;
457    }
458
459    ret = krb5_sname_to_principal(context, ap_get_server_name(r), service, 
460                                  KRB5_NT_UNKNOWN, &server);
461    if (ret) {
462       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
463                  "krb5_sname_to_principal() failed: %s",
464                  krb5_get_err_text(context, ret));
465       goto end;
466    }
467
468    krb5_verify_init_creds_opt_init(&opt);
469    krb5_verify_init_creds_opt_set_ap_req_nofail(&opt, krb_verify_kdc);
470
471    ret = krb5_verify_init_creds(context, &creds, server, keytab, NULL, &opt);
472    if (ret) {
473       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
474                  "krb5_verify_init_creds() failed: %s",
475                  krb5_get_err_text(context, ret));
476       goto end;
477    }
478                  
479    if (ccache) {
480       ret = krb5_cc_initialize(context, ccache, principal);
481       if (ret) {
482          log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
483                     "krb5_cc_initialize() failed: %s",
484                     krb5_get_err_text(context, ret));
485          goto end;
486       }
487
488       ret = krb5_cc_store_cred(context, ccache, &creds);
489       if (ret) {
490          log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
491                     "krb5_cc_store_cred() failed: %s",
492                     krb5_get_err_text(context, ret));
493          goto end;
494       }
495    }
496
497 end:
498    krb5_free_cred_contents(context, &creds);
499    if (server)
500       krb5_free_principal(context, server);
501    return ret;
502 }
503
504 static int
505 krb5_cache_cleanup(void *data)
506 {
507    krb5_context context;
508    krb5_ccache  cache;
509    krb5_error_code problem;
510    char *cache_name = (char *) data;
511
512    problem = krb5_init_context(&context);
513    if (problem) {
514       /* ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "krb5_init_context() failed"); */
515       return HTTP_INTERNAL_SERVER_ERROR;
516    }
517
518    problem = krb5_cc_resolve(context, cache_name, &cache);
519    if (problem) {
520       /* log_error(APLOG_MARK, APLOG_ERR, 0, NULL, 
521                 "krb5_cc_resolve() failed (%s: %s)",
522                 cache_name, krb5_get_err_text(context, problem)); */
523       return HTTP_INTERNAL_SERVER_ERROR;
524    }
525
526    krb5_cc_destroy(context, cache);
527    krb5_free_context(context);
528    return OK;
529 }
530
531 static int
532 create_krb5_ccache(krb5_context kcontext,
533                    request_rec *r,
534                    kerb_auth_config *conf,
535                    krb5_principal princ,
536                    krb5_ccache *ccache)
537 {
538    char *ccname;
539    int fd;
540    krb5_error_code problem;
541    int ret;
542    krb5_ccache tmp_ccache = NULL;
543
544    ccname = ap_psprintf(r->pool, "FILE:%s/krb5cc_apache_XXXXXX", P_tmpdir);
545    fd = mkstemp(ccname + strlen("FILE:"));
546    if (fd < 0) {
547       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
548                  "mkstemp() failed: %s", strerror(errno));
549       ret = HTTP_INTERNAL_SERVER_ERROR;
550       goto end;
551    }
552    close(fd);
553
554    problem = krb5_cc_resolve(kcontext, ccname, &tmp_ccache);
555    if (problem) {
556       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
557                  "krb5_cc_resolve() failed: %s",
558                  krb5_get_err_text(kcontext, problem));
559       ret = HTTP_INTERNAL_SERVER_ERROR;
560       unlink(ccname);
561       goto end;
562    }
563
564    problem = krb5_cc_initialize(kcontext, tmp_ccache, princ);
565    if (problem) {
566       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
567                  "Cannot initialize krb5 ccache %s: krb5_cc_initialize() failed: %s",
568                  ccname, krb5_get_err_text(kcontext, problem));
569       ret = HTTP_INTERNAL_SERVER_ERROR;
570       goto end;
571    }
572
573    ap_table_setn(r->subprocess_env, "KRB5CCNAME", ccname);
574    ap_register_cleanup(r->pool, ccname,
575                        krb5_cache_cleanup, ap_null_cleanup);
576
577    *ccache = tmp_ccache;
578    tmp_ccache = NULL;
579
580    ret = OK;
581
582 end:
583    if (tmp_ccache)
584       krb5_cc_destroy(kcontext, tmp_ccache);
585
586    return ret;
587 }
588
589 static int
590 store_krb5_creds(krb5_context kcontext,
591                  request_rec *r,
592                  kerb_auth_config *conf,
593                  krb5_ccache delegated_cred)
594 {
595    char errstr[1024];
596    krb5_error_code problem;
597    krb5_principal princ;
598    krb5_ccache ccache;
599    int ret;
600
601    problem = krb5_cc_get_principal(kcontext, delegated_cred, &princ);
602    if (problem) {
603       snprintf(errstr, sizeof(errstr), "krb5_cc_get_principal() failed: %s",
604                krb5_get_err_text(kcontext, problem));
605       return HTTP_INTERNAL_SERVER_ERROR;
606    }
607
608    ret = create_krb5_ccache(kcontext, r, conf, princ, &ccache);
609    if (ret) {
610       krb5_free_principal(kcontext, princ);
611       return ret;
612    }
613
614 #ifdef HEIMDAL
615    problem = krb5_cc_copy_cache(kcontext, delegated_cred, ccache);
616 #else
617    problem = krb5_cc_copy_creds(kcontext, delegated_cred, ccache);
618 #endif
619    krb5_free_principal(kcontext, princ);
620    if (problem) {
621       snprintf(errstr, sizeof(errstr), "Failed to store credentials: %s",
622                krb5_get_err_text(kcontext, problem));
623       krb5_cc_destroy(kcontext, ccache);
624       return HTTP_INTERNAL_SERVER_ERROR;
625    }
626
627    krb5_cc_close(kcontext, ccache);
628    return OK;
629 }
630
631
632 int authenticate_user_krb5pwd(request_rec *r,
633                               kerb_auth_config *conf,
634                               const char *auth_line)
635 {
636    const char      *sent_pw = NULL; 
637    const char      *sent_name = NULL;
638    const char      *realms = NULL;
639    krb5_context    kcontext = NULL;
640    krb5_error_code code;
641    krb5_principal  client = NULL;
642    krb5_ccache     ccache = NULL;
643    krb5_keytab     keytab = NULL;
644    int             ret;
645    char            *name = NULL;
646    int             all_principals_unkown;
647    char            *ccname = NULL;
648    int             fd;
649
650    code = krb5_init_context(&kcontext);
651    if (code) {
652       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
653                  "Cannot initialize Kerberos5 context (%d)", code);
654       return HTTP_INTERNAL_SERVER_ERROR;
655    }
656
657    sent_pw = ap_pbase64decode(r->pool, auth_line);
658    sent_name = ap_getword (r->pool, &sent_pw, ':');
659    /* do not allow user to override realm setting of server */
660    if (strchr(sent_name, '@')) {
661       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
662                  "specifying realm in user name is prohibited");
663       ret = HTTP_UNAUTHORIZED;
664       goto end;
665    }
666
667    if (sent_pw == NULL || *sent_pw == '\0') {
668       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
669                  "empty passwords are not accepted");
670       ret = HTTP_UNAUTHORIZED;
671       goto end;
672    }
673
674    code = krb5_cc_resolve(kcontext, "MEMORY:", &ccache);
675    if (code) {
676       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
677                  "generating new memory ccache failed: %s",
678                  krb5_get_err_text(kcontext, code));
679       ret = HTTP_INTERNAL_SERVER_ERROR;
680       unlink(ccname);
681       goto end;
682    }
683
684    if (conf->krb_5_keytab)
685       krb5_kt_resolve(kcontext, conf->krb_5_keytab, &keytab);
686
687    all_principals_unkown = 1;
688    realms = conf->krb_auth_realms;
689    do {
690       if (realms && (code = krb5_set_default_realm(kcontext,
691                                            ap_getword_white(r->pool, &realms)))){
692          log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
693                     "krb5_set_default_realm() failed: %s",
694                     krb5_get_err_text(kcontext, code));
695          continue;
696       }
697
698       if (client) {
699          krb5_free_principal(kcontext, client);
700          client = NULL;
701       }
702       code = krb5_parse_name(kcontext, sent_name, &client);
703       if (code) {
704          log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
705                     "krb5_parse_name() failed: %s",
706                     krb5_get_err_text(kcontext, code));
707          continue;
708       }
709
710       code = verify_krb5_user(r, kcontext, client, ccache, sent_pw, 
711                               conf->krb_service_name, 
712                               keytab, conf->krb_verify_kdc);
713       if (!conf->krb_authoritative && code) {
714          /* if we're not authoritative, we allow authentication to pass on
715           * to another modules if (and only if) the user is not known to us */
716          if (all_principals_unkown && code != KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN)
717             all_principals_unkown = 0;
718       }
719
720       if (code == 0)
721          break;
722
723       /* ap_getword_white() used above shifts the parameter, so it's not
724          needed to touch the realms variable */
725    } while (realms && *realms);
726
727    memset((char *)sent_pw, 0, strlen(sent_pw));
728
729    if (code) {
730       if (!conf->krb_authoritative && all_principals_unkown == 1 && code == KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN)
731          ret = DECLINED;
732       else
733          ret = HTTP_UNAUTHORIZED;
734
735       goto end;
736    }
737
738    code = krb5_unparse_name(kcontext, client, &name);
739    if (code) {
740       log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "krb5_unparse_name() failed: %s",
741                  krb5_get_err_text(kcontext, code));
742       ret = HTTP_UNAUTHORIZED;
743       goto end;
744    }
745    MK_USER = ap_pstrdup (r->pool, name);
746    MK_AUTH_TYPE = "Basic";
747    free(name);
748
749    if (conf->krb_save_credentials)
750       store_krb5_creds(kcontext, r, conf, ccache);
751
752    ret = OK;
753
754 end:
755    if (client)
756       krb5_free_principal(kcontext, client);
757    if (ccache)
758       krb5_cc_destroy(kcontext, ccache);
759    if (keytab)
760       krb5_kt_close(kcontext, keytab);
761    krb5_free_context(kcontext);
762
763    return ret;
764 }
765
766 /*********************************************************************
767  * GSSAPI Authentication
768  ********************************************************************/
769
770 static const char *
771 get_gss_error(MK_POOL *p, OM_uint32 err_maj, OM_uint32 err_min, char *prefix)
772 {
773    OM_uint32 maj_stat, min_stat; 
774    OM_uint32 msg_ctx = 0;
775    gss_buffer_desc status_string;
776    char *err_msg;
777    size_t len;
778
779    err_msg = ap_pstrdup(p, prefix);
780    do {
781       maj_stat = gss_display_status (&min_stat,
782                                      err_maj,
783                                      GSS_C_GSS_CODE,
784                                      GSS_C_NO_OID,
785                                      &msg_ctx,
786                                      &status_string);
787       if (GSS_ERROR(maj_stat))
788          break;
789       err_msg = ap_pstrcat(p, err_msg, ": ", (char*) status_string.value, NULL);
790       gss_release_buffer(&min_stat, &status_string);
791       
792       maj_stat = gss_display_status (&min_stat,
793                                      err_min,
794                                      GSS_C_MECH_CODE,
795                                      GSS_C_NULL_OID,
796                                      &msg_ctx,
797                                      &status_string);
798       if (!GSS_ERROR(maj_stat)) {
799          err_msg = ap_pstrcat(p, err_msg,
800                               " (", (char*) status_string.value, ")", NULL);
801          gss_release_buffer(&min_stat, &status_string);
802       }
803    } while (!GSS_ERROR(maj_stat) && msg_ctx != 0);
804
805    return err_msg;
806 }
807
808 static int
809 cleanup_gss_connection(void *data)
810 {
811    OM_uint32 minor_status;
812    gss_connection_t *gss_conn = (gss_connection_t *)data;
813
814    if (data == NULL)
815       return OK;
816    if (gss_conn->context != GSS_C_NO_CONTEXT)
817       gss_delete_sec_context(&minor_status, &gss_conn->context,
818                              GSS_C_NO_BUFFER);
819    if (gss_conn->server_creds != GSS_C_NO_CREDENTIAL)
820       gss_release_cred(&minor_status, &gss_conn->server_creds);
821
822    gss_connection = NULL;
823
824    return OK;
825 }
826
827 static int
828 store_gss_creds(request_rec *r, kerb_auth_config *conf, char *princ_name,
829                 gss_cred_id_t delegated_cred)
830 {
831    OM_uint32 maj_stat, min_stat;
832    krb5_principal princ = NULL;
833    krb5_ccache ccache = NULL;
834    krb5_error_code problem;
835    krb5_context context;
836    int ret = HTTP_INTERNAL_SERVER_ERROR;
837
838    problem = krb5_init_context(&context);
839    if (problem) {
840       log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Cannot initialize krb5 context");
841       return HTTP_INTERNAL_SERVER_ERROR;
842    }
843
844    problem = krb5_parse_name(context, princ_name, &princ);
845    if (problem) {
846       log_rerror(APLOG_MARK, APLOG_ERR, 0, r, 
847          "Cannot parse delegated username (%s)", krb5_get_err_text(context, problem));
848       goto end;
849    }
850
851    problem = create_krb5_ccache(context, r, conf, princ, &ccache);
852    if (problem) {
853       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
854          "Cannot create krb5 ccache (%s)", krb5_get_err_text(context, problem));
855       goto end;
856    }
857
858    maj_stat = gss_krb5_copy_ccache(&min_stat, delegated_cred, ccache);
859    if (GSS_ERROR(maj_stat)) {
860       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
861          "Cannot store delegated credential (%s)", 
862          get_gss_error(r->pool, maj_stat, min_stat, "gss_krb5_copy_ccache"));
863       goto end;
864    }
865
866    krb5_cc_close(context, ccache);
867    ccache = NULL;
868    ret = 0;
869
870 end:
871    if (princ)
872       krb5_free_principal(context, princ);
873    if (ccache)
874       krb5_cc_destroy(context, ccache);
875    krb5_free_context(context);
876    return ret;
877 }
878
879 static int
880 get_gss_creds(request_rec *r,
881               kerb_auth_config *conf,
882               gss_cred_id_t *server_creds)
883 {
884    gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER;
885    OM_uint32 major_status, minor_status, minor_status2;
886    gss_name_t server_name = GSS_C_NO_NAME;
887    char buf[1024];
888
889 #if 0
890    /* Don't specify service name. This makes MIT 1.3 not to use replay caches,
891     * which causes large problems with the Microsoft krb5 implementation. MS
892     * obviously uses a format of the krb5 authenticator that is considered by
893     * the MIT as replay (Two valid MS authenticators may contain the same time
894     * and utime fields and only differ in the sequential numbers).
895     */
896    snprintf(buf, sizeof(buf), "%s@%s", conf->krb_service_name,
897          ap_get_server_name(r));
898
899    input_token.value = buf;
900    input_token.length = strlen(buf) + 1;
901
902    major_status = gss_import_name(&minor_status, &input_token,
903                                   GSS_C_NT_HOSTBASED_SERVICE,
904                                   &server_name);
905    if (GSS_ERROR(major_status)) {
906       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
907                  "%s", get_gss_error(r->pool, major_status, minor_status,
908                  "gss_import_name() failed"));
909       return HTTP_INTERNAL_SERVER_ERROR;
910    }
911 #endif
912    
913    major_status = gss_acquire_cred(&minor_status, server_name, GSS_C_INDEFINITE,
914                                    GSS_C_NO_OID_SET, GSS_C_ACCEPT,
915                                    server_creds, NULL, NULL);
916    gss_release_name(&minor_status2, &server_name);
917    if (GSS_ERROR(major_status)) {
918       log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
919                  "%s", get_gss_error(r->pool, major_status, minor_status,
920                                      "gss_acquire_cred() failed"));
921       return HTTP_INTERNAL_SERVER_ERROR;
922    }
923    
924    return 0;
925 }
926
927 static int
928 cmp_gss_type(gss_buffer_t token, gss_OID oid)
929 {
930    unsigned char *p;
931    size_t len;
932
933    if (token->length == 0)
934       return GSS_S_DEFECTIVE_TOKEN;
935
936    p = token->value;
937    if (*p++ != 0x60)
938       return GSS_S_DEFECTIVE_TOKEN;
939    len = *p++;
940    if (len & 0x80) {
941       if ((len & 0x7f) > 4)
942          return GSS_S_DEFECTIVE_TOKEN;
943       p += len & 0x7f;
944    }
945    if (*p++ != 0x06)
946       return GSS_S_DEFECTIVE_TOKEN;
947
948    if (((OM_uint32) *p++) != oid->length)
949       return GSS_S_DEFECTIVE_TOKEN;
950
951    return memcmp(p, oid->elements, oid->length);
952 }
953
954 static int
955 authenticate_user_gss(request_rec *r, kerb_auth_config *conf,
956                       const char *auth_line, char **negotiate_ret_value)
957 {
958   OM_uint32 major_status, minor_status, minor_status2;
959   gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER;
960   gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER;
961   const char *auth_param = NULL;
962   int ret;
963   gss_name_t client_name = GSS_C_NO_NAME;
964   gss_cred_id_t delegated_cred = GSS_C_NO_CREDENTIAL;
965   OM_uint32 (*accept_sec_token)();
966   gss_OID_desc spnego_oid;
967
968   *negotiate_ret_value = "\0";
969
970   spnego_oid.length = 6;
971   spnego_oid.elements = (void *)"\x2b\x06\x01\x05\x05\x02";
972
973   if (gss_connection == NULL) {
974      gss_connection = ap_pcalloc(r->connection->pool, sizeof(*gss_connection));
975      if (gss_connection == NULL) {
976         log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
977                    "ap_pcalloc() failed (not enough memory)");
978         ret = HTTP_INTERNAL_SERVER_ERROR;
979         goto end;
980      }
981      memset(gss_connection, 0, sizeof(*gss_connection));
982      ap_register_cleanup(r->connection->pool, gss_connection, cleanup_gss_connection, ap_null_cleanup);
983   }
984
985   if (conf->krb_5_keytab) {
986      char *ktname;
987      /* we don't use the ap_* calls here, since the string passed to putenv()
988       * will become part of the enviroment and shouldn't be free()ed by apache
989       */
990      ktname = malloc(strlen("KRB5_KTNAME=") + strlen(conf->krb_5_keytab) + 1);
991      if (ktname == NULL) {
992         log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "malloc() failed: not enough memory");
993         ret = HTTP_INTERNAL_SERVER_ERROR;
994         goto end;
995      }
996      sprintf(ktname, "KRB5_KTNAME=%s", conf->krb_5_keytab);
997      putenv(ktname);
998   }
999
1000   if (gss_connection->server_creds == GSS_C_NO_CREDENTIAL) {
1001      ret = get_gss_creds(r, conf, &gss_connection->server_creds);
1002      if (ret)
1003         goto end;
1004   }
1005
1006   /* ap_getword() shifts parameter */
1007   auth_param = ap_getword_white(r->pool, &auth_line);
1008   if (auth_param == NULL) {
1009      log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1010                 "No Authorization parameter in request from client");
1011      ret = HTTP_UNAUTHORIZED;
1012      goto end;
1013   }
1014
1015   input_token.length = ap_base64decode_len(auth_param) + 1;
1016   input_token.value = ap_pcalloc(r->connection->pool, input_token.length);
1017   if (input_token.value == NULL) {
1018      log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1019                 "ap_pcalloc() failed (not enough memory)");
1020      ret = HTTP_INTERNAL_SERVER_ERROR;
1021      goto end;
1022   }
1023   input_token.length = ap_base64decode(input_token.value, auth_param);
1024
1025   accept_sec_token = (cmp_gss_type(&input_token, &spnego_oid) == 0) ?
1026                         gss_accept_sec_context_spnego : gss_accept_sec_context;
1027
1028   major_status = accept_sec_token(&minor_status,
1029                                   &gss_connection->context,
1030                                   gss_connection->server_creds,
1031                                   &input_token,
1032                                   GSS_C_NO_CHANNEL_BINDINGS,
1033                                   &client_name,
1034                                   NULL,
1035                                   &output_token,
1036                                   NULL,
1037                                   NULL,
1038                                   &delegated_cred);
1039   if (output_token.length) {
1040      char *token = NULL;
1041      size_t len;
1042      
1043      len = ap_base64encode_len(output_token.length) + 1;
1044      token = ap_pcalloc(r->connection->pool, len + 1);
1045      if (token == NULL) {
1046         log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1047                    "ap_pcalloc() failed (not enough memory)");
1048         ret = HTTP_INTERNAL_SERVER_ERROR;
1049         gss_release_buffer(&minor_status2, &output_token);
1050         goto end;
1051      }
1052      ap_base64encode(token, output_token.value, output_token.length);
1053      token[len] = '\0';
1054      *negotiate_ret_value = token;
1055      gss_release_buffer(&minor_status2, &output_token);
1056   }
1057
1058   if (GSS_ERROR(major_status)) {
1059      log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1060                 "%s", get_gss_error(r->pool, major_status, minor_status,
1061                                     "gss_accept_sec_context() failed"));
1062      /* Don't offer the Negotiate method again if call to GSS layer failed */
1063      *negotiate_ret_value = NULL;
1064      ret = HTTP_UNAUTHORIZED;
1065      goto end;
1066   }
1067
1068   if (major_status & GSS_S_CONTINUE_NEEDED) {
1069      /* Some GSSAPI mechanism (eg GSI from Globus) may require multiple 
1070       * iterations to establish authentication */
1071      ret = HTTP_UNAUTHORIZED;
1072      goto end;
1073   }
1074
1075   major_status = gss_display_name(&minor_status, client_name, &output_token, NULL);
1076   gss_release_name(&minor_status, &client_name); 
1077   if (GSS_ERROR(major_status)) {
1078     log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1079                "%s", get_gss_error(r->pool, major_status, minor_status,
1080                                    "gss_export_name() failed"));
1081     ret = HTTP_INTERNAL_SERVER_ERROR;
1082     goto end;
1083   }
1084
1085   MK_AUTH_TYPE = "Negotiate";
1086   MK_USER = ap_pstrdup(r->pool, output_token.value);
1087
1088   if (conf->krb_save_credentials && delegated_cred != GSS_C_NO_CREDENTIAL)
1089      store_gss_creds(r, conf, (char *)output_token.value, delegated_cred);
1090
1091   if (*negotiate_ret_value)
1092      set_kerb_auth_headers(r, conf, 0, 0, *negotiate_ret_value);
1093
1094   gss_release_buffer(&minor_status, &output_token);
1095
1096   ret = OK;
1097
1098 end:
1099   if (delegated_cred)
1100      gss_release_cred(&minor_status, &delegated_cred);
1101
1102   if (output_token.length) 
1103      gss_release_buffer(&minor_status, &output_token);
1104
1105   if (client_name != GSS_C_NO_NAME)
1106      gss_release_name(&minor_status, &client_name);
1107
1108   if (! major_status & GSS_S_CONTINUE_NEEDED)
1109      cleanup_gss_connection(gss_connection);
1110
1111   return ret;
1112 }
1113 #endif /* KRB5 */
1114
1115 static int
1116 already_succeeded(request_rec *r)
1117 {
1118    if (ap_is_initial_req(r) || MK_AUTH_TYPE == NULL)
1119       return 0;
1120    if (strcmp(MK_AUTH_TYPE, "Negotiate") ||
1121        (strcmp(MK_AUTH_TYPE, "Basic") && strchr(MK_USER, '@')))
1122       return 1;
1123    return 0;
1124 }
1125
1126 static void
1127 set_kerb_auth_headers(request_rec *r, const kerb_auth_config *conf,
1128                       int use_krb4, int use_krb5pwd, char *negotiate_ret_value)
1129 {
1130    const char *auth_name = NULL;
1131    int set_basic = 0;
1132    char *negoauth_param;
1133    const char *header_name = 
1134       (r->proxyreq == PROXYREQ_PROXY) ? "Proxy-Authenticate" : "WWW-Authenticate";
1135
1136    /* get the user realm specified in .htaccess */
1137    auth_name = ap_auth_name(r);
1138
1139    /* XXX should the WWW-Authenticate header be cleared first? */
1140 #ifdef KRB5
1141    if (negotiate_ret_value != NULL && conf->krb_method_gssapi) {
1142       negoauth_param = (*negotiate_ret_value == '\0') ? "Negotiate" :
1143                   ap_pstrcat(r->pool, "Negotiate ", negotiate_ret_value, NULL);
1144       ap_table_add(r->err_headers_out, header_name, negoauth_param);
1145    }
1146    if (use_krb5pwd && conf->krb_method_k5pass) {
1147       ap_table_add(r->err_headers_out, header_name,
1148                    ap_pstrcat(r->pool, "Basic realm=\"", auth_name, "\"", NULL));
1149       set_basic = 1;
1150    }
1151 #endif
1152
1153 #ifdef KRB4
1154    if (use_krb4 && conf->krb_method_k4pass && !set_basic)
1155       ap_table_add(r->err_headers_out, header_name,
1156                   ap_pstrcat(r->pool, "Basic realm=\"", auth_name, "\"", NULL));
1157 #endif
1158 }
1159
1160 int kerb_authenticate_user(request_rec *r)
1161 {
1162    kerb_auth_config *conf = 
1163       (kerb_auth_config *) ap_get_module_config(r->per_dir_config,
1164                                                 &auth_kerb_module);
1165    const char *auth_type = NULL;
1166    const char *auth_line = NULL;
1167    const char *type = NULL;
1168    int use_krb5 = 0, use_krb4 = 0;
1169    int ret;
1170    static int last_return = HTTP_UNAUTHORIZED;
1171    char *negotiate_ret_value = NULL;
1172
1173    /* get the type specified in .htaccess */
1174    type = ap_auth_type(r);
1175
1176    if (type && strcasecmp(type, "Kerberos") == 0)
1177       use_krb5 = use_krb4 = 1;
1178    else if(type && strcasecmp(type, "KerberosV5") == 0)
1179       use_krb4 = 0;
1180    else if(type && strcasecmp(type, "KerberosV4") == 0)
1181       use_krb5 = 0;
1182    else
1183       return DECLINED;
1184
1185    /* get what the user sent us in the HTTP header */
1186    auth_line = MK_TABLE_GET(r->headers_in, "Authorization");
1187    if (!auth_line) {
1188        auth_line = MK_TABLE_GET(r->headers_in, "Proxy-Authorization");
1189        if (!auth_line) {
1190                set_kerb_auth_headers(r, conf, use_krb4, use_krb5,
1191                                      (use_krb5) ? "\0" : NULL);
1192                return HTTP_UNAUTHORIZED;
1193        }
1194    }
1195    auth_type = ap_getword_white(r->pool, &auth_line);
1196
1197    if (already_succeeded(r))
1198       return last_return;
1199
1200    ret = HTTP_UNAUTHORIZED;
1201
1202 #ifdef KRB5
1203    if (use_krb5 && conf->krb_method_gssapi &&
1204        strcasecmp(auth_type, "Negotiate") == 0) {
1205       ret = authenticate_user_gss(r, conf, auth_line, &negotiate_ret_value);
1206    } else if (use_krb5 && conf->krb_method_k5pass &&
1207               strcasecmp(auth_type, "Basic") == 0) {
1208        ret = authenticate_user_krb5pwd(r, conf, auth_line);
1209    }
1210 #endif
1211
1212 #ifdef KRB4
1213    if (ret == HTTP_UNAUTHORIZED && use_krb4 && conf->krb_method_k4pass &&
1214        strcasecmp(auth_type, "Basic") == 0)
1215       ret = authenticate_user_krb4pwd(r, conf, auth_line);
1216 #endif
1217
1218    if (ret == HTTP_UNAUTHORIZED)
1219       set_kerb_auth_headers(r, conf, use_krb4, use_krb5, negotiate_ret_value);
1220
1221    last_return = ret;
1222    return ret;
1223 }
1224
1225
1226 /*************************************************************************** 
1227  Module Setup/Configuration
1228  ***************************************************************************/
1229 #ifdef APXS1
1230 module MODULE_VAR_EXPORT auth_kerb_module = {
1231         STANDARD_MODULE_STUFF,
1232         NULL,                           /*      module initializer            */
1233         kerb_dir_create_config,         /*      per-directory config creator  */
1234         NULL,                           /*      per-directory config merger   */
1235         NULL,                           /*      per-server    config creator  */
1236         NULL,                           /*      per-server    config merger   */
1237         kerb_auth_cmds,                 /*      command table                 */
1238         NULL,                           /* [ 9] content handlers              */
1239         NULL,                           /* [ 2] URI-to-filename translation   */
1240         kerb_authenticate_user,         /* [ 5] check/validate user_id        */
1241         NULL,                           /* [ 6] check user_id is valid *here* */
1242         NULL,                           /* [ 4] check access by host address  */
1243         NULL,                           /* [ 7] MIME type checker/setter      */
1244         NULL,                           /* [ 8] fixups                        */
1245         NULL,                           /* [10] logger                        */
1246         NULL,                           /* [ 3] header parser                 */
1247         NULL,                           /*      process initialization        */
1248         NULL,                           /*      process exit/cleanup          */
1249         NULL                            /* [ 1] post read_request handling    */
1250 };
1251 #else
1252 static int
1253 kerb_init_handler(apr_pool_t *p, apr_pool_t *plog,
1254                   apr_pool_t *ptemp, server_rec *s)
1255 {
1256    ap_add_version_component(p, "mod_auth_kerb/" MODAUTHKERB_VERSION);
1257    return OK;
1258 }
1259
1260 void kerb_register_hooks(apr_pool_t *p)
1261 {
1262    ap_hook_post_config(kerb_init_handler, NULL, NULL, APR_HOOK_MIDDLE);
1263    ap_hook_check_user_id(kerb_authenticate_user, NULL, NULL, APR_HOOK_MIDDLE);
1264 }
1265
1266 module AP_MODULE_DECLARE_DATA auth_kerb_module =
1267 {
1268    STANDARD20_MODULE_STUFF,
1269    kerb_dir_create_config,      /* create per-dir    conf structures  */
1270    NULL,                        /* merge  per-dir    conf structures  */
1271    NULL,                        /* create per-server conf structures  */
1272    NULL,                        /* merge  per-server conf structures  */
1273    kerb_auth_cmds,              /* table of configuration directives  */
1274    kerb_register_hooks          /* register hooks                     */
1275 };
1276 #endif