Browse code

lib/ims: When getting IMPI, only check check realm credentials if a realm is passed in

Jason Penton authored on 08/08/2014 06:33:56
Showing 1 changed files
... ...
@@ -122,23 +122,32 @@ str cscf_get_private_identity(struct sip_msg *msg, str realm)
122 122
 {
123 123
 	str pi={0,0};
124 124
 	struct hdr_field* h=0;
125
-	int ret,i;
125
+	int ret,i,res;
126 126
 
127 127
 	if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
128 128
 		return pi;
129 129
 	}
130
-
130
+        
131
+        h = msg->authorization;
131 132
 	if (!msg->authorization){
132 133
 		goto fallback;
133 134
 	}
135
+        
136
+        if (realm.len && realm.s) {
137
+            ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
138
+            if (ret < 0) {
139
+                    goto fallback;
140
+            } else 
141
+                    if (ret > 0) {
142
+                            goto fallback;
143
+                    }
144
+        }
134 145
 
135
-	ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
136
-	if (ret < 0) {
137
-		goto fallback;
138
-	} else 
139
-		if (ret > 0) {
140
-			goto fallback;
141
-		}
146
+	res = parse_credentials(h);
147
+        if (res != 0) {
148
+                LOG(L_ERR, "Error while parsing credentials\n");
149
+                return pi;
150
+        }
142 151
 
143 152
 	if (h) pi=((auth_body_t*)h->parsed)->digest.username.whole;
144 153
 
... ...
@@ -156,6 +165,45 @@ str cscf_get_private_identity(struct sip_msg *msg, str realm)
156 165
 	return pi;	
157 166
 }
158 167
 
168
+/**
169
+ * Returns the Private Identity extracted from the Authorization header.
170
+ * If none found there takes the SIP URI in To without the "sip:" prefix
171
+ * \todo - remove the fallback case to the To header
172
+ * @param msg - the SIP message
173
+ * @param realm - the realm to match in an Authorization header
174
+ * @returns the str containing the private id, no mem dup
175
+ */
176
+str cscf_get_private_identity_no_realm(struct sip_msg *msg, str realm)
177
+{
178
+	str pi={0,0};
179
+	struct hdr_field* h=0;
180
+	int ret,i;
181
+
182
+	if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
183
+		return pi;
184
+	}
185
+
186
+	if (!msg->authorization){
187
+		goto fallback;
188
+	}
189
+
190
+        h = msg->authorization;
191
+        if (h) pi=((auth_body_t*)h->parsed)->digest.username.whole;
192
+
193
+	goto done;
194
+
195
+	fallback:
196
+	pi = cscf_get_public_identity(msg);
197
+	if (pi.len>4&&strncasecmp(pi.s,"sip:",4)==0) {pi.s+=4;pi.len-=4;}
198
+	for(i=0;i<pi.len;i++)
199
+		if (pi.s[i]==';') {
200
+			pi.len=i;
201
+			break;
202
+		}
203
+	done:
204
+	return pi;	
205
+}
206
+
159 207
 /**
160 208
  * Returns the Public Identity extracted from the To header
161 209
  * @param msg - the SIP message