| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/shell/identity.h" | |
| 6 | |
| 7 #include "mojo/shell/public/cpp/names.h" | |
| 8 #include "mojo/shell/public/interfaces/connector.mojom.h" | |
| 9 | |
| 10 namespace mojo { | |
| 11 namespace shell { | |
| 12 | |
| 13 Identity::Identity() {} | |
| 14 | |
| 15 Identity::Identity(const std::string& name) | |
| 16 : Identity(name, GetNamePath(name), mojom::kRootUserID) {} | |
| 17 | |
| 18 Identity::Identity(const std::string& name, const std::string& qualifier, | |
| 19 const std::string& user_id) | |
| 20 : name_(name), | |
| 21 qualifier_(qualifier.empty() ? GetNamePath(name_) : qualifier), | |
| 22 user_id_(user_id) {} | |
| 23 | |
| 24 Identity::Identity(const Identity& other) = default; | |
| 25 | |
| 26 Identity::~Identity() {} | |
| 27 | |
| 28 bool Identity::operator<(const Identity& other) const { | |
| 29 // We specifically don't include filter in the equivalence check because we | |
| 30 // don't quite know how this should work yet. | |
| 31 // TODO(beng): figure out how it should work. | |
| 32 if (name_ != other.name_) | |
| 33 return name_ < other.name_; | |
| 34 if (qualifier_ != other.qualifier_) | |
| 35 return qualifier_ < other.qualifier_; | |
| 36 return user_id_ < other.user_id_; | |
| 37 } | |
| 38 | |
| 39 bool Identity::operator==(const Identity& other) const { | |
| 40 // We specifically don't include filter in the equivalence check because we | |
| 41 // don't quite know how this should work yet. | |
| 42 // TODO(beng): figure out how it should work. | |
| 43 return other.name_ == name_ && other.qualifier_ == qualifier_ && | |
| 44 other.user_id_ == user_id_; | |
| 45 } | |
| 46 | |
| 47 Identity CreateShellIdentity() { | |
| 48 Identity id = Identity("mojo:shell", "", mojom::kRootUserID); | |
| 49 id.set_filter(GetPermissiveCapabilityFilter()); | |
| 50 return id; | |
| 51 } | |
| 52 | |
| 53 CapabilityFilter GetPermissiveCapabilityFilter() { | |
| 54 CapabilityFilter filter; | |
| 55 AllowedInterfaces interfaces; | |
| 56 interfaces.insert("*"); | |
| 57 filter["*"] = interfaces; | |
| 58 return filter; | |
| 59 } | |
| 60 | |
| 61 AllowedInterfaces GetAllowedInterfaces(const CapabilityFilter& filter, | |
| 62 const Identity& identity) { | |
| 63 // Start by looking for interfaces specific to the supplied identity. | |
| 64 auto it = filter.find(identity.name()); | |
| 65 if (it != filter.end()) | |
| 66 return it->second; | |
| 67 | |
| 68 // Fall back to looking for a wildcard rule. | |
| 69 it = filter.find("*"); | |
| 70 if (filter.size() == 1 && it != filter.end()) | |
| 71 return it->second; | |
| 72 | |
| 73 // Finally, nothing is allowed. | |
| 74 return AllowedInterfaces(); | |
| 75 } | |
| 76 | |
| 77 } // namespace shell | |
| 78 } // namespace mojo | |
| OLD | NEW |