File: apache2.2-authn.dpatch

package info (click to toggle)
libapache-mod-fastcgi 2.4.6-1
  • links: PTS
  • area: non-free
  • in suites: lenny, squeeze
  • size: 568 kB
  • ctags: 600
  • sloc: ansic: 6,287; sh: 334; makefile: 30
file content (114 lines) | stat: -rw-r--r-- 3,234 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! /bin/sh /usr/share/dpatch/dpatch-run
## apache2.2-authn.dpatch by  <sugi@nemui.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: mod_fastcgi works as AUTHN provider for apache 2.2
## 

@DPATCH@
diff -urNad libapache-mod-fastcgi~/mod_fastcgi.c libapache-mod-fastcgi/mod_fastcgi.c
--- libapache-mod-fastcgi~/mod_fastcgi.c	2006-10-06 21:55:39.000000000 +0900
+++ libapache-mod-fastcgi/mod_fastcgi.c	2007-08-25 16:51:25.000000000 +0900
@@ -82,6 +82,10 @@
 
 #include "unixd.h"
 
+#ifdef APACHE22
+#include "mod_auth.h"
+#endif
+
 #endif
 #endif
 
@@ -2657,10 +2661,15 @@
     r->status_line = NULL;
 }
 
+#ifdef APACHE22
+static authn_status check_user_authentication(request_rec *r, const char *user, const char *password)
+{
+#else /* !APACHE22 */
 static int check_user_authentication(request_rec *r)
 {
-    int res, authenticated = 0;
     const char *password;
+#endif
+    int res, authenticated = 0;
     fcgi_request *fr;
     const fcgi_dir_config * const dir_config =
         (const fcgi_dir_config *)ap_get_module_config(r->per_dir_config, &fastcgi_module);
@@ -2668,9 +2677,11 @@
     if (dir_config->authenticator == NULL)
         return DECLINED;
 
-    /* Get the user password */
+#ifndef APACHE22
+		/* Get the user password */
     if ((res = ap_get_basic_auth_pw(r, &password)) != OK)
         return res;
+#endif /* APACHE22 */
 
     res = create_fcgi_request(r, dir_config->authenticator, &fr);
     if (res)
@@ -2704,6 +2715,20 @@
         goto AuthenticationFailed;
     }
 
+#ifdef APACHE22
+    if (authenticated)
+        return AUTH_GRANTED;
+
+AuthenticationFailed:
+    /* @@@ Probably should support custom_responses */
+    ap_note_basic_auth_failure(r);
+    ap_log_rerror(FCGI_LOG_ERR_NOERRNO, r,
+        "FastCGI: authentication failed for user \"%s\": %s",
+        r->user, r->uri);
+
+		return (res == OK) ? AUTH_DENIED : AUTH_GRANTED;
+
+#else /* !APACHE22 */
     if (authenticated)
         return OK;
 
@@ -2722,6 +2747,7 @@
 #endif
 
         return (res == OK) ? HTTP_UNAUTHORIZED : res;
+#endif /* !APACHE22 */
 }
 
 static int check_user_authorization(request_rec *r)
@@ -2913,16 +2939,31 @@
 
 #ifdef APACHE2
 
+#ifdef APACHE22
+static const authn_provider authn_fastcgi_provider =
+{
+    &check_user_authentication,
+		NULL,
+};
+#endif /* APACHE22 */
+
+
 static void register_hooks(apr_pool_t * p)
 {
     /* ap_hook_pre_config(x_pre_config, NULL, NULL, APR_HOOK_MIDDLE); */
     ap_hook_post_config(init_module, NULL, NULL, APR_HOOK_MIDDLE);
     ap_hook_child_init(fcgi_child_init, NULL, NULL, APR_HOOK_MIDDLE);
     ap_hook_handler(content_handler, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_check_user_id(check_user_authentication, NULL, NULL, APR_HOOK_MIDDLE);
     ap_hook_access_checker(check_access, NULL, NULL, APR_HOOK_MIDDLE);
     ap_hook_auth_checker(check_user_authorization, NULL, NULL, APR_HOOK_MIDDLE);
     ap_hook_fixups(fixups, NULL, NULL, APR_HOOK_MIDDLE); 
+#ifdef APACHE22
+		ap_register_provider(p, AUTHN_PROVIDER_GROUP, "fastcgi", "0",
+			 &authn_fastcgi_provider);
+#else
+    ap_hook_check_user_id(check_user_authentication, NULL, NULL, APR_HOOK_MIDDLE);
+#endif
+
 }
 
 module AP_MODULE_DECLARE_DATA fastcgi_module =