Hello,

Thanks for the solution Bob.
Changed some stuff and have 2 questions open.

  my $line;
  my (%u, %g);
  open(FILE, "< ${dir}/user.perm") or print "Failed opening file $!";   ## 1
  while ($line = <FILE>) {                                              ## 2
      if ($line =~ /^user:/) {
         $u{$_} = 1 for split(/,/, substr($line, 6));                   ## 3
      }
      if ($line =~ /^group:/) {
         $g{$_} = 1 for split(/,/, substr($line, 7));                   ## 4
      }
  }
  close(FILE);

  print "Invalid login"; exit unless $u{$pwuser} || $g{$group};         ## 5

1) I don't like to die in my script as there are many files to read. And if I
   can't open the current file I just want to continue with the rest of the files
   So I always prefer printing.
2) while my $line (<FILE>) didn't work, just a notation error.
3) I don't need to split on spaces. The script that fills the user.perm is 
   designed to always : "user: vdgeerd,and,other  ## Never mind.
   BUT, What do you do with the <1> ?? Changing it to $1 doesn't matter too.
   I keep empty places when doing a " foreach my $value(%u) { print $value; } "
   chomp %u; didn't work either.
4) Same as 3
5) I changed the && into || cause the user can have acces due to group or user 
   rights.
   BUT, how do I combine a printing error message and an exit within the unless ?
   Right now it always prints, and only exits when I have no permissions.
   
Thanks for all your previous help!!


Regs David
> > 
> > 
> > 
> > Hi,
> > 
> > I need some help on the following.
> > In my script I show users some infodocs after they are 
> > verified to be valid users.
> > Users can have the permissions following the ruleset: 
> > - user (all perm)
> > - group (all perm), 
> > - descr (Not allowed to actualy open this document).
> > 
> > Now I do the following in my script :
> > 
> > # -------------
> >  open(FILE, "< ${dir}/user.perm");
> >  my @users = <FILE>;
> >  close FILE;
> >  chomp (@users);
> > 
> >  my @out = grep {/$pwuser/} @users;
> >  my @out1 = grep {/$group/} @users;
> >  if ((!(@out)) && (!(@out1))) { print "Sorry $pwuser you have 
> > no acces to this IP-Block"; exit; }
> > # --------------
> > 
> > But if a user with description access enters the complete 
> > link right now,
> > he can view the entire document.
> > Anyway, How do I build in an if-statement in here ??
> > I know I can change the foreach loop and build the if 
> > statement within the loop,
> > but isn't there something like :
> > 
> > my @out = if (m/user:/) { grep {/$pwuser/} } @users;  ## This 
> > doesn't work
> > my @out1 = if (m/group:/) { grep {/$group/} } @users;  ## 
> > This doesn't work
> > 
> > an example of the file user.perm would be :
> 
> I think you need to parse this file into some structures rather
> than using the simple regex approach. Even if you check only the
> user: line, your logic would allow user names like 'user', or 'v',
> or ',' or even ''.
> 
> I would do something like this:
> 
>   my (%u, %g);
>   open(FILE, "< ${dir}/user.perm") or die $!;
>   while my $line (<FILE>) {
>       if ($line =~ /^user:/) {
>          $u{$_} = 1 for split(/\s*,\s*/, substr($line, 5));
>       }
>       if ($line =~ /^group:/) {
>          $g{$_} = 1 for split(/\s*,\s*/, substr($line, 6));
>       }
>   }
>   close(FILE);
> 
> Now you can check for a valid user/group like this:
> 
>    print "Invalid login" unless $u{$user} && $g{$group};

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to