aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--security/Makefile1
-rw-r--r--security/drupal-ldap_integration/Makefile86
-rw-r--r--security/drupal-ldap_integration/distinfo3
-rw-r--r--security/drupal-ldap_integration/files/pkg-install.in27
-rw-r--r--security/drupal-ldap_integration/ldap_integration/CHANGES.txt90
-rw-r--r--security/drupal-ldap_integration/ldap_integration/LICENSE.txt340
-rw-r--r--security/drupal-ldap_integration/ldap_integration/README.txt160
-rw-r--r--security/drupal-ldap_integration/ldap_integration/ldap_integration.module797
-rw-r--r--security/drupal-ldap_integration/ldap_integration/ldap_integration/LDAPInterface.php204
-rw-r--r--security/drupal-ldap_integration/ldap_integration/ldap_integration/conf.php66
-rw-r--r--security/drupal-ldap_integration/ldap_integration/zcallbacks.module50
-rw-r--r--security/drupal-ldap_integration/pkg-descr5
-rw-r--r--security/drupal4-ldap_integration/Makefile86
-rw-r--r--security/drupal4-ldap_integration/distinfo3
-rw-r--r--security/drupal4-ldap_integration/files/pkg-install.in27
-rw-r--r--security/drupal4-ldap_integration/ldap_integration/CHANGES.txt90
-rw-r--r--security/drupal4-ldap_integration/ldap_integration/LICENSE.txt340
-rw-r--r--security/drupal4-ldap_integration/ldap_integration/README.txt160
-rw-r--r--security/drupal4-ldap_integration/ldap_integration/ldap_integration.module797
-rw-r--r--security/drupal4-ldap_integration/ldap_integration/ldap_integration/LDAPInterface.php204
-rw-r--r--security/drupal4-ldap_integration/ldap_integration/ldap_integration/conf.php66
-rw-r--r--security/drupal4-ldap_integration/ldap_integration/zcallbacks.module50
-rw-r--r--security/drupal4-ldap_integration/pkg-descr5
23 files changed, 3657 insertions, 0 deletions
diff --git a/security/Makefile b/security/Makefile
index 01a1f9ec7051..5a659803a552 100644
--- a/security/Makefile
+++ b/security/Makefile
@@ -94,6 +94,7 @@
SUBDIR += doorman
SUBDIR += doscan
SUBDIR += dropbear
+ SUBDIR += drupal-ldap_integration
SUBDIR += drweb
SUBDIR += drweb-postfix
SUBDIR += drweb-qmail
diff --git a/security/drupal-ldap_integration/Makefile b/security/drupal-ldap_integration/Makefile
new file mode 100644
index 000000000000..edd29103c13d
--- /dev/null
+++ b/security/drupal-ldap_integration/Makefile
@@ -0,0 +1,86 @@
+# New ports collection makefile for: drupal-ldap_integration
+# Date created: 12 January 2006
+# Whom: Brooks Davis <brooks@FreeBSD.org>
+#
+# $FreeBSD$
+#
+
+PORTNAME= ldap_integration
+PORTVERSION= 4.6.0
+CATEGORIES= security www
+MASTER_SITES= http://drupal.org/files/projects/
+PKGNAMEPREFIX= drupal-
+DIST_SUBDIR= drupal
+
+MAINTAINER= brooks@FreeBSD.org
+COMMENT= LDAP user authentication for the Drupal CMS
+
+RUN_DEPENDS= ${LOCALBASE}/${DRUPDIR}/index.php:${PORTSDIR}/www/drupal
+
+USE_PHP= ldap
+
+NO_BUILD= yes
+
+DOCSDIR= ${PREFIX}/${DRUPDIR}/doc/${PORTNAME}
+DRUPMODDIR= ${DRUPDIR}/modules
+
+WRKSRC= ${WRKDIR}/${PORTNAME}
+MODULE_FILES= ldap_integration.module \
+ ldap_integration/LDAPInterface.php \
+ zcallbacks.module
+MODULE_CONF_FILES= ldap_integration/conf.php
+MODULE_CONF_DIRS= ldap_integration
+DOC_FILES= CHANGES.txt LICENSE.txt README.txt
+
+.if defined(MODULE_CONF_FILES)
+SUB_FILES= pkg-install
+SUB_LIST+= CONF_FILES=${MODULE_CONF_FILES:C|^|${DRUPMODDIR}/|} \
+ CONF_DIRS=${MODULE_CONF_DIRS:C|^|${DRUPMODDIR}/|}
+PKGINSTALL= ${WRKDIR}/pkg-install
+PKGDEINSTALL= ${PKGINSTALL}
+.endif
+
+PLIST_SUB+= DRUPMODDIR=${DRUPMODDIR}
+PLIST_FILES+= ${MODULE_FILES:C|^|%%DRUPMODDIR%%/|}
+PLIST_FILES+= ${MODULE_CONF_FILES:C|^|%%DRUPMODDIR%%/|:C|$|-dist|}
+PLIST_DIRS+= ${MODULE_DIRS:C|^|%%DRUPMODDIR%%/|}
+.if !defined(NOPORTDOCS)
+PLIST_FILES+= ${DOC_FILES:C|^|%%DOCSDIR%%/|}
+PLIST_DIRS+= %%DOCSDIR%%
+.endif
+
+.if !defined(DRUPDIR)
+pre-fetch:
+ @${ECHO_MSG} ""
+ @${ECHO_MSG} "Define DRUPDIR to override default of 'www/drupal'."
+ @${ECHO_MSG} ""
+.endif
+
+DRUPDIR?= www/drupal
+
+do-install:
+.if defined(MODULE_CONF_DIRS)
+ @${MKDIR} ${MODULE_CONF_DIRS:C|^|${PREFIX}/${DRUPMODDIR}/|}
+.endif
+.if defined(MODULE_DIRS)
+ @${MKDIR} ${MODULE_DIRS:C|^|${PREFIX}/${DRUPMODDIR}/|}
+.endif
+.for f in ${MODULE_FILES}
+ @${INSTALL_DATA} ${WRKSRC}/${f} ${PREFIX}/${DRUPMODDIR}/${f}
+.endfor
+.for f in ${MODULE_CONF_FILES}
+ @${INSTALL_DATA} ${WRKSRC}/${f} ${PREFIX}/${DRUPMODDIR}/${f}-dist
+.endfor
+.if !defined(NOPORTDOCS)
+ @${MKDIR} ${DOCSDIR}
+.for f in ${DOC_FILES}
+ @${INSTALL_DATA} ${WRKSRC}/${f} ${DOCSDIR}/${f}
+.endfor
+.endif
+
+.if defined(MODULE_CONF_FILES)
+post-install:
+ @${SH} ${PKGINSTALL} ${PKGNAME} POST-INSTALL
+.endif
+
+.include <bsd.port.mk>
diff --git a/security/drupal-ldap_integration/distinfo b/security/drupal-ldap_integration/distinfo
new file mode 100644
index 000000000000..0da7fee8dad3
--- /dev/null
+++ b/security/drupal-ldap_integration/distinfo
@@ -0,0 +1,3 @@
+MD5 (drupal/ldap_integration-4.6.0.tar.gz) = aa3c0fafae7839c0a9f012ea5f32cbbe
+SHA256 (drupal/ldap_integration-4.6.0.tar.gz) = b5535ab820420e66b25893296d0ea675a8aed6767db6f361137a2d6ee4a7ae1a
+SIZE (drupal/ldap_integration-4.6.0.tar.gz) = 21610
diff --git a/security/drupal-ldap_integration/files/pkg-install.in b/security/drupal-ldap_integration/files/pkg-install.in
new file mode 100644
index 000000000000..e18d858c77e8
--- /dev/null
+++ b/security/drupal-ldap_integration/files/pkg-install.in
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+PREFIX=%%PREFIX%%
+CONF_FILES="%%CONF_FILES%%"
+CONF_DIRS="%%CONF_DIRS%%"
+
+case $2 in
+POST-INSTALL)
+ for cfgfile in "${CONF_FILES}"; do
+ if [ ! -e ${PREFIX}/${cfgfile} ]; then
+ cp ${PREFIX}/${cfgfile}-dist ${PREFIX}/${cfgfile}
+ fi
+ done
+ ;;
+DEINSTALL)
+ for cfgfile in "${CONF_FILES}"; do
+ if cmp -s ${PREFIX}/${cfgfile} ${PREFIX}/${cfgfile}-dist ]; then
+ rm ${PREFIX}/${cfgfile}
+ fi
+ done
+ ;;
+POST-DEINSTALL)
+ for cfgdir in "${CONF_DIRS}"; do
+ rmdir ${PREFIX}/${cfgdir} 2> /dev/null || true
+ done
+ ;;
+esac
diff --git a/security/drupal-ldap_integration/ldap_integration/CHANGES.txt b/security/drupal-ldap_integration/ldap_integration/CHANGES.txt
new file mode 100644
index 000000000000..276174c1cba9
--- /dev/null
+++ b/security/drupal-ldap_integration/ldap_integration/CHANGES.txt
@@ -0,0 +1,90 @@
+13/Dec/2005
+-----------
+
+- Fixes in latest "groups as entries" feature
+
+20/Nov/2005
+-----------
+
+- (Initial support) groups can be now LDAP entries containing theis users
+ in a multivalued attribute
+
+
+06/Nov/2005
+-----------
+
+- Tabbed settings
+- Some strings fixed
+
+
+29/Oct/2005
+-----------
+
+- Novell's eDir support (thanks Klaus "Perfect Stranger")
+- Multiple base DNs can be specified for AD authentication.
+- Several LDAP attributes can hold group memberships.
+- Changed how group/role mapping works: now roles are created if they didn't exist, and mappings are specified in conf.php.
+- Passwords may be encrypted when written to LDAP.
+
+10/Oct/2005
+-----------
+
+- Added new settings on login process control and ldap/drupal attribute
+ mapping (feature request #27640).
+- LDAP groups can now map to Drupal roles.
+- Settings should make a bit more sense now.
+- hook_user() re-implementation. I hope this is the right one now.
+
+29/Sep/2005
+-----------
+
+- LDAP can now be set as unique source of authentication for LDAP users.
+ (Thanks sfrancis)
+- Minor fixes
+
+12/Sep/2005
+-----------
+
+- Added TLS authentification between Drupal and LDAP servers. (Thanks sfrancis)
+
+07/Sep/2005
+-----------
+
+- AD authentication fixes. (Thanks sfrancis)
+- PHP5 fixes
+
+20/Aug/2005
+-----------
+
+- (FIXED) "User View" page didn't show correctly field names
+
+19/Aug/2005
+-----------
+
+- (PATCHED) Bug #25067: Bad password or user returns blank screen
+- (PATCHED) Bug #28551: Authentication fails: Issues with global variable $con?
+- Minor changes in code
+
+01/Jun/2005
+-----------
+
+- Complete overhaul: module rewritten from scratch.
+- Search not yet included.
+- Active Directory not yet supported (not tested, at least).
+
+
+11/May/2005
+-----------
+
+- (FIXED) The callback replacement for user_login() not working properly.
+- Now it is possible to log in without having to use a login string of the
+ form user@server.
+- The module should _actually_ work now. It was time, wasn't it?
+
+
+6/Apr/2005
+----------
+
+- Settings page overhaul. Now it might even make some sense.
+- Now it's not necessary to allow anybody create accounts. (I figured
+ out a hack at last for this non-sensical hook_auth() problem).
diff --git a/security/drupal-ldap_integration/ldap_integration/LICENSE.txt b/security/drupal-ldap_integration/ldap_integration/LICENSE.txt
new file mode 100644
index 000000000000..64393a0cebcf
--- /dev/null
+++ b/security/drupal-ldap_integration/ldap_integration/LICENSE.txt
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/security/drupal-ldap_integration/ldap_integration/README.txt b/security/drupal-ldap_integration/ldap_integration/README.txt
new file mode 100644
index 000000000000..b1be581cf44d
--- /dev/null
+++ b/security/drupal-ldap_integration/ldap_integration/README.txt
@@ -0,0 +1,160 @@
+ldap_integration.module for Drupal 4.6
+--------------------------------------
+status: STABLE
+
+
+ - BRIEFING
+
+ This module allows users to authenticate against an admin-defined LDAP
+directory. Additionally, users can read and modify their LDAP entries, being
+the administrator able to limit it.
+
+
+ - INSTALLATION
+
+ Add the module files to the /modules/ directory of your Drupal
+installation. Those are:
+
+ * ldap_integration.module
+ * zcallbacks.module
+ * ldap_integration/conf.php
+ * ldap_integration/LDAPInterface.php
+
+ Activate BOTH *ldap_integration* and *zcallbacks* modules in Drupal's
+modules page (/admin/modules).
+
+
+ - SETUP
+
+ Prior to its use, administrators must set some variables in the preferences
+page, located at /admin/settings/ldap_integration.
+
+ -login string format
+
+ Drupal requires authentication from external sources to be in the form
+user@server, being 'external sources' any different from Drupal's own
+user database: LDAP directories, HTTP authentification, Jabber and, in
+general, any other authentification form provided by third-party modules.
+ Since this restriction can be annoying in some configurations (for example,
+those where all users log in from that same source and everyone of them has
+a login string on the form username@longname.foracommonserver.com), this
+module provides a way to circumvent it. Just unset the 'Logins must be
+on the form user@server' checkbox in the settings page.
+
+ -"pattern" and "replacement"
+
+ Parameters should be quite straightforward to set, except those called
+'LDAP login pattern' and 'LDAP login replacement' which refer to the way
+Drupal converts Drupal logins into LDAP logins, via regular expressions.
+Further explanation follows.
+
+ In Drupal, logins to external authentification sources (not Drupal's
+own database) must be in the form jdoe@foo.bar. This means that every login
+through this module must have that form.
+ On the other hand, logins to LDAP directories are in the form of a DN,
+i.e. something similar to: uid=jdoe,dc=foo,dc=bar .
+
+ So, the admin must set the way Drupal logins convert into LDAP logins. This
+os defined through the 'LDAP login pattern' and 'LDAP login replacement'
+parameters in preferences.
+
+ For help on defining these parameters, refer to the relevant entry on the
+PHP manual: http://www.php.net/manual/en/function.preg-replace.php
+
+ -directory-specific attributes
+
+ Besides, how Drupal should understand LDAP attributes is defined by
+'ldap_attributes' and 'ldap_drupal_mappings' global variables, found
+on the ldap_integration/conf.php file.
+ 'ldap_attributes' tells Drupal what kind of data is stored in each
+attribute, so it can present it with adequate names and forms in users'
+pages.
+ 'ldap_drupal_mappings' defines how Drupal's own user fields should be
+mapped to LDAP attributes, provided the 'Should Drupal account fields
+be mapped to LDAP attributes?' setting is properly set in the module
+configuration page.
+
+ -Drupal roles
+
+ Users can be granted Drupal roles automatically when logging in as
+LDAP users. These roles must already exist in Drupal's configuration and
+are checked anytime users log in from a LDAP source. However, once they
+have been granted, they can only be denied manually from Drupal's admin
+interface.
+ There are two ways of doing this: based in the users' DN and based in the
+values of one of their LDAP attributes.
+ In the former case, the setting uses a regular expression much in the
+same fashion as described above for mapping login names to DNs. A regular
+expression is defined for the DN and each one of its *parenthesized*
+sub-expressions is considered a role.
+ In the latter case, roles are just read from an attribute wich can be
+multivalued.
+
+ -"The Writer" and "The Reader" users
+
+ In order to perform some operations, such as providing of new passwords to
+those who forgot theirs, or enabling users to modify their LDAP entry, DN and
+password, two special users must be set in ldap_integration/conf.php.
+
+ If you don't care much about security, you can set both of them to be the
+administrator but, as I'm sure security is your priority #1, you should set
+them to accounts specially created for that matter.
+
+
+ - USE
+
+ The authentication facility needs no further configuration. For the LDAP
+user data reading and editing, the administrator can set what can be read and
+what can be modified by the user, by editing the relevant preferences.
+
+
+ - ISSUES
+
+ -new passwords generation
+
+ New passwords will only be generated if the users requesting it have
+logged in at least once before.
+
+ This is due to Drupal creating entries in its 'users' table for storing
+info about every user, including those authentified through modules. Drupal
+then looks the user up in the database whenever password generation is needed.
+
+ -security related:
+
+ As can be deduced from above, on the section about "The Writer" and "The
+Reader", the file ldap_integration/conf.php should not fall in the wrong
+hands.
+
+ -conflicts:
+
+ Due to the way I have had to hack this authentication through Drupal,
+there might be conflicts with other modules, specially, but I'd not venture
+to restrict to, with other auth modules.
+
+ If anyone experiences any conflict, please let me know so I can think
+of a possible solution.
+
+ -language
+
+ English is not the author's mother language. Corrections are not
+only welcome, but encouraged.
+
+
+ - CREDITS
+
+ Author:
+ - Pablo Brasero Moreno <pablobm at gmail (com)> (http://pablobm.com)
+ Sponsorship:
+ - VIZ Media (http://www.viz.com)
+ Based upon the original code by:
+ - Moshe Weitzman <weitzman at tejasa (com)>
+ Several patches
+ - Steve Francis (sfrancis @drupal.org)
+ - Douglas A. Galindo
+ - Klaus H. ("Perfect Stranger" @drupal.org)
+ Initial AD authentication code:
+ - allrite (http://allrite.net)
+ Invaluable testing by:
+ - Jose Luis Jimenez
+ - Francisco Javier Sanchez Zurdo
+ - And all those who gave me any feedback
diff --git a/security/drupal-ldap_integration/ldap_integration/ldap_integration.module b/security/drupal-ldap_integration/ldap_integration/ldap_integration.module
new file mode 100644
index 000000000000..1e1128a7b806
--- /dev/null
+++ b/security/drupal-ldap_integration/ldap_integration/ldap_integration.module
@@ -0,0 +1,797 @@
+<?php
+// $Id: ldap_integration.module,v 1.2.2.4.2.15 2005-12-13 20:30:27 pablobm Exp $
+
+include_once('ldap_integration/conf.php');
+include_once('ldap_integration/LDAPInterface.php');
+
+/*
+ * Private constants. Do not touch
+ */
+define(LDAP_PERM_SEARCH, 'perform ldap searches');
+define(LDAP_SETTINGS_GROUP_STRING, 'LDAP attributes');
+define(LDAP_USER_DATA_EDIT_TAB, 'LDAP entry');
+define(LDAP_CATEGORY_USER_DATA, 'ldap_user_data');
+
+define(LDAP_STANDARD_SYSTEM, 0);
+define(LDAP_AD_SYSTEM, 1);
+
+define(LDAP_FIRST_DRUPAL, 0);
+define(LDAP_FIRST_LDAP, 1);
+
+define(LDAP_MAP_ATTRIBUTES, 0);
+define(LDAP_MAP_ONLY_LOST_PASSWORDS, 1);
+define(LDAP_MAP_NOTHING, 2);
+
+define(LDAP_GROUP_IN_DN, 'ldap_group_in_dn');
+define(LDAP_GROUP_IN_ATTR, 'ldap_group_in_attr');
+define(LDAP_GROUP_AS_ENTRIES, 'ldap_group_as_entries');
+
+/*
+ * Private constants (default values). Do not touch either
+ */
+define(LDAP_DEFAULT_ORG, 'Home');
+define(LDAP_DEFAULT_PATTERN, '/(\S+)@(\S+)\.(\S+)/i');
+define(LDAP_DEFAULT_REPLACEMENT, 'cn=$1,dc=$2,dc=$3');
+define(LDAP_DEFAULT_BASE_DN, 'ou=Users,dc=drupal,dc=org');
+define(LDAP_DEFAULT_GROUP_DN_PATTERN, '/cn=\S+,ou=(\S+),dc=\S+,dc=\S+/i');
+define(LDAP_DEFAULT_GROUP_ATTR, 'userGroups');
+define(LDAP_DEFAULT_GROUP_ENTRIES, 'cn=Group,dc=example,dc=com');
+define(LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE, 'memberUid');
+
+$GLOBALS['ldap'] = new LDAPInterface();
+$GLOBALS['ldap']->setServer(variable_get('ldap_server', 'localhost'));
+$GLOBALS['ldap']->setPort(variable_get('ldap_port', 389));
+$GLOBALS['ldap']->setOption('TLS', variable_get('ldap_use_TLS', false));
+
+
+/*********************************
+ * 1. Drupal hooks *
+ *********************************/
+
+function ldap_integration_help($section) {
+ $output = '';
+
+ switch ($section) {
+ case 'admin/modules#ldap_integration':
+ $output = 'ldap_integration';
+ break;
+ case 'admin/modules#description':
+ case 'admin/help#ldap_integration':
+ $output = t('Enables authentication via LDAP. <strong>IMPORTANT:</strong> module <em>zcallbacks</em> down below must be enabled for this one to work.');
+ break;
+ case 'user/help#ldap_integration':
+ $output = t('<p>If you are registered in %org LDAP directory, you\'ll probably be able to login this site by using your LDAP login and password</p>', array('%org' => variable_get('ldap_org_name', '')));
+ break;
+ }
+
+ return $output;
+}
+
+function ldap_integration_settings($section = 'server') {
+ // Reminding admins about conf.php
+ $output = '<p><strong style="color: red;">PLEASE NOTE</strong>: do not forget there are further and important settings to be set in the module\'s config file, located at <code>modules/ldap_integration/conf.php</code> in your Drupal install.</p>';
+
+ // Server settings
+ $output .= form_textfield(t('Organisation name'), 'ldap_org_name', variable_get('ldap_org_name', ''), 50, 255, t('Name of the organisation the LDAP directory belongs to.'));
+ $output .= form_textfield(t('LDAP server'), 'ldap_server', variable_get('ldap_server', 'localhost'), 50, 255, t('The domain name or IP address of your LDAP Server.'));
+ $output .= form_textfield(t('LDAP port'), 'ldap_port', variable_get('ldap_port', 389), 50, 255, t('The TCP/IP port on the above server which accepts LDAP connections. Must be an integer.'));
+ $output .= form_checkbox(t('Use TLS encryption'), 'ldap_use_TLS', 1, variable_get('ldap_use_TLS', 0), t('Secure the connection between the Drupal and the LDAP servers using TLS.'));
+ $output .= form_checkbox(t('Store passwords in encrypted form'), 'ldap_store_encrypted_pass', 1, variable_get('ldap_store_encrypted_pass', 0), t('Secure the password in LDAP by storing it MD5 encrypted (use with care, as some LDAP directories may do this automatically, what would cause logins problems).'));
+
+ return $output;
+}
+
+function ldap_integration_settings_login_procedure() {
+ system_settings_save();
+ $output = '<p>' . t('Here you can specify the details of the login procedure') . '</p>';
+
+ // Login string format
+ $output .= form_checkbox(t('Logins must be on the form <em>user@server</em>'), 'ldap_login_string_with_server', 1, variable_get('ldap_login_string_with_server', 1), t('Drupal requires login strings from external sources to be in the form <em>user@server</em>. Disabling this setting will circumvent such limitation.'));
+
+ // Login process
+ $options_login_process = array(
+ LDAP_FIRST_DRUPAL => t('Drupal\'s own database. If it fails, will look on the LDAP directory'),
+ LDAP_FIRST_LDAP => t('LDAP directory only'));
+
+ $output .= form_radios(t('When logging in, Drupal will look up for the user on'), 'ldap_login_process', variable_get('ldap_login_process', LDAP_FIRST_DRUPAL), $options_login_process, NULL, true);
+
+ $options_attribute_mapping = array(
+ LDAP_MAP_ATTRIBUTES => t('Changes in account fields will be mapped to LDAP attributes and back (see <code>modules/ldap_integration/conf.php</code>).'),
+ LDAP_MAP_ONLY_LOST_PASSWORDS => t('No attribute mapping will be done, except for lost passwords. They will be randomly re-generated and sent to the user\'s mailbox.'),
+ LDAP_MAP_NOTHING => t('No attribute mapping will be done at all'));
+
+ $output .= form_radios(t('Should Drupal account fields be mapped to LDAP attributes?'), 'ldap_attr_mapping', variable_get('ldap_attr_mapping', LDAP_MAP_NOTHING), $options_attribute_mapping, NULL, true);
+
+ // System type and user mapping
+ $option_system_type_1 = form_textfield(t('LDAP login pattern'), 'ldap_login_pattern', variable_get('ldap_login_pattern', LDAP_DEFAULT_PATTERN), 50, 255, t('Regular expression matching logins for this module, that will be in the form of an e-mail address. <em>Example: %s </em>.', array('%s' => LDAP_DEFAULT_PATTERN)));
+ $option_system_type_1 .= form_textfield(t('LDAP login replacement'), 'ldap_login_replacement', variable_get('ldap_login_replacement', LDAP_DEFAULT_REPLACEMENT), 50, 255, t('Replacement to convert the above regular expression into the user\'s LDAP DN. <em>Example: %s</em>.', array('%s' => LDAP_DEFAULT_REPLACEMENT)));
+
+ $option_system_type_2 = form_textarea(t('Base DNs'), 'ldap_base_dn', variable_get('ldap_base_dn', LDAP_DEFAULT_BASE_DN), 50, 6, t('Base DN for users, to be used in eDirectory or Active Directory logins'));
+ $option_system_type_2 .= form_textfield(t('UserName attribute'), 'ldap_user_attribute', variable_get('ldap_user_attribute', 'sAMAccountName'), 50, 255, t('The attribute that holds the Users Loginname. (eg. <em>cn</em> for eDir or <em>sAMAccountName</em> for AD)'));
+
+ $options_system_type = array(
+ LDAP_STANDARD_SYSTEM => array('choice' => t('Standard LDAP system'), 'extended' => $option_system_type_1),
+ LDAP_AD_SYSTEM => array('choice' => t('eDirectory or Active Directory system'), 'extended' => $option_system_type_2));
+
+ $output .= form_complex_radios(t('System type and user mapping'), 'ldap_system_type', variable_get('ldap_system_type', LDAP_STANDARD_SYSTEM), $options_system_type, NULL, true);
+
+ print(theme('page', system_settings_form($output)));
+}
+
+function ldap_integration_settings_groups() {
+ system_settings_save();
+ $output = '<p>' . t('You may want your users to attain Drupal roles according to their LDAP groups. If that is the case, this is the place to tell the module how.') . '</p>';
+
+ // LDAP groups <-> Drupal roles
+ $option_grouproles_1 = form_textfield(t('Regular expression representing the pattern'), 'ldap_group_dn_pattern', variable_get('ldap_group_dn_pattern', LDAP_DEFAULT_GROUP_DN_PATTERN), 50, 255, t('Regular expression matching users\' DNs. Each <strong>parenthesized</strong> subexpression points out a group name. <em>Example: ' . LDAP_DEFAULT_GROUP_DN_PATTERN . '. In this example, \'ou=\' is followed by a group name that Drupal will associate to a role name</em>.'));
+ $option_grouproles_2 = form_textarea(t('Attribute names (one per line)'), 'ldap_group_attr', variable_get('ldap_group_attr', LDAP_DEFAULT_GROUP_ATTR), 50, 6, t('Name of the LDAP attributes containing the group names for each user.'));
+
+ $option_grouproles_3 = form_textarea(t('Entries containing groups (one per line)'), 'ldap_group_entries', variable_get('ldap_group_entries', LDAP_DEFAULT_GROUP_ENTRIES), 50, 6, t('Name of the LDAP entries representing user groups.'));
+ $option_grouproles_3 .= form_textfield(t('Attribute holding group members'), 'ldap_group_entries_attribute', variable_get('ldap_group_entries_attribute', LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE), 50, 255, t('Name of the multivalued attribute which holds the CNs of group members, for example: <em>' . LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE . '</em>.'));
+
+ $options_grouproles = array(
+ LDAP_GROUP_IN_DN => array('choice' => t('Group is specified in user\'s DN'), 'extended' => $option_grouproles_1),
+ LDAP_GROUP_IN_ATTR => array('choice' => t('Groups are specified by LDAP attributes'), 'extended' => $option_grouproles_2),
+ LDAP_GROUP_AS_ENTRIES => array('choice' => t('Groups exist as LDAP entries where a multivalued attribute contains the members\' CNs'), 'extended' => $option_grouproles_3));
+
+ $output .= form_complex_checkboxes(t('Should LDAP groups be reflected as Drupal roles?'), 'ldap_group_roles', variable_get('ldap_group_roles', array()), $options_grouproles);
+ $output .= form_checkbox(t('Map group sign offs'), 'ldap_map_group_signoffs', true, variable_get('ldap_map_group_signoffs', true), t('If you enable this, users signed off LDAP groups will be denied the respective Drupal roles, according to the rules set on <code>modules/ldap_integration/conf.php</code>.'));
+
+ print(theme('page', system_settings_form($output)));
+}
+
+function ldap_integration_settings_attributes() {
+ system_settings_save();
+ // LDAP attributes viewing/editing
+ global $ldap_attributes;
+
+ // Explanatory text
+ $output = '<p>' . t('Users may be able to view their LDAP attributes\' values, as well as edit them. You can configure this feature here.') . '</p>';
+
+ foreach ($ldap_attributes as $key => $field) {
+ $fields[$key] = $field[2];
+ }
+
+ // These two hidden forms are a workaround for a bug I seem to have found
+ // in Drupal, for I can't make the following two form_select() to work when
+ // no elements are selected.
+ $output .= form_hidden('ldap_user_attributes', null);
+ $output .= form_hidden('ldap_useredit_attributes', null);
+
+ $output .= form_select(t('Attributes displayed on user pages'), 'ldap_user_attributes', variable_get('ldap_user_attributes', array()), $fields, t('Select the attributes which will be displayed on user pages. Blank attributes will be omitted. You may add attributes to this list by editing the relevant global variable at the beginning of the module\'s code'), 'size="6"', true, false);
+ $output .= form_select(t('Attributes that can be edited by users'), 'ldap_useredit_attributes', variable_get('ldap_useredit_attributes', array()), $fields, t('Select the attributes users will be able to edit on their user pages. Blank attributes will be omitted. You may add attributes to this list by editing the relevant global variable at the beginning of the module\'s code'), 'size="6"', true, false);
+
+ print(theme('page', system_settings_form($output)));
+}
+
+function ldap_integration_auth($name, $pass, $server) {
+ global $ldap;
+
+ $ret = false;
+
+ if(variable_get('ldap_system_type', LDAP_STANDARD_SYSTEM) == LDAP_STANDARD_SYSTEM) {
+ $dn = _ldap_integration_login2dn($server ? "$name@$server" : $name);
+ $ret = $ldap->connect($dn, $pass);
+ }
+ else {
+ $possible_base_dns = explode("\r\n", variable_get('ldap_base_dn', ''));
+ foreach ($possible_base_dns as $base_dn) {
+ if($base_dn && $ret = $ldap->connect_ADstyle(variable_get('ldap_user_attribute', ''), $name, $base_dn, $pass)) {
+ break;
+ }
+ }
+ }
+
+ return $ret;
+}
+
+function ldap_integration_menu($may_cache) {
+ $items = array();
+
+ if ($may_cache) {
+ $items[] = array(
+ 'path' => 'admin/settings/ldap_integration/server',
+ 'title' => t('LDAP server settings'),
+ 'callback' => 'system_site_settings',
+ 'callback_arguments' => array('ldap_integration'),
+ 'weight' => 0,
+ 'type' => MENU_DEFAULT_LOCAL_TASK);
+ $items[] = array(
+ 'path' => 'admin/settings/ldap_integration/login_procedure',
+ 'title' => t('Login procedure'),
+ 'callback' => 'ldap_integration_settings_login_procedure',
+ 'weight' => 1,
+ 'type' => MENU_LOCAL_TASK);
+ $items[] = array(
+ 'path' => 'admin/settings/ldap_integration/groups',
+ 'title' => t('Groups and roles'),
+ 'callback' => 'ldap_integration_settings_groups',
+ 'weight' => 2,
+ 'type' => MENU_LOCAL_TASK);
+ $items[] = array(
+ 'path' => 'admin/settings/ldap_integration/attributes',
+ 'title' => t('LDAP attributes'),
+ 'callback' => 'ldap_integration_settings_attributes',
+ 'weight' => 3,
+ 'type' => MENU_LOCAL_TASK);
+ }
+ return $items;
+}
+
+function ldap_integration_user($op, &$edit, &$user, $category = NULL) {
+//msg("$op (uid: $user->uid; cat: $category)");
+ switch($op) {
+ case 'categories':
+ return ldap_integration_user_categories();
+ case 'form':
+ return ldap_integration_user_form($user, $category);
+ case 'load':
+ ldap_integration_user_load($user);
+ break;
+ case 'login':
+ ldap_integration_user_login($user);
+ break;
+ case 'update':
+ ldap_integration_user_update($edit, $user, $category);
+ break;
+ case 'view':
+ return ldap_integration_user_view($user);
+ }
+}
+
+
+/*********************************
+ * 2. Delegate functions *
+ *********************************/
+
+function ldap_integration_user_categories() {
+ global $user;
+
+ $ret = null;
+
+ if ($user->ldap_authentified && variable_get('ldap_useredit_attributes', array())) {
+ $ret = array(array('name' => LDAP_CATEGORY_USER_DATA, 'title' => t(LDAP_USER_DATA_EDIT_TAB), 'weight' => 10));
+ }
+
+ return $ret;
+}
+
+function ldap_integration_user_form($user, $category) {
+ global $ldap_attributes, $ldap;
+
+ if (!$user->ldap_authentified || $category != LDAP_CATEGORY_USER_DATA || ! $attributes = variable_get('ldap_useredit_attributes', array())) {
+ return;
+ }
+
+ $ldap->disconnect();
+ if (!$ldap->connect(LDAP_READER_USER_DN, LDAP_READER_USER_PASS)) {
+ watchdog('user', "User load: user $user->name's data could not be read in the LDAP directory");
+ return;
+ }
+
+ $entry = $ldap->retrieveAttributes($user->ldap_dn);
+
+ $output = '';
+ foreach($attributes as $attribute) {
+ $attr_info = $ldap_attributes[$attribute];
+ if ($attr_info) {
+ array_shift($attr_info);
+ $value = $entry[strtolower($attribute)][0];
+ $output .= _ldap_integration_attribute_form($attribute, $value, $attr_info);
+ }
+ }
+ $element = array(
+ 'title' => t(LDAP_SETTINGS_GROUP_STRING),
+ 'data' => $output,
+ 'weight' => 0);
+ $ret = array($element);
+
+ $ldap->disconnect();
+
+ return $ret;
+}
+
+function ldap_integration_user_load(&$user) {
+ global $ldap, $ldap_drupal_mappings;
+
+ if (!$user->ldap_authentified || !variable_get('ldap_attr_mapping', LDAP_MAP_ATTRIBUTES) == LDAP_MAP_ATTRIBUTES) {
+ return;
+ }
+
+ if (!$ldap->connect(LDAP_READER_USER_DN, LDAP_READER_USER_PASS)) {
+ watchdog('user', "User load: user $user->name's data could not be read in the LDAP directory");
+ return;
+ }
+
+ $newuser = $user;
+ foreach ($ldap_drupal_mappings as $ldap_attr => $drupal_field) {
+ if ($drupal_field != 'pass') {
+ $newuser->$drupal_field = $ldap->retrieveAttribute($user->ldap_dn, $ldap_attr);
+ } else {
+ $cleartext_pass = $ldap->retrieveAttribute($user->ldap_dn, $ldap_attr);
+ }
+ }
+
+ if ($newuser != $user) {
+ $newuser->pass = $cleartext_pass; // Drupal will do the md5 hash
+ $user = user_save($user, get_object_vars($newuser));
+ }
+
+ $ldap->disconnect();
+}
+
+function ldap_integration_user_login(&$user) {
+ global $ldap, $ldap_group_role_mappings;
+
+ // Mapping LDAP groups to Drupal roles
+ if (!$user->ldap_authentified || !variable_get('ldap_group_roles', 0)) {
+ return;
+ }
+
+ if (!$ldap->connect(LDAP_READER_USER_DN, LDAP_READER_USER_PASS)) {
+ watchdog('user', "User login: user $user->name's data could not be read in the LDAP directory");
+ return;
+ }
+
+ if (variable_get('ldap_map_group_signoffs', false)) {
+ // First, we take every mapped role from the user, later below
+ // we'll grant back those deserved.
+ foreach ($ldap_group_role_mappings as $role) {
+ _ldap_integration_take_role_from_user($user, $role);
+//msg("_ldap_integration_take_role_from_user($user, $role);");
+ }
+ }
+
+ $where_groups_are = variable_get('ldap_group_roles', array());
+ $groups_in_attr = (array_search('ldap_group_in_attr', $where_groups_are) !== FALSE);
+ $groups_in_dn = (array_search('ldap_group_in_dn', $where_groups_are) !== FALSE);
+ $groups_as_entries = (array_search('ldap_group_as_entries', $where_groups_are) !== FALSE);
+
+ $dn_groups = array();
+ if ($groups_in_dn && $dn_groups_regexp = variable_get('ldap_group_dn_pattern', '')) {
+ preg_match($dn_groups_regexp, $user->ldap_dn, $matches);
+ $dn_groups = array_slice($matches, 1);
+ }
+
+ $attrib_groups = array();
+ if ($groups_in_attr && $attributes = variable_get('ldap_group_attr', '')) {
+ $attributes_array = explode("\r\n", $attributes);
+ foreach ($attributes_array as $attribute) {
+ $tmp = $ldap->retrieveMultiAttribute($user->ldap_dn, $attribute);
+ $attrib_groups = array_merge($attrib_groups, $tmp);
+ }
+ }
+
+ $entries_groups = array();
+ if ($groups_as_entries && $entries = variable_get('ldap_group_entries', '')) {
+ $entries_array = explode("\r\n", $entries);
+ foreach ($entries_array as $entry) {
+ $tmp = $ldap->retrieveMultiAttribute($entry, variable_get('ldap_group_entries_attribute', LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE));
+ if (in_array($user->name, $tmp)) {
+ $entries_groups[] = $entry;
+ }
+ }
+ }
+
+ $groups = array_merge($dn_groups, $attrib_groups, $entries_groups);
+
+ foreach ($groups as $key => $group) {
+ if ($role = $ldap_group_role_mappings[$group]) {
+ _ldap_integration_create_role($role);
+ _ldap_integration_give_role_to_user($user, $role);
+//msg("_ldap_integration_give_role_to_user($user, $role);");
+ }
+ }
+
+ $ldap->disconnect();
+}
+
+function ldap_integration_user_update(&$edit, $user, $category) {
+ global $ldap;
+
+ if (!$user->ldap_authentified) {
+ return;
+ }
+
+ // Three cases here:
+ // 1. User logged on and editing his LDAP entry attributes ($category == LDAP_CATEGORY_USER_DATA).
+ // 2. User logged on and editing his Drupal account settings ($category == 'account').
+ // 3. Password lost and being updated (category == 'account').
+
+ // So, case 1
+ if ($category == LDAP_CATEGORY_USER_DATA && variable_get('ldap_useredit_attributes', array())) {
+ ldap_integration_user_update_ldap_attributes($edit, $user);
+ }
+ // Cases 2 && 3
+ else if ($category == 'account') {
+ ldap_integration_user_update_drupal_account($edit, $user);
+ }
+}
+
+function ldap_integration_user_update_ldap_attributes(&$edit, $user) {
+ global $ldap;
+
+ $ldap->disconnect();
+ if(!$ldap->connect(LDAP_WRITER_USER_DN, LDAP_WRITER_USER_PASS)) {
+ watchdog('user', "User update: user $user->name's data could not be updated in the LDAP directory");
+ return;
+ }
+
+ $writeout = array();
+ $editables = variable_get('ldap_useredit_attributes', array());
+
+ foreach ($edit as $edit_attr => $edit_val) {
+ // Preventing a POST data injection: we check allowance to write value.
+ if (array_search($edit_attr, $editables) !== FALSE) {
+ $writeout[$edit_attr] = $edit_val;
+ $edit[$edit_attr] = null;
+ }
+ }
+
+ if ($writeout) {
+ $ldap->writeAttributes($user->ldap_dn, $writeout);
+ }
+
+ $ldap->disconnect();
+}
+
+function ldap_integration_user_update_drupal_account(&$edit, $user) {
+ global $ldap, $ldap_drupal_mappings;
+
+ $ldap->disconnect();
+ if(!$ldap->connect(LDAP_WRITER_USER_DN, LDAP_WRITER_USER_PASS)) {
+ watchdog('user', "User update: user $user->name's data could not be updated in the LDAP directory");
+ return;
+ }
+
+ $password_updated_in_ldap =
+ variable_get('ldap_attr_mapping', LDAP_MAP_NOTHING) == LDAP_MAP_ONLY_LOST_PASSWORDS
+ || variable_get('ldap_attr_mapping', LDAP_MAP_NOTHING) == LDAP_MAP_ATTRIBUTES;
+
+ $account_updated_in_ldap = (variable_get('ldap_attr_mapping', LDAP_MAP_NOTHING) == LDAP_MAP_ATTRIBUTES);
+
+ if ($edit['pass'] && sizeof($edit) == 1 && $password_updated_in_ldap) {
+ // Case 3: password lost and new one generated randomly => update LDAP password
+ $drupal2ldap_mappings = array_flip($ldap_drupal_mappings);
+ $pass_ldap_attribute = $drupal2ldap_mappings['pass'];
+ $pw = variable_get('ldap_store_encrypted_pass', false) ? '{md5}' . base64_encode(pack('H*', md5($edit['pass']))) : $edit['pass'];
+ $ldap->writeAttributes($user->ldap_dn, array($pass_ldap_attribute => $pw));
+ }
+ else if ($edit['pass'] && sizeof($edit) == 1 && !$password_updated_in_ldap) {
+ // Same, but NOT having permission to update passwords
+ drupal_set_message('Lost passwords recovery has been disabled for LDAP users. Please contact your system administrator in order to get a new password.');
+ // Nulling out this field should suffice for Drupal not to try
+ // to regenerate the password, but it doesn't, so I add a drupal_goto()
+ $edit['pass'] = null;
+ drupal_goto('user/login');
+ }
+ else if ($user->ldap_authentified && $account_updated_in_ldap) {
+ // Case 2: updating account data
+ $drupal2ldap_mappings = array_flip($ldap_drupal_mappings);
+ $writeout = array();
+ foreach ($edit as $key => $value) {
+ $ldap_attr = $drupal2ldap_mappings[$key];
+ // $writeout[$ldap_attr] = $value;
+ if ($ldap_attr) {
+ if ($key == 'pass') {
+ $pw = variable_get('ldap_store_encrypted_pass', false) ? '{md5}' . base64_encode(pack('H*', md5($value))) : $value;
+ $writeout[$ldap_attr] = $pw;
+ } else {
+ $writeout[$ldap_attr] = $value;
+ }
+ }
+ }
+ $ldap->writeAttributes($user->ldap_dn, $writeout);
+ }
+
+ $ldap->disconnect();
+}
+
+function ldap_integration_user_view($user) {
+ global $ldap;
+
+ if (!$user->ldap_authentified) {
+ return;
+ }
+
+ $ldap->disconnect();
+ if (!$ldap->connect(LDAP_READER_USER_DN, LDAP_READER_USER_PASS)) {
+ watchdog('user', "User load: user $user->name's data could not be read in the LDAP directory");
+ return;
+ }
+
+ $entry = $ldap->retrieveAttributes($user->ldap_dn);
+
+ $ret = array();
+ $allowed_attrs = variable_get('ldap_user_attributes', array()) ? variable_get('ldap_user_attributes', array()) : array();
+
+ foreach($allowed_attrs as $attribute) {
+ $shown_attrs[$attribute] = $entry[strtolower($attribute)][0];
+ }
+
+ $ret[LDAP_SETTINGS_GROUP_STRING] = theme('ldap_integration_ldap_entry', $shown_attrs);
+
+ // Disconnecting just in case, for the sake of security
+ $ldap->disconnect();
+
+ return $ret;
+}
+
+
+/*********************************
+ * 3. Auxiliary functions *
+ *********************************/
+
+// Patched (2005-09-06) by sfrancis@drupal.org
+function _ldap_integration_login2dn($login) {
+ global $ldap;
+
+ if(variable_get('ldap_system_type', LDAP_STANDARD_SYSTEM) == LDAP_STANDARD_SYSTEM) {
+ $string = $login;
+ $pattern = variable_get('ldap_login_pattern', LDAP_DEFAULT_PATTERN);
+ $replacement = variable_get('ldap_login_replacement', LDAP_DEFAULT_REPLACEMENT);
+ $ret = preg_replace($pattern, $replacement, $string);
+ } else {
+ $possible_base_dns = explode("\r\n", variable_get('ldap_base_dn',''));
+ foreach ($possible_base_dns as $dn) {
+ if ($ret = $ldap->name_to_dn_AD(variable_get('ldap_user_attribute', ''), $login, $dn)) {
+ break;
+ }
+ }
+ //$ret = $ldap->name_to_dn_AD(variable_get('ldap_user_attribute', ''), $login, variable_get('ldap_base_dn',''));
+//msg_r($ret);
+ }
+
+ return $ret;
+}
+
+function _ldap_integration_attribute_form($attrname, $value, $info) {
+ $type = array_shift($info);
+
+ switch($type) {
+ case 'textfield':
+ $output = form_textfield(array_shift($info), $attrname, $value, array_shift($info), array_shift($info), array_shift($info), array_shift($info), array_shift($info));
+ break;
+ case 'password':
+ $output = form_password(array_shift($info), $attrname, $value, array_shift($info), array_shift($info), array_shift($info), array_shift($info), array_shift($info));
+ break;
+ }
+
+ return $output;
+}
+
+function _ldap_integration_give_role_to_user($user, $rolename) {
+ $result = db_query("SELECT * FROM {role} WHERE name = '$rolename'");
+ $role_exists = db_num_rows($result);
+
+ if ($role_exists) {
+ $role = db_fetch_object($result);
+ $result = db_query("SELECT * FROM {users_roles} WHERE uid = $user->uid AND rid = $role->rid");
+ $role_already_given = db_num_rows($result);
+ if (!$role_already_given) {
+ db_query("INSERT {users_roles} SET uid = $user->uid, rid = $role->rid");
+ }
+ }
+}
+
+function _ldap_integration_take_role_from_user($user, $rolename) {
+ $result = db_query("SELECT * FROM {role} WHERE name = '$rolename'");
+ $role_exists = db_num_rows($result);
+
+ if ($role_exists) {
+ $role = db_fetch_object($result);
+ $result = db_query("SELECT * FROM {users_roles} WHERE uid = $user->uid AND rid = $role->rid");
+ $role_present = db_num_rows($result);
+ if ($role_present) {
+ db_query("DELETE FROM {users_roles} WHERE uid = $user->uid AND rid = $role->rid");
+ }
+ }
+}
+
+function _ldap_integration_create_role($rolename) {
+ $result = db_query("SELECT * FROM {role} WHERE name = '$rolename'");
+ $role_exists = db_num_rows($result);
+
+ if (!$role_exists) {
+ db_query("INSERT {role} SET name = '$rolename'");
+ }
+}
+
+
+
+/*********************************
+ * 4. user.module faking stuff *
+ *********************************/
+
+function _ldap_integration_fake_user_login($edit = array(), $msg = '') {
+ global $user, $base_url;
+
+ // If we are already logged on, go to the user page instead.
+ if ($user->uid) {
+ drupal_goto('user');
+ }
+
+ if (user_deny('user', $edit['name'])) {
+ $error = t('The name %s has been denied access.', array('%s' => theme('placeholder', $edit['name'])));
+ }
+ else if ($edit['name'] && $edit['pass']) {
+
+ // === HACK STARTS ===
+ // --- New code starts
+ $user = _ldap_integration_code_added_user_login($edit['name'], $edit['pass']);
+ // --- New code ends
+
+ // --- Drupal's original code starts
+ //if (!$user->uid) {
+ // $user = user_authenticate($edit['name'], $edit['pass']);
+ //}
+ // --- Drupal's original code ends
+ // === HACK ENDS ===
+
+ if ($user->uid) {
+ watchdog('user', t('Session opened for %name.', array('%name' => theme('placeholder', $user->name))));
+
+ // Update the user table timestamp noting user has logged in.
+ db_query("UPDATE {users} SET changed = '%d' WHERE uid = '%s'", time(), $user->uid);
+
+ user_module_invoke('login', $edit, $user);
+
+ // Redirect the user to the page he logged on from.
+ drupal_goto();
+ }
+ else {
+ if (!$error) {
+ $error = t('Sorry. Unrecognized username or password.') .' '. l(t('Have you forgotten your password?'), 'user/password');
+ }
+ watchdog('user', t('Login attempt failed for %user: %error.', array('%user' => theme('placeholder', $edit['name']), '%error' => theme('placeholder', $error))));
+ }
+ }
+
+ // Display error message (if any):
+ if ($error) {
+ drupal_set_message($error, 'error');
+ }
+
+ // Display login form:
+ if ($msg) {
+ $output .= "<p>$msg</p>";
+ }
+ if (count(user_auth_help_links()) > 0) {
+ $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Enter your %s username, or an ID from one of our affiliates: %a.', array('%s' => variable_get('site_name', 'local'), '%a' => implode(', ', user_auth_help_links()))));
+ }
+ else {
+ $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Enter your %s username.', array('%s' => variable_get('site_name', 'local'))));
+ }
+ $output .= form_password(t('Password'), 'pass', $pass, 30, 64, t('Enter the password that accompanies your username.'));
+ $output .= form_submit(t('Log in'));
+
+ return form($output, 'post', url('user/login', drupal_get_destination()));
+}
+
+function _ldap_integration_code_added_user_login($name, $pass) {
+ $user = null;
+
+ if (_ldap_integration_is_ldap_login_only($name) == false) {
+ // Authenticate locally only if not initially authenticated by LDAP, or if configured to do so
+ $user = user_authenticate($name, $pass);
+ }
+
+ // If not succesful, try LDAP authentication directly
+ if (!$user->uid) {
+ $user = _ldap_integration_ldap_login($name, $pass);
+ }
+
+ return $user;
+}
+
+function _ldap_integration_is_ldap_login_only($name) {
+ return variable_get('ldap_login_process', LDAP_FIRST_LDAP) && db_num_rows(db_query("SELECT name FROM {users} WHERE locate('ldap_authentified',data) AND name='%s'",$name));
+}
+
+function _ldap_integration_ldap_login($login_string, $pass) {
+ global $ldap;
+
+ $user = null;
+
+ // Strip name and server from ID:
+ if ($server = strrchr($login_string, '@')) {
+ $name = substr($login_string, 0, strlen($login_string) - strlen($server));
+ $at = '@';
+ $server = substr($server, 1);
+ }
+ else {
+ $name = $login_string;
+ $at = '';
+ $server = '';
+ }
+
+ if (ldap_integration_auth($name, $pass, $server)) {
+ $user = user_load(array('name' => "$name$at$server"));
+ $tmp_user->name = "$name$at$server";
+ if (!$user->uid) { // Register this new user.
+ // Changes to this user_save():
+ // 1. 'pass' => $pass . Obviously. What I wonder is how it could
+ // be otherwise. Really.
+ // 2. 'mail' => value of LDAP_EMAIL_ATTRIBUTE in the LDAP directory
+ // 3. 'init' => same. BTW: what's the use of this field?
+ // 4. 'ldap_authentified' => TRUE . There is a need to mark
+ // people as externally authentified.
+ $dn = _ldap_integration_login2dn("$name$at$server");
+ $mail = $ldap->retrieveAttribute($dn, LDAP_EMAIL_ATTRIBUTE);
+ $user = user_save('', array('name' => "$name$at$server", 'pass' => $pass, 'mail' => $mail, 'init' => $mail, 'status' => 1, "authname_ldap_integration" => "$name$at$server", 'roles' => array(_user_authenticated_id()), 'ldap_authentified' => TRUE, 'ldap_dn' => $dn));
+ watchdog('user', t('New external user: %user using module %module.', array('%user' => theme('placeholder', $name .'@'. $server), '%module' => theme('placeholder', $module))), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $user->uid .'/edit'));
+ }
+ }
+
+ return $user;
+}
+
+
+/*********************************
+ * 5. Forms *
+ *********************************/
+
+function form_complex_radios($title, $name, $value, $options, $description = NULL, $required = FALSE, $attributes = NULL) {
+ if (count($options) > 0) {
+ $choices = '<dl>';
+ foreach ($options as $key => $choice) {
+ $choices .= '<dt><label class="option"><input type="radio" class="form-radio" name="edit['. $name .']" value="'. $key .'"'. ($key == $value ? ' checked="checked"' : ''). drupal_attributes($attributes). ' /> '. $choice['choice'] .'</label></dt>';
+ $choices .= '<dd style="border-left: 5px solid #DDDDDD; padding-left: 1em; margin-left: 1em;">' . $choice['extended'] . '</dd>';
+ }
+ $choices .= '</dl>';
+ return theme('form_element', $title, $choices, $description, NULL, $required, _form_get_error($name));
+ }
+}
+
+function form_complex_checkboxes($title, $name, $values, $options, $description = NULL, $attributes = FALSE, $required = NULL) {
+ if (count($options) > 0) {
+ $choices = '<dl>';
+ foreach ($options as $key => $choice) {
+ $choices .= '<dt><label class="option"><input type="checkbox" class="form-checkbox" name="edit['. $name .'][]" value="'. $key .'"'. ($values && in_array($key, $values) ? ' checked="checked"' : ''). drupal_attributes($attributes) .' /> '. $choice['choice'] .'</label></dt>';
+ $choices .= '<dd style="border-left: 5px solid #DDDDDD; padding-left: 1em; margin-left: 1em;">' . $choice['extended'] . '</dd>';
+ }
+ $choices .= '</dl>';
+ // Note: because unchecked boxes are not included in the POST data, we
+ // include a form_hidden() which will be overwritten as soon as there is at
+ // least one checked box.
+ return form_hidden($name, 0) . theme('form_element', $title, $choices, $description, NULL, $required, _form_get_error($name));
+ }
+}
+
+
+/*********************************
+ * 6. Themes *
+ *********************************/
+
+function theme_ldap_integration_ldap_entry($attributes) {
+ global $ldap_attributes;
+
+ $attributes = $attributes ? $attributes : array();
+ $output = "<dl>\n";
+ foreach($attributes as $attribute => $value) {
+ $attribute_title = $ldap_attributes[$attribute][2];
+ $output .= "<dt>$attribute_title</dt><dd>$value</dd>\n";
+ }
+ $output .= "</dl>\n";
+
+ return $output;
+}
+
+/*********************************
+ * 7. Debug utils *
+ *********************************/
+
+function msg($string) {
+ drupal_set_message("<pre style=\"border: 0; margin: 0; padding: 0;\">$string</pre>");
+}
+
+function msg_r($object) {
+ ob_start();
+ print_r($object);
+ $output = ob_get_contents();
+ ob_end_clean();
+ msg($output);
+}
+
+?>
+
diff --git a/security/drupal-ldap_integration/ldap_integration/ldap_integration/LDAPInterface.php b/security/drupal-ldap_integration/ldap_integration/ldap_integration/LDAPInterface.php
new file mode 100644
index 000000000000..cbb4472ced24
--- /dev/null
+++ b/security/drupal-ldap_integration/ldap_integration/ldap_integration/LDAPInterface.php
@@ -0,0 +1,204 @@
+<?php
+// $Id: LDAPInterface.php,v 1.1.4.8 2005/11/03 20:15:32 pablobm Exp $
+
+class LDAPInterface {
+
+ function LDAPInterface() {
+ $this->connection = null;
+ $this->server = localhost;
+ $this->port = 389;
+ $this->secretKey = NULL;
+ $this->useTLS = false;
+ }
+
+ var $connection;
+ var $server;
+ var $port;
+ var $useTLS;
+
+ // Setters & getters
+ function setServer($server) { $this->server = $server; }
+ function getServer() { return $this->server; }
+ function setPort($port) { $this->port = $port; }
+ function getPort() { return $this->port; }
+
+ function setOption($option, $value) {
+ if ($option == 'TLS') {
+ $this->useTLS = $value;
+ }
+ }
+
+ function getOption($option) {
+ $ret = -1;
+
+ if ($option == 'version') {
+ ldap_get_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $ret);
+ }
+
+ return $ret;
+ }
+
+ function connect($dn = '', $pass = '') {
+ $ret = FALSE;
+
+ // If a connection already exists, it should be terminated
+ $this->disconnect();
+
+ if ($this->connectAndBind($dn, $pass)) {
+ $ret = TRUE;
+ }
+
+ return $ret;
+ }
+
+ // Code contributed by allrite@drupal.org (http://allrite.net)
+ // Patched (2005-09-06) by sfrancis@drupal.org
+ // Patched (2005-10-29) by Perfect Stranger (@drupal.org)
+ function connect_ADstyle($uattr = '', $name = '', $base_dn = '', $pass = '') {
+ global $ldap;
+
+ // If a connection already exists, it should be terminated
+ $this->disconnect();
+ $this->establishConnection();
+
+ ob_start();
+ $anon_bind = @ldap_bind($this->connection, LDAP_READER_USER_DN, LDAP_READER_USER_PASS);
+
+ // Bind anonymously
+ $res = false;
+ $dn = $uattr . '=' . $name;
+ //srf
+ global $ldap;
+ //srf - the base dn is already passed as an argument to this function $anon_res = @ldap_search($this->connection, variable_get('ldap_base_dn', ''), $dn);
+ $anon_res = @ldap_search($this->connection, $base_dn, $dn);
+ //srf
+ if ($anon_res) {
+ if (ldap_count_entries($this->connection, $anon_res) !=1) {
+ watchdog('user',"Error: Zero or more than 1 user found with $dn");
+ return false;
+ }
+ //srf
+
+ $users = @ldap_get_entries($this->connection, $anon_res);
+
+ $this->disconnect();
+ $this->establishConnection();
+
+ $user_dn = $users[0]["dn"];
+ $res = @ldap_bind($this->connection, $user_dn, $pass);
+ }
+ else {
+ $this->disconnect();
+ }
+ ob_end_clean();
+
+ return $res;
+ }
+
+ // Code contributed by sfrancis@drupal.org
+ function name_to_dn_AD($uattr = '', $name = '', $base_dn = '') {
+ global $ldap;
+
+ $dn = $uattr . '=' . $name;
+ $res = @ldap_search($this->connection, $base_dn, $dn);
+ if ($res) {
+ if (ldap_count_entries($this->connection, $res) !=1) {
+ watchdog('user',"Error: Zero or more than 1 user found with $base_dn");
+ return false;
+ }
+ $users = @ldap_get_entries($this->connection, $res);
+ $user_dn = $users[0]["dn"];
+ }
+
+ return $user_dn;
+ }
+
+ function establishConnection() {
+ if (!$con = ldap_connect($this->server, $this->port)) {
+ watchdog('user', 'LDAP Connect failure to ' . $this->server . ':' . $this->port);
+ return NULL;
+ }
+ $this->connection = $con;
+ ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
+ // TLS encryption contributed by sfrancis@drupal.org
+ if ($this->useTLS) {
+ $vers = $this->getOption('version');
+ if ($vers == -1) {
+ watchdog('user', 'Could not get LDAP protocol version.');
+ }
+
+ if ($vers != 3) {
+ watchdog('user', 'Could not start TLS, only supported by LDAP v3.');
+ }
+ else if (!ldap_start_tls($con)) {
+ watchdog('user', t("Failed to start TLS on LDAP server. (Error %errno: %error).", array('%errno' => ldap_errno($con), '%error' => ldap_error($con))));
+ }
+ }
+ }
+
+ function connectAndBind($dn = '', $pass = '') {
+ $this->establishConnection();
+
+ $con = $this->connection;
+ //die('con: ' . $con . ', dn: ' . $dn . ', pass: ' . $pass . ', server: ' . $this->server . ', port: ' . $this->port);
+ // We don't want anonymous connections here
+ if (!$dn || !$pass || !$this->bind($dn, $pass)) {
+ watchdog('user', t('LDAP Bind failure for user %user. Error %errno: %error', array('%user' => $dn,'%errno' => ldap_errno($con), '%error' => ldap_error($con))));
+ return NULL;
+ }
+
+ return $con;
+ }
+
+ function bind($dn, $pass) {
+ ob_start();
+ $ret = ldap_bind($this->connection, $dn, $pass);
+ ob_end_clean();
+
+ return $ret;
+ }
+
+
+ function disconnect() {
+ if ($this->connection) {
+ ldap_unbind($this->connection);
+ $this->connection = NULL;
+ }
+ }
+
+ // WARNING! WARNING! WARNING!
+ // This function returns its entries with lowercase attribute names.
+ // Don't blame me, blame PHP's own ldap_get_entries()
+ function retrieveAttributes($dn) {
+ $result = ldap_read($this->connection, $dn, 'objectClass=*');
+ $entries = ldap_get_entries($this->connection, $result);
+
+ return $entries[0];
+ }
+
+ function retrieveAttribute($dn, $attrname) {
+ $entries = $this->retrieveAttributes($dn);
+
+ return $entries[strtolower($attrname)][0];
+ }
+
+ function retrieveMultiAttribute($dn, $attrname) {
+ $entries = $this->retrieveAttributes($dn);
+
+ $result = array();
+ $retrieved = $entries[strtolower($attrname)];
+ $retrieved = $retrieved ? $retrieved : array();
+ foreach ($retrieved as $key => $value) {
+ if ($key !== 'count') {
+ $result[] = $value;
+ }
+ }
+ return $result;
+ }
+
+ function writeAttributes($dn, $attributes) {
+ ldap_modify($this->connection, $dn, $attributes);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/security/drupal-ldap_integration/ldap_integration/ldap_integration/conf.php b/security/drupal-ldap_integration/ldap_integration/ldap_integration/conf.php
new file mode 100644
index 000000000000..38348584ddc3
--- /dev/null
+++ b/security/drupal-ldap_integration/ldap_integration/ldap_integration/conf.php
@@ -0,0 +1,66 @@
+<?php
+// $Id: conf.php,v 1.1.4.4 2005/10/29 19:09:30 pablobm Exp $
+
+/*
+ * Interesting constants that admins would want to mess with
+ */
+
+// Admin must define a user able to write users' attributes (to generate new passwords when they are lost)
+define(LDAP_WRITER_USER_DN, 'cn=writer,dc=example,dc=com');
+define(LDAP_WRITER_USER_PASS, 'secret');
+
+// Admin must define a user able to read users' attributes (to read e-mail addresses when passwords are lost)
+define(LDAP_READER_USER_DN, 'cn=reader,dc=example,dc=com');
+define(LDAP_READER_USER_PASS, 'secret');
+
+$GLOBALS['ldap_drupal_mappings'] = array(
+ // ldap_attribute => drupal field
+ // 'cn' => 'name',
+ 'mailAddress' => 'mail',
+ 'userPassword' => 'pass',
+ //'signature' => 'signature',
+ //'timeZome' => 'timezone'
+);
+
+/*
+ * Edit this list so that all attributes that you might wish to show
+ * are included. You may then enable/disable attributes in the Admin page.
+ *
+ * The left hand element indicates the LDAP attribute name.
+ *
+ * The 1st right hand elements in the array determine how the attribute and
+ * its value are displayed. The first element may be 'text', 'image', or 'url'.
+ */
+
+$GLOBALS['ldap_attributes'] = array(
+ 'givenName' => array('text', 'textfield', t('First Name'), 64, 64),
+ 'userPassword' => array('pass', 'password', t('Password'), 64, 64),
+ 'initials' => array('text', 'textfield', t('Initial'), 64, 4, t('Your middle initial.')),
+ 'sn' => array('text', 'textfield', t('Last Name'), 64, 64), //aka Surname
+ 'cn' => array('text', 'textfield', t('Common Name'), 64, 64),
+ 'displayName' => array('text', 'textfield', t('Display Name'), 64, 64),
+ 'mail' => array('mailto', 'textfield', t('Email'), 64, 64, ''),
+ 'description' => array('text', 'textfield', t('Description'), 64, 64, ''),
+ 'postOfficeBox' => array('text', 'textfield', t('P.O. Box'), 64, 64),
+ 'streetaddress' => array('text', 'textfield', t('Address'), 64, 64),
+ 'l' => array('text', 'textfield', t('City'), 64, 64, t('Your city or other location')),
+ 'st' => array('text', 'textfield', t('State'), 4, 2, t('Your state or province')),
+ 'postalCode' => array('text', 'textfield', t('Postal Code'), 7, 5, t('Your Zip or Postal code')),
+ 'co' => array('text', 'textfield', t('Country'), 64, 64, t('Country or region')),
+ 'company' => array('text', 'textfield', t('Company'), 12, 12, 'Company or organization'),
+ 'title' => array('text', 'textfield', t('Title'), 12, 12),
+ 'department' => array('text', 'textfield', t('Department'), 64, 64),
+ 'physicalDeliveryOfficeName' => array('text', 'textfield', t('Office'), 64, 64, ''),
+ 'homephone' => array('text', 'textfield', t('Home Phone'), 64, 64, ''),
+ 'mobile' => array('text', 'textfield', t('Mobile Phone'), 64, 64, ''),
+ 'otherTelephone' => array('text', 'textfield', t('Other Phone'), 64, 64, ''),
+ 'wWWHomePage' => array('image', 'textfield', t('Web Page'), 64, 64, ''),
+ 'url' => array('link', 'textfield', t('Other web pages'), 64, 64, ''),
+ 'roomNumber' => array('text', 'textfield', t('Office Location'), 64, 64, ''),
+ 'telephoneNumber' => array('text', 'textfield', t('Office Phone'), 64, 64, ''),
+
+ // examples of displaying attributes in Select menus or TextArea boxes. Helpful for composing search queries
+ 'gender' => array('text', 'select', t('Gender'), array(0 => '-', 'm' => t('male'), 'f' => t('female')), 'Pick a gender', 0, 0),
+ 'publickey' => array('text', 'textarea', t('Public key'), 64, 4, ''));
+
+?>
diff --git a/security/drupal-ldap_integration/ldap_integration/zcallbacks.module b/security/drupal-ldap_integration/ldap_integration/zcallbacks.module
new file mode 100644
index 000000000000..8446415141e1
--- /dev/null
+++ b/security/drupal-ldap_integration/ldap_integration/zcallbacks.module
@@ -0,0 +1,50 @@
+<?php
+// $Id: zcallbacks.module,v 1.1.2.1.2.3 2005-12-13 20:30:27 pablobm Exp $
+
+/*
+ * This mini-module just redefines a callback originally defined in user.module, so it
+ * serves better our interests in the ldap_integration module.
+ * It has to be separated from the rest of the module because modules are loaded in
+ * alphabetic order and this callback must be loaded after that of user.module.
+ */
+
+function zcallbacks_help($section) {
+ $output = '';
+
+ switch ($section) {
+ case 'admin/modules#zcallbacks':
+ $output = 'zcallbacks';
+ break;
+ case 'admin/modules#description':
+ case 'admin/help#zcallbacks':
+ $output = t('<strong>Needed</strong> to make <em>ldap_integration</em> module work.');
+ break;
+ case 'user/help#zcallbacks':
+ $output = t('<p>This module <strong>must be enabled</strong> for LDAP authentication to work with em>ldap_integration</em> module</p>');
+ break;
+ }
+
+ return $output;
+}
+
+function zcallbacks_menu($may_cache) {
+ $items = array();
+
+ if ($may_cache) {
+ // Hack callback. It replaces one set in user.module
+ $items[] = array(
+ 'path' => 'user/login',
+ 'title' => t('log in'),
+ 'callback' => '_zcallbacks_call',
+ 'access' => TRUE,
+ 'type' => MENU_CALLBACK);
+ }
+
+ return $items;
+}
+
+function _zcallbacks_call() {
+ print theme('page', _ldap_integration_fake_user_login($_POST['edit']));
+}
+
+?>
diff --git a/security/drupal-ldap_integration/pkg-descr b/security/drupal-ldap_integration/pkg-descr
new file mode 100644
index 000000000000..b6a23d3b7035
--- /dev/null
+++ b/security/drupal-ldap_integration/pkg-descr
@@ -0,0 +1,5 @@
+The ldap_integration Drupal module allows users to authenticate against
+a LDAP directory. Additionally, users can read and modify their data in
+the LDAP directory subject to administrative restrictions.
+
+WWW: http://drupal.org/node/15109
diff --git a/security/drupal4-ldap_integration/Makefile b/security/drupal4-ldap_integration/Makefile
new file mode 100644
index 000000000000..edd29103c13d
--- /dev/null
+++ b/security/drupal4-ldap_integration/Makefile
@@ -0,0 +1,86 @@
+# New ports collection makefile for: drupal-ldap_integration
+# Date created: 12 January 2006
+# Whom: Brooks Davis <brooks@FreeBSD.org>
+#
+# $FreeBSD$
+#
+
+PORTNAME= ldap_integration
+PORTVERSION= 4.6.0
+CATEGORIES= security www
+MASTER_SITES= http://drupal.org/files/projects/
+PKGNAMEPREFIX= drupal-
+DIST_SUBDIR= drupal
+
+MAINTAINER= brooks@FreeBSD.org
+COMMENT= LDAP user authentication for the Drupal CMS
+
+RUN_DEPENDS= ${LOCALBASE}/${DRUPDIR}/index.php:${PORTSDIR}/www/drupal
+
+USE_PHP= ldap
+
+NO_BUILD= yes
+
+DOCSDIR= ${PREFIX}/${DRUPDIR}/doc/${PORTNAME}
+DRUPMODDIR= ${DRUPDIR}/modules
+
+WRKSRC= ${WRKDIR}/${PORTNAME}
+MODULE_FILES= ldap_integration.module \
+ ldap_integration/LDAPInterface.php \
+ zcallbacks.module
+MODULE_CONF_FILES= ldap_integration/conf.php
+MODULE_CONF_DIRS= ldap_integration
+DOC_FILES= CHANGES.txt LICENSE.txt README.txt
+
+.if defined(MODULE_CONF_FILES)
+SUB_FILES= pkg-install
+SUB_LIST+= CONF_FILES=${MODULE_CONF_FILES:C|^|${DRUPMODDIR}/|} \
+ CONF_DIRS=${MODULE_CONF_DIRS:C|^|${DRUPMODDIR}/|}
+PKGINSTALL= ${WRKDIR}/pkg-install
+PKGDEINSTALL= ${PKGINSTALL}
+.endif
+
+PLIST_SUB+= DRUPMODDIR=${DRUPMODDIR}
+PLIST_FILES+= ${MODULE_FILES:C|^|%%DRUPMODDIR%%/|}
+PLIST_FILES+= ${MODULE_CONF_FILES:C|^|%%DRUPMODDIR%%/|:C|$|-dist|}
+PLIST_DIRS+= ${MODULE_DIRS:C|^|%%DRUPMODDIR%%/|}
+.if !defined(NOPORTDOCS)
+PLIST_FILES+= ${DOC_FILES:C|^|%%DOCSDIR%%/|}
+PLIST_DIRS+= %%DOCSDIR%%
+.endif
+
+.if !defined(DRUPDIR)
+pre-fetch:
+ @${ECHO_MSG} ""
+ @${ECHO_MSG} "Define DRUPDIR to override default of 'www/drupal'."
+ @${ECHO_MSG} ""
+.endif
+
+DRUPDIR?= www/drupal
+
+do-install:
+.if defined(MODULE_CONF_DIRS)
+ @${MKDIR} ${MODULE_CONF_DIRS:C|^|${PREFIX}/${DRUPMODDIR}/|}
+.endif
+.if defined(MODULE_DIRS)
+ @${MKDIR} ${MODULE_DIRS:C|^|${PREFIX}/${DRUPMODDIR}/|}
+.endif
+.for f in ${MODULE_FILES}
+ @${INSTALL_DATA} ${WRKSRC}/${f} ${PREFIX}/${DRUPMODDIR}/${f}
+.endfor
+.for f in ${MODULE_CONF_FILES}
+ @${INSTALL_DATA} ${WRKSRC}/${f} ${PREFIX}/${DRUPMODDIR}/${f}-dist
+.endfor
+.if !defined(NOPORTDOCS)
+ @${MKDIR} ${DOCSDIR}
+.for f in ${DOC_FILES}
+ @${INSTALL_DATA} ${WRKSRC}/${f} ${DOCSDIR}/${f}
+.endfor
+.endif
+
+.if defined(MODULE_CONF_FILES)
+post-install:
+ @${SH} ${PKGINSTALL} ${PKGNAME} POST-INSTALL
+.endif
+
+.include <bsd.port.mk>
diff --git a/security/drupal4-ldap_integration/distinfo b/security/drupal4-ldap_integration/distinfo
new file mode 100644
index 000000000000..0da7fee8dad3
--- /dev/null
+++ b/security/drupal4-ldap_integration/distinfo
@@ -0,0 +1,3 @@
+MD5 (drupal/ldap_integration-4.6.0.tar.gz) = aa3c0fafae7839c0a9f012ea5f32cbbe
+SHA256 (drupal/ldap_integration-4.6.0.tar.gz) = b5535ab820420e66b25893296d0ea675a8aed6767db6f361137a2d6ee4a7ae1a
+SIZE (drupal/ldap_integration-4.6.0.tar.gz) = 21610
diff --git a/security/drupal4-ldap_integration/files/pkg-install.in b/security/drupal4-ldap_integration/files/pkg-install.in
new file mode 100644
index 000000000000..e18d858c77e8
--- /dev/null
+++ b/security/drupal4-ldap_integration/files/pkg-install.in
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+PREFIX=%%PREFIX%%
+CONF_FILES="%%CONF_FILES%%"
+CONF_DIRS="%%CONF_DIRS%%"
+
+case $2 in
+POST-INSTALL)
+ for cfgfile in "${CONF_FILES}"; do
+ if [ ! -e ${PREFIX}/${cfgfile} ]; then
+ cp ${PREFIX}/${cfgfile}-dist ${PREFIX}/${cfgfile}
+ fi
+ done
+ ;;
+DEINSTALL)
+ for cfgfile in "${CONF_FILES}"; do
+ if cmp -s ${PREFIX}/${cfgfile} ${PREFIX}/${cfgfile}-dist ]; then
+ rm ${PREFIX}/${cfgfile}
+ fi
+ done
+ ;;
+POST-DEINSTALL)
+ for cfgdir in "${CONF_DIRS}"; do
+ rmdir ${PREFIX}/${cfgdir} 2> /dev/null || true
+ done
+ ;;
+esac
diff --git a/security/drupal4-ldap_integration/ldap_integration/CHANGES.txt b/security/drupal4-ldap_integration/ldap_integration/CHANGES.txt
new file mode 100644
index 000000000000..276174c1cba9
--- /dev/null
+++ b/security/drupal4-ldap_integration/ldap_integration/CHANGES.txt
@@ -0,0 +1,90 @@
+13/Dec/2005
+-----------
+
+- Fixes in latest "groups as entries" feature
+
+20/Nov/2005
+-----------
+
+- (Initial support) groups can be now LDAP entries containing theis users
+ in a multivalued attribute
+
+
+06/Nov/2005
+-----------
+
+- Tabbed settings
+- Some strings fixed
+
+
+29/Oct/2005
+-----------
+
+- Novell's eDir support (thanks Klaus "Perfect Stranger")
+- Multiple base DNs can be specified for AD authentication.
+- Several LDAP attributes can hold group memberships.
+- Changed how group/role mapping works: now roles are created if they didn't exist, and mappings are specified in conf.php.
+- Passwords may be encrypted when written to LDAP.
+
+10/Oct/2005
+-----------
+
+- Added new settings on login process control and ldap/drupal attribute
+ mapping (feature request #27640).
+- LDAP groups can now map to Drupal roles.
+- Settings should make a bit more sense now.
+- hook_user() re-implementation. I hope this is the right one now.
+
+29/Sep/2005
+-----------
+
+- LDAP can now be set as unique source of authentication for LDAP users.
+ (Thanks sfrancis)
+- Minor fixes
+
+12/Sep/2005
+-----------
+
+- Added TLS authentification between Drupal and LDAP servers. (Thanks sfrancis)
+
+07/Sep/2005
+-----------
+
+- AD authentication fixes. (Thanks sfrancis)
+- PHP5 fixes
+
+20/Aug/2005
+-----------
+
+- (FIXED) "User View" page didn't show correctly field names
+
+19/Aug/2005
+-----------
+
+- (PATCHED) Bug #25067: Bad password or user returns blank screen
+- (PATCHED) Bug #28551: Authentication fails: Issues with global variable $con?
+- Minor changes in code
+
+01/Jun/2005
+-----------
+
+- Complete overhaul: module rewritten from scratch.
+- Search not yet included.
+- Active Directory not yet supported (not tested, at least).
+
+
+11/May/2005
+-----------
+
+- (FIXED) The callback replacement for user_login() not working properly.
+- Now it is possible to log in without having to use a login string of the
+ form user@server.
+- The module should _actually_ work now. It was time, wasn't it?
+
+
+6/Apr/2005
+----------
+
+- Settings page overhaul. Now it might even make some sense.
+- Now it's not necessary to allow anybody create accounts. (I figured
+ out a hack at last for this non-sensical hook_auth() problem).
diff --git a/security/drupal4-ldap_integration/ldap_integration/LICENSE.txt b/security/drupal4-ldap_integration/ldap_integration/LICENSE.txt
new file mode 100644
index 000000000000..64393a0cebcf
--- /dev/null
+++ b/security/drupal4-ldap_integration/ldap_integration/LICENSE.txt
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/security/drupal4-ldap_integration/ldap_integration/README.txt b/security/drupal4-ldap_integration/ldap_integration/README.txt
new file mode 100644
index 000000000000..b1be581cf44d
--- /dev/null
+++ b/security/drupal4-ldap_integration/ldap_integration/README.txt
@@ -0,0 +1,160 @@
+ldap_integration.module for Drupal 4.6
+--------------------------------------
+status: STABLE
+
+
+ - BRIEFING
+
+ This module allows users to authenticate against an admin-defined LDAP
+directory. Additionally, users can read and modify their LDAP entries, being
+the administrator able to limit it.
+
+
+ - INSTALLATION
+
+ Add the module files to the /modules/ directory of your Drupal
+installation. Those are:
+
+ * ldap_integration.module
+ * zcallbacks.module
+ * ldap_integration/conf.php
+ * ldap_integration/LDAPInterface.php
+
+ Activate BOTH *ldap_integration* and *zcallbacks* modules in Drupal's
+modules page (/admin/modules).
+
+
+ - SETUP
+
+ Prior to its use, administrators must set some variables in the preferences
+page, located at /admin/settings/ldap_integration.
+
+ -login string format
+
+ Drupal requires authentication from external sources to be in the form
+user@server, being 'external sources' any different from Drupal's own
+user database: LDAP directories, HTTP authentification, Jabber and, in
+general, any other authentification form provided by third-party modules.
+ Since this restriction can be annoying in some configurations (for example,
+those where all users log in from that same source and everyone of them has
+a login string on the form username@longname.foracommonserver.com), this
+module provides a way to circumvent it. Just unset the 'Logins must be
+on the form user@server' checkbox in the settings page.
+
+ -"pattern" and "replacement"
+
+ Parameters should be quite straightforward to set, except those called
+'LDAP login pattern' and 'LDAP login replacement' which refer to the way
+Drupal converts Drupal logins into LDAP logins, via regular expressions.
+Further explanation follows.
+
+ In Drupal, logins to external authentification sources (not Drupal's
+own database) must be in the form jdoe@foo.bar. This means that every login
+through this module must have that form.
+ On the other hand, logins to LDAP directories are in the form of a DN,
+i.e. something similar to: uid=jdoe,dc=foo,dc=bar .
+
+ So, the admin must set the way Drupal logins convert into LDAP logins. This
+os defined through the 'LDAP login pattern' and 'LDAP login replacement'
+parameters in preferences.
+
+ For help on defining these parameters, refer to the relevant entry on the
+PHP manual: http://www.php.net/manual/en/function.preg-replace.php
+
+ -directory-specific attributes
+
+ Besides, how Drupal should understand LDAP attributes is defined by
+'ldap_attributes' and 'ldap_drupal_mappings' global variables, found
+on the ldap_integration/conf.php file.
+ 'ldap_attributes' tells Drupal what kind of data is stored in each
+attribute, so it can present it with adequate names and forms in users'
+pages.
+ 'ldap_drupal_mappings' defines how Drupal's own user fields should be
+mapped to LDAP attributes, provided the 'Should Drupal account fields
+be mapped to LDAP attributes?' setting is properly set in the module
+configuration page.
+
+ -Drupal roles
+
+ Users can be granted Drupal roles automatically when logging in as
+LDAP users. These roles must already exist in Drupal's configuration and
+are checked anytime users log in from a LDAP source. However, once they
+have been granted, they can only be denied manually from Drupal's admin
+interface.
+ There are two ways of doing this: based in the users' DN and based in the
+values of one of their LDAP attributes.
+ In the former case, the setting uses a regular expression much in the
+same fashion as described above for mapping login names to DNs. A regular
+expression is defined for the DN and each one of its *parenthesized*
+sub-expressions is considered a role.
+ In the latter case, roles are just read from an attribute wich can be
+multivalued.
+
+ -"The Writer" and "The Reader" users
+
+ In order to perform some operations, such as providing of new passwords to
+those who forgot theirs, or enabling users to modify their LDAP entry, DN and
+password, two special users must be set in ldap_integration/conf.php.
+
+ If you don't care much about security, you can set both of them to be the
+administrator but, as I'm sure security is your priority #1, you should set
+them to accounts specially created for that matter.
+
+
+ - USE
+
+ The authentication facility needs no further configuration. For the LDAP
+user data reading and editing, the administrator can set what can be read and
+what can be modified by the user, by editing the relevant preferences.
+
+
+ - ISSUES
+
+ -new passwords generation
+
+ New passwords will only be generated if the users requesting it have
+logged in at least once before.
+
+ This is due to Drupal creating entries in its 'users' table for storing
+info about every user, including those authentified through modules. Drupal
+then looks the user up in the database whenever password generation is needed.
+
+ -security related:
+
+ As can be deduced from above, on the section about "The Writer" and "The
+Reader", the file ldap_integration/conf.php should not fall in the wrong
+hands.
+
+ -conflicts:
+
+ Due to the way I have had to hack this authentication through Drupal,
+there might be conflicts with other modules, specially, but I'd not venture
+to restrict to, with other auth modules.
+
+ If anyone experiences any conflict, please let me know so I can think
+of a possible solution.
+
+ -language
+
+ English is not the author's mother language. Corrections are not
+only welcome, but encouraged.
+
+
+ - CREDITS
+
+ Author:
+ - Pablo Brasero Moreno <pablobm at gmail (com)> (http://pablobm.com)
+ Sponsorship:
+ - VIZ Media (http://www.viz.com)
+ Based upon the original code by:
+ - Moshe Weitzman <weitzman at tejasa (com)>
+ Several patches
+ - Steve Francis (sfrancis @drupal.org)
+ - Douglas A. Galindo
+ - Klaus H. ("Perfect Stranger" @drupal.org)
+ Initial AD authentication code:
+ - allrite (http://allrite.net)
+ Invaluable testing by:
+ - Jose Luis Jimenez
+ - Francisco Javier Sanchez Zurdo
+ - And all those who gave me any feedback
diff --git a/security/drupal4-ldap_integration/ldap_integration/ldap_integration.module b/security/drupal4-ldap_integration/ldap_integration/ldap_integration.module
new file mode 100644
index 000000000000..1e1128a7b806
--- /dev/null
+++ b/security/drupal4-ldap_integration/ldap_integration/ldap_integration.module
@@ -0,0 +1,797 @@
+<?php
+// $Id: ldap_integration.module,v 1.2.2.4.2.15 2005-12-13 20:30:27 pablobm Exp $
+
+include_once('ldap_integration/conf.php');
+include_once('ldap_integration/LDAPInterface.php');
+
+/*
+ * Private constants. Do not touch
+ */
+define(LDAP_PERM_SEARCH, 'perform ldap searches');
+define(LDAP_SETTINGS_GROUP_STRING, 'LDAP attributes');
+define(LDAP_USER_DATA_EDIT_TAB, 'LDAP entry');
+define(LDAP_CATEGORY_USER_DATA, 'ldap_user_data');
+
+define(LDAP_STANDARD_SYSTEM, 0);
+define(LDAP_AD_SYSTEM, 1);
+
+define(LDAP_FIRST_DRUPAL, 0);
+define(LDAP_FIRST_LDAP, 1);
+
+define(LDAP_MAP_ATTRIBUTES, 0);
+define(LDAP_MAP_ONLY_LOST_PASSWORDS, 1);
+define(LDAP_MAP_NOTHING, 2);
+
+define(LDAP_GROUP_IN_DN, 'ldap_group_in_dn');
+define(LDAP_GROUP_IN_ATTR, 'ldap_group_in_attr');
+define(LDAP_GROUP_AS_ENTRIES, 'ldap_group_as_entries');
+
+/*
+ * Private constants (default values). Do not touch either
+ */
+define(LDAP_DEFAULT_ORG, 'Home');
+define(LDAP_DEFAULT_PATTERN, '/(\S+)@(\S+)\.(\S+)/i');
+define(LDAP_DEFAULT_REPLACEMENT, 'cn=$1,dc=$2,dc=$3');
+define(LDAP_DEFAULT_BASE_DN, 'ou=Users,dc=drupal,dc=org');
+define(LDAP_DEFAULT_GROUP_DN_PATTERN, '/cn=\S+,ou=(\S+),dc=\S+,dc=\S+/i');
+define(LDAP_DEFAULT_GROUP_ATTR, 'userGroups');
+define(LDAP_DEFAULT_GROUP_ENTRIES, 'cn=Group,dc=example,dc=com');
+define(LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE, 'memberUid');
+
+$GLOBALS['ldap'] = new LDAPInterface();
+$GLOBALS['ldap']->setServer(variable_get('ldap_server', 'localhost'));
+$GLOBALS['ldap']->setPort(variable_get('ldap_port', 389));
+$GLOBALS['ldap']->setOption('TLS', variable_get('ldap_use_TLS', false));
+
+
+/*********************************
+ * 1. Drupal hooks *
+ *********************************/
+
+function ldap_integration_help($section) {
+ $output = '';
+
+ switch ($section) {
+ case 'admin/modules#ldap_integration':
+ $output = 'ldap_integration';
+ break;
+ case 'admin/modules#description':
+ case 'admin/help#ldap_integration':
+ $output = t('Enables authentication via LDAP. <strong>IMPORTANT:</strong> module <em>zcallbacks</em> down below must be enabled for this one to work.');
+ break;
+ case 'user/help#ldap_integration':
+ $output = t('<p>If you are registered in %org LDAP directory, you\'ll probably be able to login this site by using your LDAP login and password</p>', array('%org' => variable_get('ldap_org_name', '')));
+ break;
+ }
+
+ return $output;
+}
+
+function ldap_integration_settings($section = 'server') {
+ // Reminding admins about conf.php
+ $output = '<p><strong style="color: red;">PLEASE NOTE</strong>: do not forget there are further and important settings to be set in the module\'s config file, located at <code>modules/ldap_integration/conf.php</code> in your Drupal install.</p>';
+
+ // Server settings
+ $output .= form_textfield(t('Organisation name'), 'ldap_org_name', variable_get('ldap_org_name', ''), 50, 255, t('Name of the organisation the LDAP directory belongs to.'));
+ $output .= form_textfield(t('LDAP server'), 'ldap_server', variable_get('ldap_server', 'localhost'), 50, 255, t('The domain name or IP address of your LDAP Server.'));
+ $output .= form_textfield(t('LDAP port'), 'ldap_port', variable_get('ldap_port', 389), 50, 255, t('The TCP/IP port on the above server which accepts LDAP connections. Must be an integer.'));
+ $output .= form_checkbox(t('Use TLS encryption'), 'ldap_use_TLS', 1, variable_get('ldap_use_TLS', 0), t('Secure the connection between the Drupal and the LDAP servers using TLS.'));
+ $output .= form_checkbox(t('Store passwords in encrypted form'), 'ldap_store_encrypted_pass', 1, variable_get('ldap_store_encrypted_pass', 0), t('Secure the password in LDAP by storing it MD5 encrypted (use with care, as some LDAP directories may do this automatically, what would cause logins problems).'));
+
+ return $output;
+}
+
+function ldap_integration_settings_login_procedure() {
+ system_settings_save();
+ $output = '<p>' . t('Here you can specify the details of the login procedure') . '</p>';
+
+ // Login string format
+ $output .= form_checkbox(t('Logins must be on the form <em>user@server</em>'), 'ldap_login_string_with_server', 1, variable_get('ldap_login_string_with_server', 1), t('Drupal requires login strings from external sources to be in the form <em>user@server</em>. Disabling this setting will circumvent such limitation.'));
+
+ // Login process
+ $options_login_process = array(
+ LDAP_FIRST_DRUPAL => t('Drupal\'s own database. If it fails, will look on the LDAP directory'),
+ LDAP_FIRST_LDAP => t('LDAP directory only'));
+
+ $output .= form_radios(t('When logging in, Drupal will look up for the user on'), 'ldap_login_process', variable_get('ldap_login_process', LDAP_FIRST_DRUPAL), $options_login_process, NULL, true);
+
+ $options_attribute_mapping = array(
+ LDAP_MAP_ATTRIBUTES => t('Changes in account fields will be mapped to LDAP attributes and back (see <code>modules/ldap_integration/conf.php</code>).'),
+ LDAP_MAP_ONLY_LOST_PASSWORDS => t('No attribute mapping will be done, except for lost passwords. They will be randomly re-generated and sent to the user\'s mailbox.'),
+ LDAP_MAP_NOTHING => t('No attribute mapping will be done at all'));
+
+ $output .= form_radios(t('Should Drupal account fields be mapped to LDAP attributes?'), 'ldap_attr_mapping', variable_get('ldap_attr_mapping', LDAP_MAP_NOTHING), $options_attribute_mapping, NULL, true);
+
+ // System type and user mapping
+ $option_system_type_1 = form_textfield(t('LDAP login pattern'), 'ldap_login_pattern', variable_get('ldap_login_pattern', LDAP_DEFAULT_PATTERN), 50, 255, t('Regular expression matching logins for this module, that will be in the form of an e-mail address. <em>Example: %s </em>.', array('%s' => LDAP_DEFAULT_PATTERN)));
+ $option_system_type_1 .= form_textfield(t('LDAP login replacement'), 'ldap_login_replacement', variable_get('ldap_login_replacement', LDAP_DEFAULT_REPLACEMENT), 50, 255, t('Replacement to convert the above regular expression into the user\'s LDAP DN. <em>Example: %s</em>.', array('%s' => LDAP_DEFAULT_REPLACEMENT)));
+
+ $option_system_type_2 = form_textarea(t('Base DNs'), 'ldap_base_dn', variable_get('ldap_base_dn', LDAP_DEFAULT_BASE_DN), 50, 6, t('Base DN for users, to be used in eDirectory or Active Directory logins'));
+ $option_system_type_2 .= form_textfield(t('UserName attribute'), 'ldap_user_attribute', variable_get('ldap_user_attribute', 'sAMAccountName'), 50, 255, t('The attribute that holds the Users Loginname. (eg. <em>cn</em> for eDir or <em>sAMAccountName</em> for AD)'));
+
+ $options_system_type = array(
+ LDAP_STANDARD_SYSTEM => array('choice' => t('Standard LDAP system'), 'extended' => $option_system_type_1),
+ LDAP_AD_SYSTEM => array('choice' => t('eDirectory or Active Directory system'), 'extended' => $option_system_type_2));
+
+ $output .= form_complex_radios(t('System type and user mapping'), 'ldap_system_type', variable_get('ldap_system_type', LDAP_STANDARD_SYSTEM), $options_system_type, NULL, true);
+
+ print(theme('page', system_settings_form($output)));
+}
+
+function ldap_integration_settings_groups() {
+ system_settings_save();
+ $output = '<p>' . t('You may want your users to attain Drupal roles according to their LDAP groups. If that is the case, this is the place to tell the module how.') . '</p>';
+
+ // LDAP groups <-> Drupal roles
+ $option_grouproles_1 = form_textfield(t('Regular expression representing the pattern'), 'ldap_group_dn_pattern', variable_get('ldap_group_dn_pattern', LDAP_DEFAULT_GROUP_DN_PATTERN), 50, 255, t('Regular expression matching users\' DNs. Each <strong>parenthesized</strong> subexpression points out a group name. <em>Example: ' . LDAP_DEFAULT_GROUP_DN_PATTERN . '. In this example, \'ou=\' is followed by a group name that Drupal will associate to a role name</em>.'));
+ $option_grouproles_2 = form_textarea(t('Attribute names (one per line)'), 'ldap_group_attr', variable_get('ldap_group_attr', LDAP_DEFAULT_GROUP_ATTR), 50, 6, t('Name of the LDAP attributes containing the group names for each user.'));
+
+ $option_grouproles_3 = form_textarea(t('Entries containing groups (one per line)'), 'ldap_group_entries', variable_get('ldap_group_entries', LDAP_DEFAULT_GROUP_ENTRIES), 50, 6, t('Name of the LDAP entries representing user groups.'));
+ $option_grouproles_3 .= form_textfield(t('Attribute holding group members'), 'ldap_group_entries_attribute', variable_get('ldap_group_entries_attribute', LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE), 50, 255, t('Name of the multivalued attribute which holds the CNs of group members, for example: <em>' . LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE . '</em>.'));
+
+ $options_grouproles = array(
+ LDAP_GROUP_IN_DN => array('choice' => t('Group is specified in user\'s DN'), 'extended' => $option_grouproles_1),
+ LDAP_GROUP_IN_ATTR => array('choice' => t('Groups are specified by LDAP attributes'), 'extended' => $option_grouproles_2),
+ LDAP_GROUP_AS_ENTRIES => array('choice' => t('Groups exist as LDAP entries where a multivalued attribute contains the members\' CNs'), 'extended' => $option_grouproles_3));
+
+ $output .= form_complex_checkboxes(t('Should LDAP groups be reflected as Drupal roles?'), 'ldap_group_roles', variable_get('ldap_group_roles', array()), $options_grouproles);
+ $output .= form_checkbox(t('Map group sign offs'), 'ldap_map_group_signoffs', true, variable_get('ldap_map_group_signoffs', true), t('If you enable this, users signed off LDAP groups will be denied the respective Drupal roles, according to the rules set on <code>modules/ldap_integration/conf.php</code>.'));
+
+ print(theme('page', system_settings_form($output)));
+}
+
+function ldap_integration_settings_attributes() {
+ system_settings_save();
+ // LDAP attributes viewing/editing
+ global $ldap_attributes;
+
+ // Explanatory text
+ $output = '<p>' . t('Users may be able to view their LDAP attributes\' values, as well as edit them. You can configure this feature here.') . '</p>';
+
+ foreach ($ldap_attributes as $key => $field) {
+ $fields[$key] = $field[2];
+ }
+
+ // These two hidden forms are a workaround for a bug I seem to have found
+ // in Drupal, for I can't make the following two form_select() to work when
+ // no elements are selected.
+ $output .= form_hidden('ldap_user_attributes', null);
+ $output .= form_hidden('ldap_useredit_attributes', null);
+
+ $output .= form_select(t('Attributes displayed on user pages'), 'ldap_user_attributes', variable_get('ldap_user_attributes', array()), $fields, t('Select the attributes which will be displayed on user pages. Blank attributes will be omitted. You may add attributes to this list by editing the relevant global variable at the beginning of the module\'s code'), 'size="6"', true, false);
+ $output .= form_select(t('Attributes that can be edited by users'), 'ldap_useredit_attributes', variable_get('ldap_useredit_attributes', array()), $fields, t('Select the attributes users will be able to edit on their user pages. Blank attributes will be omitted. You may add attributes to this list by editing the relevant global variable at the beginning of the module\'s code'), 'size="6"', true, false);
+
+ print(theme('page', system_settings_form($output)));
+}
+
+function ldap_integration_auth($name, $pass, $server) {
+ global $ldap;
+
+ $ret = false;
+
+ if(variable_get('ldap_system_type', LDAP_STANDARD_SYSTEM) == LDAP_STANDARD_SYSTEM) {
+ $dn = _ldap_integration_login2dn($server ? "$name@$server" : $name);
+ $ret = $ldap->connect($dn, $pass);
+ }
+ else {
+ $possible_base_dns = explode("\r\n", variable_get('ldap_base_dn', ''));
+ foreach ($possible_base_dns as $base_dn) {
+ if($base_dn && $ret = $ldap->connect_ADstyle(variable_get('ldap_user_attribute', ''), $name, $base_dn, $pass)) {
+ break;
+ }
+ }
+ }
+
+ return $ret;
+}
+
+function ldap_integration_menu($may_cache) {
+ $items = array();
+
+ if ($may_cache) {
+ $items[] = array(
+ 'path' => 'admin/settings/ldap_integration/server',
+ 'title' => t('LDAP server settings'),
+ 'callback' => 'system_site_settings',
+ 'callback_arguments' => array('ldap_integration'),
+ 'weight' => 0,
+ 'type' => MENU_DEFAULT_LOCAL_TASK);
+ $items[] = array(
+ 'path' => 'admin/settings/ldap_integration/login_procedure',
+ 'title' => t('Login procedure'),
+ 'callback' => 'ldap_integration_settings_login_procedure',
+ 'weight' => 1,
+ 'type' => MENU_LOCAL_TASK);
+ $items[] = array(
+ 'path' => 'admin/settings/ldap_integration/groups',
+ 'title' => t('Groups and roles'),
+ 'callback' => 'ldap_integration_settings_groups',
+ 'weight' => 2,
+ 'type' => MENU_LOCAL_TASK);
+ $items[] = array(
+ 'path' => 'admin/settings/ldap_integration/attributes',
+ 'title' => t('LDAP attributes'),
+ 'callback' => 'ldap_integration_settings_attributes',
+ 'weight' => 3,
+ 'type' => MENU_LOCAL_TASK);
+ }
+ return $items;
+}
+
+function ldap_integration_user($op, &$edit, &$user, $category = NULL) {
+//msg("$op (uid: $user->uid; cat: $category)");
+ switch($op) {
+ case 'categories':
+ return ldap_integration_user_categories();
+ case 'form':
+ return ldap_integration_user_form($user, $category);
+ case 'load':
+ ldap_integration_user_load($user);
+ break;
+ case 'login':
+ ldap_integration_user_login($user);
+ break;
+ case 'update':
+ ldap_integration_user_update($edit, $user, $category);
+ break;
+ case 'view':
+ return ldap_integration_user_view($user);
+ }
+}
+
+
+/*********************************
+ * 2. Delegate functions *
+ *********************************/
+
+function ldap_integration_user_categories() {
+ global $user;
+
+ $ret = null;
+
+ if ($user->ldap_authentified && variable_get('ldap_useredit_attributes', array())) {
+ $ret = array(array('name' => LDAP_CATEGORY_USER_DATA, 'title' => t(LDAP_USER_DATA_EDIT_TAB), 'weight' => 10));
+ }
+
+ return $ret;
+}
+
+function ldap_integration_user_form($user, $category) {
+ global $ldap_attributes, $ldap;
+
+ if (!$user->ldap_authentified || $category != LDAP_CATEGORY_USER_DATA || ! $attributes = variable_get('ldap_useredit_attributes', array())) {
+ return;
+ }
+
+ $ldap->disconnect();
+ if (!$ldap->connect(LDAP_READER_USER_DN, LDAP_READER_USER_PASS)) {
+ watchdog('user', "User load: user $user->name's data could not be read in the LDAP directory");
+ return;
+ }
+
+ $entry = $ldap->retrieveAttributes($user->ldap_dn);
+
+ $output = '';
+ foreach($attributes as $attribute) {
+ $attr_info = $ldap_attributes[$attribute];
+ if ($attr_info) {
+ array_shift($attr_info);
+ $value = $entry[strtolower($attribute)][0];
+ $output .= _ldap_integration_attribute_form($attribute, $value, $attr_info);
+ }
+ }
+ $element = array(
+ 'title' => t(LDAP_SETTINGS_GROUP_STRING),
+ 'data' => $output,
+ 'weight' => 0);
+ $ret = array($element);
+
+ $ldap->disconnect();
+
+ return $ret;
+}
+
+function ldap_integration_user_load(&$user) {
+ global $ldap, $ldap_drupal_mappings;
+
+ if (!$user->ldap_authentified || !variable_get('ldap_attr_mapping', LDAP_MAP_ATTRIBUTES) == LDAP_MAP_ATTRIBUTES) {
+ return;
+ }
+
+ if (!$ldap->connect(LDAP_READER_USER_DN, LDAP_READER_USER_PASS)) {
+ watchdog('user', "User load: user $user->name's data could not be read in the LDAP directory");
+ return;
+ }
+
+ $newuser = $user;
+ foreach ($ldap_drupal_mappings as $ldap_attr => $drupal_field) {
+ if ($drupal_field != 'pass') {
+ $newuser->$drupal_field = $ldap->retrieveAttribute($user->ldap_dn, $ldap_attr);
+ } else {
+ $cleartext_pass = $ldap->retrieveAttribute($user->ldap_dn, $ldap_attr);
+ }
+ }
+
+ if ($newuser != $user) {
+ $newuser->pass = $cleartext_pass; // Drupal will do the md5 hash
+ $user = user_save($user, get_object_vars($newuser));
+ }
+
+ $ldap->disconnect();
+}
+
+function ldap_integration_user_login(&$user) {
+ global $ldap, $ldap_group_role_mappings;
+
+ // Mapping LDAP groups to Drupal roles
+ if (!$user->ldap_authentified || !variable_get('ldap_group_roles', 0)) {
+ return;
+ }
+
+ if (!$ldap->connect(LDAP_READER_USER_DN, LDAP_READER_USER_PASS)) {
+ watchdog('user', "User login: user $user->name's data could not be read in the LDAP directory");
+ return;
+ }
+
+ if (variable_get('ldap_map_group_signoffs', false)) {
+ // First, we take every mapped role from the user, later below
+ // we'll grant back those deserved.
+ foreach ($ldap_group_role_mappings as $role) {
+ _ldap_integration_take_role_from_user($user, $role);
+//msg("_ldap_integration_take_role_from_user($user, $role);");
+ }
+ }
+
+ $where_groups_are = variable_get('ldap_group_roles', array());
+ $groups_in_attr = (array_search('ldap_group_in_attr', $where_groups_are) !== FALSE);
+ $groups_in_dn = (array_search('ldap_group_in_dn', $where_groups_are) !== FALSE);
+ $groups_as_entries = (array_search('ldap_group_as_entries', $where_groups_are) !== FALSE);
+
+ $dn_groups = array();
+ if ($groups_in_dn && $dn_groups_regexp = variable_get('ldap_group_dn_pattern', '')) {
+ preg_match($dn_groups_regexp, $user->ldap_dn, $matches);
+ $dn_groups = array_slice($matches, 1);
+ }
+
+ $attrib_groups = array();
+ if ($groups_in_attr && $attributes = variable_get('ldap_group_attr', '')) {
+ $attributes_array = explode("\r\n", $attributes);
+ foreach ($attributes_array as $attribute) {
+ $tmp = $ldap->retrieveMultiAttribute($user->ldap_dn, $attribute);
+ $attrib_groups = array_merge($attrib_groups, $tmp);
+ }
+ }
+
+ $entries_groups = array();
+ if ($groups_as_entries && $entries = variable_get('ldap_group_entries', '')) {
+ $entries_array = explode("\r\n", $entries);
+ foreach ($entries_array as $entry) {
+ $tmp = $ldap->retrieveMultiAttribute($entry, variable_get('ldap_group_entries_attribute', LDAP_DEFAULT_GROUP_ENTRIES_ATTRIBUTE));
+ if (in_array($user->name, $tmp)) {
+ $entries_groups[] = $entry;
+ }
+ }
+ }
+
+ $groups = array_merge($dn_groups, $attrib_groups, $entries_groups);
+
+ foreach ($groups as $key => $group) {
+ if ($role = $ldap_group_role_mappings[$group]) {
+ _ldap_integration_create_role($role);
+ _ldap_integration_give_role_to_user($user, $role);
+//msg("_ldap_integration_give_role_to_user($user, $role);");
+ }
+ }
+
+ $ldap->disconnect();
+}
+
+function ldap_integration_user_update(&$edit, $user, $category) {
+ global $ldap;
+
+ if (!$user->ldap_authentified) {
+ return;
+ }
+
+ // Three cases here:
+ // 1. User logged on and editing his LDAP entry attributes ($category == LDAP_CATEGORY_USER_DATA).
+ // 2. User logged on and editing his Drupal account settings ($category == 'account').
+ // 3. Password lost and being updated (category == 'account').
+
+ // So, case 1
+ if ($category == LDAP_CATEGORY_USER_DATA && variable_get('ldap_useredit_attributes', array())) {
+ ldap_integration_user_update_ldap_attributes($edit, $user);
+ }
+ // Cases 2 && 3
+ else if ($category == 'account') {
+ ldap_integration_user_update_drupal_account($edit, $user);
+ }
+}
+
+function ldap_integration_user_update_ldap_attributes(&$edit, $user) {
+ global $ldap;
+
+ $ldap->disconnect();
+ if(!$ldap->connect(LDAP_WRITER_USER_DN, LDAP_WRITER_USER_PASS)) {
+ watchdog('user', "User update: user $user->name's data could not be updated in the LDAP directory");
+ return;
+ }
+
+ $writeout = array();
+ $editables = variable_get('ldap_useredit_attributes', array());
+
+ foreach ($edit as $edit_attr => $edit_val) {
+ // Preventing a POST data injection: we check allowance to write value.
+ if (array_search($edit_attr, $editables) !== FALSE) {
+ $writeout[$edit_attr] = $edit_val;
+ $edit[$edit_attr] = null;
+ }
+ }
+
+ if ($writeout) {
+ $ldap->writeAttributes($user->ldap_dn, $writeout);
+ }
+
+ $ldap->disconnect();
+}
+
+function ldap_integration_user_update_drupal_account(&$edit, $user) {
+ global $ldap, $ldap_drupal_mappings;
+
+ $ldap->disconnect();
+ if(!$ldap->connect(LDAP_WRITER_USER_DN, LDAP_WRITER_USER_PASS)) {
+ watchdog('user', "User update: user $user->name's data could not be updated in the LDAP directory");
+ return;
+ }
+
+ $password_updated_in_ldap =
+ variable_get('ldap_attr_mapping', LDAP_MAP_NOTHING) == LDAP_MAP_ONLY_LOST_PASSWORDS
+ || variable_get('ldap_attr_mapping', LDAP_MAP_NOTHING) == LDAP_MAP_ATTRIBUTES;
+
+ $account_updated_in_ldap = (variable_get('ldap_attr_mapping', LDAP_MAP_NOTHING) == LDAP_MAP_ATTRIBUTES);
+
+ if ($edit['pass'] && sizeof($edit) == 1 && $password_updated_in_ldap) {
+ // Case 3: password lost and new one generated randomly => update LDAP password
+ $drupal2ldap_mappings = array_flip($ldap_drupal_mappings);
+ $pass_ldap_attribute = $drupal2ldap_mappings['pass'];
+ $pw = variable_get('ldap_store_encrypted_pass', false) ? '{md5}' . base64_encode(pack('H*', md5($edit['pass']))) : $edit['pass'];
+ $ldap->writeAttributes($user->ldap_dn, array($pass_ldap_attribute => $pw));
+ }
+ else if ($edit['pass'] && sizeof($edit) == 1 && !$password_updated_in_ldap) {
+ // Same, but NOT having permission to update passwords
+ drupal_set_message('Lost passwords recovery has been disabled for LDAP users. Please contact your system administrator in order to get a new password.');
+ // Nulling out this field should suffice for Drupal not to try
+ // to regenerate the password, but it doesn't, so I add a drupal_goto()
+ $edit['pass'] = null;
+ drupal_goto('user/login');
+ }
+ else if ($user->ldap_authentified && $account_updated_in_ldap) {
+ // Case 2: updating account data
+ $drupal2ldap_mappings = array_flip($ldap_drupal_mappings);
+ $writeout = array();
+ foreach ($edit as $key => $value) {
+ $ldap_attr = $drupal2ldap_mappings[$key];
+ // $writeout[$ldap_attr] = $value;
+ if ($ldap_attr) {
+ if ($key == 'pass') {
+ $pw = variable_get('ldap_store_encrypted_pass', false) ? '{md5}' . base64_encode(pack('H*', md5($value))) : $value;
+ $writeout[$ldap_attr] = $pw;
+ } else {
+ $writeout[$ldap_attr] = $value;
+ }
+ }
+ }
+ $ldap->writeAttributes($user->ldap_dn, $writeout);
+ }
+
+ $ldap->disconnect();
+}
+
+function ldap_integration_user_view($user) {
+ global $ldap;
+
+ if (!$user->ldap_authentified) {
+ return;
+ }
+
+ $ldap->disconnect();
+ if (!$ldap->connect(LDAP_READER_USER_DN, LDAP_READER_USER_PASS)) {
+ watchdog('user', "User load: user $user->name's data could not be read in the LDAP directory");
+ return;
+ }
+
+ $entry = $ldap->retrieveAttributes($user->ldap_dn);
+
+ $ret = array();
+ $allowed_attrs = variable_get('ldap_user_attributes', array()) ? variable_get('ldap_user_attributes', array()) : array();
+
+ foreach($allowed_attrs as $attribute) {
+ $shown_attrs[$attribute] = $entry[strtolower($attribute)][0];
+ }
+
+ $ret[LDAP_SETTINGS_GROUP_STRING] = theme('ldap_integration_ldap_entry', $shown_attrs);
+
+ // Disconnecting just in case, for the sake of security
+ $ldap->disconnect();
+
+ return $ret;
+}
+
+
+/*********************************
+ * 3. Auxiliary functions *
+ *********************************/
+
+// Patched (2005-09-06) by sfrancis@drupal.org
+function _ldap_integration_login2dn($login) {
+ global $ldap;
+
+ if(variable_get('ldap_system_type', LDAP_STANDARD_SYSTEM) == LDAP_STANDARD_SYSTEM) {
+ $string = $login;
+ $pattern = variable_get('ldap_login_pattern', LDAP_DEFAULT_PATTERN);
+ $replacement = variable_get('ldap_login_replacement', LDAP_DEFAULT_REPLACEMENT);
+ $ret = preg_replace($pattern, $replacement, $string);
+ } else {
+ $possible_base_dns = explode("\r\n", variable_get('ldap_base_dn',''));
+ foreach ($possible_base_dns as $dn) {
+ if ($ret = $ldap->name_to_dn_AD(variable_get('ldap_user_attribute', ''), $login, $dn)) {
+ break;
+ }
+ }
+ //$ret = $ldap->name_to_dn_AD(variable_get('ldap_user_attribute', ''), $login, variable_get('ldap_base_dn',''));
+//msg_r($ret);
+ }
+
+ return $ret;
+}
+
+function _ldap_integration_attribute_form($attrname, $value, $info) {
+ $type = array_shift($info);
+
+ switch($type) {
+ case 'textfield':
+ $output = form_textfield(array_shift($info), $attrname, $value, array_shift($info), array_shift($info), array_shift($info), array_shift($info), array_shift($info));
+ break;
+ case 'password':
+ $output = form_password(array_shift($info), $attrname, $value, array_shift($info), array_shift($info), array_shift($info), array_shift($info), array_shift($info));
+ break;
+ }
+
+ return $output;
+}
+
+function _ldap_integration_give_role_to_user($user, $rolename) {
+ $result = db_query("SELECT * FROM {role} WHERE name = '$rolename'");
+ $role_exists = db_num_rows($result);
+
+ if ($role_exists) {
+ $role = db_fetch_object($result);
+ $result = db_query("SELECT * FROM {users_roles} WHERE uid = $user->uid AND rid = $role->rid");
+ $role_already_given = db_num_rows($result);
+ if (!$role_already_given) {
+ db_query("INSERT {users_roles} SET uid = $user->uid, rid = $role->rid");
+ }
+ }
+}
+
+function _ldap_integration_take_role_from_user($user, $rolename) {
+ $result = db_query("SELECT * FROM {role} WHERE name = '$rolename'");
+ $role_exists = db_num_rows($result);
+
+ if ($role_exists) {
+ $role = db_fetch_object($result);
+ $result = db_query("SELECT * FROM {users_roles} WHERE uid = $user->uid AND rid = $role->rid");
+ $role_present = db_num_rows($result);
+ if ($role_present) {
+ db_query("DELETE FROM {users_roles} WHERE uid = $user->uid AND rid = $role->rid");
+ }
+ }
+}
+
+function _ldap_integration_create_role($rolename) {
+ $result = db_query("SELECT * FROM {role} WHERE name = '$rolename'");
+ $role_exists = db_num_rows($result);
+
+ if (!$role_exists) {
+ db_query("INSERT {role} SET name = '$rolename'");
+ }
+}
+
+
+
+/*********************************
+ * 4. user.module faking stuff *
+ *********************************/
+
+function _ldap_integration_fake_user_login($edit = array(), $msg = '') {
+ global $user, $base_url;
+
+ // If we are already logged on, go to the user page instead.
+ if ($user->uid) {
+ drupal_goto('user');
+ }
+
+ if (user_deny('user', $edit['name'])) {
+ $error = t('The name %s has been denied access.', array('%s' => theme('placeholder', $edit['name'])));
+ }
+ else if ($edit['name'] && $edit['pass']) {
+
+ // === HACK STARTS ===
+ // --- New code starts
+ $user = _ldap_integration_code_added_user_login($edit['name'], $edit['pass']);
+ // --- New code ends
+
+ // --- Drupal's original code starts
+ //if (!$user->uid) {
+ // $user = user_authenticate($edit['name'], $edit['pass']);
+ //}
+ // --- Drupal's original code ends
+ // === HACK ENDS ===
+
+ if ($user->uid) {
+ watchdog('user', t('Session opened for %name.', array('%name' => theme('placeholder', $user->name))));
+
+ // Update the user table timestamp noting user has logged in.
+ db_query("UPDATE {users} SET changed = '%d' WHERE uid = '%s'", time(), $user->uid);
+
+ user_module_invoke('login', $edit, $user);
+
+ // Redirect the user to the page he logged on from.
+ drupal_goto();
+ }
+ else {
+ if (!$error) {
+ $error = t('Sorry. Unrecognized username or password.') .' '. l(t('Have you forgotten your password?'), 'user/password');
+ }
+ watchdog('user', t('Login attempt failed for %user: %error.', array('%user' => theme('placeholder', $edit['name']), '%error' => theme('placeholder', $error))));
+ }
+ }
+
+ // Display error message (if any):
+ if ($error) {
+ drupal_set_message($error, 'error');
+ }
+
+ // Display login form:
+ if ($msg) {
+ $output .= "<p>$msg</p>";
+ }
+ if (count(user_auth_help_links()) > 0) {
+ $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Enter your %s username, or an ID from one of our affiliates: %a.', array('%s' => variable_get('site_name', 'local'), '%a' => implode(', ', user_auth_help_links()))));
+ }
+ else {
+ $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Enter your %s username.', array('%s' => variable_get('site_name', 'local'))));
+ }
+ $output .= form_password(t('Password'), 'pass', $pass, 30, 64, t('Enter the password that accompanies your username.'));
+ $output .= form_submit(t('Log in'));
+
+ return form($output, 'post', url('user/login', drupal_get_destination()));
+}
+
+function _ldap_integration_code_added_user_login($name, $pass) {
+ $user = null;
+
+ if (_ldap_integration_is_ldap_login_only($name) == false) {
+ // Authenticate locally only if not initially authenticated by LDAP, or if configured to do so
+ $user = user_authenticate($name, $pass);
+ }
+
+ // If not succesful, try LDAP authentication directly
+ if (!$user->uid) {
+ $user = _ldap_integration_ldap_login($name, $pass);
+ }
+
+ return $user;
+}
+
+function _ldap_integration_is_ldap_login_only($name) {
+ return variable_get('ldap_login_process', LDAP_FIRST_LDAP) && db_num_rows(db_query("SELECT name FROM {users} WHERE locate('ldap_authentified',data) AND name='%s'",$name));
+}
+
+function _ldap_integration_ldap_login($login_string, $pass) {
+ global $ldap;
+
+ $user = null;
+
+ // Strip name and server from ID:
+ if ($server = strrchr($login_string, '@')) {
+ $name = substr($login_string, 0, strlen($login_string) - strlen($server));
+ $at = '@';
+ $server = substr($server, 1);
+ }
+ else {
+ $name = $login_string;
+ $at = '';
+ $server = '';
+ }
+
+ if (ldap_integration_auth($name, $pass, $server)) {
+ $user = user_load(array('name' => "$name$at$server"));
+ $tmp_user->name = "$name$at$server";
+ if (!$user->uid) { // Register this new user.
+ // Changes to this user_save():
+ // 1. 'pass' => $pass . Obviously. What I wonder is how it could
+ // be otherwise. Really.
+ // 2. 'mail' => value of LDAP_EMAIL_ATTRIBUTE in the LDAP directory
+ // 3. 'init' => same. BTW: what's the use of this field?
+ // 4. 'ldap_authentified' => TRUE . There is a need to mark
+ // people as externally authentified.
+ $dn = _ldap_integration_login2dn("$name$at$server");
+ $mail = $ldap->retrieveAttribute($dn, LDAP_EMAIL_ATTRIBUTE);
+ $user = user_save('', array('name' => "$name$at$server", 'pass' => $pass, 'mail' => $mail, 'init' => $mail, 'status' => 1, "authname_ldap_integration" => "$name$at$server", 'roles' => array(_user_authenticated_id()), 'ldap_authentified' => TRUE, 'ldap_dn' => $dn));
+ watchdog('user', t('New external user: %user using module %module.', array('%user' => theme('placeholder', $name .'@'. $server), '%module' => theme('placeholder', $module))), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $user->uid .'/edit'));
+ }
+ }
+
+ return $user;
+}
+
+
+/*********************************
+ * 5. Forms *
+ *********************************/
+
+function form_complex_radios($title, $name, $value, $options, $description = NULL, $required = FALSE, $attributes = NULL) {
+ if (count($options) > 0) {
+ $choices = '<dl>';
+ foreach ($options as $key => $choice) {
+ $choices .= '<dt><label class="option"><input type="radio" class="form-radio" name="edit['. $name .']" value="'. $key .'"'. ($key == $value ? ' checked="checked"' : ''). drupal_attributes($attributes). ' /> '. $choice['choice'] .'</label></dt>';
+ $choices .= '<dd style="border-left: 5px solid #DDDDDD; padding-left: 1em; margin-left: 1em;">' . $choice['extended'] . '</dd>';
+ }
+ $choices .= '</dl>';
+ return theme('form_element', $title, $choices, $description, NULL, $required, _form_get_error($name));
+ }
+}
+
+function form_complex_checkboxes($title, $name, $values, $options, $description = NULL, $attributes = FALSE, $required = NULL) {
+ if (count($options) > 0) {
+ $choices = '<dl>';
+ foreach ($options as $key => $choice) {
+ $choices .= '<dt><label class="option"><input type="checkbox" class="form-checkbox" name="edit['. $name .'][]" value="'. $key .'"'. ($values && in_array($key, $values) ? ' checked="checked"' : ''). drupal_attributes($attributes) .' /> '. $choice['choice'] .'</label></dt>';
+ $choices .= '<dd style="border-left: 5px solid #DDDDDD; padding-left: 1em; margin-left: 1em;">' . $choice['extended'] . '</dd>';
+ }
+ $choices .= '</dl>';
+ // Note: because unchecked boxes are not included in the POST data, we
+ // include a form_hidden() which will be overwritten as soon as there is at
+ // least one checked box.
+ return form_hidden($name, 0) . theme('form_element', $title, $choices, $description, NULL, $required, _form_get_error($name));
+ }
+}
+
+
+/*********************************
+ * 6. Themes *
+ *********************************/
+
+function theme_ldap_integration_ldap_entry($attributes) {
+ global $ldap_attributes;
+
+ $attributes = $attributes ? $attributes : array();
+ $output = "<dl>\n";
+ foreach($attributes as $attribute => $value) {
+ $attribute_title = $ldap_attributes[$attribute][2];
+ $output .= "<dt>$attribute_title</dt><dd>$value</dd>\n";
+ }
+ $output .= "</dl>\n";
+
+ return $output;
+}
+
+/*********************************
+ * 7. Debug utils *
+ *********************************/
+
+function msg($string) {
+ drupal_set_message("<pre style=\"border: 0; margin: 0; padding: 0;\">$string</pre>");
+}
+
+function msg_r($object) {
+ ob_start();
+ print_r($object);
+ $output = ob_get_contents();
+ ob_end_clean();
+ msg($output);
+}
+
+?>
+
diff --git a/security/drupal4-ldap_integration/ldap_integration/ldap_integration/LDAPInterface.php b/security/drupal4-ldap_integration/ldap_integration/ldap_integration/LDAPInterface.php
new file mode 100644
index 000000000000..cbb4472ced24
--- /dev/null
+++ b/security/drupal4-ldap_integration/ldap_integration/ldap_integration/LDAPInterface.php
@@ -0,0 +1,204 @@
+<?php
+// $Id: LDAPInterface.php,v 1.1.4.8 2005/11/03 20:15:32 pablobm Exp $
+
+class LDAPInterface {
+
+ function LDAPInterface() {
+ $this->connection = null;
+ $this->server = localhost;
+ $this->port = 389;
+ $this->secretKey = NULL;
+ $this->useTLS = false;
+ }
+
+ var $connection;
+ var $server;
+ var $port;
+ var $useTLS;
+
+ // Setters & getters
+ function setServer($server) { $this->server = $server; }
+ function getServer() { return $this->server; }
+ function setPort($port) { $this->port = $port; }
+ function getPort() { return $this->port; }
+
+ function setOption($option, $value) {
+ if ($option == 'TLS') {
+ $this->useTLS = $value;
+ }
+ }
+
+ function getOption($option) {
+ $ret = -1;
+
+ if ($option == 'version') {
+ ldap_get_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $ret);
+ }
+
+ return $ret;
+ }
+
+ function connect($dn = '', $pass = '') {
+ $ret = FALSE;
+
+ // If a connection already exists, it should be terminated
+ $this->disconnect();
+
+ if ($this->connectAndBind($dn, $pass)) {
+ $ret = TRUE;
+ }
+
+ return $ret;
+ }
+
+ // Code contributed by allrite@drupal.org (http://allrite.net)
+ // Patched (2005-09-06) by sfrancis@drupal.org
+ // Patched (2005-10-29) by Perfect Stranger (@drupal.org)
+ function connect_ADstyle($uattr = '', $name = '', $base_dn = '', $pass = '') {
+ global $ldap;
+
+ // If a connection already exists, it should be terminated
+ $this->disconnect();
+ $this->establishConnection();
+
+ ob_start();
+ $anon_bind = @ldap_bind($this->connection, LDAP_READER_USER_DN, LDAP_READER_USER_PASS);
+
+ // Bind anonymously
+ $res = false;
+ $dn = $uattr . '=' . $name;
+ //srf
+ global $ldap;
+ //srf - the base dn is already passed as an argument to this function $anon_res = @ldap_search($this->connection, variable_get('ldap_base_dn', ''), $dn);
+ $anon_res = @ldap_search($this->connection, $base_dn, $dn);
+ //srf
+ if ($anon_res) {
+ if (ldap_count_entries($this->connection, $anon_res) !=1) {
+ watchdog('user',"Error: Zero or more than 1 user found with $dn");
+ return false;
+ }
+ //srf
+
+ $users = @ldap_get_entries($this->connection, $anon_res);
+
+ $this->disconnect();
+ $this->establishConnection();
+
+ $user_dn = $users[0]["dn"];
+ $res = @ldap_bind($this->connection, $user_dn, $pass);
+ }
+ else {
+ $this->disconnect();
+ }
+ ob_end_clean();
+
+ return $res;
+ }
+
+ // Code contributed by sfrancis@drupal.org
+ function name_to_dn_AD($uattr = '', $name = '', $base_dn = '') {
+ global $ldap;
+
+ $dn = $uattr . '=' . $name;
+ $res = @ldap_search($this->connection, $base_dn, $dn);
+ if ($res) {
+ if (ldap_count_entries($this->connection, $res) !=1) {
+ watchdog('user',"Error: Zero or more than 1 user found with $base_dn");
+ return false;
+ }
+ $users = @ldap_get_entries($this->connection, $res);
+ $user_dn = $users[0]["dn"];
+ }
+
+ return $user_dn;
+ }
+
+ function establishConnection() {
+ if (!$con = ldap_connect($this->server, $this->port)) {
+ watchdog('user', 'LDAP Connect failure to ' . $this->server . ':' . $this->port);
+ return NULL;
+ }
+ $this->connection = $con;
+ ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
+ // TLS encryption contributed by sfrancis@drupal.org
+ if ($this->useTLS) {
+ $vers = $this->getOption('version');
+ if ($vers == -1) {
+ watchdog('user', 'Could not get LDAP protocol version.');
+ }
+
+ if ($vers != 3) {
+ watchdog('user', 'Could not start TLS, only supported by LDAP v3.');
+ }
+ else if (!ldap_start_tls($con)) {
+ watchdog('user', t("Failed to start TLS on LDAP server. (Error %errno: %error).", array('%errno' => ldap_errno($con), '%error' => ldap_error($con))));
+ }
+ }
+ }
+
+ function connectAndBind($dn = '', $pass = '') {
+ $this->establishConnection();
+
+ $con = $this->connection;
+ //die('con: ' . $con . ', dn: ' . $dn . ', pass: ' . $pass . ', server: ' . $this->server . ', port: ' . $this->port);
+ // We don't want anonymous connections here
+ if (!$dn || !$pass || !$this->bind($dn, $pass)) {
+ watchdog('user', t('LDAP Bind failure for user %user. Error %errno: %error', array('%user' => $dn,'%errno' => ldap_errno($con), '%error' => ldap_error($con))));
+ return NULL;
+ }
+
+ return $con;
+ }
+
+ function bind($dn, $pass) {
+ ob_start();
+ $ret = ldap_bind($this->connection, $dn, $pass);
+ ob_end_clean();
+
+ return $ret;
+ }
+
+
+ function disconnect() {
+ if ($this->connection) {
+ ldap_unbind($this->connection);
+ $this->connection = NULL;
+ }
+ }
+
+ // WARNING! WARNING! WARNING!
+ // This function returns its entries with lowercase attribute names.
+ // Don't blame me, blame PHP's own ldap_get_entries()
+ function retrieveAttributes($dn) {
+ $result = ldap_read($this->connection, $dn, 'objectClass=*');
+ $entries = ldap_get_entries($this->connection, $result);
+
+ return $entries[0];
+ }
+
+ function retrieveAttribute($dn, $attrname) {
+ $entries = $this->retrieveAttributes($dn);
+
+ return $entries[strtolower($attrname)][0];
+ }
+
+ function retrieveMultiAttribute($dn, $attrname) {
+ $entries = $this->retrieveAttributes($dn);
+
+ $result = array();
+ $retrieved = $entries[strtolower($attrname)];
+ $retrieved = $retrieved ? $retrieved : array();
+ foreach ($retrieved as $key => $value) {
+ if ($key !== 'count') {
+ $result[] = $value;
+ }
+ }
+ return $result;
+ }
+
+ function writeAttributes($dn, $attributes) {
+ ldap_modify($this->connection, $dn, $attributes);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/security/drupal4-ldap_integration/ldap_integration/ldap_integration/conf.php b/security/drupal4-ldap_integration/ldap_integration/ldap_integration/conf.php
new file mode 100644
index 000000000000..38348584ddc3
--- /dev/null
+++ b/security/drupal4-ldap_integration/ldap_integration/ldap_integration/conf.php
@@ -0,0 +1,66 @@
+<?php
+// $Id: conf.php,v 1.1.4.4 2005/10/29 19:09:30 pablobm Exp $
+
+/*
+ * Interesting constants that admins would want to mess with
+ */
+
+// Admin must define a user able to write users' attributes (to generate new passwords when they are lost)
+define(LDAP_WRITER_USER_DN, 'cn=writer,dc=example,dc=com');
+define(LDAP_WRITER_USER_PASS, 'secret');
+
+// Admin must define a user able to read users' attributes (to read e-mail addresses when passwords are lost)
+define(LDAP_READER_USER_DN, 'cn=reader,dc=example,dc=com');
+define(LDAP_READER_USER_PASS, 'secret');
+
+$GLOBALS['ldap_drupal_mappings'] = array(
+ // ldap_attribute => drupal field
+ // 'cn' => 'name',
+ 'mailAddress' => 'mail',
+ 'userPassword' => 'pass',
+ //'signature' => 'signature',
+ //'timeZome' => 'timezone'
+);
+
+/*
+ * Edit this list so that all attributes that you might wish to show
+ * are included. You may then enable/disable attributes in the Admin page.
+ *
+ * The left hand element indicates the LDAP attribute name.
+ *
+ * The 1st right hand elements in the array determine how the attribute and
+ * its value are displayed. The first element may be 'text', 'image', or 'url'.
+ */
+
+$GLOBALS['ldap_attributes'] = array(
+ 'givenName' => array('text', 'textfield', t('First Name'), 64, 64),
+ 'userPassword' => array('pass', 'password', t('Password'), 64, 64),
+ 'initials' => array('text', 'textfield', t('Initial'), 64, 4, t('Your middle initial.')),
+ 'sn' => array('text', 'textfield', t('Last Name'), 64, 64), //aka Surname
+ 'cn' => array('text', 'textfield', t('Common Name'), 64, 64),
+ 'displayName' => array('text', 'textfield', t('Display Name'), 64, 64),
+ 'mail' => array('mailto', 'textfield', t('Email'), 64, 64, ''),
+ 'description' => array('text', 'textfield', t('Description'), 64, 64, ''),
+ 'postOfficeBox' => array('text', 'textfield', t('P.O. Box'), 64, 64),
+ 'streetaddress' => array('text', 'textfield', t('Address'), 64, 64),
+ 'l' => array('text', 'textfield', t('City'), 64, 64, t('Your city or other location')),
+ 'st' => array('text', 'textfield', t('State'), 4, 2, t('Your state or province')),
+ 'postalCode' => array('text', 'textfield', t('Postal Code'), 7, 5, t('Your Zip or Postal code')),
+ 'co' => array('text', 'textfield', t('Country'), 64, 64, t('Country or region')),
+ 'company' => array('text', 'textfield', t('Company'), 12, 12, 'Company or organization'),
+ 'title' => array('text', 'textfield', t('Title'), 12, 12),
+ 'department' => array('text', 'textfield', t('Department'), 64, 64),
+ 'physicalDeliveryOfficeName' => array('text', 'textfield', t('Office'), 64, 64, ''),
+ 'homephone' => array('text', 'textfield', t('Home Phone'), 64, 64, ''),
+ 'mobile' => array('text', 'textfield', t('Mobile Phone'), 64, 64, ''),
+ 'otherTelephone' => array('text', 'textfield', t('Other Phone'), 64, 64, ''),
+ 'wWWHomePage' => array('image', 'textfield', t('Web Page'), 64, 64, ''),
+ 'url' => array('link', 'textfield', t('Other web pages'), 64, 64, ''),
+ 'roomNumber' => array('text', 'textfield', t('Office Location'), 64, 64, ''),
+ 'telephoneNumber' => array('text', 'textfield', t('Office Phone'), 64, 64, ''),
+
+ // examples of displaying attributes in Select menus or TextArea boxes. Helpful for composing search queries
+ 'gender' => array('text', 'select', t('Gender'), array(0 => '-', 'm' => t('male'), 'f' => t('female')), 'Pick a gender', 0, 0),
+ 'publickey' => array('text', 'textarea', t('Public key'), 64, 4, ''));
+
+?>
diff --git a/security/drupal4-ldap_integration/ldap_integration/zcallbacks.module b/security/drupal4-ldap_integration/ldap_integration/zcallbacks.module
new file mode 100644
index 000000000000..8446415141e1
--- /dev/null
+++ b/security/drupal4-ldap_integration/ldap_integration/zcallbacks.module
@@ -0,0 +1,50 @@
+<?php
+// $Id: zcallbacks.module,v 1.1.2.1.2.3 2005-12-13 20:30:27 pablobm Exp $
+
+/*
+ * This mini-module just redefines a callback originally defined in user.module, so it
+ * serves better our interests in the ldap_integration module.
+ * It has to be separated from the rest of the module because modules are loaded in
+ * alphabetic order and this callback must be loaded after that of user.module.
+ */
+
+function zcallbacks_help($section) {
+ $output = '';
+
+ switch ($section) {
+ case 'admin/modules#zcallbacks':
+ $output = 'zcallbacks';
+ break;
+ case 'admin/modules#description':
+ case 'admin/help#zcallbacks':
+ $output = t('<strong>Needed</strong> to make <em>ldap_integration</em> module work.');
+ break;
+ case 'user/help#zcallbacks':
+ $output = t('<p>This module <strong>must be enabled</strong> for LDAP authentication to work with em>ldap_integration</em> module</p>');
+ break;
+ }
+
+ return $output;
+}
+
+function zcallbacks_menu($may_cache) {
+ $items = array();
+
+ if ($may_cache) {
+ // Hack callback. It replaces one set in user.module
+ $items[] = array(
+ 'path' => 'user/login',
+ 'title' => t('log in'),
+ 'callback' => '_zcallbacks_call',
+ 'access' => TRUE,
+ 'type' => MENU_CALLBACK);
+ }
+
+ return $items;
+}
+
+function _zcallbacks_call() {
+ print theme('page', _ldap_integration_fake_user_login($_POST['edit']));
+}
+
+?>
diff --git a/security/drupal4-ldap_integration/pkg-descr b/security/drupal4-ldap_integration/pkg-descr
new file mode 100644
index 000000000000..b6a23d3b7035
--- /dev/null
+++ b/security/drupal4-ldap_integration/pkg-descr
@@ -0,0 +1,5 @@
+The ldap_integration Drupal module allows users to authenticate against
+a LDAP directory. Additionally, users can read and modify their data in
+the LDAP directory subject to administrative restrictions.
+
+WWW: http://drupal.org/node/15109