Skip to content

Commit

Permalink
Merge pull request #46 from Castaglia/fsio-realpath-impl-issue1780
Browse files Browse the repository at this point in the history
Provide a `realpath(3)` implementation, for use by other modules, usi…
  • Loading branch information
Castaglia authored Apr 3, 2024
2 parents 04fc1be + 811de54 commit abcc817
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
27 changes: 26 additions & 1 deletion fsio.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion fsio.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion mod_vroot.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions mod_vroot.h.in
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit abcc817

Please sign in to comment.