File: cvssh.pl

package info (click to toggle)
gforge 4.5.14-22etch13
  • links: PTS
  • area: main
  • in suites: etch
  • size: 13,004 kB
  • ctags: 11,918
  • sloc: php: 36,047; sql: 29,050; sh: 10,538; perl: 6,496; xml: 3,810; makefile: 341; python: 263; ansic: 256
file content (50 lines) | stat: -rwxr-xr-x 1,102 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/perl -w
#
# $Id: cvssh.pl 3612 2004-11-27 23:01:07Z cbayle $
#
# "Shell" for a restricted account, limiting the available commands
# Roland Mas, debian-sf (Sourceforge for Debian)
#
# Inspired from the grap.c file in Sourceforge 2.5

use strict ;
use vars qw/ @allowed_options @allowed_commands $errmsg @cmd / ;
use subs qw/ &reject / ;
no locale ;

@allowed_options = ('-c', '-e') ;
@allowed_commands = ('cvs','scp','svnserve') ;

# Clean up our environment
delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)};

if ($#ARGV != 1) {
    if ($#ARGV < 1) {
	$errmsg = "Not enough arguments." ;
    } else {
	$errmsg = "Too many arguments." ;
    }
    &reject ;
}

if (scalar (grep { $_ eq $ARGV[0] } @allowed_options) == 0) {
    $errmsg = "Option not allowed." ;
    &reject ;
}

@cmd = split (/ +/, $ARGV[1]) ;

if (scalar (grep { $_ eq $cmd[0] } @allowed_commands) == 0) {
    $errmsg = "Command not allowed." ;
    &reject ;
}

exec @cmd ;

sub reject {
    print "This is a restricted account.\n" . 
	"You cannot execute anything here.\n" . 
	# $errmsg . "\n" .
	"Goodbye.\n" ;
    exit 1 ;
}