#
# 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,
# General Public License for more details.
#
# You should already have a copy of the GNU General Public License.
-# If not, write to the Free Software Foundation, Inc., 59 Temple
-# Place - Suite 330, Boston, MA 02111-1307, USA.
+# If not, consult the Free Software Foundation's website at
+# www.fsf.org, or the GNU Project website at www.gnu.org.
#
-# $Id: sync-accounts,v 1.22 2002-07-14 22:21:29 ianmdlvl Exp $
+# $Id: sync-accounts,v 1.25 2007-09-21 21:21:15 ianmdlvl Exp $
use POSIX;
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 () {
return 1;
}
+sub must_eval ($) {
+ eval $_[0] or die "$_[0] // $@";
+}
+
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;
- eval "\$modified$file= 1; 1;" or die $@;
+ must_eval("\$modified$file= 1; 1;");
}
}
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();
}
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+)$/) {
- 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)$/) {
- eval "\$ch_lockstyle_$1= \$2; 1;" or die $@;
+ must_eval("\$ch_lockstyle_$1= \$2; 1;");
} 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) {
- eval "\$ch_$1= \$2; 1;" or die $@;
+ must_eval("\$ch_$1= \$2; 1;");
} elsif (m/^createuser$/) {
$opt_createuser= $def_createuser;
} elsif (m/^nocreateuser$/) {
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$/) {
$yes= $1 eq 'no' ? 0 : 1;
$_= $2;
@groupglobs=() if $_ eq '*';
- s/[-+._]/\\$1/g;
+ s/[-+._]/\\$&/g;
s/\*/\.\*/g;
s/\?/\./g;
unshift @groupglobs, [ $_, $yes ];