summaryrefslogtreecommitdiff
path: root/daemon/digest.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/digest.c')
-rw-r--r--daemon/digest.c35
1 files changed, 19 insertions, 16 deletions
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);