2929
3030namespace usbguard
3131{
32- static const char * options_short = " ha:t" ;
32+ static const char * options_short = " ha:r: t" ;
3333
3434 static const struct ::option options_long[] = {
3535 { " help" , no_argument, nullptr , ' h' },
3636 { " after" , required_argument, nullptr , ' a' },
37+ { " ruleset" , required_argument, nullptr , ' r' },
3738 { " temporary" , no_argument, nullptr , ' t' },
3839 { nullptr , 0 , nullptr , 0 }
3940 };
@@ -43,17 +44,21 @@ namespace usbguard
4344 stream << " Usage: " << usbguard_arg0 << " append-rule [OPTIONS] <rule>" << std::endl;
4445 stream << std::endl;
4546 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;
5155 stream << std::endl;
5256 }
5357
5458 int usbguard_append_rule (int argc, char * argv[])
5559 {
5660 uint32_t parent_id = usbguard::Rule::LastID;
61+ std::string ruleset;
5762 bool permanent = true ;
5863 int opt = 0 ;
5964
@@ -67,6 +72,10 @@ namespace usbguard
6772 parent_id = std::stoul (optarg);
6873 break ;
6974
75+ case ' r' :
76+ ruleset = optarg;
77+ break ;
78+
7079 case ' t' :
7180 permanent = false ;
7281 break ;
@@ -89,7 +98,7 @@ namespace usbguard
8998
9099 usbguard::IPCClient ipc (/* connected=*/ true );
91100 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);
93102 std::cout << id << std::endl;
94103 return EXIT_SUCCESS;
95104 }
0 commit comments