MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / find_credentials

Function find_credentials

modules/auth/api.c:64–143  ·  view source on GitHub ↗

* Find credentials with given realm in a SIP message header */

Source from the content-addressed store, hash-verified

62 * Find credentials with given realm in a SIP message header
63 */
64static inline int find_credentials(struct sip_msg* _m, str* _realm,
65 hdr_types_t _hftype, struct hdr_field** _h)
66{
67 struct hdr_field** hook, *ptr, *prev;
68 hdr_flags_t hdr_flags;
69 int res;
70 str* r;
71
72 /*
73 * Determine if we should use WWW-Authorization or
74 * Proxy-Authorization header fields, this parameter
75 * is set in www_authorize and proxy_authorize
76 */
77 switch(_hftype) {
78 case HDR_AUTHORIZATION_T:
79 hook = &(_m->authorization);
80 hdr_flags=HDR_AUTHORIZATION_F;
81 break;
82 case HDR_PROXYAUTH_T:
83 hook = &(_m->proxy_auth);
84 hdr_flags=HDR_PROXYAUTH_F;
85 break;
86 default:
87 hook = &(_m->authorization);
88 hdr_flags=HDR_T2F(_hftype);
89 break;
90 }
91
92 /*
93 * If the credentials haven't been parsed yet, do it now
94 */
95 if (*hook == 0) {
96 /* No credentials parsed yet */
97 if (parse_headers(_m, hdr_flags, 0) == -1) {
98 LM_ERR("failed to parse headers\n");
99 return -1;
100 }
101 }
102
103 ptr = *hook;
104
105 /*
106 * Iterate through the credentials in the message and
107 * find credentials with given realm
108 */
109 while(ptr) {
110 res = parse_credentials(ptr);
111 if (res < 0) {
112 LM_ERR("failed to parse credentials\n");
113 return (res == -1) ? -2 : -3;
114 } else if (res == 0) {
115 auth_body_t *abp = (auth_body_t *)(ptr->parsed);
116 dig_cred_t *dcp = &(abp->digest);
117 r = &(abp->digest.realm);
118 if (r->len == _realm->len && get_digest_calc(dcp->alg.alg_parsed) != NULL) {
119 if (!strncasecmp(_realm->s, r->s, r->len)) {
120 *_h = ptr;
121 return 0;

Callers 1

pre_authFunction · 0.85

Calls 2

parse_credentialsFunction · 0.85
get_digest_calcFunction · 0.85

Tested by

no test coverage detected