Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB

  1. package filetest;
  2. =head1 NAME
  3. filetest - Perl pragma to control the filetest permission operators
  4. =head1 SYNOPSIS
  5. $can_perhaps_read = -r "file"; # use the mode bits
  6. {
  7. use filetest 'access'; # intuit harder
  8. $can_really_read = -r "file";
  9. }
  10. $can_perhaps_read = -r "file"; # use the mode bits again
  11. =head1 DESCRIPTION
  12. This pragma tells the compiler to change the behaviour of the filetest
  13. permissions operators, the C<-r> C<-w> C<-x> C<-R> C<-W> C<-X>
  14. (see L<perlfunc>).
  15. The default behaviour to use the mode bits as returned by the stat()
  16. family of calls. This, however, may not be the right thing to do if
  17. for example various ACL (access control lists) schemes are in use.
  18. For such environments, C<use filetest> may help the permission
  19. operators to return results more consistent with other tools.
  20. Each "use filetest" or "no filetest" affects statements to the end of
  21. the enclosing block.
  22. There may be a slight performance decrease in the filetests
  23. when C<use filetest> is in effect, because in some systems
  24. the extended functionality needs to be emulated.
  25. B<NOTE>: using the file tests for security purposes is a lost cause
  26. from the start: there is a window open for race conditions (who is to
  27. say that the permissions will not change between the test and the real
  28. operation?). Therefore if you are serious about security, just try
  29. the real operation and test for its success. Think atomicity.
  30. =head2 subpragma access
  31. Currently only one subpragma, C<access> is implemented. It enables
  32. (or disables) the use of access() or similar system calls. This
  33. extended filetest functionality is used only when the argument of the
  34. operators is a filename, not when it is a filehandle.
  35. =cut
  36. $filetest::hint_bits = 0x00400000;
  37. sub import {
  38. if ( $_[1] eq 'access' ) {
  39. $^H |= $filetest::hint_bits;
  40. } else {
  41. die "filetest: the only implemented subpragma is 'access'.\n";
  42. }
  43. }
  44. sub unimport {
  45. if ( $_[1] eq 'access' ) {
  46. $^H &= ~$filetest::hint_bits;
  47. } else {
  48. die "filetest: the only implemented subpragma is 'access'.\n";
  49. }
  50. }
  51. 1;