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

Function parse_entry

freebsd/security/mac_veriexec_parser/mac_veriexec_parser.c:316–375  ·  view source on GitHub ↗

* Process single line. * First split it into path, digest_type and digest. * Then try to open the file and insert its fingerprint into metadata store. */

Source from the content-addressed store, hash-verified

314 * Then try to open the file and insert its fingerprint into metadata store.
315 */
316static int
317parse_entry(char *entry, char *prefix)
318{
319 struct nameidata nid;
320 struct vattr va;
321 char path[MAXPATHLEN];
322 char *fp_type;
323 unsigned char *digest;
324 int rc, is_exec, flags;
325
326 fp_type = NULL;
327 digest = NULL;
328 flags = 0;
329
330 rc = get_fp(entry, &fp_type, &digest, &flags);
331 if (rc != 0)
332 return (rc);
333
334 rc = hexstring_to_bin(digest);
335 if (rc != 0)
336 return (rc);
337
338 if (strnlen(entry, MAXPATHLEN) == MAXPATHLEN)
339 return (EINVAL);
340
341 /* If the path is not absolute prepend it with a prefix */
342 if (prefix != NULL && entry[0] != '/') {
343 rc = snprintf(path, MAXPATHLEN, "%s/%s",
344 prefix, entry);
345 if (rc < 0)
346 return (-rc);
347 } else {
348 strcpy(path, entry);
349 }
350
351 rc = open_file(path, &nid);
352 NDFREE(&nid, NDF_ONLY_PNBUF);
353 if (rc != 0)
354 return (rc);
355
356 rc = VOP_GETATTR(nid.ni_vp, &va, curthread->td_ucred);
357 if (rc != 0)
358 goto out;
359
360 is_exec = (va.va_mode & VEXEC);
361
362 mtx_lock(&ve_mutex);
363 rc = mac_veriexec_metadata_add_file(
364 is_exec == 0,
365 va.va_fsid, va.va_fileid, va.va_gen,
366 digest,
367 NULL, 0,
368 flags, fp_type, 1);
369 mtx_unlock(&ve_mutex);
370
371out:
372 VOP_UNLOCK(nid.ni_vp);
373 vn_close(nid.ni_vp, FREAD, curthread->td_ucred, curthread);

Callers 1

parse_manifestFunction · 0.70

Calls 11

get_fpFunction · 0.85
hexstring_to_binFunction · 0.85
strnlenFunction · 0.85
snprintfFunction · 0.85
NDFREEFunction · 0.85
VOP_GETATTRFunction · 0.85
open_fileFunction · 0.70
mtx_lockFunction · 0.50
mtx_unlockFunction · 0.50
vn_closeFunction · 0.50

Tested by

no test coverage detected