| 61 | } |
| 62 | |
| 63 | bool policy_manager_impl::check_credentials(client_t _client, const vsomeip_sec_client_t* _sec_client) { |
| 64 | |
| 65 | #ifdef VSOMEIP_DISABLE_SECURITY |
| 66 | (void)_client; |
| 67 | (void)_sec_client; |
| 68 | |
| 69 | return true; |
| 70 | #else |
| 71 | if (!policy_enabled_) |
| 72 | return true; |
| 73 | |
| 74 | if (!_sec_client) |
| 75 | return true; |
| 76 | |
| 77 | if (_sec_client->port != VSOMEIP_SEC_PORT_UNUSED) |
| 78 | return true; |
| 79 | |
| 80 | uid_t its_uid(_sec_client->user); |
| 81 | gid_t its_gid(_sec_client->group); |
| 82 | |
| 83 | bool has_id(false); |
| 84 | |
| 85 | std::shared_lock its_lock(any_client_policies_mutex_); |
| 86 | for (const auto& p : any_client_policies_) { |
| 87 | |
| 88 | std::scoped_lock its_policy_lock(p->mutex_); |
| 89 | |
| 90 | bool has_uid, has_gid(false); |
| 91 | |
| 92 | const auto found_uid = p->credentials_.find(its_uid); |
| 93 | has_uid = (found_uid != p->credentials_.end()); |
| 94 | if (has_uid) { |
| 95 | const auto found_gid = found_uid->second.find(its_gid); |
| 96 | has_gid = (found_gid != found_uid->second.end()); |
| 97 | } |
| 98 | |
| 99 | has_id = (has_uid && has_gid); |
| 100 | |
| 101 | if ((has_id && p->allow_who_) || (!has_id && !p->allow_who_)) { |
| 102 | // Code is unaccessible due to logic checks. |
| 103 | if (!store_client_to_sec_client_mapping(_client, _sec_client)) { |
| 104 | std::string security_mode_text = "!"; |
| 105 | if (!check_credentials_) { |
| 106 | security_mode_text = " but will be allowed due to audit mode is active!"; |
| 107 | } |
| 108 | VSOMEIP_INFO << "vSomeIP Security: Client 0x" << hex4(_client) << " with UID/GID=" << its_uid << "/" << its_gid |
| 109 | << " : Check credentials failed as existing credentials would be overwritten" << security_mode_text; |
| 110 | return !check_credentials_; |
| 111 | } |
| 112 | store_sec_client_to_client_mapping(_sec_client, _client); |
| 113 | return true; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | std::string security_mode_text = " ~> Skip!"; |
| 118 | if (!check_credentials_) { |
| 119 | security_mode_text = " but will be allowed due to audit mode is active!"; |
| 120 | } |
no test coverage detected