From d37f82509fcfbbaf56ed267aa4f77a2e66c9ff74 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 21 Nov 2006 16:14:17 +0000 Subject: Added debug statements. Don't crash when called on an uninitialised chap structure; this allows us to avoid extra checks within iscsi.c to make sure that we receive the CHAP_XXX keys in a sensible order. --- src/crypto/chap.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/crypto/chap.c') diff --git a/src/crypto/chap.c b/src/crypto/chap.c index cbfef2d9..6064a30a 100644 --- a/src/crypto/chap.c +++ b/src/crypto/chap.c @@ -51,10 +51,15 @@ int chap_init ( struct chap_challenge *chap, assert ( chap->digest_context == NULL ); assert ( chap->response == NULL ); + DBG ( "CHAP %p initialising with %s digest\n", chap, digest->name ); + state_len = ( digest->context_len + digest->digest_len ); state = malloc ( state_len ); - if ( ! state ) + if ( ! state ) { + DBG ( "CHAP %p could not allocate %d bytes for state\n", + chap, state_len ); return -ENOMEM; + } chap->digest = digest; chap->digest_context = state; @@ -76,6 +81,9 @@ void chap_update ( struct chap_challenge *chap, const void *data, assert ( chap->digest != NULL ); assert ( chap->digest_context != NULL ); + if ( ! chap->digest ) + return; + chap->digest->update ( chap->digest_context, data, len ); } @@ -92,6 +100,11 @@ void chap_respond ( struct chap_challenge *chap ) { assert ( chap->digest_context != NULL ); assert ( chap->response != NULL ); + DBG ( "CHAP %p responding to challenge\n", chap ); + + if ( ! chap->digest ) + return; + chap->digest->finish ( chap->digest_context, chap->response ); } @@ -103,6 +116,8 @@ void chap_respond ( struct chap_challenge *chap ) { void chap_finish ( struct chap_challenge *chap ) { void *state = chap->digest_context; + DBG ( "CHAP %p finished\n", chap ); + free ( state ); memset ( chap, 0, sizeof ( *chap ) ); } -- cgit v1.2.3-55-g7522