From 570c17aa3bb6a39030ebefc5618f0c3fa8cf0089 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sun, 25 Apr 2004 05:50:07 +0000 Subject: Debugging of simple authentication handler --- daemon/digest.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'daemon/digest.c') diff --git a/daemon/digest.c b/daemon/digest.c index 79b4ff3..099ca49 100644 --- a/daemon/digest.c +++ b/daemon/digest.c @@ -87,16 +87,13 @@ digest_record_t* digest_makerec(unsigned char* nonce, const char* user) return rec; } -const char* digest_challenge(ha_buffer_t* buf, unsigned char* nonce, +const char* digest_challenge(ha_buffer_t* buf, const char* nonce_str, const char* realm, const char* domains, int stale) { - ASSERT(buf && realm && nonce); + ASSERT(buf && realm && nonce_str); - ha_bufmcat(buf, HA_PREFIX_DIGEST, " realm=\"", realm, "\", nonce=\"", NULL); - ha_bufjoin(buf); - ha_bufenc64(buf, nonce, DIGEST_NONCE_LEN); - ha_bufjoin(buf); - ha_bufmcat(buf, "\", qop=\"auth\", algorithm=\"MD5\"", NULL); + ha_bufmcat(buf, HA_PREFIX_DIGEST, " realm=\"", realm, "\", nonce=\"", + nonce_str, "\", qop=\"auth\", algorithm=\"MD5\"", NULL); if(domains) { @@ -143,7 +140,7 @@ int digest_parse(char* header, ha_buffer_t* buf, digest_header_t* rec, if(!header) return HA_ERROR; - memset(rec, 0, sizeof(rec)); + memset(rec, 0, sizeof(*rec)); while(header[0]) { @@ -178,8 +175,6 @@ int digest_parse(char* header, ha_buffer_t* buf, digest_header_t* rec, if(next == '=') { - header++; - while(header[0] && isspace(header[0])) header++; @@ -191,6 +186,7 @@ int digest_parse(char* header, ha_buffer_t* buf, digest_header_t* rec, while(header[0] && header[0] != '\"') header++; + next = header[0]; header[0] = 0; header++; } @@ -202,15 +198,19 @@ int digest_parse(char* header, ha_buffer_t* buf, digest_header_t* rec, while(header[0] && header[0] != ',' && !isspace(header[0])) header++; + next = header[0]; header[0] = 0; header++; } - while(header[0] && header[0] != ',') - header++; + if(next != ',') + { + while(header[0] && header[0] != ',') + header++; - if(header[0]) - header++; + if(header[0]) + header++; + } if(!strcasecmp(key, "username")) rec->username = value; @@ -320,7 +320,7 @@ int digest_check(const char* realm, const char* method, const char* uri, char* e; long nc = strtol(dg->nc, &e, 10); - if(e != (dg->nc + strlen(e)) || nc != rec->nc) + if(*e || nc != rec->nc) { ha_messagex(LOG_WARNING, "digest response has invalid nc value: %s", dg->nc); @@ -455,6 +455,9 @@ const char* digest_respond(ha_buffer_t* buf, digest_header_t* dg, ASSERT(buf && dg && rec); + /* This makes a new buffer */ + ha_bufcpy(buf, ""); + if(next) { nextnonce = ha_bufenc64(buf, next, DIGEST_NONCE_LEN); @@ -464,7 +467,7 @@ const char* digest_respond(ha_buffer_t* buf, digest_header_t* dg, } /* For older clients RFC 2069 */ - if(dg->qop) + if(!dg->qop) { if(nextnonce) ha_bufmcat(buf, "nextnonce=\"", nextnonce, "\"", NULL); -- cgit v1.2.3