Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Perms Perms Perms

by blssu (Pilgrim)
on Sep 13, 2002 at 14:20 UTC ( #197592=note: print w/replies, xml ) Need Help??


in reply to Perms Perms Perms

As others have said, those READ and WRITE constants are actually Perl subroutines. You can't use "READ" the string as if it were READ the subroutine.

However, you can find the subroutine using the string name and then call it. There are two ways to do this. The first is to use string references and the second is to use the package "stash". Here's a short demo:

use strict; sub READ () { 34 } { no strict 'refs'; print &{'READ'}(), "\n"; } { print &{$main::{'READ'}}(), "\n"; }

You "use strict" so you'll probably want to use the second method. Here's the change you need to make to your program:

&{$main::{$folder_ace}}() | &{$main::{$subfolder_ace}}()

Be sure to include those empty parens -- when calling subs using the '&', the prototype is ignored and the current '@_' will always be passed to the sub unless an explicit argument list is given. The empty parens means the sub gets an empty argument list.

WARNING! This technique is not safe to use unless you trust the input -- it can allow people to call any subroutine in your package. I think it's ok to use in the example without any checking, but if you are very concerned about security, check the strings before looking up the subroutine.

Replies are listed 'Best First'.
Re: Re: Perms Perms Perms
by blackadder (Hermit) on Sep 16, 2002 at 15:13 UTC
    OK, the hash technique seems to work,....(Thanks very much for this chaps)

    Now, in NT explorer, if I wanted to assign read permission -which is (RX)(RX) i.e. read and execute - to Mr Jo Bloggs on the directory c:/temp then I would do something like this:
    Use Win32::Perms; My $path = ‘c:/temp’; My $dir = new Win32::Perms($path) || die “\n$E, $^E\n”; $dir->Add(‘MYDOMAIN\BloggsJo’, READ|EXECUTE, ACCESS_ALLOWED_ACE_TYPE, +OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE);
    If I wanted the Change permission then I would do this:
    $dir->Add(‘MYDOMAIN\BloggsJo’, CHANGE|CHANGE, ACCESS_ALLOWED_ACE_TYPE, + OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE);
    And if I wanted Full permission, then I change the CHANGE|CHANGE to FULL|FULL. All this works fine, however If I wanted to assign the List permission – which is (RX)(Not Specific) – or the Add&Read permission - which is (RWX)(RX). Then can someone please enlighten me on how can I go about implementing this?

    Thanks in Advance.
    Regards

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://197592]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-10-22 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?