Paranoid - Paranoia support for safer programs


Paranoid documentation Contained in the Paranoid distribution.

Index


Code Index:

NAME

Top

Paranoid - Paranoia support for safer programs

VERSION

Top

$Id: Paranoid.pm,v 0.29 2011/04/15 22:05:29 acorliss Exp $

SYNOPSIS

Top

  use Paranoid;

  $errMsg = Paranoid::ERROR;

  psecureEnv("/bin:/usr/bin");

DESCRIPTION

Top

This collection of modules started out as modules which perform things (debatably) in a safer and taint-safe manner. Since then it's also grown to include functionality that fit into the same framework and conventions of the original modules, including keeping the debug hooks for command-line debugging.

All the modules below are intended to be used directly in your programs if you need the functionality they provide.

This module does provide one function meant to secure your environment enough to satisfy taint-enabled programs, and as a container which holds the last reported error from any code in the Paranoid framework.

SUBROUTINES/METHODS

Top

psecureEnv

  psecureEnv("/bin:/usr/bin");

This function deletes some of the dangerous environment variables that can be used to subvert perl when being run in setuid applications. It also sets the path, either to the passed argument (if passed) or a default of "/bin:/usr/bin".

Paranoid::ERROR

  $errMsg = Paranoid::ERROR;
  Paranoid::ERROR = $errMsg;

This lvalue function is not exported and must be referenced via the Paranoid namespace.

TAINT NOTES

Top

Taint-mode programming can be somewhat of an adventure until you know all the places considered dangerous under perl's taint mode. The following functions should generally have their arguments detainted before using:

  exec        system      open        glob
  unlink      mkdir       chdir       rmdir
  chown       chmod       umask       utime
  link        symlink     kill        eval
  truncate    ioctl       fcntl       chroot
  setpgrp     setpriority syscall     socket
  socketpair  bind        connect

DEPENDENCIES

Top

While this module itself doesn't have any external dependencies various child modules do. Please check their documentation for any particulars should you use them.

SEE ALSO

Top

The following modules are available for use. You should check their POD for specifics on use:

o

Paranoid::Args: Command-line argument parsing functions

o

Paranoid::BerkeleyDB: OO-oriented BerkelyDB access with concurrent access capabilities

o

Paranoid::Data: Misc. data manipulation functions

o

Paranoid::Debug: Command-line debugging framework and functions

o

Paranoid::Filesystem: Filesystem operation functions

o

Paranoid::Glob: Paranoid Glob objects

o

Paranoid::Input: Input-related functions (file reading, detainting)

o

Paranoid::Lockfile: Lockfile support

o

Paranoid::Log: Unified logging framework and functions

o

Paranoid::Module: Run-time module loading functions

o

Paranoid::Network: Network-related functions

o

Paranoid::Process: Process management functions

BUGS AND LIMITATIONS

Top

If your application is sensitive to performance issues then you may be better off not using these modules. The primary focus was on security, robustness, and diagnostics. That said, there's probably a lot of room for improvement on the performance front.

AUTHOR

Top

Arthur Corliss (corliss@digitalmages.com)

LICENSE AND COPYRIGHT

Top


Paranoid documentation Contained in the Paranoid distribution.

# Paranoid -- Paranoia support for safer programs
#
# (c) 2005, Arthur Corliss <corliss@digitalmages.com>
#
# $Id: Paranoid.pm,v 0.29 2011/04/15 22:05:29 acorliss Exp $
#
#    This software is licensed under the same terms as Perl, itself.
#    Please see http://dev.perl.org/licenses/ for more information.
#
#####################################################################

#####################################################################
#
# Environment definitions
#
#####################################################################

package Paranoid;

use 5.006;

use strict;
use warnings;
use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS);
use base qw(Exporter);

($VERSION) = ( q$Revision: 0.29 $ =~ /(\d+(?:\.(\d+))+)/sm );

@EXPORT      = qw(psecureEnv);
@EXPORT_OK   = qw(psecureEnv);
%EXPORT_TAGS = ( all => [qw(psecureEnv)], );

#####################################################################
#
# Module code follows
#
#####################################################################

#BEGIN {
#die "This module requires taint mode to be enabled!\n" unless
#  ${^TAINT} == 1;
#delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
#$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin';
#no ops qw(backtick system exec);
#  :subprocess = system, backtick, exec, fork, glob
#  :dangerous = syscall, dump, chroot
#  :others = mostly IPC stuff
#  :filesys_write = link, unlink, rename, mkdir, rmdir, chmod,
#                   chown, fcntl
#  :sys_db = getpwnet, etc.
#}

sub psecureEnv (;$) {

    # Purpose:  To delete taint-unsafe environment variables and to sanitize
    #           the PATH variable
    # Returns:  True (1) -- no matter what
    # Usage:    psecureEnv();

    my $path = shift;

    $path = '/bin:/usr/bin' unless defined $path;

    delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
    $ENV{PATH} = $path;
    if ( exists $ENV{TERM} ) {
        if ( $ENV{TERM} =~ /^([\w\+\.\-]+)$/sm ) {
            $ENV{TERM} = $1;
        } else {
            $ENV{TERM} = 'vt100';
        }
    }

    return 1;
}

{
    my $errorMsg = '';

    sub ERROR : lvalue {

        # Purpose:  To store/retrieve a string error message
        # Returns:  Scalar string
        # Usage:    $errMsg = Paranoid::ERROR;
        # Usage:    Paranoid::ERROR = $errMsg;

        $errorMsg;
    }
}

1;

__END__