Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I was not doing anything fancy, just removing user permission off a remote server. I was using Win32::Perms library and tried to remove the 'Everyone account' from that remote server (the server is located next door to where my desk is, and I do have Domain Admins rights to it). The script, after dumping account permission information on the screen, just hang forever (while I was chewing my nails to the bone and my boss was breathing hot and cold down my neck, by the way - I got this Job only 3 weeks ago).
I am not sure where I went wrong, maybe Perl is not the best tools to do this job!!?? Maybe I should have chosen another language, NT shell or VB script instead!!?? Maybe Win32::Perms doesn’t work as it was claimed to be!!?? Maybe there is no logic after all. But the whole thing is so very simple. This is what I did : first I get server name from the command line with this command “my $path = @ARGV;“, ensuring proper path was entered with correct number of slashes) and then applying the following command “my $result = system('cacls', $path, '/t', '/e', '/r', 'Everyone')”; the script tears through the server and removes the permissions as expected without any delays or problems. In contrast I used Win32::Perms in number of ways in my script, including some example code from Dave Roth’s first edition of Perl Win32 administration; None worked. Next, went and bought the second edition of his book (priced 59.4650 USD) and used the following example, by the way the PC that I am using is Windows 2000 Pro and the server is Windows 2000:
Guess what happened, exactly, it just hung (no errors or bleepso rattle and shake or smoke…etc, absolutely not a diddley). I do the same thing using Cacls and, hey Presto, it works.use Win32::Lanman; use Win32::Perms; use warnings; $! = $^E = 0; my %info; my ( $machine, $share_name ) = ( shift @ARGV || die ) =~ /^(\\\\.+?)\\ +(.*?)$/; if ( ! Win32::Lanman::NetShareGetInfo($machine, $share_name, \ %info ) + ) { print "Unable to retrieve information, $! : $^E.\n"; exit( ); } print "\n\nSuccessfully retrieved information\n\n"; my ( $perms_object ) = new Win32::Perms ( ) || die "\n\n$! : $^E\n\n"; $perms_object -> Import ( $info{security_descriptor}); $perms_object -> Dump; $perms_object -> Remove ('Everyone'); # HANGS HERE FOREVER $info{security_descriptor} = $perms_object -> GetSD ( SD_RELATIVE ); if ( ! Win32::Lanman::NetShareSetInfo($machine, $share_name, \ %info ) + ) { print "\n\nCompleted Successfully\n\n"; } else { print "\n\nUnable to set new Permissions\n\n"; my $status = Win32::Lanman::GetLastError(); print "\n\nError : ", Win32::FormatMessage( $status ); } $perms_object -> Close();
Mr Monk “Particle” whom has helped me with this problem commented that it is a bit of an over kill to use Win32::Perms library if removing Permissions from dir/sub-dirs was the only thing I was doing, True, but there again, Why not use this library then??, why was this library produced ?? What is the threshold of number of NT permission commands used in any script before it warrants using this library??
CAN SOMEONE THROUGH SOME LIGHT ON THIS PLEASE, AND RESTORE MY FAITH?
Edit by tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::Perms failes where Cacls doesn't
by gumby (Scribe) on Jun 18, 2002 at 15:58 UTC | |
|
Re: Win32::Perms failes where Cacls doesn't
by Marza (Vicar) on Jun 18, 2002 at 18:41 UTC | |
by Anonymous Monk on Jun 19, 2002 at 13:04 UTC |