Commit 76796608 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Checkpoint the NetBSD version of tmcd client side stuff.

parent df0f12cc
......@@ -942,6 +942,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/checkpass/GNUmakefile \
tip/GNUmakefile \
tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \
tmcd/netbsd/GNUmakefile \
tmcd/tmcd.restart \
www/GNUmakefile www/defs.php3 www/dbdefs.php3"
......
......@@ -108,6 +108,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/checkpass/GNUmakefile \
tip/GNUmakefile \
tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \
tmcd/netbsd/GNUmakefile \
tmcd/tmcd.restart \
www/GNUmakefile www/defs.php3 www/dbdefs.php3"
......
#
# DON'T RUN THIS!
#
# Trivial. These things just need to be installed into the right place
# on a testbed node before cutting an image.
#
#
SRCDIR = @srcdir@
TESTBED_SRCDIR = @top_srcdir@
OBJDIR = ../..
SUBDIR = tmcd
include $(OBJDIR)/Makeconf
all:
include $(TESTBED_SRCDIR)/GNUmakerules
INSTALL_DIR = /etc/testbed
INSTALL_FILES = group master.passwd setup
INSTALL = /usr/bin/install -c
install:
-mkdir -p $(INSTALL_DIR)
$(INSTALL) -m 644 $(SRCDIR)/group $(INSTALL_DIR)/group
$(INSTALL) -m 600 $(SRCDIR)/master.passwd $(INSTALL_DIR)/master.passwd
$(INSTALL) -m 755 $(SRCDIR)/setup $(INSTALL_DIR)/setup
$(INSTALL) -m 755 $(SRCDIR)/rc.testbed $(INSTALL_DIR)/rc.testbed
$(INSTALL) -m 755 ../tmcc $(INSTALL_DIR)/tmcc
wheel:*:0:root,mike,stoller,lepreau,forys,danderse,newbold,calfeld
daemon:*:1:daemon
kmem:*:2:root
sys:*:3:root
tty:*:4:root
operator:*:5:root
mail:*:6:
bin:*:7:
news:*:8:
wsrc:*:9:
maildrop:*:11:
postfix:*:12:
games:*:13:
staff:*:20:root,mike,stoller,lepreau
guest:*:31:root
nobody:*:39:
utmp:*:45:
ingres:*:74:ingres
dialer:*:117:
nogroup:*:32766:
root:kEi.I6fTKyJDg:0:0::0:0:Charlie &:/root:/bin/csh
toor:*:0:0::0:0:Bourne-again Superuser:/root:/bin/sh
daemon:*:1:31::0:0:The devil himself:/:/sbin/nologin
operator:*:2:5::0:0:System &:/usr/guest/operator:/sbin/nologin
bin:*:3:7::0:0:Binaries Commands and Source:/:/sbin/nologin
news:*:6:8::0:0:Network News:/var/spool/news:/sbin/nologin
games:*:7:13::0:0:Games pseudo-user:/usr/games:/sbin/nologin
uucp:*:66:1::0:0:UUCP:/var/spool/uucppublic:/usr/libexec/uucp/uucico
nobody:*:32767:39::0:0:Unprivileged user:/nonexistent:/sbin/nologin
lepreau:XzOQ6qRSyDp5A:12:6000::0:0:Jay Lepreau:/users/lepreau:/bin/csh
mike:OQYay0WnwMYTs:27:6000::0:0:Mike Hibler:/users/mike:/bin/csh
stoller:4.MMzSPURcOls:282:6000::0:0:Leigh B. Stoller:/users/stoller:/bin/csh
tullmann:slG0cJEVIV7fk:3654:6000::0:0:Patrick A Tullmann:/users/tullmann:/bin/tcsh
calfeld:amGW2iuQCjmyQ:2986:6000::0:0:Chris Alfeld:/users/calfeld:/bin/tcsh
danderse:i7zCwgOeDkwZ6:2146:6000::0:0:David G Andersen:/users/danderse:/bin/tcsh
reid:i9vTbxvJp1Rpo:1296:6000::0:0:Alastair Reid,,,:/users/reid:/bin/tcsh
newbold:b5CNBeTTiXYqA:2224:6000::0:0:Mac G Newbold:/users/newbold:/bin/tcsh
axon:MAg80zUaZS52Q:2347:6000::0:0:Logan Axon:/users/axon:/bin/tcsh
ricci:3MYM/vEONbd8k:1182:6000::0:0:Robert Ricci:/users/ricci:/bin/tcsh
#!/bin/sh
if [ -x /etc/testbed/setup ]; then
echo "Setting up Testbed configuration..."
/etc/testbed/setup
fi
if [ -x /etc/testbed/rc.ifc ]; then
echo "Setting up Testbed interfaces..."
/etc/testbed/rc.ifc
fi
#!/usr/pkg/bin/perl -wT
use English;
#
# Initialize at boot time.
#
my $TMCC = "/etc/testbed/tmcc";
my $TMIFC = "/etc/testbed/rc.ifc";
my $TMGROUP = "/etc/testbed/group";
my $TMPASSWD = "/etc/testbed/master.passwd";
my @CONFIGS = ($TMIFC);
my $REBOOTCMD = "reboot";
my $STATCMD = "status";
my $IFCCMD = "ifconfig";
my $ACCTCMD = "accounts";
my $IFCONFIG = "/sbin/ifconfig cs%d alias %s netmask %s ".
"media 10baseT mediaopt full-duplex\n";
my $CP = "/bin/cp -f";
my $MKDB = "/usr/sbin/pwd_mkdb -p";
my $USERADD = "/usr/sbin/useradd";
my $USERMOD = "/usr/sbin/usermod";
my $GROUPADD = "/usr/sbin/groupadd";
my $IFACE = "cs";
my $CTLIFACENUM = "0";
my $CTLIFACE = "${IFACE}${CTLIFACENUM}";
my $project = "";
my $PROJDIR = "/proj";
my $MOUNTCMD = "/sbin/mount fs.emulab.net:/q/proj/";
#
# This is a debugging thing for my home network.
#
my $NODE = "MYIP=155.99.214.136";
$NODE = "";
#
# Untaint path
#
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/local/bin:/etc/testbed';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# First clean up the node.
#
cleanup_node();
#
# Inform the master that we have rebooted.
#
open(TM, "$TMCC $NODE $REBOOTCMD |")
or die "Cannot start $TMCC: $!";
close(TM)
or die $? ? "$TMCC exited with status $?" : "Error closing pipe: $!";
#
# See if this node is allocated to an experiment.
#
print STDOUT "Checking Testbed reservation status ... \n";
open(TM, "$TMCC $NODE $STATCMD |")
or die "Cannot start $TMCC: $!";
$_ = <TM>;
close(TM)
or die $? ? "$TMCC exited with status $?" : "Error closing pipe: $!";
if ($_ =~ /^FREE/) {
print STDOUT " Free!\n";
exit(0);
}
if ($_ =~ /ALLOCATED=([-\@\w.]*)\/([-\@\w.]*)/) {
print STDOUT " Allocated: $1/$2!\n";
$project = $1;
}
else {
die("Error getting reservation status\n");
}
#
# Mount the project directory.
#
print STDOUT "Mounting the project directory on $PROJDIR/$project ... \n";
if (! mkdir("$PROJDIR/$project", 0770)) {
print STDERR "Could not make directory $PROJDIR/$project: $!\n";
}
if (system("$MOUNTCMD/$project $PROJDIR/$project") != 0) {
print STDERR "Could not mount project directory on $PROJDIR/$project.\n";
}
#
# Okay, lets find out about interfaces.
# Write a file of ifconfig lines, which will get executed.
#
print STDOUT "Checking Testbed interface configuration ... \n";
#
# Open a connection to the TMCD, and then open a local file into which
# we write ifconfig commands (as a shell script).
#
#open(TM, "$TMCC $NODE $IFCCMD |")
# or die "Cannot start $TMCC: $!";
#open(IFC, ">$TMIFC")
# or die("Could not open $TMIFC");
#print IFC "#!/bin/sh\n";
#while (<TM>) {
# $_ =~ /INTERFACE=(\d*) INET=([0-9.]*) MASK=([0-9.]*)/;
# printf STDOUT " $IFCONFIG", $1, $2, $3;
# printf IFC $IFCONFIG, $1, $2, $3;
#}
#close(TM);
#close(IFC);
#chmod(0755, "$TMIFC");
#
# Account stuff. Again, open a connection to the TMCD, and receive
# ADDGROUP and ADDUSER commands. We turn those into "pw" commands.
#
print STDOUT "Checking Testbed group/user configuration ... \n";
open(TM, "$TMCC $NODE $ACCTCMD |")
or die "Cannot start $TMCC: $!";
while (<TM>) {
if ($_ =~ /^ADDGROUP NAME=([-\@\w.]+) GID=([0-9]+)/) {
print STDOUT " Group: $1/$2\n";
$group = $1;
$gid = $2;
($exists) = getgrgid($gid);
if ($exists) {
next;
}
if (system("$GROUPADD -g $gid $group") != 0) {
print STDERR "Error adding new group $1/$2: $!\n";
}
next;
}
if ($_ =~
/^ADDUSER LOGIN=([0-9a-z]+) PSWD=([^:]+) UID=(\d+) GID=(\d+) ROOT=(\d) NAME="(.*)"/)
{
$login = $1;
$pswd = $2;
$uid = $3;
$gid = $4;
$root = $5;
$name = $6;
if ( $name =~ /^(([^:]+$|^))$/ ) {
$name = $1;
}
print STDOUT " User: $login/$uid/$gid/$root/$name\n";
($exists) = getpwuid($uid);
if ($exists) {
if ($root) {
$GLIST = "-G wheel";
}
system("$USERMOD $GLIST -g $gid $login");
next;
}
$GLIST = " ";
if ($root) {
$GLIST = "-G wheel";
}
if (system("$USERADD -u $uid -g $gid -p $pswd $GLIST ".
"-d /users/$login -s /bin/tcsh -c \"$name\" $login") != 0) {
print STDERR "Error adding new user $login\n";
next;
}
next;
}
}
close(TM);
#
# If node is free, reset to a moderately clean state.
#
sub cleanup_node () {
print STDOUT "Cleaning node; removing configuration files ...\n";
unlink @CONFIGS;
printf STDOUT "Resetting passwd and group files\n";
if (system("$CP -f $TMGROUP /etc/group") != 0) {
print STDERR "Could not copy default group file into place: $!\n";
exit(1);
}
if (system("$CP -f $TMPASSWD /etc/master.passwd_testbed") != 0) {
print STDERR "Could not copy default passwd file into place: $!\n";
exit(1);
}
if (system("$MKDB /etc/master.passwd_testbed") != 0) {
print STDERR "Failure running pwd_mkdb on default password file: $!\n";
exit(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