[Mod-auth-commit] mod_authn_dbi/src mod_authn_dbi.c,1.17,1.18
Brought to you by:
firechipmunk,
honx
From: <ho...@us...> - 2004-02-16 14:20:17
|
Update of /cvsroot/mod-auth/mod_authn_dbi/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12342 Modified Files: mod_authn_dbi.c Log Message: prevents segfaulting in reslist management if database server is not available. more of a workaround than an actual fix, but a clean fix would require bigger changes that should wait until we restructure the code for v1.0. Index: mod_authn_dbi.c =================================================================== RCS file: /cvsroot/mod-auth/mod_authn_dbi/src/mod_authn_dbi.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- mod_authn_dbi.c 8 Feb 2004 23:40:33 -0000 1.17 +++ mod_authn_dbi.c 16 Feb 2004 14:12:13 -0000 1.18 @@ -298,7 +298,7 @@ conn_id encap_conn_id(cmd_parms * cmd, const char *conn_id) { - /* this will be used to allow configuration in htaccess */ + /* XXX: this will be used to allow configuration in htaccess */ return conn_id; } @@ -667,8 +667,14 @@ apr_status_t rv; ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "[mod_authn_dbi.c] Returning Server Connection to DBI Pool"); - rv = apr_reslist_release(dbi_pool, (void **) server); - return rv; + if(dbi_pool) { + rv = apr_reslist_release(dbi_pool, (void **) server); + return rv; + } + else { + /* XXX: This can not really happen, but just to be on the safe side... */ + return APR_EGENERAL; + } } static int safe_dbi_query(dbi_rest * mydbi_res, dbi_result * res, @@ -727,8 +733,11 @@ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "[mod_authn_dbi.c] Attempting to Acquire DBI Connection"); - apr_reslist_acquire(conf->pool, (void **) &dbi_res); - + if(!conf->pool || apr_reslist_acquire(conf->pool, (void **) &dbi_res) != APR_SUCCESS) { + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, + "[mod_authn_dbi.c] Failed to Acquire DBI Connection"); + return AUTH_GENERAL_ERROR; + } /* make the query to get the user's password */ if (conf->rec.isactive_field) { if (conf->rec.password_query == NULL) { @@ -912,8 +921,12 @@ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "[mod_authn_dbi.c] Attempting to Acquire DBI Connection"); - apr_reslist_acquire(conf->pool, (void **) &dbi_res); - + if(!conf->pool || apr_reslist_acquire(conf->pool, (void **) &dbi_res) != APR_SUCCESS) { + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, + "[mod_authn_dbi.c] Failed to Acquire DBI Connection"); + return AUTH_GENERAL_ERROR; + } + /* make the query to get the user's password */ if (conf->rec.isactive_field) { @@ -1047,7 +1060,8 @@ for (idx = apr_hash_first((apr_pool_t *) p, authn_dbi_config); idx; idx = apr_hash_next(idx)) { apr_hash_this(idx, (void *) &key, &len, (void *) &val); - apr_reslist_destroy(val->pool); + if(val->pool) + apr_reslist_destroy(val->pool); } dbi_shutdown(); @@ -1114,13 +1128,25 @@ for (idx = apr_hash_first(p, authn_dbi_config); idx; idx = apr_hash_next(idx)) { apr_hash_this(idx, (void *) &key, &len, (void *) &val); - apr_reslist_create(&val->pool, val->rec.conn_min, /* hard minimum */ + if(apr_reslist_create(&val->pool, val->rec.conn_min, /* hard minimum */ val->rec.conn_soft, /* soft maximum */ val->rec.conn_max, /* hard maximum */ val->rec.conn_ttl, /* Time to live -- dbi server might override/disconnect! */ safe_dbi_new_conn, /* Make a New Connection */ safe_dbi_kill_conn, /* Kill Old Connection */ - (void *) &val->rec, p); + (void *) &val->rec, p) != APR_SUCCESS) + ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, p, + "[mod_authn_dbi.c] - Creation of dbi connection pool failed for config set %s", + key); + /* XXX: If no new connection could be opened, the reslist will not + contain any resources and reslist_create will fail, giving + val->pool the value NULL and making it unusable. The configuration + set is not really recoverable in this case. For now we log this condition + and the authentication functions protect themselves against this + condition. A much better way would be to free the configuration + set completely. But to do this other changes are necessary, so for + now this is basically a workaround. This has to be fixed before + 1.0 */ apr_hash_set(authn_dbi_config, key, APR_HASH_KEY_STRING, val); } |