#!/h/COE/Comp/PERL5/bin/perl -T -I/h/COE/lib -w #- # Copyright (C) 2002, Federal Linux Systems # License: GNU Lesser General Public License, v2.1 #- use strict; use Coe; my $PRGM="COE_add_profile_reserved_data"; my $VERSION="1.1.4.0"; if (@ARGV == 0) { &useage; exit 202; } sub useage { print "Useage: $PRGM [options] \"\" "; print "-f \"\" [-f \"Value\"]*\n"; } my $arg1; my $newstr=""; my $profile=""; my $pscope="a"; my $i; my @profiledat; my @fieldval=("","","","","","","","","","",""); my @oldval=("","","","","","","","","","",""); my @newval; while (@ARGV > 0 ){ $arg1=cleanString(shift,1); if ("$arg1" eq "-h") { useage; exit 0; } elsif ("$arg1" eq "-H") { coeMan("COE_COMP/UserMgmt/docs/man/$PRGM"); exit 0; } elsif ("$arg1" eq "-V") { print "VERSION: $VERSION\n"; exit 0; } else { $profile=$arg1; $pscope=cleanString(shift,1); while (@ARGV > 0) { # the argument is formatted "-f Value" # so I am parsing the first arg for N # and using that to define array postion N+3 with Value # I should only allow for reserved num 1-6 # The +3 normalizes the string positions 4-9 # where 0 is first string field $arg1=cleanString(shift,1); $_=$arg1; s/-f//; $i=$_; $fieldval[$i+3]=cleanString(shift,1); } } } # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # do simple sanity checks # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # is this a legal scope ? if ( "$pscope" eq "l" || "$pscope" eq "local") { $pscope="local"; } elsif ("$pscope" eq "g" || "$pscope" eq "global") { $pscope="global"; } else { &useage; exit 202; } # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # define some stuff # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # path for the Profile data file my $coedat=coeFileConv "COE_USER/$pscope/Profiles/.Profile.dat"; # Profile.dat format => profile:acctgrp:lockflag:abbrev:::::: # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # cat out the Profile.dat file, removing the profile string for alteration # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| $i=0; #open file, "$PROFILEDAT" || die "Cannot open file $PROFILEDAT: $!\n"; my $COEDAT = readFile ($coedat); while (<$COEDAT>) { if (/^$profile:/) { @oldval=split(':'); } else { $profiledat[$i++]=$_; } } close $COEDAT; # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # exit if no such profile is found with COE_NO_SUCH_PROFILE # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| if ("$oldval[0]" eq "") { exit 204; } # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # construct a new profile string to replace the old one # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # if a new value is defined, use it, else default to the old value #$newval[0]=$oldval[0]; #$newval[1]=$oldval[1]; #$newval[2]=$oldval[2]; #$newval[3]=$oldval[3]; #$newval[4]=$oldval[4]; #$newval[5]=$oldval[5]; #$newval[6]=$oldval[6]; #$newval[7]=$oldval[7]; #$newval[8]=$oldval[8]; #$newval[9]=$oldval[9]; @newval=@oldval; $i=4; while ($i < 10) { if ("$fieldval[$i]" ne "") { $newval[$i]=$fieldval[$i]; } else { $newval[$i]=$oldval[$i]; } $i++; } # build the new user string $i=1; $newstr=$newval[0]; while ($i < 10) { $newstr=$newstr.":".$newval[$i++]; } chomp($newstr); # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| # rewrite the file with the old data and the new user string # --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----| #open file, (">$PROFILEDAT") || die "Cannot open file $PROFILEDAT: $!\n"; open COEDAT, (">$coedat") || die "Cannot open file $coedat: $!\n"; foreach (@profiledat) { print COEDAT "$_"; } print COEDAT "$newstr\n"; close COEDAT; exit 0;