#!/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_user_data";
my $VERSION="1.1.4.1";
if (@ARGV == 0) {
&useage;
exit 202;
}
sub useage {
print "Useage: $PRGM [options] ";
print "\"\" \n";
}
my $coedatstr;
my $userid="0";
my $username="dummy";
my $userdesc="dummy";
my $uscope="a";
my $arg1;
my $flag="false";
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;
$username=cleanString(shift,1);
$userdesc=cleanString(shift,1);
$uscope=cleanString(shift,1);
}
}
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# 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;
}
# does this acct group exist?
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# define some stuff
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# path for the AppData data COEDAT
my $coedat=coeFileConv "COE_USER/$uscope/Profiles/.User.dat";
# User.dat format:: userid:$username:$userdesc::::::
$coedatstr="$userid:$username:$userdesc\:\:\:\:\:\:\n";
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
# if the user id is unique, append it to the COEDAT
# --+----|----+----|----+----|----+----|----+----|----+----|----+----|----+----|
#open COEDAT, "$coedat" || die "Cannot open COEDAT $coedat: $!\n";
my $COEDAT = readFile $coedat;
while (<$COEDAT>) { if (/^$userid:/) { $flag="true"; }}
close $COEDAT;
if ("$flag" eq "false") {
open COEDAT, (">>$coedat") || die "Cannot open COEDAT $coedat: $!\n";
print COEDAT "$coedatstr";
close COEDAT;
exit 0;
} else {
exit 212;
}