diff options
-rw-r--r-- | .cvsignore | 4 | ||||
-rw-r--r-- | common/buffer.c | 63 | ||||
-rw-r--r-- | daemon/bd.c | 8 | ||||
-rw-r--r-- | daemon/ldap.c | 23 | ||||
-rw-r--r-- | daemon/mysql.c | 4 | ||||
-rw-r--r-- | daemon/pgsql.c | 2 |
6 files changed, 76 insertions, 28 deletions
@@ -19,3 +19,7 @@ stamp-* compile config.h.in *.tar.gz +*.prj +*.bak +*.pws + diff --git a/common/buffer.c b/common/buffer.c index a217298..3d427e5 100644 --- a/common/buffer.c +++ b/common/buffer.c @@ -43,6 +43,7 @@ #include <errno.h> #include <syslog.h> #include <string.h> +#include <stdio.h> /* ----------------------------------------------------------------------- * Memory Buffer @@ -74,6 +75,19 @@ typedef struct ha_buffer_internal } internal_t; +#ifdef BUF_DEBUG +void buffer_dump(ha_buffer_t* buf) +{ + internal_t* itl; + int i = 0; + + fprintf(stderr, "Buffer DUMP ---------------------------\n"); + for(itl = buf->_ft; itl; itl = itl->next, i++) + fprintf(stderr, "itl %d: 0x%08X bytes\n", i, itl->end - (char*)itl); + fprintf(stderr, "---------------------------------------\n"); +} +#endif /* BUF_DEBUG */ + void buffer_bump(ha_buffer_t* buf, int count) { int allocated; @@ -85,6 +99,7 @@ void buffer_bump(ha_buffer_t* buf, int count) return; ASSERT(BUF_DELTA < BUF_INITIAL); + ASSERT(buf->_dt->next == NULL); /* Handle this common case first for efficiency */ if(buf->_rp + (count + BUF_DELTA) < buf->_dt->end) @@ -94,6 +109,10 @@ void buffer_bump(ha_buffer_t* buf, int count) if(BUF_IN_JOIN(buf) && (buf->_rp + count < buf->_dt->end)) return; +#ifdef BUF_DEBUG + buffer_dump (buf); +#endif + /* Okay now we know we have to extend */ allocated = buf->_dt->end - (char*)(buf->_dt); ASSERT(allocated > 0 && (allocated % BUF_INITIAL) == 0); @@ -133,7 +152,7 @@ void buffer_bump(ha_buffer_t* buf, int count) /* Copy the memory and blank out old */ memcpy(beg, buf->_pp, diff); #ifdef _DEBUG - FILL_BETWEEN(buf->_pp, buf->_rp, 0xDD); + FILL_BETWEEN(buf->_pp, buf->_rp, 0xCD); #endif buf->_pp = beg; @@ -165,27 +184,47 @@ void ha_bufinit(ha_buffer_t* buf) FILL_BETWEEN(INTERNAL_DATA(buf->_ft), buf->_ft->end, 0xCD); #endif - ha_bufreset(buf); - } + buf->_dt = buf->_ft; + ha_bufreset(buf); + } } void ha_bufreset(ha_buffer_t* buf) { -#ifdef _DEBUG - internal_t* intl; -#endif + internal_t* itl; + internal_t* next; ASSERT(buf); ASSERT(buf->_ft); + if(ha_buferr(buf)) + return; + + /* We keep the last buffer, and free the rest */ + itl = buf->_ft; + buf->_ft = buf->_dt; + buf->_rp = buf->_pp = (char*)INTERNAL_DATA(buf->_ft); + +#ifdef BUF_DEBUG + fprintf(stderr, "RESET BUFFER: %d\n", buf->_ft->end - (char*)buf->_ft); +#endif + + for( ; itl != buf->_ft; itl = next) + { + ASSERT(itl != NULL); + next = itl->next; #ifdef _DEBUG - /* Go through all the buffers and set them to 0xCD */ - for(intl = buf->_ft; intl; intl = intl->next) - FILL_BETWEEN(INTERNAL_DATA(intl), intl->end, 0xCD); + FILL_BETWEEN(INTERNAL_DATA(itl), itl->end, 0xDD); +#endif +#ifdef BUF_DEBUG + fprintf(stderr, "FREEING: %d\n", itl->end - (char*)itl); #endif + free(itl); + } - buf->_dt = buf->_ft; - buf->_rp = buf->_pp = (char*)INTERNAL_DATA(buf->_ft); +#ifdef _DEBUG + FILL_BETWEEN(INTERNAL_DATA(buf->_ft), buf->_ft->end, 0xCD); +#endif } void ha_buffree(ha_buffer_t* buf) @@ -199,7 +238,9 @@ void ha_buffree(ha_buffer_t* buf) for(intl = buf->_ft; intl; intl = next) { next = intl->next; +#ifdef _DEBUG FILL_BETWEEN(INTERNAL_DATA(intl), intl->end, 0xDD); +#endif free(intl); } diff --git a/daemon/bd.c b/daemon/bd.c index 09dc45f..cb4f2cf 100644 --- a/daemon/bd.c +++ b/daemon/bd.c @@ -140,7 +140,7 @@ static int save_cached_digest(bd_context_t* ctx, ha_context_t* c, if(!r) { - ha_messagex(NULL, LOG_CRIT, "out of memory"); + ha_memerr(NULL); return HA_CRITERROR; } @@ -168,7 +168,7 @@ static int add_cached_basic(bd_context_t* ctx, ha_context_t* c, if(!r) { - ha_messagex(NULL, LOG_CRIT, "out of memory"); + ha_memerr(NULL); return HA_CRITERROR; } @@ -183,7 +183,7 @@ digest_record_t* make_digest_rec(unsigned char* nonce, const char* user) if(!rec) { - ha_messagex(NULL, LOG_CRIT, "out of memory"); + ha_memerr(NULL); return NULL; } @@ -569,7 +569,7 @@ int bd_init(ha_context_t* context) /* The cache for digest records and basic */ if(!(ctx->cache = hsh_create(MD5_LEN))) { - ha_messagex(NULL, LOG_CRIT, "out of memory"); + ha_memerr(NULL); return HA_CRITERROR; } diff --git a/daemon/ldap.c b/daemon/ldap.c index 946e5ed..2c8f915 100644 --- a/daemon/ldap.c +++ b/daemon/ldap.c @@ -145,7 +145,7 @@ static int report_ldap(const ha_request_t* rq, const char* msg, int code) switch(code) { case LDAP_NO_MEMORY: - ha_messagex(NULL, LOG_CRIT, "out of memory"); + ha_memerr(NULL); return HA_CRITERROR; default: @@ -656,7 +656,7 @@ static int validate_digest(ha_request_t* rq, const char* user, digest_context_t* LDAP* ld = NULL; /* freed in finally */ LDAPMessage* results = NULL; /* freed in finally */ LDAPMessage* entry = NULL; /* no need to free */ - struct berval** ha1s = NULL; /* freed manually */ + struct berval** ha1s = NULL; /* freed in finally */ const char** pws = NULL; /* freed in finally */ int ret = HA_FALSE; const char* dn = NULL; @@ -696,10 +696,11 @@ static int validate_digest(ha_request_t* rq, const char* user, digest_context_t* if(ha1s && *ha1s) { int foundinvalid = 0; + struct berval** h = NULL; - while(*ha1s) - { - r = parse_ldap_ha1(rq, *ha1s, dg->ha1); + for(h = ha1s; *h; ++h) + { + r = parse_ldap_ha1(rq, *h, dg->ha1); if(r == HA_FALSE) { @@ -719,8 +720,6 @@ static int validate_digest(ha_request_t* rq, const char* user, digest_context_t* else if(r < 0) RETURN(r); - - ha1s++; } if(foundinvalid) @@ -732,18 +731,22 @@ static int validate_digest(ha_request_t* rq, const char* user, digest_context_t* if(pws && *pws) { + const char** p = pws; + /* Find a cleartext password */ - while((pws = find_cleartext_password(rq->buf, pws))) + while((p = find_cleartext_password(rq->buf, p))) { foundany = 1; - digest_makeha1(dg->ha1, user, rq->context->realm, *pws); + digest_makeha1(dg->ha1, user, rq->context->realm, *p); /* Run the actual check */ ret = digest_complete_check(dg, rq->buf); if(ret != HA_FALSE) RETURN(ret); + + p++; } } @@ -1026,7 +1029,7 @@ int ldap_inithand(ha_context_t* context) ctx->pool = (LDAP**)malloc(sizeof(LDAP*) * ctx->ldap_max); if(!ctx->pool) { - ha_messagex(NULL, LOG_CRIT, "out of memory"); + ha_memerr(NULL); return HA_CRITERROR; } diff --git a/daemon/mysql.c b/daemon/mysql.c index d3f3271..091a607 100644 --- a/daemon/mysql.c +++ b/daemon/mysql.c @@ -315,7 +315,7 @@ static MYSQL* get_mysql_connection(const ha_request_t* rq, mysql_context_t* ctx) my = mysql_init(NULL); if(!my) { - ha_messagex(rq, LOG_ERR, "out of memory"); + ha_memerr(rq); return NULL; } @@ -762,7 +762,7 @@ int mysql_initialize(ha_context_t* context) ctx->pool = (MYSQL**)malloc(sizeof(MYSQL*) * ctx->mysql_max); if(!ctx->pool) { - ha_messagex(NULL, LOG_CRIT, "out of memory"); + ha_memerr(NULL); return HA_CRITERROR; } diff --git a/daemon/pgsql.c b/daemon/pgsql.c index 1870049..13ecd85 100644 --- a/daemon/pgsql.c +++ b/daemon/pgsql.c @@ -799,7 +799,7 @@ int pgsql_init(ha_context_t* context) ctx->pool = (PGconn**)malloc(sizeof(PGconn*) * ctx->pgsql_max); if(!ctx->pool) { - ha_messagex(NULL, LOG_CRIT, "out of memory"); + ha_memerr(NULL); return HA_CRITERROR; } |