home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / lib / site / Win32 / FileSecurity.pm < prev    next >
Encoding:
Perl POD Document  |  1997-08-10  |  5.6 KB  |  221 lines

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