home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / site / Win32 / FileSecurity.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  4.6 KB  |  201 lines

  1. package Win32::FileSecurity;
  2.  
  3.  
  4. require Exporter;
  5. require DynaLoader;
  6. use Carp ;
  7.  
  8. $VERSION = '1.01';
  9.  
  10. croak "The Win32::FileSecurity module works only on Windows NT" if (!Win32::IsWinNT()) ;
  11.  
  12. @ISA= qw( Exporter DynaLoader );
  13.  
  14. require Exporter ;
  15. require DynaLoader ;
  16.  
  17. @ISA = qw(Exporter DynaLoader) ;
  18. @EXPORT_OK = qw( Get Set EnumerateRights MakeMask ) ;
  19.  
  20. sub AUTOLOAD
  21. {
  22.  
  23.     local($constname);
  24.     ($constname = $AUTOLOAD) =~ s/.*:://;
  25.     $!=0;
  26.     $val = constant($constname);
  27.     if($! != 0)
  28.     {
  29.         if($! =~ /Invalid/)
  30.         {
  31.             $AutoLoader::AUTOLOAD = $AUTOLOAD;
  32.             goto &AutoLoader::AUTOLOAD;
  33.         }
  34.         else
  35.         {
  36.             ($pack,$file,$line) = caller;
  37.             die "Your vendor has not defined Win32::FileSecurity macro $constname, used in $file at line $line.";
  38.         }
  39.     }
  40.     eval "sub $AUTOLOAD { $val }";
  41.     goto &$AUTOLOAD;
  42. }
  43.  
  44. bootstrap Win32::FileSecurity;
  45.  
  46.  
  47.  
  48. 1;
  49.  
  50. __END__
  51.  
  52. =head1 NAME
  53.  
  54. Win32::FileSecurity - manage FileSecurity Discretionary Access Control Lists in perl
  55.  
  56. =head1 SYNOPSIS
  57.  
  58.     use Win32::FileSecurity;
  59.  
  60. =head1 DESCRIPTION
  61.  
  62. This module offers control over the administration of system FileSecurity DACLs.  
  63. You may want to use Get and EnumerateRights to get an idea of what mask values
  64. correspond to what rights as viewed from File Manager.
  65.  
  66. =head1 CONSTANTS
  67.  
  68.   DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER,
  69.   SYNCHRONIZE, STANDARD_RIGHTS_REQUIRED, 
  70.   STANDARD_RIGHTS_READ, STANDARD_RIGHTS_WRITE,
  71.   STANDARD_RIGHTS_EXECUTE, STANDARD_RIGHTS_ALL,
  72.   SPECIFIC_RIGHTS_ALL, ACCESS_SYSTEM_SECURITY, 
  73.   MAXIMUM_ALLOWED, GENERIC_READ, GENERIC_WRITE,
  74.   GENERIC_EXECUTE, GENERIC_ALL, F, FULL, R, READ,
  75.   C, CHANGE
  76.  
  77. =head1 FUNCTIONS
  78.  
  79. =head2 NOTE:
  80.  
  81. All of the functions return FALSE (0) if they fail, unless otherwise noted.  Errors returned
  82. via $! containing both Win32 GetLastError() and a text message indicating Win32 function that 
  83. failed.
  84.  
  85. =over 10
  86.  
  87. =item constant( $name, $set )
  88.     Stores the value of named constant $name into $set.
  89.     Alternatively, $set = Win32::FileSecurity::NAME_OF_CONSTANT() ;
  90.  
  91. =item Get( $filename, \%permisshash )
  92.     Gets the DACLs of a file or directory
  93.  
  94. =item Set( $filename, \%permisshash )
  95.     Sets the DACL for a file or directory
  96.  
  97. =item EnumerateRights( $mask, \@rightslist )
  98.     Turns the bitmask in $mask into a list of strings in @rightslist
  99.  
  100. =item MakeMask( qw( DELETE READ_CONTROL ) )
  101.     Takes a list of strings representing constants and returns a bitmasked integer value.
  102.  
  103. =back
  104.  
  105. =head2 %permisshash
  106.  
  107. Entries take the form $permisshash{USERNAME} = $mask ;
  108.  
  109. =head1 EXAMPLE1
  110.  
  111. use Win32::FileSecurity ;
  112.  
  113. foreach( @ARGV ) {
  114.     next unless -e $_ ;
  115.     
  116.     if ( Win32::FileSecurity::Get( $_, \%hash ) ) {
  117.         while( ($name, $mask) = each %hash ) {
  118.             print "$name:\n\t"; 
  119.             Win32::FileSecurity::EnumerateRights( $mask, \@happy ) ;
  120.             print join( "\n\t", @happy ), "\n";
  121.         }
  122.     } else {
  123.         print( "Error #", int( $! ), ": $!" ) ;
  124.     }
  125. }
  126.  
  127. =head1 EXAMPLE2
  128.  
  129. use Win32::FileSecurity ;
  130.  
  131. $file = Win32::FileSecurity::MakeMask( qw( FULL ) );
  132.  
  133. $dir = Win32::FileSecurity::MakeMask( qw(
  134.     FULL
  135.     GENERIC_ALL
  136. ) );
  137.  
  138.  
  139. foreach( @ARGV ) {
  140.     s/\\$//;
  141.     next unless -e;
  142.     
  143.     Win32::FileSecurity::Get( $_, \%hash ) ;
  144.     $hash{Administrator} = ( -d ) ? $dir : $file ;
  145.     Win32::FileSecurity::Set( $_, \%hash ) ;
  146. }
  147.  
  148. =head1 VERSION
  149.  
  150. 1.01 ALPHA 97-04-25
  151.  
  152. =head1 REVISION NOTES
  153.  
  154. =over 10
  155.  
  156. =item 1.01 ALPHA 1997.04.25
  157.     CORE Win32 version imported from 0.66 <gsar@umich.edu>
  158.  
  159. =item 0.66 ALPHA 1997.03.13
  160.     Fixed bug in memory allocation check
  161.  
  162. =item 0.65 ALPHA 1997.02.25
  163.     Tested with 5.003 build 303
  164.     Added ISA exporter, and @EXPORT_OK
  165.     Added F, FULL, R, READ, C, CHANGE as composite pre-built mask names.
  166.     Added server\ to keys returned in hash from Get
  167.     Made constants and MakeMask case insensitive (I don't know why I did that)
  168.     Fixed mask comparison in ListDacl and Enumerate Rights from simple & mask
  169.         to exact bit match ! ( ( x & y ) ^ x ) makes sure all bits in x
  170.         are set in y
  171.     Fixed some "wild" pointers
  172.  
  173. =item 0.60 ALPHA 1996.07.31
  174.     Now suitable for file and directory permissions
  175.     Included ListDacl.exe in bundle for debugging
  176.     Added "intuitive" inheritance for directories, basically functions like FM
  177.         triggered by presence of GENERIC_ rights this may need to change
  178.         see EXAMPLE2
  179.     Changed from AddAccessAllowedAce to AddAce for control over inheritance
  180.     
  181. =item 0.51 ALPHA 1996.07.20
  182.     Fixed memory allocation bug
  183.  
  184. =item 0.50 ALPHA 1996.07.29
  185.     Base functionality
  186.     Using AddAccessAllowedAce
  187.     Suitable for file permissions
  188. =back
  189.  
  190. =head1 KNOWN ISSUES / BUGS
  191.  
  192. =over 10
  193.  
  194. =item 1
  195.     May not work on remote drives.
  196.  
  197. =item 2
  198.     Errors croak, don't return via $! as documented.
  199.  
  200. =cut
  201.