Browse Source

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.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
d37f82509f
1 changed files with 16 additions and 1 deletions
  1. 16
    1
      src/crypto/chap.c

+ 16
- 1
src/crypto/chap.c View File

@@ -51,10 +51,15 @@ int chap_init ( struct chap_challenge *chap,
51 51
 	assert ( chap->digest_context == NULL );
52 52
 	assert ( chap->response == NULL );
53 53
 
54
+	DBG ( "CHAP %p initialising with %s digest\n", chap, digest->name );
55
+
54 56
 	state_len = ( digest->context_len + digest->digest_len );
55 57
 	state = malloc ( state_len );
56
-	if ( ! state )
58
+	if ( ! state ) {
59
+		DBG ( "CHAP %p could not allocate %d bytes for state\n",
60
+		      chap, state_len );
57 61
 		return -ENOMEM;
62
+	}
58 63
 	
59 64
 	chap->digest = digest;
60 65
 	chap->digest_context = state;
@@ -76,6 +81,9 @@ void chap_update ( struct chap_challenge *chap, const void *data,
76 81
 	assert ( chap->digest != NULL );
77 82
 	assert ( chap->digest_context != NULL );
78 83
 
84
+	if ( ! chap->digest )
85
+		return;
86
+
79 87
 	chap->digest->update ( chap->digest_context, data, len );
80 88
 }
81 89
 
@@ -92,6 +100,11 @@ void chap_respond ( struct chap_challenge *chap ) {
92 100
 	assert ( chap->digest_context != NULL );
93 101
 	assert ( chap->response != NULL );
94 102
 
103
+	DBG ( "CHAP %p responding to challenge\n", chap );
104
+
105
+	if ( ! chap->digest )
106
+		return;
107
+
95 108
 	chap->digest->finish ( chap->digest_context, chap->response );
96 109
 }
97 110
 
@@ -103,6 +116,8 @@ void chap_respond ( struct chap_challenge *chap ) {
103 116
 void chap_finish ( struct chap_challenge *chap ) {
104 117
 	void *state = chap->digest_context;
105 118
 
119
+	DBG ( "CHAP %p finished\n", chap );
120
+
106 121
 	free ( state );
107 122
 	memset ( chap, 0, sizeof ( *chap ) );
108 123
 }

Loading…
Cancel
Save