MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rctl_string_to_rule

Function rctl_string_to_rule

freebsd/kern/kern_rctl.c:1145–1270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1143}
1144
1145static int
1146rctl_string_to_rule(char *rulestr, struct rctl_rule **rulep)
1147{
1148 struct rctl_rule *rule;
1149 char *subjectstr, *subject_idstr, *resourcestr, *actionstr,
1150 *amountstr, *perstr;
1151 id_t id;
1152 int error = 0;
1153
1154 ASSERT_RACCT_ENABLED();
1155
1156 rule = rctl_rule_alloc(M_WAITOK);
1157
1158 subjectstr = strsep(&rulestr, ":");
1159 subject_idstr = strsep(&rulestr, ":");
1160 resourcestr = strsep(&rulestr, ":");
1161 actionstr = strsep(&rulestr, "=/");
1162 amountstr = strsep(&rulestr, "/");
1163 perstr = rulestr;
1164
1165 if (subjectstr == NULL || subjectstr[0] == '\0')
1166 rule->rr_subject_type = RCTL_SUBJECT_TYPE_UNDEFINED;
1167 else {
1168 error = str2value(subjectstr, &rule->rr_subject_type, subjectnames);
1169 if (error != 0)
1170 goto out;
1171 }
1172
1173 if (subject_idstr == NULL || subject_idstr[0] == '\0') {
1174 rule->rr_subject.rs_proc = NULL;
1175 rule->rr_subject.rs_uip = NULL;
1176 rule->rr_subject.rs_loginclass = NULL;
1177 rule->rr_subject.rs_prison_racct = NULL;
1178 } else {
1179 switch (rule->rr_subject_type) {
1180 case RCTL_SUBJECT_TYPE_UNDEFINED:
1181 error = EINVAL;
1182 goto out;
1183 case RCTL_SUBJECT_TYPE_PROCESS:
1184 error = str2id(subject_idstr, &id);
1185 if (error != 0)
1186 goto out;
1187 sx_assert(&allproc_lock, SA_LOCKED);
1188 rule->rr_subject.rs_proc = pfind(id);
1189 if (rule->rr_subject.rs_proc == NULL) {
1190 error = ESRCH;
1191 goto out;
1192 }
1193 PROC_UNLOCK(rule->rr_subject.rs_proc);
1194 break;
1195 case RCTL_SUBJECT_TYPE_USER:
1196 error = str2id(subject_idstr, &id);
1197 if (error != 0)
1198 goto out;
1199 rule->rr_subject.rs_uip = uifind(id);
1200 break;
1201 case RCTL_SUBJECT_TYPE_LOGINCLASS:
1202 rule->rr_subject.rs_loginclass =

Callers 5

sys_rctl_get_racctFunction · 0.85
sys_rctl_get_rulesFunction · 0.85
sys_rctl_get_limitsFunction · 0.85
sys_rctl_add_ruleFunction · 0.85
sys_rctl_remove_ruleFunction · 0.85

Calls 11

rctl_rule_allocFunction · 0.85
strsepFunction · 0.85
str2valueFunction · 0.85
str2idFunction · 0.85
loginclass_findFunction · 0.85
prison_racct_findFunction · 0.85
str2int64Function · 0.85
rctl_rule_releaseFunction · 0.85
pfindFunction · 0.70
uifindFunction · 0.70
panicFunction · 0.70

Tested by

no test coverage detected