patches/system-tools-backends-05-services.diff
author rohinis
Tue, 29 Nov 2011 17:32:55 +0000
branchs11express-2010-11
changeset 22234 c23e64da3e06
parent 11797 7784792b3624
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

diff -u system-tools-backends-1.4.2/services-conf.in-orig system-tools-backends-1.4.2/services-conf.in
--- system-tools-backends-1.4.2/services-conf.in-orig	2006-01-02 23:32:34.000000000 +0800
+++ system-tools-backends-1.4.2/services-conf.in	2007-11-14 16:37:05.174308000 +0800
@@ -35,7 +35,6 @@
   require "$SCRIPTSDIR/general.pl$DOTIN";
   require "$SCRIPTSDIR/platform.pl$DOTIN";
   require "$SCRIPTSDIR/service.pl$DOTIN";
-  require "$SCRIPTSDIR/print.pl$DOTIN";
 }
 
 # --- Tool information --- #
@@ -51,6 +50,7 @@
               
               "debian-2.2", "debian-3.0", "debian-sarge",
 
+	          "nexenta-1.0", "solaris-2.11",
               "suse-7.0", "turbolinux-7.0", "fedora-1", "fedora-2", "fedora-3", "rpath",
               "pld-1.0", "pld-1.1", "pld-1.99",
               "slackware-9.1.0", "slackware-10.0.0", "slackware-10.1.0", "slackware-10.2.0",
@@ -91,6 +91,7 @@
   {
     if ($elem eq "runlevels") { $runlevel = &xml_parse_runlevel_list (shift @$tree)}
     elsif ($elem eq "services") { push @$services, &xml_parse_service_list (shift @$tree); }
+    elsif ($elem eq "longname") { shift @$tree; }
     else { &gst_report ("xml_unexp_tag", $elem); shift @$tree; }
   }
 
@@ -173,6 +174,7 @@
     elsif ($elem eq "role") { shift @$tree }
     elsif ($elem eq "runlevels") { push @$runlevels, &xml_parse_runlevels (shift @$tree); }
     elsif ($elem eq "script") { $$hash{"script"} = &gst_xml_get_pcdata (shift @$tree); }
+    elsif ($elem eq "longname") { shift @$tree; }
     else { &gst_report ("xml_unexp_tag", $elem); shift @$tree; }
   }
   
@@ -260,6 +262,7 @@
 sub xml_print_runlevels
 {
   my ($h, $default) = @_;
+  &gst_xml_print_pcdata ("longname", $i);
   &gst_xml_print_line ("<runlevels>");
   &gst_xml_enter ();
 
diff -up system-tools-backends-1.4.2/service.pl.in-clean system-tools-backends-1.4.2/service.pl.in
--- system-tools-backends-1.4.2/service.pl.in-clean	2006-01-02 15:42:19.000000000 +0000
+++ system-tools-backends-1.4.2/service.pl.in	2008-03-05 14:00:46.119320000 +0000
@@ -85,6 +85,9 @@ sub gst_service_sysv_get_paths
        "ubuntu-5.10"  => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],
        "ubuntu-6.04"  => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],
        
+       "nexenta-1.0" => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],       
+       "solaris-2.11" => ["$gst_prefix/etc", "$gst_prefix/etc/init.d", "../init.d"],       
+
        "suse-7.0"     => ["$gst_prefix/etc/rc.d", "$gst_prefix/etc/rc.d", "../"],
        "suse-9.0"     => ["$gst_prefix/etc/init.d", "$gst_prefix/etc/init.d", "../"],
        "suse-9.1"     => ["$gst_prefix/etc/init.d", "$gst_prefix/etc/init.d", "../"],
@@ -154,6 +157,9 @@ sub gst_service_sysv_get_runlevels
        "ubuntu-5.04"    => [2, 3],
        "ubuntu-5.10"    => [2, 3],
        "ubuntu-6.04"    => [2, 3],
+
+       "nexenta-1.0"   => [2, 3],       
+       "solaris-2.11"  => [2, 3],       
        
        "suse-7.0"       => [3, 5],
        "suse-9.0"       => [3, 5],
