* Check if a header field contains the same username * as digest credentials */
| 63 | * as digest credentials |
| 64 | */ |
| 65 | static inline int check_username(struct sip_msg* _m, str* _table, |
| 66 | struct sip_uri *_uri) |
| 67 | { |
| 68 | static db_ps_t my_ps = NULL; |
| 69 | struct hdr_field* h; |
| 70 | auth_body_t* c; |
| 71 | db_key_t keys[3]; |
| 72 | db_val_t vals[3]; |
| 73 | db_key_t cols[1]; |
| 74 | db_res_t* res = NULL; |
| 75 | |
| 76 | if (_uri == NULL) { |
| 77 | LM_ERR("Bad parameter\n"); |
| 78 | return ERR_INTERNAL; |
| 79 | } |
| 80 | |
| 81 | /* Get authorized digest credentials */ |
| 82 | get_authorized_cred(_m->authorization, &h); |
| 83 | if (h == NULL) { |
| 84 | get_authorized_cred(_m->proxy_auth, &h); |
| 85 | if (h == NULL) { |
| 86 | LM_ERR("No authorized credentials found (error in scripts)\n"); |
| 87 | LM_ERR("Call {www,proxy}_authorize before calling check_* functions!\n"); |
| 88 | return ERR_CREDENTIALS; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | c = (auth_body_t*)(h->parsed); |
| 93 | |
| 94 | /* Parse To/From URI */ |
| 95 | /* Make sure that the URI contains username */ |
| 96 | if (_uri->user.len == 0) { |
| 97 | LM_ERR("Username not found in URI\n"); |
| 98 | return ERR_USERNOTFOUND; |
| 99 | } |
| 100 | |
| 101 | /* Use URI table to determine if Digest username |
| 102 | * and To/From username match. URI table is a table enumerating all allowed |
| 103 | * usernames for a single, thus a user can have several different usernames |
| 104 | * (which are different from digest username and it will still match) |
| 105 | */ |
| 106 | keys[0] = &uri_user_column; |
| 107 | keys[1] = &uri_domain_column; |
| 108 | keys[2] = &uri_uriuser_column; |
| 109 | cols[0] = &uri_user_column; |
| 110 | |
| 111 | /* The whole fields are type DB_STR, and not null */ |
| 112 | VAL_TYPE(vals) = VAL_TYPE(vals + 1) = VAL_TYPE(vals + 2) = DB_STR; |
| 113 | VAL_NULL(vals) = VAL_NULL(vals + 1) = VAL_NULL(vals + 2) = 0; |
| 114 | |
| 115 | VAL_STR(vals) = c->digest.username.user; |
| 116 | VAL_STR(vals + 1) = *GET_REALM(&c->digest); |
| 117 | VAL_STR(vals + 2) = _uri->user; |
| 118 | |
| 119 | auth_dbf.use_table(auth_db_handle, _table); |
| 120 | |
| 121 | CON_SET_CURR_PS(auth_db_handle, &my_ps); |
| 122 | if (auth_dbf.query(auth_db_handle, keys, 0, vals, cols, 3, 1, 0, &res) < 0) |
no test coverage detected