* 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. */
| 314 | * Then try to open the file and insert its fingerprint into metadata store. |
| 315 | */ |
| 316 | static int |
| 317 | parse_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 | |
| 371 | out: |
| 372 | VOP_UNLOCK(nid.ni_vp); |
| 373 | vn_close(nid.ni_vp, FREAD, curthread->td_ucred, curthread); |
no test coverage detected