Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Setting file ownership with Win32::Perms

by Biff (Novice)
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.

Thanks,

Biff

Comment on Setting file ownership with Win32::Perms
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://537291]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2014-08-21 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (136 votes), past polls