From 811de54f8952f780c8f15c794be37cd326616cd1 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Sat, 30 Mar 2024 12:05:00 -0700 Subject: [PATCH] Provide a `realpath(3)` implementation, for use by other modules, using the new FSIO API for such functionality. --- fsio.c | 27 ++++++++++++++++++++++++++- fsio.h | 3 ++- mod_vroot.c | 5 ++++- mod_vroot.h.in | 4 ++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/fsio.c b/fsio.c index 2e80b9d..031ed33 100644 --- a/fsio.c +++ b/fsio.c @@ -1,6 +1,6 @@ /* * ProFTPD: mod_vroot FSIO API - * Copyright (c) 2002-2021 TJ Saunders + * Copyright (c) 2002-2024 TJ Saunders * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -643,6 +643,31 @@ int vroot_fsio_utimes(pr_fs_t *fs, const char *utimes_path, return res; } +const char *vroot_fsio_realpath(pr_fs_t *fs, pool *p, const char *path) { + const char *res = NULL; + int xerrno; + char vpath[PR_TUNABLE_PATH_MAX + 1], *real_path = NULL; + pool *tmp_pool = NULL; + + tmp_pool = make_sub_pool(p); + pr_pool_tag(tmp_pool, "VRoot FSIO realpath pool"); + + real_path = vroot_realpath(p, path, VROOT_REALPATH_FL_ABS_PATH); + + if (vroot_path_lookup(NULL, vpath, sizeof(vpath)-1, real_path, 0, NULL) < 0) { + xerrno = errno; + + destroy_pool(tmp_pool); + errno = xerrno; + return NULL; + } + + destroy_pool(tmp_pool); + + res = pstrdup(p, vpath); + return res; +} + static struct dirent *vroot_dent = NULL; static size_t vroot_dentsz = 0; diff --git a/fsio.h b/fsio.h index 3de324c..8ef9158 100644 --- a/fsio.h +++ b/fsio.h @@ -1,6 +1,6 @@ /* * ProFTPD - mod_vroot FSIO API - * Copyright (c) 2016 TJ Saunders + * Copyright (c) 2016-2024 TJ Saunders * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,6 +43,7 @@ int vroot_fsio_lchown(pr_fs_t *fs, const char *path, uid_t uid, gid_t gid); int vroot_fsio_chroot(pr_fs_t *fs, const char *path); int vroot_fsio_chdir(pr_fs_t *fs, const char *path); int vroot_fsio_utimes(pr_fs_t *fs, const char *path, struct timeval *tvs); +const char *vroot_fsio_realpath(pr_fs_t *fs, pool *p, const char *path); void *vroot_fsio_opendir(pr_fs_t *fs, const char *path); struct dirent *vroot_fsio_readdir(pr_fs_t *fs, void *dirh); int vroot_fsio_closedir(pr_fs_t *fs, void *dirh); diff --git a/mod_vroot.c b/mod_vroot.c index 79422ba..684d725 100644 --- a/mod_vroot.c +++ b/mod_vroot.c @@ -1,7 +1,7 @@ /* * ProFTPD: mod_vroot -- a module implementing a virtual chroot capability * via the FSIO API - * Copyright (c) 2002-2022 TJ Saunders + * Copyright (c) 2002-2024 TJ Saunders * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -587,6 +587,9 @@ static void vroot_chroot_ev(const void *event_data, void *user_data) { #if PROFTPD_VERSION_NUMBER >= 0x0001030407 fs->lchown = vroot_fsio_lchown; #endif /* ProFTPD 1.3.4c or later */ +#if PROFTPD_VERSION_NUMBER >= 0x0001030903 + fs->realpath = vroot_fsio_realpath; +#endif /* ProFTPD 1.3.9rc3 or later */ fs->chdir = vroot_fsio_chdir; fs->chroot = vroot_fsio_chroot; fs->utimes = vroot_fsio_utimes; diff --git a/mod_vroot.h.in b/mod_vroot.h.in index 0a1b37e..bf8ccd7 100644 --- a/mod_vroot.h.in +++ b/mod_vroot.h.in @@ -1,6 +1,6 @@ /* * ProFTPD - mod_vroot - * Copyright (c) 2016-2022 TJ Saunders + * Copyright (c) 2016-2024 TJ Saunders * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ #include "conf.h" -#define MOD_VROOT_VERSION "mod_vroot/0.9.11" +#define MOD_VROOT_VERSION "mod_vroot/0.9.12" /* Make sure the version of proftpd is as necessary. */ #if PROFTPD_VERSION_NUMBER < 0x0001030602