Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Setting file ownership with Win32::Perms

by Biff (Acolyte)
on Mar 16, 2006 at 21:34 UTC ( #537291=perlquestion: print w/replies, xml ) Need Help??
Biff has asked for the wisdom of the Perl Monks concerning the following question:

Pray tell Kind Monks,

I've been wrestling with Win32::Perms attempting to set the owner of files and directories and have found what appears to me to be a bug but wanted to seek your wisdom first.

Apparently, Win32::Perms has problems with local users. I attempted the code:

use Win32::Perms; Win32::Perms::LookupDC(1); $filename = "c:\\foo.txt"; # $owner = 'DOMAIN\bob'; $owner = '\\HOSTNAME\Joe'; $SD = new Win32::Perms($filename) || die "new: $^E"; $SD->Dump; $SD->Remove(-1); # Null out the DACL; $SD->Set(); $SD->Owner($owner) or die "owner: $^E"; $SD->Set(); $SD->Dump;
When I run this I get the error:

No mapping between account names and security IDs was done.

If I uncomment the $owner assignment that uses a domain account and comment out the $owner assignment that uses the local host account then no errors and the script works.

I've logged into the machine as the local user and was able to create files as that user.

I'm at a loss to what is wrong except that there is a bug in Win32::Perms.



Replies are listed 'Best First'.
Re: Setting file ownership with Win32::Perms
by ikegami (Pope) on Mar 16, 2006 at 21:52 UTC

    For starters, the literal '\\HOSTNAME\Joe' results in the string \HOSTNAME\Joe. I don't think that's what you meant to use. Don't forget to escape your backslashes! To get the string \\HOSTNAME\Joe, the literal would be '\\\\HOSTNAME\\Joe' or the "optimized" (and confusing) '\\\HOSTNAME\Joe'.

    But I'm not convinved that would help. If it's 'DOMAIN\bob' for domains, wouldn't it be 'HOSTNAME\Joe' for local accounts? I'd also try just 'Joe'.

Re: Setting file ownership with Win32::Perms
by Marza (Vicar) on Mar 16, 2006 at 23:04 UTC

    ikegami is correct on the backslashes since you used the single quotes. If you used double it should have worked

    As to the comment of the local account; Dave Roths scripting book mentions that you use \\server\joe for local accounts.

      I'm such an idiot! Jeez!

      Thanks guys. '\\\hostname\Joe' worked like a charm. Did I mention I was an idiot!?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://537291]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2018-03-23 11:57 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (292 votes). Check out past polls.