Commit 9306d6ba authored by Ryan Jackson's avatar Ryan Jackson
Browse files

Lots of little bugs fixed after initial testing on inner elab setup.

parent 78fd1167
......@@ -466,23 +466,24 @@ tmcdresp_t *tmcd_handle_request(int sock, char *command, char *rdata, tmcdreq_t
/*
* Figure out what command was given.
*/
for (i = 0; i < numcommands; i++)
if (strncmp(command, xml_command_array[i].cmdname,
strlen(xml_command_array[i].cmdname)) == 0) {
for (i = 0; i < numcommands; i++) {
if (strcmp(command, xml_command_array[i].cmdname) == 0) {
flags = xml_command_array[i].flags;
break;
}
}
if (i == numcommands) {
for (i = 0; i < numrawcommands; i++)
if (strncmp(command, raw_xml_command_array[i].cmdname,
strlen(raw_xml_command_array[i].cmdname)) == 0) {
for (i = 0; i < numrawcommands; i++) {
if (strcmp(command, raw_xml_command_array[i].cmdname) == 0) {
is_xml_command = 0;
flags = raw_xml_command_array[i].flags;
break;
}
}
if (i == numrawcommands) {
info("%s: INVALID REQUEST: %.8s\n", reqp->nodeid, command);
printf("%s: INVALID REQUEST: %.8s\n", reqp->nodeid, command);
goto skipit;
}
......@@ -569,10 +570,7 @@ tmcdresp_t *tmcd_handle_request(int sock, char *command, char *rdata, tmcdreq_t
memcpy(response->data, (char *)xmlbuf, response->length);
xmlFree(xmlbuf);
response->data = (char *)xmlbuf;
}
else {
} else {
err = raw_xml_command_array[i].func(&response->data, &response->length, sock, reqp, rdata);
if (err)
......@@ -627,7 +625,7 @@ XML_COMMAND_PROTOTYPE(dostatus)
{
xmlNode *node;
node = new_response(root, "nodestatus");
node = new_response(root, "status");
/*
* Now check reserved table
*/
......@@ -1535,6 +1533,7 @@ XML_COMMAND_PROTOTYPE(doaccounts)
add_key(node, "key", pubkey_row[1]);
pubkeys_nrows--;
}
}
mysql_free_result(pubkeys_res);
......@@ -4546,7 +4545,7 @@ XML_COMMAND_PROTOTYPE(dofwinfo)
}
fwinfo_node = new_response(root, "fwinfo");
fwinfo_node = new_response(root, "firewallinfo");
/*
* Common case, no firewall
......@@ -4640,10 +4639,10 @@ XML_COMMAND_PROTOTYPE(dofwinfo)
if (res && mysql_num_rows(res) > 0) {
row = mysql_fetch_row(res);
if (row[0]) { /* XXX Ryan */
node = new_response(fwinfo_node, "fwvar")
node = new_response(fwinfo_node, "fwvar");
add_key(node, "var", "EMULAB_GWIP");
add_key(node, "value", CONTROL_ROUTER_IP);
node = new_response(fwinfo_node, "fwvar")
node = new_response(fwinfo_node, "fwvar");
add_key(node, "var", "EMULAB_GWMAC");
add_key(node, "value", row[0]);
}
......@@ -4713,7 +4712,7 @@ XML_COMMAND_PROTOTYPE(dofwinfo)
for (n = nrows; n > 0; n--) {
row = mysql_fetch_row(res);
node = new_response(fwrules_node, "fwrule");
node = new_response(fwinfo_node, "fwrule");
add_key(node, "ruleno", row[0]);
add_key(node, "rule", row[1]);
}
......@@ -5111,7 +5110,7 @@ XML_COMMAND_PROTOTYPE(dolocalize)
return 1;
}
node = new_response(root, "localize");
node = new_response(root, "localization");
row = mysql_fetch_row(res);
if (row[1]) {
add_key(node, "rootpubkey", row[1]);
......
......@@ -891,10 +891,12 @@ execute:
response = tmcd_handle_request(sock, bp, rdata, reqp);
skipit:
client_writeback(sock, response->data, response->length, istcp);
if (!istcp)
client_writeback_done(sock,
if (response) {
client_writeback(sock, response->data, response->length, istcp);
if (!istcp)
client_writeback_done(sock,
redirect ? &redirect_client : client);
}
#if 0
if (byteswritten && (command_array[i].flags & F_MINLOG) == 0)
......
......@@ -29,7 +29,7 @@ BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
# library and initialize itself.
#
use libsetup;
use libtmcc;
use libnewtmcc;
use librc;
# This runs as a separate Local System service on XP. Change to root.
......@@ -249,7 +249,7 @@ sub doboot()
#
# We want to restart, go around the loop again. Turn the cache off.
#
libtmcc::configtmcc("nocache", 1);
libnewtmcc::configtmcc("nocache", 1);
}
return;
}
......
......@@ -124,62 +124,68 @@ sub doboot()
#
# First just get the current set of groups/accounts from tmcd.
#
my $ptr = $tmccresults{"uc(addgroup)"};
if (ref $ptr ne 'ARRAY') {
$ptr = [ $ptr ];
}
foreach my $group (@$ptr) {
my $gname = $$group{'name'};
$gname = lc($gname)
if (PLAB());
if (REMOTE() && !JAILED() && !PLAB()) {
$gname = "emu-${gname}";
}
$newgroups{$gname} = $$group{'gid'};
}
my $ptr;
if ($ptr = $tmccresults{"ADDGROUP"}) {
if (ref $ptr ne 'ARRAY') {
$ptr = [ $ptr ];
}
foreach my $group (@$ptr) {
my $gname = $$group{'NAME'};
$gname = lc($gname)
if (PLAB());
if (REMOTE() && !JAILED() && !PLAB()) {
$gname = "emu-${gname}";
}
$ptr = $tmccresults{"uc(adduser)"};
if (ref $ptr ne 'ARRAY') {
$ptr = [ $ptr ];
$newgroups{$gname} = $$group{'GID'};
}
}
foreach my $user (@$ptr) {
if ($$user{'login'} !~ /^[-\w]+$/ && $$user{'pswd'} !~ /^[^:]+$/ &&
$$user{'uid'} !~ /^\d+$/ && $$user{'gid'} !~ /^.*$/ &&
$$user{'root'} !~ /^\d$/ && $$user{'name'} !~ /^.*$/ &&
$$user{'homedir'} !~ /^.*$/ && $$user{'glist'} !~ /^.*$/ &&
$$user{'serial'} !~ /^\d+$/ && $$user{'email'} !~ /^[-\w\@\.\+]+$/ &&
$$user{'shell'} !~ /^[-\w]*$/) {
if ($ptr = $tmccresults{"ADDUSER"}) {
if (ref $ptr ne 'ARRAY') {
$ptr = [ $ptr ];
}
warning("bad account data: for user $$user{'login'}");
}
else {
$newaccounts{$$user{'login'}} = $user;
foreach my $user (@$ptr) {
if ($$user{'LOGIN'} !~ /^[-\w]+$/ && $$user{'PSWD'} !~ /^[^:]+$/ &&
$$user{'UID'} !~ /^\d+$/ && $$user{'GID'} !~ /^.*$/ &&
$$user{'ROOT'} !~ /^\d$/ && $$user{'NAME'} !~ /^.*$/ &&
$$user{'HOMEDIR'} !~ /^.*$/ && $$user{'GLIST'} !~ /^.*$/ &&
$$user{'SERIAL'} !~ /^\d+$/ && $$user{'EMAIL'} !~ /^[-\w\@\.\+]+$/ &&
$$user{'SHELL'} !~ /^[-\w]*$/) {
warning("bad account data: for user $$user{'LOGIN'}");
}
else {
$newaccounts{$$user{'LOGIN'}} = $user;
}
}
}
$ptr = $tmccresults{"uc(pubkey)"};
if (ref $ptr ne 'ARRAY') {
$ptr = [ $ptr ];
}
if ($ptr = $tmccresults{"PUBKEY"}) {
if (ref $ptr ne 'ARRAY') {
$ptr = [ $ptr ];
}
foreach my $pubkey (@$ptr) {
my $login = $$pubkey{'login'};
if (! defined($pubkeys{$login})) {
$pubkeys{$login} = [];
}
push(@{$pubkeys{$login}}, $$pubkey{'key'});
foreach my $pubkey (@$ptr) {
my $login = $$pubkey{'LOGIN'};
if (! defined($pubkeys{$login})) {
$pubkeys{$login} = [];
}
push(@{$pubkeys{$login}}, $$pubkey{'KEY'});
}
}
$ptr = $tmccresults{"uc(sfskey)"};
if (ref $ptr ne 'ARRAY') {
$ptr = [ $ptr ];
}
foreach my $sfskey (@$ptr) {
# SFS key goes into the array.
#
push(@sfskeys, $$sfskey{'key'});
if ($ptr = $tmccresults{"SFSKEY"}) {
if (ref $ptr ne 'ARRAY') {
$ptr = [ $ptr ];
}
foreach my $sfskey (@$ptr) {
# SFS key goes into the array.
#
push(@sfskeys, $$sfskey{'KEY'});
}
}
# On CygWin, just make a batch of Windows accounts and generate
......@@ -338,16 +344,16 @@ sub doboot()
my @addedUsers = ();
while (($login, $info) = each %newaccounts) {
$pswd = $$info{'pswd'};
$uid = $$info{'uid'};
$gid = $$info{'gid'};
$root = $$info{'root'};
$name = $$info{'name'};
$hdir = $$info{'homedir'};
$glist = $$info{'glist'};
$serial= $$info{'serial'};
$email = $$info{'email'};
$shell = $$info{'shell'};
$pswd = $$info{'PSWD'};
$uid = $$info{'UID'};
$gid = $$info{'GID'};
$root = $$info{'ROOT'};
$name = $$info{'NAME'};
$hdir = $$info{'HOMEDIR'};
$glist = $$info{'GLIST'};
$serial= $$info{'SERIAL'};
$email = $$info{'EMAIL'};
$shell = $$info{'SHELL'};
if ( $name =~ /^(([^:]+$|^))$/ ) {
$name = $1;
}
......@@ -472,12 +478,12 @@ sub doboot()
}
foreach my $login (@addedUsers) {
$info = $newaccounts{$login};
$pswd = $$info{'pswd'};
$uid = $$info{'uid'};
$gid = $$info{'gid'};
$root = $$info{'root'};
$name = $$info{'name'};
$hdir = $$info{'homedir'};
$pswd = $$info{'PSWD'};
$uid = $$info{'UID'};
$gid = $$info{'GID'};
$root = $$info{'ROOT'};
$name = $$info{'NAME'};
$hdir = $$info{'HOMEDIR'};
# We have to put the authorized_keys files somewhere that they
# won't be covered up by the Samba homedir mounts.
......
......@@ -138,16 +138,16 @@ sub dokeyhash()
}
unlink TMKEYHASH();
return 0
if (! exists($tmccresults{"uc(hash)"}));
if (! exists($tmccresults{"HASH"}));
#
# There should be just one string. Ignore anything else.
#
if ($tmccresults{"uc(hash)"} =~ /^([\w]*)$/) {
if ($tmccresults{"HASH"} =~ /^([\w]*)$/) {
$keyhash = $1;
}
else {
fatal("Bad keyhash: $tmccresults{"uc(hash)"}");
fatal("Bad keyhash: $tmccresults{HASH}");
}
#
......@@ -175,16 +175,16 @@ sub doeventkey()
}
unlink TMEVENTKEY();
return 0
if (! exists($tmccresults{"uc(key)"}));
if (! exists($tmccresults{"KEY"}));
#
# There should be just one string. Ignore anything else.
#
if ($tmccresults{"uc(key)"} =~ /^([\w]*)$/) {
if ($tmccresults{"KEY"} =~ /^([\w]*)$/) {
$eventkey = $1;
}
else {
fatal("Bad eventkey line: $tmccresults{"uc(hash)"}");
fatal("Bad eventkey line: $tmccresults{HASH}");
}
#
......
......@@ -101,13 +101,13 @@ sub doboot()
fatal("Could not get localization info from server!");
}
# Important; if no results then do nothing.
return 0 if (! exists($tmccresults{"uc(rootpubkey)"}));
return 0 if (! exists($tmccresults{"ROOTPUBKEY"}));
#
# Go through and see what we got. For now, we expect just ssh keys
#
my $ptr = $tmccresults{"uc(rootpubkey)"};
$ptr = [ $ptr ] if (ref $pter ne 'ARRAY');
my $ptr = $tmccresults{"ROOTPUBKEY"};
$ptr = [ $ptr ] if (ref $ptr ne 'ARRAY');
foreach my $key (@$ptr) {
push(@pubkeys, $key);
......
......@@ -134,16 +134,16 @@ sub donodeid()
if (tmcc(TMCCCMD_NODEID, undef, \%tmccresults) < 0) {
fatal("Could not get nodeid from server!");
}
return 0 if (! exists($tmccresults{"uc(id)"}));
return 0 if (! exists($tmccresults{"ID"}));
#
# There should be just one string. Ignore anything else.
#
if ($tmccresults{"uc(id)"} =~ /([-\w]*)/) {
if ($tmccresults{"ID"} =~ /([-\w]*)/) {
$nodeid = $1;
}
else {
fatal("Bad nodeid line: $tmccresults{"uc(id)"}");
fatal("Bad nodeid line: $tmccresults{ID}");
}
system("echo '$nodeid' > ". TMNODEID);
......@@ -166,22 +166,22 @@ sub docreator()
#
# There should be one string for the creator of the experiment...
#
if ($tmccresults{"uc(creator)"} =~ /^([-\w]*)$/) {
if ($tmccresults{"CREATOR"} =~ /^([-\w]*)$/) {
$creator = $1;
}
else {
fatal("Bad creator line: $tmccresults{"uc(creator)"}");
fatal("Bad creator line: $tmccresults{CREATOR}");
}
system("echo '$creator' > ". TMCREATOR());
#
# ... and another string for the user who swapped it in.
#
if ($tmccresults{"uc(swapper)"} =~ /^([-\w]*)$/) {
if ($tmccresults{"SWAPPER"} =~ /^([-\w]*)$/) {
$swapper = $1;
}
else {
fatal("Bad swapper line: $tmccresults{"uc(swapper)"}");
fatal("Bad swapper line: $tmccresults{SWAPPER}");
}
system("echo '$swapper' > ". TMSWAPPER());
......
......@@ -193,6 +193,8 @@ sub doboot()
fatal("Could not get Inner Emulab Config info from server!");
}
# If no results then do nothing. No inner elab.
print "foo " . keys(%tmccresults) . "\n";
exit 0;
return 0 if (! keys(%tmccresults));
#
......@@ -264,7 +266,7 @@ sub doboot()
if ($line =~ /^(.*)="(.+)"$/ ||
$line =~ /^(.*)=(.+)$/) {
$emulabconfig{uc $key} = uc $tmccresults{$key};
$emulabconfig{uc $key} = $tmccresults{uc $key};
}
}
......
......@@ -132,34 +132,36 @@ sub doboot()
fatal("Could not get mount list from server!");
}
$ptr = $tmccresults{"uc(mount)"};
$ptr = [ $ptr ] if (ref $ptr ne 'ARRAY');
if ($ptr = $tmccresults{"MOUNT"}) {
$ptr = [ $ptr ] if (ref $ptr ne 'ARRAY');
foreach my $mount (@$ptr) {
my $remote = $$mount{'remote'};
my $local = $$mount{'local'};
foreach my $mount (@$ptr) {
my $remote = $$mount{'REMOTE'};
my $local = $$mount{'LOCAL'};
if ($remote =~ /^[-:\@\w\.\/]+$/ && $local =! /^[-\@\w\.\/]+$/) {
$mounts{$remote} = $local;
}
else {
warning("Malformed mount information: REMOTE=$remote LOCAL=$local");
}
if (($remote =~ /^[-:\@\w\.\/]+$/) && ($local =~ /^[-\@\w\.\/]+$/)) {
$mounts{$remote} = $local;
}
else {
warning("Malformed mount information: REMOTE=$remote LOCAL=$local");
}
}
}
$ptr = $tmccresults{"uc(sfs)"};
$ptr = [ $ptr ] if (ref $ptr ne 'ARRAY');
if ($ptr = $tmccresults{"SFS"}) {
$ptr = [ $ptr ] if (ref $ptr ne 'ARRAY');
foreach my $sfs (@$ptr) {
my $remote = $$sfs{'remote'};
my $local = $$sfs{'local'};
foreach my $sfs (@$ptr) {
my $remote = $$sfs{'REMOTE'};
my $local = $$sfs{'LOCAL'};
if ($remote =~ /^[-:\@\w\.\/]+$/ && $local =! /^[-\@\w\.\/]+$/) {
$sfss{$remote} = $local;
}
else {
warning("Malformed sfs information: REMOTE=$remote LOCAL=$local");
}
if (($remote =~ /^[-:\@\w\.\/]+$/) && ($local =~ /^[-\@\w\.\/]+$/)) {
$$sfs{$remote} = $local;
}
else {
warning("Malformed sfs information: REMOTE=$remote LOCAL=$local");
}
}
}
#
......
......@@ -75,6 +75,7 @@ if (@ARGV) {
$action = $ARGV[0];
}
# Execute the action.
SWITCH: for ($action) {
/^boot$/i && do {
......@@ -104,11 +105,12 @@ sub doboot()
{
my %agents = ();
my %userenv = ();
my %tmccresults;
#
# Need the pid/eid.
#
my ($pid, $eid, $vname) = check_nickname();
#my ($pid, $eid, $vname) = check_nickname();
#
# Daemonize and let the boot continue. We have to disconnect and
......@@ -155,15 +157,14 @@ sub doboot()
# This is backward compatible and enables us to boot up unallocated
# nodes (though I am not sure they would ever reach this script).
#
if (@agents == 0) {
my %tmccresults;
if (!keys(%agents)) {
if (tmcc(TMCCCMD_CREATOR, undef, \%tmccresults) < 0) {
fatal("Could not get UID for progagent from server!");
}
if ($tmccresults{"SWAPPER"} =~ /^[-\w]*$/) {
$uid = $tmccresults{"SWAPPER"});
$uid = $tmccresults{"SWAPPER"};
} elsif ($tmccresults{"CREATOR"} =~ /^[-\w]*$/) {
$uid = $tmccresults{"CREATOR"});
$uid = $tmccresults{"CREATOR"};
} else {
warning("Cannot determine UID for program agent, not running");
exit(0);
......@@ -178,7 +179,7 @@ sub doboot()
if (!open(RUN, ">$CONFIG")) {
fatal("Could not open $CONFIG: $!");
}
$ptr = $agents{'agent'};
$ptr = $agents{'AGENT'};
$ptr = [ $ptr ] if (ref $ptr ne 'ARRAY');
foreach my $agent (@$ptr) {
......
......@@ -94,6 +94,7 @@ sub doboot()
{
my %rpms = ();
my $errors = 0;
my %tmccresults;
print STDOUT "Checking Testbed RPM configuration ... \n";
......@@ -114,7 +115,7 @@ sub doboot()
#
my $installoption = ((REMOTE() || WINDOWS()) ? "-t" : "-c");
my $ptr = $tmccresults{"uc(package)"};
my $ptr = $tmccresults{"PACKAGE"};
$ptr = [ $ptr ] if (ref $ptr ne 'ARRAY');
foreach my $rpm (@$ptr) {
......
......@@ -101,7 +101,7 @@ sub doboot()
if (!open(RUN, ">" . TMSTARTUPCMD)) {
fatal("Could not open " . TMSTARTUPCMD . ": $!");
}
print RUN "$tmccresults{"uc(cmd)"}";
print RUN "$tmccresults{CMD}";
close(RUN);
chmod(0755, TMSTARTUPCMD);
......
......@@ -107,14 +107,14 @@ sub doboot()
#
# There should be just one string. Ignore anything else.
#
if ($tmccresults{"uc(server)"} =~ /^[-\w\.]*$/ ||
$tmccresults{"uc(isserver)"} =~ /\d/) {
if ($tmccresults{"SERVER"} =~ /^[-\w\.]*$/ ||
$tmccresults{"ISSERVER"} =~ /\d/) {
$syncserver = $tmccresults{"uc(server)"};
$startserver = $tmccresults{"uc(isserver)"};
$syncserver = $tmccresults{"SERVER"};
$startserver = $tmccresults{"ISSERVER"};
}
else {
fatal("Bad syncserver line: $tmccresults{"uc(server)"} $tmccresults{"uc(isserver)"}");
fatal("Bad syncserver line: $tmccresults{SERVER} $tmccresults{ISSERVER}");
}
#
......
......@@ -10,7 +10,7 @@
#
# Common routines and constants for the client bootime setup stuff.
#
package libsetup;
package libnewsetup;
use Exporter;
@ISA = "Exporter";
@EXPORT =
......@@ -40,7 +40,7 @@ use Exporter;
use English;
# The tmcc library.
use libtmcc;
use libnewtmcc;
#
# This is the VERSION. We send it through to tmcd so it knows what version
......@@ -49,13 +49,13 @@ use libtmcc;
# BE SURE TO BUMP THIS AS INCOMPATIBILE CHANGES TO TMCD ARE MADE!
#
sub TMCD_VERSION() { 29; };
libtmcc::configtmcc("version", TMCD_VERSION());
libnewtmcc::configtmcc("version", TMCD_VERSION());
# Control tmcc timeout.
sub libsetup_settimeout($) { libtmcc::configtmcc("timeout", $_[0]); };
sub libsetup_settimeout($) { libnewtmcc::configtmcc("timeout", $_[0]); };
# Refresh tmcc cache.
sub libsetup_refresh() { libtmcc::tmccgetconfig(); };
sub libsetup_refresh() { libnewtmcc::tmccgetconfig(); };
#
# For virtual (multiplexed nodes). If defined, tack onto tmcc command.
......@@ -75,7 +75,7 @@ sub libsetup_setvnodeid($)
}
$vnodeid = $vid;
libtmcc::configtmcc("subnode", $vnodeid);