diff options
-rw-r--r-- | AUTHORS | 5 | ||||
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | apache13.h | 1 | ||||
-rw-r--r-- | apache20.h | 1 | ||||
-rw-r--r-- | functions.h | 337 | ||||
-rw-r--r-- | functions13.h | 1 | ||||
-rw-r--r-- | functions20.h | 1 | ||||
-rw-r--r-- | mod_log_sql.c | 428 | ||||
-rw-r--r-- | mod_log_sql_ssl.c | 100 |
9 files changed, 453 insertions, 424 deletions
@@ -0,0 +1,5 @@ | |||
1 | Christopher B. Powell | ||
2 | Main author | ||
3 | |||
4 | Edward Rudd <eddie at omegaware dot com> | ||
5 | Apache 2.0 port. | ||
@@ -1,4 +1,4 @@ | |||
1 | $Id: CHANGELOG,v 1.6 2004/01/20 16:27:34 urkle Exp $ | 1 | $Id: CHANGELOG,v 1.7 2004/01/20 19:38:07 urkle Exp $ |
2 | 2 | ||
3 | TODO: | 3 | TODO: |
4 | * Port connection portion to other DBMS? Genericize the module? Start with | 4 | * Port connection portion to other DBMS? Genericize the module? Start with |
@@ -28,6 +28,7 @@ CHANGES: | |||
28 | * updated configure m4 scripts to detect both apache versions at the same time | 28 | * updated configure m4 scripts to detect both apache versions at the same time |
29 | and assign defines as to which version was found. | 29 | and assign defines as to which version was found. |
30 | * made install default to not activate module in configuration files. | 30 | * made install default to not activate module in configuration files. |
31 | (use make activate) | ||
31 | 32 | ||
32 | 1.92: 2004-01-05 | 33 | 1.92: 2004-01-05 |
33 | * fixed compilation issue with mysql 4.x where mysql_error returns const char * | 34 | * fixed compilation issue with mysql 4.x where mysql_error returns const char * |
@@ -1,3 +1,4 @@ | |||
1 | /* $Header: /home/cvs/mod_log_sql/apache13.h,v 1.2 2004/01/20 19:38:07 urkle Exp $ */ | ||
1 | #ifndef APACHE13_H | 2 | #ifndef APACHE13_H |
2 | #define APACHE13_H | 3 | #define APACHE13_H |
3 | 4 | ||
@@ -1,3 +1,4 @@ | |||
1 | /* $Header: /home/cvs/mod_log_sql/apache20.h,v 1.2 2004/01/20 19:38:07 urkle Exp $ */ | ||
1 | #ifndef APACHE20_H | 2 | #ifndef APACHE20_H |
2 | #define APACHE20_H | 3 | #define APACHE20_H |
3 | 4 | ||
diff --git a/functions.h b/functions.h new file mode 100644 index 0000000..60d08b5 --- /dev/null +++ b/functions.h | |||
@@ -0,0 +1,337 @@ | |||
1 | /* $Header: /home/cvs/mod_log_sql/functions.h,v 1.1 2004/01/20 19:38:08 urkle Exp $ */ | ||
2 | /* Begin the individual functions that, given a request r, | ||
3 | * extract the needed information from it and return the | ||
4 | * value to the calling entity. | ||
5 | */ | ||
6 | |||
7 | static const char *extract_remote_host(request_rec *r, char *a) | ||
8 | { | ||
9 | return (char *) ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, NULL); | ||
10 | } | ||
11 | |||
12 | static const char *extract_remote_logname(request_rec *r, char *a) | ||
13 | { | ||
14 | return (char *) ap_get_remote_logname(r); | ||
15 | } | ||
16 | |||
17 | static const char *extract_remote_user(request_rec *r, char *a) | ||
18 | { | ||
19 | #ifdef WITH_APACHE13 | ||
20 | char *rvalue = r->connection->user; | ||
21 | #else | ||
22 | char *rvalue = r->user; | ||
23 | #endif | ||
24 | if (rvalue == NULL) { | ||
25 | rvalue = "-"; | ||
26 | } else if (strlen(rvalue) == 0) { | ||
27 | rvalue = "\"\""; | ||
28 | } | ||
29 | return rvalue; | ||
30 | } | ||
31 | |||
32 | static const char *extract_request_method(request_rec *r, char *a) | ||
33 | { | ||
34 | return r->method; | ||
35 | } | ||
36 | |||
37 | static const char *extract_request_protocol(request_rec *r, char *a) | ||
38 | { | ||
39 | return r->protocol; | ||
40 | } | ||
41 | |||
42 | static const char *extract_request_line(request_rec *r, char *a) | ||
43 | { | ||
44 | return r->the_request; | ||
45 | } | ||
46 | |||
47 | static const char *extract_request_file(request_rec *r, char *a) | ||
48 | { | ||
49 | return r->filename; | ||
50 | } | ||
51 | |||
52 | static const char *extract_request_uri(request_rec *r, char *a) | ||
53 | { | ||
54 | return r->uri; | ||
55 | } | ||
56 | |||
57 | static const char *extract_request_args(request_rec *r, char *a) | ||
58 | { | ||
59 | return r->args; | ||
60 | } | ||
61 | |||
62 | static const char *extract_status(request_rec *r, char *a) | ||
63 | { | ||
64 | if (r->status <= 0) { | ||
65 | return "-"; | ||
66 | } else { | ||
67 | return apr_psprintf(r->pool, "%d", r->status); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | static const char *extract_bytes_sent(request_rec *r, char *a) | ||
72 | { | ||
73 | if (!r->sent_bodyct || !r->bytes_sent) { | ||
74 | return "-"; | ||
75 | } else { | ||
76 | return apr_psprintf(r->pool, "%" APR_OFF_T_FMT, r->bytes_sent); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | /* | ||
81 | static const char *extract_header_in(request_rec *r, char *a) | ||
82 | { | ||
83 | return table_get(r->headers_in, a); | ||
84 | } | ||
85 | |||
86 | static const char *extract_header_out(request_rec *r, char *a) | ||
87 | { | ||
88 | const char *cp = table_get(r->headers_out, a); | ||
89 | if (!strcasecmp(a, "Content-type") && r->content_type) { | ||
90 | cp = r->content_type; | ||
91 | } | ||
92 | if (cp) { | ||
93 | return cp; | ||
94 | } | ||
95 | return table_get(r->err_headers_out, a); | ||
96 | } | ||
97 | */ | ||
98 | |||
99 | static const char *extract_virtual_host(request_rec *r, char *a) | ||
100 | { | ||
101 | return apr_pstrdup(r->pool, r->server->server_hostname); | ||
102 | } | ||
103 | |||
104 | static const char *extract_machine_id(request_rec *r, char *a) | ||
105 | { | ||
106 | if (!global_config.machid) | ||
107 | return "-"; | ||
108 | else | ||
109 | return global_config.machid; | ||
110 | } | ||
111 | |||
112 | static const char *extract_server_port(request_rec *r, char *a) | ||
113 | { | ||
114 | return apr_psprintf(r->pool, "%u", | ||
115 | r->server->port ? r->server->port : ap_default_port(r)); | ||
116 | } | ||
117 | |||
118 | static const char *extract_child_pid(request_rec *r, char *a) | ||
119 | { | ||
120 | if (*a == '\0' || !strcmp(a, "pid")) { | ||
121 | return apr_psprintf(r->pool, "%" APR_PID_T_FMT, getpid()); | ||
122 | } | ||
123 | else if (!strcmp(a, "tid")) { | ||
124 | #if APR_HAS_THREADS | ||
125 | apr_os_thread_t tid = apr_os_thread_current(); | ||
126 | #else | ||
127 | int tid = 0; /* APR will format "0" anyway but an arg is needed */ | ||
128 | #endif | ||
129 | return apr_psprintf(r->pool, "%pT", &tid); | ||
130 | } | ||
131 | /* bogus format */ | ||
132 | return a; | ||
133 | } | ||
134 | |||
135 | static const char *extract_referer(request_rec *r, char *a) | ||
136 | { | ||
137 | const char *tempref; | ||
138 | |||
139 | tempref = apr_table_get(r->headers_in, "Referer"); | ||
140 | if (!tempref) | ||
141 | { | ||
142 | return "-"; | ||
143 | } else { | ||
144 | return tempref; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | static const char *extract_agent(request_rec *r, char *a) | ||
149 | { | ||
150 | const char *tempag; | ||
151 | |||
152 | tempag = apr_table_get(r->headers_in, "User-Agent"); | ||
153 | if (!tempag) | ||
154 | { | ||
155 | return "-"; | ||
156 | } else { | ||
157 | return tempag; | ||
158 | } | ||
159 | } | ||
160 | |||
161 | static const char *extract_cookie(request_rec *r, char *a) | ||
162 | { | ||
163 | const char *cookiestr; | ||
164 | char *cookieend; | ||
165 | char *isvalid; | ||
166 | char *cookiebuf; | ||
167 | |||
168 | logsql_state *cls = ap_get_module_config(r->server->module_config, | ||
169 | &log_sql_module); | ||
170 | |||
171 | if (cls->cookie_name != NULL) { | ||
172 | #ifdef DEBUG | ||
173 | log_error(APLOG_MARK,APLOG_DEBUG, r->server, | ||
174 | "watching for cookie '%s'", cls->cookie_name); | ||
175 | #endif | ||
176 | |||
177 | /* Fetch out the cookie header */ | ||
178 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); | ||
179 | if (cookiestr != NULL) { | ||
180 | #ifdef DEBUG | ||
181 | log_error(APLOG_MARK,APLOG_DEBUG, r->server, | ||
182 | "Cookie2: [%s]", cookiestr); | ||
183 | #endif | ||
184 | /* Does the cookie string contain one with our name? */ | ||
185 | isvalid = strstr(cookiestr, cls->cookie_name); | ||
186 | if (isvalid != NULL) { | ||
187 | /* Move past the cookie name and equal sign */ | ||
188 | isvalid += strlen(cls->cookie_name) + 1; | ||
189 | /* Duplicate it into the pool */ | ||
190 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
191 | /* Segregate just this cookie out of the string | ||
192 | * with a terminating nul at the first semicolon */ | ||
193 | cookieend = strchr(cookiebuf, ';'); | ||
194 | if (cookieend != NULL) | ||
195 | *cookieend = '\0'; | ||
196 | return cookiebuf; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); | ||
201 | if (cookiestr != NULL) { | ||
202 | #ifdef DEBUG | ||
203 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, | ||
204 | "Cookie: [%s]", cookiestr); | ||
205 | #endif | ||
206 | isvalid = strstr(cookiestr, cls->cookie_name); | ||
207 | if (isvalid != NULL) { | ||
208 | isvalid += strlen(cls->cookie_name) + 1; | ||
209 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
210 | cookieend = strchr(cookiebuf, ';'); | ||
211 | if (cookieend != NULL) | ||
212 | *cookieend = '\0'; | ||
213 | return cookiebuf; | ||
214 | } | ||
215 | } | ||
216 | |||
217 | cookiestr = apr_table_get(r->headers_out, "set-cookie"); | ||
218 | if (cookiestr != NULL) { | ||
219 | #ifdef DEBUG | ||
220 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, | ||
221 | "Set-Cookie: [%s]", cookiestr); | ||
222 | #endif | ||
223 | isvalid = strstr(cookiestr, cls->cookie_name); | ||
224 | if (isvalid != NULL) { | ||
225 | isvalid += strlen(cls->cookie_name) + 1; | ||
226 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
227 | cookieend = strchr(cookiebuf, ';'); | ||
228 | if (cookieend != NULL) | ||
229 | *cookieend = '\0'; | ||
230 | return cookiebuf; | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | |||
235 | return "-"; | ||
236 | } | ||
237 | |||
238 | static const char *extract_specific_cookie(request_rec *r, char *a) | ||
239 | { | ||
240 | const char *cookiestr; | ||
241 | char *cookieend; | ||
242 | char *isvalid; | ||
243 | char *cookiebuf; | ||
244 | |||
245 | if (a != NULL) { | ||
246 | #ifdef DEBUG | ||
247 | log_error(APLOG_MARK,APLOG_DEBUG, | ||
248 | r->server,"watching for cookie '%s'", a); | ||
249 | #endif | ||
250 | |||
251 | /* Fetch out the cookie header */ | ||
252 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); | ||
253 | if (cookiestr != NULL) { | ||
254 | #ifdef DEBUG | ||
255 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, | ||
256 | "Cookie2: [%s]", cookiestr); | ||
257 | #endif | ||
258 | /* Does the cookie string contain one with our name? */ | ||
259 | isvalid = strstr(cookiestr, a); | ||
260 | if (isvalid != NULL) { | ||
261 | /* Move past the cookie name and equal sign */ | ||
262 | isvalid += strlen(a) + 1; | ||
263 | /* Duplicate it into the pool */ | ||
264 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
265 | /* Segregate just this cookie out of the string | ||
266 | * with a terminating nul at the first semicolon */ | ||
267 | cookieend = strchr(cookiebuf, ';'); | ||
268 | if (cookieend != NULL) | ||
269 | *cookieend = '\0'; | ||
270 | return cookiebuf; | ||
271 | } | ||
272 | } | ||
273 | |||
274 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); | ||
275 | if (cookiestr != NULL) { | ||
276 | #ifdef DEBUG | ||
277 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, | ||
278 | "Cookie: [%s]", cookiestr); | ||
279 | #endif | ||
280 | isvalid = strstr(cookiestr, a); | ||
281 | if (isvalid != NULL) { | ||
282 | isvalid += strlen(a) + 1; | ||
283 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
284 | cookieend = strchr(cookiebuf, ';'); | ||
285 | if (cookieend != NULL) | ||
286 | *cookieend = '\0'; | ||
287 | return cookiebuf; | ||
288 | } | ||
289 | } | ||
290 | |||
291 | cookiestr = apr_table_get(r->headers_out, "set-cookie"); | ||
292 | if (cookiestr != NULL) { | ||
293 | #ifdef DEBUG | ||
294 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, | ||
295 | "Set-Cookie: [%s]", cookiestr); | ||
296 | #endif | ||
297 | isvalid = strstr(cookiestr, a); | ||
298 | if (isvalid != NULL) { | ||
299 | isvalid += strlen(a) + 1; | ||
300 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
301 | cookieend = strchr(cookiebuf, ';'); | ||
302 | if (cookieend != NULL) | ||
303 | *cookieend = '\0'; | ||
304 | return cookiebuf; | ||
305 | } | ||
306 | } | ||
307 | } | ||
308 | |||
309 | return "-"; | ||
310 | } | ||
311 | |||
312 | |||
313 | /* | ||
314 | static const char *extract_note(request_rec *r, char *a) | ||
315 | { | ||
316 | return apr_table_get(r->notes, a); | ||
317 | |||
318 | } | ||
319 | */ | ||
320 | |||
321 | static const char *extract_env_var(request_rec *r, char *a) | ||
322 | { | ||
323 | return apr_table_get(r->subprocess_env, a); | ||
324 | } | ||
325 | |||
326 | static const char *extract_unique_id(request_rec *r, char *a) | ||
327 | { | ||
328 | const char *tempid; | ||
329 | |||
330 | tempid = apr_table_get(r->subprocess_env, "UNIQUE_ID"); | ||
331 | if (!tempid) | ||
332 | return "-"; | ||
333 | else | ||
334 | return tempid; | ||
335 | } | ||
336 | |||
337 | /* End declarations of various extract_ functions */ | ||
diff --git a/functions13.h b/functions13.h index bff37f2..1b85d0e 100644 --- a/functions13.h +++ b/functions13.h | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $Header: /home/cvs/mod_log_sql/functions13.h,v 1.2 2004/01/20 19:38:08 urkle Exp $ */ | ||
1 | static const char *extract_request_time(request_rec *r, char *a) | 2 | static const char *extract_request_time(request_rec *r, char *a) |
2 | { | 3 | { |
3 | int timz; | 4 | int timz; |
diff --git a/functions20.h b/functions20.h index 9ff3a63..c8701a2 100644 --- a/functions20.h +++ b/functions20.h | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $Header: /home/cvs/mod_log_sql/functions20.h,v 1.2 2004/01/20 19:38:08 urkle Exp $ */ | ||
1 | /* functions */ | 2 | /* functions */ |
2 | static const char *extract_request_time_custom(request_rec *r, char *a, | 3 | static const char *extract_request_time_custom(request_rec *r, char *a, |
3 | apr_time_exp_t *xt) | 4 | apr_time_exp_t *xt) |
diff --git a/mod_log_sql.c b/mod_log_sql.c index 02d5fd4..1ce4a44 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.7 2004/01/20 16:27:34 urkle Exp $ */ | 1 | /* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.8 2004/01/20 19:38:08 urkle Exp $ */ |
2 | /* --------* | 2 | /* --------* |
3 | * DEFINES * | 3 | * DEFINES * |
4 | * --------*/ | 4 | * --------*/ |
@@ -44,11 +44,6 @@ | |||
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | 46 | ||
47 | #ifdef WANT_SSL_LOGGING | ||
48 | #include "mod_ssl.h" | ||
49 | #endif | ||
50 | |||
51 | |||
52 | /* Configuratino Defaults */ | 47 | /* Configuratino Defaults */ |
53 | #define DEFAULT_TRANSFER_LOG_FMT "AbHhmRSsTUuv" | 48 | #define DEFAULT_TRANSFER_LOG_FMT "AbHhmRSsTUuv" |
54 | #define DEFAULT_NOTES_TABLE_NAME "notes" | 49 | #define DEFAULT_NOTES_TABLE_NAME "notes" |
@@ -121,420 +116,13 @@ typedef struct { | |||
121 | 116 | ||
122 | static int safe_create_tables(logsql_state *cls, request_rec *r); | 117 | static int safe_create_tables(logsql_state *cls, request_rec *r); |
123 | 118 | ||
124 | static char *format_integer(apr_pool_t *p, int i) | 119 | /* Include all the extract functions */ |
125 | { | 120 | #include "functions.h" |
126 | char dummy[40]; | ||
127 | apr_snprintf(dummy, sizeof(dummy), "%d", i); | ||
128 | return apr_pstrdup(p, dummy); | ||
129 | } | ||
130 | |||
131 | static char *pfmt(apr_pool_t *p, int i) | ||
132 | { | ||
133 | if (i <= 0) { | ||
134 | return "-"; | ||
135 | } else { | ||
136 | return format_integer(p, i); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | /* Begin the individual functions that, given a request r, | ||
141 | * extract the needed information from it and return the | ||
142 | * value to the calling entity. | ||
143 | */ | ||
144 | |||
145 | static const char *extract_remote_host(request_rec *r, char *a) | ||
146 | { | ||
147 | return (char *) ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, NULL); | ||
148 | } | ||
149 | |||
150 | static const char *extract_remote_logname(request_rec *r, char *a) | ||
151 | { | ||
152 | return (char *) ap_get_remote_logname(r); | ||
153 | } | ||
154 | |||
155 | static const char *extract_remote_user(request_rec *r, char *a) | ||
156 | { | ||
157 | #ifdef WITH_APACHE13 | ||
158 | char *rvalue = r->connection->user; | ||
159 | #else | ||
160 | char *rvalue = r->user; | ||
161 | #endif | ||
162 | if (rvalue == NULL) { | ||
163 | rvalue = "-"; | ||
164 | } else if (strlen(rvalue) == 0) { | ||
165 | rvalue = "\"\""; | ||
166 | } | ||
167 | return rvalue; | ||
168 | } | ||
169 | |||
170 | #ifdef WANT_SSL_LOGGING | ||
171 | static const char *extract_ssl_keysize(request_rec *r, char *a) | ||
172 | { | ||
173 | char *result = NULL; | ||
174 | SSLConnRec *scc = myConnConfig(r->connection); | ||
175 | SSLSrvConfigRec *ssc = mySrvConfig(r->server); | ||
176 | |||
177 | if (myCtxConfig(scc,ssc) != NULL) { | ||
178 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_USEKEYSIZE"); | ||
179 | #ifdef DEBUG | ||
180 | log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_KEYSIZE: %s", result); | ||
181 | #endif | ||
182 | if (result != NULL && result[0] == '\0') | ||
183 | result = NULL; | ||
184 | return result; | ||
185 | } else { | ||
186 | return "0"; | ||
187 | } | ||
188 | } | ||
189 | |||
190 | static const char *extract_ssl_maxkeysize(request_rec *r, char *a) | ||
191 | { | ||
192 | char *result = NULL; | ||
193 | SSLConnRec *scc = myConnConfig(r->connection); | ||
194 | SSLSrvConfigRec *ssc = mySrvConfig(r->server); | ||
195 | |||
196 | if (myCtxConfig(scc,ssc) != NULL) { | ||
197 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_ALGKEYSIZE"); | ||
198 | #ifdef DEBUG | ||
199 | log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_ALGKEYSIZE: %s", result); | ||
200 | #endif | ||
201 | if (result != NULL && result[0] == '\0') | ||
202 | result = NULL; | ||
203 | return result; | ||
204 | } else { | ||
205 | return "0"; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | static const char *extract_ssl_cipher(request_rec *r, char *a) | ||
210 | { | ||
211 | char *result = NULL; | ||
212 | SSLConnRec *scc = myConnConfig(r->connection); | ||
213 | SSLSrvConfigRec *ssc = mySrvConfig(r->server); | ||
214 | |||
215 | if (myCtxConfig(scc,ssc) != NULL) { | ||
216 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER"); | ||
217 | #ifdef DEBUG | ||
218 | log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_CIPHER: %s", result); | ||
219 | #endif | ||
220 | if (result != NULL && result[0] == '\0') | ||
221 | result = NULL; | ||
222 | return result; | ||
223 | } else { | ||
224 | return "-"; | ||
225 | } | ||
226 | } | ||
227 | #endif /* WANT_SSL_LOGGING */ | ||
228 | |||
229 | static const char *extract_request_method(request_rec *r, char *a) | ||
230 | { | ||
231 | return r->method; | ||
232 | } | ||
233 | |||
234 | static const char *extract_request_protocol(request_rec *r, char *a) | ||
235 | { | ||
236 | return r->protocol; | ||
237 | } | ||
238 | |||
239 | static const char *extract_request_line(request_rec *r, char *a) | ||
240 | { | ||
241 | return r->the_request; | ||
242 | } | ||
243 | |||
244 | static const char *extract_request_file(request_rec *r, char *a) | ||
245 | { | ||
246 | return r->filename; | ||
247 | } | ||
248 | |||
249 | static const char *extract_request_uri(request_rec *r, char *a) | ||
250 | { | ||
251 | return r->uri; | ||
252 | } | ||
253 | |||
254 | static const char *extract_request_args(request_rec *r, char *a) | ||
255 | { | ||
256 | return r->args; | ||
257 | } | ||
258 | |||
259 | static const char *extract_status(request_rec *r, char *a) | ||
260 | { | ||
261 | return pfmt(r->pool, r->status); | ||
262 | } | ||
263 | |||
264 | static const char *extract_bytes_sent(request_rec *r, char *a) | ||
265 | { | ||
266 | if (!r->sent_bodyct || !r->bytes_sent) { | ||
267 | return "-"; | ||
268 | } else { | ||
269 | return apr_psprintf(r->pool, "%" APR_OFF_T_FMT, r->bytes_sent); | ||
270 | } | ||
271 | } | ||
272 | |||
273 | /* | ||
274 | static const char *extract_header_in(request_rec *r, char *a) | ||
275 | { | ||
276 | return table_get(r->headers_in, a); | ||
277 | } | ||
278 | |||
279 | static const char *extract_header_out(request_rec *r, char *a) | ||
280 | { | ||
281 | const char *cp = table_get(r->headers_out, a); | ||
282 | if (!strcasecmp(a, "Content-type") && r->content_type) { | ||
283 | cp = r->content_type; | ||
284 | } | ||
285 | if (cp) { | ||
286 | return cp; | ||
287 | } | ||
288 | return table_get(r->err_headers_out, a); | ||
289 | } | ||
290 | */ | ||
291 | |||
292 | #if defined(WITH_APACHE13) | 121 | #if defined(WITH_APACHE13) |
293 | #include "functions13.h" | 122 | # include "functions13.h" |
294 | #elif defined(WITH_APACHE20) | 123 | #elif defined(WITH_APACHE20) |
295 | #include "functions20.h" | 124 | # include "functions20.h" |
296 | #endif | 125 | #endif |
297 | static const char *extract_virtual_host(request_rec *r, char *a) | ||
298 | { | ||
299 | return apr_pstrdup(r->pool, r->server->server_hostname); | ||
300 | } | ||
301 | |||
302 | static const char *extract_machine_id(request_rec *r, char *a) | ||
303 | { | ||
304 | if (!global_config.machid) | ||
305 | return "-"; | ||
306 | else | ||
307 | return global_config.machid; | ||
308 | } | ||
309 | |||
310 | static const char *extract_server_port(request_rec *r, char *a) | ||
311 | { | ||
312 | return apr_psprintf(r->pool, "%u", | ||
313 | r->server->port ? r->server->port : ap_default_port(r)); | ||
314 | } | ||
315 | |||
316 | static const char *extract_child_pid(request_rec *r, char *a) | ||
317 | { | ||
318 | if (*a == '\0' || !strcmp(a, "pid")) { | ||
319 | return apr_psprintf(r->pool, "%" APR_PID_T_FMT, getpid()); | ||
320 | } | ||
321 | else if (!strcmp(a, "tid")) { | ||
322 | #if APR_HAS_THREADS | ||
323 | apr_os_thread_t tid = apr_os_thread_current(); | ||
324 | #else | ||
325 | int tid = 0; /* APR will format "0" anyway but an arg is needed */ | ||
326 | #endif | ||
327 | return apr_psprintf(r->pool, "%pT", &tid); | ||
328 | } | ||
329 | /* bogus format */ | ||
330 | return a; | ||
331 | } | ||
332 | |||
333 | static const char *extract_referer(request_rec *r, char *a) | ||
334 | { | ||
335 | const char *tempref; | ||
336 | |||
337 | tempref = apr_table_get(r->headers_in, "Referer"); | ||
338 | if (!tempref) | ||
339 | { | ||
340 | return "-"; | ||
341 | } else { | ||
342 | return tempref; | ||
343 | } | ||
344 | } | ||
345 | |||
346 | static const char *extract_agent(request_rec *r, char *a) | ||
347 | { | ||
348 | const char *tempag; | ||
349 | |||
350 | tempag = apr_table_get(r->headers_in, "User-Agent"); | ||
351 | if (!tempag) | ||
352 | { | ||
353 | return "-"; | ||
354 | } else { | ||
355 | return tempag; | ||
356 | } | ||
357 | } | ||
358 | |||
359 | static const char *extract_cookie(request_rec *r, char *a) | ||
360 | { | ||
361 | const char *cookiestr; | ||
362 | char *cookieend; | ||
363 | char *isvalid; | ||
364 | char *cookiebuf; | ||
365 | |||
366 | logsql_state *cls = ap_get_module_config(r->server->module_config, | ||
367 | &log_sql_module); | ||
368 | |||
369 | if (cls->cookie_name != NULL) { | ||
370 | #ifdef DEBUG | ||
371 | log_error(APLOG_MARK,APLOG_DEBUG, r->server, | ||
372 | "watching for cookie '%s'", cls->cookie_name); | ||
373 | #endif | ||
374 | |||
375 | /* Fetch out the cookie header */ | ||
376 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); | ||
377 | if (cookiestr != NULL) { | ||
378 | #ifdef DEBUG | ||
379 | log_error(APLOG_MARK,APLOG_DEBUG, r->server, | ||
380 | "Cookie2: [%s]", cookiestr); | ||
381 | #endif | ||
382 | /* Does the cookie string contain one with our name? */ | ||
383 | isvalid = strstr(cookiestr, cls->cookie_name); | ||
384 | if (isvalid != NULL) { | ||
385 | /* Move past the cookie name and equal sign */ | ||
386 | isvalid += strlen(cls->cookie_name) + 1; | ||
387 | /* Duplicate it into the pool */ | ||
388 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
389 | /* Segregate just this cookie out of the string | ||
390 | * with a terminating nul at the first semicolon */ | ||
391 | cookieend = strchr(cookiebuf, ';'); | ||
392 | if (cookieend != NULL) | ||
393 | *cookieend = '\0'; | ||
394 | return cookiebuf; | ||
395 | } | ||
396 | } | ||
397 | |||
398 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); | ||
399 | if (cookiestr != NULL) { | ||
400 | #ifdef DEBUG | ||
401 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, | ||
402 | "Cookie: [%s]", cookiestr); | ||
403 | #endif | ||
404 | isvalid = strstr(cookiestr, cls->cookie_name); | ||
405 | if (isvalid != NULL) { | ||
406 | isvalid += strlen(cls->cookie_name) + 1; | ||
407 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
408 | cookieend = strchr(cookiebuf, ';'); | ||
409 | if (cookieend != NULL) | ||
410 | *cookieend = '\0'; | ||
411 | return cookiebuf; | ||
412 | } | ||
413 | } | ||
414 | |||
415 | cookiestr = apr_table_get(r->headers_out, "set-cookie"); | ||
416 | if (cookiestr != NULL) { | ||
417 | #ifdef DEBUG | ||
418 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, | ||
419 | "Set-Cookie: [%s]", cookiestr); | ||
420 | #endif | ||
421 | isvalid = strstr(cookiestr, cls->cookie_name); | ||
422 | if (isvalid != NULL) { | ||
423 | isvalid += strlen(cls->cookie_name) + 1; | ||
424 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
425 | cookieend = strchr(cookiebuf, ';'); | ||
426 | if (cookieend != NULL) | ||
427 | *cookieend = '\0'; | ||
428 | return cookiebuf; | ||
429 | } | ||
430 | } | ||
431 | } | ||
432 | |||
433 | return "-"; | ||
434 | } | ||
435 | |||
436 | static const char *extract_specific_cookie(request_rec *r, char *a) | ||
437 | { | ||
438 | const char *cookiestr; | ||
439 | char *cookieend; | ||
440 | char *isvalid; | ||
441 | char *cookiebuf; | ||
442 | |||
443 | if (a != NULL) { | ||
444 | #ifdef DEBUG | ||
445 | log_error(APLOG_MARK,APLOG_DEBUG, | ||
446 | r->server,"watching for cookie '%s'", a); | ||
447 | #endif | ||
448 | |||
449 | /* Fetch out the cookie header */ | ||
450 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); | ||
451 | if (cookiestr != NULL) { | ||
452 | #ifdef DEBUG | ||
453 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, | ||
454 | "Cookie2: [%s]", cookiestr); | ||
455 | #endif | ||
456 | /* Does the cookie string contain one with our name? */ | ||
457 | isvalid = strstr(cookiestr, a); | ||
458 | if (isvalid != NULL) { | ||
459 | /* Move past the cookie name and equal sign */ | ||
460 | isvalid += strlen(a) + 1; | ||
461 | /* Duplicate it into the pool */ | ||
462 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
463 | /* Segregate just this cookie out of the string | ||
464 | * with a terminating nul at the first semicolon */ | ||
465 | cookieend = strchr(cookiebuf, ';'); | ||
466 | if (cookieend != NULL) | ||
467 | *cookieend = '\0'; | ||
468 | return cookiebuf; | ||
469 | } | ||
470 | } | ||
471 | |||
472 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); | ||
473 | if (cookiestr != NULL) { | ||
474 | #ifdef DEBUG | ||
475 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, | ||
476 | "Cookie: [%s]", cookiestr); | ||
477 | #endif | ||
478 | isvalid = strstr(cookiestr, a); | ||
479 | if (isvalid != NULL) { | ||
480 | isvalid += strlen(a) + 1; | ||
481 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
482 | cookieend = strchr(cookiebuf, ';'); | ||
483 | if (cookieend != NULL) | ||
484 | *cookieend = '\0'; | ||
485 | return cookiebuf; | ||
486 | } | ||
487 | } | ||
488 | |||
489 | cookiestr = apr_table_get(r->headers_out, "set-cookie"); | ||
490 | if (cookiestr != NULL) { | ||
491 | #ifdef DEBUG | ||
492 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, | ||
493 | "Set-Cookie: [%s]", cookiestr); | ||
494 | #endif | ||
495 | isvalid = strstr(cookiestr, a); | ||
496 | if (isvalid != NULL) { | ||
497 | isvalid += strlen(a) + 1; | ||
498 | cookiebuf = apr_pstrdup(r->pool, isvalid); | ||
499 | cookieend = strchr(cookiebuf, ';'); | ||
500 | if (cookieend != NULL) | ||
501 | *cookieend = '\0'; | ||
502 | return cookiebuf; | ||
503 | } | ||
504 | } | ||
505 | } | ||
506 | |||
507 | return "-"; | ||
508 | } | ||
509 | |||
510 | |||
511 | /* | ||
512 | static const char *extract_note(request_rec *r, char *a) | ||
513 | { | ||
514 | return apr_table_get(r->notes, a); | ||
515 | |||
516 | } | ||
517 | */ | ||
518 | |||
519 | static const char *extract_env_var(request_rec *r, char *a) | ||
520 | { | ||
521 | return apr_table_get(r->subprocess_env, a); | ||
522 | } | ||
523 | |||
524 | static const char *extract_unique_id(request_rec *r, char *a) | ||
525 | { | ||
526 | const char *tempid; | ||
527 | |||
528 | tempid = apr_table_get(r->subprocess_env, "UNIQUE_ID"); | ||
529 | if (!tempid) | ||
530 | return "-"; | ||
531 | else | ||
532 | return tempid; | ||
533 | } | ||
534 | |||
535 | /* End declarations of various extract_ functions */ | ||
536 | |||
537 | |||
538 | 126 | ||
539 | struct log_sql_item_list { | 127 | struct log_sql_item_list { |
540 | char ch; /* its letter code */ | 128 | char ch; /* its letter code */ |
@@ -567,15 +155,9 @@ struct log_sql_item_list { | |||
567 | { 'u', extract_remote_user, "remote_user", 0, 1 }, | 155 | { 'u', extract_remote_user, "remote_user", 0, 1 }, |
568 | { 'U', extract_request_uri, "request_uri", 1, 1 }, | 156 | { 'U', extract_request_uri, "request_uri", 1, 1 }, |
569 | { 'v', extract_virtual_host, "virtual_host", 0, 1 }, | 157 | { 'v', extract_virtual_host, "virtual_host", 0, 1 }, |
570 | #ifdef WANT_SSL_LOGGING | ||
571 | { 'q', extract_ssl_keysize, "ssl_keysize", 0, 1 }, | ||
572 | { 'Q', extract_ssl_maxkeysize, "ssl_maxkeysize", 0, 1 }, | ||
573 | { 'z', extract_ssl_cipher, "ssl_cipher", 0, 1 }, | ||
574 | #endif | ||
575 | {'\0'} | 158 | {'\0'} |
576 | }; | 159 | }; |
577 | 160 | ||
578 | |||
579 | /* Routine to escape the 'dangerous' characters that would otherwise | 161 | /* Routine to escape the 'dangerous' characters that would otherwise |
580 | * corrupt the INSERT string: ', \, and " | 162 | * corrupt the INSERT string: ', \, and " |
581 | */ | 163 | */ |
diff --git a/mod_log_sql_ssl.c b/mod_log_sql_ssl.c new file mode 100644 index 0000000..3346d2f --- /dev/null +++ b/mod_log_sql_ssl.c | |||
@@ -0,0 +1,100 @@ | |||
1 | /* $Header: /home/cvs/mod_log_sql/mod_log_sql_ssl.c,v 1.1 2004/01/20 19:38:08 urkle Exp $ */ | ||
2 | /* mod_log_sql_ssl */ | ||
3 | |||
4 | #if defined(WITH_APACHE20) | ||
5 | # include "apache20.h" | ||
6 | #elif defined(WITH_APACHE13) | ||
7 | # include "apache13.h" | ||
8 | #else | ||
9 | # error Unsupported Apache version | ||
10 | #endif | ||
11 | |||
12 | #ifdef HAVE_CONFIG_H | ||
13 | /* Undefine these to prevent conflicts between Apache ap_config_auto.h and | ||
14 | * my config.h. Only really needed for Apache < 2.0.48, but it can't hurt. | ||
15 | */ | ||
16 | #undef PACKAGE_BUGREPORT | ||
17 | #undef PACKAGE_NAME | ||
18 | #undef PACKAGE_STRING | ||
19 | #undef PACKAGE_TARNAME | ||
20 | #undef PACKAGE_VERSION | ||
21 | |||
22 | #include "config.h" | ||
23 | #endif | ||
24 | |||
25 | #include "mod_ssl.h" | ||
26 | |||
27 | static const char *extract_ssl_keysize(request_rec *r, char *a) | ||
28 | { | ||
29 | char *result = NULL; | ||
30 | #if defined(APACHE20) | ||
31 | SSLConnRec *scc = myConnConfig(r->connection); | ||
32 | SSLSrvConfigRec *ssc = mySrvConfig(r->server); | ||
33 | if (myCtxConfig(scc,ssc) != NULL | ||
34 | #elif defined(APACHE13) | ||
35 | if (ap_ctx_get(r->connection->client->ctx, "ssl") != NULL) | ||
36 | #endif | ||
37 | { | ||
38 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_USEKEYSIZE"); | ||
39 | #ifdef DEBUG | ||
40 | log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_KEYSIZE: %s", result); | ||
41 | #endif | ||
42 | if (result != NULL && result[0] == '\0') | ||
43 | result = NULL; | ||
44 | return result; | ||
45 | } else { | ||
46 | return "0"; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | static const char *extract_ssl_maxkeysize(request_rec *r, char *a) | ||
51 | { | ||
52 | char *result = NULL; | ||
53 | #if defined(APACHE20) | ||
54 | SSLConnRec *scc = myConnConfig(r->connection); | ||
55 | SSLSrvConfigRec *ssc = mySrvConfig(r->server); | ||
56 | if (myCtxConfig(scc,ssc) != NULL | ||
57 | #elif defined(APACHE13) | ||
58 | if (ap_ctx_get(r->connection->client->ctx, "ssl") != NULL) | ||
59 | #endif | ||
60 | { | ||
61 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_ALGKEYSIZE"); | ||
62 | #ifdef DEBUG | ||
63 | log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_ALGKEYSIZE: %s", result); | ||
64 | #endif | ||
65 | if (result != NULL && result[0] == '\0') | ||
66 | result = NULL; | ||
67 | return result; | ||
68 | } else { | ||
69 | return "0"; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | static const char *extract_ssl_cipher(request_rec *r, char *a) | ||
74 | { | ||
75 | char *result = NULL; | ||
76 | #if defined(APACHE20) | ||
77 | SSLConnRec *scc = myConnConfig(r->connection); | ||
78 | SSLSrvConfigRec *ssc = mySrvConfig(r->server); | ||
79 | if (myCtxConfig(scc,ssc) != NULL | ||
80 | #elif defined(APACHE13) | ||
81 | if (ap_ctx_get(r->connection->client->ctx, "ssl") != NULL) | ||
82 | #endif | ||
83 | { | ||
84 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER"); | ||
85 | #ifdef DEBUG | ||
86 | log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_CIPHER: %s", result); | ||
87 | #endif | ||
88 | if (result != NULL && result[0] == '\0') | ||
89 | result = NULL; | ||
90 | return result; | ||
91 | } else { | ||
92 | return "-"; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | #ifdef WANT_SSL_LOGGING | ||
97 | { 'q', extract_ssl_keysize, "ssl_keysize", 0, 1 }, | ||
98 | { 'Q', extract_ssl_maxkeysize, "ssl_maxkeysize", 0, 1 }, | ||
99 | { 'z', extract_ssl_cipher, "ssl_cipher", 0, 1 }, | ||
100 | #endif | ||