From 37f51391c8888c7f84e27ec6995fda5dd3af49c3 Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 6 Jun 2024 21:11:11 +0000 Subject: driver: implemented and integrated the -H (follow symlink args) cmdline option. --- src/logic/tpax_archive_enqueue.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/logic/tpax_archive_enqueue.c') diff --git a/src/logic/tpax_archive_enqueue.c b/src/logic/tpax_archive_enqueue.c index 222b0ad..b81661b 100644 --- a/src/logic/tpax_archive_enqueue.c +++ b/src/logic/tpax_archive_enqueue.c @@ -400,6 +400,7 @@ int tpax_archive_enqueue( const struct tpax_unit_ctx * uctx) { int fdat; + int fdlnk; uintptr_t addr; const char * name; const char * mark; @@ -409,11 +410,15 @@ int tpax_archive_enqueue( struct tpax_dirent * cdent; struct tpax_dirent * cnext; struct dirent * dirent; + struct dirent * lnkent; + struct stat lnkst; char entbuf[PATH_MAX + sizeof(struct dirent)]; + char lnkbuf[PATH_MAX + sizeof(struct dirent)]; /* init */ fdat = tpax_driver_fdcwd(dctx); dirent = (struct dirent *)entbuf; + lnkent = (struct dirent *)lnkbuf; prefix = 0; /* split path to prefix + basename */ @@ -449,6 +454,39 @@ int tpax_archive_enqueue( TPAX_NESTED_ERROR(dctx), 0); + /* follow command-line symlink arguments as needed */ + fdlnk = (uctx->link[0] && (dctx->cctx->drvflags & TPAX_DRIVER_PAX_SYMLINK_ARGS)) + ? openat(fdat,uctx->link[0],O_RDONLY|O_CLOEXEC) : (-1); + + if (fdlnk >= 0) { + if (fstat(fdlnk,&lnkst) <0) { + close(fdlnk); + return tpax_archive_enqueue_ret( + TPAX_SYSTEM_ERROR(dctx), + 0); + } + + close(fdlnk); + + if (tpax_dirent_init_from_uctx(&lnkst,uctx->link[0],lnkent) < 0) + return tpax_archive_enqueue_ret( + TPAX_CUSTOM_ERROR( + dctx, + TPAX_ERR_FLOW_ERROR), + 0); + + cdent = tpax_get_driver_dirmark(dctx); + cdent->flags |= TPAX_ITEM_NAMEREF; + + if (tpax_archive_add_queue_item( + dctx,lnkent,cdent,0,1, + TPAX_ITEM_EXPLICIT|TPAX_ITEM_SYMLINK, + fdat,&fkeep) < 0) + return tpax_archive_enqueue_ret( + TPAX_NESTED_ERROR(dctx), + 0); + } + /* queue directory child items */ dentbuf = tpax_get_driver_dirents(dctx); cdent = tpax_get_driver_dirmark(dctx); -- cgit v1.2.3