###################################################
#  RAID utility CGI Proguram                      #
#       SAN Project                               #
#                 Copy right. 2004  Hitachi.Lmt.  #
###################################################
#
# History  :Version       :DATE        : Coder       : P# & Summary
# RAID 500 :50-03-02/00-03:2004.10.22  : T.Kishimoto : U5002223708
#          :50-03-0X/00-03:2004.10.22  : K.Usami     : UPRM2223552 SLPR
#          :50-03-02/00-03:2006.03.13  : T.Kishimoto : UUAM2227009
#
# subroutine name  :check_userlist2
# filename         :check_userlist2.cgi
# 
# Augument : void
#
# Return   : == 1  Normal END
#            != 1  Error  END
#
# Document
#
require 'fandor.pl';                               # UUAM2227009
$useractaboption   ="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040"; #UUAM2227009 
$logtaboption      ="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080"; #UUAM2227009
$useractaboption_a ="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBF"; #UUAM2227009 
$logtaboption_a    ="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F"; #UUAM2227009  
$storagetaboption  ="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000"; #UUAM2227009 
sub check_userlist2 {

    local($userlist,$len,$adj) ;
    local($i,$j) ;
    local(@tmp,@tmp1,@buf) ;

    $userlist="./csv/userlist.csv" ;

# Read USERLIST.CSV
    unless (open(FH,"< $userlist")) {
      sleep 1 ;
      unless (open(FH,"< $userlist")) {
        sleep 1 ;
        unless (open(FH,"< $userlist")) {
            return (-1) ;                # File Open Error
        }
      }
    }
# remake UPRM2223552 SLPR
    while (<FH>) {
	chomp;
        $buf[$.] = $_ ;                     # Read All DATA
    }
    close(FH) ;
    foreach $i (1 .. $#buf) {
       @tmp2 = split(/,/,$buf[$i]);
        if($tmp2[7] eq ""){
	  $flg=1;
          $modify[$i]=1; # It is necessary to modify in userlist.csv.
        }
    } 
    if($flg==0){
       return(0);
    }
#print "flg =$flg\n";
# Write USERLIST.CSV
    unless (open(FH,"> $userlist")) {
      sleep 1 ;
      unless (open(FH,"> $userlist")) {
        sleep 1 ;
        unless (open(FH,"> $userlist")) {
            return (-1) ;                # File Open Error
        }
      }
    }

    foreach $i (1 .. $#buf) {
      if($modify[$i] ==1){
        @tmp3 = split(/,/,$buf[$i]);
#        print "OK $i $buf[$i] $tmp3[2]\n";
        $tmp3[4]="F"x128;
        $tmp3[6]="0";
        $tmp3[7]="1900/01/01";
        $tmp3[8]="0";
        $tmp3[9]="0";
        $tmp3[10]="1900/01/01";
        $tmp3[11]="0";
        $tmp3[12]="0";
# Storage Authority  is  checked for ALL user 
        $tmp3[2]=&f_or($tmp3[2],$storagetaboption); 
        $tmp3[4]=&f_or($tmp3[4],$storagetaboption); 
#   Authority check
        if($tmp3[3] == 1 ){
           $tmp3[2]=&f_or($tmp3[2],$useractaboption); 
           $tmp3[4]=&f_or($tmp3[4],$useractaboption); 
        }else{
           $tmp3[2]=&f_and($tmp3[2],$useractaboption_a); 
           $tmp3[4]=&f_and($tmp3[4],$useractaboption_a); 
        }
#  Log administrator check
        if(f_and($tmp3[2],$logtaboption) eq "0"x128){
           $tmp3[2]=&f_and($tmp3[2],$logtaboption_a); 
           $tmp3[4]=&f_and($tmp3[4],$logtaboption_a); 
        }else{
           $tmp3[2]=&f_or($tmp3[2],$logtaboption); 
           $tmp3[4]=&f_or($tmp3[4],$logtaboption); 
        }
#  PSA Check
        if($tmp3[5] != 65535 && $tmp3[5] ne "" ){
           $tmp3[2]=&f_and($tmp3[2],$logtaboption_a); 
           $tmp3[4]=&f_and($tmp3[4],$logtaboption_a); 
        }
        print FH "$tmp3[0]" ;
        foreach $i1 (1 .. 12){
          print FH ",$tmp3[$i1]" ;
        }
        print FH "\n" ;
      }else{
        print FH "$buf[$i]\n";
      }  

    }

    close(FH) ;

    return (1) ;

}
1;
