patches/system-tools-backends-07-time.diff
author rohinis
Tue, 29 Nov 2011 17:32:55 +0000
branchs11express-2010-11
changeset 22234 c23e64da3e06
parent 12148 f6e9b52b2417
permissions -rwxr-xr-x
2011-11-29 Rohini S <[email protected]> * patches/Python26-22-audio.diff: Fixes CVE-2010-1634 * specs/SUNWPython26.spec: Fixes CR 7085446

--- system-tools-backends-1.4.2.orig/time-conf.in	2006-01-02 23:47:30.000000000 +0800
+++ system-tools-backends-1.4.2/time-conf.in	2008-04-17 14:21:37.441179000 +0800
@@ -67,6 +67,7 @@
               "mandrake-7.1", "mandrake-7.2", "mandrake-9.0", "mandrake-9.1", "mandrake-9.2",
               "mandrake-10.0", "mandrake-10.1",
               "debian-2.2", "debian-3.0", "debian-sarge",
+              "nexenta-1.0", "solaris-2.11",
               "suse-7.0", "suse-9.0", "suse-9.1", "turbolinux-7.0",
               "slackware-8.0.0", "slackware-8.1", "slackware-9.0.0", "slackware-9.1.0", "slackware-10.0.0", "slackware-10.1.0", "slackware-10.2.0",
               "gentoo", "vlos-1.2", "pld-1.0", "pld-1.1", "pld-1.99", "fedora-1", "fedora-2", "fedora-3", "rpath",
@@ -79,6 +80,7 @@
 end_of_description;
 
 $progress_max = 365;
+$profile_file =     "profiles.xml";
 
 
 # --- XML parsing --- #
@@ -123,6 +125,8 @@
     if    ($$tree[0] eq "local_time"){ $$hash{"local_time"} = &xml_parse_local_time ($$tree[1]); }
     elsif ($$tree[0] eq "timezone") { $$hash{"timezone"} = &gst_xml_get_word ($$tree[1]); }
     elsif ($$tree[0] eq "sync")     { $$hash{"sync"} = &xml_parse_sync ($$tree[1], $hash); }
+    elsif ($$tree[0] eq "sync_now")     { $$hash{"sync_now"} = &xml_parse_sync ($$tree[1], $hash); }
+    elsif ($$tree[0] eq "profiledb")     { $$hash{"profiledb"} = &xml_parse_profiledb ($tree, $hash); } # zhua
 
     shift @$tree;
     shift @$tree;
@@ -150,6 +154,23 @@
   return \@sync;
 }
 