@@ -223,6 +229,10 @@ sub gst_service_get_runlevel_roles
      "ubuntu-5.04"    => "debian-2.2",
      "ubuntu-5.10"    => "debian-2.2",
      "ubuntu-6.04"    => "debian-2.2",
+
+     "nexenta-1.0"   => "nexenta",     
+
+     "solaris-2.11"   => "solaris",     
           
      "suse-7.0"       => "redhat-5.2",
      "suse-9.0"       => "redhat-5.2",
@@ -277,6 +287,14 @@ sub gst_service_get_runlevel_roles
                       "default"   => "GRAPHICAL",
                       "nonetwork" => "RECOVER"
                      },
+     "nexenta"    => {"single-user"  => "TEXT",
+                      "multi-user"   => "GRAPHICAL",
+                      "none"         => "RECOVER"
+                     },
+     "solaris"    => {"single-user"  => "TEXT",
+                      "multi-user"   => "GRAPHICAL",
+                      "none"         => "RECOVER"
+                     },
      "freebsd-5"  => {"rc" => "GRAPHICAL" },
      "slackware-9.1.0" => {"4" => "GRAPHICAL" }
     );
@@ -797,6 +815,159 @@ sub gst_service_bsd_get_services
   return \%ret;
 }
 
+sub gst_service_smf_service_exist
+{
+  my($service) = @_;
+  my($services) = &gst_service_smf_get_services_list();
+
+  foreach $i (@$services)
+  {
+    return 1 if ($i =~ /$service/);
+  }
+
+  return 0;
+}
+
+sub gst_service_smf_run_svcadm
+{
+  my ($service, $arg) = @_;
+  my ($option);
+
+  my %map =
+    ("stop" => "stopped",
+     "start" => "started"
+    );
+
+  my %op =
+    ("stop" => "disable",
+     "start" => "enable"
+    );
+
+  &gst_report_enter ();
+
+  if (!exists $map{$arg})
+  {
+    &gst_report ("service_sysv_op_unk", $arg);
+    &gst_report_leave ();
+    return -1;
+  }
+
+  if (&gst_service_smf_service_exist ($service))
+  {
+    if (!&gst_file_run ("svcadm $op{$arg} $service"))
+    {
+      &gst_report ("service_sysv_op_success", $service, $str);
+      &gst_report_leave ();
+      return 0;
+    }
+  }
+
+  &gst_report ("service_sysv_op_failed", $service, $str);
+  &gst_report_leave ();
+  return -1;
+}
+
+sub gst_service_smf_runlevel_status_by_service
+{
+  my ($service, $status) = @_;
+  my (@arr, @ret);
+  my (@runlevels) = split(" ","single-user multi-user");
+
+  foreach $runlevel (@runlevels)
+  {
+    if ($status)
+    {
+      push @arr, { "name"   => $runlevel,
+                   "action" => "start" };
+    }
+    else
+    {
+      push @arr, { "name"   => $runlevel,
+                   "action" => "stop" };
+    }
+  }
+
+  push @ret, { "runlevel" => \@arr };
+  return @ret;
+}
+
+sub gst_service_smf_get_service_info
+{
+  my ($service) = @_;
+  my ($script, @actions, @runlevels);
+  my %hash;
+  my $role;
+  my $status = 0;
+  my $longname = "";
+
+  
+  return undef if (&gst_service_list_service_is_forbidden ($service));
+
+  my $fd = &gst_file_run_pipe_read ("svcs -l $service");
+  while (<$fd>) {
+    $status = 1 if (/^state.*online/);
+    $longname = $1 if (/^name\s*(.*)/);
+  }
+  gst_file_close ($fd);
+
+  my($runlevels) = &gst_service_smf_runlevel_status_by_service ($service, $status);
+
+  $hash{"script"} = $service;
+  $hash{"longname"} = $longname if ($longname);
+  $hash{"runlevels"} = $runlevels unless ($runlevels eq undef);
+  $role = &gst_service_get_role ($service);
+
+  if ($role eq "UNKNOWN") {
+    $role = "SYSTEM" if ($service =~ /^system\// || $service =~ /^platform\//);
+    $role = "NETWORK" if ($service =~ /^network\//);
+    $role = "NTP_SERVER" if ($service =~ /^network\/ntp/);
+    $role = "FILE_SERVER" if ($service =~ /^network\/nfs/);
+    $role = "DYNAMIC_DNS" if ($service =~ /^network\/dns/);
+    $role = "SYSTEM_LOGGER" if ($service =~ /^system\/system-log/);
+    $role = "MTA" if ($service =~ /^network\/smtp/);
+    $role = "PRINTER_SERVICE" if ($service =~ /^application\/print\/server/);
+  }
+
+  $hash{"role"} = $role;
+
+  return \%hash;
+}
+
+sub gst_service_smf_get_services_list
+{
+  my @list;
+  local *SVCS=gst_file_run_pipe_read("svcs -H -a");
+  while (<SVCS>) {
+    next if (/svc:\/milestone/);
+    if (/^.*\s*.*\s*svc:\/(.*):(.*)/) {
+      my $svcname = $1;
+      $svcname .= ":$2" if ( $2 ne "default" );
+
+      push(@list,$svcname);
+    }
+  }
+  close (SVCS);
+
+  return \@list;
+}
+
+sub gst_service_smf_get_services
+{
+  my ($service);
+  my (%ret);
+  my ($service_list) = &gst_service_smf_get_services_list ();
+
+  foreach $service (@$service_list)
+  {
+    my (%hash);
+    $hash = &gst_service_smf_get_service_info ($service);
+
+    $ret{$service} = $hash if ($hash ne undef);
+  }
+
+  return \%ret;
+}
+
 # these functions get a list of the services that run on a gentoo init
 sub gst_service_gentoo_get_service_status
 {
@@ -1163,6 +1334,10 @@ sub gst_get_init_type
   {
     return "suse";
   }
+  elsif ($gst_dist =~ /nexenta/ || $gst_dist =~ /solaris-2.11/)
+  {
+    return "smf";
+  }
   else
   {
     return "sysv";
@@ -1180,6 +1355,8 @@ sub gst_service_get_services
   return &gst_service_rcng_get_services ()   if ($type eq "rcng");
   return &gst_service_suse_get_services ()   if ($type eq "suse");
   return &gst_service_archlinux_get_services() if ($type eq "archlinux");
+  return &gst_service_smf_get_services ()   if ($type eq "smf");
+
   return undef;
 }
 
@@ -1199,7 +1376,7 @@ sub gst_service_get_default_runlevel
 {
     my ($type) = &gst_get_init_type ();
 
-    return "default" if ($type eq "gentoo");
+    return "default" if ($type eq "gentoo" || $type eq "smf");
     return "rc"      if ($type eq "rcng");
     return "rc"      if ($type eq "archlinux");
     return &gst_service_sysv_get_default_runlevel ();
@@ -1585,6 +1762,7 @@ sub gst_service_set_services
   &gst_service_rcng_set_services   ($services, $runlevel) if ($type eq "rcng");
   &gst_service_suse_set_services   ($services, $runlevel) if ($type eq "suse");
   &gst_service_archlinux_set_services ($services, $runlevel) if ($type eq "archlinux");
+  &gst_service_smf_set_services   ($services, $runlevel) if ($type eq "smf");
 }
 
 sub gst_service_set_conf
@@ -1632,6 +1810,47 @@ sub gst_service_debian_get_status
   return undef;
 }
 
+sub gst_service_smf_set_services
+{
+  my ($services, $runlevel) = @_;
+  my ($action);
+
+  foreach $service (@$services)
+  {
+    $script = $$service{"script"};
+    $arr = $$service{"runlevels"}[0]{"runlevel"};
+
+    foreach $i (@$arr)
+    {
+      $action = $$i{"action"};
+      $rl = $$i{"name"};
+
+      if ( $action eq "start")
+      {
+        &gst_file_run ("rc-update add $script $rl");
+      }
+      elsif ($action eq "stop")
+      {
+        &gst_file_run ("rc-update del $script $rl");
+      }
+    }
+  }
+}
+
+sub gst_service_smf_get_status
+{
+  my ($service) = @_;
+  my $ret = 0;
+  my $fd = &gst_file_run_pipe_read ("svcs -H -ostate $service");
+
+  while (<$fd>) {
+    if (/^online/) { $ret = 1; last; }
+  }
+  gst_file_close ($fd);
+
+  return $ret;
+}
+
 sub gst_service_redhat_get_status
 {
   my ($service) = @_;
@@ -1697,6 +1916,9 @@ sub gst_service_get_status
        "ubuntu-5.04"  => \&gst_service_debian_get_status,
        "ubuntu-5.10"  => \&gst_service_debian_get_status,
        "ubuntu-6.04"  => \&gst_service_debian_get_status,
+
+       "nexenta-1.0" => \&gst_service_smf_get_status,
+       "solaris-2.11" => \&gst_service_smf_get_status,
               
        "redhat-5.2"   => \&gst_service_redhat_get_status,
        "redhat-6.0"   => \&gst_service_redhat_get_status,
@@ -1909,6 +2131,7 @@ sub gst_service_run_script
        "rcng"    => \&gst_service_rcng_run_script,
        "suse"    => \&gst_service_sysv_run_initd_script,
        "archlinux" => \&gst_service_archlinux_run_script,
+       "smf"    => \&gst_service_smf_run_svcadm,
       );
 
   $type = &gst_get_init_type ();
@@ -1964,6 +2187,14 @@ sub gst_service_rcng_installed
   return 0;
 }
 
+sub gst_service_smf_installed
+{
+  my ($service) = @_;
+
+  return 1 if (! &gst_file_run("svcs -H -ostate $service"));
+  return 0;
+}
+
 sub gst_service_installed
 {
   my ($service) = @_;
@@ -1975,6 +2206,8 @@ sub gst_service_installed
   return &gst_service_gentoo_installed ($service) if ($type eq "gentoo");
   return &gst_service_rcng_installed ($service) if ($type eq "rcng");
   return &gst_service_rcng_installed ($service) if ($type eq "archlinux");
+  return &gst_service_smf_installed ($service) if ($type eq "smf");
+
   return 0;
 }
 
@@ -2013,6 +2246,21 @@ sub gst_service_bsd_set_status
   }
 }
 
