Pārlūkot izejas kodu

uac: optional param for uac_auth() to specify auth mode

- if mode is set to 1, then the password is provided in ha1 format
Daniel-Constantin Mierla 5 gadi atpakaļ
vecāks
revīzija
981d787acf
3 mainītis faili ar 43 papildinājumiem un 6 dzēšanām
  1. 15 5
      src/modules/uac/auth.c
  2. 4 1
      src/modules/uac/auth.h
  3. 24 0
      src/modules/uac/uac.c

+ 15 - 5
src/modules/uac/auth.c

@@ -375,9 +375,10 @@ error:
 	return -1;
 }
 
-
-
-int uac_auth(sip_msg_t *msg)
+/**
+ *
+ */
+int uac_auth_mode(sip_msg_t *msg, int mode)
 {
 	static struct authenticate_body auth;
 	struct uac_credential *crd;
@@ -451,6 +452,10 @@ int uac_auth(sip_msg_t *msg)
 		goto error;
 	}
 
+	if(mode & UACAUTH_MODE_HA1) {
+		crd->aflags |= UAC_FLCRED_HA1;
+	}
+
 	/* do authentication */
 	do_uac_auth( &msg->first_line.u.request.method,
 			&t->uac[branch].uri, crd, &auth, response);
@@ -489,5 +494,10 @@ error:
 	return -1;
 }
 
-
-
+/**
+ *
+ */
+int uac_auth(sip_msg_t *msg)
+{
+	return uac_auth_mode(msg, 0);
+}

+ 4 - 1
src/modules/uac/auth.h

@@ -47,6 +47,8 @@ typedef struct authenticate_body {
 	str *cnonce;
 } uac_authenticate_body_t;
 
+#define UACAUTH_MODE_HA1 (1<<0)
+
 #define AUTHENTICATE_MD5         (1<<0)
 #define AUTHENTICATE_MD5SESS     (1<<1)
 #define AUTHENTICATE_STALE       (1<<2)
@@ -67,7 +69,8 @@ void destroy_credentials(void);
 
 struct hdr_field *get_autenticate_hdr(struct sip_msg *rpl, int rpl_code);
 
-int uac_auth( struct sip_msg *msg);
+int uac_auth(sip_msg_t *msg);
+int uac_auth_mode(sip_msg_t *msg, int mode);
 
 void do_uac_auth(str *method, str *uri,
 		struct uac_credential *crd,

+ 24 - 0
src/modules/uac/uac.c

@@ -98,6 +98,7 @@ static int w_restore_from(struct sip_msg* msg, char* p1, char* p2);
 static int w_replace_to(struct sip_msg* msg, char* p1, char* p2);
 static int w_restore_to(struct sip_msg* msg, char* p1, char* p2);
 static int w_uac_auth(struct sip_msg* msg, char* str, char* str2);
+static int w_uac_auth_mode(struct sip_msg* msg, char* pmode, char* str2);
 static int w_uac_reg_lookup(struct sip_msg* msg, char* src, char* dst);
 static int w_uac_reg_status(struct sip_msg* msg, char* src, char* dst);
 static int w_uac_reg_request_to(struct sip_msg* msg, char* src, char* mode_s);
@@ -132,6 +133,8 @@ static cmd_export_t cmds[]={
 		REQUEST_ROUTE | BRANCH_ROUTE },
 	{"uac_restore_to",  (cmd_function)w_restore_to,  0, 0, 0, REQUEST_ROUTE },
 	{"uac_auth",	  (cmd_function)w_uac_auth,       0, 0, 0, FAILURE_ROUTE },
+	{"uac_auth_mode", (cmd_function)w_uac_auth_mode,  1,
+			fixup_igp_null, fixup_free_igp_null, FAILURE_ROUTE },
 	{"uac_req_send",  (cmd_function)w_uac_req_send,   0, 0, 0, ANY_ROUTE},
 	{"uac_reg_lookup",  (cmd_function)w_uac_reg_lookup,  2, fixup_spve_pvar,
 		fixup_free_spve_pvar, ANY_ROUTE },
@@ -615,6 +618,22 @@ static int ki_uac_auth(struct sip_msg* msg)
 	return (uac_auth(msg)==0)?1:-1;
 }
 
+static int w_uac_auth_mode(struct sip_msg* msg, char* pmode, char* str2)
+{
+	int imode = 0;
+
+	if(fixup_get_ivalue(msg, (gparam_t*)pmode, &imode)<0) {
+		LM_ERR("failed to get the mode parameter\n");
+		return -1;
+	}
+	return (uac_auth_mode(msg, imode)==0)?1:-1;
+}
+
+static int ki_uac_auth_mode(sip_msg_t* msg, int mode)
+{
+	return (uac_auth_mode(msg, mode)==0)?1:-1;
+}
+
 static int w_uac_reg_lookup(struct sip_msg* msg, char* src, char* dst)
 {
 	pv_spec_t *dpv;
@@ -757,6 +776,11 @@ static sr_kemi_t sr_kemi_uac_exports[] = {
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
+	{ str_init("uac"), str_init("uac_auth_mode"),
+		SR_KEMIP_INT, ki_uac_auth_mode,
+		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 	{ str_init("uac"), str_init("uac_req_send"),
 		SR_KEMIP_INT, ki_uac_req_send,
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,