home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / sbin / update-inetd < prev    next >
Encoding:
Text File  |  2006-07-20  |  6.2 KB  |  171 lines

  1. #!/usr/bin/perl
  2. #
  3. # update-inetd: a utility to add entries to the /etc/inetd.conf file
  4. #
  5. # Copyright (C) 1995 Peter Tobias <tobias@et-inf.fho-emden.de>
  6. #
  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.
  11. #
  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.
  16. #
  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.
  20. #
  21.  
  22. require 5.000;
  23. require DebianNet;
  24.  
  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): $!";
  32. }
  33.  
  34. $| = 1;
  35.  
  36. $version = "1.12";
  37.  
  38. $0 =~ s#.*/##;
  39.  
  40. while ($ARGV[0] =~ m/^-/) {
  41.     $_ = shift(@ARGV);
  42.     if (/--help$/) {
  43.         &usage;
  44.     } elsif (/--version$/) {
  45.         &version;
  46.     } elsif (/--add$/) {
  47.         $mode="add";
  48.     } elsif (/--remove$/) {
  49.         $mode="remove";
  50.     } elsif (/--enable$/) {
  51.         $mode="enable";
  52.     } elsif (/--disable$/) {
  53.         $mode="disable";
  54.     } elsif (/--multi$/) {
  55.         $DebianNet::multi = "true";
  56.     } elsif (/--verbose$/) {
  57.         $DebianNet::verbose = "true";
  58.     } elsif (/--debug$/) {
  59.         $debug = "true";
  60.     } elsif (/--file$/) {
  61.         $file = shift(@ARGV);
  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$/) {
  68.         $sep = shift(@ARGV);
  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/^--/));
  75.     } else {
  76.         print "$0: Unknown option: $_\n";
  77.         print "Try \`$0 --help' for more information.\n";
  78.         exit(1);
  79.     }
  80. }
  81.  
  82. $group = "OTHER" unless ($group);
  83.  
  84. &usage unless($mode);
  85.  
  86. # die "You must be root to run this script.\n" if ($> != 0);
  87.  
  88. if ($#ARGV > 0) {
  89.     print "Too many arguments!\n";
  90. } elsif ($#ARGV == -1) {
  91.     print "Too few arguments!\n";
  92. } else {
  93.     $modearg = $ARGV[0];
  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/));
  96. }
  97.  
  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));
  102.  
  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";
  112.     }
  113.  
  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);
  119.     while(@arglst) {
  120.         $_ = shift(@arglst);
  121.         DebianNet::enable_service($_, $pattern);
  122.     }
  123. } elsif ($mode eq "disable") {
  124.     @arglst = split(/,/, $modearg);
  125.     while(@arglst) {
  126.         $_ = shift(@arglst);
  127.         DebianNet::disable_service($_, $pattern);
  128.     }
  129. } else {
  130.     die "Mode = \`$modearg'? This should not happen!\n";
  131. }
  132.  
  133. sub version {
  134.     print "$0 $version\n";
  135.     print "DebianNet module $DebianNet::version\n";
  136.     exit(0);
  137. }
  138.  
  139. sub usage {
  140.     print <<EOF;
  141. Usage: $0 [OPTION] MODE ARGUMENT
  142.  
  143. Options:
  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
  153.  
  154. Modes:
  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
  159.  
  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
  165. allowed).
  166.  
  167. EOF
  168.     exit(0);
  169. }
  170.  
  171.