MCPcopy Create free account
hub / github.com/COVESA/vsomeip / is_client_allowed

Method is_client_allowed

implementation/security/src/policy_manager_impl.cpp:176–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176bool policy_manager_impl::is_client_allowed(const vsomeip_sec_client_t* _sec_client, service_t _service, instance_t _instance,
177 method_t _method, bool _is_request_service) const {
178
179#ifdef VSOMEIP_DISABLE_SECURITY
180 (void)_sec_client;
181 (void)_service;
182 (void)_instance;
183 (void)_method;
184 (void)_is_request_service;
185
186 return true;
187#else
188 if (!policy_enabled_) {
189 return true;
190 }
191
192 uid_t its_uid(ANY_UID);
193 gid_t its_gid(ANY_GID);
194 if (_sec_client) {
195 if (_sec_client->port == VSOMEIP_SEC_PORT_UNUSED) {
196 its_uid = _sec_client->user;
197 its_gid = _sec_client->group;
198 } else {
199 return true;
200 }
201 } else {
202 std::string security_mode_text = " ~> Skip!";
203 if (!check_credentials_) {
204 security_mode_text = " but will be allowed due to audit mode is active!";
205 }
206 VSOMEIP_INFO << "vSomeIP Security: uid/gid " << its_uid << "/" << its_gid << " is not valid."
207 << "Therefore it isn't allowed to communicate to service/instance " << _service << "/" << _instance
208 << security_mode_text;
209
210 return !check_credentials_;
211 }
212
213 // Check cache
214 auto its_credentials = std::make_pair(its_uid, its_gid);
215 auto its_key = std::make_tuple(_service, _instance, _method);
216 {
217 std::shared_lock its_cache_lock(is_client_allowed_cache_mutex_);
218 const auto its_iter = is_client_allowed_cache_.find(its_credentials);
219 if (its_iter != is_client_allowed_cache_.end()) {
220 if (its_iter->second.contains(its_key)) {
221 return true;
222 }
223 }
224 }
225
226 // Check policies
227 std::shared_lock its_lock(any_client_policies_mutex_);
228 for (const auto& p : any_client_policies_) {
229 std::scoped_lock its_policy_lock(p->mutex_);
230 bool has_uid, has_gid(false);
231 bool is_matching(false);
232
233 const auto found_uid = p->credentials_.find(its_uid);

Calls 4

hex4Function · 0.85
endMethod · 0.80
insertMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected