%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /sbin/
Upload File :
Create Path :
Current File : //sbin/update-inetd

#!/usr/bin/perl
#
# update-inetd: a utility to add entries to the /etc/inetd.conf file
#
# Copyright © 1995 Peter Tobias <tobias@et-inf.fho-emden.de>
# Copyright © 2009-2012  Serafeim Zanikolas <sez@debian.org>
# Copyright © 2018 Guillem Jover <guillem@debian.org>
#
# 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, see <https://www.gnu.org/licenses/>.

use 5.000;
use strict;
use warnings;

use DebianNet ();

# We need to preserve the original @ARGV, otherwise when the Debconf module
# tries to reexecute us after it has started the backend it would miss
# arguments.
@DebianNet::DEBCONF_ARGV = @ARGV;

$| = 1;

$0 =~ s{.*/}{};
my $version = '4.51';
my $debug;
my $mode;
my $modearg;
my $pattern;
my $group;

while ($ARGV[0] =~ m/^-/) {
    $_ = shift @ARGV;
    if (/--help$/) {
        usage();
    } elsif (/--version$/) {
        version();
    } elsif (/--add$/) {
        $mode = 'add';
    } elsif (/--remove$/) {
        $mode = 'remove';
    } elsif (/--enable$/) {
        $mode = 'enable';
    } elsif (/--disable$/) {
        $mode = 'disable';
    } elsif (/--multi$/) {
        $DebianNet::MULTI = 'true';
    } elsif (/--verbose$/) {
        $DebianNet::VERBOSE = 'true';
    } elsif (/--debug$/) {
        $debug = 'true';
    } elsif (/--file$/) {
        my $file = shift @ARGV;
        error("option '--file' requires an argument")
            if not $file or $file =~ m/^--/;
        $DebianNet::INETD_CONF = $file;
    } elsif (/--group$/) {
        $group = shift @ARGV;
        error("option '--group' requires an argument")
            if not $group or $group =~ m/^--/;
    } elsif (/--comment-chars$/) {
        my $sep = shift @ARGV;
        error("option '--comment-chars' requires an argument") unless $sep;
        error("the comment characters do not start with a '#'") unless $sep =~ /^#/;
        $DebianNet::SEP = $sep;
    } elsif (/--pattern$/) {
        $pattern = shift @ARGV;
        error("option '--pattern' requires an argument")
            if not $pattern or $pattern =~ m/^--/;
    } else {
        warning("unknown option: $_");
        warning("try '$0 --help' for more information.");
        exit 1;
    }
}

usage() unless $mode;

if (defined $group and $mode ne 'add') {
    warning('--group is only relevant with --add');
}
$group //= 'OTHER';

if (defined $pattern and $mode eq 'add') {
    warning('--pattern is not relevant with --add');
}
$pattern //= '';

# die "You must be root to run this script.\n" if ($> != 0);

if ($#ARGV > 0) {
    warning('too many arguments');
} elsif ($#ARGV == -1) {
    warning('too few arguments');
} else {
    $modearg = $ARGV[0];
    error('the service name may not include whitespace characters')
        if ($mode eq 'enable' or $mode eq 'disable') and ($modearg =~ /\s+|\\t/);
    error('the entry definition does not contain any whitespace characters')
        if $mode eq 'add' and not ($modearg =~ /\s+|\\t/);
}

warn "Processing $DebianNet::INETD_CONF\n" if defined $DebianNet::VERBOSE;
debug("Using mode \"$mode\", group \"$group\", pattern \"$pattern\" and seperator \"$DebianNet::SEP\"");
debug("Multiple remove/disable: $DebianNet::MULTI") if defined $DebianNet::MULTI;
debug("ARGUMENT: $modearg");

if ($mode eq 'add') {
    DebianNet::add_service($modearg, $group);
} elsif ($mode eq 'remove') {
    DebianNet::remove_service($modearg, $pattern);
} elsif ($mode eq 'enable') {
    foreach my $service (split /,/, $modearg) {
        DebianNet::enable_service($service, $pattern);
    }
} elsif ($mode eq 'disable') {
    foreach my $service (split /,/, $modearg) {
        DebianNet::disable_service($service, $pattern);
    }
} else {
    die "Mode = '$modearg'? This should not happen!\n";
}

sub debug {
    my $msg = shift;

    warn "$msg\n" if $debug;
}

sub warning {
    my $msg = shift;

    warn "$0: warning: $msg\n";
}

sub error {
    my $msg = shift;

    die "$0: error: $msg\n";
}

sub version {
    warn "$0 $version\n";
    warn "DebianNet module $DebianNet::VERSION\n";
    exit 0;
}

sub usage {
    warn <<"EOF";
Usage: $0 [<option>...] <command> <argument>

Commands:
  --add <entry-line>              add <entry-line>
  --remove <entry-regex>          remove <entry-regex>
  --enable <service>[,...]        enable <service> (comma-separated list)
  --disable <service>[,...]       disable <service> (comma-separated list)

Options:
  --group <group-name>            add entry to section <group-name>
  --pattern <pattern>             use <pattern> to select a service
  --comment-chars <characters>    use <characters> as comment characters
  --multi                         allow multiple removes/disables
  --file <filename>               use <filename> instead of /etc/inetd.conf
  --verbose                       explain what is being done
  --debug                         enables debugging mode
  --help                          display this help and exit
  --version                       output version information and exit

In order to prevent the shell from changing your <entry-line> definition you
have to quote the <entry-line> using single or double quotes. You can use tabs
(tab character or \\t) and spaces to separate the fields of the <entry-line>.

Note: users must use --comment-chars '#' to disable a service for that setting
to survive upgrades. Package maintainer scripts should use the default
--comment-chars. See update-inetd(8) for details.

EOF
    exit 0;
}

Zerion Mini Shell 1.0