--- /usr/sbin/fileshareset 2008-12-09 20:32:26.000000000 +0100
+++ /usr/lib64/kde4/libexec/fileshareset 2008-05-21 13:08:06.000000000 +0200
@@ -1,9 +1,9 @@
#!/usr/bin/perl -T
-
+use strict;
########################################
# config files
-$nfs_exports::default_options = '*(ro,all_squash,sync,no_subtree_check)';
+$nfs_exports::default_options = '*(ro,all_squash)';
$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 @@
########################################
-# fileshare utility $Id: fileshareset 233183 2008-01-23 12:17:07Z tv $
-# Copyright (C) 2001-2008 Mandriva (pixel@mandriva.com)
+# Copyright (C) 2001-2002 MandrakeSoft (pixel@mandrakesoft.com)
#
# 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
@@ -26,7 +25,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
########################################
@@ -38,7 +37,6 @@
my $usage =
"usage: fileshareset --add
fileshareset --remove ";
-
my $not_enabled =
qq(File sharing is not enabled.
To enable file sharing put
@@ -50,13 +48,14 @@
"SHARINGMODE=simple" in $authorisation_file);
my $non_authorised =
-qq(You are not authorised to use fileshare'ing
+qq(You are not authorised to use file sharing
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 %exit_codes = reverse(
+my $no_export_method = "can't export anything: no nfs, no smb";
+
+my %exit_codes = reverse (
1 => $non_authorised,
2 => $usage,
@@ -109,7 +108,7 @@
$export->update_server;
}
}
-my @mntpoints = grep { $_ } uniq(map { map { $_->{mntpoint} } @$_ } @exports);
+my @mntpoints = grep {$_} uniq(map { map { $_->{mntpoint} } @$_ } @exports);
print "$_\n" foreach grep { own($_) } @mntpoints;
@@ -119,7 +118,7 @@
local ($_) = @_;
my $ok = 1;
$ok &&= m|^/|;
- $ok &&= !m|\Q/../|;
+ $ok &&= !m|/\.\./|;
$ok &&= !m|[\0\n\r]|;
$ok &&= -d $_;
$ok &&= own($_);
@@ -138,13 +137,12 @@
################################################################################
package authorisation;
-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";
+ open F_lock, $authorisation_file; # don't care if it's missing
+ flock(F_lock, $exclusive_lock ? 2 : 1) or die "can't lock";
my %conf;
- foreach (<$F_lock>) {
+ foreach () {
s/#.*//; # remove comments
s/^\s+//;
s/\s+$//;
@@ -152,21 +150,26 @@
my ($cmd, $value) = split('=', $_, 2);
$conf{$cmd} = $value || warn qq(suspicious line "$_" in $authorisation_file\n);
}
- # no close $F_lock, keep it locked
+ # no close F_lock, keep it locked
\%conf
}
sub check {
my ($exclusive_lock) = @_;
my $conf = read_conf($exclusive_lock);
-
if (lc($conf->{FILESHARING}) eq 'no') {
::error($not_enabled);
- } elsif (lc($conf->{SHARINGMODE}) eq 'advanced') {
+ }
+
+ if (lc($conf->{SHARINGMODE}) eq 'advanced') {
::error($not_simple_enabled);
- } elsif ($conf->{FILESHAREGROUP}) {
- $authorisation_group = $conf->{FILESHAREGROUP};
- } elsif (lc($conf->{RESTRICT}) eq 'no') {
+ }
+
+ if (lc($conf->{FILESHAREGROUP} ne '')) {
+ $authorisation_group = lc($conf->{FILESHAREGROUP});
+ }
+
+ if (lc($conf->{RESTRICT}) eq 'no') {
# ok, access granted for everybody
} else {
my @l;
@@ -190,7 +193,9 @@
sub add {
my ($exports, $mntpoint) = @_;
- find($exports, $mntpoint) and die 'add';
+ foreach (@$exports) {
+ $_->{mntpoint} eq $mntpoint and die 'add';
+ }
push @$exports, my $e = { mntpoint => $mntpoint };
$e;
}
@@ -206,16 +211,17 @@
################################################################################
package nfs_exports;
-
+use vars qw(@ISA $conf_file $default_options);
BEGIN { @ISA = 'exports' }
-sub read() {
+sub read {
my $file = $conf_file;
- open(my $F, $file) or return [];
+ local *F;
+ open F, $file or return [];
- my ($prev_raw, $prev_line, @l);
+ my ($prev_raw, $prev_line, %e, @l);
my $line_nb = 0;
- foreach my $raw (<$F>) {
+ foreach my $raw () {
$line_nb++;
local $_ = $raw;
$raw .= "\n" if !/\n/;
@@ -250,7 +256,7 @@
$mntpoint =~ s/\\(\d{3})/chr(oct $1)/ge;
# not accepting weird characters that would break the output
- $mntpoint =~ m/[\0\n\r]/ and die "i will not handle this";
+ $mntpoint =~ m/[\0\n\r]/ and die "i won't handle this";
push @l, { mntpoint => $mntpoint, option => $options, raw => $raw_line };
}
bless \@l, 'nfs_exports';
@@ -267,17 +273,18 @@
$_->{raw} = sprintf("%s %s\n", $mntpoint, $_->{options});
}
}
- open(my $F, ">$conf_file") or die "can not write $conf_file";
- print $F $_->{raw} foreach @$nfs_exports;
+ local *F;
+ open F, ">$conf_file" or die "can't write $conf_file";
+ print F $_->{raw} foreach @$nfs_exports;
}
-sub update_server() {
- if (fork()) {
+sub update_server {
+ if (fork) {
system('/usr/sbin/exportfs', '-r');
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/portmap start') if system('/etc/init.d/portmap status') != 0;
system('/etc/init.d/nfs', $_) foreach 'stop', 'start';
}
exit 0;
@@ -287,15 +294,16 @@
################################################################################
package smb_exports;
-
+use vars qw(@ISA $conf_file);
BEGIN { @ISA = 'exports' }
-sub read() {
+sub read {
my ($s, @l);
- open(my $F, $conf_file);
+ local *F;
+ open F, $conf_file;
local $_;
- while (<$F>) {
- if (/^\s*\[.*\]/ || eof $F) {
+ while () {
+ if (/^\s*\[.*\]/ || eof F) {
#- first line in the category
my ($label) = $s =~ /^\s*\[(.*)\]/;
my ($mntpoint) = $s =~ /^\s*path\s*=\s*(.*)/m;
@@ -323,8 +331,9 @@
EOF
}
}
- open(my $F, ">$conf_file") or die "can not write $conf_file";
- print $F $_->{raw} foreach @$smb_exports;
+ local *F;
+ open F, ">$conf_file" or die "can't write $conf_file";
+ print F $_->{raw} foreach @$smb_exports;
}
sub add {
@@ -357,13 +366,15 @@
if (length($s) > 8 && !grep { /\Q$s/ } @others) {
# dropping leading directories when the resulting is still long and meaningful
$_ = $s;
- } else {
- s|(.*)[0-9#\-_!/]|$1|
- # inspired by "Christian Brolin" "Long names are doom" on comp.lang.functional
- || s|(.+)[AEIOU]|$1|# allButFirstVowels
- || s|(.*)(.)\2|$1$2| # adjacentDuplicates
- || s|(.*).|$1|; # booh, :'-(
+ next;
}
+ s|(.*)[0-9#\-_!/]|$1| and next;
+
+ # inspired by "Christian Brolin" "Long names are doom" on comp.lang.functional
+ s|(.+)[AEIOU]|$1| and next; # allButFirstVowels
+ s|(.*)(.)\2|$1$2| and next; # adjacentDuplicates
+
+ s|(.*).|$1|; # booh, :'-(
}
# 5. remove "/"s still there
@@ -380,8 +391,8 @@
last A;
}
}
- $_ or die "can not find a unique name";
- # can not find a unique name, dropping the last letter
+ $_ or die "can't find a unique name";
+ # can't find a unique name, dropping the last letter
s|(.*).|$1|;
}
}
@@ -390,19 +401,25 @@
$_;
}
-sub update_server() {
- if (fork()) {
- system('/usr/bin/killall -HUP smbd 2>/dev/null');
- if (system('PATH=/bin:/sbin pidof smbd >/dev/null') != 0 ||
- system('PATH=/bin:/sbin pidof nmbd >/dev/null') != 0) {
- # trying to start the server...
- 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;
+sub update_server {
+ if (fork) {
+ system('/usr/bin/killall -HUP smbd 2>/dev/null');
+ if (system('PATH=/bin:/sbin pidof smbd >/dev/null') != 0 ||
+ system('PATH=/bin:/sbin pidof nmbd >/dev/null') != 0) {
+# trying to start the server...
+ if ( -f '/etc/init.d/smb' ) {
+ system('/etc/init.d/smb', $_) foreach 'stop', 'start';
+ }
+ elsif ( -f '/etc/init.d/samba' ) {
+ system('/etc/init.d/samba', $_) foreach 'stop', 'start';
+ }
+ elsif ( -f '/etc/rc.d/rc.samba' ) {
+ system('/etc/rc.d/rc.samba', $_) foreach 'stop', 'start';
+ }
+ else {
+ print STDERR "Error: Can't find the samba init script \n";
+ }
}
+ exit 0;
+ }
}