summaryrefslogtreecommitdiffstats
path: root/net-ftp/bsdftpd-ssl/files/auth.sslftp
blob: 539140d9dd982434d58370012c33e0f55cd14669 (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
#! /usr/bin/perl

# Output must be at least 8 bytes

sub return_error {
    print STDOUT "200\r\n\r\n";
    exit;
}

sub return_ok {
    $user=@_[0];
    print STDOUT "100\r\n$user\r\n";
    exit;
}

$/="\r\n";
$user=<STDIN>;chomp($user);
$/="\n";
$mode=0;
while (<>) {
    if (($mode==0)&&($_ =~ /-----BEGIN CERTIFICATE-----/)) { $mode = 1; }
    elsif (($mode==1)&&($_ =~ /-----END CERTIFICATE-----/)) { $mode = 2; }
    if ($mode) {
	$_ =~ /^(.*)[\n\r]+$/;
	$cert.=$1;
    }
    if ($mode==2) { last; }
}

#$cert=join "", @cert_lines;
$cert =~ m/-----BEGIN CERTIFICATE-----(.*)-----END CERTIFICATE-----/;
$client_cert = $1;

open(ucf, "/opt/ssl/user_certs/$user.crt") or return_error();
@cert_lines=<ucf>;
chomp(@cert_lines);
$cert=join "", @cert_lines;
close(ucf);
$cert =~ m/-----BEGIN CERTIFICATE-----(.*)-----END CERTIFICATE-----/;
$user_cert = $1;

if (($user_cert cmp $client_cert) == 0) { return_ok($user); }
return_error();