| 442 | } |
| 443 | |
| 444 | static inline int pv_authorize(struct sip_msg* msg, str *domain, |
| 445 | hdr_types_t hftype) |
| 446 | { |
| 447 | HASHHEX ha1; |
| 448 | int res; |
| 449 | struct hdr_field* h; |
| 450 | auth_body_t* cred; |
| 451 | str msg_body; |
| 452 | auth_result_t ret; |
| 453 | |
| 454 | if (domain->len==0) |
| 455 | domain->s = 0; |
| 456 | |
| 457 | ret = pre_auth(msg, domain, hftype, &h, 0); |
| 458 | |
| 459 | if (ret != DO_AUTHORIZATION) |
| 460 | return ret; |
| 461 | |
| 462 | cred = (auth_body_t*)h->parsed; |
| 463 | |
| 464 | res = auth_get_ha1(msg, &cred->digest, domain, &ha1); |
| 465 | if (res < 0) { |
| 466 | /* Error */ |
| 467 | if (sigb.reply(msg, 500, &auth_500_err, NULL) == -1) |
| 468 | LM_ERR("failed to send 500 reply\n"); |
| 469 | |
| 470 | return ERROR; |
| 471 | } else if (res > 0) { |
| 472 | /* Username not found */ |
| 473 | return USER_UNKNOWN; |
| 474 | } |
| 475 | |
| 476 | if (cred->digest.qop.qop_parsed == QOP_AUTHINT_D && |
| 477 | get_body(msg, &msg_body) < 0) { |
| 478 | LM_ERR("Failed to get body of SIP message\n"); |
| 479 | return ERROR; |
| 480 | } |
| 481 | |
| 482 | /* Recalculate response, it must be same to authorize successfully */ |
| 483 | if (!check_response(&(cred->digest),&msg->first_line.u.request.method, |
| 484 | &msg_body, &ha1)) |
| 485 | { |
| 486 | return post_auth(msg, h); |
| 487 | } |
| 488 | return INVALID_PASSWORD; |
| 489 | } |
| 490 | |
| 491 | |
| 492 | int pv_proxy_authorize(struct sip_msg* msg, str* realm) |
no test coverage detected