[Mod-auth-commit] mod_authn_dbi/src mod_authn_dbi.c,1.15,1.16
Brought to you by:
firechipmunk,
honx
From: <fir...@us...> - 2004-02-08 22:44:26
|
Update of /cvsroot/mod-auth/mod_authn_dbi/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32512/src Modified Files: mod_authn_dbi.c Log Message: removed DBI_NOT_THREAD_SAFE. fixed sha1 support. Index: mod_authn_dbi.c =================================================================== RCS file: /cvsroot/mod-auth/mod_authn_dbi/src/mod_authn_dbi.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- mod_authn_dbi.c 8 Feb 2004 21:47:23 -0000 1.15 +++ mod_authn_dbi.c 8 Feb 2004 22:41:12 -0000 1.16 @@ -25,7 +25,6 @@ #include "../include/mod_authn_dbi_config.h" -#define AUTHN_DBI_CVS_ID "$Id$" #define MOD_AUTHN_DBI_VERSION VERSION #include "apr_lib.h" @@ -35,7 +34,6 @@ #include "apr_md5.h" /* for apr_password_validate */ #include "apr_sha1.h" #include "apr_reslist.h" -#include "apr_thread_mutex.h" /* to block MySQL on dbi_connect */ #include "apr_hash.h" #include "ap_provider.h" @@ -51,14 +49,6 @@ #include <dbi/dbi.h> -#ifndef DBI_NOT_THREAD_SAFE -#define DBI_NOT_THREAD_SAFE (1) -#endif - -#if DBI_NOT_THREAD_SAFE -static apr_thread_mutex_t *dbi_lock = NULL; -#endif - #define DFLT_DBI_NAME "AuthDB" #define DFLT_DBI_HOST "localhost" #define DFLT_DBI_DRIVER "mysql" @@ -128,6 +118,7 @@ CONF_DBI_CONN_TTL, CONF_DBI_OPTIONS }; + typedef struct dbi_dconfig { const char *id; @@ -192,15 +183,14 @@ dbi_conn_count++; if (DBI_HARD_MAX_CONNS > dbi_conn_count) { - ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, r, - "[mod_authn_dbi.c] Creating New DBI Server Connection"); + myres = apr_palloc(r, sizeof(*myres)); myres->conn = dbi_conn_new(driver); if (myres->conn == NULL) { ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, r, "[mod_authn_dbi.c] DBI Connection Failed. dbi_conn_new returned NULL. Insufficient memory or invalid DBD?"); - rv = !APR_SUCCESS; + rv = APR_EGENERAL; /* * modules/ssl/ssl_engine_log.c:103 * said this was okay. so i do it. @@ -212,28 +202,19 @@ dbi_conn_set_option(myres->conn, "username", user); dbi_conn_set_option(myres->conn, "password", pwd); dbi_conn_set_option(myres->conn, "dbname", name); -#if DBI_NOT_THREAD_SAFE - if (strcmp(driver, "mysql") == 0) { - apr_thread_mutex_lock(dbi_lock); - } -#endif + if (dbi_conn_connect(myres->conn) != 0) { err_num = dbi_conn_error(myres->conn, &err_str); /* Connetion Failed */ ap_log_perror(APLOG_MARK, APLOG_ERR, 0, r, "[mod_authn_dbi.c] DBI Connection to %s://%s@%s/%s Failed. Error: (%d) %s", driver, user, host, name, err_num, err_str); - rv = !APR_SUCCESS; + rv = APR_EGENERAL; } else { ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, r, "[mod_authn_dbi.c] Connection was created sucessfully"); } -#if DBI_NOT_THREAD_SAFE - if (strcmp(driver, "mysql") == 0) { - apr_thread_mutex_unlock(dbi_lock); - } -#endif } *resource = myres; } @@ -244,7 +225,7 @@ DBI_HARD_MAX_CONNS); /* we didn't create a new connection! */ dbi_conn_count--; - rv = !APR_SUCCESS; + rv = APR_EGENERAL; } return rv; } @@ -253,8 +234,7 @@ apr_pool_t * pool) { dbi_rest *res = resource; - ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, pool, - "[mod_authn_dbi.c] Disconnecting from Server"); + dbi_conn_close(res->conn); dbi_conn_count--; @@ -802,9 +782,6 @@ } else { /* XXX: what about portability!? are any special precautions needed for win32/netware/ebdic ? */ - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, - "Password format is %d", - (int) conf->rec.password_format); switch (conf->rec.password_format) { case plain: @@ -830,7 +807,7 @@ */ #ifndef SKIP_APR_PWCHECK - /* Define SKIP_APR_PWCHECK to disable this check if apr-util supports new algorithms we don't yet + /* Define SKIP_APR_PWCHECK to disable this check if apr-util supports new algorithms we don't yetSKIP_APR_PWCHECK * know about. Should be used as a workaround only since it might open the door to DoS attacks if specially * crafted entries are passed to apr_password_validate. */ @@ -839,8 +816,10 @@ c = strlen(dbi_pass); /* we do some checks to keep libc from making wrong assumptions and ourselves from segfaulting */ - if (!((c == 13) && (apr_isalnum(dbi_pass[0]) || (dbi_pass[0] == '.') || (dbi_pass[0] == '.')) && (apr_isalnum(dbi_pass[1]) || (dbi_pass[1] == '.') || (dbi_pass[1] == '.'))) && /* crypt */ - !((c == 37))) { /* not much to be done for md5, apr-util is old enough to look after itself */ + if (!((c == 13) && (apr_isalnum(dbi_pass[0]) || (dbi_pass[0] == '.') || (dbi_pass[0] == '.')) + && (apr_isalnum(dbi_pass[1]) || (dbi_pass[1] == '.') || (dbi_pass[1] == '.'))) && /* crypt */ + !((c == 37)) && /* not much to be done for md5, apr-util is old enough to look after itself */ + (0 != strncmp(dbi_pass, APR_SHA1PW_ID, strlen(APR_SHA1PW_ID)))) { /* sha1 */ ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "[mod_authn_dbi.c] Invalid Apr-format entry or unsupported format in password field of user %s in config %s", user, conf->rec.dbi_name); @@ -994,9 +973,6 @@ realm, ":", dbi_pass, NULL)); - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, - "[mod_authn_dbi.c] Query Good. Returning Hash: MD5( %s:%s:%s ) = %s", - user, realm, dbi_pass, dbi_hash); *rethash = dbi_hash; ARV = AUTH_USER_FOUND; break; @@ -1009,8 +985,8 @@ ARV = AUTH_GENERAL_ERROR; } else { - ARV = AUTH_USER_FOUND; *rethash = apr_pstrdup(r->pool, dbi_pass); + ARV = AUTH_USER_FOUND; } break; default: @@ -1075,9 +1051,6 @@ } dbi_shutdown(); -#if DBI_NOT_THREAD_SAFE - rv = apr_thread_mutex_destroy(dbi_lock); -#endif return rv; } @@ -1104,17 +1077,6 @@ } ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, p, "[mod_authn_dbi.c] Running DBI init Code"); -#if DBI_NOT_THREAD_SAFE - rv = apr_thread_mutex_create(&dbi_lock, APR_LOCK_DEFAULT, p); - ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, p, - "[mod_authn_dbi.c] DBI is running in Non-Thread Safe Mode"); - if (rv != APR_SUCCESS) { - ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, p, - "[mod_authn_dbi.c] - Failed Creating DBI thread Mutex! apr_thread_mutex_create returned: \"%d\" ", - rv); - return rv; - } -#endif if ((rval = dbi_initialize(dbi_global_config.driverdir)) > 0) { if (dbi_global_config.driverdir == NULL) { ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, p, @@ -1145,7 +1107,7 @@ "[mod_authn_dbi.c] - Initlialization of libdbi with AuthnDbiDriverDir %s failed", dbi_global_config.driverdir); } - return !APR_SUCCESS; + return APR_EDSOOPEN; } /* loop the hashed config stuff... */ @@ -1180,9 +1142,9 @@ module AP_MODULE_DECLARE_DATA authn_dbi_module = { STANDARD20_MODULE_STUFF, create_authn_dbi_dir_config, /* dir config creater */ - NULL, /* dir merger --- default is to override */ - NULL, /* server config creator */ - NULL, /* merge server config */ - authn_dbi_cmds, /* command apr_table_t */ - register_hooks /* register hooks */ + NULL, /* dir merger --- default is to override */ + NULL, /* server config creator */ + NULL, /* merge server config */ + authn_dbi_cmds, /* command apr_table_t */ + register_hooks /* register hooks */ }; |