/usr/sbin/pure-ftpd-wrapper is in pure-ftpd-common 1.0.46-1build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | #! /usr/bin/perl
#
# Copyright 2002,2003,2004,2005,2007,2009,2010,2011,2014 by Stefan Hornburg (Racke) <racke@linuxia.de>
#
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.
use strict;
use warnings;
use File::Basename;
use File::Spec;
use Getopt::Long;
# Process command line parameters
my $whandler = $SIG{__WARN__};
$SIG{__WARN__} = sub {print STDERR "$0: @_";};
my %opts;
unless (GetOptions (\%opts, 'show-options|s')) {
exit 1;
}
$SIG{__WARN__} = $whandler;
my $daemon = '/usr/sbin/pure-ftpd';
my @capabilities = @ARGV;
if ($ARGV[0]) {
$daemon = "$daemon-$ARGV[0]";
}
# configuration schema
#
# fields of the array:
# 0. option name
# 1. parser
# 2. priority
#
# SysLogFacility has the highest priority, because we want to
# avoid to log to the wrong location (see pure-ftpd manpage).
my %conf = ('AllowAnonymousFXP' => ['-W'],
'AllowDotFiles' => ['-z'],
'AllowUserFXP' => ['-w'],
'AltLog' => ['-O %s', \&parse_string],
'AnonymousBandwidth' => ['-t %s', \&parse_number_1_2],
'AnonymousCanCreateDirs' => ['-M'],
'AnonymousCantUpload' => ['-i'],
'AnonymousOnly', => ['-e'],
'AnonymousRatio' => ['-q %d:%d', \&parse_number_2],
'AntiWarez' => ['-s'],
'AutoRename' => ['-r'],
'Bind' => ['-S %s', \&parse_string],
'BrokenClientsCompatibility' => ['-b'],
'CallUploadScript' => ['-o'],
'ChrootEveryone' => ['-A'],
'CreateHomeDir' => ['-j'],
'CustomerProof' => ['-Z'],
'Daemonize' => ['-B'],
'DisplayDotFiles' => ['-D'],
'DontResolve' => ['-H'],
'ForcePassiveIP' => ['-P %s', \&parse_string],
'FortunesFile' => ['-F %s', \&parse_filename],
'FSCharset' => ['-8 %s', \&parse_string],
'ClientCharset' => ['-9 %s', \&parse_string],
'IPV4Only' => ['-4'],
'IPV6Only' => ['-6'],
'KeepAllFiles' => ['-K'],
'LimitRecursion' => ['-L %d:%d', \&parse_number_2_unlimited],
'LogPID' => ['-1'],
'MaxClientsNumber' => ['-c %d', \&parse_number_1],
'MaxClientsPerIP' => ['-C %d', \&parse_number_1],
'MaxDiskUsage' => ['-k %d', \&parse_number_1],
'MaxIdleTime' => ['-I %d', \&parse_number_1],
'MaxLoad' => ['-m %d', \&parse_number_1],
'MinUID' => ['-u %d', \&parse_number_1],
'NATmode' => ['-N'],
'NoAnonymous' => ['-E'],
'NoChmod' => ['-R'],
'NoRename' => ['-G'],
'NoTruncate' => ['-0'],
'PassivePortRange' => ['-p %d:%d', \&parse_number_2],
'PerUserLimits' => ['-y %d:%d', \&parse_number_2],
'ProhibitDotFilesRead' => ['-X'],
'ProhibitDotFilesWrite' => ['-x'],
'Quota' => ['-n %d:%d', \&parse_number_2],
'SyslogFacility' => ['-f %s', \&parse_word, 99],
'TLS' => ['-Y %d', \&parse_number_1],
'TLSCipherSuite' => ['-J %s', \&parse_string],
'TrustedGID' => ['-a %d', \&parse_number_1],
'TrustedIP' => ['-V %s', \&parse_ip],
'Umask' => ['-U %s:%s', \&parse_umask],
'UserBandwidth' => ['-T %s', \&parse_number_1_2],
'UserRatio' => ['-Q %d:%d', \&parse_number_2],
'VerboseLog' => ['-d'],
);
my %authconf = ('ExtAuth' => ['extauth:%s', \&parse_sockname],
'LDAPConfigFile' => ['ldap:%s', \&parse_filename, 0,
'ldap'],
'MySQLConfigFile' => ['mysql:%s', \&parse_filename, 0,
'mysql'],
'PGSQLConfigFile' => ['pgsql:%s', \&parse_filename, 0,
'postgresql'],
'PAMAuthentication' => ['pam'],
'PureDB' => ['puredb:%s', \&parse_filename],
'UnixAuthentication' => ['unix'],
);
# examine all configuration files in /etc/pure-ftpd/conf
my @conffiles;
opendir (ETCCONF, '/etc/pure-ftpd/conf')
|| die "$0: Couldn't examine directory /etc/pure-ftpd/conf: $!\n";
@conffiles = readdir (ETCCONF);
closedir (ETCCONF);
# examine authentication files in /etc/pure-ftpd/auth
my @authfiles;
opendir (ETCAUTH, '/etc/pure-ftpd/auth')
|| die "$0: Couldn't examine directory /etc/pure-ftpd/auth: $!\n";
@authfiles = sort (grep {-l "/etc/pure-ftpd/auth/$_"} readdir (ETCAUTH));
closedir (ETCAUTH);
my ($file, $cref, $name);
my (@options, $option, $ret);
for my $authname (@authfiles) {
# check if corresponding file exists
next unless $file = readlink("/etc/pure-ftpd/auth/$authname");
unless (File::Spec->file_name_is_absolute($file)) {
$file = File::Spec->catfile('/etc/pure-ftpd/auth',$file);
}
next unless -f $file;
# check if configuration directive exists
$name = basename($file);
# check if we have the right capability for this authentication method
next if $authconf{$authname}->[3] && ! grep {$authconf{$authname}->[3] eq $_} @capabilities;
if ($ret = parse_file(\%authconf, $file, $name)) {
$ret->[0] = "-l $ret->[0]";
push (@options, $ret);
}
}
for (@conffiles) {
# simply skip files with non-word/non-numeric characters
next unless /^[A-Za-z][A-Za-z0-9]+$/;
# skip authentication configuration files
next if exists $authconf{$_};
$file = "/etc/pure-ftpd/conf/$_";
if ($ret = parse_file(\%conf, $file, $_)) {
push (@options, $ret);
}
}
@options = map {split(/ /, $_->[0], 2)} (sort {$b->[1] <=> $a->[1]} @options);
if (exists $ENV{STANDALONE_OR_INETD} && $ENV{STANDALONE_OR_INETD} eq 'standalone') {
push (@options, '-B');
print "Running: $daemon ", join (' ', @options), "\n";
}
# force PID file to /var/run/pure-ftpd/pure-ftpd.pid
push(@options, '-g', '/var/run/pure-ftpd/pure-ftpd.pid');
if ($opts{'show-options'}) {
print join(' ', @options), "\n";
exit 0;
}
exec { $daemon } ($daemon, @options) or die "$0: Cannot exec $daemon: $!";
sub parse_file {
my ($cref, $file, $option) = @_;
my @lines;
unless (exists $cref->{$option}) {
die "$0: Invalid configuration file $file: No corresponding directive\n";
}
open (FILE, $file)
|| die "$0: Couldn't open configuration file $file: $!\n";
while (<FILE>) {
next unless /\S/;
s/^\s+//;
s/\s+$//;
next if /^\#/;
push (@lines, $_);
}
close (FILE);
# call parser
for my $line (@lines) {
my $buf = '';
if (defined $cref->{$option}->[1]) {
$ret = $cref->{$option}->[1]->(\$buf, $cref->{$option}->[0], $line);
} else {
$ret = parse_yesno(\$buf, $cref->{$option}->[0], $line);
}
unless ($ret) {
die "$0: Invalid configuration file $file: $buf\n";
}
return [$buf, $cref->{$option}->[2] || 0] if length $buf;
}
}
sub parse_filename {
my ($buf, $fmt, $val) = @_;
unless (-f $val) {
$$buf = qq{"$val": No such file};
return;
}
$$buf = sprintf $fmt, $val;
return 1;
}
sub parse_ip {
my ($buf, $fmt, $val) = @_;
if ($val =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/
&& $1 < 256 && $2 < 256 && $3 < 256 && $4 < 256) {
$$buf = sprintf $fmt, $val;
return 1;
}
$$buf = qq{"$val": Invalid IP address};
}
sub parse_number_1 {
my ($buf, $fmt, $val) = @_;
if ($val =~ /\D/) {
$$buf = qq{"$val" not a number};
return;
}
$$buf = sprintf $fmt, $val;
return 1;
}
sub parse_number_1_2 {
my ($buf, $fmt, $val) = @_;
if ($val =~ /^(\d+)(\s+|:)(\d+)$/) {
$$buf = sprintf $fmt, "$1:$3";
return 1;
}
if ($val =~ /^(:?\d+)$/ || $val =~ /^(\d+:)/) {
$$buf = sprintf $fmt, $1;
return 1;
}
$$buf = qq{"$val" not one or two numbers};
return;
}
sub parse_number_2 {
my ($buf, $fmt, $val) = @_;
if ($val !~ /^(\d+)\s+(\d+)$/) {
$$buf = qq{"$val" not two numbers};
return;
}
$$buf = sprintf $fmt, $1, $2;
return 1;
}
sub parse_number_2_unlimited {
my ($buf, $fmt, $val) = @_;
if ($val !~ /^(\-?\d+)\s+(\-?\d+)$/) {
$$buf = qq{"$val" not two numbers};
return;
}
if ($1 < -1 || $2 < -1) {
$$buf = qq{"$val" smaller than unlimited (-1)};
return;
}
$$buf = sprintf $fmt, $1, $2;
return 1;
}
sub parse_sockname {
my ($buf, $fmt, $val) = @_;
unless (-S $val) {
$$buf = qq{"$val": No such socket};
return;
}
$$buf = sprintf $fmt, $val;
return 1;
}
sub parse_string {
my ($buf, $fmt, $val) = @_;
if ($val =~ /\s/) {
$$buf = qq{"$val" contains whitespace};
return;
}
$$buf = sprintf $fmt, $val;
return 1;
}
sub parse_umask {
my ($buf, $fmt, $val) = @_;
if ($val !~ /^([0-7]{3,3})\s+([0-7]{3,3})$/) {
$$buf = qq{"$val" not two octal numbers};
return;
}
$$buf = sprintf $fmt, $1, $2;
return 1;
}
sub parse_word {
my ($buf, $fmt, $val) = @_;
if ($val !~ /^(\w+)$/) {
$$buf = qq{"$val" contains non-word characters};
return;
}
$$buf = sprintf $fmt, $1;
return 1;
}
sub parse_yesno {
my ($buf, $fmt, $val) = @_;
my @y = ('yes', 1, 'on');
my @n = ('no', 0, 'off');
if (grep {$_ eq lc($val)} @y) {
# result is 'yes'
$$buf = $fmt;
return 1;
}
if (grep {$_ eq lc($val)} @n) {
# result is 'no'
$$buf = '';
return 1;
}
# error
$$buf = qq{"$val" not convertible to true or false};
return;
}
__END__
=head1 NAME
pure-ftpd-wrapper - configures and starts Pure-FTPd daemon
=head1 SYNOPSIS
pure-ftpd-wrapper
=head1 DESCRIPTION
B<pure-ftpd-wrapper> reads the configuration for the Pure-FTPd daemon
from files in the directory F</etc/pure-ftpd/conf>. Each file in this
directory is related to a command line option. No more than one
line with configuration values is allowed. Empty lines or lines
starting with the comment character C<#> are discarded.
The Pure-FTPd daemon allows to use different authentication methods
together. The authentication methods are tried in the order they are
specified on the command line. In order to achieve the same flexibility
with files in the F</etc/pure-ftpd> directory, B<pure-ftpd-wrapper>
checks all valid symbolic links within the directory F</etc/pure-ftpd/auth>
in alphabetical order. E.g., a link in this directory pointing to
F</etc/pure-ftpd/conf/PureDB> would enable authentication against
a PureDB database.
There are no means to configure the I<PIDFile> setting, it is hardwired
to /var/run/pure-ftpd/pure-ftpd.pid in this script.
You can display the Pure-FTPd commandline options with C<-s> or
C<--show-options>:
pure-ftpd-wrapper --show-options
=head1 CONFIGURATION
=head2 Boolean values
The strings C<Yes>,C<1>,C<On> enable the corresponding commandline option
(case doesn't matter). To disable the option use C<No>,C<0> or C<Off>.
Configuration files containing boolean values are C<AllowAnonymousFXP>,
C<AllowDotFiles>, C<AllowUserFXP>, C<AnonymousCanCreateDirs>,
C<AnonymousCantUpload>, C<AnonymousOnly>, C<AntiWarez>, C<AutoRename>,
C<BrokenClientsCompatibility>, C<CallUploadScript>, C<ChrootEveryone>,
C<CreateHomeDir>, C<CustomerProof>, C<Daemonize>, C<DisplayDotFiles>,
C<DontResolve>, C<IPV4Only>, C<IPV6Only>, C<KeepAllFiles>, C<LogPID>,
C<NATmode>, C<NoAnonymous>, C<NoChmod>, C<NoRename>, C<NoTruncate>,
C<PAMAuthentication>, C<ProhibitDotFilesRead>, C<ProhibitDotFilesWrite>,
C<UnixAuthentication> and C<VerboseLog>.
=head2 Numerical values
There are several types of numerical values (one number, two numbers,
one or two numbers, two octal numbers).
=over 4
=item One number
C<MaxClientsNumber>, C<MaxClientsPerIP>, C<MaxDiskUsage>, C<MaxIdleTime>,
C<MaxLoad>, C<MinUID>, C<TLS>, C<TrustedGID>.
=item Two numbers
C<AnonymousRatio>, C<LimitRecursion>, C<PassivePortRange>,
C<PerUserLimits>, C<Quota>, C<UserRatio>.
=item Two numbers (with unlimited value)
This allows -1 in addition to positive numbers indicating an unlimited
values.
C<LimitRecursion>.
=item One or two numbers
C<AnonymousBandwidth>, C<UserBandwidth>.
=item Two octal numbers
C<Umask>.
=back
=head2 String values
=over
=item Arbritrary strings
C<AltLog>, C<Bind>, C<ForcePassiveIP>.
=item Words
C<SyslogFacility>.
=back
=head2 Character Sets
C<FSCharset>, C<ClientCharset>.
=head2 IP values
C<TrustedIP>.
=head2 File values
These values designate an existing file or socket.
=over
=item File
C<FortunesFile>, C<LDAPConfigFile>, C<MySQLConfigFile>, C<PGSQLConfigFile>, C<PureDB>.
=item Socket
C<ExtAuth>.
=back
=head1 AUTHOR
This manual page was written by Stefan Hornburg (Racke) <racke@linuxia.de>
for the Debian GNU/Linux system.
|