Skip to content

Commit

Permalink
Allow configuration files to be included
Browse files Browse the repository at this point in the history
Adapted from a PR by Kiril Vladimirov
  • Loading branch information
jedisct1 committed Nov 23, 2021
1 parent 09b36ea commit 868f0e2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ compile-time are not parsed any more.
- When virtual quotas were configured, files were removed after an
upload if the size quota was exceeded, but not during the upload. This
has been fixed.
- A configuration file can now include other files with the `Include`
directive.

* Version 1.0.49:
- This version fixes a regression introduced in version 1.0.48 that broke
Expand Down
8 changes: 8 additions & 0 deletions pure-ftpd.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,11 @@ CustomerProof yes
# By default, both IPv4 and IPv6 are enabled.

# IPV6Only yes



# Append the content of another file, if the file exists.
# If the file doesn't exist, the directive is ignored.
# More files can be recursively included.

# Include additional_configuration.conf
35 changes: 29 additions & 6 deletions src/ftpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -5443,6 +5443,24 @@ static struct passwd *fakegetpwnam(const char * const name)
}
#endif

#ifndef MINIMAL
static SimpleConfSpecialHandlerResult sc_special_handler(void **output_p,
const char *arg,
void *user_data)
{
struct stat st;
(void) user_data;

if (stat(arg, &st) != 0) {
return SC_SPECIAL_HANDLER_RESULT_NEXT;
}
if ((*output_p = strdup(arg)) == NULL) {
return SC_SPECIAL_HANDLER_RESULT_ERROR;
}
return SC_SPECIAL_HANDLER_RESULT_INCLUDE;
}
#endif

int pureftpd_start(int argc, char *argv[], const char *home_directory_)
{
#ifndef NO_GETOPT_LONG
Expand Down Expand Up @@ -5507,12 +5525,17 @@ int pureftpd_start(int argc, char *argv[], const char *home_directory_)
#endif

#ifndef MINIMAL
if (argc == 2 && *argv[1] != '-' &&
sc_build_command_line_from_file(argv[1], NULL, simpleconf_options,
(sizeof simpleconf_options) /
(sizeof simpleconf_options[0]),
argv[0], &argc, &argv) != 0) {
die(421, LOG_ERR, MSG_CONF_ERR);
{
static SimpleConfConfig config = { NULL, sc_special_handler };

if (argc == 2 && *argv[1] != '-' &&
sc_build_command_line_from_file(argv[1], &config,
simpleconf_options,
(sizeof simpleconf_options) /
(sizeof simpleconf_options[0]),
argv[0], &argc, &argv) != 0) {
die(421, LOG_ERR, MSG_CONF_ERR);
}
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion src/simpleconf_ftpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ static const SimpleConfEntry simpleconf_options[] = {
#ifdef RATIOS
{"UserRatio (<digits>) (<digits>)", "--userratio=$0:$1"},
#endif
{"VerboseLog? <bool>", "--verboselog"}
{"VerboseLog? <bool>", "--verboselog"},
{"!Include <any*>", "$*"}
};

#endif

0 comments on commit 868f0e2

Please sign in to comment.