source: trunk/server/common/oursrc/execsys/ldapize.pl @ 1823

Last change on this file since 1823 was 1823, checked in by andersk, 11 years ago
ldapize: Support wildcard vhosts As a side effect, this magically gives us useful error messages for unknown vhosts (Trac: #166).
  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Net::LDAP;
7use Net::LDAP::Filter;
8
9my $url = $ARGV[0];
10my ($proto, $hostname, $path) = $url =~ m|^(.*?)://([^/]*)(.*)| or die "Could not match URL";
11my $mesg;
12
13my $vhostName = $hostname;
14
15vhost:
16# oh my gosh Net::LDAP::Filter SUCKS
17my $filter = bless({and =>
18    [{equalityMatch => {attributeDesc  => 'objectClass',
19                        assertionValue => 'scriptsVhost'}},
20     {or =>
21         [{equalityMatch => {attributeDesc  => 'scriptsVhostName',
22                             assertionValue => $vhostName}},
23          {equalityMatch => {attributeDesc  => 'scriptsVhostAlias',
24                             assertionValue => $vhostName}}]}]},
25    'Net::LDAP::Filter');
26
27my $ldap = Net::LDAP->new("ldapi://%2fvar%2frun%2fslapd-scripts.socket/");
28$mesg = $ldap->bind();
29$mesg->code && die $mesg->error;
30
31$mesg = $ldap->search(base => "ou=VirtualHosts,dc=scripts,dc=mit,dc=edu",
32                      filter => $filter);
33$mesg->code && die $mesg->error;
34
35my $vhostEntry = $mesg->pop_entry;
36if (!defined $vhostEntry) {
37  $vhostName ne '*' or die 'No vhost for *';
38  $vhostName =~ s/^(?:\*\.)?[^.]*/*/;  # Try next wildcard
39  goto vhost;
40}
41
42my $vhostDirectory = $vhostEntry->get_value('scriptsVhostDirectory');
43
44$mesg = $ldap->search(base => $vhostEntry->get_value('scriptsVhostAccount'),
45                      scope => 'base', filter => 'objectClass=posixAccount');
46$mesg->code && die $mesg->error;
47
48my $userEntry = $mesg->pop_entry;
49my ($homeDirectory, $uidNumber, $gidNumber) =
50    map { $userEntry->get_value($_) } qw(homeDirectory uidNumber gidNumber);
51(my $scriptsdir = $homeDirectory) =~ s{(?:/Scripts)?$}{/Scripts};
52
53if ($proto eq 'svn') {
54  chdir '/usr/libexec/scripts-trusted';
55  exec('/usr/sbin/suexec', $uidNumber, $gidNumber, '/usr/libexec/scripts-trusted/svn', "$scriptsdir/svn/$vhostDirectory");
56} elsif ($proto eq 'git') {
57  chdir '/usr/libexec/scripts-trusted';
58  exec('/usr/sbin/suexec', $uidNumber, $gidNumber, '/usr/libexec/scripts-trusted/git', "$scriptsdir/git/$vhostDirectory");
59} elsif ($proto eq 'http') {
60  print "suexec $uidNumber $gidNumber $scriptsdir/web/$vhostDirectory/$path\n";
61} else {
62  die "Unknown protocol\n";
63}
Note: See TracBrowser for help on using the repository browser.