#!/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_delete_user_reserved_data";
my $VERSION="1.1.4.1";
if (@ARGV == 0) {
&useage;
exit 202;
}
sub useage {
print "Useage: $0 [options] {UserID} {Scope} {-f} {-f} ...\n";
}
my $arg1;
my $newstr;
my $userid="0";
my $uscope="a";
my $coedat;
my $COEDAT;
my $i;
my @oldval=("","","","","","","","","","");
my @newval=("","","","","","","","","","");
my @fieldval=("","","","","","","","","","");
my @userdat;
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 {
$userid=$arg1;
$uscope=cleanString(shift,1);
$i=0;
while (@ARGV > 0) {
# the argument is formatted "-f"
# so I am parsing the first arg for N
# and using that to define array postion N+2 with aflag
# I should only allow for reserved num 1-6
# The +2 normalizes the string positions 3-8
# where 0 is first string field
$arg1=cleanString(shift,1);
$_=$arg1;
s/-f//;
$fieldval[$_+2]="zremq";
}
}
}
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# do simple sanity checks
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# is this a legal scope ?
if ( "$uscope" eq "l" || "$uscope" eq "local" ) {
$uscope="local";
} elsif ("$uscope" eq "g" || "$uscope" eq "global" ) {
$uscope="global";
} else {
&useage;
exit 202;
}
# does this acct group exist?
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# define some stuff
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# path for the AppData data COEDAT
$coedat=coeFileConv "COE_USER/$uscope/Profiles/.User.dat";
# User.dat format:: userid:$username:$userdesc::::::
#$userstr="$userid:$username:$userdesc:$fieldval[1]:$fieldval[2]:$fieldval[3]:$fieldval[4]:$fieldval[5]:$fieldval[6]\n";
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# cat out the User.dat COEDAT, removing the user string for alteration
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
$i=0;
$COEDAT=readFile($coedat);
while (<$COEDAT>) {
if (/^$userid:/) {
chomp();
@oldval=split(':');
} else {
$userdat[$i++]=cleanString($_,3);
}
}
close $COEDAT;
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# if no user data was found, exit with COE_NO_SUCH_USER
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
if ("$oldval[0]" eq "" ) {
exit 203;
}
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# construct a new user string to replace the old one nulling defined fields
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# 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=@oldval;
$i=3;
while ($i < 9) {
if ("$fieldval[$i]" eq "zremq") {
$newval[$i]="";
} else {
$newval[$i]=$oldval[$i];
}
$i++;
}
# build the new user string
$i=1;
$newstr=$newval[0];
while ($i < 9) {
$newstr=$newstr.":".$newval[$i++];
}
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# rewrite the COEDAT with the old data and the new user string
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
open COEDAT, (">$coedat") || die "Cannot open COEDAT $coedat: $!\n";
foreach (@userdat) {
print COEDAT "$_\n";
}
print COEDAT "$newstr\n";
close COEDAT;