C
corky
I have a function that manages security for various hyperlinks on the
web. Each user has an integer representation of a binary number (24
security on/off switches) stored in the database. Each link has a link
ID associated. This function takes the link ID, looks through a list
of restricted link ID / security pairs, and denies the user access to
a link if there is a match.
For instance, GetLinkSecurity (2, <user's security mask as integer>)
would pass the function a link ID of 2 and the user's security mask.
The function then looks through the list of link ID / security bit
pairs to see if the user should be denied access.
The problems started when I added a new security bit with an integer
value of 8388608 (24 bits). The function stopped working properly for
users with that security bit turned on. I don't know if it's some
overflow condition or something, and I can't find any reference to
capacity in the camel book.
I'm not a regular Perl programmer, so please forgive me if the
question is basic.
The function follows:
sub GetLinkSecurity {
&LogItem("--> GetLinkSecurity()");
my ($link, $knowrights) = @_;
my ($linknum, $badright);
my ($secflag) = 1;
open(LINKSEC, "linksec.txt");
while(<LINKSEC>){
chomp;
($linknum, $badright) = split;
if ($linknum == $link) {
if (($knowrights & $badright) == $badright) {
$secflag = 0;
}
}
}
close LINKSEC;
return($secflag);
}
Here is a sample of data in the linksec.txt file:
1 8
1 131072
1 524288
2 8
2 131072
2 524288
3 8
3 131072
3 524288
4 8
4 131072
4 524288
5 8
5 131072
5 524288
6 8
6 131072
6 524288
Thanks,
Corky
web. Each user has an integer representation of a binary number (24
security on/off switches) stored in the database. Each link has a link
ID associated. This function takes the link ID, looks through a list
of restricted link ID / security pairs, and denies the user access to
a link if there is a match.
For instance, GetLinkSecurity (2, <user's security mask as integer>)
would pass the function a link ID of 2 and the user's security mask.
The function then looks through the list of link ID / security bit
pairs to see if the user should be denied access.
The problems started when I added a new security bit with an integer
value of 8388608 (24 bits). The function stopped working properly for
users with that security bit turned on. I don't know if it's some
overflow condition or something, and I can't find any reference to
capacity in the camel book.
I'm not a regular Perl programmer, so please forgive me if the
question is basic.
The function follows:
sub GetLinkSecurity {
&LogItem("--> GetLinkSecurity()");
my ($link, $knowrights) = @_;
my ($linknum, $badright);
my ($secflag) = 1;
open(LINKSEC, "linksec.txt");
while(<LINKSEC>){
chomp;
($linknum, $badright) = split;
if ($linknum == $link) {
if (($knowrights & $badright) == $badright) {
$secflag = 0;
}
}
}
close LINKSEC;
return($secflag);
}
Here is a sample of data in the linksec.txt file:
1 8
1 131072
1 524288
2 8
2 131072
2 524288
3 8
3 131072
3 524288
4 8
4 131072
4 524288
5 8
5 131072
5 524288
6 8
6 131072
6 524288
Thanks,
Corky