3 # Returns a list of services from the services file, each being an array of
4 # line name port protocol aliases index
9 system("$config{'get_services_command'}") if ($config{'get_services_command'});
10 open(SERVICES, $config{services_file});
13 if (/^(\S+)\s+([0-9]+)\/(\S+)\s*(.*)$/) {
14 push(@rv, [ $l, $1, $2, $3, $4, scalar(@rv) ]);
15 if ($config{'ipv6'}) {
16 push(@rv, [ $l, $1, $2, $3.'6', $4, scalar(@rv) ]);
25 # create_service(name, port, proto, aliases)
26 # Add a new service to the list
30 if ($config{'ipv6'} && $p =~ /^(\S+)6$/) {
31 # don't add the service if it is already there
32 foreach $s (&list_services()) {
33 return if ($s->[1] eq $_[0] && $s->[2] == $_[1] &&
38 &open_tempfile(SERVICES, ">> $config{services_file}");
39 &print_tempfile(SERVICES, "$_[0]\t$_[1]/$p",$_[3] ? "\t$_[3]\n" : "\n");
40 &close_tempfile(SERVICES);
41 system("$config{'put_services_command'}") if ($config{'put_services_command'});
45 # modify_service(line, name, port, proto, aliases)
46 # Change an existing service
50 open(SERVICES, $config{services_file});
53 $serv[$_[0]] = "$_[1]\t$_[2]/$_[3]".($_[4] ? "\t$_[4]\n" : "\n");
54 &open_tempfile(SERVICES, "> $config{services_file}");
55 &print_tempfile(SERVICES, @serv);
56 &close_tempfile(SERVICES);
57 system("$config{'put_services_command'}") if ($config{'put_services_command'});
60 # delete_service(line)
64 open(SERVICES, $config{services_file});
67 splice(@serv, $_[0], 1);
68 &open_tempfile(SERVICES, "> $config{services_file}");
69 &print_tempfile(SERVICES, @serv);
70 &close_tempfile(SERVICES);
71 system("$config{'put_services_command'}") if ($config{'put_services_command'});
75 # Returns a list of supported protocols on this system
79 open(PROT, $config{protocols_file});
85 if ($config{'ipv6'}) {
86 if ($1 eq 'tcp') { push(@rv, 'tcp6'); }
87 elsif ($1 eq 'udp') { push(@rv, 'udp6'); }
95 # Returns a list of service details handled by inetd. RPC services
96 # will have a name like foo/1 or bar/1-3, where the thing after the / is
97 # the version or versions supported. For each service, the list contains
98 # line active? rpc? name type protocol wait user path|internal args file
101 # build list of inetd files
102 local (@files, @rv, $l);
103 @files = ( $config{'inetd_conf_file'} );
104 opendir(DIR, $config{'inetd_dir'});
105 foreach $f (readdir(DIR)) {
106 next if ($f =~ /^\./);
107 push(@files, "$config{'inetd_dir'}/$f");
112 foreach $f (@files) {
117 if (/^(#+|#<off>#)?\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\??\/\S+|internal)\s*(.*)$/) {
118 push(@rv, [ $l, !$1, 0, $2, $3, $4,
119 $5, $6, $7, $8, $f ]);
120 $rv[$#rv]->[2] = ($2 =~ /\//);
129 # create_inet(enabled, name, type, protocol, wait, user, program, args)
130 # Add a new service to the main inetd config file
133 &open_tempfile(INET, ">> $config{inetd_conf_file}");
134 &print_tempfile(INET,
135 ($_[0] ? "" : "#")."$_[1]\t$_[2]\t$_[3]\t$_[4]\t$_[5]\t$_[6]".
136 ($_[7] ? "\t$_[7]\n" : "\n"));
137 &close_tempfile(INET);
141 # modify_inet(line, enabled, name, type, protocol,
142 # wait, user, program, args, file)
143 # Modify an existing inetd service
150 $inet[$_[0]] = ($_[1] ? "" : "#")."$_[2]\t$_[3]\t$_[4]\t$_[5]\t$_[6]\t$_[7]".
151 ($_[8] ? "\t$_[8]\n" : "\n");
152 &open_tempfile(INET, ">$_[9]");
153 &print_tempfile(INET, @inet);
154 &close_tempfile(INET);
158 # delete_inet(line, file)
159 # Delete an internet service at some line
166 splice(@inet, $_[0], 1);
167 &open_tempfile(INET, ">$_[1]");
168 &print_tempfile(INET, @inet);
169 &close_tempfile(INET);
172 %prot_name = ("ip", "Internet Protocol",
173 "tcp", "Transmission Control Protocol",
174 "udp", "User Datagram Protocol",
175 "tcp6", "Transmission Control Protocol IPv6",
176 "udp6", "User Datagram Protocol IPv6");