chiark / gitweb /
update licence to GPLv3 or later (was GPLv2 or later).
[chiark-utils.git] / sync-accounts / sync-accounts
index 44daddbff72df601b9703259abe6e23804cefa71..5e26a988e4371e60e075bda8b52b3f94dbd68823 100755 (executable)
@@ -7,7 +7,7 @@
 #
 #  sync-accounts is free software; you can redistribute it and/or
 #  modify it under the terms of the GNU General Public License as
 #
 #  sync-accounts is free software; you can redistribute it and/or
 #  modify it under the terms of the GNU General Public License as
-#  published by the Free Software Foundation; either version 2, or (at
+#  published by the Free Software Foundation; either version 3, or (at
 #  your option) any later version.
 #
 #  sync-accounts is distributed in the hope that it will be useful,
 #  your option) any later version.
 #
 #  sync-accounts is distributed in the hope that it will be useful,
@@ -19,7 +19,7 @@
 #  If not, write to the Free Software Foundation, Inc., 59 Temple
 #  Place - Suite 330, Boston, MA 02111-1307, USA.
 #
 #  If not, write to the Free Software Foundation, Inc., 59 Temple
 #  Place - Suite 330, Boston, MA 02111-1307, USA.
 #
-# $Id: sync-accounts,v 1.22 2002-07-14 22:21:29 ianmdlvl Exp $
+# $Id: sync-accounts,v 1.24 2007-09-21 20:59:02 ianmdlvl Exp $
 
 use POSIX;
 
 
 use POSIX;
 
@@ -223,7 +223,7 @@ sub regroupglobs () {
     for $g (@groupglobs) { $ggfunc.= "    m/^$g->[0]\$/ ? $g->[1] :\n"; }
     $ggfunc.= "    die;\n};\n1;\n";
 #print STDERR "$ggfunc\n";
     for $g (@groupglobs) { $ggfunc.= "    m/^$g->[0]\$/ ? $g->[1] :\n"; }
     $ggfunc.= "    die;\n};\n1;\n";
 #print STDERR "$ggfunc\n";
-    eval $ggfunc or die "$ggfunc // $@";
+    must_eval($ggfunc);
 }
 
 sub fetchown () {
 }
 
 sub fetchown () {
@@ -263,16 +263,20 @@ sub checkuid ($$) {
     return 1;
 }
 
     return 1;
 }
 
+sub must_eval ($) {
+    eval $_[0] or die "$_[0] // $@";
+}
+
 sub copyfield ($$$$) {
     my ($file,$entry,$field,$value) = @_;
 sub copyfield ($$$$) {
     my ($file,$entry,$field,$value) = @_;
-    eval "\$ary_ref= \\\@own$file; 1;" or die $@;
+    must_eval("\$ary_ref= \\\@own$file; 1;");
 #print STDERR "copyfield($file,$entry,$field,$value)\n";
     for $e (@$ary_ref) {
 #print STDERR "copyfield($file,$entry,$field,$value) $e->[0] $e->[field] ".join(':',@$e)."\n";
        next unless $e->[0] eq $entry;
        next if $e->[$field] eq $value;
        $e->[$field]= $value;
 #print STDERR "copyfield($file,$entry,$field,$value)\n";
     for $e (@$ary_ref) {
 #print STDERR "copyfield($file,$entry,$field,$value) $e->[0] $e->[field] ".join(':',@$e)."\n";
        next unless $e->[0] eq $entry;
        next if $e->[$field] eq $value;
        $e->[$field]= $value;
-       eval "\$modified$file= 1; 1;" or die $@;
+       must_eval("\$modified$file= 1; 1;");
     }
 }
 
     }
 }
 
