source: branches/fc13-dev/server/common/oursrc/execsys/ldapize.pl @ 1624

Last change on this file since 1624 was 849, checked in by andersk, 16 years ago
Support Git.
  • Property svn:executable set to *
File size: 1.9 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
13# oh my gosh Net::LDAP::Filter SUCKS
14my $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}}]}]},
22    'Net::LDAP::Filter');
23
24my $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
32my $vhostEntry = $mesg->pop_entry;
33my $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
39my $userEntry = $mesg->pop_entry;
40my ($homeDirectory, $uidNumber, $gidNumber) =
41    map { $userEntry->get_value($_) } qw(homeDirectory uidNumber gidNumber);
42
43if ($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");
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");
49} elsif ($proto eq 'http') {
50  print "suexec $uidNumber $gidNumber $homeDirectory/Scripts/web/$vhostDirectory/$path\n";
51} else {
52  die "Unknown protocol\n";
53}
Note: See TracBrowser for help on using the repository browser.