Skip to content

Commit 590a19f

Browse files
committed
Merge branch 'auth' of https://github.com/l2dy/opensips into l2dy-auth
Some improvements: * preserve the former behavior of returning a "Username Not Found" SIP error when the "username" or "password" PVs are not populated * return an internal error when the PVs contain unexpected values and/or types (e.g. NULL or non-string) * improve coding style in pv_authorize()
2 parents b9a6292 + 96fcb5f commit 590a19f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

modules/auth/auth_mod.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static inline int auth_get_ha1(struct sip_msg *msg, struct username* _username,
382382
|| (sval.flags&PV_VAL_EMPTY) || (!(sval.flags&PV_VAL_STR)))
383383
{
384384
pv_value_destroy(&sval);
385-
return 1;
385+
return -1;
386386
}
387387
if(sval.rs.len!= _username->whole.len
388388
|| strncasecmp(sval.rs.s, _username->whole.s, sval.rs.len))
@@ -403,7 +403,7 @@ static inline int auth_get_ha1(struct sip_msg *msg, struct username* _username,
403403
|| (sval.flags&PV_VAL_EMPTY) || (!(sval.flags&PV_VAL_STR)))
404404
{
405405
pv_value_destroy(&sval);
406-
return 1;
406+
return -1;
407407
}
408408
} else {
409409
return 1;
@@ -442,14 +442,13 @@ static inline int pv_authorize(struct sip_msg* msg, str *domain,
442442
cred = (auth_body_t*)h->parsed;
443443

444444
res = auth_get_ha1(msg, &cred->digest.username, domain, ha1);
445-
if (res != 0) {
445+
if (res < 0) {
446446
/* Error */
447-
if (sigb.reply(msg, 500, &auth_500_err, NULL) == -1) {
447+
if (sigb.reply(msg, 500, &auth_500_err, NULL) == -1)
448448
LM_ERR("failed to send 500 reply\n");
449-
}
449+
450450
return ERROR;
451-
}
452-
if (res > 0) {
451+
} else if (res > 0) {
453452
/* Username not found */
454453
return USER_UNKNOWN;
455454
}

0 commit comments

Comments
 (0)