Skip to content

Commit

Permalink
Merge pull request proftpd#1295 from proftpd/ifsess-directory-config-…
Browse files Browse the repository at this point in the history
…bug4315

Bug #4315: When mod_ifsession merges in an `<IfUser>` or `<IfGroup>` …
  • Loading branch information
Castaglia authored Aug 9, 2021
2 parents 1ef600f + d1cc107 commit 45207de
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 8 deletions.
19 changes: 11 additions & 8 deletions contrib/mod_ifsession.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ProFTPD: mod_ifsession -- a module supporting conditional
* per-user/group/class configuration contexts.
* 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 All @@ -28,7 +28,7 @@

#include "conf.h"

#define MOD_IFSESSION_VERSION "mod_ifsession/1.3"
#define MOD_IFSESSION_VERSION "mod_ifsession/1.3.1"

/* Make sure the version of proftpd is as necessary. */
#if PROFTPD_VERSION_NUMBER < 0x0001030402
Expand Down Expand Up @@ -842,7 +842,7 @@ MODRET ifsess_post_pass(cmd_rec *cmd) {
*/

c = find_config(main_server->conf, -1, IFSESS_AUTHN_TEXT, FALSE);
while (c) {
while (c != NULL) {
config_rec *list = NULL;

pr_signals_handle();
Expand Down Expand Up @@ -881,7 +881,7 @@ MODRET ifsess_post_pass(cmd_rec *cmd) {
}

c = find_config(main_server->conf, -1, IFSESS_GROUP_TEXT, FALSE);
while (c) {
while (c != NULL) {
config_rec *list = NULL;

pr_signals_handle();
Expand Down Expand Up @@ -936,7 +936,7 @@ MODRET ifsess_post_pass(cmd_rec *cmd) {
mergein = TRUE;
}

if (mergein) {
if (mergein == TRUE) {
pr_log_debug(DEBUG2, MOD_IFSESSION_VERSION
": merging <IfGroup %s> directives in", (char *) list->argv[0]);
ifsess_dup_set(session.pool, main_server->conf, c->subset);
Expand Down Expand Up @@ -983,7 +983,7 @@ MODRET ifsess_post_pass(cmd_rec *cmd) {
}

c = find_config(main_server->conf, -1, IFSESS_USER_TEXT, FALSE);
while (c) {
while (c != NULL) {
config_rec *list = NULL;

pr_signals_handle();
Expand Down Expand Up @@ -1016,7 +1016,7 @@ MODRET ifsess_post_pass(cmd_rec *cmd) {
mergein = TRUE;
}

if (mergein) {
if (mergein == TRUE) {
pr_log_debug(DEBUG2, MOD_IFSESSION_VERSION
": merging <IfUser %s> directives in", (char *) list->argv[0]);
ifsess_dup_set(session.pool, main_server->conf, c->subset);
Expand Down Expand Up @@ -1055,7 +1055,7 @@ MODRET ifsess_post_pass(cmd_rec *cmd) {

destroy_pool(tmp_pool);

if (ifsess_merged) {
if (ifsess_merged == TRUE) {
/* Try to honor any <Limit LOGIN> sections that may have been merged in. */
if (!login_check_limits(TOPLEVEL_CONF, FALSE, TRUE, &found)) {
pr_log_debug(DEBUG3, MOD_IFSESSION_VERSION
Expand All @@ -1080,6 +1080,9 @@ MODRET ifsess_post_pass(cmd_rec *cmd) {
pr_fsio_close(displaylogin_fh);
displaylogin_fh = NULL;
}

/* Make sure directory config pointers are set correctly (Bug #4315). */
dir_check_full(cmd->tmp_pool, cmd, G_NONE, session.cwd, NULL);
}

return PR_DECLINED(cmd);
Expand Down
101 changes: 101 additions & 0 deletions tests/t/lib/ProFTPD/Tests/Modules/mod_ifsession.pm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ my $TESTS = {
order => ++$order,
test_class => [qw(bug forking)],
},

ifuser_directory_bug4315 => {
order => ++$order,
test_class => [qw(bug forking)],
},

};

sub new {
Expand Down Expand Up @@ -2334,4 +2340,99 @@ EOC
test_cleanup($setup->{log_file}, $ex);
}

sub ifuser_directory_bug4315 {
my $self = shift;
my $tmpdir = $self->{tmpdir};
my $setup = test_setup($tmpdir, 'ifsess');

my $config = {
PidFile => $setup->{pid_file},
ScoreboardFile => $setup->{scoreboard_file},
SystemLog => $setup->{log_file},

AuthUserFile => $setup->{auth_user_file},
AuthGroupFile => $setup->{auth_group_file},

IfModules => {
'mod_delay.c' => {
DelayEngine => 'off',
},
},
};

my ($port, $config_user, $config_group) = config_write($setup->{config_file},
$config);

if (open(my $fh, ">> $setup->{config_file}")) {
print $fh <<EOC;
<IfModule mod_ifsession.c>
<IfUser $setup->{user}>
<Directory />
PathAllowFilter ^a
</Directory>
</IfUser>
</IfModule>
EOC
unless (close($fh)) {
die("Can't write $setup->{config_file}: $!");
}

} else {
die("Can't open $setup->{config_file}: $!");
}

# Open pipes, for use between the parent and child processes. Specifically,
# the child will indicate when it's done with its test by writing a message
# to the parent.
my ($rfh, $wfh);
unless (pipe($rfh, $wfh)) {
die("Can't open pipe: $!");
}

my $ex;

# Fork child
$self->handle_sigchld();
defined(my $pid = fork()) or die("Can't fork: $!");
if ($pid) {
eval {
my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
$client->login($setup->{user}, $setup->{passwd});

eval { $client->mkd('bad') };
unless ($@) {
die("MKD /bad succeeded unexpectedly");
}

eval { $client->mkd('bad') };
unless ($@) {
die("MKD /bad succeeded unexpectedly");
}

$client->quit();
};
if ($@) {
$ex = $@;
}

$wfh->print("done\n");
$wfh->flush();

} else {
eval { server_wait($setup->{config_file}, $rfh) };
if ($@) {
warn($@);
exit 1;
}

exit 0;
}

# Stop server
server_stop($setup->{pid_file});
$self->assert_child_ok($pid);

test_cleanup($setup->{log_file}, $ex);
}

1;

0 comments on commit 45207de

Please sign in to comment.