X-Git-Url: https://git.hcoop.net/hcoop/debian/libapache-mod-waklog.git/blobdiff_plain/678051d73489e976065510c6e4bd4afb1b350dd9..fcf33557c36c8c2fe3068e8178a1f7438c2a09b9:/mod_waklog.c diff --git a/mod_waklog.c b/mod_waklog.c index 7931874..07f1339 100644 --- a/mod_waklog.c +++ b/mod_waklog.c @@ -10,6 +10,8 @@ #ifdef sun #include +#include +#include #elif linux #define use_pthreads #include @@ -31,9 +33,6 @@ /********************* APACHE1 ******************************************************************************/ #ifndef APACHE2 #include "ap_config.h" -#if defined(sun) -#include -#endif /* sun */ #include #define MK_POOL pool #define MK_TABLE_GET ap_table_get @@ -46,6 +45,7 @@ module waklog_module; /********************* APACHE2 ******************************************************************************/ #else +#include "http_connection.h" #include #include #define ap_pcalloc apr_pcalloc @@ -54,11 +54,6 @@ module waklog_module; #define MK_POOL apr_pool_t #define MK_TABLE_GET apr_table_get #define MK_TABLE_SET apr_table_set -#include "unixd.h" -extern unixd_config_rec unixd_config; -#define ap_user_id unixd_config.user_id -#define ap_group_id unixd_config.group_id -#define ap_user_name unixd_config.user_name #define command(name, func, var, type, usage) \ AP_INIT_ ## type (name, (void*) func, \ NULL, \ @@ -67,11 +62,19 @@ module AP_MODULE_DECLARE_DATA waklog_module; typedef struct { int dummy; } child_info; const char *userdata_key = "waklog_init"; +/* Apache 2.4 */ +#ifdef APLOG_USE_MODULE +APLOG_USE_MODULE(waklog); +#endif + #endif /* APACHE2 */ /**************************************************************************************************/ #include -#include +#include + +#include + #include #include #include @@ -81,9 +84,7 @@ const char *userdata_key = "waklog_init"; #define TKT_LIFE ( 12 * 60 * 60 ) #define SLEEP_TIME ( TKT_LIFE - 5*60 ) -#define WAKLOG_ON 1 -#define WAKLOG_OFF 2 -#define WAKLOG_UNSET 0 +#define WAKLOG_UNSET -1 #ifdef WAKLOG_DEBUG #undef APLOG_DEBUG @@ -163,22 +164,16 @@ int renewcount = 0; #define getModConfig(P, X) P = (waklog_config *) ap_get_module_config( (X)->module_config, &waklog_module ); -#include - -#if defined(sun) -#include -#endif /* sun */ -#include -#include -#include -#include -#include -#include - +#ifdef APLOG_USE_MODULE +static void +log_error (const char *file, int line, int module_index, int level, int status, + const server_rec * s, const char *fmt, ...) +#else static void log_error (const char *file, int line, int level, int status, const server_rec * s, const char *fmt, ...) +#endif { char errstr[4096]; va_list ap; @@ -188,7 +183,12 @@ log_error (const char *file, int line, int level, int status, va_end (ap); #ifdef APACHE2 + #ifdef APLOG_USE_MODULE + /* Apache 2.4 */ + ap_log_error (file, line, module_index, level | APLOG_NOERRNO, status, s, "%s", errstr); + #else ap_log_error (file, line, level | APLOG_NOERRNO, status, s, "(%d) %s", getpid(), errstr); + #endif #else ap_log_error (file, line, level | APLOG_NOERRNO, s, "(%d) %s", getpid(), errstr); #endif @@ -310,7 +310,7 @@ set_auth ( server_rec *s, request_rec *r, int self, char *principal, char *keyta #ifdef APACHE2 if ( ! ( r && r->connection && r->user )) { log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_waklog: self authentication selected, but no data available"); - log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_waklog: r->user=%s", (r->user==NULL ? "null" : r->user==NULL)); + log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_waklog: r->user=%s", (r->user==NULL ? "null" : r->user)); return -1; } @@ -345,7 +345,7 @@ set_auth ( server_rec *s, request_rec *r, int self, char *principal, char *keyta } #endif - log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "mod_waklog: set_auth: k5user=%s", k5user ? k5user : "NULL"); + log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "mod_waklog: set_auth: k5user=%s", k5user); mytime = time(0); /* see if we should just go ahead and ignore this call, since we already should be set to these @@ -416,7 +416,7 @@ set_auth ( server_rec *s, request_rec *r, int self, char *principal, char *keyta } /* if 'usecached' isn't set, we've got to get our tokens from somewhere... */ - if (( ! usecached ) && ( k5user )) { + if ( ! usecached ) { /* clear out the creds structure */ memset((void *) &v5creds, 0, sizeof(v5creds)); @@ -464,11 +464,11 @@ set_auth ( server_rec *s, request_rec *r, int self, char *principal, char *keyta log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_waklog: krb5_get_init_creds_password %s", error_message(kerror) ); /* nuke the password so it doesn't end up in core files */ - memset(k5secret, 0, sizeof(k5secret)); + memset(k5secret, 0, strlen(k5secret)); goto cleanup; } - memset(k5secret, 0, sizeof(k5secret)); + memset(k5secret, 0, strlen(k5secret)); } /* initialize the credentials cache and store the stuff we just got */ @@ -520,7 +520,7 @@ set_auth ( server_rec *s, request_rec *r, int self, char *principal, char *keyta strncat(buf, "/", sizeof(buf) - strlen(buf) - 1); strncat(buf, cfg->afs_cell, sizeof(buf) - strlen(buf) - 1); } - if (cfg->afs_cell_realm != WAKLOG_UNSET) { + if (cfg->afs_cell_realm != NULL) { strncat(buf, "@", sizeof(buf) - strlen(buf) - 1); strncat(buf, cfg->afs_cell_realm, sizeof(buf) - strlen(buf) - 1); } @@ -744,6 +744,27 @@ set_auth ( server_rec *s, request_rec *r, int self, char *principal, char *keyta } +int get_cfg_usertokens(waklog_config *cfg) +{ + if (cfg->usertokens==WAKLOG_UNSET) + return 0; /* default */ + return cfg->usertokens; +} + +int get_cfg_protect(waklog_config *cfg) +{ + if (cfg->protect==WAKLOG_UNSET) + return 0; /* default */ + return cfg->protect; +} + +int get_cfg_disable_token_cache(waklog_config *cfg) +{ + if (cfg->disable_token_cache==WAKLOG_UNSET) + return 0; /* default */ + return cfg->disable_token_cache; +} + static void * waklog_create_server_config (MK_POOL * p, server_rec * s) @@ -757,12 +778,12 @@ waklog_create_server_config (MK_POOL * p, server_rec * s) cfg->protect = WAKLOG_UNSET; cfg->usertokens = WAKLOG_UNSET; cfg->disable_token_cache = WAKLOG_UNSET; - cfg->keytab = WAKLOG_UNSET; - cfg->principal = WAKLOG_UNSET; - cfg->default_principal = WAKLOG_UNSET; - cfg->default_keytab = WAKLOG_UNSET; - cfg->afs_cell = WAKLOG_UNSET; - cfg->afs_cell_realm = WAKLOG_UNSET; + cfg->keytab = NULL; + cfg->principal = NULL; + cfg->default_principal = NULL; + cfg->default_keytab = NULL; + cfg->afs_cell = NULL; + cfg->afs_cell_realm = NULL; cfg->forked = 0; cfg->configured = 0; @@ -786,12 +807,12 @@ waklog_create_dir_config (MK_POOL * p, char *dir) cfg->protect = WAKLOG_UNSET; cfg->usertokens = WAKLOG_UNSET; cfg->disable_token_cache = WAKLOG_UNSET; - cfg->keytab = WAKLOG_UNSET; - cfg->principal = WAKLOG_UNSET; - cfg->default_principal = WAKLOG_UNSET; - cfg->default_keytab = WAKLOG_UNSET; - cfg->afs_cell = WAKLOG_UNSET; - cfg->afs_cell_realm = WAKLOG_UNSET; + cfg->keytab = NULL; + cfg->principal = NULL; + cfg->default_principal = NULL; + cfg->default_keytab = NULL; + cfg->afs_cell = NULL; + cfg->afs_cell_realm = NULL; cfg->forked = 0; cfg->configured = 0; @@ -806,23 +827,23 @@ static void *waklog_merge_dir_config(MK_POOL *p, void *parent_conf, void *newloc merged->protect = child->protect != WAKLOG_UNSET ? child->protect : parent->protect; - merged->path = child->path != WAKLOG_UNSET ? child->path : parent->path; + merged->path = child->path != NULL ? child->path : parent->path; merged->usertokens = child->usertokens != WAKLOG_UNSET ? child->usertokens : parent->usertokens; merged->disable_token_cache = child->disable_token_cache != WAKLOG_UNSET ? child->disable_token_cache : parent->disable_token_cache; - merged->principal = child->principal != WAKLOG_UNSET ? child->principal : parent->principal; + merged->principal = child->principal != NULL ? child->principal : parent->principal; - merged->keytab = child->keytab != WAKLOG_UNSET ? child->keytab : parent->keytab; + merged->keytab = child->keytab != NULL ? child->keytab : parent->keytab; - merged->default_keytab = child->default_keytab != WAKLOG_UNSET ? child->default_keytab : parent->default_keytab; + merged->default_keytab = child->default_keytab != NULL ? child->default_keytab : parent->default_keytab; - merged->default_principal = child->default_principal != WAKLOG_UNSET ? child->default_principal : parent->default_principal; + merged->default_principal = child->default_principal != NULL ? child->default_principal : parent->default_principal; - merged->afs_cell = child->afs_cell != WAKLOG_UNSET ? child->afs_cell : parent->afs_cell; + merged->afs_cell = child->afs_cell != NULL ? child->afs_cell : parent->afs_cell; - merged->afs_cell_realm = child->afs_cell_realm != WAKLOG_UNSET ? child->afs_cell_realm : parent->afs_cell_realm; + merged->afs_cell_realm = child->afs_cell_realm != NULL ? child->afs_cell_realm : parent->afs_cell_realm; return (void *) merged; @@ -840,23 +861,23 @@ static void *waklog_merge_server_config(MK_POOL *p, void *parent_conf, void *new merged->disable_token_cache = nconf->disable_token_cache == WAKLOG_UNSET ? pconf->disable_token_cache : nconf->disable_token_cache; - merged->keytab = nconf->keytab == WAKLOG_UNSET ? ap_pstrdup(p, pconf->keytab) : - ( nconf->keytab == WAKLOG_UNSET ? WAKLOG_UNSET : ap_pstrdup(p, pconf->keytab) ); + merged->keytab = nconf->keytab == NULL ? ap_pstrdup(p, pconf->keytab) : + ( nconf->keytab == NULL ? NULL : ap_pstrdup(p, nconf->keytab) ); - merged->principal = nconf->principal == WAKLOG_UNSET ? ap_pstrdup(p, pconf->principal) : - ( nconf->principal == WAKLOG_UNSET ? WAKLOG_UNSET : ap_pstrdup(p, pconf->principal) ); + merged->principal = nconf->principal == NULL ? ap_pstrdup(p, pconf->principal) : + ( nconf->principal == NULL ? NULL : ap_pstrdup(p, nconf->principal) ); - merged->afs_cell = nconf->afs_cell == WAKLOG_UNSET ? ap_pstrdup(p, pconf->afs_cell) : - ( nconf->afs_cell == WAKLOG_UNSET ? WAKLOG_UNSET : ap_pstrdup(p, pconf->afs_cell) ); + merged->afs_cell = nconf->afs_cell == NULL ? ap_pstrdup(p, pconf->afs_cell) : + ( nconf->afs_cell == NULL ? NULL : ap_pstrdup(p, nconf->afs_cell) ); - merged->afs_cell_realm = nconf->afs_cell_realm == WAKLOG_UNSET ? ap_pstrdup(p, pconf->afs_cell_realm) : - ( nconf->afs_cell_realm == WAKLOG_UNSET ? WAKLOG_UNSET : ap_pstrdup(p, pconf->afs_cell_realm) ); + merged->afs_cell_realm = nconf->afs_cell_realm == NULL ? ap_pstrdup(p, pconf->afs_cell_realm) : + ( nconf->afs_cell_realm == NULL ? NULL : ap_pstrdup(p, nconf->afs_cell_realm) ); - merged->default_keytab = nconf->default_keytab == WAKLOG_UNSET ? ap_pstrdup(p, pconf->default_keytab) : - ( nconf->default_keytab == WAKLOG_UNSET ? WAKLOG_UNSET : ap_pstrdup(p, pconf->default_keytab) ); + merged->default_keytab = nconf->default_keytab == NULL ? ap_pstrdup(p, pconf->default_keytab) : + ( nconf->default_keytab == NULL ? NULL : ap_pstrdup(p, nconf->default_keytab) ); - merged->default_principal = nconf->default_principal == WAKLOG_UNSET ? ap_pstrdup(p, pconf->default_principal) : - ( nconf->default_principal == WAKLOG_UNSET ? WAKLOG_UNSET : ap_pstrdup(p, pconf->default_principal) ); + merged->default_principal = nconf->default_principal == NULL ? ap_pstrdup(p, pconf->default_principal) : + ( nconf->default_principal == NULL ? NULL : ap_pstrdup(p, nconf->default_principal) ); return (void *) merged; @@ -1090,12 +1111,12 @@ waklog_child_init (server_rec * s, MK_POOL * p) } if ( pag_for_children ) { - setpag (); + k_setpag (); } getModConfig (cfg, s); - if ( cfg->default_principal != WAKLOG_UNSET ) { + if ( cfg->default_principal != NULL ) { log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "mod_waklog: child_init setting default user %s, %s", cfg->default_principal, cfg->default_keytab); set_auth( s, NULL, 0, cfg->default_principal, cfg->default_keytab, 0); } @@ -1160,7 +1181,15 @@ token_cleanup (void *data) return 0; } +/* This function doesn't return anything but is passed to ap_bspawn_child on + * Apache 1 which expects it to return a pid as an int. For want of better + * understanding, err on the side of not changing Apache 1 code while fixing + * the compile warning on Apache 2. */ +#ifdef APACHE2 +static void +#else static int +#endif waklog_child_routine (void *data, child_info * pinfo) { int i; @@ -1301,15 +1330,24 @@ waklog_init_handler (apr_pool_t * p, apr_pool_t * plog, struct sharedspace_s bob; log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_waklog: sizing our cache file %d to %d", fd, sizeof(struct sharedspace_s) ); memset( &bob, 0, sizeof(struct sharedspace_s)); - write(fd, &bob, sizeof(struct sharedspace_s)); + if ( write(fd, &bob, sizeof(struct sharedspace_s)) != sizeof(struct sharedspace_s) ) { + log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_waklog: failed to write to our cache file %s (%d)", cache_file, errno ); + exit(errno); + } log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_waklog: done sizing our cache file to %d", sizeof(struct sharedspace_s) ); } /* mmap the region */ if ( ( sharedspace = (struct sharedspace_s *) mmap ( NULL, sizeof(struct sharedspace_s), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0 ) ) != MAP_FAILED ) { + int err = 0; log_error( APLOG_MARK, APLOG_DEBUG, 0, s, "mod_waklog: shared mmap region ok %d", sharedspace ); - close(fd); + err = unlink(cache_file); + if (err) { + log_error( APLOG_MARK, APLOG_ERR, 0, s, "mod_waklog: unable to delete %s due to %d", cache_file, errno); + } else { + log_error( APLOG_MARK, APLOG_DEBUG, 0, s, "mod_waklog: shared cache unlinked (will be deleted when Apache quits)"); + } } else { log_error( APLOG_MARK, APLOG_DEBUG, 0, s, "mod_waklog: mmap failed %d", errno ); exit(errno); @@ -1322,7 +1360,7 @@ waklog_init_handler (apr_pool_t * p, apr_pool_t * plog, #define locktype rwlock_t #endif - if ( sharedlock = ( locktype * ) mmap ( NULL, sizeof(locktype), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0 ) ) { + if ( ( sharedlock = ( locktype * ) mmap ( NULL, sizeof(locktype), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0 ) ) != NULL ) { #ifndef use_pthreads rwlock_init(sharedlock, USYNC_PROCESS, NULL ); #else @@ -1493,7 +1531,7 @@ waklog_phase0 (request_rec * r) cfg = retrieve_config(r); - if ( cfg->protect && cfg->principal ) { + if ( get_cfg_protect(cfg) && cfg->principal ) { log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "mod_waklog: phase0 using user %s", cfg->principal); set_auth(r->server, r, 0, cfg->principal, cfg->keytab, 0); } else if ( cfg->default_principal ) { @@ -1522,7 +1560,7 @@ waklog_phase1 (request_rec * r) cfg = retrieve_config(r); - if ( cfg->protect && cfg->principal ) { + if ( get_cfg_protect(cfg) && cfg->principal ) { log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "mod_waklog: phase1 using user %s", cfg->principal); set_auth(r->server, r, 0, cfg->principal, cfg->keytab, 0); } else if ( cfg->default_principal ) { @@ -1545,7 +1583,7 @@ waklog_phase3 (request_rec * r) cfg = retrieve_config(r); - if ( cfg->protect && cfg->principal ) { + if ( get_cfg_protect(cfg) && cfg->principal ) { log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "mod_waklog: phase3 using user %s", cfg->principal); set_auth(r->server, r, 0, cfg->principal, cfg->keytab, 0); } else if ( cfg->default_principal ) { @@ -1568,7 +1606,7 @@ waklog_phase6 (request_rec * r) cfg = retrieve_config(r); - if ( cfg->protect && cfg->principal ) { + if ( get_cfg_protect(cfg) && cfg->principal ) { log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "mod_waklog: phase6 using user %s", cfg->principal); set_auth(r->server, r, 0, cfg->principal, cfg->keytab, 0); } else if ( cfg->default_principal ) { @@ -1592,10 +1630,10 @@ waklog_phase7 (request_rec * r) cfg = retrieve_config (r); - if ( cfg->protect && cfg->usertokens ) { + if ( get_cfg_protect(cfg) && get_cfg_usertokens(cfg) ) { log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "mod_waklog: phase7 using usertokens"); rc = set_auth( r->server, r, 1, NULL, NULL, 0); - } else if ( cfg->protect && cfg->principal ) { + } else if ( get_cfg_protect(cfg) && cfg->principal ) { log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "mod_waklog: phase7 using user %s", cfg->principal); rc = set_auth( r->server, r, 0, cfg->principal, cfg->keytab, 0); } else if ( cfg->default_principal ) {