Commit ca522ca0 authored by Russ Fish's avatar Russ Fish

Support for prepare/cleanup on CygWin

parent eeaa6aa2
...@@ -498,8 +498,8 @@ sub doboot() ...@@ -498,8 +498,8 @@ sub doboot()
# top-down, chowning the directory away and then trying to read it. # top-down, chowning the directory away and then trying to read it.
# #
# Okay, this is really wrong. The authkeys files can't be mode 600 # Okay, this is really wrong. The authkeys files can't be mode 600
# and owned by the user. They can be 644/root, or 600/SYSTEM. # and owned by the user. They can be 644/user, or 600/SYSTEM.
# This is a bug in sshd's use of setreuid(). We prefer 600/SYSTEM. # Is this a bug in sshd's use of setreuid()? We prefer 600/SYSTEM.
my $cmd = "$CHOWN SYSTEM $sshdir/*"; my $cmd = "$CHOWN SYSTEM $sshdir/*";
if (system($cmd) != 0) { if (system($cmd) != 0) {
warning("Failed $cmd: $!"); warning("Failed $cmd: $!");
...@@ -600,7 +600,7 @@ sub doshutdown() ...@@ -600,7 +600,7 @@ sub doshutdown()
# old accounts as needed. # old accounts as needed.
# Make the CygWin /etc/passwd and /etc/group files match Windows. # Make the CygWin /etc/passwd and /etc/group files match Windows.
os_account_cleanup() os_accounts_sync()
if (WINDOWS()); if (WINDOWS());
} }
...@@ -632,7 +632,7 @@ sub docleanup() ...@@ -632,7 +632,7 @@ sub docleanup()
unlink $gdb unlink $gdb
if (-e $gdb); if (-e $gdb);
# Hand this off to libloc to restore default passwd/group files. # Hand this off to liblocsetup to restore default passwd/group files.
os_account_cleanup(); os_account_cleanup();
} }
......
...@@ -120,7 +120,7 @@ sub doreconfig() ...@@ -120,7 +120,7 @@ sub doreconfig()
# #
sub docleanup() sub docleanup()
{ {
unlink TMNODEID(), TMCREATOR(); unlink TMNODEID(), TMCREATOR(), TMSWAPPER();
} }
# #
......
...@@ -258,6 +258,7 @@ sub CONTROL() { if (-e "$ETCDIR/isctrl") { return 1; } else { return 0; } } ...@@ -258,6 +258,7 @@ sub CONTROL() { if (-e "$ETCDIR/isctrl") { return 1; } else { return 0; } }
# #
# Same for a Windows (CygWinXP) node. # Same for a Windows (CygWinXP) node.
# #
# XXX If you change this, look in libtmcc::tmccgetconfig() as well.
sub WINDOWS() { if (-e "$ETCDIR/iscygwin") { return 1; } else { return 0; } } sub WINDOWS() { if (-e "$ETCDIR/iscygwin") { return 1; } else { return 0; } }
# #
......
...@@ -538,7 +538,9 @@ sub tmccgetconfig() ...@@ -538,7 +538,9 @@ sub tmccgetconfig()
return -1; return -1;
} }
if (runtmcc("fullconfig", undef, \@tmccresults) < 0 || # XXX Can't "use libsetup" in libtmcc to reference the WINDOWS() function.
my $arg = (-e "$ETCDIR/iscygwin") ? "pubkeys" : undef;
if (runtmcc("fullconfig", $arg, \@tmccresults) < 0 ||
!scalar(@tmccresults)) { !scalar(@tmccresults)) {
warn("*** WARNING: Could not get fullconfig from tmcd!\n"); warn("*** WARNING: Could not get fullconfig from tmcd!\n");
return -1; return -1;
......
...@@ -91,6 +91,7 @@ script-install: dir-install $(SCRIPTS) ...@@ -91,6 +91,7 @@ script-install: dir-install $(SCRIPTS)
$(INSTALL) -m 755 $(SRCDIR)/liblocsetup.pm $(BINDIR)/liblocsetup.pm $(INSTALL) -m 755 $(SRCDIR)/liblocsetup.pm $(BINDIR)/liblocsetup.pm
$(INSTALL) -m 755 $(SRCDIR)/startsshd $(BINDIR)/startsshd $(INSTALL) -m 755 $(SRCDIR)/startsshd $(BINDIR)/startsshd
$(INSTALL) -m 755 $(SRCDIR)/stopsshd $(BINDIR)/stopsshd $(INSTALL) -m 755 $(SRCDIR)/stopsshd $(BINDIR)/stopsshd
$(INSTALL) -m 755 $(SRCDIR)/prepare $(BINDIR)/prepare
$(INSTALL) -c -m 755 -o root -g wheel -d /sbin $(INSTALL) -c -m 755 -o root -g wheel -d /sbin
$(INSTALL) -m 755 $(SRCDIR)/reboot /sbin/reboot $(INSTALL) -m 755 $(SRCDIR)/reboot /sbin/reboot
ln -f -s /bin/shutdown /sbin/shutdown ln -f -s /bin/shutdown /sbin/shutdown
......
...@@ -12,10 +12,10 @@ package liblocsetup; ...@@ -12,10 +12,10 @@ package liblocsetup;
use Exporter; use Exporter;
@ISA = "Exporter"; @ISA = "Exporter";
@EXPORT = @EXPORT =
qw ( $CP $LN $RM $CHOWN $CHMOD $TOUCH $MOUNT $EGREP qw ( $CP $LN $RM $CHOWN $CHMOD $TOUCH $MOUNT $UMOUNT $EGREP
$NFSMOUNT $UMOUNT $SFCMOUNT $SFCUMOUNT $NTS $NET $HOSTSFILE $NTS $NET $HOSTSFILE
$TMPASSWD $SFSSD $SFSCD $RPMCMD $TMPASSWD $SFSSD $SFSCD $RPMCMD
os_account_cleanup os_accounts_start os_accounts_end os_account_cleanup os_accounts_start os_accounts_end os_accounts_sync
os_ifconfig_line os_etchosts_line os_ifconfig_line os_etchosts_line
os_setup os_groupadd os_groupgid os_useradd os_userdel os_usermod os_mkdir os_setup os_groupadd os_groupgid os_useradd os_userdel os_usermod os_mkdir
os_ifconfig_veth os_ifconfig_veth
...@@ -57,23 +57,14 @@ $CHOWN = "/bin/chown"; ...@@ -57,23 +57,14 @@ $CHOWN = "/bin/chown";
$CHMOD = "/bin/chmod"; $CHMOD = "/bin/chmod";
$TOUCH = "/bin/touch"; $TOUCH = "/bin/touch";
$MOUNT = "/bin/mount"; $MOUNT = "/bin/mount";
$UMOUNT = "/bin/umount";
$EGREP = "/bin/egrep -q"; $EGREP = "/bin/egrep -q";
# Emulab wrappers for Windows. # Emulab wrappers for Windows.
$NFSMOUNT = "$BINDIR/emount";
$UMOUNT = "$BINDIR/eumount";
$MKPASSWD = "/bin/mkpasswd"; $MKPASSWD = "/bin/mkpasswd";
$MKGROUP = "/bin/mkgroup"; $MKGROUP = "/bin/mkgroup";
$AWK = "/bin/gawk"; $AWK = "/bin/gawk";
$CYGMOUNT = "/bin/mount";
$CYGUOUNT = "/bin/umount";
$SFC = "/cygdrive/c/SFU/common";
$SFCMOUNT = "$SFC/mount";
$SFCUMOUNT = "$SFC/umount";
$NTS = "/cygdrive/c/WINDOWS/system32"; $NTS = "/cygdrive/c/WINDOWS/system32";
$NET = "$NTS/net"; $NET = "$NTS/net";
$NETSH = "$NTS/netsh"; $NETSH = "$NTS/netsh";
...@@ -95,6 +86,7 @@ my $IFC_FDUPLEX = "FD"; ...@@ -95,6 +86,7 @@ my $IFC_FDUPLEX = "FD";
my $IFC_HDUPLEX = "HD"; my $IFC_HDUPLEX = "HD";
my @LOCKFILES = ("/etc/group.lock", "/etc/gshadow.lock"); my @LOCKFILES = ("/etc/group.lock", "/etc/gshadow.lock");
my $MKDIR = "/bin/mkdir"; my $MKDIR = "/bin/mkdir";
my $RMDIR = "/bin/rmdir";
my $GATED = "/usr/sbin/gated"; my $GATED = "/usr/sbin/gated";
my $ROUTE = "/sbin/route"; my $ROUTE = "/sbin/route";
my $SHELLS = "/etc/shells"; my $SHELLS = "/etc/shells";
...@@ -106,6 +98,87 @@ my $usershellsfile = "$BOOTDIR/usershells"; ...@@ -106,6 +98,87 @@ my $usershellsfile = "$BOOTDIR/usershells";
# OS dependent part of cleanup node state. # OS dependent part of cleanup node state.
# #
sub os_account_cleanup() sub os_account_cleanup()
{
# Undo what rc.mounts and rc.accounts did.
# The users list could be gotten from multiple places; let's use the /users
# directory as truth.
if (opendir(DIRHANDLE, "/users")) {
while ($name = readdir(DIRHANDLE)) {
if ($name =~ m/^\.+/) {
next;
}
print "Removing user: $name\n";
# There is always an NT account.
my $cmd = "$NET user $name /delete > /dev/null";
if (system($cmd) != 0) {
warning("Failed: ($cmd), $!\n");
}
# There will only be an NT homedir if the user has logged in sometime.
$cmd = "$RM -rf C:/Documents and Settings/$name";
if (system($cmd) != 0) {
warning("Failed: ($cmd), $!\n");
}
# Unmount the homedir so we can get to the mount point.
$cmd = "$UMOUNT /users/$name";
if (system($cmd) != 0) {
warning("Failed: ($cmd), $!\n");
}
$cmd = "$RMDIR /users/$name";
if (system($cmd) != 0) {
warning("Failed: ($cmd), $!\n");
}
}
closedir(DIRHANDLE);
# Make the CygWin /etc/passwd and /etc/group files match Windows.
os_accounts_sync();
}
# Clean out the user /sshkeys directories.
$cmd = "$CHOWN -R root /sshkeys";
if (system($cmd) != 0) {
warning("Failed ($cmd): $!");
}
$cmd = "$RM -rf /sshkeys";
if (system($cmd) != 0) {
warning("Failed ($cmd): $!");
}
# Clean out the /proj directories.
if (opendir(DIRHANDLE, "/proj")) {
while ($name = readdir(DIRHANDLE)) {
if ($name =~ m/^\.+/) {
next;
}
print "Removing project: $name\n";
# Unmount the project dir so we can get to the mount point.
$cmd = "$UMOUNT /proj/$name";
if (system($cmd) != 0) {
warning("Failed ($cmd): $!");
}
$cmd = "$RMDIR /proj/$name";
if (system($cmd) != 0) {
warning("Failed ($cmd): $!");
}
}
}
# Just unmount /share.
$cmd = "$UMOUNT /share";
if (system($cmd) != 0) {
warning("Failed ($cmd): $!");
}
}
#
# Make the CygWin /etc/passwd and /etc/group files match Windows.
#
sub os_accounts_sync()
{ {
unlink @LOCKFILES; unlink @LOCKFILES;
...@@ -369,7 +442,7 @@ sub os_accounts_end() ...@@ -369,7 +442,7 @@ sub os_accounts_end()
# Make the CygWin /etc/passwd and /etc/group files match Windows. # Make the CygWin /etc/passwd and /etc/group files match Windows.
# Note that the group membership is not reported into the CygWin files. # Note that the group membership is not reported into the CygWin files.
return os_account_cleanup(); return os_accounts_sync();
} }
# #
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
require 'ctime.pl';
#
# Prepare the node for cutting a new image. Should be run just prior.
#
# Note: No /etc/dumpdates support on CygWin, and no /etc/fstab or /var/account either.
my @DBFILES = ();
my @VARDIRS = ("logs", "db", "jails", "boot", "lock", "lib/dhcp");
my $LOGDIR = "/var/log";
my $RUNDIR = "/var/run";
my $HISTORY = "~root/.bash_history";
my $MAILFILE = "/var/spool/mail/root";
my $NTPDRIFT = "/etc/ntp/drift";
#
# Dead wood in $BINDIR
# If you remove/move a script, list it here so that it goes away when the
# image is remade.
#
my @DEADFILES = ("rc.agents", "rc.delayagent", "rc.delta", "rc.healthd",
"rc.injail", "rc.ipod", "rc.mfs", "rc.progagent",
"rc.setup", "rc.slothd", "rc.testbed",
"batchcmddone", "bootsetup", "install-tarfile",
"jailsetup", "update_delays", "rc/rc.linux",
"sethostname" # replaced by sethostname.dhclient on linux
);
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
#
# Turn off line buffering on output
#
$| = 1;
#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself.
#
use libsetup;
#
# First clean up the node as it would be if free.
#
cleanup_node(1);
print "Running $BINDIR/rc/rc.config to clean up ...\n";
system("$BINDIR/rc/rc.config reset");
print "Removing old DB files ...\n";
foreach my $dbfile (@DBFILES) {
if (-e $dbfile) {
unlink($dbfile) or
die("Could not unlink $dbfile");
}
}
print "Cleaning logfiles ...\n";
opendir(LOG,$LOGDIR) or
die("Could not open directory $LOGDIR: $!");
while ($dirent = readdir(LOG)) {
my $file = $LOGDIR . "/" . $dirent;
if (-f $file) {
if (($file =~ /\.\d$/) || ($file =~ /\.\d\.gz$/)) {
# Remove archived logfiles
unlink($file) or
die("Could not unlink $file: $!");
} elsif (-s $file) {
# Truncate other logfiles - many do not get re-created
truncate($file,0) or
die("Could not truncate $file: $!");
}
}
}
closedir(LOG);
print "Removing root's history ...\n";
if (-f $HISTORY) {
unlink($HISTORY) or
die("Could not unlink $HISTORY: $!");
}
print "Removing root's mailfile ...\n";
if (-f $MAILFILE) {
unlink($MAILFILE) or
die("Could not unlink $MAILFILE: $!");
}
#
# Just removing the drift file results in no drift being tracked,
# so set it to zero instead. Not ideal, but at least the clock will
# stabilize eventually this way.
#
print "Resetting drift in $NTPDRIFT ...\n";
if (-f $NTPDRIFT) {
open(DRIFT, ">$NTPDRIFT") or
die("Could not open $NTPDRIFT: $!");
print DRIFT "0\n";
close(DRIFT);
}
print "Clearing out $RUNDIR ...\n";
system("rm -rf $RUNDIR/*.pid");
print "Clearing out /tmp ...\n";
system("chown -R root /tmp");
system("rm -rf /tmp/* /tmp/.??*");
print "Clearing out C:/TEMP ...\n";
system("chown -R root C:/TEMP");
system("rm -rf C:/TEMP/* C:/TEMP/.??*");
print "Clearing out directories in $VARDIR ...\n";
foreach my $dir (@VARDIRS) {
if (-d "$VARDIR/$dir") {
system("rm -rf $VARDIR/$dir/*");
}
}
print "Clearing out old Emulab scripts and binaries in $BINDIR ...\n";
foreach my $file (@DEADFILES) {
if (-f "$BINDIR/$file") {
unlink("$BINDIR/$file") or
warn("*** could not remove $BINDIR/$file\n");
}
}
print "Removing backup files in /etc\n";
opendir(ETC,"/etc") or
die ("Couldn't open /etc: $!");
while ($dirent = readdir(ETC)) {
my $file = "/etc/" . $dirent;
if (-f $file) {
if (($file =~ /~$/) || ($file =~ /-$/)) {
unlink($file) or
die ("Couldn't unlink $file: $!");
}
}
}
closedir(ETC);
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