diff options
Diffstat (limited to 'perl-install/standalone/fileshareset')
-rwxr-xr-x | perl-install/standalone/fileshareset | 67 |
1 files changed, 45 insertions, 22 deletions
diff --git a/perl-install/standalone/fileshareset b/perl-install/standalone/fileshareset index 4ca41efac..9223d6f29 100755 --- a/perl-install/standalone/fileshareset +++ b/perl-install/standalone/fileshareset @@ -3,7 +3,7 @@ use strict; ######################################## # config files -$nfs_exports::default_options = '*(ro,all_squash,sync)'; +$nfs_exports::default_options = '*(ro,all_squash,sync,no_subtree_check)'; $nfs_exports::conf_file = '/etc/exports'; $smb_exports::conf_file = '/etc/samba/smb.conf'; my $authorisation_file = '/etc/security/fileshare.conf'; @@ -11,8 +11,7 @@ my $authorisation_group = 'fileshare'; ######################################## -# fileshare utility $Id$ -# Copyright (C) 2001-2004 Mandrakesoft (pixel@mandrakesoft.com) +# Copyright (C) 2001-2008 Mandriva (pixel) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -38,12 +37,23 @@ my $username = getpwuid($uid); my $usage = "usage: fileshareset --add <dir> fileshareset --remove <dir>"; + +my $not_enabled = +qq(File sharing is not enabled. +To enable file sharing put +"FILESHARING=yes" in $authorisation_file); + +my $not_simple_enabled = +qq(Simple file sharing is not enabled. +To enable simple file sharing put +"SHARINGMODE=simple" in $authorisation_file); + my $non_authorised = qq(You are not authorised to use fileshare'ing To grant you the rights: - put "RESTRICT=no" in $authorisation_file - or put user "$username" in group "$authorisation_group"); -my $no_export_method = "can not export anything: no nfs, no smb"; +my $no_export_method = "cannot export anything: no nfs, no smb"; my %exit_codes = reverse( 1 => $non_authorised, @@ -57,6 +67,10 @@ my %exit_codes = reverse( 5 => "not exported", 6 => $no_export_method, + + 7 => $not_enabled, + + 8 => $not_simple_enabled, 255 => "various", ); @@ -78,7 +92,7 @@ my @exports = ( if ($modify) { my ($cmd, $dir) = @ARGV; $< = $>; - @ARGV == 2 && ($cmd eq '--add' || $cmd eq '--remove') or error($usage); + @ARGV == 2 && (member($cmd, qw(--add --remove))) or error($usage); verify_mntpoint($dir); @@ -127,7 +141,7 @@ my $F_lock; sub read_conf { my ($exclusive_lock) = @_; open $F_lock, $authorisation_file; # do not care if it's missing - flock($F_lock, $exclusive_lock ? 2 : 1) or die "can not lock"; + flock($F_lock, $exclusive_lock ? 2 : 1) or die "cannot lock"; my %conf; foreach (<$F_lock>) { s/#.*//; # remove comments @@ -138,18 +152,24 @@ sub read_conf { $conf{$cmd} = $value || warn qq(suspicious line "$_" in $authorisation_file\n); } # no close $F_lock, keep it locked - \%conf + \%conf; } sub check { my ($exclusive_lock) = @_; my $conf = read_conf($exclusive_lock); - if (lc($conf->{RESTRICT}) eq 'no') { + if (lc($conf->{FILESHARING}) eq 'no') { + ::error($not_enabled); + } elsif (lc($conf->{SHARINGMODE}) eq 'advanced') { + ::error($not_simple_enabled); + } elsif ($conf->{FILESHAREGROUP}) { + $authorisation_group = $conf->{FILESHAREGROUP}; + } elsif (lc($conf->{RESTRICT}) eq 'no') { # ok, access granted for everybody } else { my @l; - while (@l = getgrent) { + while (@l = getgrent()) { last if $l[0] eq $authorisation_group; } ::member($username, split(' ', $l[3])) or ::error($non_authorised); @@ -159,7 +179,7 @@ sub check { ################################################################################ package exports; -sub find { +sub _find { my ($exports, $mntpoint) = @_; foreach (@$exports) { $_->{mntpoint} eq $mntpoint and return $_; @@ -169,9 +189,7 @@ sub find { sub add { my ($exports, $mntpoint) = @_; - foreach (@$exports) { - $_->{mntpoint} eq $mntpoint and die 'add'; - } + _find($exports, $mntpoint) and die 'add'; push @$exports, my $e = { mntpoint => $mntpoint }; $e; } @@ -248,15 +266,15 @@ sub write { $_->{raw} = sprintf("%s %s\n", $mntpoint, $_->{options}); } } - open(my $F, ">$conf_file") or die "can not write $conf_file"; + open(my $F, ">$conf_file") or die "cannot write $conf_file"; print $F $_->{raw} foreach @$nfs_exports; } sub update_server() { if (fork()) { system('/usr/sbin/exportfs', '-r'); - if (system('/sbin/pidof rpc.mountd >/dev/null') != 0 || - system('/sbin/pidof nfsd >/dev/null') != 0) { + if (system('PATH=/bin:/sbin pidof rpc.mountd >/dev/null') != 0 || + system('PATH=/bin:/sbin pidof nfsd >/dev/null') != 0) { # trying to start the server... system('/etc/init.d/portmap start') if system('/etc/init.d/portmap status >/dev/null') != 0; system('/etc/init.d/nfs', $_) foreach 'stop', 'start'; @@ -304,7 +322,7 @@ sub write { EOF } } - open(my $F, ">$conf_file") or die "can not write $conf_file"; + open(my $F, ">$conf_file") or die "cannot write $conf_file"; print $F $_->{raw} foreach @$smb_exports; } @@ -361,8 +379,8 @@ sub name_mangle { last A; } } - $_ or die "can not find a unique name"; - # can not find a unique name, dropping the last letter + $_ or die "cannot find a unique name"; + # cannot find a unique name, dropping the last letter s|(.*).|$1|; } } @@ -374,10 +392,15 @@ sub name_mangle { sub update_server() { if (fork()) { system('/usr/bin/killall -HUP smbd 2>/dev/null'); - if (system('/sbin/pidof smbd >/dev/null') != 0 || - system('/sbin/pidof nmbd >/dev/null') != 0) { + if (system('PATH=/bin:/sbin pidof smbd >/dev/null') != 0 || + system('PATH=/bin:/sbin pidof nmbd >/dev/null') != 0) { # trying to start the server... - system('/etc/init.d/smb', $_) foreach 'stop', 'start'; + my ($f) = grep { -f $_ } map { "/etc/init.d/$_" } 'smb', 'samba', 'rc.samba'; + if ($f) { + system($f, $_) foreach 'stop', 'start'; + } else { + print STDERR "Error: Can't find the samba init script \n"; + } } exit 0; } |