Explorar o código

modules_k/uac: skip realm matching when realm pv for uac_auth is empty or null

This can be used if the realm used by the upsteam UAS isn't known in advance.
Alex Hermann %!s(int64=13) %!d(string=hai) anos
pai
achega
0507b848d0
Modificáronse 2 ficheiros con 18 adicións e 9 borrados
  1. 12 8
      modules_k/uac/auth.c
  2. 6 1
      modules_k/uac/doc/uac_admin.xml

+ 12 - 8
modules_k/uac/auth.c

@@ -263,16 +263,20 @@ static inline struct uac_credential *get_avp_credential(struct sip_msg *msg,
 	static struct uac_credential crd;
 	pv_value_t pv_val;
 
-	if(pv_get_spec_value( msg, &auth_realm_spec, &pv_val)!=0
-	|| pv_val.flags&PV_VAL_NULL || pv_val.rs.len<=0)
-		return 0;
-	
-	crd.realm = pv_val.rs;
-	/* is it the domain we are looking for? */
-	if (realm->len!=crd.realm.len ||
-	strncmp( realm->s, crd.realm.s, realm->len)!=0 )
+	if(pv_get_spec_value( msg, &auth_realm_spec, &pv_val)!=0)
 		return 0;
 
+	if (pv_val.flags&PV_VAL_NULL || pv_val.rs.len<=0) {
+		/* if realm parameter is empty or NULL, match any realm asked for */
+		crd.realm = *realm;
+	} else {
+		crd.realm = pv_val.rs;
+		/* is it the domain we are looking for? */
+		if (realm->len!=crd.realm.len ||
+		  strncmp( realm->s, crd.realm.s, realm->len)!=0 )
+			return 0;
+	}
+
 	/* get username and password */
 	if(pv_get_spec_value( msg, &auth_username_spec, &pv_val)!=0
 	|| pv_val.flags&PV_VAL_NULL || pv_val.rs.len<=0)

+ 6 - 1
modules_k/uac/doc/uac_admin.xml

@@ -302,9 +302,14 @@ modparam("uac","credential","username:domain:password")
 		<section id="auth-realm-avp-id">
 			<title><varname>auth_realm_avp</varname> (string)</title>
 			<para>
-			The definition of an AVP that might contain the realm to be used
+			The definition of an PV that might contain the realm to be used
 			to perform authentication.
 			</para>
+			<para>
+			When the PV value is an empty string or NULL when uac_auth() is called,
+			the realm is taken from the reply and only username matching is done.
+			This can be used if the realm upstream will be using is not known in advance.
+			</para>
 			<para><emphasis>
 				If you define it, you also need to define 
 				<quote>auth_username_avp</quote>