From 5a20f5baa5b3af753819c5b4a23634689dee61aa Mon Sep 17 00:00:00 2001 From: root Date: Mon, 29 Jun 2015 17:02:38 +0200 Subject: [PATCH] MO-P: Upload logins --- mop/admin/Makefile | 3 ++ mop/admin/mo-create-logins.sh | 3 +- mop/admin/mo-help-upload-logins.pl | 72 ++++++++++++++++++++++++++++++ mop/admin/mo-upload-logins.sh | 5 +++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 mop/admin/mo-help-upload-logins.pl create mode 100644 mop/admin/mo-upload-logins.sh diff --git a/mop/admin/Makefile b/mop/admin/Makefile index 359ea2c..6a8a9cb 100644 --- a/mop/admin/Makefile +++ b/mop/admin/Makefile @@ -7,6 +7,7 @@ PROGS+=$(addprefix $(o)/mop/admin/,\ mo-backup \ mo-cms-users \ mo-create-contestants mo-create-logins mo-create-public \ + mo-upload-logins mo-help-upload-logins \ mo-get-users) $(o)/mop/admin/md5crypt: $(o)/mop/admin/md5crypt.o $(LIBUCW) @@ -14,6 +15,8 @@ $(o)/mop/admin/md5crypt: $(o)/mop/admin/md5crypt.o $(LIBUCW) $(o)/mop/admin/mo-backup: $(s)/mop/admin/mo-backup.sh $(o)/mop/admin/mo-cms-users: $(s)/mop/admin/mo-cms-users.pl $(o)/mop/admin/mo-get-users: $(s)/mop/admin/mo-get-users.sh +$(o)/mop/admin/mo-help-upload-logins: $(s)/mop/admin/mo-help-upload-logins.pl $(o)/mop/admin/mo-create-contestants: $(s)/mop/admin/mo-create-contestants.sh $(o)/mop/admin/mo-create-logins: $(s)/mop/admin/mo-create-logins.sh $(o)/mop/admin/mo-create-public: $(s)/mop/admin/mo-create-public.sh +$(o)/mop/admin/mo-upload-logins: $(s)/mop/admin/mo-upload-logins.sh diff --git a/mop/admin/mo-create-logins.sh b/mop/admin/mo-create-logins.sh index f07324e..f0f3a78 100644 --- a/mop/admin/mo-create-logins.sh +++ b/mop/admin/mo-create-logins.sh @@ -60,12 +60,13 @@ case $mode in EOF bin/mo-get-users --full | while read user name; do + asciiname=$(echo $name | iconv -f utf-8 -t us-ascii//translit) passwd=`apg -n1 -m6 -Mncl -E"01lO" | cut -d" " -f1` passwd_md5=`echo $passwd | bin/md5crypt` echo $user:x:$uid:$uid:$name:$MO_ROOT/users/$user/$user:/bin/bash >> etcpasswd echo $user:x:$uid: >> etcgroup echo $user:$passwd_md5:`expr \`date +%s\` / 86400 - 1`:0:99999:7::: >> etcshadow - echo "\\user{$user}{$passwd}{$name}" >> logins.tex + echo "\\user{$user}{$passwd}{$asciiname}" >> logins.tex uid=$(($uid + 1)) done diff --git a/mop/admin/mo-help-upload-logins.pl b/mop/admin/mo-help-upload-logins.pl new file mode 100644 index 0000000..7957a17 --- /dev/null +++ b/mop/admin/mo-help-upload-logins.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl +# Helper script for synchronizing /etc/passwd, /etc/group, and /etc/shadow + +use common::sense; + +my $all = $ARGV[0] eq '--all'; +my @files = (); + +print "Syncing /etc/passwd\n"; +open my $p, '<', '/etc/passwd' or die; +open my $q, '>', '/etc/passwd.new' or die; +system qw(chmod --reference /etc/passwd /etc/passwd.new); +system qw(chown --reference /etc/passwd /etc/passwd.new); +my %sysusers = (); +while (<$p>) { + my @a = split /:/; + # FIXME: Hard-wired UIDs + if ($a[3] < 65000 || $a[3] >= 65500) { + print $q $_; + $sysusers{$a[0]} = 1; + } +} +open my $r, '<', 'etcpasswd' or die; +while (<$r>) { print $q $_; } +close $r; +close $q; +close $p; +push @files, 'passwd'; + +print "Syncing /etc/group\n"; +open my $p, '<', '/etc/group' or die; +open my $q, '>', '/etc/group.new' or die; +system qw(chmod --reference /etc/group /etc/group.new); +system qw(chown --reference /etc/group /etc/group.new); +while (<$p>) { + my @a = split /:/; + # FIXME: Hard-wired GIDs + if ($a[2] < 65000 || $a[2] >= 65500) { + print $q $_; + } +} +open my $r, '<', 'etcgroup' or die; +while (<$r>) { print $q $_; } +close $r; +close $q; +close $p; +push @files, 'group'; + +if ($all) { + print "Syncing /etc/shadow\n"; + open my $p, '<', '/etc/shadow' or die; + open my $q, '>', '/etc/shadow.new' or die; + system qw(chmod --reference /etc/shadow /etc/shadow.new); + system qw(chown --reference /etc/shadow /etc/shadow.new); + while (<$p>) { + my @a = split /:/; + if ($sysusers{$a[0]}) { + print $q $_; + } + } + open my $r, '<', 'etcshadow' or die; + while (<$r>) { print $q $_; } + close $r; + close $q; + close $p; + push @files, 'shadow'; +} + +for my $f (@files) { + rename "/etc/$f", "/etc/$f.old" or die "Rename failed: $!\n"; + rename "/etc/$f.new", "/etc/$f" or die "Rename failed: $!\n"; +} diff --git a/mop/admin/mo-upload-logins.sh b/mop/admin/mo-upload-logins.sh new file mode 100644 index 0000000..a1b72aa --- /dev/null +++ b/mop/admin/mo-upload-logins.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Upload created accounts to all machines +set -e +bex add -a etcpasswd -a etcgroup -a etcshadow -a bin/mo-help-upload-logins -i upload-logins -s 'Upload logins' -e './mo-help-upload-logins' all !contest -g +bex add -a etcpasswd -a etcgroup -a etcshadow -a bin/mo-help-upload-logins -i upload-passwords -s 'Upload logins and passwords' -e './mo-help-upload-logins --all' contest -g -- 2.39.5