Commit 9f861236 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Merge with freebsd version so we use a common file.

Move linux version to attic for now.
parent caef91e3
......@@ -40,6 +40,9 @@ BEGIN
my $BOOTDIR = "/etc/testbed";
}
}
# Convenience.
sub REMOTE() { return libsetup::REMOTE(); }
sub MFS() { return libsetup::MFS(); }
#
# Various programs and things specific to FreeBSD and that we want to export.
......@@ -91,6 +94,10 @@ my $TMCCCMD_DELAY = "delay";
sub os_cleanup_node ($) {
my ($scrub) = @_;
if (REMOTE()) {
return 0;
}
unlink $TMDELAY;
unlink $TMDELMAP;
......@@ -228,16 +235,21 @@ sub os_usermod($$$$$)
sub os_useradd($$$$$$$$)
{
my($login, $uid, $gid, $pswd, $glist, $homedir, $gcos, $root) = @_;
my $args;
if ($root) {
$glist = join(',', split(/,/, $glist), "wheel");
}
if ($glist ne "") {
$glist = "-G $glist";
$args .= "-G $glist ";
}
# If remote, let it decide where to put the homedir.
if (!REMOTE()) {
$args .= "-d $homedir ";
}
if (system("$USERADD $login -u $uid -g $gid $glist ".
"-m -d $homedir -s /bin/tcsh -c \"$gcos\"") != 0) {
if (system("$USERADD $login -u $uid -g $gid $args ".
"-m -s /bin/tcsh -c \"$gcos\"") != 0) {
warn "*** WARNING: $USERADD $login error.\n";
return -1;
}
......@@ -286,10 +298,13 @@ sub os_mkdir($$)
#
sub os_setup()
{
if (! libsetup::MFS()) {
print STDOUT "Checking Testbed delay configuration ... \n";
dodelays();
# This should never happen!
if (REMOTE() || MFS()) {
print "Ignoring os setup on remote/MFS node!\n";
return 0;
}
print STDOUT "Checking Testbed delay configuration ... \n";
dodelays();
}
#
......@@ -297,10 +312,14 @@ sub os_setup()
#
sub update_delays()
{
if (! libsetup::MFS()) {
dodelays();
system($TMDELAY);
# This should never happen!
if (REMOTE() || MFS()) {
print "Ignoring update delay on remote/MFS node!\n";
return 0;
}
dodelays();
system($TMDELAY);
return 0;
}
sub dodelays ()
......@@ -594,8 +613,13 @@ sub os_routing_enable_forward()
{
my $cmd;
$cmd = "sysctl -w net.inet.ip.forwarding=1\n";
$cmd .= "sysctl -w net.inet.ip.fastforwarding=1";
if (REMOTE()) {
$cmd = "echo 'IP forwarding not turned on!'";
}
else {
$cmd = "sysctl -w net.inet.ip.forwarding=1\n";
$cmd .= "sysctl -w net.inet.ip.fastforwarding=1";
}
return $cmd;
}
......@@ -603,7 +627,12 @@ sub os_routing_enable_gated()
{
my $cmd;
$cmd = "$GATED -f $BINDIR/gated_`$BINDIR/control_interface`.conf";
if (REMOTE()) {
$cmd = "echo 'GATED IS NOT ALLOWED!'";
}
else {
$cmd = "$GATED -f $BINDIR/gated_`$BINDIR/control_interface`.conf";
}
return $cmd;
}
......
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
#
# FreeBSD specific routines and constants for the client bootime setup stuff.
#
package liblocsetup;
use Exporter;
@ISA = "Exporter";
@EXPORT =
qw ( $CP $EGREP $SFSSD $SFSCD
os_groupadd os_useradd os_userdel os_usermod os_mkdir
os_groupdel os_cleanup_node os_homedirdel
os_routing_enable_forward os_routing_enable_gated
os_routing_add_manual os_routing_del_manual
);
# Must come after package declaration!
use English;
#
# This is the FreeBSD dependent part of the setup library.
#
my $SETUPDIR = "/usr/local/etc/emulab";
libsetup::libsetup_init($SETUPDIR);
#
# Various programs and things specific to FreeBSD and that we want to export.
#
$CP = "/bin/cp";
$EGREP = "/usr/bin/egrep -s -q";
$SFSSD = "/usr/local/sbin/sfssd";
$SFSCD = "/usr/local/sbin/sfscd";
#
# These are not exported
#
my $USERADD = "/usr/sbin/pw useradd";
my $USERDEL = "/usr/sbin/pw userdel";
my $USERMOD = "/usr/sbin/pw usermod";
my $GROUPADD = "/usr/sbin/pw groupadd";
my $GROUPDEL = "/usr/sbin/pw groupdel";
my $CHPASS = "/usr/bin/chpass -p";
my $MKDB = "/usr/sbin/pwd_mkdb -p";
my $MKDIR = "/bin/mkdir";
my $ROUTE = "/sbin/route";
#
# OS dependent part of cleanup node state.
#
sub os_cleanup_node ($) {
my ($scrub) = @_;
return 0;
}
#
# Add a new group
#
sub os_groupadd($$)
{
my($group, $gid) = @_;
return system("$GROUPADD $group -g $gid");
}
#
# Remove a new group
#
sub os_groupdel($)
{
my($group) = @_;
return system("$GROUPDEL $group");
}
#
# Remove a user account.
#
sub os_userdel($)
{
my($login) = @_;
return system("$USERDEL $login");
}
#
# Modify user group membership.
#
sub os_usermod($$$$$)
{
my($login, $gid, $glist, $pswd, $root) = @_;
if ($root) {
$glist = join(',', split(/,/, $glist), "wheel");
}
if ($glist ne "") {
$glist = "-G $glist";
}
if (system("$CHPASS '$pswd' $login") != 0) {
warn "*** WARNING: $CHPASS $login error.\n";
return -1;
}
return system("$USERMOD $login -g $gid $glist");
}
#
# Remove a homedir. Might someday archive and ship back.
#
sub os_homedirdel($$)
{
my ($login, $homedir) = @_;
#print "Removing home directory: $homedir\n";
#return(system("rm -rf $homedir"));
return 0;
}
#
# Add a user.
#
sub os_useradd($$$$$$$$)
{
my($login, $uid, $gid, $pswd, $glist, $homedir, $gcos, $root) = @_;
if ($root) {
$glist = join(',', split(/,/, $glist), "wheel");
}
if ($glist ne "") {
$glist = "-G $glist";
}
if (system("$USERADD $login -u $uid -g $gid $glist ".
"-m -s /bin/tcsh -c \"$gcos\"") != 0) {
warn "*** WARNING: $USERADD $login error.\n";
return -1;
}
if (system("$CHPASS '$pswd' $login") != 0) {
warn "*** WARNING: $CHPASS $login error.\n";
return -1;
}
return 0;
}
#
# Create a directory including all intermediate directories.
#
sub os_mkdir($$)
{
my ($dir, $mode) = @_;
if (system("$MKDIR -p -m $mode $dir")) {
return 0;
}
return 1;
}
#
# OS dependent, routing-related commands
#
sub os_routing_enable_forward()
{
return "echo 'IP forwarding not turned on!'";
}
sub os_routing_enable_gated()
{
return "echo 'GATED IS NOT ALLOWED!'";
}
sub os_routing_add_manual($$$$$)
{
my ($routetype, $destip, $destmask, $gate, $cost) = @_;
my $cmd;
if ($routetype eq "host") {
$cmd = "$ROUTE add -host $destip $gate";
} elsif ($routetype eq "net") {
$cmd = "$ROUTE add -net $destip $gate $destmask";
} else {
warn "*** WARNING: bad routing entry type: $routetype\n";
$cmd = "";
}
return $cmd;
}
sub os_routing_del_manual($$$$$)
{
my ($routetype, $destip, $destmask, $gate, $cost) = @_;
my $cmd;
if ($routetype eq "host") {
$cmd = "$ROUTE delete -host $destip";
} elsif ($routetype eq "net") {
$cmd = "$ROUTE delete -net $destip $gate $destmask";
} else {
warn "*** WARNING: bad routing entry type: $routetype\n";
$cmd = "";
}
return $cmd;
}
1;
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
#
# Linux specific routines and constants for the client bootime setup stuff.
#
package liblocsetup;
use Exporter;
@ISA = "Exporter";
@EXPORT =
qw ( $CP $EGREP $SFSSD $SFSCD
os_groupadd os_useradd os_userdel os_usermod os_mkdir
os_groupdel os_cleanup_node os_homedirdel
os_routing_enable_forward os_routing_enable_gated
os_routing_add_manual os_routing_del_manual
);
# Must come after package declaration!
use English;
#
# This is the Linux dependent part of the setup library.
#
my $SETUPDIR = "/usr/local/etc/emulab";
libsetup::libsetup_init($SETUPDIR);
#
# Various programs and things specific to FreeBSD and that we want to export.
#
$CP = "/bin/cp";
$EGREP = "/bin/egrep -q";
$SFSSD = "/usr/local/sbin/sfssd";
$SFSCD = "/usr/local/sbin/sfscd";
#
# These are not exported
#
my $USERADD = "/usr/sbin/useradd";
my $USERDEL = "/usr/sbin/userdel";
my $USERMOD = "/usr/sbin/usermod";
my $GROUPADD = "/usr/sbin/groupadd";
my $GROUPDEL = "/usr/sbin/groupdel";
my $MKDIR = "/bin/mkdir";
my $ROUTE = "/sbin/route";
#
# OS dependent part of cleanup node state.
#
sub os_cleanup_node ($) {
my ($scrub) = @_;
return 0;
}
#
# Add a new group
#
sub os_groupadd($$)
{
my($group, $gid) = @_;
return system("$GROUPADD $group -g $gid");
}
#
# Remove a new group
#
sub os_groupdel($)
{
my($group) = @_;
return system("$GROUPDEL $group");
}
#
# Remove a user account.
#
sub os_userdel($)
{
my($login) = @_;
return system("$USERDEL $login");
}
#
# Modify user group membership.
#
sub os_usermod($$$$$)
{
my($login, $gid, $glist, $pswd, $root) = @_;
if ($root) {
$glist = join(',', split(/,/, $glist), "root");
}
if ($glist ne "") {
$glist = "-G $glist";
}
return system("$USERMOD -g $gid $glist -p '$pswd' $login");
}
#
# Remove a homedir. Might someday archive and ship back.
#
sub os_homedirdel($$)
{
my ($login, $homedir) = @_;
return 0;
}
#
# Add a user.
#
sub os_useradd($$$$$$$$)
{
my($login, $uid, $gid, $pswd, $glist, $homedir, $gcos, $root) = @_;
if ($root) {
$glist = join(',', split(/,/, $glist), "root");
}
if ($glist ne "") {
$glist = "-G $glist";
}
if (system("$USERADD -M -u $uid -g $gid $glist -p '$pswd' ".
"-d $homedir -s /bin/tcsh -c \"$gcos\" $login") != 0) {
warn "*** WARNING: $USERADD $login error.\n";
return -1;
}
return 0;
}
#
# Create a directory including all intermediate directories.
#
sub os_mkdir($$)
{
my ($dir, $mode) = @_;
if (system("$MKDIR -p -m $mode $dir")) {
return 0;
}
return 1;
}
#
# OS dependent, routing-related commands
#
sub os_routing_enable_forward()
{
return "echo 'IP forwarding not turned on!'";
}
sub os_routing_enable_gated()
{
return "echo 'GATED IS NOT ALLOWED!'";
}
sub os_routing_add_manual($$$$$)
{
my ($routetype, $destip, $destmask, $gate, $cost) = @_;
my $cmd;
if ($routetype eq "host") {
$cmd = "$ROUTE add -host $destip gw $gate";
} elsif ($routetype eq "net") {
$cmd = "$ROUTE add -net $destip netmask $destmask gw $gate";
} else {
warn "*** WARNING: bad routing entry type: $routetype\n";
$cmd = "";
}
return $cmd;
}
sub os_routing_del_manual($$$$$)
{
my ($routetype, $destip, $destmask, $gate, $cost) = @_;
my $cmd;
if ($routetype eq "host") {
$cmd = "$ROUTE delete -host $destip";
} elsif ($routetype eq "net") {
$cmd = "$ROUTE delete -net $destip netmask $destmask gw $gate";
} else {
warn "*** WARNING: bad routing entry type: $routetype\n";
$cmd = "";
}
return $cmd;
}
1;
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