Commit 4fa870b7 authored by Leigh Stoller's avatar Leigh Stoller

Two unrelated changes. 1) Return the email address to version 9

clients so they can create a proper .forward file. 2) Add some
test code for seeing how feasible it is to do accounts on ops/tips
using tmcd instead of direct ssh. Initial results are not good; too
many accounts; does not scale well. Going to need a smarter protocol
for doing hundreds of accounts, but I will leave this code in place
for now. Note, unlike testbed nodes, control nodes must connect with
ssl.
parent 786cc95c
......@@ -14,12 +14,13 @@ package libsetup;
use Exporter;
@ISA = "Exporter";
@EXPORT =
qw ( libsetup_init inform_reboot cleanup_node check_status
qw ( libsetup_init cleanup_node check_status
doifconfig dohostnames check_nickname
doaccounts dorpms dotarballs dostartupcmd install_deltas
bootsetup nodeupdate startcmdstatus whatsmynickname
TBBackGround TBForkCmd vnodesetup
jailedsetup dojailconfig JailedNFSMounts findiface
tmccdie tmcctimeout
OPENTMCC CLOSETMCC RUNTMCC MFS REMOTE JAILED
......@@ -175,7 +176,7 @@ my $USESFS = 1;
#
# BE SURE TO BUMP THIS AS INCOMPATIBILE CHANGES TO TMCD ARE MADE!
#
sub TMCD_VERSION() { 8; };
sub TMCD_VERSION() { 9; };
#
# These are the TMCC commands.
......@@ -239,6 +240,11 @@ sub MFS() { if (-e "$ETCDIR/ismfs") { return 1; } else { return 0; } }
#
sub REMOTE() { if (-e "$ETCDIR/isrem") { return 1; } else { return 0; } }
#
# Same for a control node.
#
sub CONTROL() { if (-e "$ETCDIR/isctrl") { return 1; } else { return 0; } }
#
# Are we jailed? See above.
#
......@@ -332,15 +338,6 @@ sub RUNTMCC($;$$)
return 0;
}
#
# Inform the master we have rebooted.
#
sub inform_reboot()
{
RUNTMCC(TMCCCMD_REBOOT);
return 0;
}
#
# Reset to a moderately clean state.
#
......@@ -434,7 +431,7 @@ sub check_nickname()
#
# Process mount directives from TMCD. We keep track of all the mounts we
# have added in here so that we delete just the accounts we added, when
# have added in here so that we delete just the mounts we added, when
# project membership changes. Same goes for project directories on shared
# nodes. We use a simple perl DB for that.
#
......@@ -447,6 +444,24 @@ sub domounts()
my %sfsmounts;
my %sfsdeletes;
#
# Update our SFS hostid first. If this fails, dosfshostid will
# unset USESFS.
#
if ($USESFS) {
if (! MFS()) {
#
# Setup SFS hostid.
#
print STDOUT "Setting up for SFS ... \n";
dosfshostid();
}
else {
# No SFS on the MFS.
$USESFS = 0;
}
}
$TM = OPENTMCC(TMCCCMD_MOUNTS, "USESFS=$USESFS");
while (<$TM>) {
......@@ -1234,7 +1249,7 @@ sub doaccounts()
my $pat = q(ADDUSER LOGIN=([0-9A-Za-z]+) PSWD=([^:]+) UID=(\d+) GID=(.*) );
$pat .= q(ROOT=(\d) NAME="(.*)" HOMEDIR=(.*) GLIST="(.*)" );
$pat .= q(SERIAL=(\d+));
$pat .= q(SERIAL=(\d+) EMAIL="([-\w\@\.\+]+)");
while (($login, $info) = each %newaccounts) {
if ($info =~ /$pat/) {
......@@ -1246,6 +1261,7 @@ sub doaccounts()
$hdir = $7;
$glist = $8;
$serial= $9;
$email = $10;
if ( $name =~ /^(([^:]+$|^))$/ ) {
$name = $1;
}
......@@ -1297,39 +1313,35 @@ sub doaccounts()
}
#
# Skip ssh stuff if a local node or not updating (if the
# user did not exist, $doupdate will be true).
# Remote nodes and local control nodes get this.
#
if (!REMOTE() || !$doupdate) {
next;
}
#
# Must ask for the current home dir since we rely on pw.conf.
#
my (undef,undef,undef,undef,
undef,undef,undef,$homedir) = getpwuid($uid);
my $sshdir = "$homedir/.ssh";
my $forward = "$homedir/.forward";
#
# Create .ssh dir and populate it with an authkeys file.
#
TBNewsshKeyfile($sshdir, $uid, $gid, 1, @{$pubkeys1{$login}});
TBNewsshKeyfile($sshdir, $uid, $gid, 2, @{$pubkeys2{$login}});
#
# Give user a .forward back to emulab.
#
if (! -e $forward) {
system("echo '${login}\@emulab.net' > $forward");
if ((REMOTE() || CONTROL()) && $doupdate) {
#
# Must ask for the current home dir since we rely on pw.conf.
#
my (undef,undef,undef,undef,
undef,undef,undef,$homedir) = getpwuid($uid);
my $sshdir = "$homedir/.ssh";
my $forward = "$homedir/.forward";
#
# Create .ssh dir and populate it with an authkeys file.
#
TBNewsshKeyfile($sshdir, $uid, $gid, 1, @{$pubkeys1{$login}});
TBNewsshKeyfile($sshdir, $uid, $gid, 2, @{$pubkeys2{$login}});
#
# Give user a .forward back to emulab.
#
if (! -e $forward) {
system("echo '$email' > $forward");
chown($uid, $gid, $forward)
or warn("*** Could not chown $forward: $!\n");
chown($uid, $gid, $forward)
or warn("*** Could not chown $forward: $!\n");
chmod(0644, $forward)
or warn("*** Could not chmod $forward: $!\n");
chmod(0644, $forward)
or warn("*** Could not chmod $forward: $!\n");
}
}
}
else {
......@@ -1913,11 +1925,6 @@ sub dojailifconfig()
#
sub bootsetup()
{
#
# Inform the master that we have rebooted.
#
inform_reboot();
#
# Check allocation. Exit now if not allocated.
#
......@@ -1934,20 +1941,6 @@ sub bootsetup()
#
cleanup_node(0);
if ($USESFS) {
if (! MFS()) {
#
# Setup SFS hostid.
#
print STDOUT "Setting up for SFS ... \n";
dosfshostid();
}
else {
# No SFS on the MFS.
$USESFS = 0;
}
}
#
# Mount the project and user directories and symlink SFS "mounted"
# directories
......@@ -2055,20 +2048,6 @@ sub nodeupdateaux()
return 0;
}
if ($USESFS) {
if (! MFS()) {
#
# Setup SFS hostid.
#
print STDOUT "Setting up for SFS ... \n";
dosfshostid();
}
else {
# No SFS on the MFS.
$USESFS = 0;
}
}
#
# Mount the project and user directories and symlink SFS "mounted"
# directories
......@@ -2282,11 +2261,6 @@ sub install_deltas ()
#
sub whatsmynickname()
{
#
# Inform the master that we have rebooted. THIS MUST BE DONE!
#
inform_reboot();
#
# Check allocation. Exit now if not allocated.
#
......
......@@ -14,12 +14,13 @@ package libsetup;
use Exporter;
@ISA = "Exporter";
@EXPORT =
qw ( libsetup_init inform_reboot cleanup_node check_status
qw ( libsetup_init cleanup_node check_status
doifconfig dohostnames check_nickname
doaccounts dorpms dotarballs dostartupcmd install_deltas
bootsetup nodeupdate startcmdstatus whatsmynickname
TBBackGround TBForkCmd vnodesetup
jailedsetup dojailconfig JailedNFSMounts findiface
tmccdie tmcctimeout
OPENTMCC CLOSETMCC RUNTMCC MFS REMOTE JAILED
......@@ -175,7 +176,7 @@ my $USESFS = 1;
#
# BE SURE TO BUMP THIS AS INCOMPATIBILE CHANGES TO TMCD ARE MADE!
#
sub TMCD_VERSION() { 8; };
sub TMCD_VERSION() { 9; };
#
# These are the TMCC commands.
......@@ -239,6 +240,11 @@ sub MFS() { if (-e "$ETCDIR/ismfs") { return 1; } else { return 0; } }
#
sub REMOTE() { if (-e "$ETCDIR/isrem") { return 1; } else { return 0; } }
#
# Same for a control node.
#
sub CONTROL() { if (-e "$ETCDIR/isctrl") { return 1; } else { return 0; } }
#
# Are we jailed? See above.
#
......@@ -332,15 +338,6 @@ sub RUNTMCC($;$$)
return 0;
}
#
# Inform the master we have rebooted.
#
sub inform_reboot()
{
RUNTMCC(TMCCCMD_REBOOT);
return 0;
}
#
# Reset to a moderately clean state.
#
......@@ -434,7 +431,7 @@ sub check_nickname()
#
# Process mount directives from TMCD. We keep track of all the mounts we
# have added in here so that we delete just the accounts we added, when
# have added in here so that we delete just the mounts we added, when
# project membership changes. Same goes for project directories on shared
# nodes. We use a simple perl DB for that.
#
......@@ -447,6 +444,24 @@ sub domounts()
my %sfsmounts;
my %sfsdeletes;
#
# Update our SFS hostid first. If this fails, dosfshostid will
# unset USESFS.
#
if ($USESFS) {
if (! MFS()) {
#
# Setup SFS hostid.
#
print STDOUT "Setting up for SFS ... \n";
dosfshostid();
}
else {
# No SFS on the MFS.
$USESFS = 0;
}
}
$TM = OPENTMCC(TMCCCMD_MOUNTS, "USESFS=$USESFS");
while (<$TM>) {
......@@ -1234,7 +1249,7 @@ sub doaccounts()
my $pat = q(ADDUSER LOGIN=([0-9A-Za-z]+) PSWD=([^:]+) UID=(\d+) GID=(.*) );
$pat .= q(ROOT=(\d) NAME="(.*)" HOMEDIR=(.*) GLIST="(.*)" );
$pat .= q(SERIAL=(\d+));
$pat .= q(SERIAL=(\d+) EMAIL="([-\w\@\.\+]+)");
while (($login, $info) = each %newaccounts) {
if ($info =~ /$pat/) {
......@@ -1246,6 +1261,7 @@ sub doaccounts()
$hdir = $7;
$glist = $8;
$serial= $9;
$email = $10;
if ( $name =~ /^(([^:]+$|^))$/ ) {
$name = $1;
}
......@@ -1297,39 +1313,35 @@ sub doaccounts()
}
#
# Skip ssh stuff if a local node or not updating (if the
# user did not exist, $doupdate will be true).
# Remote nodes and local control nodes get this.
#
if (!REMOTE() || !$doupdate) {
next;
}
#
# Must ask for the current home dir since we rely on pw.conf.
#
my (undef,undef,undef,undef,
undef,undef,undef,$homedir) = getpwuid($uid);
my $sshdir = "$homedir/.ssh";
my $forward = "$homedir/.forward";
#
# Create .ssh dir and populate it with an authkeys file.
#
TBNewsshKeyfile($sshdir, $uid, $gid, 1, @{$pubkeys1{$login}});
TBNewsshKeyfile($sshdir, $uid, $gid, 2, @{$pubkeys2{$login}});
#
# Give user a .forward back to emulab.
#
if (! -e $forward) {
system("echo '${login}\@emulab.net' > $forward");
if ((REMOTE() || CONTROL()) && $doupdate) {
#
# Must ask for the current home dir since we rely on pw.conf.
#
my (undef,undef,undef,undef,
undef,undef,undef,$homedir) = getpwuid($uid);
my $sshdir = "$homedir/.ssh";
my $forward = "$homedir/.forward";
#
# Create .ssh dir and populate it with an authkeys file.
#
TBNewsshKeyfile($sshdir, $uid, $gid, 1, @{$pubkeys1{$login}});
TBNewsshKeyfile($sshdir, $uid, $gid, 2, @{$pubkeys2{$login}});
#
# Give user a .forward back to emulab.
#
if (! -e $forward) {
system("echo '$email' > $forward");
chown($uid, $gid, $forward)
or warn("*** Could not chown $forward: $!\n");
chown($uid, $gid, $forward)
or warn("*** Could not chown $forward: $!\n");
chmod(0644, $forward)
or warn("*** Could not chmod $forward: $!\n");
chmod(0644, $forward)
or warn("*** Could not chmod $forward: $!\n");
}
}
}
else {
......@@ -1913,11 +1925,6 @@ sub dojailifconfig()
#
sub bootsetup()
{
#
# Inform the master that we have rebooted.
#
inform_reboot();
#
# Check allocation. Exit now if not allocated.
#
......@@ -1934,20 +1941,6 @@ sub bootsetup()
#
cleanup_node(0);
if ($USESFS) {
if (! MFS()) {
#
# Setup SFS hostid.
#
print STDOUT "Setting up for SFS ... \n";
dosfshostid();
}
else {
# No SFS on the MFS.
$USESFS = 0;
}
}
#
# Mount the project and user directories and symlink SFS "mounted"
# directories
......@@ -2055,20 +2048,6 @@ sub nodeupdateaux()
return 0;
}
if ($USESFS) {
if (! MFS()) {
#
# Setup SFS hostid.
#
print STDOUT "Setting up for SFS ... \n";
dosfshostid();
}
else {
# No SFS on the MFS.
$USESFS = 0;
}
}
#
# Mount the project and user directories and symlink SFS "mounted"
# directories
......@@ -2282,11 +2261,6 @@ sub install_deltas ()
#
sub whatsmynickname()
{
#
# Inform the master that we have rebooted. THIS MUST BE DONE!
#
inform_reboot();
#
# Check allocation. Exit now if not allocated.
#
......
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