summaryrefslogtreecommitdiff
path: root/fs_sesmon/FS-SessionClient/fs_sessiond
blob: bfdb20a1dc4b3dbfb6a11d98e957e6e67e7c782b (plain)
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
#!/usr/bin/perl -Tw
#
# fs_sessiond
#
# This is run REMOTELY over ssh by fs_session_server
#

use strict;
use Socket;

use vars qw( $Debug );

$Debug = 1;

my $fs_sessiond_socket = "/usr/local/freeside/fs_sessiond_socket";

$ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
$ENV{'SHELL'} = '/bin/sh';
$ENV{'IFS'} = " \t\n";
$ENV{'CDPATH'} = '';
$ENV{'ENV'} = '';
$ENV{'BASH_ENV'} = '';

$|=1;

my $me = "[fs_sessiond]";

warn "$me starting\n" if $Debug;
#nothing to read from server

warn "$me creating $fs_sessiond_socket\n" if $Debug;
my $uaddr = sockaddr_un($fs_sessiond_socket);
my $proto = getprotobyname('tcp');
socket(Server,PF_UNIX,SOCK_STREAM,0) or die "socket: $!";
unlink($fs_sessiond_socket);
bind(Server, $uaddr) or die "bind: $!";
listen(Server,SOMAXCONN) or die "listen: $!";

warn "$me entering main loop\n" if $Debug;
my $paddr;
for ( ; $paddr = accept(Client,Server); close Client) {

  chomp( my $command = <Client> );

  if ( $command eq 'login' || $command eq 'logout' || $command eq 'portnum' ) {
    warn "$me reading data from local client\n" if $Debug;
    my @data;
    my $dos = 0;
    push @data, scalar(<Client>) until $dos++ == 99 || $data[$#data] eq "END\n";
    if ( $dos == 99 ) { 
      warn "$me WARNING: DoS attempt!" 
    } else {
      warn "$me sending data to remote server\n" if $Debug;
      print "$command\n", @data;
      warn "$me reading result from remote server\n" if $Debug;
      my $error = <STDIN>;
      warn "$me sending error to local client\n" if $Debug;
      print Client $error;
    }
  } else {
    warn "$me WARNING: unexpected command from client: $command";
  }

}