3 # Setup the CVS server in inetd or xinetd
5 require './pserver-lib.pl';
7 $access{'setup'} || &error($text{'setup_ecannot'});
8 $inet = &check_inetd();
9 $restart = $inet->{'type'} if ($inet);
10 %xconfig = &foreign_config("xinetd");
11 %iconfig = &foreign_config("inetd");
13 # Need to setup for the first time .. first construct the CVS command
15 foreach $r (split(/\t+/, $config{'cvsroot'})) {
16 $cmd .= " --allow-root $r";
21 # Just add an unlisted service
22 &lock_file($xconfig{'xinetd_conf'});
23 $xinet = { 'name' => 'service',
24 'values' => [ $cvs_inet_name ] };
25 &xinetd::set_member_value($xinet, "port", $cvs_port);
26 &xinetd::set_member_value($xinet, "socket_type", "stream");
27 &xinetd::set_member_value($xinet, "protocol", "tcp");
28 &xinetd::set_member_value($xinet, "user", $in{'user'});
29 &xinetd::set_member_value($xinet, "wait", "no");
30 &xinetd::set_member_value($xinet, "disable", "no");
31 &xinetd::set_member_value($xinet, "type", "UNLISTED");
32 &xinetd::set_member_value($xinet, "server", $cvs_path);
33 &xinetd::set_member_value($xinet, "server_args", $cmd);
34 &xinetd::create_xinet($xinet);
35 &unlock_file($xconfig{'xinetd_conf'});
39 # Is there already a service on port 2401, or named cvspserver?
40 &lock_file($iconfig{'services_file'});
41 &lock_file($iconfig{'inetd_conf_file'});
42 foreach $s (&inetd::list_services()) {
43 local @al = split(/\s+/, $s->[4]);
44 if ($s->[2] == $cvs_port ||
45 $s->[1] eq $cvs_inet_name ||
46 &indexof($cvs_inet_name, @al) >= 0) {
53 $sname = $cvs_inet_name;
54 &inetd::create_service($sname, $cvs_port, "tcp", undef);
56 &inetd::create_inet(1, $sname, "stream", "tcp", "nowait",
57 $in{'user'}, $cvs_path, "cvs $cmd");
58 &unlock_file($iconfig{'services_file'});
59 &unlock_file($iconfig{'inetd_conf_file'});
63 &error($text{'setup_einet'});
67 elsif ($inet->{'active'}) {
69 if ($inet->{'type'} eq 'inetd') {
70 local @i = @{$inet->{'inetd'}};
72 &inetd::modify_inet($i[0], 0, $i[3], $i[4], $i[5],
73 $i[6], $i[7], $i[8], $i[9], $i[10]);
77 local $x = $inet->{'xinetd'};
78 &lock_file($x->{'file'});
79 &xinetd::set_member_value($x, "disable", "yes");
80 &xinetd::modify_xinet($x);
81 &unlock_file($x->{'file'});
86 # Need to activate, possibly updating CVS root and user
87 if ($inet->{'type'} eq 'inetd') {
88 local @i = @{$inet->{'inetd'}};
90 if ($i[9] =~ /^(.*)\s(\/\S+)\s+pserver$/) {
92 $i[9] = "$1 $config{'cvsroot'} pserver";
94 &inetd::modify_inet($i[0], 1, $i[3], $i[4], $i[5],
95 $i[6], $in{'user'}, $i[8], $i[9], $i[10]);
99 local $x = $inet->{'xinetd'};
100 &lock_file($x->{'file'});
101 &xinetd::set_member_value($x, "disable", "no");
102 &xinetd::set_member_value($x, "user", $in{'user'});
103 if ($x->{'quick'}->{'server_args'}->[0] =~
104 /^(.*)\s(\/\S+)\s+pserver$/) {
106 &xinetd::set_member_value($x, "server_args",
107 "$1 $config{'cvsroot'} pserver");
109 &xinetd::modify_xinet($x);
110 &unlock_file($x->{'file'});
115 # Restart inetd or xinetd
116 if ($restart eq "inetd") {
118 "$iconfig{'restart_command'} >/dev/null 2>&1 </dev/null");
121 if (open(PID, $xconfig{'pid_file'})) {
124 &kill_logged('USR2', $pid);