[825] | 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 |
---|
[828] | 14 | my $filter = bless({and => |
---|
| 15 | [{equalityMatch => {attributeDesc => 'objectClass', |
---|
| 16 | assertionValue => 'scriptsVhost'}}, |
---|
| 17 | {or => |
---|
| 18 | [{equalityMatch => {attributeDesc => 'scriptsVhostName', |
---|
| 19 | assertionValue => $hostname}}, |
---|
| 20 | {equalityMatch => {attributeDesc => 'scriptsVhostAlias', |
---|
| 21 | assertionValue => $hostname}}]}]}, |
---|
[825] | 22 | 'Net::LDAP::Filter'); |
---|
| 23 | |
---|
| 24 | my $ldap = Net::LDAP->new("ldapi://%2fvar%2frun%2fdirsrv%2fslapd-scripts.socket/"); |
---|
| 25 | $mesg = $ldap->bind(); |
---|
| 26 | $mesg->code && die $mesg->error; |
---|
| 27 | |
---|
| 28 | $mesg = $ldap->search(base => "ou=VirtualHosts,dc=scripts,dc=mit,dc=edu", |
---|
| 29 | filter => $filter); |
---|
| 30 | $mesg->code && die $mesg->error; |
---|
| 31 | |
---|
| 32 | my $vhostEntry = $mesg->pop_entry; |
---|
| 33 | my $vhostDirectory = $vhostEntry->get_value('scriptsVhostDirectory'); |
---|
| 34 | |
---|
| 35 | $mesg = $ldap->search(base => $vhostEntry->get_value('scriptsVhostAccount'), |
---|
| 36 | scope => 'base', filter => 'objectClass=posixAccount'); |
---|
| 37 | $mesg->code && die $mesg->error; |
---|
| 38 | |
---|
| 39 | my $userEntry = $mesg->pop_entry; |
---|
| 40 | my ($homeDirectory, $uidNumber, $gidNumber) = |
---|
| 41 | map { $userEntry->get_value($_) } qw(homeDirectory uidNumber gidNumber); |
---|
| 42 | |
---|
| 43 | if ($proto eq 'svn') { |
---|
| 44 | chdir '/usr/libexec/scripts-trusted'; |
---|
| 45 | exec('/usr/sbin/suexec', $uidNumber, $gidNumber, '/usr/libexec/scripts-trusted/svn', "$homeDirectory/Scripts/svn/$vhostDirectory"); |
---|
[849] | 46 | } elsif ($proto eq 'git') { |
---|
| 47 | chdir '/usr/libexec/scripts-trusted'; |
---|
| 48 | exec('/usr/sbin/suexec', $uidNumber, $gidNumber, '/usr/libexec/scripts-trusted/git', "$homeDirectory/Scripts/git/$vhostDirectory"); |
---|
[825] | 49 | } elsif ($proto eq 'http') { |
---|
| 50 | print "suexec $uidNumber $gidNumber $homeDirectory/Scripts/web/$vhostDirectory/$path\n"; |
---|
| 51 | } else { |
---|
| 52 | die "Unknown protocol\n"; |
---|
| 53 | } |
---|