Commit 1d2ddefb authored by Kirk Webb's avatar Kirk Webb

Added dynamic samba share setup to exports_setup.

Share names are constructed as follows:

Path			Sharename
----------------------------------
/proj/<pid>		proj-<pid>
/group/<pid>/<eid>	<pid>-<eid>
/users/<uid>		<uid>

Share namespace collisions are detected, and mail is sent in the
(unlikely) event that this occurs (and exports_setup bails out).
parent c10ee252
......@@ -33,10 +33,11 @@ my $DISABLED = "@DISABLE_EXPORTS_SETUP@";
# Note no -n option. We redirect stdin from the new exports file below.
my $SSH = "$TB/bin/sshtb -l root -host $FSNODE";
my $PROG = "/usr/testbed/sbin/exports_setup.proxy";
my $PROG = "$TB/sbin/exports_setup.proxy";
my $exportstail = "/var/tmp/exports.tail";
my $smbconftail = "/var/tmp/smbconf.tail";
my $lockfile = "/var/tmp/testbed_exports_lockfile";
my $dbg = 0;
my $dbg = 1;
my @row;
# For determining file server mountpoints (XXX BSD specific)
......@@ -154,14 +155,21 @@ utime $now, $now, $lockfile;
#
if (!$TESTMODE) {
open(MAP, ">$exportstail") || fatal("Couldn't open $exportstail\n");
open(SMBMAP, ">$smbconftail") || fatal("Couldn't open $smbconftail\n");
} else {
open(MAP, ">/dev/null") || fatal("Couldn't open /dev/null\n");
open(SMBMAP, ">/dev/null") || fatal("Couldn't open /dev/null\n");
}
print MAP "\n";
print MAP "#\n";
print MAP "# DO NOT EDIT below this point. Auto generated entries!\n";
print MAP "#\n";
print MAP "\n";
my $maphdr =
"\n".
"#\n".
"# DO NOT EDIT below this point. Auto generated entries!\n".
"#\n".
"\n";
print MAP $maphdr;
print SMBMAP $maphdr;
#
# First gather up all the nodes that are reserved and the required info.
......@@ -183,8 +191,10 @@ $nodes_result =
" and node_types.isremotenode=0 ".
"order by r.pid,e.gid,r.eid,nodes.priority");
my %ipgroups = ();
my %ipgroups = ();
my %globalsmbshares = ();
my %lastfslist = ();
my @lastsmbshares = ();
my $lastpid = "";
my $lastgid = "";
......@@ -206,6 +216,7 @@ while (@row = $nodes_result->fetchrow_array) {
my $ip = $row[4];
my %fslist = ();
my @dirlist = ();
my @smbshares = ();
# Sanity check - don't try this if any of the above are not defined - we
# may end up with a bad line in exports
......@@ -219,7 +230,8 @@ while (@row = $nodes_result->fetchrow_array) {
# If this is for the same proj and group again, don't requery the db
# and don't recompute everything.
%fslist = %lastfslist;
%fslist = %lastfslist;
@smbshares = @lastsmbshares;
} else {
......@@ -231,6 +243,7 @@ while (@row = $nodes_result->fetchrow_array) {
# XXX needs to be fixed for shared experiments?
if (-d "$PROJROOT/$pid") {
push(@dirlist, "$projdir/$pid");
push(@smbshares, ["proj-$pid", "$projdir/$pid"]);
}
else {
print STDERR "*** exports_setup: $PROJROOT/$pid does not exist!\n";
......@@ -238,7 +251,8 @@ while (@row = $nodes_result->fetchrow_array) {
if ($gid ne $pid) {
if (-d "$GROUPROOT/$pid/$gid") {
push(@dirlist, "$groupdir/$pid/$gid");
push(@dirlist, "$groupdir/$pid/$gid");
push(@smbshares, ["${pid}-${gid}", "$groupdir/$pid/$gid"]);
}
else {
print STDERR "*** exports_setup: ".
......@@ -262,6 +276,7 @@ while (@row = $nodes_result->fetchrow_array) {
if (-d "$USERROOT/$uid") {
push(@dirlist, "$usersdir/$uid");
push(@smbshares, [$uid, "$usersdir/$uid"]);
}
else {
print STDERR "*** exports_setup: ".
......@@ -280,9 +295,11 @@ while (@row = $nodes_result->fetchrow_array) {
else {
push(@{ $fslist{$fs} }, $dir);
}
}
%lastfslist = %fslist;
%lastfslist = %fslist;
@lastsmbshares = @smbshares;
}
# For each FS directory list, create a hash key out of its directory list.
......@@ -300,6 +317,25 @@ while (@row = $nodes_result->fetchrow_array) {
push(@{ $ipgroups{$str} }, $ip);
}
}
# Build up Samba share permissions hash
foreach my $shareptr ( @smbshares ) {
my ($share, $path) = @{$shareptr};
if (! defined($globalsmbshares{$share}->{iplist})) {
$globalsmbshares{$share}->{path} = $path;
$globalsmbshares{$share}->{iplist} = [ $ip ];
}
else {
# Make sure there are no share name collisions first!
if ($globalsmbshares{$share}->{path} ne $path) {
fatal("Share name collision!\n".
"sharename: $share\n".
"original path: $globalsmbshares{$share}->{path}\n".
"new path: $path\n");
}
push(@{ $globalsmbshares{$share}->{iplist} }, $ip);
}
}
}
#
......@@ -314,6 +350,23 @@ foreach my $str ( keys(%ipgroups) ) {
print MAP "\n";
close(MAP);
#
# Spit out smb shares!
#
foreach my $share ( keys(%globalsmbshares) ) {
my @iplist = @{ $globalsmbshares{$share}->{iplist} };
my $path = $globalsmbshares{$share}->{path};
print SMBMAP "[$share]\n";
print SMBMAP "\tpath = $path\n";
print SMBMAP "\tbrowsable = no\n";
print SMBMAP "\twritable = yes\n";
print SMBMAP "\thosts allow = @iplist\n\n";
}
print SMBMAP "\n";
close(SMBMAP);
#
# Fire the new tail file over to the fileserver to finish. We cat the file
# right into it.
......@@ -326,12 +379,19 @@ if (!$TESTMODE) {
if ($dbg) {
my $backup = "$TB/log/exports/" . TBDateTimeFSSafe();
system("cp $exportstail $backup");
system("cp $smbconftail $backup");
}
# First do the NFS exports
system("$SSH $PROG < $exportstail") == 0 or
fatal("Failed: $SSH $PROG < $exportstail: $?");
unlink("$exportstail");
# Next the SMB shares
system("$SSH $PROG -S < $smbconftail") == 0 or
fatal("Failed: $SSH $PROG < $smbconftail: $?");
unlink("$smbconftail");
#
# Close the lock file. Exiting releases it, but might as well.
#
......
......@@ -9,6 +9,7 @@
use English;
use Errno;
use Fcntl ':flock';
use Getopt::Std;
#
# Create and /etc/exports file based on current reserved table and project
......@@ -17,17 +18,45 @@ use Fcntl ':flock';
# usage: exports_setup
#
my %opts = ();
getopts('S', \%opts);
#
# Configure variables
#
my $TBOPS = "@TBOPSEMAIL@";
my $etcdir = "/etc";
my $exports = "$etcdir/exports";
my $exportsnew = "$etcdir/exports.new";
my $exportsback = "$etcdir/exports.backup";
my $exportshead = "$etcdir/exports.head";
my $exportstail = "$etcdir/exports.tail";
my $etcdir;
my $exports;
my $exportsnew;
my $exportsback;
my $exportshead;
my $exportstail;
my $pidfile;
my $daemon;
# Are we modifying the Samba config file or the NFS exports?
if (defined($opts{'S'})) {
$etcdir = "/usr/local/etc";
$exports = "$etcdir/smb.conf";
$exportsnew = "$etcdir/smb.conf.new";
$exportsback = "$etcdir/smb.conf.backup";
$exportshead = "$etcdir/smb.conf.head";
$exportstail = "$etcdir/smb.conf.tail";
$pidfile = "/var/run/smbd.pid";
$daemon = "smbd";
}
else {
$etcdir = "/etc";
$exports = "$etcdir/exports";
$exportsnew = "$etcdir/exports.new";
$exportsback = "$etcdir/exports.backup";
$exportshead = "$etcdir/exports.head";
$exportstail = "$etcdir/exports.tail";
$pidfile = "/var/run/mountd.pid";
$daemon = "mountd";
}
my $dbg = 0;
my @row;
......@@ -102,14 +131,14 @@ chmod(0444, $exports);
#
# I have little faith in HUPing mountd, but do it anyway.
#
$mpid = `cat /var/run/mountd.pid`;
$mpid =~ s/\n//;
my $daemonpid = `cat $pidfile`;
$daemonpid =~ s/\n//;
# untaint
if ($mpid =~ /^([-\@\w.]+)$/) {
$mpid = $1;
if ($daemonpid =~ /^([-\@\w.]+)$/) {
$daemonpid = $1;
}
if (kill('HUP', $mpid) == 0) {
fatal("Could not kill(HUP) process $mpid (mountd): $!");
if (kill('HUP', $daemonpid) == 0) {
fatal("Could not kill(HUP) process $daemonpid ($daemon): $!");
}
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment