| 369 | } |
| 370 | |
| 371 | static inline int auth_get_ha1(struct sip_msg *msg, dig_cred_t* digest, |
| 372 | str* _domain, HASHHEX* _ha1) |
| 373 | { |
| 374 | pv_value_t sval; |
| 375 | struct username* _username = &digest->username; |
| 376 | |
| 377 | /* get username from PV */ |
| 378 | memset(&sval, 0, sizeof(pv_value_t)); |
| 379 | if(pv_get_spec_value(msg, &user_spec, &sval)==0) |
| 380 | { |
| 381 | if(sval.flags==PV_VAL_NONE || (sval.flags&PV_VAL_NULL) |
| 382 | || (sval.flags&PV_VAL_EMPTY) || (!(sval.flags&PV_VAL_STR))) |
| 383 | { |
| 384 | pv_value_destroy(&sval); |
| 385 | return -1; |
| 386 | } |
| 387 | if(sval.rs.len!= _username->whole.len |
| 388 | || strncasecmp(sval.rs.s, _username->whole.s, sval.rs.len)) |
| 389 | { |
| 390 | LM_DBG("username mismatch [%.*s] [%.*s]\n", |
| 391 | _username->whole.len, _username->whole.s, sval.rs.len, sval.rs.s); |
| 392 | pv_value_destroy(&sval); |
| 393 | return 1; |
| 394 | } |
| 395 | } else { |
| 396 | if (!user_spec.type) |
| 397 | LM_ERR("before calling pv_xxx_authorize(), you MUST first define" |
| 398 | " the 'username_spec' modparam\n"); |
| 399 | return -1; |
| 400 | } |
| 401 | /* get password from PV */ |
| 402 | memset(&sval, 0, sizeof(pv_value_t)); |
| 403 | if(pv_get_spec_value(msg, &passwd_spec, &sval)==0) |
| 404 | { |
| 405 | if(sval.flags==PV_VAL_NONE || (sval.flags&PV_VAL_NULL) |
| 406 | || (sval.flags&PV_VAL_EMPTY) || (!(sval.flags&PV_VAL_STR))) |
| 407 | { |
| 408 | pv_value_destroy(&sval); |
| 409 | return -1; |
| 410 | } |
| 411 | } else { |
| 412 | if (!passwd_spec.type) |
| 413 | LM_ERR("before calling pv_xxx_authorize(), you MUST first define" |
| 414 | " the 'password_spec' modparam\n"); |
| 415 | return -1; |
| 416 | } |
| 417 | const struct digest_auth_calc *digest_calc; |
| 418 | digest_calc = get_digest_calc(digest->alg.alg_parsed); |
| 419 | if (digest_calc == NULL) { |
| 420 | LM_ERR("digest algorithm (%d) unsupported\n", digest->alg.alg_parsed); |
| 421 | return -1; |
| 422 | } |
| 423 | if (auth_calc_ha1) { |
| 424 | struct digest_auth_credential creds = {.realm = *_domain, |
| 425 | .user = _username->whole, .passwd = sval.rs}; |
| 426 | /* Only plaintext passwords are stored in database, |
| 427 | * we have to calculate HA1 */ |
| 428 | if (digest_calc->HA1(&creds, _ha1) != 0) |
no test coverage detected