| 219 | |
| 220 | |
| 221 | int getAuthParameter(const char *name, const char *header, char *result, int len) |
| 222 | { |
| 223 | char *start, *end; |
| 224 | |
| 225 | start = stristr(header, name); |
| 226 | while (start) { |
| 227 | // Ensure that the preceding character is "," or whitespace - this |
| 228 | // stops us finding "cnonce" when we search for "nonce". |
| 229 | char preceding_char = start[-1]; |
| 230 | if ((preceding_char == ',') |
| 231 | || isspace(preceding_char)) { |
| 232 | break; |
| 233 | } |
| 234 | start = stristr(start+1, name); |
| 235 | } |
| 236 | |
| 237 | if (!start) { |
| 238 | result[0] = '\0'; |
| 239 | return 0; |
| 240 | } |
| 241 | start += strlen(name); |
| 242 | if (*start++ != '=') { |
| 243 | return getAuthParameter(name, start, result, len); |
| 244 | } |
| 245 | if (*start == '"') { |
| 246 | start++; |
| 247 | end = start; |
| 248 | while (*end != '"' && *end) { |
| 249 | end++; |
| 250 | } |
| 251 | } else { |
| 252 | end = start + strcspn(start, " ,\"\r\n"); |
| 253 | } |
| 254 | |
| 255 | if (end - start >= len) { |
| 256 | strncpy(result, start, len - 1); |
| 257 | result[len - 1] = '\0'; |
| 258 | } else { |
| 259 | strncpy(result, start, end - start); |
| 260 | result[end - start] = '\0'; |
| 261 | } |
| 262 | |
| 263 | return end - start; |
| 264 | } |
| 265 | |
| 266 | static int createAuthResponseMD5( |
| 267 | const char* user, const char* password, int password_len, |
no test coverage detected