1 int kerb_authenticate_user(request_rec *r) {
2 const char *name; /* AuthName specified */
3 const char *type; /* AuthType specified */
4 int KerberosV5 = 0; /* Kerberos V5 check enabled */
5 int KerberosV4 = 0; /* Kerberos V4 check enabled */
6 int KerberosV4first = 0; /* Kerberos V4 check first */
7 const char *sent_pw; /* Password sent by browser */
8 const char *t; /* Return value holder */
9 int res; /* Response holder */
10 int retcode; /* Return code holder */
12 kerb_auth_config *conf =
13 (kerb_auth_config *)ap_get_module_config(r->per_dir_config,
16 const char *auth_line = apr_table_get(r->headers_in,
17 (PROXYREQ_PROXY == r->proxyreq)
18 ? "Proxy-Authorization"
21 type = ap_auth_type(r);
25 if ((strncasecmp(type, "KerberosV5", 10) == 0) ||
26 (strncasecmp(conf->krb_auth_type, "KerberosV5", 10) == 0)) {
32 if ((strncasecmp(type, "KerberosV4", 10) == 0) ||
33 (strncasecmp(conf->krb_auth_type, "KerberosV4", 10) == 0)) {
38 #if defined(KRB5) && defined(KRB4)
39 if ((strncasecmp(type, "KerberosDualV5V4", 15) == 0) ||
40 (strncasecmp(conf->krb_auth_type, "KerberosDualV5V4", 15) == 0)) {
45 if ((strncasecmp(type, "KerberosDualV4V5", 15) == 0) ||
46 (strncasecmp(conf->krb_auth_type, "KerberosDualV4V5", 15) == 0)) {
51 #endif /* KRB5 && KRB4 */
54 if (!KerberosV4 && !KerberosV5) {
58 name = ap_auth_name(r);
60 ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR,
61 0, r, "need AuthName: %s", r->uri);
62 return HTTP_INTERNAL_SERVER_ERROR;
66 apr_table_set(r->err_headers_out, "WWW-Authenticate",
67 (char *)apr_pstrcat(r->pool, "Basic realm=\"", name, "\"", NULL));
68 return HTTP_UNAUTHORIZED;
71 type = ap_getword_white(r->pool, &auth_line);
72 t = ap_pbase64decode(r->pool, auth_line);
73 r->user = ap_getword_nulls(r->pool, &t, ':');
74 r->ap_auth_type = "Kerberos";
75 sent_pw = ap_getword_white(r->pool, &t);
80 if (KerberosV5 && !KerberosV4first && retcode != OK) {
81 r->ap_auth_type = "KerberosV5";
82 if (kerb5_password_validate(r->user, sent_pw)) {
86 retcode = conf->krb_fail_status;
92 if (KerberosV4 && retcode != OK) {
93 r->ap_auth_type = "KerberosV4";
94 if (kerb4_password_validate(r->user, sent_pw)) {
98 retcode = conf->krb_fail_status;
103 #if defined(KRB5) && defined(KRB4)
104 if (KerberosV5 && KerberosV4first && retcode != OK) {
105 r->ap_auth_type = "KerberosV5";
106 if (kerb5_password_validate(r->user, sent_pw)) {
110 retcode = conf->krb_fail_status;
113 #endif /* KRB5 && KRB4 */