1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | use Net::LDAP; |
---|
7 | use Net::LDAP::Filter; |
---|
8 | |
---|
9 | my $url = $ARGV[0]; |
---|
10 | my ($proto, $hostname, $path) = $url =~ m|^(.*?)://([^/]*)(.*)| or die "Could not match URL"; |
---|
11 | my $mesg; |
---|
12 | |
---|
13 | # oh my gosh Net::LDAP::Filter SUCKS |
---|
14 | my $filter = bless({or => |
---|
15 | [{equalityMatch => {attributeDesc => 'scriptsVhostName', |
---|
16 | assertionValue => $hostname}}, |
---|
17 | {equalityMatch => {attributeDesc => 'scriptsVhostAlias', |
---|
18 | assertionValue => $hostname}}]}, |
---|
19 | 'Net::LDAP::Filter'); |
---|
20 | |
---|
21 | my $ldap = Net::LDAP->new("ldapi://%2fvar%2frun%2fdirsrv%2fslapd-scripts.socket/"); |
---|
22 | $mesg = $ldap->bind(); |
---|
23 | $mesg->code && die $mesg->error; |
---|
24 | |
---|
25 | $mesg = $ldap->search(base => "ou=VirtualHosts,dc=scripts,dc=mit,dc=edu", |
---|
26 | filter => $filter); |
---|
27 | $mesg->code && die $mesg->error; |
---|
28 | |
---|
29 | my $vhostEntry = $mesg->pop_entry; |
---|
30 | my $vhostDirectory = $vhostEntry->get_value('scriptsVhostDirectory'); |
---|
31 | |
---|
32 | $mesg = $ldap->search(base => $vhostEntry->get_value('scriptsVhostAccount'), |
---|
33 | scope => 'base', filter => 'objectClass=posixAccount'); |
---|
34 | $mesg->code && die $mesg->error; |
---|
35 | |
---|
36 | my $userEntry = $mesg->pop_entry; |
---|
37 | my ($homeDirectory, $uidNumber, $gidNumber) = |
---|
38 | map { $userEntry->get_value($_) } qw(homeDirectory uidNumber gidNumber); |
---|
39 | |
---|
40 | if ($proto eq 'svn') { |
---|
41 | chdir '/usr/libexec/scripts-trusted'; |
---|
42 | exec('/usr/sbin/suexec', $uidNumber, $gidNumber, '/usr/libexec/scripts-trusted/svn', "$homeDirectory/Scripts/svn/$vhostDirectory"); |
---|
43 | } elsif ($proto eq 'http') { |
---|
44 | print "suexec $uidNumber $gidNumber $homeDirectory/Scripts/web/$vhostDirectory/$path\n"; |
---|
45 | } else { |
---|
46 | die "Unknown protocol\n"; |
---|
47 | } |
---|