linux454 has asked for the wisdom of the Perl Monks concerning the following question:
This method requires that we have 1 bit for every permission across the entire system. Thus a system with 256 distinct permissions will represent the integer 1.15792089237316e+77. To assign a user a permissinos mask we bitwise OR the permissions bits together. To check for a particular permission in the mask we bitwise AND the permission bit that we are looking for against the user's mask.... use constant READ_PERM => 0x04; use constant WRITE_PERM => 0x02; use constant EXECUTE_PERM => 0x01; use constant NO_PERM => 0x00; my $allowed_perms = READ_PERM | WRITE_PERM; # Check for permissions: if ( $allowd_perms == NO_PERM ) { print "PERMISSION DENIED\n" exit -1; } if ( $allowed_perms & READ_PERM ) print "READ Allowed\n"; if ( $allowed_perms & WRITE_PERM ) print "WRITE Allowed"; if ( $allowed_perms & EXECUTE_PERM ) print "EXECUTE Allowd\n"; ...
The pros:use constant READ_PERM => READ_PERM use constant WRITE_PERM => WRITE_PERM; use constant EXECUTE_PERM => EXECUTE_PERM; my @allowed_perms = ( READ_PERM, EXECUTE_PERM ); # Check permissions if ( scalar(@allowed_perms) == 0 ) { print "PERMISSION DENIED\n"; exit -1; } if ( grep { $_ == READ_PERM } @allowed_perms ) print "READ Allowed\n"; if ( grep { $_ == WRITE_PERM } @allowed_perms ) print "WRITE Allowed\n"; if ( grep { $_ == EXECUTE_PERM } @allowed_perms ) print "EXECUTE Allowed\n";
The objectives are to create an access control system that is flexible, maintainable, and easy to use.
Many of you would point out that by those virtues the named permission method would fit the bill more closely. Too true. However, I am hoping that some of you see something I've missed. I personally prefer the bitmask method, however the problem of having a large enough place to store the mask without stringifying it is a problem.
Any constructive criticism, comments and/or suggestions are greatly welcomed and desired.
Thank you all for your hard work and attention.
update (broquaint): fixed missing </ul> tag
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Bitmask or Named permissions
by idsfa (Vicar) on Oct 06, 2003 at 17:18 UTC | |
by linux454 (Pilgrim) on Oct 06, 2003 at 17:54 UTC | |
by waswas-fng (Curate) on Oct 06, 2003 at 18:53 UTC | |
Re: Bitmask or Named permissions
by halley (Prior) on Oct 06, 2003 at 18:00 UTC | |
Re: Bitmask or Named permissions
by graff (Chancellor) on Oct 07, 2003 at 04:22 UTC | |
Re: Bitmask or Named permissions
by blssu (Pilgrim) on Oct 07, 2003 at 14:36 UTC | |
Re: Bitmask or Named permissions
by duffbeer703 (Novice) on Oct 06, 2003 at 19:10 UTC | |
Re: Bitmask or Named permissions
by IOrdy (Friar) on Oct 07, 2003 at 03:25 UTC | |
Re: Bitmask or Named permissions
by Anonymous Monk on Oct 07, 2003 at 10:51 UTC |