29
29
30
30
namespace usbguard
31
31
{
32
- static const char * options_short = " ha:t" ;
32
+ static const char * options_short = " ha:r: t" ;
33
33
34
34
static const struct ::option options_long[] = {
35
35
{ " help" , no_argument, nullptr , ' h' },
36
36
{ " after" , required_argument, nullptr , ' a' },
37
+ { " ruleset" , required_argument, nullptr , ' r' },
37
38
{ " temporary" , no_argument, nullptr , ' t' },
38
39
{ nullptr , 0 , nullptr , 0 }
39
40
};
@@ -43,17 +44,21 @@ namespace usbguard
43
44
stream << " Usage: " << usbguard_arg0 << " append-rule [OPTIONS] <rule>" << std::endl;
44
45
stream << std::endl;
45
46
stream << " Options:" << std::endl;
46
- stream << " -a, --after <id> Append the new rule after a rule with the specified id" << std::endl;
47
- stream << " instead of appending it at the end of the rule set." << std::endl;
48
- stream << " -t, --temporary Make the decision temporary. The rule policy file will not" << std::endl;
49
- stream << " be updated." << std::endl;
50
- stream << " -h, --help Show this help." << std::endl;
47
+ stream << " -a, --after <id> Append the new rule after a rule with the specified id" << std::endl;
48
+ stream << " instead of appending it at the end of the rule set." << std::endl;
49
+ stream << " If 'id' is 0, then the rule is appended to the beginning" << std::endl;
50
+ stream << " of the rule set." << std::endl;
51
+ stream << " -r, --ruleset <prefix> Append the new rule into a ruleset with specified prefix." << std::endl;
52
+ stream << " -t, --temporary Make the decision temporary. The rule policy file will not" << std::endl;
53
+ stream << " be updated." << std::endl;
54
+ stream << " -h, --help Show this help." << std::endl;
51
55
stream << std::endl;
52
56
}
53
57
54
58
int usbguard_append_rule (int argc, char * argv[])
55
59
{
56
60
uint32_t parent_id = usbguard::Rule::LastID;
61
+ std::string ruleset;
57
62
bool permanent = true ;
58
63
int opt = 0 ;
59
64
@@ -67,6 +72,10 @@ namespace usbguard
67
72
parent_id = std::stoul (optarg );
68
73
break ;
69
74
75
+ case ' r' :
76
+ ruleset = optarg ;
77
+ break ;
78
+
70
79
case ' t' :
71
80
permanent = false ;
72
81
break ;
@@ -89,7 +98,7 @@ namespace usbguard
89
98
90
99
usbguard::IPCClient ipc (/* connected=*/ true );
91
100
const std::string rule_spec = argv[0 ];
92
- const uint32_t id = ipc.appendRule (rule_spec, parent_id, permanent);
101
+ const uint32_t id = ipc.insertRule (rule_spec, parent_id, ruleset , permanent);
93
102
std::cout << id << std::endl;
94
103
return EXIT_SUCCESS;
95
104
}
0 commit comments