| 897 | } |
| 898 | |
| 899 | std::shared_ptr<Rule> Daemon::getInsertedDevicePolicyRule(std::shared_ptr<Device> device) |
| 900 | { |
| 901 | USBGUARD_LOG(Trace) << "device_ptr=" << device.get(); |
| 902 | std::shared_ptr<const Rule> device_rule = \ |
| 903 | device->getDeviceRule(/*with_port=*/true, |
| 904 | /*with_parent_hash=*/true, |
| 905 | /*match_rule=*/true); |
| 906 | Rule::Target target = Rule::Target::Invalid; |
| 907 | std::shared_ptr<Rule> policy_rule; |
| 908 | const DevicePolicyMethod policy_method = _inserted_device_policy_method; |
| 909 | |
| 910 | switch (policy_method) { |
| 911 | case DevicePolicyMethod::Block: |
| 912 | target = Rule::Target::Block; |
| 913 | break; |
| 914 | |
| 915 | case DevicePolicyMethod::Reject: |
| 916 | target = Rule::Target::Reject; |
| 917 | break; |
| 918 | |
| 919 | case DevicePolicyMethod::ApplyPolicy: |
| 920 | policy_rule = _policy.getFirstMatchingRule(device_rule); |
| 921 | break; |
| 922 | |
| 923 | case DevicePolicyMethod::Allow: |
| 924 | case DevicePolicyMethod::Keep: |
| 925 | default: |
| 926 | throw USBGUARD_BUG("Invalid DevicePolicyMethod value"); |
| 927 | } |
| 928 | |
| 929 | if (policy_rule == nullptr) { |
| 930 | policy_rule = std::make_shared<Rule>(); |
| 931 | policy_rule->setTarget(target); |
| 932 | policy_rule->setRuleID(Rule::RootID); |
| 933 | } |
| 934 | |
| 935 | return policy_rule; |
| 936 | } |
| 937 | |
| 938 | std::shared_ptr<Rule> Daemon::getPresentDevicePolicyRule(std::shared_ptr<Device> device) |
| 939 | { |
nothing calls this directly
no test coverage detected