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

Function parse_rule_element

freebsd/security/mac_portacl/mac_portacl.c:174–238  ·  view source on GitHub ↗

* Note: parsing routines are destructive on the passed string. */

Source from the content-addressed store, hash-verified

172 * Note: parsing routines are destructive on the passed string.
173 */
174static int
175parse_rule_element(char *element, struct rule **rule)
176{
177 char *idtype, *id, *protocol, *portnumber, *p;
178 struct rule *new;
179 int error;
180
181 error = 0;
182 new = malloc(sizeof(*new), M_PORTACL, M_ZERO | M_WAITOK);
183
184 idtype = strsep(&element, ":");
185 if (idtype == NULL) {
186 error = EINVAL;
187 goto out;
188 }
189 id = strsep(&element, ":");
190 if (id == NULL) {
191 error = EINVAL;
192 goto out;
193 }
194 new->r_id = strtol(id, &p, 10);
195 if (*p != '\0') {
196 error = EINVAL;
197 goto out;
198 }
199 if (strcmp(idtype, UID_STRING) == 0)
200 new->r_idtype = RULE_UID;
201 else if (strcmp(idtype, GID_STRING) == 0)
202 new->r_idtype = RULE_GID;
203 else {
204 error = EINVAL;
205 goto out;
206 }
207 protocol = strsep(&element, ":");
208 if (protocol == NULL) {
209 error = EINVAL;
210 goto out;
211 }
212 if (strcmp(protocol, TCP_STRING) == 0)
213 new->r_protocol = RULE_PROTO_TCP;
214 else if (strcmp(protocol, UDP_STRING) == 0)
215 new->r_protocol = RULE_PROTO_UDP;
216 else {
217 error = EINVAL;
218 goto out;
219 }
220 portnumber = element;
221 if (portnumber == NULL) {
222 error = EINVAL;
223 goto out;
224 }
225 new->r_port = strtol(portnumber, &p, 10);
226 if (*p != '\0') {
227 error = EINVAL;
228 goto out;
229 }
230
231out:

Callers 1

parse_rulesFunction · 0.85

Calls 5

mallocFunction · 0.85
strsepFunction · 0.85
strtolFunction · 0.85
strcmpFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected