xconv.pl updates
[packages/xinetd.git] / xinetd / xconv.pl
1 #!/usr/bin/perl
2 #/*
3 # * (c) Copyright 1998-2001 by Rob Braun
4 # * All rights reserved.  The file named COPYRIGHT specifies the terms
5 # * and conditions for redistribution.
6 # */
7
8 # $RCSid = "$Id: xconv.pl,v 1.3 2005/03/29 15:50:34 bbraun Exp $";
9
10 sub print_header;
11 sub print_defaults;
12
13
14 print_header;
15 print_defaults;
16
17 while( <STDIN> ) {
18
19         $disable = 0;                                   # Default to 'enable'
20
21         chomp;
22
23         # Check for disable before we check for comments
24         if (m/^\#<off>\#/i) {
25                 s/^.*?\s//;
26                 $disable = 1;
27         }
28
29         # Remove comment lines
30         if( grep /^#/, $_ ) {
31                 next;
32         }
33
34         @command = split ;
35
36         if( !defined $command[0] ) {
37                 next;
38         }
39
40         if( grep /rpc/, $command[2] ) {
41                 print STDERR "Warning: Service $command[0] not added because\n";
42                 print STDERR "xinetd does not handle rpc services well\n";
43                 next;
44         }
45
46         print "service $command[0]\n";
47         print "{\n";
48         print "\tsocket_type = $command[1]\n";
49         print "\tprotocol    = $command[2]\n";
50         if( $command[0] =~ /^\d+$/ ) {
51                 print "\tport        = $command[0]\n";
52                 print "\ttype        = UNLISTED\n";
53         }
54         if( grep /no/, $command[3] ) {
55                 print "\twait        = no\n";
56         } else {
57                 print "\twait        = yes\n";
58         }
59         @user = split /[:\.]/, $command[4];
60         print "\tuser        = $user[0]\n";
61         if( defined $user[1] ) {
62                 print "\tgroup       = $user[1]\n";
63         }
64         # Amanda is a special case, it needs this, see
65         # http://www.amanda.org/docs/install.html and 
66         # Bug report #167367
67         if ( $command[6] =~ /(amandad|amindexd|amidxtaped)/ ) {
68                 print "\tgroups      = yes\n";
69         }
70         if( grep /internal/, $command[5] ) {
71                 print "\ttype        = INTERNAL\n";
72                 print "\tid          = $command[0]-$command[1]\n";
73         } elsif ( $command[5] =~ /\/usr\/sbin\/tcpd/ ){
74         # Tcp wrapping is already implemented in xinetd
75                 print "\tserver      = $command[6]\n";
76                 if ( defined $command[7] ) {
77                         print "\tserver_args = ";
78                         $i = 7;
79                         while( defined $command[$i] ) {
80                                 print "$command[$i] ";
81                                 $i++;
82                         }
83                         print "\n";
84                 }
85         
86         } else {
87                 print "\tserver      = $command[5]\n";
88                 print "\tserver_args = ";
89
90                 $i = 6;
91                 while( defined $command[$i] ) {
92                         print "$command[$i] ";
93                         $i++;
94                 }
95
96                 print "\n";
97         }
98
99         if ($disable) {
100                 print "\tdisable     = yes\n";
101         }
102
103         print "}\n";
104         print "\n";
105 }
106
107 sub print_defaults
108 {
109         print "# The defaults section sets some information for all services\n";
110         print "defaults\n";
111         print "{\n";
112         print "\t#The maximum number of requests a particular service may handle\n";
113         print "\t# at once.\n";
114         print "\tinstances   = 25\n";
115         print "\n";
116         print "\t# The type of logging.  This logs to a file that is specified.\n";
117         print "\t# Another option is: SYSLOG syslog_facility [syslog_level]\n";
118         print "\tlog_type    = FILE /var/log/servicelog\n";
119         print "\n";
120         print "\t# What to log when the connection succeeds.\n";
121         print "\t# PID logs the pid of the server processing the request.\n";
122         print "\t# HOST logs the remote host's ip address.\n";
123         print "\t# USERID logs the remote user (using RFC 1413)\n";
124         print "\t# EXIT logs the exit status of the server.\n";
125         print "\t# DURATION logs the duration of the session.\n";
126         print "\tlog_on_success = HOST PID\n";
127         print "\n";
128         print "\t# What to log when the connection fails.  Same options as above\n";
129         print "\tlog_on_failure = HOST\n";
130         print "\n";
131         print "\t# The maximum number of connections a specific IP address can\n";
132         print "\t# have to a specific service.  \n";
133         print "\tper_source  = 5\n";
134
135         print "}\n";
136         print "\n";
137 }
138
139 sub print_header
140 {
141         print "# This file generated by xconv.pl, included with the xinetd\n";
142         print "# package.  xconv.pl was written by Rob Braun (bbraun\@synack.net)\n";
143         print "#\n";
144         print "# The file is merely a translation of your inetd.conf file into\n";
145         print "# the equivalent in xinetd.conf syntax.  xinetd has many \n";
146         print "# features that may not be taken advantage of with this translation.\n";
147         print "# Please refer to the xinetd.conf man page for more information \n";
148         print "# on how to properly configure xinetd.\n";
149         print "\n";
150         print "\n";
151 }