Skip to content

Commit

Permalink
Merge pull request #32 from Castaglia/vroot-multiple-aliases-issue22
Browse files Browse the repository at this point in the history
Issue #22: Refine the logic used for determining when a given `VRootA…
  • Loading branch information
Castaglia authored Sep 4, 2021
2 parents 64e9845 + 199b4fd commit bda9144
Show file tree
Hide file tree
Showing 3 changed files with 433 additions and 72 deletions.
7 changes: 5 additions & 2 deletions alias.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ProFTPD: mod_vroot Alias API
* Copyright (c) 2002-2016 TJ Saunders
* Copyright (c) 2002-2021 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 @@ -53,11 +53,14 @@ int vroot_alias_do(int cb(const void *key_data, size_t key_datasz,
}

int vroot_alias_exists(const char *path) {
const void *v;

if (path == NULL) {
return FALSE;
}

if (pr_table_get(alias_tab, path, 0) != NULL) {
v = pr_table_get(alias_tab, path, 0);
if (v != NULL) {
return TRUE;
}

Expand Down
27 changes: 25 additions & 2 deletions fsio.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,10 @@ static int vroot_alias_dirscan(const void *key_data, size_t key_datasz,
real_path = value_data;
dir_path = user_data;

pr_trace_msg(trace_channel, 19,
"scanning aliases: aliased path = '%s', real path = '%s' in directory '%s'",
alias_path, real_path, dir_path);

ptr = strrchr(alias_path, '/');
if (ptr == NULL) {
/* This is not likely to happen, but if it does, simply move to the
Expand All @@ -688,11 +692,30 @@ static int vroot_alias_dirscan(const void *key_data, size_t key_datasz,
dir_pathlen = strlen(dir_path);

if (strncmp(dir_path, alias_path, dir_pathlen) == 0) {
const char *alias_rel_path;

/* Now we need to determine if the alias path in question belongs in this
* directory, or a subdirectory. If it belongs in a subdirectory, then
* we still need to add a directory entry here, constructing that alias
* path to the subdirectory (Issue #22).
*/
alias_rel_path = alias_path + dir_pathlen;
if (alias_rel_path[0] == '/') {
alias_rel_path++;
}
ptr = strchr(alias_rel_path, '/');

pr_trace_msg(trace_channel, 17,
"adding VRootAlias '%s' to list of aliases contained in '%s'",
alias_path, dir_path);
*((char **) push_array(vroot_dir_aliases)) = pstrdup(vroot_dir_pool,
ptr + 1);
if (ptr != NULL) {
*((char **) push_array(vroot_dir_aliases)) = pstrndup(vroot_dir_pool,
alias_rel_path, ptr - alias_rel_path);

} else {
*((char **) push_array(vroot_dir_aliases)) = pstrdup(vroot_dir_pool,
alias_rel_path);
}
}

return 0;
Expand Down
Loading

0 comments on commit bda9144

Please sign in to comment.