@@ -557,8 +561,8 @@ sub finish () {
     umask 077;
     for $file (qw(passwd shadow group)) {
        $realfile= $file{$file,$PW_format};
     umask 077;
     for $file (qw(passwd shadow group)) {
        $realfile= $file{$file,$PW_format};
-       eval "\$modified= \$modified$file; \$data_ref= \\\@own$file;".
-           " \$fetched= \$own_fetched$file; 1;" or die $@;
+       must_eval("\$modified= \$modified$file; \$data_ref= \\\@own$file;".
+                 " \$fetched= \$own_fetched$file; 1;");
        next if !$modified;
        die $file unless $fetched;
        banner();
        next if !$modified;
        die $file unless $fetched;
        banner();
@@ -607,19 +611,19 @@ while (<CF>) {
        }
        fields_fmt('REM','std');
     } elsif (m/^(getpasswd|getshadow|getgroup)\s+(.*\S)$/) {
        }
        fields_fmt('REM','std');
     } elsif (m/^(getpasswd|getshadow|getgroup)\s+(.*\S)$/) {
-       eval "\$ch_$1= \$2; 1;" or die $@;
+       must_eval("\$ch_$1= \$2; 1;");
     } elsif (m/^(local|remote)format\s+(\w+)$/) {
        fields_fmt($1 eq 'local' ? 'PW' :
                   $1 eq 'remote' ? 'REM' : die,
                   $2);
     } elsif (m/^lock(passwd|group)\s+(runvia|link)\s+(\S+)$/) {
     } elsif (m/^(local|remote)format\s+(\w+)$/) {
        fields_fmt($1 eq 'local' ? 'PW' :
                   $1 eq 'remote' ? 'REM' : die,
                   $2);
     } elsif (m/^lock(passwd|group)\s+(runvia|link)\s+(\S+)$/) {
-       eval "\$ch_lock_$1= \$3; \$ch_lockstyle_$1= \$2; 1;" or die $@;
+       must_eval("\$ch_lock_$1= \$3; \$ch_lockstyle_$1= \$2; 1;");
     } elsif (m/^lock(passwd|group)\s+(none)$/) {
     } elsif (m/^lock(passwd|group)\s+(none)$/) {
-       eval "\$ch_lockstyle_$1= \$2; 1;" or die $@;
+       must_eval("\$ch_lockstyle_$1= \$2; 1;");
     } elsif (m,^(homebase|defaultshell)\s+(/\S+)$,) {
     } elsif (m,^(homebase|defaultshell)\s+(/\S+)$,) {
-       eval "\$ch_$1= \$2; 1;" or die $@;
+       must_eval("\$ch_$1= \$2; 1;");
     } elsif (m/^(uidmin|uidmax)\s+(\d+)$/ && $2>0) {
     } elsif (m/^(uidmin|uidmax)\s+(\d+)$/ && $2>0) {
-       eval "\$ch_$1= \$2; 1;" or die $@;
+       must_eval("\$ch_$1= \$2; 1;");
     } elsif (m/^createuser$/) {
        $opt_createuser= $def_createuser;
     } elsif (m/^nocreateuser$/) {
     } elsif (m/^createuser$/) {
        $opt_createuser= $def_createuser;
     } elsif (m/^nocreateuser$/) {
@@ -634,7 +638,7 @@ while (<CF>) {
            print "would log to $1\n" or die $!;
        }
     } elsif (m/^(no|)(sameuid)$/) {
            print "would log to $1\n" or die $!;
        }
     } elsif (m/^(no|)(sameuid)$/) {
-       eval "\$opt_$2= ".($1 eq 'no' ? 0 : 1)."; 1;" or die $@;
+       must_eval("\$opt_$2= ".($1 eq 'no' ? 0 : 1)."; 1;");
     } elsif (m/^usergroups$/) {
        $defaultgid= -1;
     } elsif (m/^nousergroups$/) {
     } elsif (m/^usergroups$/) {
        $defaultgid= -1;
     } elsif (m/^nousergroups$/) {
@@ -645,7 +649,7 @@ while (<CF>) {
        $yes= $1 eq 'no' ? 0 : 1;
        $_= $2;
        @groupglobs=() if $_ eq '*';
        $yes= $1 eq 'no' ? 0 : 1;
        $_= $2;
        @groupglobs=() if $_ eq '*';
-       s/[-+._]/\\$1/g;
+       s/[-+._]/\\$&/g;
        s/\*/\.\*/g;
        s/\?/\./g;
        unshift @groupglobs, [ $_, $yes ];
        s/\*/\.\*/g;
        s/\?/\./g;
        unshift @groupglobs, [ $_, $yes ];