+sub xml_parse_sync_now
+{
+  my $tree = $_[0];
+  my $hash = $_[1];
+  my @sync_now;
+
+  while (@$tree)
+  {
+    if ($$tree[0] eq "server")  { push (@sync_now, &gst_xml_get_word($$tree[1])); }
+    
+    shift @$tree;
+    shift @$tree;
+  }
+
+  return \@sync_now;
+}
+
 
 sub xml_parse_local_time
 {
@@ -189,7 +210,8 @@
 
   &gst_xml_print_vspace ();
   &gst_xml_print_hash ($$h{"local_time"}, "local_time");
-  &gst_xml_print_vspace ();
+  
+  &xml_print_profiledb($$h{"profiledb"}); #zhua
   
   &gst_xml_print_vspace ();
   &gst_xml_print_line ("<sync active='" . &gst_print_boolean_yesno ($$h{'sync_active'}) . "'>\n");
@@ -213,7 +235,7 @@
 # Main operations
 
 sub get
-{
+{ 
   my $hash;
 
   $hash = &conf_get ();
@@ -225,8 +247,9 @@
 
 sub set
 {
-  my $hash;
 
+  my $hash;
+  
   $hash = &xml_parse ();
 
   &conf_set ($hash);
@@ -277,6 +300,28 @@
   return \%h;
 }
 
+sub time_get_sunos_zone
+{
+  my $zone;
+  local *INFILE;
+
+  *INFILE = &gst_file_open_read_from_names("/etc/default/init");
+  if (not *INFILE) { return; }
+
+  &gst_report ("time_timezone_scan");
+
+  while (<INFILE>)
+  {
+    if (/^TZ\s*=\s*(.*)/)
+    {
+      ($d, $zone) = split /\=/, $_;
+      last;
+    }
+  }
+  close (INFILE);
+  return $zone;
+}
+
 sub time_get_rh62_zone
 {
   my ($local_time_file, $zoneinfo_dir) = @_;
@@ -318,8 +363,8 @@
     $zone = "";
   }
   
-  return $zone;
   close (TZLIST);
+  return $zone;
 }
 
 sub conf_get
@@ -342,7 +387,13 @@
   my ($plat) = $$tool {"system"};
   my ($command);
 
+  my $sunos_table = {
+    "nexenta-1.0"   => "date %02d%02d%02d%02d%04d.%02d",
+    "solaris-2.11"   => "date %02d%02d%02d%02d%04d.%02d"
+  };
+
   my $plat_table = {
+    "SunOS"   => $$sunos_table {$$tool {"platform"}},
     "Linux"   => "date %02d%02d%02d%02d%04d.%02d",
     "FreeBSD" => "date -f %%m%%d%%H%%M%%Y.%%S  %02d%02d%02d%02d%04d.%02d"
   };
@@ -356,6 +407,52 @@
 
   return &gst_file_run ($command);
 }
+# Synchronise time now - moved to backend since it needs root privs.
+sub time_set_sync_now 
+{
+  my ($sync_servers) = @_;
+  my ($plat) = $$tool{"system"};
+
+  &gst_report_enter();
+
+  if ( $plat eq "SunOS" ) {
+    if ( $#$sync_servers >= 0 ) 
+    {
+        $ntp_service_was_active = &gst_service_smf_get_status( "network/ntp" );
+        &gst_service_smf_set_status( "network/ntp", 0 ) if ($ntp_service_was_active);
+        $command = "ntpdate -s ";
+        foreach $server (@$sync_servers)
+        {
+          $command .= "$server ";
+        }
+        &gst_file_run( $command );
+        &gst_service_smf_set_status( "network/ntp", 1 ) if ($ntp_service_was_active);
+    }
+  }
+  else {
+    &gst_file_run("/etc/init.d/ntpdate restart");
+  }
+  &gst_report_leave();
+}
+
+sub time_set_sync_period
+{
+  my ($service, $active) = @_;
+  my ($plat) = $$tool{"system"};
+
+  &gst_report_enter();
+
+  if ( $plat eq "SunOS" ) {
+    $ntp_service_was_active = &gst_service_smf_get_status( $service );
+    if ( $active && $ntp_service_was_active )
+    {
+    	&gst_file_run( "svcadm restart $service" );
+    } else {
+	&gst_service_smf_set_status( $service, $active );
+    }  
+  }
+  &gst_report_leave();
+}
 
 sub time_set_local_time
 {
@@ -378,6 +475,49 @@
   return 0;
 }
 
+sub time_set_sunos_zone
+{
+  my ($localtime, $zonebase, $timezone) = @_;
+  my ($ifh, $ofh);
+  local (*INFILE, *OUTFILE);
+
+  ($ifh, $ofh) = &gst_file_open_filter_write_from_names("/etc/default/init");
+  if (not $ofh) { return; }  # No point if we can't write.
+  *INFILE = $ifh; *OUTFILE = $ofh;
+
+  &gst_report_enter ();
+  &gst_report ("time_timezone_set", $timezone);
+
+  &gst_file_run ("rtc -z $timezone");
+
+  while (<INFILE>)
+  {
+    if (/^TZ\s*=\s*(.*)/) {
+      print OUTFILE "TZ=$timezone\n";
+      next;
+    }
+    print OUTFILE $_;
+  }
+  close OUTFILE;
+  close INFILE;
+
+  # update /etc/localtime too, so unported GNU software will not complain
+  my $tz = "$zonebase/$timezone";
+  if (stat($tz) ne "")
+  {
+    unlink $localtime;  # Important, since it might be a symlink.
+    
+    &gst_report_enter ();
+    $res = copy ($tz, $localtime);
+    &gst_report_leave ();
+    return -1 unless $res;
+    return 0;
+  }
+
+  &gst_report_leave ();
+  return -1;
+}
+
 sub time_set_archlinux_zone
 {
 	my ($localtime, $zonebase, $timezone) =@_;
@@ -442,7 +582,10 @@
 
 sub time_sync_hw_from_sys
 {
-  &gst_file_run ("hwclock --systohc");
+  if ( $$tool{"system"} ne "SunOS" ) 
+  {
+      &gst_file_run ("hwclock --systohc");
+  }
   return 0;
 }
 
@@ -560,6 +703,10 @@
    "debian-3.0"      => "debian-3.0",
    "debian-sarge"    => "debian-3.0",
 
+   "nexenta-1.0"     => "nexenta",
+
+   "solaris-2.11"     => "solaris",
+
    "suse-7.0"        => "suse-7.0",
    "suse-9.0"        => "suse-9.0",
    "suse-9.1"        => "suse-9.0",
@@ -758,7 +905,24 @@
           [ "ntpinstalled", \&gst_service_rcng_installed, [ "ntpd", "openntpd" ]],
           ]
         },
-	
+
+       "solaris" =>
+       {
+         fn =>
+         {
+           NTP_CONF     => "/etc/inet/ntp.conf"
+         },
+         table =>
+         [
+          [ "local_time",   \&time_get_local_time ],
+          [ "timezone",     \&time_get_sunos_zone ],
+          [ "sync",         \&gst_parse_split_all_array_with_pos, NTP_CONF, "server", 0, "[ \t]+", "[ \t]+" ],
+          [ "sync_active",  \&gst_service_smf_get_status, "network/ntp" ],
+          [ "profiledb",   \&read_profiledb], #zhua
+          [ "ntpinstalled", \&gst_service_installed, "network/ntp" ],
+          ]
+        },
+
        "freebsd-5" =>
        {
          fn =>
@@ -813,6 +977,10 @@
    "debian-3.0"      => "debian-3.0",
    "debian-sarge"    => "debian-3.0",
 
+   "nexenta-1.0"     => "nexenta",
+
+   "solaris-2.11"     => "solaris",
+
    "suse-7.0"        => "suse-7.0",
    "suse-9.0"        => "suse-9.0",
    "suse-9.1"        => "suse-9.0",
@@ -859,6 +1027,7 @@
              [
               [ "timezone",    \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
               [ "local_time",  \&time_set_local_time ],
+              [ "sync_now",     \&time_set_sync_now ],
               [ "sync",        \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
               [ "sync_active", \&gst_service_sysv_set_status, 90, "xntpd", "%sync_active%" ],
               ]
@@ -876,6 +1045,7 @@
              [
               [ "timezone",     \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
               [ "local_time",   \&time_set_local_time ],
+              [ "sync_now",     \&time_set_sync_now ],
               [ "sync",         \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
               [ "sync_active",  \&gst_service_sysv_set_status, 90, "ntpd", "%sync_active%" ],
               ]
@@ -893,6 +1063,7 @@
              [
               [ "timezone",    \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
               [ "local_time",  \&time_set_local_time ],
+              [ "sync_now",     \&time_set_sync_now ],
               [ "sync",        \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
               [ "sync_active", \&gst_service_sysv_set_status, 23, "ntp", "%sync_active%" ],
               ]
@@ -912,6 +1083,7 @@
               [ "timezone",    \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
               [ "timezone",    \&gst_replace_line_first, TIMEZONE ],
               [ "local_time",  \&time_set_local_time ],
+              [ "sync_now",     \&time_set_sync_now ],
               [ "sync",        \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
               [ "sync_active", \&gst_service_sysv_set_status, 23, "ntp-server", "%sync_active%" ],
               ]
@@ -929,6 +1101,7 @@
              [
               [ "timezone",     \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
               [ "local_time",   \&time_set_local_time ],
+              [ "sync_now",     \&time_set_sync_now ],
               [ "sync",         \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
               [ "sync_active",  \&gst_service_sysv_set_status, 90, "xntpd", "%sync_active%" ],
               ]
@@ -946,6 +1119,7 @@
          [
           [ "timezone",     \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
           [ "local_time",   \&time_set_local_time ],
+              [ "sync_now",     \&time_set_sync_now ],
           [ "sync",         \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
           [ "sync_active",  \&gst_service_suse_set_status, "xntpd" ],
          ]
@@ -963,6 +1137,7 @@
              [
               [ "timezone",     \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
               [ "local_time",   \&gst_replace_join_all, NTP_CONF, "server", "[ \t]+" ],
+              [ "sync_now",     \&time_set_sync_now ],
               [ "sync_active",  \&gst_service_sysv_set_status, 90, "ntpd", "%sync_active%" ],
               ]
         },
@@ -979,6 +1154,7 @@
          [
           [ "timezone",     \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
           [ "local_time",   \&time_set_local_time ],
+          [ "sync_now",     \&time_set_sync_now ],
           [ "sync",         \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
           [ "sync_active",  \&gst_service_gentoo_set_status, "ntpd", 1, "%sync_active%" ],
           ]
@@ -996,10 +1172,49 @@
          [
           [ "timezone",     \&time_set_archlinux_zone, [LOCAL_TIME, ZONEINFO] ],
           [ "local_time",   \&time_set_local_time ],
+          [ "sync_now",     \&time_set_sync_now ],
           [ "sync",         \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
           [ "sync_active",  \&gst_service_archlinux_set_status, "ntpd", "%sync_active%" ],
          ]
        },
+
+       "nexenta" =>
+       {
+         fn =>
+         {
+           NTP_CONF     => "/etc/inet/ntp.conf",
+           ZONEINFO     => "/usr/share/lib/zoneinfo",
+           LOCAL_TIME    => "/etc/localtime"
+         },
+         table =>
+         [
+          [ "timezone",     \&time_set_sunos_zone, [LOCAL_TIME, ZONEINFO] ],
+          [ "local_time",   \&time_set_local_time ],
+          [ "sync_now",     \&time_set_sync_now ],
+          [ "sync",         \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
+          [ "sync_active",  \&time_set_sync_peroid, "network/ntp", "%sync_active%" ],
+          ]
+        },
+
+       "solaris" =>
+       {
+         fn =>
+         {
+           NTP_CONF     => "/etc/inet/ntp.conf",
+           ZONEINFO     => "/usr/share/lib/zoneinfo",
+           LOCAL_TIME    => "/etc/localtime"
+         },
+         table =>
+         [
+          [ "timezone",     \&time_set_sunos_zone, [LOCAL_TIME, ZONEINFO] ],
+          [ "local_time",   \&time_set_local_time ],
+          [ "sync_now",     \&time_set_sync_now ],
+          [ "sync",         \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
+          [ "profiledb",    \&write_profiledb ], #zhua
+          [ "sync_active",  \&time_set_sync_period, "network/ntp", "%sync_active%" ],
+          ]
+        },
+
        
        "freebsd-5" =>
        {
@@ -1013,6 +1228,7 @@
          [
           [ "timezone",     \&time_set_rh62_zone, [LOCAL_TIME, ZONEINFO] ],
           [ "local_time",   \&time_set_local_time ],
+          [ "sync_now",     \&time_set_sync_now ],
           [ "sync",         \&time_replace_ntp_servers, NTP_CONF, "server", "[ \t]+" ],
           [ "sync_active",  \&gst_service_rcng_set_status, "ntpd", "%sync_active%" ],
           ]
@@ -1026,3 +1242,140 @@
   return undef;
 }
 
+# zhua 
+# add profiledb for ntp server added
+sub read_profiledb
+{
+  my ($hash);
+  my $path;
+  my $servers;
+
+  
+  $path = &gst_file_get_data_path () . "/" . $main::tool->{'name'} . "/" . $profile_file;
+  my $tree = &gst_xml_scan ($path, $tool);
+
+  if ($tree && scalar @$tree)
+  {
+    $servers = &xml_parse_profiledb ($tree, $hash);
+  }
+
+  return $servers;
+}
+
+sub xml_parse_profiledb
+{
+    my ($tree, $hash) = @_;
+    my (@servers);
+
+    if ($$tree[0] eq 'profiledb')
+    {
+      my $svrs = &xml_parse_profile ($$tree[1], $hash);
+      push(@servers, @$svrs);
+    }
+    else
+    {
+      &gst_report ('xml_unexp_tag', $$tree[0]);
+    }
+
+    return \@servers ;
+
+}
+
+sub xml_parse_profile
+{
+  my ($tree, $hash) = @_;
+  my (@servers);
+  
+  shift @$tree; # Skip attributes.
+  
+  while (@$tree)
+  {
+    my $server;
+
+    if ($$tree[0] eq "profile") { $server =  &xml_parse_server ($$tree[1], $hash); }
+    else
+    {
+	&gst_report ("xml_unexp_tag", $$tree[0]);
+    }
+
+    push(@servers, $server) if ( $server );
+
+    shift @$tree;
+    shift @$tree;
+  } 
+  return \@servers;
+}
+
+sub xml_parse_server
+{
+  my ($tree, $hash) = @_;
+  my ($server);
+
+  shift @$tree;  # Skip attributes.
+
+  while (@$tree)
+  {
+    if ($$tree[0] eq "server")
+    {
+	    $server = $$tree[1][2];
+    }
+    else  # files tag is ignored for parsing. # FIXME!
+    {
+	 &gst_report ("xml_unexp_tag", $$tree[0]);
+    }
+
+    shift @$tree;
+    shift @$tree; 
+            
+   }     
+   return $server;
+}    
+
+sub write_profiledb
+{
+  my ($profiledb) = @_;
+
+  unless ($profiledb)
+  {
+    &gst_report ('users_write_profiledb_fail');
+    return;
+  }
+
+  # Write our profiles.
+  my $path = &gst_file_get_data_path () . "/" . $main::tool->{'name'} . "/" . $profile_file;
+  my $fh = &gst_file_open_write_from_names ($path);
+  if ($fh)
+  {
+    local *STDOUT = $fh;
+
+    &xml_print_profiledb( $profiledb );
+
+    close ($fh);
+    &gst_report ('users_write_profiledb_success');
+  }
+  else
+  {
+    &gst_report ('users_write_profiledb_fail');
+  }
+}
+
+sub xml_print_profiledb
+{
+  my ($profiledb) = @_;
+
+  return unless (scalar @$profiledb);
+
+  &gst_xml_container_enter ('profiledb');
+
+  foreach my $profile (@$profiledb)
+  {
+    my $key;
+    &gst_xml_container_enter ('profile');
+	&gst_xml_print_pcdata("server", $profile);
+    &gst_xml_container_leave ();
+  }
+
+  &gst_xml_container_leave ();
+  &gst_xml_print_vspace ();
+}
+