+sub gst_service_smf_set_status
+{
+  my ($service, $active) = @_;
+  my (@arr);
+
+  if ($active)
+  {
+    &gst_file_run ("svcadm enable $service");
+  }
+  else
+  {
+    &gst_file_run ("svcadm disable $service");
+  }
+}
+
 sub gst_service_gentoo_set_status
 {
   my ($script, $force_now, $active) = @_;

diff -up system-tools-backends-1.4.2/service-list.pl.in-clean system-tools-backends-1.4.2/service-list.pl.in
--- system-tools-backends-1.4.2/service-list.pl.in-clean	2006-01-02 15:39:39.000000000 +0000
+++ system-tools-backends-1.4.2/service-list.pl.in	2008-03-05 14:00:30.285948000 +0000
@@ -82,7 +82,7 @@ sub gst_service_list_service_is_forbidde
      "hostname",
      "keymaps",
      "localmount",
-     "net\..*",
+     "net\\..*",
      "numlock",
      "depscan\.sh",
      "functions\.sh",
@@ -145,6 +145,8 @@ sub gst_service_list_service_is_forbidde
      "rc[sS0-9]\.d",
      "boot",
      "boot\..*",
+     # These are the services found in Solaris
+     "application\/graphical-login\/gdm",
     ];
 
   foreach $i (@$service_forbidden_list)
@@ -328,10 +330,24 @@ sub gst_service_get_role
     "zmailer" => "MTA",
   );
 
-  my ($role) = $service_roles{$script};
+  if ($gst_dist =~ /nexenta/ || $gst_dist =~ /solaris-2.11/) {
+    my $role;
 
-  return $role if ($role);
-  return "UNKNOWN";
+    foreach $key (keys %service_roles) {
+      if ( $script =~ /.*\b$key\b.*/ ) {
+        $role = $service_roles{$key}; 
+        last;
+      }
+    }
+    return $role if ($role);
+    return "UNKNOWN";
+  }
+  else {
+    my ($role) = $service_roles{$script};
+
+    return $role if ($role);
+    return "UNKNOWN";
+  }
 }
 
 1;