--- a/patches/system-tools-backends-06-shares.diff Wed Aug 30 11:10:10 2006 +0000
+++ b/patches/system-tools-backends-06-shares.diff Wed Aug 30 15:52:38 2006 +0000
@@ -73,3 +73,463 @@
{
$$ifaces{$i}{"network"} = &gst_network_ipv4_calc_subnet ($$ifaces{$i}{"addr"},
$$ifaces{$i}{"mask"});
+
+diff -ru /usr/tmp/clean/system-tools-backends-1.4.2/share.pl.in system-tools-backends-1.4.2/share.pl.in
+--- /usr/tmp/clean/system-tools-backends-1.4.2/share.pl.in 2005-02-25 14:15:34.000000000 +0000
++++ system-tools-backends-1.4.2/share.pl.in 2006-04-24 13:34:21.048581000 +0100
+@@ -202,6 +202,16 @@
+ }
+ }
+
++sub gst_share_nfs_info_get_name
++{
++ return $_[0]->{'name'};
++}
++
++sub gst_share_nfs_info_set_name
++{
++ &gst_share_nfs_info_set ($_[0], 'name', $_[1]);
++}
++
+ sub gst_share_nfs_info_get_point
+ {
+ return $_[0]->{'point'};
+@@ -397,6 +407,52 @@
+ return $table;
+ }
+
++sub gst_share_dfstab_list
++{
++ my ($file) = @_;
++ my $lnum = 0;
++ my @rv;
++
++ # dfstab example:
++ #
++ # share [-F fstype] [-o fs_options ] [-d description] [pathname [resourcename]]
++ # .e.g,
++ # share -F nfs -o rw=engineering -d "home dirs" /export/home2
++ my $fd = &gst_file_open_read_from_names ($file);
++ return @rv if !$fd;
++
++ while (<$fd>) {
++ s/\r|\n//g; s/#.*$//;
++ if (/^\s*\S*share\s+(.*)/) {
++ # Found a share line
++ my $share = { 'line' => $lnum,
++ 'index' => scalar(@rv) };
++ my $line = $1;
++ while($line =~ /\\$/) {
++ $_ = <$fd>;
++ s/\r|\n//g; s/#.*$//;
++ $line =~ s/\\$//;
++ $line .= $_;
++ $lnum++;
++ }
++ $share->{'eline'} = $lnum;
++ if ($line =~ /\s+(\/\S+)/ || $line =~ /\s+(\/)/ || $line eq "/") { $share->{'dir'} = $1; }
++ if ($line =~ /-d\s+"([^"]+)"/) { $share->{'desc'} = $1; }
++ elsif ($line =~ /-d\s+(\S+)/) { $share->{'desc'} = $1; }
++ if ($line =~ /-o\s+"([^"]+)"/) { $share->{'opts'} = $1; }
++ elsif ($line =~ /-o\s+(\S+)/) { $share->{'opts'} = $1; }
++ if ($line =~ /\s-F\s+(\S+)/) { $share->{'type'} = $1; }
++ else { $share->{'type'} = "nfs"; }
++ $share->{'desc'} =~ s/"//g; $share->{'desc'} =~ s/'//g;
++ push(@rv, $share);
++ }
++ $lnum++;
++ }
++ &gst_file_close ($fd);
++
++ return @rv;
++}
++
+ sub gst_share_parse_nfs_exports
+ {
+ my ($nfs_exports_name) = @_;
+@@ -405,43 +461,87 @@
+
+ $table = &gst_share_nfs_table_new ();
+
+- $entries = &gst_parse_split_hash_with_continuation ($nfs_exports_name, "[ \t]+", "[ \t]+");
++ if ($$tool{"system"} eq "SunOS") {
++ foreach $share (&gst_share_dfstab_list($nfs_exports_name)) {
++ if ($share->{'type'} eq "nfs") {
++ my $info = &gst_share_nfs_info_new ();
++ my $client_table = &gst_share_nfs_client_table_new ();
++
++ &gst_share_nfs_info_set_point ($info, $share->{'dir'});
++ &gst_share_nfs_info_set_name ($info, $share->{'desc'});
++
++ # Parse a mount options string like rw=foo,nosuid,...
++ # Parts with no value are given an empty string as the value
++ foreach my $opt (split(/,/, $share->{'opts'})) {
++ if ($opt =~ /^([^=]+)=(.*)$/) {
++ my $pattern;
++ my $access = $1;
++ my $client = $2;
++
++ $client =~ /^([a-zA-Z0-9.-_*?@\/]+)/;
++ $pattern = $1;
++ $pattern = "0.0.0.0/0" if $pattern eq "";
++ foreach my $host (split(/:/, $pattern)) {
++ my $cinfo = &gst_share_nfs_client_info_new ();
++ &gst_share_nfs_client_info_set_pattern ($cinfo, $host);
++
++ if ($access eq "rw") {
++ &gst_share_nfs_client_info_set_write ($cinfo, 1);
++ }
++
++ # ignore settings other than rw or ro, e.g. root
++ if ($access eq "rw" || $access eq "ro") {
++ &gst_share_nfs_client_table_add ($client_table, $cinfo);
++ }
++ }
++ } else {
++ $clients{$opt} = "";
++ }
++ }
+
+- foreach $point (keys %$entries)
+- {
+- my $clients = $$entries{$point};
+- my $info = &gst_share_nfs_info_new ();
+- my $client_table = &gst_share_nfs_client_table_new ();
+-
+- &gst_share_nfs_info_set_point ($info, $point);
+-
+- foreach $client (@$clients)
++ &gst_share_nfs_info_set_client_table ($info, $client_table);
++ &gst_share_nfs_table_add ($table, $info);
++ }
++ }
++ } else {
++ $entries = &gst_parse_split_hash_with_continuation ($nfs_exports_name, "[ \t]+", "[ \t]+");
++
++ foreach $point (keys %$entries)
+ {
+- my $cinfo = &gst_share_nfs_client_info_new ();
+- my $pattern;
+-
+- $client =~ /^([a-zA-Z0-9.-_*?@\/]+)/;
+- $pattern = $1;
+- $pattern = "0.0.0.0/0" if $pattern eq "";
+- &gst_share_nfs_client_info_set_pattern ($cinfo, $pattern);
+-
+- my $option_str = "";
+- my @options;
+-
+- if ($client =~ /\((.+)\)/) { $option_str = $1; }
+- @options = ($option_str =~ /([a-zA-Z0-9_=-]+),?/mg);
+-
+- for $option (@options)
++ my $clients = $$entries{$point};
++ my $info = &gst_share_nfs_info_new ();
++ my $client_table = &gst_share_nfs_client_table_new ();
++
++ &gst_share_nfs_info_set_point ($info, $point);
++
++ foreach $client (@$clients)
+ {
+- if ($option eq "rw") { &gst_share_nfs_client_info_set_write ($cinfo, 1); }
+- # Add supported NFS export options here. Some might have to be split on '='.
++ my $cinfo = &gst_share_nfs_client_info_new ();
++ my $pattern;
++
++ $client =~ /^([a-zA-Z0-9.-_*?@\/]+)/;
++ $pattern = $1;
++ $pattern = "0.0.0.0/0" if $pattern eq "";
++ &gst_share_nfs_client_info_set_pattern ($cinfo, $pattern);
++
++ my $option_str = "";
++ my @options;
++
++ if ($client =~ /\((.+)\)/) { $option_str = $1; }
++ @options = ($option_str =~ /([a-zA-Z0-9_=-]+),?/mg);
++
++ for $option (@options)
++ {
++ if ($option eq "rw") { &gst_share_nfs_client_info_set_write ($cinfo, 1); }
++ # Add supported NFS export options here. Some might have to be split on '='.
++ }
++
++ &gst_share_nfs_client_table_add ($client_table, $cinfo);
+ }
+-
+- &gst_share_nfs_client_table_add ($client_table, $cinfo);
++
++ &gst_share_nfs_info_set_client_table ($info, $client_table);
++ &gst_share_nfs_table_add ($table, $info);
+ }
+-
+- &gst_share_nfs_info_set_client_table ($info, $client_table);
+- &gst_share_nfs_table_add ($table, $info);
+ }
+
+ return $table;
+@@ -495,11 +595,27 @@
+ {
+ # Each line is in the following format:
+ # <point> <clients>
+- my @line = split /[ \t]+/, $_;
+- if ($line[0] eq "") { shift @line; }
+- if (@line < 1 || &gst_ignore_line (@line)) { print $outfd $_; next; }
+-
+- return $_;
++ if ($$tool{"system"} eq "SunOS") {
++ if (&gst_ignore_line($_)) { print $outfd $_; next; }
++ if (/^\s*\S*share\s+(.*)/) {
++ my $point, $type;
++ my $line = $1;
++ while($line =~ /\\$/) {
++ $_ = <$infd>;
++ s/\r|\n//g; s/#.*$//;
++ $line =~ s/\\$//;
++ $line .= $_;
++ }
++ if ($line =~ /\s-F\s+(\S+)/) { $type = $1; }
++ else { $type = "nfs"; }
++ return "share $line\n" if ($type eq "nfs");
++ }
++ } else {
++ my @line = split /[ \t]+/, $_;
++ if ($line[0] eq "") { shift @line; }
++ if (@line < 1 || &gst_ignore_line (@line)) { print $outfd $_; next; }
++ return $_;
++ }
+ }
+
+ return undef;
+@@ -526,11 +642,43 @@
+
+ $clients = &gst_share_nfs_info_get_client_table ($info);
+
+- for $client (@$clients)
+- {
+- $line .= &gst_share_nfs_client_info_get_pattern ($client);
+- $line .= "(rw)" if (&gst_share_nfs_client_info_get_write ($client));
+- $line .= " ";
++ if ($$tool{"system"} eq "SunOS") {
++ my $nowrite = 1;
++ my $noread = 1;
++ for $client (@$clients)
++ {
++ if (&gst_share_nfs_client_info_get_write ($client)) {
++ if ($nowrite eq 1) {
++ $line .= "rw=";
++ $nowrite = 0;
++ } else {
++ $line .= ":";
++ }
++ $line .= &gst_share_nfs_client_info_get_pattern ($client);
++ }
++ }
++ for $client (@$clients)
++ {
++ if (!&gst_share_nfs_client_info_get_write ($client)) {
++ if ($noread eq 1) {
++ if ($nowrite eq 0) {
++ $line .= ",";
++ }
++ $line .= "ro=";
++ $noread = 0;
++ } else {
++ $line .= ":";
++ }
++ $line .= &gst_share_nfs_client_info_get_pattern ($client);
++ }
++ }
++ } else {
++ for $client (@$clients)
++ {
++ $line .= &gst_share_nfs_client_info_get_pattern ($client);
++ $line .= "(rw)" if (&gst_share_nfs_client_info_get_write ($client));
++ $line .= " ";
++ }
+ }
+
+ return $line;
+@@ -541,13 +689,19 @@
+ my ($info) = @_;
+ my $line;
+
+- # <point>
+-
+- $line = sprintf ("%-15s ", &gst_share_nfs_info_get_point ($info));
+-
+- # <clients>
+-
+- $line .= &gst_share_nfs_info_print_clients ($info);
++ if ($$tool{"system"} eq "SunOS") {
++ $line = "share -F nfs ";
++ $line .= sprintf ("-o %s ", &gst_share_nfs_info_print_clients ($info))
++ if (&gst_share_nfs_info_print_clients ($info));
++ $line .= sprintf ("-d %s ", &gst_share_nfs_info_get_name ($info))
++ if (&gst_share_nfs_info_get_name ($info));
++ $line .= sprintf ("%-15s ", &gst_share_nfs_info_get_point ($info));
++ } else {
++ # <point>
++ $line = sprintf ("%-15s ", &gst_share_nfs_info_get_point ($info));
++ # <clients>
++ $line .= &gst_share_nfs_info_print_clients ($info);
++ }
+
+ return $line;
+ }
+@@ -583,66 +737,75 @@
+ my $outline;
+ my $ctable = &gst_share_nfs_info_get_client_table ($info);
+
+- # <point>
+-
+- $outline = sprintf ("%-15s", &gst_share_nfs_info_get_point ($info));
+-
+- # <clients>
+-
+- chomp $line;
+- my @clients = split /[ \t]+/, $line;
+- shift @clients;
+-
+- # Make client hash based on line.
+-
+- my $chash = { };
+-
+- for $client (@clients)
+- {
+- my $opthash = { };
+-
+- $client =~ /^([a-zA-Z0-9.-_*?@\/]+)/;
+- my $pattern = $1;
+- $$chash{$pattern} = $opthash;
+-
+- my $option_str = "";
+- if ($client =~ /\((.+)\)/) { $option_str = $1; }
+- @options = ($option_str =~ /([a-zA-Z0-9_=-]+),?/mg);
+-
+- for $option (@options)
+- {
+- my ($key, $value) = split /[=]/, $option;
+- next if ($key eq "");
+-
+- if ($value eq "" && $option =~ /=/) { $value = " "; }
+- $$opthash{$key} = $value;
+- }
+- }
+-
+- # @clients contains client(options) entries.
+-
+- for $cinfo (@$ctable)
+- {
+- my $pattern = &gst_share_nfs_client_info_get_pattern ($cinfo);
+- my $opthash = $$chash{$pattern};
+-
+- if (&gst_share_nfs_client_info_get_write ($cinfo))
+- {
+- $$opthash{'rw'} = "";
+- }
+- else
++ if ($$tool{"system"} eq "SunOS") {
++ my $desc = "unknown";
++ if ($line =~ /-d\s+"([^"]+)"/) { $desc = $1; }
++ elsif ($line =~ /-d\s+(\S+)/) { $desc = $1; }
++ $desc =~ s/"//g; $desc =~ s/'//g;
++ &gst_share_nfs_info_set_name ($info, $desc);
++ $outline = &gst_share_nfs_info_print_entry ($info);
++ } else {
++ # <point>
++
++ $outline = sprintf ("%-15s", &gst_share_nfs_info_get_point ($info));
++
++ # <clients>
++
++ chomp $line;
++ my @clients = split /[ \t]+/, $line;
++ shift @clients;
++
++ # Make client hash based on line.
++
++ my $chash = { };
++
++ for $client (@clients)
+ {
+- delete $$opthash{'rw'};
++ my $opthash = { };
++
++ $client =~ /^([a-zA-Z0-9.-_*?@\/]+)/;
++ my $pattern = $1;
++ $$chash{$pattern} = $opthash;
++
++ my $option_str = "";
++ if ($client =~ /\((.+)\)/) { $option_str = $1; }
++ @options = ($option_str =~ /([a-zA-Z0-9_=-]+),?/mg);
++
++ for $option (@options)
++ {
++ my ($key, $value) = split /[=]/, $option;
++ next if ($key eq "");
++
++ if ($value eq "" && $option =~ /=/) { $value = " "; }
++ $$opthash{$key} = $value;
++ }
+ }
+-
+- $outline .= " " . &gst_share_nfs_client_info_get_pattern ($cinfo);
+- my $client_string = &gst_share_nfs_client_print_option_hash ($opthash);
+- if ($client_string ne "")
++
++ # @clients contains client(options) entries.
++
++ for $cinfo (@$ctable)
+ {
+- $outline .= "(" . $client_string . ")";
++ my $pattern = &gst_share_nfs_client_info_get_pattern ($cinfo);
++ my $opthash = $$chash{$pattern};
++
++ if (&gst_share_nfs_client_info_get_write ($cinfo))
++ {
++ $$opthash{'rw'} = "";
++ }
++ else
++ {
++ delete $$opthash{'rw'};
++ }
++
++ $outline .= " " . &gst_share_nfs_client_info_get_pattern ($cinfo);
++ my $client_string = &gst_share_nfs_client_print_option_hash ($opthash);
++ if ($client_string ne "")
++ {
++ $outline .= "(" . $client_string . ")";
++ }
+ }
+ }
+-
++
+ return $outline;
+ }
+
+@@ -719,7 +882,11 @@
+ my ($line) = @_;
+ my $point;
+
+- ($point) = split /[ \t]+/, $line;
++ if ($$tool{"system"} eq "SunOS") {
++ if ($line =~ /\s+(\/\S+)/ || $line =~ /\s+(\/)/ || $line eq "/") { $point = $1; }
++ } else {
++ ($point) = split /[ \t]+/, $line;
++ }
+ return $point;
+ }
+
+@@ -752,6 +919,12 @@
+ &gst_share_nfs_exports_remove_entry ($file, $old_info);
+ }
+ }
++
++ if ($$tool{"system"} eq "SunOS") {
++ &gst_file_run ("svcadm enable nfs/server");
++ &gst_file_run ("unshareall");
++ &gst_file_run ("/bin/sh $file");
++ }
+ }
+
+