From adad1e490979cd789763c5c1a47872fc3c061f04 Mon Sep 17 00:00:00 2001 From: lo-lan-do <> Date: Sun, 18 Jan 2004 21:47:18 +0000 Subject: [PATCH] Initial revision --- gforge-plugin-ldapextauth/bin/db-delete.pl | 189 ++++++++++++ gforge-plugin-ldapextauth/bin/db-upgrade.pl | 280 ++++++++++++++++++ .../debian/README.Debian | 7 + gforge-plugin-ldapextauth/debian/changelog | 6 + gforge-plugin-ldapextauth/debian/control | 11 + gforge-plugin-ldapextauth/debian/copyright | 24 ++ gforge-plugin-ldapextauth/debian/dirs | 20 ++ gforge-plugin-ldapextauth/debian/postinst | 50 ++++ gforge-plugin-ldapextauth/debian/postrm.ex | 38 +++ gforge-plugin-ldapextauth/debian/preinst.ex | 38 +++ gforge-plugin-ldapextauth/debian/prerm | 41 +++ gforge-plugin-ldapextauth/debian/rules | 91 ++++++ .../include/LdapExtAuthPlugin.class | 69 +++++ .../include/ldapextauth-init.php | 14 + 14 files changed, 878 insertions(+) create mode 100755 gforge-plugin-ldapextauth/bin/db-delete.pl create mode 100755 gforge-plugin-ldapextauth/bin/db-upgrade.pl create mode 100644 gforge-plugin-ldapextauth/debian/README.Debian create mode 100644 gforge-plugin-ldapextauth/debian/changelog create mode 100644 gforge-plugin-ldapextauth/debian/control create mode 100644 gforge-plugin-ldapextauth/debian/copyright create mode 100644 gforge-plugin-ldapextauth/debian/dirs create mode 100644 gforge-plugin-ldapextauth/debian/postinst create mode 100644 gforge-plugin-ldapextauth/debian/postrm.ex create mode 100644 gforge-plugin-ldapextauth/debian/preinst.ex create mode 100644 gforge-plugin-ldapextauth/debian/prerm create mode 100755 gforge-plugin-ldapextauth/debian/rules create mode 100644 gforge-plugin-ldapextauth/include/LdapExtAuthPlugin.class create mode 100644 gforge-plugin-ldapextauth/include/ldapextauth-init.php diff --git a/gforge-plugin-ldapextauth/bin/db-delete.pl b/gforge-plugin-ldapextauth/bin/db-delete.pl new file mode 100755 index 0000000000..92afc3224c --- /dev/null +++ b/gforge-plugin-ldapextauth/bin/db-delete.pl @@ -0,0 +1,189 @@ +#!/usr/bin/perl -w +# +# $Id$ +# +# Debian-specific script to delete plugin-specific tables +# Roland Mas + +use strict ; +use diagnostics ; + +use DBI ; +use MIME::Base64 ; +use HTML::Entities ; + +use vars qw/$dbh @reqlist $query/ ; +use vars qw/$sys_default_domain $sys_cvs_host $sys_download_host + $sys_shell_host $sys_users_host $sys_docs_host $sys_lists_host + $sys_dns1_host $sys_dns2_host $FTPINCOMING_DIR $FTPFILES_DIR + $sys_urlroot $sf_cache_dir $sys_name $sys_themeroot + $sys_news_group $sys_dbhost $sys_dbname $sys_dbuser $sys_dbpasswd + $sys_ldap_base_dn $sys_ldap_host $admin_login $admin_password + $server_admin $domain_name $newsadmin_groupid $statsadmin_groupid + $skill_list/ ; +use vars qw/$pluginname/ ; + +sub is_lesser ( $$ ) ; +sub is_greater ( $$ ) ; +sub debug ( $ ) ; +sub parse_sql_file ( $ ) ; + +require ("/usr/lib/gforge/lib/include.pl") ; # Include a few predefined functions +require ("/usr/lib/gforge/lib/sqlparser.pm") ; # Our magic SQL parser + +debug "You'll see some debugging info during this installation." ; +debug "Do not worry unless told otherwise." ; + +&db_connect ; + +# debug "Connected to the database OK." ; + +$pluginname = "ldapextauth" ; + +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; +eval { + my ($sth, @array, $version, $action, $path, $target, $rname) ; + + my $pattern = "plugin_" . $pluginname . '_%' ; + + $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='v'" ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + while (@array = $sth->fetchrow_array ()) { + $rname = $array [0] ; + &drop_view_if_exists ($rname) ; + } + $sth->finish () ; + + $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='r'" ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + while (@array = $sth->fetchrow_array ()) { + $rname = $array [0] ; + &drop_table_if_exists ($rname) ; + } + $sth->finish () ; + + $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='i'" ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + while (@array = $sth->fetchrow_array ()) { + $rname = $array [0] ; + &drop_index_if_exists ($rname) ; + } + $sth->finish () ; + + $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='s'" ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + while (@array = $sth->fetchrow_array ()) { + $rname = $array [0] ; + &drop_sequence_if_exists ($rname) ; + } + $sth->finish () ; + + $dbh->commit (); + + + debug "It seems your database deletion went well and smoothly. That's cool." ; + debug "Please enjoy using Debian GForge." ; + + # There should be a commit at the end of every block above. + # If there is not, then it might be symptomatic of a problem. + # For safety, we roll back. + $dbh->rollback (); +}; + +if ($@) { + warn "Transaction aborted because $@" ; + debug "Transaction aborted because $@" ; + debug "Last SQL query was:\n$query\n(end of query)" ; + $dbh->rollback ; + debug "Please report this bug on the Debian bug-tracking system." ; + debug "Please include the previous messages as well to help debugging." ; + debug "You should not worry too much about this," ; + debug "your DB is still in a consistent state and should be usable." ; + exit 1 ; +} + +$dbh->rollback ; +$dbh->disconnect ; + +sub debug ( $ ) { + my $v = shift ; + chomp $v ; + print STDERR "$v\n" ; +} + +sub drop_table_if_exists ( $ ) { + my $tname = shift or die "Not enough arguments" ; + $query = "SELECT count(*) FROM pg_class WHERE relname='$tname' AND relkind='r'" ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + my @array = $sth->fetchrow_array () ; + $sth->finish () ; + + if ($array [0] != 0) { + # debug "Dropping table $tname" ; + $query = "DROP TABLE $tname" ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } +} + +sub drop_sequence_if_exists ( $ ) { + my $sname = shift or die "Not enough arguments" ; + $query = "SELECT count(*) FROM pg_class WHERE relname='$sname' AND relkind='S'" ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + my @array = $sth->fetchrow_array () ; + $sth->finish () ; + + if ($array [0] != 0) { + # debug "Dropping sequence $sname" ; + $query = "DROP SEQUENCE $sname" ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } +} + +sub drop_index_if_exists ( $ ) { + my $iname = shift or die "Not enough arguments" ; + $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND relkind='i'" ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + my @array = $sth->fetchrow_array () ; + $sth->finish () ; + + if ($array [0] != 0) { + # debug "Dropping index $iname" ; + $query = "DROP INDEX $iname" ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } +} + +sub drop_view_if_exists ( $ ) { + my $iname = shift or die "Not enough arguments" ; + $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND relkind='v'" ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + my @array = $sth->fetchrow_array () ; + $sth->finish () ; + + if ($array [0] != 0) { + # debug "Dropping view $iname" ; + $query = "DROP VIEW $iname" ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } +} diff --git a/gforge-plugin-ldapextauth/bin/db-upgrade.pl b/gforge-plugin-ldapextauth/bin/db-upgrade.pl new file mode 100755 index 0000000000..d055b2c758 --- /dev/null +++ b/gforge-plugin-ldapextauth/bin/db-upgrade.pl @@ -0,0 +1,280 @@ +#!/usr/bin/perl -w +# +# $Id$ +# +# Debian-specific script to upgrade the database between releases +# Roland Mas + +use strict ; +use diagnostics ; + +use DBI ; +use MIME::Base64 ; +use HTML::Entities ; + +use vars qw/$dbh @reqlist $query/ ; +use vars qw/$sys_default_domain $sys_cvs_host $sys_download_host + $sys_shell_host $sys_users_host $sys_docs_host $sys_lists_host + $sys_dns1_host $sys_dns2_host $FTPINCOMING_DIR $FTPFILES_DIR + $sys_urlroot $sf_cache_dir $sys_name $sys_themeroot + $sys_news_group $sys_dbhost $sys_dbname $sys_dbuser $sys_dbpasswd + $sys_ldap_base_dn $sys_ldap_host $admin_login $admin_password + $server_admin $domain_name $newsadmin_groupid $statsadmin_groupid + $skill_list/ ; +use vars qw/$pluginname/ ; + +sub is_lesser ( $$ ) ; +sub is_greater ( $$ ) ; +sub debug ( $ ) ; +sub parse_sql_file ( $ ) ; + +require ("/usr/lib/gforge/lib/include.pl") ; # Include a few predefined functions +require ("/usr/lib/gforge/lib/sqlparser.pm") ; # Our magic SQL parser + +debug "You'll see some debugging info during this installation." ; +debug "Do not worry unless told otherwise." ; + +&db_connect ; + +# debug "Connected to the database OK." ; + +$pluginname = "ldapextauth" ; + +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; +eval { + my ($sth, @array, $version, $path, $target) ; + + &create_metadata_table ("0") ; + + $dbh->commit () ; + + $version = &get_db_version ; + $target = "0.1" ; + if (is_lesser $version, $target) { + my @filelist = ( + # "/usr/lib/gforge/plugins/$pluginname/lib/$pluginname-init.sql", + ) ; + + foreach my $file (@filelist) { + debug "Processing $file" ; + @reqlist = @{ &parse_sql_file ($file) } ; + + foreach my $s (@reqlist) { + $query = $s ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } + } + @reqlist = () ; + + &update_db_version ($target) ; + debug "Committing." ; + $dbh->commit () ; + } + + debug "It seems your database install/upgrade went well and smoothly. That's cool." ; + debug "Please enjoy using Debian GForge." ; + + # There should be a commit at the end of every block above. + # If there is not, then it might be symptomatic of a problem. + # For safety, we roll back. + $dbh->rollback (); +}; + +if ($@) { + warn "Transaction aborted because $@" ; + debug "Transaction aborted because $@" ; + debug "Last SQL query was:\n$query\n(end of query)" ; + $dbh->rollback ; + debug "Please report this bug on the Debian bug-tracking system." ; + debug "Please include the previous messages as well to help debugging." ; + debug "You should not worry too much about this," ; + debug "your DB is still in a consistent state and should be usable." ; + exit 1 ; +} + +$dbh->rollback ; +$dbh->disconnect ; + +sub is_lesser ( $$ ) { + my $v1 = shift || 0 ; + my $v2 = shift || 0 ; + + my $rc = system "dpkg --compare-versions $v1 lt $v2" ; + + return (! $rc) ; +} + +sub is_greater ( $$ ) { + my $v1 = shift || 0 ; + my $v2 = shift || 0 ; + + my $rc = system "dpkg --compare-versions $v1 gt $v2" ; + + return (! $rc) ; +} + +sub debug ( $ ) { + my $v = shift ; + chomp $v ; + print STDERR "$v\n" ; +} + +sub create_metadata_table ( $ ) { + my $v = shift || "0" ; + my $tablename = "plugin_" .$pluginname . "_meta_data" ; + # Do we have the metadata table? + + $query = "SELECT count(*) FROM pg_class WHERE relname = '$tablename' and relkind = 'r'"; + # debug $query ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + my @array = $sth->fetchrow_array () ; + $sth->finish () ; + + # Let's create this table if we have it not + + if ($array [0] == 0) { + debug "Creating $tablename table." ; + $query = "CREATE TABLE $tablename (key varchar primary key, value text not null)" ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } + + $query = "SELECT count(*) FROM $tablename WHERE key = 'db-version'"; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + @array = $sth->fetchrow_array () ; + $sth->finish () ; + + # Empty table? We'll have to fill it up a bit + + if ($array [0] == 0) { + debug "Inserting first data into $tablename table." ; + $query = "INSERT INTO $tablename (key, value) VALUES ('db-version', '$v')" ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } +} + +sub update_db_version ( $ ) { + my $v = shift or die "Not enough arguments" ; + my $tablename = "plugin_" .$pluginname . "_meta_data" ; + + debug "Updating $tablename table." ; + $query = "UPDATE $tablename SET value = '$v' WHERE key = 'db-version'" ; + # debug $query ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; +} + +sub get_db_version () { + my $tablename = "plugin_" .$pluginname . "_meta_data" ; + + $query = "SELECT value FROM $tablename WHERE key = 'db-version'" ; + # debug $query ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + my @array = $sth->fetchrow_array () ; + $sth->finish () ; + + my $version = $array [0] ; + + return $version ; +} + +sub drop_table_if_exists ( $ ) { + my $tname = shift or die "Not enough arguments" ; + $query = "SELECT count(*) FROM pg_class WHERE relname='$tname' AND relkind='r'" ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + my @array = $sth->fetchrow_array () ; + $sth->finish () ; + + if ($array [0] != 0) { + # debug "Dropping table $tname" ; + $query = "DROP TABLE $tname" ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } +} + +sub drop_sequence_if_exists ( $ ) { + my $sname = shift or die "Not enough arguments" ; + $query = "SELECT count(*) FROM pg_class WHERE relname='$sname' AND relkind='S'" ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + my @array = $sth->fetchrow_array () ; + $sth->finish () ; + + if ($array [0] != 0) { + # debug "Dropping sequence $sname" ; + $query = "DROP SEQUENCE $sname" ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } +} + +sub drop_index_if_exists ( $ ) { + my $iname = shift or die "Not enough arguments" ; + $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND relkind='i'" ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + my @array = $sth->fetchrow_array () ; + $sth->finish () ; + + if ($array [0] != 0) { + # debug "Dropping index $iname" ; + $query = "DROP INDEX $iname" ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } +} + +sub drop_view_if_exists ( $ ) { + my $iname = shift or die "Not enough arguments" ; + $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND relkind='v'" ; + my $sth = $dbh->prepare ($query) ; + $sth->execute () ; + my @array = $sth->fetchrow_array () ; + $sth->finish () ; + + if ($array [0] != 0) { + # debug "Dropping view $iname" ; + $query = "DROP VIEW $iname" ; + # debug $query ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + $sth->finish () ; + } +} + +sub bump_sequence_to ( $$ ) { + my ($sth, @array, $seqname, $targetvalue) ; + + $seqname = shift ; + $targetvalue = shift ; + + do { + $query = "select nextval ('$seqname')" ; + $sth = $dbh->prepare ($query) ; + $sth->execute () ; + @array = $sth->fetchrow_array () ; + $sth->finish () ; + } until $array[0] >= $targetvalue ; +} diff --git a/gforge-plugin-ldapextauth/debian/README.Debian b/gforge-plugin-ldapextauth/debian/README.Debian new file mode 100644 index 0000000000..c8c5c78a94 --- /dev/null +++ b/gforge-plugin-ldapextauth/debian/README.Debian @@ -0,0 +1,7 @@ +gforge-plugin-ldapextauth for Debian +------------------------------------ + +This plugin allows Gforge to authenticate users against an external +LDAP directory. + + -- Roland Mas , Sun Dec 14 21:55:40 2003 diff --git a/gforge-plugin-ldapextauth/debian/changelog b/gforge-plugin-ldapextauth/debian/changelog new file mode 100644 index 0000000000..48c29a40f3 --- /dev/null +++ b/gforge-plugin-ldapextauth/debian/changelog @@ -0,0 +1,6 @@ +gforge-plugin-ldapextauth (0.1-1) UNRELEASED; urgency=low + + * First release of the external LDAP authentication plugin. + + -- Roland Mas Sun, 14 Dec 2003 21:50:15 +0100 + diff --git a/gforge-plugin-ldapextauth/debian/control b/gforge-plugin-ldapextauth/debian/control new file mode 100644 index 0000000000..615ce638af --- /dev/null +++ b/gforge-plugin-ldapextauth/debian/control @@ -0,0 +1,11 @@ +Source: gforge-plugin-ldapextauth +Section: devel +Priority: optional +Maintainer: Roland Mas +Build-Depends-Indep: debhelper (>> 4.0.0) +Standards-Version: 3.5.8 + +Package: gforge-plugin-ldapextauth +Architecture: all +Depends: gforge-common, gforge-db-postgresql | gforge-db, gforge-web-apache | gforge-web +Description: A Gforge plugin to authenticate from an external LDAP directory diff --git a/gforge-plugin-ldapextauth/debian/copyright b/gforge-plugin-ldapextauth/debian/copyright new file mode 100644 index 0000000000..ce9eda579e --- /dev/null +++ b/gforge-plugin-ldapextauth/debian/copyright @@ -0,0 +1,24 @@ +This package was debianized by Roland Mas on +Sun, 14 Dec 2003 21:52:12 +0100 + +Upstream Author: Roland Mas (Based on an idea and +preliminary code by Joseph Bironas ). + +Copyright: + + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 dated June, 1991. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. + +On Debian GNU/Linux systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL'. diff --git a/gforge-plugin-ldapextauth/debian/dirs b/gforge-plugin-ldapextauth/debian/dirs new file mode 100644 index 0000000000..62d652cee2 --- /dev/null +++ b/gforge-plugin-ldapextauth/debian/dirs @@ -0,0 +1,20 @@ +etc +etc/gforge +etc/gforge/httpd.conf.d +etc/gforge/httpd.secrets.d +etc/gforge/plugins +etc/gforge/plugins/ldapextauth +usr +usr/lib +usr/lib/gforge +usr/lib/gforge/plugins/ +usr/lib/gforge/plugins/ldapextauth +usr/lib/gforge/plugins/ldapextauth/bin +usr/lib/gforge/plugins/ldapextauth/include +usr/lib/gforge/plugins/ldapextauth/lib +usr/lib/gforge/cgi-bin +usr/share +usr/share/gforge +usr/share/gforge/www +usr/share/gforge/www/plugins +usr/share/gforge/www/plugins/ldapextauth diff --git a/gforge-plugin-ldapextauth/debian/postinst b/gforge-plugin-ldapextauth/debian/postinst new file mode 100644 index 0000000000..e2681df80d --- /dev/null +++ b/gforge-plugin-ldapextauth/debian/postinst @@ -0,0 +1,50 @@ +#! /bin/sh +# postinst script for gforge-plugin-ldapextauth +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package +# +# quoting from the policy: +# Any necessary prompting should almost always be confined to the +# post-installation script, and should be protected with a conditional +# so that unnecessary prompting doesn't happen if a package's +# installation fails and the `postinst' is called with `abort-upgrade', +# `abort-remove' or `abort-deconfigure'. + +case "$1" in + configure) + /usr/lib/gforge/plugins/ldapextauth/bin/db-upgrade.pl + /usr/lib/gforge/bin/register-plugin ldapextauth "LDAP external authentication" + invoke-rc.d apache reload + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 + + diff --git a/gforge-plugin-ldapextauth/debian/postrm.ex b/gforge-plugin-ldapextauth/debian/postrm.ex new file mode 100644 index 0000000000..4aad00a8bc --- /dev/null +++ b/gforge-plugin-ldapextauth/debian/postrm.ex @@ -0,0 +1,38 @@ +#! /bin/sh +# postrm script for gforge-plugin-moinwiki +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `abort-install' +# * `abort-install' +# * `abort-upgrade' +# * `disappear' overwrit>r> +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + + + ;; + + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/gforge-plugin-ldapextauth/debian/preinst.ex b/gforge-plugin-ldapextauth/debian/preinst.ex new file mode 100644 index 0000000000..fa69a032ac --- /dev/null +++ b/gforge-plugin-ldapextauth/debian/preinst.ex @@ -0,0 +1,38 @@ +#! /bin/sh +# preinst script for gforge-plugin-moinwiki +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `install' +# * `install' +# * `upgrade' +# * `abort-upgrade' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + install|upgrade) + ;; + + abort-upgrade) + ;; + + *) + echo "preinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 + + diff --git a/gforge-plugin-ldapextauth/debian/prerm b/gforge-plugin-ldapextauth/debian/prerm new file mode 100644 index 0000000000..e1ca691e04 --- /dev/null +++ b/gforge-plugin-ldapextauth/debian/prerm @@ -0,0 +1,41 @@ +#! /bin/sh +# prerm script for gforge-plugin-ldapextauth +# +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `remove' +# * `upgrade' +# * `failed-upgrade' +# * `remove' `in-favour' +# * `deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + + +case "$1" in + remove|deconfigure) + /usr/lib/gforge/bin/unregister-plugin ldapextauth + invoke-rc.d apache reload + /usr/lib/gforge/plugins/ldapextauth/bin/db-delete.pl + ;; + upgrade|failed-upgrade) + ;; + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 + + diff --git a/gforge-plugin-ldapextauth/debian/rules b/gforge-plugin-ldapextauth/debian/rules new file mode 100755 index 0000000000..4aeccf35c5 --- /dev/null +++ b/gforge-plugin-ldapextauth/debian/rules @@ -0,0 +1,91 @@ +#!/usr/bin/make -f +# Sample debian/rules that uses debhelper. +# GNU copyright 1997 to 1999 by Joey Hess. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# This is the debhelper compatibility version to use. +export DH_COMPAT=4 + +export PLUGIN=ldapextauth + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + touch configure-stamp + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + touch build-stamp + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + dh_clean + +DESTDIR=$(CURDIR)/debian/gforge-plugin-$(PLUGIN) + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + cp -r bin/* $(DESTDIR)/usr/lib/gforge/plugins/$(PLUGIN)/bin/ + cp -r include/* $(DESTDIR)/usr/lib/gforge/plugins/$(PLUGIN)/include/ + # cp -r lib/* $(DESTDIR)/usr/lib/gforge/plugins/$(PLUGIN)/lib/ + # cp -r cgi-bin/* $(DESTDIR)/usr/lib/gforge/plugins/$(PLUGIN)/cgi-bin/ + # cp -r etc/* $(DESTDIR)/etc/gforge/plugins/$(PLUGIN)/ + # cp -r www/* $(DESTDIR)/usr/share/gforge/www/plugins/$(PLUGIN)/ + # install -m 0644 httpd.conf $(DESTDIR)/etc/gforge/httpd.conf.d/50$(PLUGIN) + # install -m 0600 httpd.secrets $(DESTDIR)/etc/gforge/httpd.secrets.d/50$(PLUGIN) + find $(DESTDIR)/ -name CVS -type d | xargs rm -rf + find $(DESTDIR)/usr/lib/gforge/plugins/$(PLUGIN)/bin/ -type f | xargs chmod 0755 + find $(DESTDIR)/usr/lib/gforge/plugins/$(PLUGIN)/include/ -type f | xargs chmod 0644 + # find $(DESTDIR)/usr/lib/gforge/plugins/$(PLUGIN)/lib/ -type f | xargs chmod 0644 + # find $(DESTDIR)/usr/lib/gforge/plugins/$(PLUGIN)/cgi-bin/ -type f | xargs chmod 0755 + # find $(DESTDIR)/etc/gforge/plugins/$(PLUGIN)/ -type f | xargs chmod 0644 + # find $(DESTDIR)/usr/share/gforge/www/plugins/$(PLUGIN)/ -type f | xargs chmod 0644 + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot +# dh_installdebconf + dh_installdocs + dh_installexamples + dh_installmenu +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_installinit + dh_installcron + dh_installman + dh_installinfo +# dh_undocumented + dh_installchangelogs + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_makeshlibs + dh_installdeb +# dh_perl + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/gforge-plugin-ldapextauth/include/LdapExtAuthPlugin.class b/gforge-plugin-ldapextauth/include/LdapExtAuthPlugin.class new file mode 100644 index 0000000000..8862fb79f0 --- /dev/null +++ b/gforge-plugin-ldapextauth/include/LdapExtAuthPlugin.class @@ -0,0 +1,69 @@ +Plugin() ; + $this->name = "ldapextauth"; + $this->hooks[] = "session_before_login"; + + $this->ldap_conn = false ; + } + + function CallHook ($hookname, $params) { + global $Language, $HTML ; + + $loginname = $params['loginname'] ; + $passwd = $params['passwd'] ; + + switch ($hookname) { + case "session_before_login": + // Authenticate against LDAP + $f=fopen ('php://stderr', 'a'); + fwrite ($f, "Login = $loginname pass = $passwd\n") ; + + break; + case "blah": + // Should not happen + break; + default: + // Forgot something + } + } + + function AuthUser ($loginname, $passwd) { + if (!$this->ldap_conn) { + $this->ldap_conn = ldap_connect ($sys_ldap_host,$sys_ldap_port); + } + if ($sys_ldap_version) { + ldap_set_option ($this->ldap_conn, LDAP_OPT_PROTOCOL_VERSION, $sys_ldap_version); + } + $dn = "cn=".$loginname.",".$base_dn ; + if (ldap_bind($this->ldap_conn,$dn,$user_pass)) { + // User authenticated + // Now get her info + $res = ldap_search ($this->ldap_conn, $base_dn, $dn) ; + $info = ldap_get_entries ($this->ldap_conn,$res); + + $realname = $info[0]['gecos'][0] ; + $email = $info[0]['email'][0] ; + + // Insert into DB + $u = new User () ; + $u->create ($loginname, $realname, $passwd, $passwd, $email, + 1, 1, 0, 'GMT', '', 0) ; + return true ; + } else { + // Do nothing + return false ; // Probably ignored, but just in case + } + } +} + +// Local Variables: +// mode: php +// c-file-style: "bsd" +// End: + +?> diff --git a/gforge-plugin-ldapextauth/include/ldapextauth-init.php b/gforge-plugin-ldapextauth/include/ldapextauth-init.php new file mode 100644 index 0000000000..debb9fb288 --- /dev/null +++ b/gforge-plugin-ldapextauth/include/ldapextauth-init.php @@ -0,0 +1,14 @@ + -- 2.30.2