--------------------- PatchSet 10433 Date: 2008/01/25 09:40:47 Author: adri Branch: s27_adri Tag: (none) Log: Use a temporary C string to make the digest code work (for now). I'll revisit this later and rewrite it to use string iterators. Members: src/auth/digest/auth_digest.c:1.24.10.3->1.24.10.4 Index: squid/src/auth/digest/auth_digest.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/auth/digest/auth_digest.c,v retrieving revision 1.24.10.3 retrieving revision 1.24.10.4 diff -u -r1.24.10.3 -r1.24.10.4 --- squid/src/auth/digest/auth_digest.c 25 Jan 2008 04:15:39 -0000 1.24.10.3 +++ squid/src/auth/digest/auth_digest.c 25 Jan 2008 09:40:47 -0000 1.24.10.4 @@ -1136,13 +1136,18 @@ * Auth_user structure. */ +/* + * XXX this function does too much copying internally and should be + * XXX simplified later on! Part of this is my fault; as I really + * XXX can't bring myself to rewrite all of this for now --adrian + */ static void authenticateDigestDecodeAuth(auth_user_request_t * auth_user_request, String proxy_auth) { String temp; const char *item; const char *p; - const char *pos = NULL; + int pos = 0; char *username = NULL; digest_nonce_h *nonce; int ilen; @@ -1150,6 +1155,8 @@ digest_user_h *digest_user; auth_user_t *auth_user; dlink_node *node; + const char *ti = NULL; + int pa; debug(29, 9) ("authenticateDigestDecodeAuth: beginning\n"); assert(auth_user_request != NULL); @@ -1157,18 +1164,20 @@ digest_request = authDigestRequestNew(); /* trim DIGEST from string */ - while (xisgraph(*proxy_auth)) - proxy_auth++; + pa = 0; + while (pa < strLen2(proxy_auth) && xisgraph(strGetPos(proxy_auth, pa))) + pa++; /* Trim leading whitespace before decoding */ - while (xisspace(*proxy_auth)) - proxy_auth++; + while (pa < strLen2(proxy_auth) && xisspace(strGetPos(proxy_auth, pa))) + pa++; - stringInit(&temp, proxy_auth); + temp = strSubStr(proxy_auth, pa, -1); while (strListGetItem(&temp, ',', &item, &ilen, &pos)) { - if ((p = strchr(item, '=')) && (p - item < ilen)) - ilen = p++ - item; - if (!strncmp(item, "username", ilen)) { + ti = xstrndup(item, ilen); + if ((p = strchr(ti, '=')) && (p - item < ilen)) + ilen = p++ - ti; + if (!strncmp(ti, "username", ilen)) { /* white space */ while (xisspace(*p)) p++; @@ -1176,7 +1185,7 @@ p++; username = xstrndup(p, strchr(p, '"') + 1 - p); debug(29, 9) ("authDigestDecodeAuth: Found Username '%s'\n", username); - } else if (!strncmp(item, "realm", ilen)) { + } else if (!strncmp(ti, "realm", ilen)) { /* white space */ while (xisspace(*p)) p++; @@ -1184,7 +1193,7 @@ p++; digest_request->realm = xstrndup(p, strchr(p, '"') + 1 - p); debug(29, 9) ("authDigestDecodeAuth: Found realm '%s'\n", digest_request->realm); - } else if (!strncmp(item, "qop", ilen)) { + } else if (!strncmp(ti, "qop", ilen)) { /* white space */ while (xisspace(*p)) p++; @@ -1193,7 +1202,7 @@ p++; digest_request->qop = xstrndup(p, strcspn(p, "\" \t\r\n()<>@,;:\\/[]?={}") + 1); debug(29, 9) ("authDigestDecodeAuth: Found qop '%s'\n", digest_request->qop); - } else if (!strncmp(item, "algorithm", ilen)) { + } else if (!strncmp(ti, "algorithm", ilen)) { /* white space */ while (xisspace(*p)) p++; @@ -1202,7 +1211,7 @@ p++; digest_request->algorithm = xstrndup(p, strcspn(p, "\" \t\r\n()<>@,;:\\/[]?={}") + 1); debug(29, 9) ("authDigestDecodeAuth: Found algorithm '%s'\n", digest_request->algorithm); - } else if (!strncmp(item, "uri", ilen)) { + } else if (!strncmp(ti, "uri", ilen)) { /* white space */ while (xisspace(*p)) p++; @@ -1210,7 +1219,7 @@ p++; digest_request->uri = xstrndup(p, strchr(p, '"') + 1 - p); debug(29, 9) ("authDigestDecodeAuth: Found uri '%s'\n", digest_request->uri); - } else if (!strncmp(item, "nonce", ilen)) { + } else if (!strncmp(ti, "nonce", ilen)) { /* white space */ while (xisspace(*p)) p++; @@ -1218,13 +1227,13 @@ p++; digest_request->nonceb64 = xstrndup(p, strchr(p, '"') + 1 - p); debug(29, 9) ("authDigestDecodeAuth: Found nonce '%s'\n", digest_request->nonceb64); - } else if (!strncmp(item, "nc", ilen)) { + } else if (!strncmp(ti, "nc", ilen)) { /* white space */ while (xisspace(*p)) p++; xstrncpy(digest_request->nc, p, 9); debug(29, 9) ("authDigestDecodeAuth: Found noncecount '%s'\n", digest_request->nc); - } else if (!strncmp(item, "cnonce", ilen)) { + } else if (!strncmp(ti, "cnonce", ilen)) { /* white space */ while (xisspace(*p)) p++; @@ -1232,7 +1241,7 @@ p++; digest_request->cnonce = xstrndup(p, strchr(p, '"') + 1 - p); debug(29, 9) ("authDigestDecodeAuth: Found cnonce '%s'\n", digest_request->cnonce); - } else if (!strncmp(item, "response", ilen)) { + } else if (!strncmp(ti, "response", ilen)) { /* white space */ while (xisspace(*p)) p++; @@ -1241,10 +1250,12 @@ digest_request->response = xstrndup(p, strchr(p, '"') + 1 - p); debug(29, 9) ("authDigestDecodeAuth: Found response '%s'\n", digest_request->response); } + safe_free(ti); ti = NULL; } + if (ti) + safe_free(ti); stringClean(&temp); - /* now we validate the data given to us */ /*