You could do the if{...}elsif{...}elsif{...}else{...} things, but much simpler would be to set yourself up some hashes that will convert the strings to their bitmap constant values like this:
#! perl -sw
use strict;
use Win32::Perms;
my %ACE_masks = (
FULL => FULL, # Full access (RWDXOP)
ALL => ALL, # Same as FULL
CHANGE => CHANGE, # Change access (RWDX)
READ => READ, # Read access
WRITE => WRITE, # Write access
DELETE => DELETE, # Delete access
EXECUTE => EXECUTE, # Execute access
NO_ACCESS => NO_ACCESS, # No permissions specified
);
my %ACE_types = (
ALLOW => ALLOW, # The permission mask is allowed
GRANT => GRANT, # Same as ALLOW
DENY => DENY, # Permission mask is denied
AUDIT => AUDIT, # The permission mask is for auditin
+g
OWNER => OWNER, # The account specified is the OWNER
+ (the permission mask is ignored)
GROUP => GROUP, # The account specified is the GROUP
+ (the permission mask is ignored)
);
my %ACE_flags = (
DIRECTORY => DIRECTORY, # The permission is for a directory
DIR => DIR, # Same as DIRECTORY
KEY => KEY, # the permission is for a Registry k
+ey
CONTAINER => CONTAINER, # The permission is for a container
+object (dir, Registry key, etc)
FILE => FILE, # The permission is for a file
NON_CONTAINER => NON_CONTAINER, # The permission is for
+a non container object (file, etc)
SUCCESS => SUCCESS, # If the type is AUDIT then this wil
+l log a successful audit
FAILURE => FAILURE, # If the type is AUDIT then this wil
+l log a failed audit
);
This is only a subset of those exported by Win32::Perms, but it may be enough for your needs.
You would use these in a snippet from your code like this:
...
$perms->Add('MYDOMAIN\bloggJo', $ACE_masks{$ARGV[1]}|$ACE_masks{$ARGV[
+2]}
ACCESS_ALLOWED_ACE_TYPE, OBJECT_INHERIT_ACE | CONTAINER_INHERIT_AC
+E);
This will take the 2nd string that you supply on the command line as $ARGV[1] (ie. READ), use that as the key in the %ACE_masks hash and retreive the corresponding bit map. The same for the 3rd command line parm $ARGV[2] (WRITE) and do the same. It will then binary or (|) these together and then supply the result to Add().
If you need to supply a variable number of arguements, then you will need to loop over the @ARGV array, lookup the strings, oring the values into a scalar and then pass those.
If you get stuck with that, come back.
Well It's better than the Abottoire, but Yorkshire! |