00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00041 #include <string.h>
00042 #include "auth_api.h"
00043 #include "../../dprint.h"
00044 #include "../../parser/digest/digest.h"
00045 #include "../../sr_module.h"
00046
00047
00048
00049
00050
00051
00052 inline int find_credentials(struct sip_msg* _m, str* _realm,
00053 hdr_types_t _hftype, struct hdr_field** _h)
00054 {
00055 struct hdr_field** hook, *ptr, *prev;
00056 hdr_flags_t hdr_flags;
00057 int res;
00058 str* r;
00059
00060
00061
00062
00063
00064
00065 switch(_hftype) {
00066 case HDR_AUTHORIZATION_T:
00067 hook = &(_m->authorization);
00068 hdr_flags=HDR_AUTHORIZATION_F;
00069 break;
00070 case HDR_PROXYAUTH_T:
00071 hook = &(_m->proxy_auth);
00072 hdr_flags=HDR_PROXYAUTH_F;
00073 break;
00074 default:
00075 hook = &(_m->authorization);
00076 hdr_flags=HDR_T2F(_hftype);
00077 break;
00078 }
00079
00080
00081
00082
00083 if (*hook == 0) {
00084
00085 if (parse_headers(_m, hdr_flags, 0) == -1) {
00086 LOG(L_ERR, "find_credentials(): Error while parsing headers\n");
00087 return -1;
00088 }
00089 }
00090
00091 ptr = *hook;
00092
00093
00094
00095
00096
00097 while(ptr) {
00098 res = parse_credentials(ptr);
00099 if (res < 0) {
00100 LOG(L_ERR, "find_credentials(): Error while parsing credentials\n");
00101 return (res == -1) ? -2 : -3;
00102 } else if (res == 0) {
00103 if (_realm->len) {
00104 r = &(((auth_body_t*)(ptr->parsed))->digest.realm);
00105
00106 if (r->len == _realm->len) {
00107 if (!strncasecmp(_realm->s, r->s, r->len)) {
00108 *_h = ptr;
00109 return 0;
00110 }
00111 }
00112 }
00113 else {
00114 *_h = ptr;
00115 return 0;
00116 }
00117
00118 }
00119
00120 prev = ptr;
00121 if (parse_headers(_m, hdr_flags, 1) == -1) {
00122 LOG(L_ERR, "find_credentials(): Error while parsing headers\n");
00123 return -4;
00124 } else {
00125 if (prev != _m->last_header) {
00126 if (_m->last_header->type == _hftype) ptr = _m->last_header;
00127 else break;
00128 } else break;
00129 }
00130 }
00131
00132
00133
00134
00135 return 1;
00136 }