|
@@ -147,88 +147,6 @@ int get_realm(struct sip_msg* m, int hftype, struct sip_uri* u)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-/* Find credentials with given realm in a SIP message header */
|
|
|
-int find_credentials(struct sip_msg* _m, str* _realm, int _hftype,
|
|
|
- struct hdr_field** _h)
|
|
|
-{
|
|
|
- struct hdr_field** hook, *ptr, *prev;
|
|
|
- int res;
|
|
|
- hdr_flags_t hdr_flags;
|
|
|
- str* r;
|
|
|
-
|
|
|
- switch(_hftype)
|
|
|
- {
|
|
|
- case HDR_AUTHORIZATION_T:
|
|
|
- hook = &(_m->authorization);
|
|
|
- hdr_flags=HDR_AUTHORIZATION_F;
|
|
|
- break;
|
|
|
- case HDR_PROXYAUTH_T:
|
|
|
- hook = &(_m->proxy_auth);
|
|
|
- hdr_flags=HDR_PROXYAUTH_F;
|
|
|
- break;
|
|
|
- default:
|
|
|
- hook = &(_m->authorization);
|
|
|
- hdr_flags=HDR_T2F(_hftype);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- /* If the credentials haven't been parsed yet, do it now */
|
|
|
- if (*hook == 0)
|
|
|
- if (parse_headers(_m, hdr_flags, 0) == -1)
|
|
|
- {
|
|
|
- LM_ERR("failed to parse headers\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- ptr = *hook;
|
|
|
-
|
|
|
- /* Iterate through the credentials of the message to find
|
|
|
- credentials with given realm
|
|
|
- */
|
|
|
- while(ptr)
|
|
|
- {
|
|
|
- res = parse_credentials(ptr);
|
|
|
- if (res < 0)
|
|
|
- {
|
|
|
- LM_ERR("failed to parse credentials\n");
|
|
|
- return (res == -1) ? -2 : -3;
|
|
|
- }
|
|
|
- else
|
|
|
- if (res == 0)
|
|
|
- {
|
|
|
- r = &(((auth_body_t*)(ptr->parsed))->digest.realm);
|
|
|
-
|
|
|
- if (r->len == _realm->len)
|
|
|
- {
|
|
|
- if (!strncasecmp(_realm->s, r->s, r->len))
|
|
|
- {
|
|
|
- *_h = ptr;
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- prev = ptr;
|
|
|
- if (parse_headers(_m, hdr_flags, 1) == -1)
|
|
|
- {
|
|
|
- LM_ERR("failed to parse headers\n");
|
|
|
- return -4;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (prev != _m->last_header)
|
|
|
- {
|
|
|
- if (_m->last_header->type == _hftype) ptr = _m->last_header;
|
|
|
- else break;
|
|
|
- }
|
|
|
- else break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /* Credentials with given realm not found */
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
auth_result_t diam_pre_auth(struct sip_msg* _m, str* _realm, int _hftype,
|
|
|
struct hdr_field** _h)
|