Commit 481787cb authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Checkpoint for posterity.

parent dab646b5
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# All rights reserved.
#
SRCDIR = @srcdir@
TESTBED_SRCDIR = @top_srcdir@
OBJDIR = ../..
SUBDIR = collab/mailman
include $(OBJDIR)/Makeconf
SBIN_SCRIPTS = addmmlist setmmlistmembers mmsetup
CTRL_LIBEXEC_SCRIPTS = genaliases
CTRL_LIB_FILES = mmscript.py
CTRL_SBIN_SCRIPTS = mailmanproxy
#
# Force dependencies on the scripts so that they will be rerun through
# configure if the .in file is changed.
#
all: $(SBIN_SCRIPTS) $(CTRL_SBIN_SCRIPTS) $(CTRL_LIBEXEC_SCRIPTS) \
$(CTRL_LIB_FILES)
include $(TESTBED_SRCDIR)/GNUmakerules
install: $(addprefix $(INSTALL_SBINDIR)/, $(SBIN_SCRIPTS)) \
$(addprefix $(INSTALL_DIR)/opsdir/libexec/mailman/, $(CTRL_LIBEXEC_SCRIPTS)) \
$(addprefix $(INSTALL_DIR)/opsdir/sbin/, $(CTRL_SBIN_SCRIPTS)) \
$(addprefix $(INSTALL_DIR)/opsdir/lib/mailman/, $(CTRL_LIB_FILES))
boss-install: install
post-install:
chown root $(INSTALL_SBINDIR)/addmmlist
chmod u+s $(INSTALL_SBINDIR)/addmmlist
chown root $(INSTALL_SBINDIR)/setmmlistmembers
chmod u+s $(INSTALL_SBINDIR)/setmmlistmembers
#
# Control node installation (okay, plastic)
#
control-install: \
$(addprefix $(INSTALL_SBINDIR)/, $(CTRL_SBIN_SCRIPTS)) \
$(addprefix $(INSTALL_LIBDIR)/mailman/, $(CTRL_LIB_FILES)) \
$(addprefix $(INSTALL_LIBEXECDIR)/mailman/, $(CTRL_LIBEXEC_FILES))
clean:
rm -f *.o core
$(INSTALL_DIR)/opsdir/sbin/%: %
@echo "Installing $<"
-mkdir -p $(INSTALL_DIR)/opsdir/sbin
$(INSTALL) $< $@
$(INSTALL_DIR)/opsdir/lib/mailman/%: %
@echo "Installing $<"
-mkdir -p $(INSTALL_DIR)/opsdir/lib/mailman
$(INSTALL_DATA) $< $@
$(INSTALL_DIR)/opsdir/libexec/mailman/%: %
@echo "Installing $<"
-mkdir -p $(INSTALL_DIR)/opsdir/libexec/mailman
$(INSTALL) $< $@
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
#
# Add a mailman list, say for a project or other reason. If for a project
# the admin password comes from the groups table. Otherwise it comes from
# the sitevars table cause its assumed to be an admins list of some kind.
#
sub usage()
{
print STDOUT "Usage: addmmlist -a <listname> or\n";
print STDOUT " addmmlist -u <listname> <listowner> <listpassword>\n";
exit(-1);
}
my $optlist = "dau";
my $debug = 0;
my $listtype;
my $listname;
my $listowner;
my $listowner_email;
my $listpasswd;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $CONTROL = "@USERNODE@";
my $BOSSNODE = "@BOSSNODE@";
my $OURDOMAIN = "@OURDOMAIN@";
my $MAILMANSUPPORT= @MAILMANSUPPORT@;
my $SSH = "$TB/bin/sshtb";
my $MMPROXY = "$TB/sbin/mailmanproxy";
# Protos
sub fatal($);
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/usr/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
#
# Load the Testbed support stuff.
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;
#
# We don't want to run this script unless its the real version.
#
if ($EUID != 0) {
die("*** $0:\n".
" Must be setuid! Maybe its a development version?\n");
}
#
# This script is setuid, so please do not run it as root. Hard to track
# what has happened.
#
if ($UID == 0) {
die("*** $0:\n".
" Please do not run this as root! Its already setuid!\n");
}
#
# If no mailman support, just exit.
#
if (! $MAILMANSUPPORT) {
print "MailMan support is not enabled. Exit ...\n";
exit(0);
}
#
# Only testbed admins.
#
if (!TBAdmin($UID)) {
die("*** $0:\n".
" Must be a testbed admin to run this script\n");
}
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"a"})) {
$listtype = "admin";
usage()
if (@ARGV != 1);
$listname = $ARGV[0];
}
if (defined($options{"u"})) {
my $listowner;
$listtype = "user";
usage()
if (@ARGV != 3);
$listname = $ARGV[0];
$listowner = $ARGV[1];
$listpasswd = $ARGV[2];
#
# Untaint args.
#
if ($listowner =~ /^([-\w]+)$/) {
$listowner = $1;
}
else {
die("Bad data in listowner: $listowner");
}
if ($listpasswd =~ /^([-\w]+)$/) {
$listpasswd = $1;
}
else {
die("Bad data in listpasswd: $listpasswd");
}
}
usage()
if (! (defined($options{"a"}) || defined($options{"u"})));
usage()
if (defined($options{"a"}) && defined($options{"u"}));
#
# Untaint args.
#
if ($listname =~ /^([-\w]+)$/) {
$listname = $1;
}
else {
die("Bad data in listname: $listname");
}
if ($listtype eq "admin") {
# An admins list of some kind.
$listowner_email = $TBOPS;
if (! TBGetSiteVar("general/mailman/password", \$listpasswd)) {
fatal("Could not mailman admin password from sitevars!");
}
}
else {
# A user created list.
$listowner_email = "${listowner}\@${OURDOMAIN}";
}
#
# Note that since we are sending cleartext passwords over, pipe the info
# into its STDIN so that the passwords are not visible in a ps listing.
#
# For ssh.
#
$UID = $EUID;
if ($CONTROL ne $BOSSNODE) {
my $optarg = ($debug ? "-d" : "");
print "Adding mailman list $listname ($listtype) on $CONTROL.\n";
if (system("echo '$listowner_email $listpasswd' | ".
"$SSH -host $CONTROL $MMPROXY addlist $listname $listtype")) {
fatal("$MMPROXY failed on $CONTROL!");
}
}
exit(0);
sub fatal($)
{
my($mesg) = $_[0];
die("*** $0:\n".
" $mesg\n");
}
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
use Errno;
#
# Generate a new aliases database from the existing mailman lists.
#
sub usage()
{
print "Usage: genaliases\n";
exit(-1);
}
my $optlist = "d";
my $debug = 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $MAILMANDIR = "/usr/local/mailman";
my $MMBINDIR = "$MAILMANDIR/bin";
my $MMALIASES = "/etc/mail/aliases.mailman";
my $NEWALIASES = "/usr/bin/newaliases";
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Only real root, cause the script has to read/write a pid file that
# cannot be accessed by the user.
#
if ($UID != 0) {
die("*** $0:\n".
" Must be root to run this script!\n");
}
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libtestbed;
# Protos
sub fatal($);
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (@ARGV) {
usage();
}
#
# Generate the new aliases into a temp file. If that works, move it
# to /etc/mail and then run newaliases
#
my $tempfile = "/tmp/mailman-aliases.$$";
# Run the config script.
system("$MMBINDIR/genaliases -q > $tempfile") == 0 or
fatal("Could not generate new mailman aliases file!");
system("/bin/mv -f $tempfile $MMALIASES") == 0 or
fatal("Could not mv $tempfile to $MMALIASES!");
system("$NEWALIASES") == 0 or
fatal("Could not regenerate the aliases database!");
unlink($tempfile);
exit(0);
sub fatal($)
{
my($mesg) = $_[0];
unlink($tempfile)
if (defined($tempfile) && -e $tempfile);
die("*** $0:\n".
" $mesg\n");
}
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
use Errno;
#
# A wrapper for messing with Mailman from boss.
#
sub usage()
{
print "Usage: mailmanproxy addlist <listname> <listtype> or\n";
print " mailmanproxy setlistmembers <listname> or\n";
print " mailmanproxy modifymember <email>\n";
exit(-1);
}
my $optlist = "dn";
my $debug = 1;
my $impotent = 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $OURDOMAIN = "@OURDOMAIN@";
my $MAILMANDIR = "/usr/local/mailman";
my $MMBINDIR = "$MAILMANDIR/bin";
my $MMLISTDIR = "$MAILMANDIR/lists";
my $GENALIASES = "$TB/libexec/mailman/genaliases";
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
# For Mailman withlist wrapper
$ENV{'PYTHONPATH'} = "$TB/lib/mailman";
#
# Only real root, cause the script has to read/write a pid file that
# cannot be accessed by the user.
#
if ($UID != 0) {
die("*** $0:\n".
" Must be root to run this script!\n");
}
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libtestbed;
# Protos
sub fatal($);
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"n"})) {
$impotent = 1;
}
if (! @ARGV) {
usage();
}
#
# Before we continue, flip to mailman user/group.
#
my (undef,undef,$unix_uid) = getpwnam("mailman") or
fatal("No such user mailman!");
my (undef,undef,$unix_gid) = getgrnam("mailman") or
fatal("No such group mailman!");
$GID = $unix_gid;
$EGID = $unix_gid;
$EUID = $UID = $unix_uid;
$ENV{'USER'} = "mailman";
$ENV{'LOGNAME'} = "mailman";
#
# Lets work from the mailman dir ...
#
chdir($MAILMANDIR) or
fatal("Could not chdir to $MAILMANDIR!");
my $action = shift(@ARGV);
if ($action eq "addlist") {
exit(AddList(@ARGV));
}
elsif ($action eq "setlistmembers") {
exit(SetListMembers(@ARGV));
}
elsif ($action eq "modifymember") {
exit(ModifyMember(@ARGV));
}
elsif ($action eq "xlogin") {
exit(xLogin(@ARGV));
}
else {
die("*** $0:\n".
" Do not know what to do with '$action'!\n");
}
exit(0);
#
# Create a new project mailing list.
#
sub AddList(@)
{
usage()
if (@_ != 2);
my ($name, $listtype) = @_;
my ($owneremail, $password) = ();
# Other info for list comes in from STDIN.
$_ = <STDIN>;
usage()
if (!defined($_));
if ($_ =~ /^(.*) (.*)$/) {
$owneremail = $1;
$password = $2;
}
else {
fatal("AddList: Bad line in input: $_");
}
# Step 1: Create the list.
if (! -d "$MMLISTDIR/" . lc($name)) {
system("$MMBINDIR/newlist -q $name $owneremail $password") == 0 or
fatal("AddList: Could not create mailing list!");
}
# Step 2: Config the list. We just need to alter a few of the defaults.
my $tempfile = "/tmp/config.$$";
open(CONFIG, "> $tempfile") or
fatal("Could not open $tempfile for writing!");
#
# These options are described in gory detail in the listconfig file
# in the source directory.
#
print CONFIG "real_name = '$name'\n";
print CONFIG "owner = ['$owneremail']\n";
print CONFIG "description = 'Emulab Mail list: $name'\n";
print CONFIG "subject_prefix = '[Emulab Mail List: $name] '\n";
print CONFIG "reply_goes_to_list = 1\n";
print CONFIG "send_reminders = False\n";
print CONFIG "send_welcome_msg = False\n";
print CONFIG "send_goodbye_msg = False\n";
if ($listtype eq "admin") {
# No need for tbops to see any of this.
print CONFIG "admin_notify_mchanges = 0\n";
# Users may not unsubscribe from our lists. Only their own.
print CONFIG "unsubscribe_policy = 0\n";
}
else {
print CONFIG "admin_notify_mchanges = 1\n";
print CONFIG "unsubscribe_policy = 1\n";
}
print CONFIG "max_message_size = 500\n";
print CONFIG "host_name = '$OURDOMAIN'\n";
print CONFIG "advertised = 0\n";
print CONFIG "subscribe_policy = 3\n";
print CONFIG "obscure_addresses = 0\n";
print CONFIG "archive = True\n";
print CONFIG "archive_private = 1\n";
print CONFIG "digestable = 0\n";
# Be default, lists are closed unless the mail originates in the domain.
# The point is to allow admin people to post to the lists, but this will
# do for now, since we do not expect spammers from within ...
print CONFIG "generic_nonmember_action = 2\n";
print CONFIG "accept_these_nonmembers = ['^.*\@.*${OURDOMAIN}\$', ".
"'^.*\@.*utah.edu\$']\n";
close(CONFIG);
# Run the config script.
system("$MMBINDIR/config_list -i $tempfile $name") == 0 or
fatal("AddList: Could not configure mailing list!");
unlink($tempfile);
# Step 3: Regen the aliases. We use an external script for this.
# $EUID = $UID = 0;
# system("$GENALIASES") == 0 or
# fatal("AddList: Could not generate a new aliases file!");
return 0;
}
#
# Set the membership for a list; this mirrors how genelists operates.
# The main difference is that we have to deal with the passwd.
#
sub SetListMembers(@)
{
usage()
if (@_ != 1);
my ($listname) = @_;
if ($debug) {
print "Setting members for list: $listname\n";
}
#
# The list of users and their passwords is going to come from stdin.
# The actual format looks like:
#
# email-addr password 'full name'
#
# All of these are indexed by the email-addr.
#
my %members = (); # Stores the password.
my %fullnames = ();
my %curmembers = ();
while (<STDIN>) {
# Allow for comments
if ($_ =~ /^\#/) {
next;
}
elsif ($_ =~ /^(.*) (.*) '(.*)'$/) {
$members{$1} = $2;
$fullnames{$1} = $3;
}
else {
print STDERR "Bad line in input: $_";
}
}
#
# Lets find out which members are already subscribed. We also want their
# fullname info.
#