3 # update-inetd: a utility to add entries to the /etc/inetd.conf file
5 # Copyright (C) 1995 Peter Tobias <tobias@et-inf.fho-emden.de>
7 # update-inetd is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published
9 # by the Free Software Foundation; either version 2 of the License,
10 # or (at your option) any later version.
12 # update-inetd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with update-inetd; if not, write to the Free Software Foundation,
19 # Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 # hack to make update-inetd work in a script which calls debconf
26 if($ENV{DEBIAN_HAS_FRONTEND}) {
27 my $file = ($ENV{DEBIAN_FRONTEND} eq 'noninteractive') ?
28 '/dev/null' : '/dev/tty'; # see 4.13 changelog entry
29 open(STDIN, "<$file") or die "Couldn't reopen stdin($file): $!";
30 open(STDOUT, ">$file") or die "Couldn't reopen stdout($file): $!";
31 open(STDERR, ">$file") or die "Couldn't reopen stderr($file): $!";
40 while ($ARGV[0] =~ m/^-/) {
44 } elsif (/--version$/) {
48 } elsif (/--remove$/) {
50 } elsif (/--enable$/) {
52 } elsif (/--disable$/) {
54 } elsif (/--multi$/) {
55 $DebianNet::multi = "true";
56 } elsif (/--verbose$/) {
57 $DebianNet::verbose = "true";
58 } elsif (/--debug$/) {
62 die "$0: Option \`--file' requires an argument\n" unless ($file and not ($file =~ m/^--/));
63 $DebianNet::inetdcf = $file;
64 } elsif (/--group$/) {
65 $group = shift(@ARGV);
66 die "$0: Option \`--group' requires an argument\n" unless ($group and not ($group =~ m/^--/));
67 } elsif (/--comment-chars$/) {
69 die "$0: Option \`--comment-chars' requires an argument\n" unless ($sep);
70 die "$0: The comment characters do not start with a \`#'!\n" unless ($sep =~ /^#/);
71 $DebianNet::sep = $sep;
72 } elsif (/--pattern$/) {
73 $pattern = shift(@ARGV);
74 die "$0: Option \`--pattern' requires an argument\n" unless ($pattern and not ($pattern =~ m/^--/));
76 print "$0: Unknown option: $_\n";
77 print "Try \`$0 --help' for more information.\n";
82 $group = "OTHER" unless ($group);
86 # die "You must be root to run this script.\n" if ($> != 0);
89 print "Too many arguments!\n";
90 } elsif ($#ARGV == -1) {
91 print "Too few arguments!\n";
94 die "The service name may not include a whitespace character!\n" if (($mode eq "enable" or $mode eq "disable") and ($modearg =~ /\s+|\\t/));
95 die "The entry definition does not contain any whitespace characters!\n" if ($mode eq "add" and not ($modearg =~ /\s+|\\t/));
98 print "Processing $DebianNet::inetdcf\n" if (defined($DebianNet::verbose));
99 print "Using mode \"$mode\", group \"$group\", pattern \"$pattern\" and seperator \"$DebianNet::sep\"\n" if (defined($debug));
100 print "Multiple remove/disable: $DebianNet::multi\n" if (defined($debug) and defined($DebianNet::multi));
101 print "ARGUMENT: $modearg\n" if (defined($debug));
103 if ($mode eq "add") {
104 if (( -f "/etc/xinetd.conf" ) && ( -x "/usr/sbin/xinetd" )) {
105 print "--------- IMPORTANT INFORMATION FOR XINETD USERS ----------\n";
106 print "The following line will be added to your /etc/inetd.conf file:\n\n";
107 print "$modearg\n\n";
108 print "If you are indeed using xinetd, you will have to convert the\n";
109 print "above into /etc/xinetd.conf format, and add it manually. See\n";
110 print "/usr/share/doc/xinetd/README.Debian for more information.\n";
111 print "-----------------------------------------------------------\n\n";
114 DebianNet::add_service($modearg, $group);
115 } elsif ($mode eq "remove") {
116 DebianNet::remove_service($modearg);
117 } elsif ($mode eq "enable") {
118 @arglst = split(/,/, $modearg);
121 DebianNet::enable_service($_, $pattern);
123 } elsif ($mode eq "disable") {
124 @arglst = split(/,/, $modearg);
127 DebianNet::disable_service($_, $pattern);
130 die "Mode = \`$modearg'? This should not happen!\n";
134 print "$0 $version\n";
135 print "DebianNet module $DebianNet::version\n";
141 Usage: $0 [OPTION] MODE ARGUMENT
144 --version output version information and exit
145 --help display this help and exit
146 --verbose explain what is being done
147 --debug enables debugging mode
148 --multi allow multiple removes/disables
149 --file FILENAME use FILENAME instead of /etc/inetd.conf
150 --group GROUPNAME add entry to section GROUPNAME
151 --comment-chars CHARACTERS use CHARACTERS as comment characters
152 --pattern PATTERN use PATTERN to select a service
155 --add ENTRY add ENTRY to $DebianNet::inetdcf
156 --remove ENTRY remove ENTRY (regular expression)
157 --enable SERVICE enable SERVICE in $DebianNet::inetdcf
158 --disable SERVICE disable SERVICE in $DebianNet::inetdcf
160 In order to prevent the shell from changing your ENTRY definition
161 you have to quote the ENTRY using single or double quotes. You can
162 use tabs (the tab character or \\t) and spaces to separate the fields
163 of the ENTRY. If you want to enable/disable more than one SERVICE you
164 can use a comma separated list of services (no whitespace characters