Back to square one
[hcoop/debian/libapache-mod-waklog.git] / mod_waklog.c
CommitLineData
bed98ff9 1#include "httpd.h"
2#include "http_config.h"
7193eb01 3#include "http_conf_globals.h"
bed98ff9 4#include "http_log.h"
7193eb01 5#include "http_protocol.h"
6#include "http_request.h"
7#include "http_core.h"
bed98ff9 8#include "ap_config.h"
4e1ae1cd 9#include <krb5.h>
bed98ff9 10
7193eb01 11#if defined(sun)
bed98ff9 12#include <sys/ioccom.h>
7193eb01 13#endif /* sun */
bed98ff9 14#include <stropts.h>
bed98ff9 15#include <afs/venus.h>
7193eb01 16#include <afs/auth.h>
17#include <rx/rxkad.h>
18
58bbdc54 19#define KEYTAB "/home/drh/keytab.umweb.drhtest"
20#define KEYTAB_PRINCIPAL "umweb/drhtest"
4e1ae1cd 21
58bbdc54 22#define TKT_LIFE 10*60*60
23#define SLEEP_TIME 5*60 /* should be TKT_LIFE */
24
25#define AFS_CELL "umich.edu" /* NB: lower case */
26
27#define K5PATH "FILE:/tmp/waklog.creds.k5"
28#define K4PATH "/tmp/waklog.creds.k4"
7193eb01 29
313dde40 30module waklog_module;
bed98ff9 31
32struct ClearToken {
33 long AuthHandle;
34 char HandShakeKey[ 8 ];
35 long ViceId;
36 long BeginTimestamp;
37 long EndTimestamp;
38};
39
313dde40 40typedef struct {
4e1ae1cd 41 int configured;
42 int protect;
43 char *keytab;
7193eb01 44 char *keytab_principal;
403921ef 45 char *afs_cell;
313dde40 46} waklog_host_config;
47
7193eb01 48typedef struct {
49 struct ktc_token token;
50} waklog_child_config;
58bbdc54 51waklog_child_config child;
52
e21f34f0 53
4d47a8d9 54 static void *
55waklog_create_dir_config( pool *p, char *path )
56{
57 waklog_host_config *cfg;
58
59 cfg = (waklog_host_config *)ap_pcalloc( p, sizeof( waklog_host_config ));
60 cfg->configured = 0;
61 cfg->protect = 0;
62 cfg->keytab = KEYTAB;
63 cfg->keytab_principal = KEYTAB_PRINCIPAL;
64 cfg->afs_cell = AFS_CELL;
65
66 return( cfg );
67}
68
69
313dde40 70 static void *
71waklog_create_server_config( pool *p, server_rec *s )
72{
73 waklog_host_config *cfg;
74
75 cfg = (waklog_host_config *)ap_pcalloc( p, sizeof( waklog_host_config ));
76 cfg->configured = 0;
77 cfg->protect = 0;
58bbdc54 78 cfg->keytab = KEYTAB;
79 cfg->keytab_principal = KEYTAB_PRINCIPAL;
80 cfg->afs_cell = AFS_CELL;
313dde40 81
4d47a8d9 82#if 0
83 ap_set_module_config( s->module_config, &waklog_module, cfg);
84#endif /* 0 */
85
313dde40 86 return( cfg );
87}
88
89
313dde40 90 static const char *
91set_waklog_protect( cmd_parms *params, void *mconfig, int flag )
92{
93 waklog_host_config *cfg;
94
95 if ( params->path == NULL ) {
96 cfg = (waklog_host_config *) ap_get_module_config(
97 params->server->module_config, &waklog_module );
98 } else {
99 cfg = (waklog_host_config *)mconfig;
100 }
101
102 cfg->protect = flag;
103 cfg->configured = 1;
104 return( NULL );
105}
106
107
4e1ae1cd 108 static const char *
109set_waklog_use_keytab( cmd_parms *params, void *mconfig, char *file )
110{
111 waklog_host_config *cfg;
112
113 if ( params->path == NULL ) {
114 cfg = (waklog_host_config *) ap_get_module_config(
115 params->server->module_config, &waklog_module );
116 } else {
117 cfg = (waklog_host_config *)mconfig;
118 }
119
3ed1e28a 120 ap_log_error( APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, params->server,
121 "mod_waklog: using keytab: %s", file );
122
4e1ae1cd 123 cfg->keytab = file;
124 cfg->configured = 1;
125 return( NULL );
126}
127
128
58bbdc54 129 static const char *
130set_waklog_use_keytab_principal( cmd_parms *params, void *mconfig, char *file )
b74fad73 131{
58bbdc54 132 waklog_host_config *cfg;
7193eb01 133
58bbdc54 134 if ( params->path == NULL ) {
135 cfg = (waklog_host_config *) ap_get_module_config(
136 params->server->module_config, &waklog_module );
137 } else {
138 cfg = (waklog_host_config *)mconfig;
7193eb01 139 }
140
58bbdc54 141 ap_log_error( APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, params->server,
142 "mod_waklog: using keytab_principal: %s", file );
143
144 cfg->keytab_principal = file;
145 cfg->configured = 1;
146 return( NULL );
147}
148
149
150 static const char *
151set_waklog_use_afs_cell( cmd_parms *params, void *mconfig, char *file )
152{
153 waklog_host_config *cfg;
154
155 if ( params->path == NULL ) {
156 cfg = (waklog_host_config *) ap_get_module_config(
157 params->server->module_config, &waklog_module );
158 } else {
159 cfg = (waklog_host_config *)mconfig;
160 }
161
162 ap_log_error( APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, params->server,
163 "mod_waklog: using afs_cell: %s", file );
164
165 cfg->afs_cell = file;
166 cfg->configured = 1;
167 return( NULL );
168}
169
170
171 static void
172waklog_child_init( server_rec *s, pool *p )
173{
174
175 memset( &child.token, 0, sizeof( struct ktc_token ) );
7193eb01 176
b74fad73 177 setpag();
7193eb01 178
b74fad73 179 return;
180}
181
182
313dde40 183command_rec waklog_cmds[ ] =
184{
185 { "WaklogProtected", set_waklog_protect,
186 NULL, RSRC_CONF | ACCESS_CONF, FLAG,
187 "enable waklog on a location or directory basis" },
188
58bbdc54 189 { "WaklogUseKeytabPath", set_waklog_use_keytab,
190 NULL, RSRC_CONF, TAKE1,
191 "Use the supplied keytab rather than the default" },
192
193 { "WaklogUseKeytabPrincipal", set_waklog_use_keytab_principal,
194 NULL, RSRC_CONF, TAKE1,
195 "Use the supplied keytab principal rather than the default" },
196
197 { "WaklogUseAFSCell", set_waklog_use_afs_cell,
4e1ae1cd 198 NULL, RSRC_CONF, TAKE1,
58bbdc54 199 "Use the supplied AFS cell rather than the default" },
4e1ae1cd 200
313dde40 201 { NULL }
202};
203
204
bed98ff9 205 static void
e2df6441 206token_cleanup( void *data )
bed98ff9 207{
208 request_rec *r = (request_rec *)data;
bed98ff9 209
58bbdc54 210 if ( child.token.ticketLen ) {
211 memset( &child.token, 0, sizeof( struct ktc_token ) );
bed98ff9 212
7193eb01 213 ktc_ForgetAllTokens();
bed98ff9 214
7193eb01 215 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
58bbdc54 216 "mod_waklog: ktc_ForgetAllTokens succeeded: pid: %d", getpid() );
7193eb01 217 }
b74fad73 218 return;
bed98ff9 219}
220
221
4e1ae1cd 222 static int
e2df6441 223waklog_kinit( server_rec *s )
4e1ae1cd 224{
225 krb5_error_code kerror;
e2df6441 226 krb5_context kcontext = NULL;
227 krb5_principal kprinc = NULL;
4e1ae1cd 228 krb5_get_init_creds_opt kopts;
7193eb01 229 krb5_creds v5creds;
e2df6441 230 krb5_ccache kccache = NULL;
231 krb5_keytab keytab = NULL;
4e1ae1cd 232 char ktbuf[ MAX_KEYTAB_NAME_LEN + 1 ];
e21f34f0 233 waklog_host_config *cfg;
4e1ae1cd 234
e21f34f0 235 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
e2df6441 236 "mod_waklog: waklog_kinit called" );
4e1ae1cd 237
58bbdc54 238 cfg = (waklog_host_config *) ap_get_module_config( s->module_config,
239 &waklog_module );
240
e21f34f0 241 if (( kerror = krb5_init_context( &kcontext ))) {
242 ap_log_error( APLOG_MARK, APLOG_ERR, s,
243 (char *)error_message( kerror ));
4e1ae1cd 244
e2df6441 245 goto cleanup;
e21f34f0 246 }
4e1ae1cd 247
e21f34f0 248 /* use the path */
249 if (( kerror = krb5_cc_resolve( kcontext, K5PATH, &kccache )) != 0 ) {
250 ap_log_error( APLOG_MARK, APLOG_ERR, s,
251 (char *)error_message( kerror ));
4e1ae1cd 252
e2df6441 253 goto cleanup;
e21f34f0 254 }
4e1ae1cd 255
58bbdc54 256 if (( kerror = krb5_parse_name( kcontext, cfg->keytab_principal, &kprinc ))) {
e21f34f0 257 ap_log_error( APLOG_MARK, APLOG_ERR, s,
258 (char *)error_message( kerror ));
7193eb01 259
e2df6441 260 goto cleanup;
e21f34f0 261 }
7193eb01 262
e21f34f0 263 krb5_get_init_creds_opt_init( &kopts );
58bbdc54 264 krb5_get_init_creds_opt_set_tkt_life( &kopts, TKT_LIFE );
e21f34f0 265 krb5_get_init_creds_opt_set_renew_life( &kopts, 0 );
266 krb5_get_init_creds_opt_set_forwardable( &kopts, 1 );
267 krb5_get_init_creds_opt_set_proxiable( &kopts, 0 );
7193eb01 268
58bbdc54 269 /* keytab from config */
270 strncpy( ktbuf, cfg->keytab, sizeof( ktbuf ) - 1 );
7193eb01 271
e21f34f0 272 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
e2df6441 273 "mod_waklog: waklog_kinit using: %s", ktbuf );
7193eb01 274
e21f34f0 275 if (( kerror = krb5_kt_resolve( kcontext, ktbuf, &keytab )) != 0 ) {
276 ap_log_error( APLOG_MARK, APLOG_ERR, s,
277 (char *)error_message( kerror ));
7193eb01 278
e2df6441 279 goto cleanup;
e21f34f0 280 }
7193eb01 281
e21f34f0 282 /* get the krbtgt */
283 if (( kerror = krb5_get_init_creds_keytab( kcontext, &v5creds,
403921ef 284 kprinc, keytab, 0, NULL, &kopts ))) {
7193eb01 285
e21f34f0 286 ap_log_error( APLOG_MARK, APLOG_ERR, s,
287 (char *)error_message( kerror ));
7193eb01 288
e2df6441 289 goto cleanup;
e21f34f0 290 }
7193eb01 291
e21f34f0 292 if (( kerror = krb5_verify_init_creds( kcontext, &v5creds,
293 kprinc, keytab, NULL, NULL )) != 0 ) {
7193eb01 294
e21f34f0 295 ap_log_error( APLOG_MARK, APLOG_ERR, s,
296 (char *)error_message( kerror ));
7193eb01 297
e2df6441 298 goto cleanup;
e21f34f0 299 }
7193eb01 300
e21f34f0 301 if (( kerror = krb5_cc_initialize( kcontext, kccache, kprinc )) != 0 ) {
302 ap_log_error( APLOG_MARK, APLOG_ERR, s,
303 (char *)error_message( kerror ));
7193eb01 304
e2df6441 305 goto cleanup;
e21f34f0 306 }
7193eb01 307
e2df6441 308 kerror = krb5_cc_store_cred( kcontext, kccache, &v5creds );
309 krb5_free_cred_contents( kcontext, &v5creds );
310 if ( kerror != 0 ) {
e21f34f0 311 ap_log_error( APLOG_MARK, APLOG_ERR, s,
312 (char *)error_message( kerror ));
7193eb01 313
e2df6441 314 goto cleanup;
e21f34f0 315 }
7193eb01 316
e21f34f0 317 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
e2df6441 318 "mod_waklog: waklog_kinit success" );
319
320cleanup:
321 if ( keytab )
322 (void)krb5_kt_close( kcontext, keytab );
323 if ( kprinc )
324 krb5_free_principal( kcontext, kprinc );
325 if ( kccache )
326 krb5_cc_close( kcontext, kccache );
327 if ( kcontext )
328 krb5_free_context( kcontext );
e21f34f0 329
330 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s,
e2df6441 331 "mod_waklog: waklog_kinit: exiting" );
7193eb01 332
333 return( 0 );
334}
335
336
337 static void
338waklog_aklog( request_rec *r )
339{
340 int rc;
58bbdc54 341 char buf[ 2048 ];
7193eb01 342 const char *k4path = NULL;
343 const char *k5path = NULL;
344 krb5_error_code kerror;
e2df6441 345 krb5_context kcontext = NULL;
7193eb01 346 krb5_creds increds;
347 krb5_creds *v5credsp = NULL;
e2df6441 348 krb5_ccache kccache = NULL;
403921ef 349 struct ktc_principal server = { "afs", "", "" };
7193eb01 350 struct ktc_principal client;
351 struct ktc_token token;
403921ef 352 waklog_host_config *cfg;
58bbdc54 353 int buflen;
7193eb01 354
355 k5path = ap_table_get( r->subprocess_env, "KRB5CCNAME" );
356 k4path = ap_table_get( r->subprocess_env, "KRBTKFILE" );
357
358 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
359 "mod_waklog: waklog_aklog called: k5path: %s, k4path: %s", k5path, k4path );
360
361 if ( !k5path || !k4path ) {
362 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
363 "mod_waklog: waklog_aklog giving up" );
e2df6441 364 goto cleanup;
4e1ae1cd 365 }
366
7193eb01 367 /*
368 ** Get/build creds from file/tgs, then see if we need to SetToken
369 */
370
371 if (( kerror = krb5_init_context( &kcontext ))) {
372 /* Authentication Required ( kerberos error ) */
4e1ae1cd 373 ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
374 (char *)error_message( kerror ));
7193eb01 375
e2df6441 376 goto cleanup;
4e1ae1cd 377 }
378
7193eb01 379 memset( (char *)&increds, 0, sizeof(increds));
4e1ae1cd 380
403921ef 381 cfg = (waklog_host_config *) ap_get_module_config(
382 r->server->module_config, &waklog_module );
383
384 /* afs/<cell> or afs */
385 strncpy( buf, "afs", sizeof( buf ) - 1 );
58bbdc54 386 if ( strcmp( cfg->afs_cell, AFS_CELL ) ) {
403921ef 387 strncat( buf, "/" , sizeof( buf ) - strlen( buf ) - 1 );
388 strncat( buf, cfg->afs_cell, sizeof( buf ) - strlen( buf ) - 1 );
389 }
390
7193eb01 391 /* set server part */
403921ef 392 if (( kerror = krb5_parse_name( kcontext, buf, &increds.server ))) {
4e1ae1cd 393 ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
394 (char *)error_message( kerror ));
395
e2df6441 396 goto cleanup;
4e1ae1cd 397 }
398
7193eb01 399 if (( kerror = krb5_cc_resolve( kcontext, k5path, &kccache )) != 0 ) {
400 ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
401 (char *)error_message( kerror ));
402
e2df6441 403 goto cleanup;
7193eb01 404 }
4e1ae1cd 405
7193eb01 406 /* set client part */
407 krb5_cc_get_principal( kcontext, kccache, &increds.client );
4e1ae1cd 408
7193eb01 409 increds.times.endtime = 0;
410 /* Ask for DES since that is what V4 understands */
411 increds.keyblock.enctype = ENCTYPE_DES_CBC_CRC;
412
413 /* get the V5 credentials */
414 if (( kerror = krb5_get_credentials( kcontext, 0, kccache,
415 &increds, &v5credsp ) ) ) {
403921ef 416 ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
417 "mod_waklog: krb5_get_credentials: %s", error_message( kerror ));
e2df6441 418 goto cleanup;
4e1ae1cd 419 }
420
58bbdc54 421 /* don't overflor */
422 if ( v5credsp->ticket.length >= 344 ) { /* from krb524d.c */
403921ef 423 ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
58bbdc54 424 "mod_waklog: ticket size (%d) to big to fake", v5credsp->ticket.length );
e2df6441 425 goto cleanup;
4e1ae1cd 426 }
427
7193eb01 428 /* assemble the token */
58bbdc54 429 memset( &token, 0, sizeof( struct ktc_token ) );
430
431 token.startTime = v5credsp->times.starttime ? v5credsp->times.starttime : v5credsp->times.authtime;
7193eb01 432 token.endTime = v5credsp->times.endtime;
58bbdc54 433 memmove( &token.sessionKey, v5credsp->keyblock.contents, v5credsp->keyblock.length );
434 token.kvno = RXKAD_TKT_TYPE_KERBEROS_V5;
435 token.ticketLen = v5credsp->ticket.length;
436 memmove( token.ticket, v5credsp->ticket.data, token.ticketLen );
7193eb01 437
58bbdc54 438 /* make sure we have to do this */
439 if ( child.token.kvno != token.kvno ||
440 child.token.ticketLen != token.ticketLen ||
441 (memcmp( &child.token.sessionKey, &token.sessionKey,
442 sizeof( token.sessionKey ) )) ||
443 (memcmp( child.token.ticket, token.ticket, token.ticketLen )) ) {
444
8258901d 445 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
446 "mod_waklog: client: %s", buf );
7193eb01 447
448 /* build the name */
58bbdc54 449 memmove( buf, v5credsp->client->data[0].data, v5credsp->client->data[0].length );
450 buf[ v5credsp->client->data[0].length ] = '\0';
451 if ( v5credsp->client->length > 1 ) {
8258901d 452 strncat( buf, ".", sizeof( buf ) - strlen( buf ) - 1 );
58bbdc54 453 buflen = strlen( buf );
454 memmove( buf + buflen, v5credsp->client->data[1].data, v5credsp->client->data[1].length );
455 buf[ buflen + v5credsp->client->data[1].length ] = '\0';
7193eb01 456 }
457
458 /* assemble the client */
403921ef 459 strncpy( client.name, buf, sizeof( client.name ) - 1 );
460 strncpy( client.instance, "", sizeof( client.instance) - 1 );
58bbdc54 461 memmove( buf, v5credsp->client->realm.data, v5credsp->client->realm.length );
462 buf[ v5credsp->client->realm.length ] = '\0';
463 strncpy( client.cell, buf, sizeof( client.cell ) - 1 );
403921ef 464
58bbdc54 465 /* assemble the server's cell */
403921ef 466 strncpy( server.cell, cfg->afs_cell , sizeof( server.cell ) - 1 );
7193eb01 467
468 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
469 "mod_waklog: server: name=%s, instance=%s, cell=%s",
470 server.name, server.instance, server.cell );
471
472 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
473 "mod_waklog: client: name=%s, instance=%s, cell=%s",
474 client.name, client.instance, client.cell );
475
476 /* use the path */
477 krb_set_tkt_string( (char *)k4path );
478
479 /* rumor: we have to do this for AIX 4.1.4 with AFS 3.4+ */
480 write( 2, "", 0 );
481
482 if ( ( rc = ktc_SetToken( &server, &token, &client, 0 ) ) ) {
58bbdc54 483 ap_log_error( APLOG_MARK, APLOG_ERR, r->server,
7193eb01 484 "mod_waklog: settoken returned %d", rc );
58bbdc54 485 goto cleanup;
7193eb01 486 }
487
488 /* save this */
58bbdc54 489 memmove( &child.token, &token, sizeof( struct ktc_token ) );
7193eb01 490
491 /* we'll need to unlog when this connection is done. */
e2df6441 492 ap_register_cleanup( r->pool, (void *)r, token_cleanup, ap_null_cleanup );
7193eb01 493 }
494
e2df6441 495cleanup:
496 if ( v5credsp )
497 krb5_free_cred_contents( kcontext, v5credsp );
498 if ( increds.client )
499 krb5_free_principal( kcontext, increds.client );
500 if ( increds.server )
501 krb5_free_principal( kcontext, increds.server );
502 if ( kccache )
503 krb5_cc_close( kcontext, kccache );
504 if ( kcontext )
505 krb5_free_context( kcontext );
3ed1e28a 506
7193eb01 507 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
508 "mod_waklog: finished with waklog_aklog" );
509
e2df6441 510 return;
511
4e1ae1cd 512}
513
e21f34f0 514 static int
515waklog_child_routine( void *s, child_info *pinfo )
516{
e21f34f0 517 if ( !getuid() ) {
132ef613 518 ap_log_error( APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, s,
e21f34f0 519 "mod_waklog: waklog_child_routine called as root" );
520
521 /* this was causing the credential file to get owned by root */
522 setgid(ap_group_id);
523 setuid(ap_user_id);
524 }
525
526 while( 1 ) {
e2df6441 527 waklog_kinit( s );
58bbdc54 528 sleep( SLEEP_TIME );
e21f34f0 529 }
530
531}
532
533
534 static void
535waklog_init( server_rec *s, pool *p )
536{
537 extern char *version;
538 int pid;
539
540 ap_log_error( APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, s,
541 "mod_waklog: version %s initialized.", version );
542
543 pid = ap_bspawn_child( p, waklog_child_routine, s, kill_always,
544 NULL, NULL, NULL );
545
132ef613 546 ap_log_error( APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, s,
e21f34f0 547 "mod_waklog: ap_bspawn_child: %d.", pid );
548}
549
4e1ae1cd 550
bed98ff9 551 static int
7193eb01 552waklog_phase0( request_rec *r )
bed98ff9 553{
313dde40 554 waklog_host_config *cfg;
555
7193eb01 556 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
557 "mod_waklog: phase0 called" );
558
313dde40 559 /* directory config? */
560 cfg = (waklog_host_config *)ap_get_module_config(
561 r->per_dir_config, &waklog_module);
bed98ff9 562
313dde40 563 /* server config? */
564 if ( !cfg->configured ) {
7193eb01 565 cfg = (waklog_host_config *)ap_get_module_config(
566 r->server->module_config, &waklog_module);
313dde40 567 }
568
7193eb01 569 if ( !cfg->protect ) {
4e1ae1cd 570 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
7193eb01 571 "mod_waklog: phase0 declining" );
572 return( DECLINED );
573 }
4e1ae1cd 574
7193eb01 575 /* do this only if we are still unauthenticated */
58bbdc54 576 if ( !child.token.ticketLen ) {
4e1ae1cd 577
e21f34f0 578 /* set our environment variables */
579 ap_table_set( r->subprocess_env, "KRB5CCNAME", K5PATH );
580 ap_table_set( r->subprocess_env, "KRBTKFILE", K4PATH );
3ed1e28a 581
7193eb01 582 /* stuff the credentials into the kernel */
583 waklog_aklog( r );
4e1ae1cd 584 }
7193eb01 585
586 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
587 "mod_waklog: phase0 returning" );
588 return DECLINED;
589}
4e1ae1cd 590
1e18ef7d 591
7193eb01 592 static int
593waklog_phase7( request_rec *r )
594{
595 waklog_host_config *cfg;
1e18ef7d 596
7193eb01 597 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
598 "mod_waklog: phase7 called" );
1e18ef7d 599
7193eb01 600 /* directory config? */
601 cfg = (waklog_host_config *)ap_get_module_config(
602 r->per_dir_config, &waklog_module);
1e18ef7d 603
7193eb01 604 /* server config? */
605 if ( !cfg->configured ) {
606 cfg = (waklog_host_config *)ap_get_module_config(
607 r->server->module_config, &waklog_module);
bed98ff9 608 }
609
7193eb01 610 if ( !cfg->protect ) {
611 return( DECLINED );
bed98ff9 612 }
613
7193eb01 614 /* stuff the credentials into the kernel */
615 waklog_aklog( r );
bed98ff9 616
7193eb01 617 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server,
618 "mod_waklog: phase7 returning" );
bed98ff9 619
7193eb01 620 return DECLINED;
bed98ff9 621}
622
7193eb01 623 static void
624waklog_new_connection( conn_rec *c ) {
625 ap_log_error( APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, c->server,
58bbdc54 626 "mod_waklog: new_connection called: pid: %d", getpid() );
7193eb01 627 return;
628}
bed98ff9 629
313dde40 630module MODULE_VAR_EXPORT waklog_module = {
bed98ff9 631 STANDARD_MODULE_STUFF,
003832b1 632 waklog_init, /* module initializer */
4d47a8d9 633 waklog_create_dir_config, /* create per-dir config structures */
bed98ff9 634 NULL, /* merge per-dir config structures */
313dde40 635 waklog_create_server_config, /* create per-server config structures */
bed98ff9 636 NULL, /* merge per-server config structures */
313dde40 637 waklog_cmds, /* table of config file commands */
bed98ff9 638 NULL, /* [#8] MIME-typed-dispatched handlers */
639 NULL, /* [#1] URI to filename translation */
640 NULL, /* [#4] validate user id from request */
641 NULL, /* [#5] check if the user is ok _here_ */
642 NULL, /* [#3] check access by host address */
643 NULL, /* [#6] determine MIME type */
7193eb01 644 waklog_phase7, /* [#7] pre-run fixups */
bed98ff9 645 NULL, /* [#9] log a transaction */
313dde40 646 NULL, /* [#2] header parser */
647 waklog_child_init, /* child_init */
bed98ff9 648 NULL, /* child_exit */
7193eb01 649 waklog_phase0 /* [#0] post read-request */
bed98ff9 650#ifdef EAPI
651 ,NULL, /* EAPI: add_module */
652 NULL, /* EAPI: remove_module */
653 NULL, /* EAPI: rewrite_command */
7193eb01 654 waklog_new_connection /* EAPI: new_connection */
bed98ff9 655#endif
656};