David vd Geer Inhuur tbv IPlib wrote:

> Hi Sudarsan,
>
> Sorry forgot to mention that :
>
>   $pwuser = ($ENV{'REMOTE_USER'});      ## Apache var
>
> $groupfile is the group-file apache uses to authenticate. Unfortunetly there is
> no such thing as :
>
>   $group = ($ENV{'REMOTE_GROUP'});
>
> Therefor I have to open the file manualy and set it's $group.
>
> Any suggestions about a faster foreach ??

If the group format file is the same as what you have mentioned below, try this

open (GRPSFH, $apache_grp_file) or die "cannot open $apache_grp_file : $!\n";
while (<GRPSFH>) {
    $grp_name = (split (/:/))[0] if (m/\b$pwuser\b/);
}

Read the file in line by line and check if $pwuser is present in the line.
If so split on ':' and element 0 is your group name.
I don't know a lot about apache and I am groping around in the dark here
(so forgive me if I am wrong), can a user be member of more than one group.
If so you will have to change the line within the loop accordingly.

>
>
> Regs David
>
> >
> > David vd Geer Inhuur tbv IPlib wrote:
> >
> > > Hi,
> > >
> > > I am currently almost done with my current job.
> > > As I am reviewing my scripts the foreach-loop started to anoy me.
> > >
> > > I am afraid this is slowing down the script. Does anyone know a faster way to
> > > do the following :
> > >
> > > # ------
> > > open(FH, "< $groupfile");
> > > @usrs = <FH>;
> >
> > Always check if open succeeds with an or die "..." statement
> > Slurping the file in is not advisable. It will be better to loop through it
> >
> > >
> > > close FH;
> > >
> > >  $htusr = (grep {/htuser: /} @usrs)[0] ;
> > >  $phi = (grep {/phil: /} @usrs)[0] ;
> > >  $al = (grep {/all: /} @usrs)[0] ;
> >
> > It is better to anchor regexes, this should be written as /^htuser:/ etc.
> > I guess you are trying to find the group name of an entered user (You have
> > not mentioned what $pwuser is, this is a guess)
> >
> > If this is true (perldoc -f getpwnam, perldoc -f getgrgid)
> > This piece of code should do the job for you
> > #!/usr/bin/perl -w
> > use strict;
> > my $grp_name = getgrgid ((getpwnam ($pwuser))[3]);
> > $grp_name will contain the group name
> >
> >
> > >
> > >
> > >  @htuser = split(/ /, $htusr);
> > >  @phil = split(/ /, $phi);
> > >  @all = split(/ /, $al);
> > >
> > >  foreach $htuser(@htuser) {
> > >   chomp $htuser;
> > >   if ( "$pwuser" eq "$htuser" ) { $group = "iclab"; }
> > >  }
> > >  foreach $phil(@phil) {
> > >   chomp $phil;
> > >   if ( "$pwuser" eq "$phil" ) { $group = "phil"; }
> > >  }
> > >  foreach $all(@all) {
> > >   chomp $all;
> > >   if ( "$pwuser" eq "$all" ) { $group = "all"; }
> > >  }
> > >  if(!($group)) { $group = "none"; }

> > > # ------
> > > Groupfile :
> > >
> > > htuser: user1 user2 user3 manyothers
> > > phil: user4 user5 manymore
> > > all: external1 external2 etc
> > > # -------
> > >
> > > I know I should have used Strict, after I reviewed everything I will try to make
> > > it strict again. You guys convinced me of using strict. It's only a pain to 
>correct
> > > it afterwards :(
> > >
> > > Thanks for your help in advance !
> > >
> > > Regs David
> > >
> >


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

Reply via email to