1
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3
# NTP Configuration handling
5
# Copyright (C) 2000-2001 Ximian, Inc.
7
# Authors: Hans Petter Jansson <hpj@ximian.com>
8
# Carlos Garnacho <carlosg@gnome.org>
10
# This program is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU Library General Public License as published
12
# by the Free Software Foundation; either version 2 of the License, or
13
# (at your option) any later version.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU Library General Public License for more details.
20
# You should have received a copy of the GNU Library General Public License
21
# along with this program; if not, write to the Free Software
22
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
26
sub get_config_file ()
30
"redhat-6.2" => "redhat-6.2",
31
"redhat-7.0" => "redhat-6.2",
32
"redhat-7.1" => "redhat-6.2",
33
"redhat-7.2" => "redhat-6.2",
34
"redhat-7.3" => "redhat-6.2",
35
"redhat-8.0" => "redhat-6.2",
36
"mandrake-9.0" => "redhat-6.2",
37
"debian" => "redhat-6.2",
38
"suse-9.0" => "redhat-6.2",
39
"slackware-9.1.0" => "redhat-6.2",
40
"gentoo" => "redhat-6.2",
41
"pld-1.0" => "pld-1.0",
42
"vine-3.0" => "redhat-6.2",
43
"freebsd-5" => "redhat-6.2",
44
"archlinux" => "redhat-6.2",
45
"solaris-2.11" => "solaris-2.11",
50
"redhat-6.2" => "/etc/ntp.conf",
51
"pld-1.0" => "/etc/ntp/ntp.conf",
52
"solaris-2.11" => "/etc/inet/ntp.conf",
55
my $dist = $dist_map{$Utils::Backend::tool{"platform"}};
56
return $dist_table{$dist} if $dist;
58
&Utils::Report::do_report ("platform_no_table", $$tool{"platform"});
64
$ntp_conf = &get_config_file ();
66
return &Utils::Parse::split_all_array_with_pos ($ntp_conf, "server", 0, "[ \t]+", "[ \t]+");
71
my ($file, $key, $re, $value) = @_;
72
my ($fd, @line, @res);
74
my ($pre_space, $post_comment);
75
my ($line_key, $val, $rest);
78
&Utils::Report::enter ();
79
&Utils::Report::do_report ("replace_split", $key, $file);
81
$buff = &Utils::File::load_buffer ($file);
85
$pre_space = $post_comment = "";
89
$pre_space = $1 if $i =~ s/^([ \t]+)//;
90
$post_comment = $1 if $i =~ s/([ \t]*\#.*)//;
94
@line = split ($re, $i, 3);
95
$line_key = shift (@line);
97
$rest = shift (@line);
100
if ($line_key eq $key)
104
while (@$value[$n] && (@$value[$n] ne $val))
109
if (@$value[$n] ne $val)
117
$i = &Utils::Replace::set_value ($key, $val, $re) . " " . $rest;
121
$i = $pre_space . $i . $post_comment . "\n";
126
push (@$buff, &Utils::Replace::set_value ($key, $i, $re) . "\n") if ($i ne "");
129
&Utils::File::clean_buffer ($buff);
130
$ret = &Utils::File::save_buffer ($buff, $file);
131
&Utils::Report::leave ();
140
$ntp_conf = &get_config_file ();
141
return &ntp_conf_replace ($ntp_conf, "server", "[ \t]+", @config);
147
my ($servers, $server);
149
foreach $server (@$config) {
150
$servers .= " $server";
154
# There are no servers, pick them from the ntp.org pool
155
$server = "0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org";
158
# run ntpdate, this will only be effective
159
# when there isn't any NTP server running
160
&Utils::File::run ("ntpdate", "-b", $servers) if ($servers);
165
return &get_ntp_servers ();
170
&apply_ntp_date (@_);
171
return &set_ntp_servers (@_);
178
push @$files, &get_config_file ();