This file is indexed.

/usr/share/perl5/File/Policy.pm is in libfile-policy-perl 1.005-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
###############################################################################
# Purpose : Interface to File I/O policies
# Author  : John Alden
# Created : March 2005
# CVS     : $Id: Policy.pm,v 1.5 2005/05/18 15:58:21 johna Exp $
###############################################################################

package File::Policy;

use strict;
use vars qw($VERSION $Aliased);

$VERSION = sprintf"%d.%03d", q$Revision: 1.5 $ =~ /: (\d+)\.(\d+)/;
$Aliased = 0;

sub import {
	my $package = shift;
	
	#Allow default implementation to be set in a config module
	my $default_implementation = 'Default';
	eval {
		require File::Policy::Config;
		$default_implementation = &File::Policy::Config::IMPLEMENTATION;	
	};
	
	my $impl = $default_implementation; #Currently no way of overriding default - could be extended later
	die("Invalid File::Policy package - $impl") unless($impl =~ /^[\w:]+$/); #Sanitize package name
	$impl = "File::Policy::" . $impl;
	TRACE("File::Policy Implementation: ". $impl);
	
	#Export symbols to caller
	eval "require $impl";
	die("Unable to compile $impl - $@") if($@);
	++ local $Exporter::ExportLevel; #Bypass this module in caller()
	$impl->import(@_);
		
	#Alias symbols into this package too for fully qualified access
	unless($Aliased) {
		foreach(qw(check_safe get_log_dir get_temp_dir)) {
			no strict 'refs';
			*{"File::Policy::$_"} = *{"${impl}::$_"};
		}
		$Aliased = 1;
	}
}

#Stubs compatible with Log::Trace
sub TRACE{}
sub DUMP{}

1;

=head1 NAME

File::Policy - Site policy for file I/O functions

=head1 SYNOPSIS

	use File::Policy;
	use File::Policy qw/check_safe/;   # to import a specific subroutine
	use File::Policy qw/:all/;         # to import all subroutines

	#Checking I/O policy
	check_safe($filename, 'r');
	check_safe($filename, 'w');

	#Preferred directory locations
	$logdir = get_log_dir();
	$tmpdir = get_temp_dir();

=head1 DESCRIPTION

This defines the policy for file I/O with modules such as File::Slurp::WithinPolicy.
The purpose is to allow systems administrators to define locations and restrictions
for applications' file I/O and give app developers a policy to follow.  Note that the
module doesn't ENFORCE the policy - application developers can choose to ignore it 
(and systems administrators can choose not to install their applications if they do!).

You may control which policy gets applied by creating a File::Policy::Config module
with an IMPLEMENTATION constant. You may write your own policy as a module within the File::Policy:: namespace.

By default (if no File::Policy::Config is present), the File::Policy::Default policy gets applied which doesn't impose
any restrictions and provides reasonable default locations for temporary and log files.

The motivation behind this module was a standard, flexible approach to allow a site wide file policy to be defined.  This will be most useful in large environments where a few sysadmins are responsible for code written by many other people.  Simply ensuring that submitted code calls check_safe() ensures file access is sane, reducing the amount of effort required to do a security audit.

If your code is not security audit'd, or you are the only developer at your site, this might be overkill. However you may consider it good practise regardless and protection against paths in your code getting corrupted accidentally or maliciously in the future.

There are two major benefits of using this module.  One, sites that do implement a policy can more easily integrate your code in a standard way.  If you have a file policy at your site, you can apply different policies (via File::Policy::Config) in different environments (production, integration test, development) and the appropriate policy is automatically applied without having to change your code or configs.

=head1 FUNCTIONS

=over 4

=item check_safe

	check_safe( FILENAME , MODE );

Checks FILENAME is safe - dies if not.  MODE is r (read) or w (write).

=item get_temp_dir

	$temporary_directory = get_temp_dir();

Returns the path to temporary directory.  Note that any return value will have been cleared of a trailing slash.

=item get_log_dir

	$log_directory = get_log_dir();

Returns the path to log directory.  Note that any return value will have been cleared of a trailing slash.

=back

=head1 DEFINING YOUR OWN POLICY

To implement your own custom policy

  cp File/Policy/Default.pm File/Policy/YourPolicy.pm
  
and modify YourPolicy accordingly.  Then, create File/Policy/Config.pm containing:

  use constant IMPLEMENTATION => 'YourPolicy';

Now having used File::Policy, calling check_safe in your scripts will enforce your policy 
(as well as give you access to log and temp paths in locations you recommend).

=head1 SEE ALSO

L<File::Policy::Default>, L<Safe>

=head1 VERSION

$Revision: 1.5 $ on $Date: 2005/05/18 15:58:21 $ by $Author: johna $

=head1 AUTHOR

John Alden <cpan _at_ bbc _dot_ co _dot_ uk>

=head1 COPYRIGHT

(c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL.

See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt 

=cut