#!/opt/bin/perl # ########################################################################### # # # Tool for copying the UIDs (GIDs) from one passwd-file (group-file) to # # another. # # # ########################################################################### # # # Version 1.0 - Written 14.04.95 by Steffen Beyer # # Version 1.0.1 - Written 15.04.95 by Steffen Beyer # # Version 1.0.2 - Written 04.05.95 by Steffen Beyer # # # ########################################################################### # # # Copyright (C) 1995 by software design & management GmbH & Co. KG # # # ########################################################################### # # Some important default settings... # $version = 'version 1.0.2'; # $self = $0; # if ($self =~ /^.*\/([^\/]+)$/) { $self = $1; } # # Display usage if tool was called without parameters: # if (@ARGV == 0) { $help = 1; } # # Get and check command line options: # while (@ARGV) { $_ = shift; if (/^-\?$/) { $help = 1; } elsif (/^-h$/) { $help = 1; } elsif (/^-.*/) { $error = 1; unless (defined $option) { $option = $_; } } else { push(@filename, $_); } } # # Was help requested? # if ($help) { print <<"@@"; '$self' $version Usage: $self [ ]* where is one of the following: -h produces this help screen -? produces this help screen Copies the UIDs (GIDs) from the passwd-file (group-file) to the passwd-file (group-file) for the corresponding users (groups). @@ exit; } # # Unknown option encountered? # if ($error) { die "Error: Unknown option '$option' encountered!\nEnter '$self -h' for help.\n"; } # # Are there two filenames specified? # if (@filename != 2) { die "Error: You must specify two filenames!\nEnter '$self -h' for help.\n"; } # # Extract the two filenames: # $file_a = $filename[$[]; $file_b = $filename[$[+1]; # # Do the specified files exist? # unless (($file_a ne "") && (-f $file_a)) { die "Error: Can't find file '$file_a'!\n"; } unless (($file_b ne "") && (-f $file_b)) { die "Error: Can't find file '$file_b'!\n"; } # # Scan first file: # open(FILE_A, "<$file_a") || die "Can't open '$file_a': $!\n"; # while () { chop; ($name, $passwd, $id) = split(/:/); if ($id_name{$name} ne "") { if ($id == $id_name{$name}) { warn "Warning: Name '$name' in file '$file_a' is not unique!\n"; } else { die "Error: Name '$name' in file '$file_a' is not unique!\n"; } } else { $id_name{$name} = $id; } } # close(FILE_A); # # Prepare output filename: # $file_c = "$file_b.$self"; # # Scan second file: # open(FILE_B, "<$file_b") || die "Can't open '$file_b': $!\n"; open(FILE_C, ">$file_c") || die "Can't write '$file_c': $!\n"; # while () { chop; undef @field; @field = split(/:/, $_, 10); $name = $field[$[]; if ($id_name{$name} ne "") { $field[$[+2] = $id_name{$name}; } else { warn "Warning: No new ID for name '$name' of file '$file_b'!\n"; } $_ = join(':', @field); print FILE_C $_, "\n"; } # close(FILE_B); close(FILE_C); # # Print acknowledgement: # printf("\n'%s' %s\n\n", $self, $version); printf("Input file (source) = '%s'\n", $file_a); printf("Input file (target) = '%s'\n", $file_b); printf("Output file = '%s'\n\n", $file_c); # # Done. #