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

Last change on this file since 1818 was 1818, checked in by mitchb, 11 years ago
Move 389-ds's slapd-scripts.socket to /var/run It turns out that mode 777 directories containing files that daemons use is... not the most brilliant thing we've done. 389-ds has finally decided to insist on clobbering the permissions of /var/run/dirsrv to be less foolish, but several of our daemons and client programs need to be able to access the LDAP daemon's socket. Come visit it in its new home, conveniently located just two directories below the root.
  • Property svn:executable set to *
File size: 2.3 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Net::LDAP;
7use Net::LDAP::Filter;
8
9sub report_error
10{
11    my $proto = shift;
12    my $mesg = shift;
13
14    if ($proto eq 'git') {
15        $mesg = "ERR \n  " . $mesg . "\n";
16        my $len = length($mesg)+4;
17        printf "%04x%s", $len, $mesg;
18    } else {
19        print $mesg;
20    }
21    exit 0;
22}
23
24my $url = $ARGV[0];
25my ($proto, $hostname, $path) = $url =~ m|^(.*?)://([^/]*)(.*)| or die "Could not match URL";
26my $mesg;
27
28# oh my gosh Net::LDAP::Filter SUCKS
29my $filter = bless({and =>
30    [{equalityMatch => {attributeDesc  => 'objectClass',
31                        assertionValue => 'scriptsVhost'}},
32     {or =>
33         [{equalityMatch => {attributeDesc  => 'scriptsVhostName',
34                             assertionValue => $hostname}},
35          {equalityMatch => {attributeDesc  => 'scriptsVhostAlias',
36                             assertionValue => $hostname}}]}]},
37    'Net::LDAP::Filter');
38
39my $ldap = Net::LDAP->new("ldapi://%2fvar%2frun%2fslapd-scripts.socket/");
40$mesg = $ldap->bind();
41$mesg->code && die $mesg->error;
42
43$mesg = $ldap->search(base => "ou=VirtualHosts,dc=scripts,dc=mit,dc=edu",
44                      filter => $filter);
45$mesg->code && die $mesg->error;
46
47my $vhostEntry = $mesg->pop_entry;
48if (!$vhostEntry)
49{
50    report_error($proto, "Could not find Host $hostname");
51}
52my $vhostDirectory = $vhostEntry->get_value('scriptsVhostDirectory');
53
54$mesg = $ldap->search(base => $vhostEntry->get_value('scriptsVhostAccount'),
55                      scope => 'base', filter => 'objectClass=posixAccount');
56$mesg->code && die $mesg->error;
57
58my $userEntry = $mesg->pop_entry;
59my ($homeDirectory, $uidNumber, $gidNumber) =
60    map { $userEntry->get_value($_) } qw(homeDirectory uidNumber gidNumber);
61
62if ($proto eq 'svn') {
63  chdir '/usr/libexec/scripts-trusted';
64  exec('/usr/sbin/suexec', $uidNumber, $gidNumber, '/usr/libexec/scripts-trusted/svn', "$homeDirectory/Scripts/svn/$vhostDirectory");
65} elsif ($proto eq 'git') {
66  chdir '/usr/libexec/scripts-trusted';
67  exec('/usr/sbin/suexec', $uidNumber, $gidNumber, '/usr/libexec/scripts-trusted/git', "$homeDirectory/Scripts/git/$vhostDirectory");
68} elsif ($proto eq 'http') {
69  print "suexec $uidNumber $gidNumber $homeDirectory/Scripts/web/$vhostDirectory/$path\n";
70} else {
71  die "Unknown protocol\n";
72}
Note: See TracBrowser for help on using the repository browser.